akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}




template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;



main(){
  int v,e;
  cin>>v>>e;
  WG<int> es(v);
  vector<vector<int>> dp((1<<v),vector<int>(v,INF));
  vector<int> cost(v,INF);

  rep(i,e){
    int s,t,d;
    cin>>s>>t>>d;
    es[s].PB(edge<int>(t,d));
    if(t==0){
      cost[s]=min(cost[t],d);
    }
  }
  dp[1][0]=0;
  rep(i,(1<<v)){
    rep(j,v){
      if(dp[i][j]==inf) continue;
      for(auto et:es[j]){
        if(i&(1<<et.to)) continue;
        dp[i|(1<<et.to)][et.to]=min(dp[i|(1<<et.to)][et.to],dp[i][j]+et.cost);
      }
    }
  }

  int ans=INF;
  rep(i,v){
    if(dp[(1<<v)-1][i]!=INF&&cost[i]!=INF)
      ans=min(ans,dp[(1<<v)-1][i]+cost[i]);
    }

  cout<<((ans==INF)?-1:ans)<<endl;

}



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

vector<int>adj1[200005],adj2[200005];

int gr1[200005],gr2[200005],idx1,idx2;

void dfs2(int u){
    gr2[u]=idx2;
    for(auto v : adj2[u])
        if(!gr2[v])
            dfs2(v);
}

void dfs1(int u){
    gr1[u]=idx1;
    for(auto v : adj1[u])
        if(!gr1[v])
            dfs1(v);
}

int main()
{
    ios_base::sync_with_stdio(0);

    int n,k,l,x,y;
    cin >> n >> k >> l;
    for(int i=0;i<k;i++){
        cin >> x >> y;
        adj1[x-1].push_back(y-1);
        adj1[y-1].push_back(x-1);
    }

    for(int i=0;i<l;i++){
        cin >> x >> y;
        adj2[x-1].push_back(y-1);
        adj2[y-1].push_back(x-1);
    }



    for(int i=0;i<n;i++){
        if(!gr1[i]){
            idx1++;
            dfs1(i);
        }
        if(!gr2[i]){
            idx2++;
            dfs2(i);
        }
    }
            
    vector<pair<int,int> >groups(n);

    for(int i=0;i<n;i++)
        groups[i]=make_pair(gr1[i],gr2[i]);
    sort(groups.begin(),groups.end());

    vector<int>ans(n);

    for(int i=0;i<n;i++){
        pair<int,int>p = make_pair(gr1[i],gr2[i]);
        ans[i]=upper_bound(groups.begin(),groups.end(),p)-lower_bound(groups.begin(),groups.end(),p);
    }

    for(auto x : ans)
        cout << x <<  " ";
    cout << endl;

    return 0;
}

Measured memory_bytes: 20224
splitEvery :: Int -> [a] -> [[a]]
splitEvery _ [] = []
splitEvery n xs = as : splitEvery n bs 
     where (as,bs) = splitAt n xs

check :: Int -> Bool
check value = not $ null $ filter (== value) $ takeWhile (<= value) [x*x|x<-[1..]]

solve :: [Int] -> Int
solve (n:d:rest) =
    func datas
    where
        datas = splitEvery d rest
        func :: [[Int]] -> Int
        func [] = 0
        func (x:xs) =
            l1 + l2
            where 
                l1 = func xs 
                l2 = length $ filter check $ do{
                    x2 <- xs;
                    return $ foldr (+) 0 $ do {
                        (i1,i2) <- zip x x2; 
                        return $ (i1 - i2) * (i1 - i2);
                    };
                }

main = interact $ show.solve.map read.words


Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int N, A, B, C, D;
  cin >> N >> A >> B >> C >> D;
  A--; B--; C--; D--;
  string S;
  cin >> S;
  S = S.substr(A, max(C, D) - A + 1);
  N = max(C, D) - A + 1;
  B -= A; C -= A; D -= A; A = 0;
  cerr << S << endl << N << " " << A << " " << B << " " << C << " " << D << endl;

  for (int i = 1; i < N; i++)
  {
    if (S.substr(i - 1, 2) == "##")
    {
      cout << "No" << endl;
      return 0;
    }
  }

  if (C < D)
  {
    cout << "Yes" << endl;
    return 0;
  }

  for (int i = 1; i < N - 1; i++)
  {
    if (S.substr(i - 1, 3) == "..." && B <= i && i <= D)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 772
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

int n, m, q;
vector<int> a, b, c, d;
int ans = 0;

void dfs(vector<int> v = vector<int>(0)){
    if(v.size() == n){
        int sum = 0;
        for(int i = 0; i < q; ++i){
            if(v[b[i]] - v[a[i]] == c[i])   sum += d[i];
        }
        chmax(ans, sum);
        return;
    }

    int st = 1;
    if(v.size() != 0)   st = v.back();
    for(int i = st; i <= m; ++i){
        vector<int> next = v;
        next.push_back(i);
        dfs(next);
    }
}

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

    cin >> n >> m >> q;
    a.resize(q);
    b.resize(q);
    c.resize(q);
    d.resize(q);
    for(int i = 0; i < q; ++i){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        --a[i], --b[i];
    }

    dfs();
    cout << ans << endl;
}

Measured memory_bytes: 3620
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,l; cin>>n>>l;
    int ans=(l-1)*n+n*(n+1)/2;
    if(l*(l+n-1)>0){
        if(l>0) ans-=l;
        else ans-=(l+n-1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	long long int sol=0;
	cin>>n;
	int vet[n];
	for(int i=0;i<n;i++)cin>>vet[i];
	for(int i=1;i<n;i++){
		if(vet[i]<vet[i-1]){
			sol+=vet[i-1]-vet[i];
			vet[i]=vet[i-1];
		}
	}
	cout<<sol;
}



Measured memory_bytes: 4416
x, y = list(map(int, input().split()))

a = {1,3,5,7,8,10,12}
b = {4,6,9,11}
c = {2}

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
  print('Yes')
else:
  print('No')



Measured memory_bytes: 2940
#!/usr/local/bin/ruby
while (n=gets.to_i)!=0
  rec=Array.new
  for i in 0..n-1
    rec << gets.to_i
  end
  ans = -1000000
    for x in 0..n-1
    sum = 0
    for y in x..n-1
      sum = sum + rec[y].to_i
      if sum > ans
        ans = sum
      end
    end
  end
  puts "#{ans}"
end

Measured memory_bytes: 6116
import collections

n = int(input())
a = list(map(int, input().split()))
q = int(input())
bc = [list(map(int, input().split())) for _ in range(q)]

c = collections.Counter(a)

s = sum(a)
for bi, ci in bc:
    if bi not in c:
        print(s)
    else:
        s = s - c[bi] * bi + c[bi] * ci
        print(s)
        if ci in c:
            c[ci] = c[ci] + c[bi]
            c[bi] = 0
        else:
            c[ci] = c[bi]
            c[bi] = 0

Measured memory_bytes: 36460
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>
#include<random>
#include<set>
 
#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
#define Sort(X) sort(X.begin(), X.end())
#define RSort(X, T) sort(X.begin(), X.end(), greater<T>())
//#define MOD 998244353
#define MAX 1000000000ll
 
typedef long long int ll;
typedef unsigned long long int ull;
 
using namespace std;
 
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; }


ll cnt = 0;
ll slv(vvl &T, ll p, ll pc, vl &C, ll num) {
	ll c = 1;
	ll max = 0;
	cnt++;
	rep(i, T[num].size()) {
		if (c == pc) c++;
		if (T[num][i] == p) {
			i++;
			continue;
		}
		C[T[num][i+1]] = c;
		chmax(max, slv(T, num, c, C, T[num][i]));
		c++;
		i++;
	}

	chmax(max, c);

	return max;
}

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

	ll N;
	cin >> N;
	vvl T(N);
	vl C(N-1, -1);
	vector<pair<ll, ll>> B(N);
	vvl TC(N);
	ll a, b;

	rep(i, N-1) {
		cin >> a;
		cin >> b;
		a--;
		b--;
		T[a].pb(b);
		T[a].pb(i);
	}

	ll max = slv(T, 0, 0, C, 0);

	cout << max-1 << endl;
	rep(i, N-1) {
		cout << C[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 10880
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int T = sc.nextInt();
        int A = sc.nextInt();
        
        int ans = 0; //現地点で最も良い建設地点の番号
        double best = 100000000; //現地点で最も良い建設地点の温度差
        //小さいほど嬉しいので,ダミーの初期値はうんと大きい値にしておこう
        for(int n=1;n<=N;n++){
        	int h = sc.nextInt();
        	double temp = T - h*0.006; //この地点の気温を求める.
        	double err = Math.abs(A-temp); //目標気温との差を求める.
        	//絶対値関数がサポートされていない言語では,if-else文の分岐を使うことになるだろう
        	if(err<best){//最高記録を更新した! データを記録しよう
        		best = err;
        		ans = n;
        	}
        }
        System.out.println(ans); //答を出力
    }
}


Measured memory_bytes: 22228
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
using namespace std;
using ll = long long;
using ull = unsigned long long;
ll cnt[51];
ll len[51];
void init() {
    cnt[0] = 1LL;
    len[0] = 1LL;
    for (int i = 0; i < 50; i++) {
        cnt[i + 1] = (cnt[i] << 1) + 1LL;
        len[i + 1] = (len[i] << 1) + 3LL;
    }
}
bool falg = false;
void recur(ll N, ll &X, ll &total) {
    if (X == 0) {
        return;
    }
    if (X >= (len[N] - N)) {
        total += cnt[N];
        X -= len[N];
        if (X < 1) {
            return;
        }
        else if (X == 1) {
            total ++;
            return;
        }
        else {
            total ++;
            X--;
            recur(N, X, total);
        }
    }
    else {
        X--;
        recur(N - 1LL, X, total);
    }
}
int main(int argc, char *argv[]) {
    ios_base::sync_with_stdio(false);//bugs with `printf'
    cin.tie(NULL);//incompatible with `while (cin >> ...)'
    ll N, X, total;
    total = 0LL;
    cin >> N >> X;
    if (N == 0LL) {
        cout << 0 << endl;
        return 0;
    }
    if (X <= N) {
        cout << 0 << endl;
        return 0;
    }
    init();
    recur(N, X, total);
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int a, b,c;
	int x, y;
	int price_min;
		cin >> a >> b >> c >> x >> y;
		price_min = a * x + b * y;
			for (int i = 0; i <= max(x,y)*2; i+=2) {
					if (c * i + max((x - (i / 2)), 0) * a + max((y - (i / 2)), 0)*b< price_min) {
						price_min = c * i +max( (x - (i/ 2)),0) * a + max((y - (i/ 2)),0) * b;
					}
			}
			cout << price_min;
		
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
//using Graph = vector<vector<pair<ll,ll>>>;
const int mod =1e+9+7;

const int dy[4]={0,1,0,-1};
const int dx[4]={1,0,-1,0};
const ll INF=1e10;

int main(){
    ll n; cin>>n;
    ll ans=n;
    for(int i=0;i<=n;i++){
        ll  cnt=0;
        ll t=i;
        while(t>0){
            cnt+=t%6;
            t/=6;
        }
        t=n-i;
        while(t>0){
            cnt+=t%9;
            t/=9;
        }
        ans=min(ans,cnt);
    }
    cout<<ans<<endl;
}











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

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

  if (s.back() == 's') {
    cout << s + "es" << endl;
  } else {
    cout << s + "s" << endl;
  }

  return 0;
}


Measured memory_bytes: 3628
n = int(input())
h = list(map(int, input().split()))
h = h[::-1]
count = 0
for i in range(1, n):
    if h[i]-h[i-1]==1:
        h[i]+=-1
    elif h[i]-h[i-1]>=2:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe

ll gcd(ll c, ll d) { return d ? gcd(d, c%d) : c;}
ll lcm(ll c, ll d) { return c / gcd(c,   d) * d;}
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int n,x,l[100]={},ans=0,d = 0;
cin >> n >> x;
for(int i=1;i<n+1;i++){
    cin >> l[i];
}
for(int i=0;i<n+1;i++){
    d = d + l[i];
    if(d<=x){
        ans++;
    }
}
cout << ans << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#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) x.size()
#define fi first
#define se second
const int INF = 1e9;
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; cin >> N;
    int mi=INF;
    int A[N];
    rep(i,N) cin >> A[i];
    rng(i,1,100){
        int pos=0;
        rep(j,N){
            pos+=(abs(A[j]-i)*abs(A[j]-i));
        }
        chmin(mi,pos);
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
<?php

        $in = fgets(STDIN);
        $in_array = explode(" ", trim($in));
        $a = (int)$in_array[0];
        $b = (int)$in_array[1];
        if($a * $b % 2 == 0){
            echo "Even";
        } else {
            echo "Odd";
        }
        

?>


Measured memory_bytes: 3828
#include <stdlib.h>
#include<iostream>
#include<bits/stdc++.h>
#include<cmath>
#define LL long long
const int INF=0x3f3f3f3f;
#define mod 1000000007
using namespace std;
//priority_queue
int Max=0;
char s[2003][2003];
int n,m;
int sum=0;
int ll[2003][2003];
int hh[2003][2003];
int main()
{
    cin>>n>>m;
    for(int i=1; i<=n; i++)
        scanf("%s",s[i]+1);
    for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
            if(s[i][j]=='.')ll[i][j]=1,hh[i][j]=1;
           /* for(int i=1;i<=n;i++)
                for(int j=1;j<=m;j++)
                printf(j==m?"%d\n":"%d ",ll[i][j]);*/
   for(int i=1; i<=n; i++)
        for(int j=1; j<=m; j++)
        {
            if(s[i][j-1]=='.'&&s[i][j]=='.')hh[i][j]+=hh[i][j-1];
        }
    for(int i=1; i<=n; i++)
        for(int j=m; j>=1; j--)
            if(s[i][j]=='.'&&s[i][j-1]=='.')hh[i][j-1]=hh[i][j];
 // cout<<hh[1][2];
   for(int i=1; i<=m; i++)
        for(int j=1; j<=n; j++)
        {
            if(s[j-1][i]=='.'&&s[j][i]=='.')ll[j][i]+=ll[j-1][i];
        }
    for(int i=1; i<=m; i++)
        for(int j=n; j>=1; j--)
            if(s[j][i]=='.'&&s[j-1][i]=='.')ll[j-1][i]=ll[j][i];
    /*for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
     {
         if(s[i][j-1]=='.'&&s[i][j]=='.')ll[i][j]+=ll[i][j-1];
     }*/
     for(int i=1;i<=n;i++)
    for(int j=1;j<=m;j++)
        Max=max(Max,ll[i][j]+hh[i][j]-1);

    cout<<Max;
}


Measured memory_bytes: 35456
#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 D;
  cin >> D;
  long long c[26];
  for (int i = 0; i < 26; i++) cin >> c[i];
  long long s[D][26];
  for (int d = 0; d < D; d++) {
    for (int i = 0; i < 26; i++) {
      cin >> s[d][i];
    }
  }
  long long last[26];
  fill(last, last + 26, 0);
  int ans[D];
  for (int d = 0; d < D; d++) {
    int max_i = 0;
    long long max_v = 0;
    for (int i = 0; i < 26; i++) {
      long long tmp = c[i] * (d + 1 - last[i]) + s[d][i];
      if (max_v < tmp) {
        max_v = tmp;
        max_i = i;
      }
      last[max_i] = d + 1;
      ans[d] = max_i + 1;
    }
  }
  for (int d = 0; d < D; d++) {
    cout << ans[d] << endl;
  }
  return 0;
}


Measured memory_bytes: 3728
import java.util.Scanner;


public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        int a = nextInt();
        int  b= nextInt();
        int  c= nextInt();
        int k = nextInt();
        int sum = 0;

        if(k<=a){
            print(k);
            System.exit(0);
        }
        if(k<=a+b){
            print(a);
            System.exit(0);
        }
        else{
            print(a-(k-a-b));
            System.exit(0);
        }
    }

    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

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

int main(){
  int n,i,P,K,hantei;

  cin>>n;

  for(i=0;i<n;i++){
    cin>>K>>P;

    hantei = K % P;

    if(hantei==0)
      cout<<P<<endl;

    else
      cout<<hantei<<endl;
  }
    return 0;
}

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

template< typename iterator >
bool solve( iterator first, iterator last, int M, int i = 0 )
{
    if( M == 0 ) 
        return 1 ;
    if( i >= std::distance( first, last ) )
        return 0 ;

    bool res = solve( first, last, M, i+1 ) || solve( first, last, M - *(first+i), i+1 ) ;
    return res ;
}

int main()
{
    int n, q ;
    std::cin >> n ; 
    std::vector<int> A(n) ;
    for( int i = 0 ; i < n ; ++i )
    {
        std::cin >> A.at(i) ;
    }
    std::cin >> q ;
    int M ;
    for( int i = 0 ; i < q ; ++i )
    {
        std::cin >> M ;
        if( solve( A.begin(), A.end(), M ) )
            std::cout << "yes" << std::endl ;
        else
            std::cout << "no" << std::endl ;
    }
}



Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define INF 1000000007
//S.size()

using namespace std;


typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<bool> VB;
typedef unsigned long long ll;



int main(void){
  int N;cin>>N;
  int d[N];rep(i , N)cin>>d[i];
  int num1 = 0 ,num2 = 0;
  sort(d,d + N);
  int min = d[0],max = d[N - 1];
  for(int t = min ;t <= max ;t++){
    if(d[N / 2] >= t && d[N / 2 - 1] < t){
      num1 = t;
      break;
    }
  }
  for(int k = max;k >= min;k--){
    if(d[N / 2] >= k && d[N / 2 - 1] < k){
      num2 = k;
      break;
    }
  }
  if(num1 == 0 && num2 == 0)cout<<0;
  else cout<<num2 - num1 + 1;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=int (a);i<int (n);i++)
#define OUT  freopen("output.txt", "w", stdout)
#define IN  freopen("input.txt", "r", stdin)
#define mem(a,b) memset((a),(b),sizeof(a))
#define NumofDigits(n) ((int)log10(n)+1)
#define NumofBits(n) ((int)log2(n)+1)
#define PI 3.14159265358979323846264
#define vii vector<pair<int,int>>
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi  vector<int>
#define nl  cout<<"\n"
#define pb  push_back
#define mp  make_pair
#define ll  long long 
#define ss  second 
#define ff  first
#define endl "\n"
#define sp  " "
using namespace std;
	
int main(){
ios::sync_with_stdio(0);cin.tie(0);
int t=1; //cin>>t;
while(t--)
{
	
  ll n; cin>>n;
 if(n<30)cout<<"No";
 else cout<<"Yes";
 	
  
}

}


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
int main()
{
	int n;
	cin>>n;
	if(n==1){
		cout<<"1";
		return 0;
	}
	if(n>=2&&n<=3){
		cout<<"2";
		return 0;
	}
	if(n>=4&&n<=7){
		cout<<"4";
		return 0;
	}
	if(n>=8&&n<=15){
		cout<<"8";
		return 0;
	}
	if(n>=16&&n<=31){
		cout<<"16";
		return 0;
	}
	if(n>=32&&n<=63){
		cout<<"32";
		return 0;
	}
	if(n>=64){
		cout<<"64";
		return 0;
	}
    return 0;
}

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

int main()
{
	string S1, S2, S3;
	cin >> S1 >> S2 >> S3;

	cout << S1[0] << S2[0] << S3[0] << endl;
}






Measured memory_bytes: 3580
var std = process.stdin;
std.resume();
std.setEncoding('utf8');
std.on('data', function (chunk) {
    var data = chunk.split(/\n/g);

    for (var i = 0; i < data.length; i++) {
        var op = data[i].split(' ')[1];
        if (op === '?') { break; }
        var ans = Math.floor(eval(data[i]));
        console.log(ans);
    };
});

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

ans = "No"
cnt = {}
for ai in a:
    if ai in cnt:
        cnt[ai] += 1
    else:
        cnt[ai] = 1
if len(cnt) == 1:
    if 0 in cnt:
        ans = "Yes"
elif len(cnt) == 2:
    k = list(sorted(cnt.keys()))
    if k[0] == 0 and 2 * cnt[0] == cnt[k[1]] and 3 * cnt[0] == n:
        ans = "Yes"
elif len(cnt) == 3:
    v = list(cnt.values())
    k = list(cnt.keys())
    if v[0] == v[1] == v[2] and k[0] ^ k[1] == k[2]:
        ans = "Yes"
print(ans)

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

using namespace std;    

const int maxn = 3e5 + 222;

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

    string s;
    cin >> s;

    for(int i = 0; i < s.size(); i++)
    	if(s[i]=='?')cout<<'D';
    	else cout << s[i];	
	return 0;
}
                                               

Measured memory_bytes: 3788
#include<iostream>
#include<algorithm>
#include<deque>
#include<set>
using namespace std;
#define MAX_N 100100


int par[MAX_N * 2 + 10];
int myrank[MAX_N * 2 + 10];
int n, a[MAX_N * 2 + 10];
deque<int> v[MAX_N*2+10];
set<int> s;

void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		myrank[i] = 0;
	}
}

int find(int x){
	if(par[x] == x){
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	
	if(myrank[x] < myrank[y]){
		par[x] = y;
	} else {
		par[y] = x;
		if(myrank[x] == myrank[y]) myrank[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

int main(){
	
	init(MAX_N*2+10);
	
	cin>>n;
	
	for(int i = 0; i < n; i++){
		cin>>a[i];
		int n = a[i];
		a[i] += MAX_N;
		for(int j = 2; j * j <= n; j++){
			if(n%j == 0){
				// cout<<j<<endl;
				unite(j,a[i]);
				while(n%j == 0){
					n/=j;
				}
			}
		}
		if(n != 1){
			unite(n,a[i]);
			// cout<<n<<endl;
		}
	}
	
	for(int i = 0; i < n; i++){
		// cout<<find(a[i])<<endl;
		v[find(a[i])].push_back(a[i]);
		s.insert(find(a[i]));
	}
	for(int y : s){
		sort(v[y].begin(), v[y].end());
	}
	for(int i = 0; i < n; i++){
		a[i] = v[find(a[i])].front();
		v[find(a[i])].pop_front();
		if(i&&a[i-1] > a[i]){
			cout<<0<<endl;
			return 0;
		}
		// cout<<a[i]-MAX_N<<endl;
	}
	
	cout<<1<<endl;
	
	return 0;
}


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

int main(void){
    long long A,B,C,X,Y;cin>>A>>B>>C>>X>>Y;
    long long a,b;a=b=0;
    long long ans=0;
    if(A+B>=2*C){
        if(X>=Y){
            ans+=Y*2*C+(X-Y)*min(2*C,A);    
        }
        else{
            ans+=X*2*C+(Y-X)*min(2*C,B);
        }
    }
    else{
        ans+=X*A+Y*B;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>

int main(void) {
	int h, w;
	char c[100][100];
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; ++i) {
		scanf("%s", c[i]);
	}
	for (int i = 0; i < h; ++i) {
		for (int k = 0; k < w; ++k) {
			printf("%c", c[i][k]);
		}printf("\n");
		for (int k = 0; k < w; ++k) {
			printf("%c", c[i][k]);
		}printf("\n");
	}

	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[][]dp=new int[n][3];
		for(int[]v:dp)
			Arrays.setAll(v,i->s.nextInt());
		for(int i=1;i<n;++i) {
			int[]c=dp[i-1],d=dp[i];
			d[0]+=Math.max(c[1],c[2]);
			d[1]+=Math.max(c[2],c[0]);
			d[2]+=Math.max(c[0],c[1]);
		}
		System.out.println(Arrays.stream(dp[n-1]).max().getAsInt());
	}
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,m;
  while(cin >> n >> m&&n && m){
    vary(ll,c,m,0);
    vary(ll,x,n+1,0);
    rep(i,m){
      cin >> c[i];
    }
    rep(j,n){
      cin >> x[j+1];
    }
    vector<vector<ll>> dp(n+1 ,vector<ll>(260,inf));
    dp[0][128] = 0;
    REP(i,1,n+1){
      rep(j,256){
        rep(k,m){
          ll C = j+c[k];
          if(C > 255) C = 255;
          if(C < 0) C = 0;
          dp[i][C] = min(dp[i][C], dp[i-1][j]+(ll)pow(x[i] - C,2));
        }
      }
    }
    ll ans = inf;
    rep(i,256){
      ans = min(ans,dp[n][i]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 44516
N, M = map(int,input().split())
A = [[] for _ in range(N)]
B = [[] for _ in range(M)]
for i in range(N):
    A[i] = input()
for j in range(M):
    B[j] = input()
for k in range(N-M+1):
    for l in range(N-M+1):
        f = 0
        for p in range(M):
            for q in range(M):
                if not A[k+p][l+q] == B[p][q]:
                    f = 1
                    break
            if f == 1:
                break
        if f == 0:
            print('Yes')
            exit()
print('No')

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

int main()
{
    int n;
    scanf("%d",&n);
    getchar();

    char s1[n/2];
    char s2[n/2];
    fgets(s1,(n/2)+1,stdin);
    fgets(s2,(n/2)+1,stdin);



    if((n%2)==0)
    {
        if(strcmp(s1,s2)==0)

            printf("Yes\n");
        else
            printf("No\n");
    }

    else if (n==1)
    {
        fgets(s1,2,stdin);
        printf("No\n");
    }
    else if ((n%2)!=0)
        printf("No\n");


return 0;

}


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

struct BIT{
  int size;
  vector<ll> dat;
  void init(int n){
    size=n;
    dat.clear();
    dat.resize(n+1);
  }
  void Add(int i,ll x){
    while(0<i&&i<=size){
      dat[i]+=x;
      i+=(i&-i);
    }
  }
  ll Sum(int i){
    ll res=0;
    while(0<i){
      res+=dat[i];
      i-=(i&-i);
    }
    return res;
  }
};



int main(){
  int n,q;
  BIT A,B;
  scanf("%d %d",&n,&q);
  A.init(n);
  B.init(n);
  for(int i=1;i<=q;i++){
    int type;
    ll s,t,value;
    scanf("%d",&type);
    if(type==0){
      scanf("%lld %lld %lld",&s,&t,&value);
      A.Add(s,value);
      A.Add(t,-value);
      B.Add(s,-value*(s-1));
      B.Add(t,value*(s-1) + value*(t-s+1) );
    }
    if(type==1){
      scanf("%lld %lld",&s,&t);
      s--;
      printf("%lld\n", A.Sum(t)*t+B.Sum(t) - A.Sum(s)*s-B.Sum(s) );
    }
  }
  return 0;
}

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

using namespace std;
using ll  = long long;
using ii  = pair < int , int >;
using pll = pair < ll , ll >;
using i3  = pair < int , ii >;
using vi  = vector < int >;
using vl  = vector < ll >;
using vii = vector < ii >;
using vi3 = vector < i3 >;

const int N = 2e5 + 5;
const ll INF = 1e12;
const double eps = 1e-9 , PI = acos(-1);

char s[N];
int n , k;
bool hate[12];
int cnt = 0;
int ans = 1e9;

void go(int i , int x){
    if(i == cnt){
        if(x >= n){
            ans = min(ans , x);
        }
        return;
    }

    for(int j = (i == 0 ? 1 : 0) ; j <= 9 ; j ++){
        if(!hate[j])go(i + 1 , x*10 + j);
    }
}

void get(int n){
    while(true){
        cnt ++;
        n /= 10;
        if(n == 0)return;
    }
}

void solve(){
    scanf("%d %d" , &n , &k);
    get(n);

    while( k -- ){
        int x; scanf("%d" , &x);
        hate[x] = 1;
    }

    go(0 , 0);
    if(ans == 1e9){
        int mn = 12;
        for(int i = 1 ; i <= 9 ; i ++)if(!hate[i]){
            mn = i;
            break;
        }

        printf("%d" , mn);
        if(!hate[0])mn = 0;
        for(int i = 0 ; i < cnt ; i ++)printf("%d" , mn);
        printf("\n");
    }
    else {
        printf("%d\n" , ans);
    }
}

main(){
    int t = 1;
    //scanf("%d" , &t);

    while( t -- ){
            solve();
    }

    return 0;
}





Measured memory_bytes: 256
n = int(input())
s = [list(input()) for _ in range(n)]
alluse = set(s[0])
for i in range(1, len(s)):
    alluse = alluse & set(s[i])
res = ""
alluse = sorted(alluse)
for c in alluse:
    count = 100
    for i in range(n):
        count = min(count, s[i].count(c))
    res += c*count
print(res)


Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		int numberOfDices;
		boolean sameDiceCheck = false;
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		numberOfDices = Integer.parseInt(in.readLine());
		Dice dices[] = new Dice[numberOfDices];

		for (int i = 0; i < numberOfDices; i++) {
			dices[i] = new Dice();
			dices[i].createDice(in.readLine().split(" "));
		}

		for (int i = 0; i < numberOfDices; i++) {
			for (int j = i + 1; j < numberOfDices; j++) {
				sameDiceCheck = dices[i].check(dices[j]);
				if (sameDiceCheck) {
					break;
				}
			}
			if (sameDiceCheck) {
				break;
			}
		}
		if (sameDiceCheck) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

class Dice {
	public Dice Dices[];

	public int on, tw, th, fo, fi, si;

	public Dice() {

	}

	public Dice(int on, int tw, int th, int fo, int fi, int si) {
		this.on = on;
		this.tw = tw;
		this.th = th;
		this.fo = fo;
		this.fi = fi;
		this.si = si;
	}

	void createDice(String[] data) {
		int[] diceNums = new int[6];
		for (int i = 0; i < data.length; i++) {
			diceNums[i] = Integer.parseInt(data[i]);
		}
		on = diceNums[0];
		tw = diceNums[1];
		th = diceNums[2];
		fo = diceNums[3];
		fi = diceNums[4];
		si = diceNums[5];
	}

	boolean check(Dice otherDice) {
		boolean result = false;
		int checkTimes = 0;

		while (checkTimes <= 29) {
			result = this.match(otherDice);
			if (result)
				break;
			checkTimes++;
			if (checkTimes == 5 || checkTimes == 15 || checkTimes == 25) {
				otherDice.north();
			} else if (checkTimes == 10 || checkTimes == 20) {
				otherDice.west();
			} else {
				otherDice.rightSpin();
			}
		}
		return result;
	}

	boolean match(Dice otherDice) {
		if (this.on == otherDice.on && this.tw == otherDice.tw
				&& this.th == otherDice.th && this.fo == otherDice.fo
				&& this.fi == otherDice.fi && this.si == otherDice.si) {
			return true;
		}
		return false;
	}

	void rightSpin() {
		int temp = tw;
		tw = fo;
		fo = fi;
		fi = th;
		th = temp;
	}

	public void north() {
		int temp = on;
		on = tw;
		tw = si;
		si = fi;
		fi = temp;
	}

	public void east() {
		int temp = on;
		on = fo;
		fo = si;
		si = th;
		th = temp;
	}

	public void west() {
		int temp = on;
		on = th;
		th = si;
		si = fo;
		fo = temp;
	}

	public void south() {
		int temp = on;
		on = fi;
		fi = si;
		si = tw;
		tw = temp;
	}
}

Measured memory_bytes: 19672
n = input()[::-1]
dp = [[0, 0] for i in range(len(n) + 1)]
dp[0][1] = 1
for i in range(len(n)):
    dp[i + 1][0] = min(dp[i][0] + int(n[i]), dp[i][1] - int(n[i]) + 10)
    dp[i + 1][1] = min(dp[i][0] + int(n[i]) + 1, dp[i][1] - int(n[i]) + 9)
print(dp[len(n)][0])

Measured memory_bytes: 162288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,f,n) for(int i=f; i<(n); i++)
int main()
{
  int n,x,t,ans = 0;
  cin >> n >> x >> t;
  ans = (n/x)*t;
  if(n%x>0)ans+=t;
  cout << ans << endl;

  //--debug : end_stoper
  //string end_stoper; cin >> end_stoper;

  return 0;
}

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

const int N = 16;

int dp[N][1 << N], sum[1 << N], G[N][N];

int main() {
	int n, m, res = 0; scanf("%d%d", &n, &m);
	for (int i = 1, a, b, c; i <= m; i++)
		scanf("%d%d%d", &a, &b, &c), G[a][b] = G[b][a] = c, res += c;
	for (int i = 1; i < 1 << n; i++)
		for (int j = 1; j <= n; j++) if (i & (1 << j - 1))
			for (int k = j + 1; k <= n; k++) if (i & (1 << k - 1))
				sum[i] += G[j][k];
	memset(dp, -0x3f, sizeof(dp));
	for (int s = 1; s < 1 << n; s++) if (s & 1) dp[1][s] = sum[s];
	for (int s = 1; s < 1 << n; s++)
		for (int i = 1; i < n; i++) if (dp[i][s] >= 0) {
			for (int j = 1; j <= n; j++) if (G[i][j] && !(s & (1 << j - 1))) {
				int t = (1 << n) - 1; t ^= s, t ^= (1 << j - 1);
				for (int t1 = t; ~t1; t1 = (t1 - 1) & t) {
					dp[j][s | (1 << j - 1) | t1] = max(dp[j][s | (1 << j - 1) | t1], 
						dp[i][s] + G[i][j] + sum[t1 | (1 << j - 1)]);
					if (!t1) break;
				}	
			}	
		}
	printf("%d\n", res - dp[n][(1 << n) - 1]);
}

Measured memory_bytes: 4480
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        Console.WriteLine(getAns(s) ? "Yes" : "No");
    }
    static bool getAns(string s)
    {
        var sL = s.Length;
        if (!check(s, 0, sL - 1)) return false;
        if (!check(s, 0, sL / 2 - 1)) return false;
        return check(s, sL / 2 + 1, sL - 1);
    }
    static bool check(string s, int L, int r)
    {
        var imax = (r - L + 1) / 2;
        for (int i = 0; i < imax; i++)
            if (s[L + i] != s[r - i]) return false;
        return true;
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
typedef priority_queue<string> priquest;
typedef priority_queue<string,vector<string>,greater<string>> rpriquest;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000007;
ll exp(ll x,ll y){
    if(y==0)return 1;
    if(x==1||x==0)return x;
    if(y%2==1)return (exp(x,y-1)*x)%big;
    ll t=exp(x,y/2);
    return (t*t)%big;
}
void chmin(ll a,ll b){
    if(a>b)a=b;
    return;
}


int main(){
  //cout << fixed << setprecision(10);
  int n,m;cin >> n >> m;
  vector<int> high(n);
  rep(i,n)cin >> high[i];
  vector<bool> ok(n,true);
  rep(i,m){
    int a,b;cin >> a >> b;a--;b--;
    if(high[a]>=high[b])ok[b]=false;
    if(high[a]<=high[b])ok[a]=false;
  }
  int cnt=0;
  rep(i,n)if(ok[i])cnt++;
  cout << cnt << endl;
  
  return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int x[1000];
int main()
{
	int num;
	scanf("%d", &num);
	int sum = 0;
	for (int i = 0; i < num; i++)scanf("%d", &x[i]), sum += x[i];
	int query;
	scanf("%d", &query);
	for (int p = 0; p < query; p++)
	{
		int za, zb;
		scanf("%d%d", &za, &zb);
		za--;
		printf("%d\n", sum - x[za] + zb);
	}
}

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


namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Solve();
        }

        public void Solve()
        {

            string s = Console.ReadLine();
            bool Flag = true;
            bool Cflag = false;
            for (int i = 0; i < s.Length; i++)
            {
                if (i == 0)
                {
                    if (s[0] != 'A') Flag = false;
                }
                else if(2 <= i && i < s.Length - 1)
                {
                    if (('a' <= s[i] && s[i] <= 'z'))
                    {
                        continue;
                    }
                    else if(s[i] == 'C' && Cflag==false)
                    {
                        Cflag = true;
                        continue;
                    }

                    Flag = false;
                }
                else
                {
                    if (('a' <= s[i] && s[i] <= 'z')) continue;
                    Flag = false;
                }
            }

            if (Flag && Cflag) Console.WriteLine("AC");
            else Console.WriteLine("WA");
        }
    }

}


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

int main(){
    long long int ans = 0;
    long long int a = 0;
    long long int b = 0;
    long long int c = 0;
    cin >> a;
    if(a / 100 == 7 || (a % 100) / 10 == 7 || (a % 100) % 10 == 7 ){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;
    }
//    cout << ans <<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

const int N = 200'010;
int a[N];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    sort(a, a + n);
    int ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        if (i > 0 && a[i] == a[i - 1] || i < n - 1 && a[i] == a[i + 1]) continue;
        int v = a[i];
        bool valid = 1;
        for (int d = 1; d * d <= a[i]; d++) {
            if (v % d == 0) {
                if (binary_search(a, a + i, d) || binary_search(a, a + i, v / d)) {
                    valid = 0;
                    break;
                }
            }
        }
        if (valid) ans++;
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 4612
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<string > vecstr;
int main()
{
  int n;
  cin >> n;
  vecint a(n,0);
  REP(i,n){
    cin >> a[i];
  }
  map<int, int> check;
  check[0]++;
  int i = 0;
  int count = 0;
  while(true){
    // cout << count << " " << i << " " << a[i] - 1 << endl;
    if(check.count(1) == 1){
      cout << count << endl;
      return 0;
    }
    check[a[i] - 1]++;
    i = a[i] - 1;
    count ++;
    // if(check.count(i) == 1){
    //   cout << -1 << endl;
    //   return 0;
    // }
    if(count == n){
      cout << -1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,sum = 0;
  cin >> n;
  vector<int> l(n);
  for (int i = 0; i < n; i++){
    cin >> l[i];
  }
  sort(l.begin(),l.end());
  for (int i = 0; i < n-1; i++){
    sum += l[i];
  }
  /*cout << sum << '\n';*/
  if (sum > l[n-1]){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }
  return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    long double D,T,S;
    cin >> D >> T >> S;
    Yes(D/S <= T);
}

Measured memory_bytes: 3716
# https://atcoder.jp/contests/abc081/tasks/arc086_a

import itertools
import collections
import bisect

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    C = collections.Counter(A)
    need_rewrite = max(0, len(C.keys()) - K)
    if need_rewrite:
        ans = 0
        for kv in C.most_common()[-need_rewrite:]:
            ans += kv[1]
        print(ans)
    else:
        print(0)


if __name__ == '__main__':
    main()


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

class Combination {
public:
    Combination(int64_t max_num, int64_t mod) {
        fact_.resize(max_num + 1, 1);
        inv_fact_.resize(max_num + 1, 1);
        mod_ = mod;
        for (int64_t i = 2; i <= max_num; i++) {
            fact_[i] = i * fact_[i - 1] % mod_;
            inv_fact_[i] = MODpow(fact_[i], mod_ - 2);
            assert(fact_[i] * inv_fact_[i] % mod_ == 1);
        }
    }
    int64_t operator()(int64_t n, int64_t m) const {
        if (m < 0 || m > n) return 0;
        return fact_[n] * inv_fact_[n - m] % mod_ * inv_fact_[m] % mod_;
    }
private:
    int64_t MODpow(int64_t n, int64_t m) const {
        int64_t result = 1;
        while (m) {
            if (m % 2 == 1) {
                result *= n;
                result %= mod_;
            }

            m /= 2;
            n *= n;
            n %= mod_;
        }

        return result;
    }

    vector<int64_t> fact_, inv_fact_;
    int64_t mod_;
};

int main() {
    int64_t N, K;
    cin >> N >> K;
    vector<int64_t> A(N);
    for (int64_t& a : A) {
        cin >> a;
    }

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

    constexpr int64_t MOD = 1e9 + 7;
    Combination comb(N, MOD);

    int64_t ans = 0;
    for (int64_t i = 0; i < N; i++) {
        //A[i]が最小値となる場合
        //自分より大きいN - 1 - i個からK - 1個選ぶ
        if (N - 1 - i >= K - 1) {
            int64_t num = comb(N - 1 - i, K - 1);
            (ans += MOD - num * A[i] % MOD) %= MOD;
        }

        //A[i]が最大値となる場合
        //自分より小さいi個からK - 1個選ぶ
        if (i >= K - 1) {
            int64_t num = comb(i, K - 1);
            (ans += num * A[i] % MOD) %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
N = int(input())
XY = [[int(_) for _ in input().split()] for _ in range(N)]
ans = -1
for dx, dy in ((1, 1), (-1, 1), (-1, -1), (1, -1)):
    xy2 = [x * dx + y * dy for x, y in XY]
    ans = max(ans, max(xy2) - min(xy2))
print(ans)


Measured memory_bytes: 58112