akhauriyash/Code-Regression huggingface dataset:
// Problem : B - Minor Change
// Contest : AtCoder - AtCoder Beginner Contest 172
// URL : https://atcoder.jp/contests/abc172/tasks/abc172_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<long,long> pl;
typedef pair<ll,ll> pll;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef vector<vl> vvl;
typedef vector<vb> vvb;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;

#define FOR(i,a,b) for(long long i=a;i<b;++i)
#define REV(i,a,b) for(long long i=a;i>=b;i--)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define tc ll tests;cin>>tests;while(tests--)
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define coutv(v) for(auto it: (v))cout<<it<<" ";newl;
#define cout2d(v) for(auto it: (v)) {for(auto j:it) cout<<j<<" ";newl;}
#define cinv(v,n) vll (v)(n);FOR(i,0,(n)){cin>>v[i];}
#define cinvg(v,n) (v).resize(n);FOR(i,0,(n)){cin>>v[i];}
#define cin2d(v,n,m) vvll (v)(n,vll(m,0));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define cin2dg(v,n,m) (v).resize(n,vll(m));FOR(i,0,n){FOR(j,0,m){cin>>v[i][j];}}
#define newl cout<<"\n"
#define mod 1000000007
#define INF 1e1

int main()
{
	io;
	string s,t;
	cin>>s>>t;
	ll n=s.size(),cnt=0;
	FOR(i,0,n)
	{
		if(s[i]!=t[i])
		{cnt++;}
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3884
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

vl v,w;
vvl dp(1024,vl(1e5+1,0));//頂点,コスト->価値のまっくす

ll bfs(ll V,ll W,ll c){
  if(W<0){
    return 0;
  }
  else if(V<=1023){
    return c+dp[V][W];
  }
  else{
    ll x=bfs(V/2,W,c);
    ll y=bfs(V/2,W-w[V],c+v[V]);
    return max(x,y);
  }
}

int main() {
  ll N;
  cin >> N;
  v.resize(N+1),w.resize(N+1);
  rep(i,N){
    cin >> v[i+1] >> w[i+1];
  }
  ll q;
  cin >> q;
  ll x;
  dp[1][w[1]]=v[1];
  FOR(i,1,min(N+1,(ll)1024)){
    rep(j,1e5+1){
      if(j==0||(i==1&&j==w[1])){
        continue;
      }
      if(j>=w[i]){
        dp[i][j]=max(dp[i/2][j],dp[i/2][j-w[i]]+v[i]);
      }
      else{
        dp[i][j]=dp[i/2][j];
      }
    }
  }
  rep(i,q){
    ll V,W;
    cin >> V >> W;
    x=bfs(V,W,0);
    cout << x << endl;
  }
}

Measured memory_bytes: 810168
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    string s, t; cin >> s >> t;
    if (s.size()+1 != t.size()) {
        cout << "No" << endl;
        return 0;
    }
    rep(i,s.size()) {
        if (s[i]!=t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

















Measured memory_bytes: 3596
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;


int bc(int v) {
    int ans = 0;
    for (; v > 0; v >>= 1) {
        ans += v & 1;
    }
    return ans;
}

string S;

map<int, int> w;

int main() {
    cin >> S;
    const int N = S.size();

    int p[202020];
    fill(p, p+N, 0);

    for (int j = 0; j < N; ++j) {
        p[j] |= (1 << (S[j] - 'a'));
        if (j > 0) p[j] ^= p[j-1];
    }

    int m[202020];
    for (int j = 0; j < N; ++j) m[j] = j+1;
    m[0] = 1;
    w[p[0]] = 0;
    for (int j = 1; j < N; ++j) {
        if (bc(p[j]) <= 1) {
            m[j] = 1;
        }

        int v = p[j];
        for (int k = 0; k < 26; ++k) {
            int x = v ^ (1 << k);
            if (w.find(x) != end(w)) {
                m[j] = min(m[j], m[w[x]] + 1);
            }
        }
        if (w.find(v) != end(w)) {
            m[j] = min(m[j], m[w[v]] + 1);
        }
        w[p[j]] = j;
    }
    cout << m[N-1] << endl;

    return 0;
}


Measured memory_bytes: 11388
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;

string s1, s2;
int n, m, dp[3002][3002];
stack<char> st;
//pair<int, string> dp[3002][3002];

int main()
{
    IOS
    cin >> s1 >> s2;
    n = s1.size();
    m = s2.size();
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            if (s1[i-1]==s2[j-1]) {
                dp[i][j] = dp[i-1][j-1]+1;
            } else {
                dp[i][j] = max(dp[i][j-1], dp[i-1][j]);
            }
        }
    }
    int i = n, j = m, idx = dp[n][m];
    while (i > 0 && j > 0) {
        if (s1[i-1]==s2[j-1]) {
            st.push(s1[i-1]);
            i--;
            j--;
            idx--;
        } else if (dp[i-1][j] > dp[i][j-1]) {
            i--;
        } else {
            j--;
        }
    }
    while (!st.empty()) {
        cout << st.top();
        st.pop();
    }
    cout << endl;


    return 0;
}


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

int main() {
	ll k,n;
	cin >> k >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,n-1) ans = max(ans, a[i+1]-a[i]);
	ans = max(ans, k-a[n-1]+a[0]);
	ans = k - ans;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define x real()
#define y imag()
using namespace std;
typedef complex<double> P;
typedef pair<int,int> Pi;
typedef pair<double,int> Pd;
typedef pair<Pd,Pi> S;

int n;
double r,d;
P p[20];
double dp[20][20][10001],ab[20][20];
int ck[20][20][20];
bool check(int a,int b,int c){
  if(b==c)return 0;
  if(a==b)return 1;
  P o=p[b]-p[a],s=p[c]-p[b];
  s*=conj(o);
  return real(s/abs(s))>=cos(M_PI*d/180);
}

int cal(){
  priority_queue<S,vector<S>,greater<S> > Q;
  int ans=0;
  for(int i=0;i<=r;i++)
    for(int j=0;j<n;j++)
      for(int k=0;k<n;k++)dp[j][k][i]=1e9;
  dp[0][0][0]=0;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++)ck[i][j][k]=check(i,j,k);
      ab[i][j]=abs(p[i]-p[j]);
    }
  Q.push(S(Pd(0,0),Pi(0,0)));
  while(!Q.empty()){
    double cs=Q.top().first.first;
    int i=Q.top().first.second;
    int j=Q.top().second.first;
    int k=Q.top().second.second;
    Q.pop();
    if(dp[j][k][i]<cs)continue;
    if(cs>r)return ans;
    for(int l=0;l<n;l++){
      double ncs=cs+ab[k][l];
      if(ck[j][k][l]&&ncs<=r){
	if(dp[k][l][i+1]>ncs){
	  Q.push(S(Pd(cs+ab[k][l],i+1),Pi(k,l)));
	  dp[k][l][i+1]=ncs;
	}
      }
    }
    ans=max(ans,i);
  }
  return ans;
}

int main(){
  cin>>n>>r>>d;
  double a,b;
  for(int i=0;i<n;i++)cin>>a>>b,p[i]=P(a,b);
  cout<<cal()<<endl;
  return 0;
}

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

int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    int a,b;
    cin>>a>>b;
    vector<int>v;
    for(int i=0;i<a;i++){
       int x;
       cin>>x;
       v.push_back(x);
    }
    int ans=1;
    int c=0;
    for(int i=0;i<a;i++){
        c=c+v[i];
        if(c<=b)ans++;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)

typedef long long ll;

int main(void) {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i,n) cin >> a[i];
    int ans = 0;
    REP(i,n){
        int mi = i;
        int j=i;
        while (j<n){
            if (a[j]<a[mi])
                mi=j;
            j++;
        }
        if (mi!=i){
            swap(a[i],a[mi]);
            ans++;
        }
    }
    REP(i,n){
        cout << a[i];
        if (i<n-1)
            cout << " ";
        else
            cout << endl;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1196
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class CSqrtInequality {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        lint a, b, c;
        in>>a>>b>>c;
        if(a+b>c) out<<"No\n";
        else{
            lint d = c - a - b;
            if(4*a*b<d*d) out<<"Yes\n";
            else out<<"No\n";
        }
    }
};


int main() {
	CSqrtInequality solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#define MP make_pair
using ll = long long;
using namespace std;

int main()
{
  ll X,Y;
  cin >> X >> Y;
  ll a = X;
  int i=1;
  for(;;){
    a = a*2;
    if(a > Y)
      break;
    i++;
  }
  cout << i << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define show(x) {for(auto i: x){cout << i << " ";} cout << endl;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  // 二分探索
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];
  sort(L.begin(), L.end());
  ll ans = 0;
  int right = 2;
  rep(i, N) {
    right = i+2;
    for (int j = i+1; j < N; j++) {
      int ab = L[i] + L[j];
      while (right < N && L[right] < ab) right++;
      ans += max(0, right - (j+1));
    }
  }
  cout << ans << '\n'; 
  return 0;
}

Measured memory_bytes: 3640
N = int(input())

s = []
for i in range(N):
    s.append(input())

M = int(input())

t = []
for i in range(M):
    t.append(input())

max_money = 0

for word in set(s):
    money = s.count(word) - t.count(word)
    if money > max_money:
        max_money = money

print(max_money)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

const int MAX_H = 100;
const int MAX_W = 8;

int mod = 1e9 + 7;
int H, W, K;
int dp[MAX_H + 5][MAX_W + 5];

bool is_valid_state(int bit) {
    for (int i = 0; i < W - 1; ++i) {
        int pattern = (1 << i) | (1 << (i + 1));
        if ((bit | pattern) == bit) {
            return false;
        }
    }

    return true;
}

void print_bit(int bit) {
    string s = "";
    rep(i, W - 1) {
        s += (bit & (1 << i)) ? '1' : '0';
    }
    reverse(all(s));
    cout << "0b" << s << endl;
}

signed main()
{
    cin >> H >> W >> K;

    dp[0][0] = 1;

    // 0 ~ H
    rep(i, H) {
        rep(j, W) {
            rep(mask, 1 << (W - 1)) {
                if (!is_valid_state(mask)) continue;
                bool flag = false;
                if (j - 1 >= 0 && (mask & (1 << (j - 1)))) {
                    flag = true;
                    dp[i+1][j] += dp[i][j - 1];
                    dp[i+1][j] %= mod;
                }
                if (j + 1 < W && (mask & (1 << j))) {
                    flag = true;
                    dp[i+1][j] += dp[i][j + 1];
                    dp[i+1][j] %= mod;
                }
                if (!flag) {
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= mod;
                }
            }
        }
    }

    cout << dp[H][K - 1] << endl;
}


Measured memory_bytes: 256
/*....Abhilash's coding template....*/
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define pb push_back
#define pob pop_back
#define mp make_pair
#define in insert
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define vll vector<ll>
#define fl(i,a,b) for(ll i=a;i<=b;i++)
#define flr(i,a,b) for(ll i=a;i>=b;i--)
#define print(v) for(auto i=v.begin();i!=v.end();i++){cout<<*i<<" ";}cout<<"\n";
#define tr(c,i) for(decltype((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define test() ll te; cin >> te; while(te--)
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define PI 3.14159265
#define MOD 1000000007
#define M 998244353
#define node pair<ll , pair<ll,ll> >
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);

int main()
{
    //test()
    {
    ll n,flag=0; cin>>n;
    vll v(n); fl(i,0,n-1) {cin>>v[i];if(v[i]==1)flag=1; }
    ll in=1;
    if(flag){
    fl(i,0,n-1)
    {
        if(v[i]==in)in++;
    }
    in--;
    cout<<n-in;
    }
    else cout<<-1;
}
}


Measured memory_bytes: 1792
import heapq
from collections import deque

N,M,X = map(int,input().split())
H = [0]
for i in range(N):
  H.append(int(input()))

adj_list = [ [] for _ in range(N+1)]
for _ in range(M):
  u,v,c = map(int,input().split())
  # adj_list[u].append((v,c))
  # adj_list[v].append((u,c))
  if H[u] >= c: adj_list[u].append((v,c))
  if H[v] >= c: adj_list[v].append((u,c))

INF = float('inf')
visited = [False] * (N+1)
costs = [INF] * (N+1)

# q=time,neighbor,cur_h
q = [(0,1,X)]
costs[1] = 0
last_position = 0
while q:
  cost,n,h = heapq.heappop(q)
  visited[n] = True
  if n == N: 
    last_position = h
    break

  for nei,nc in adj_list[n]:
    if visited[nei]: continue
    # p-nt < 0        => ntの高さまで上る
    # p-nt > H[nei]   => 最低限下りられるところまで
    #    　　　　　       もしも下りられなかったらFalse
    # 0 <= p-nt <= nt => 普通に飛び移れる
    if h-nc < 0:
      # import pdb; pdb.set_trace()
      climbUp = (nc-h)
      if climbUp > H[n]: continue
      nextCost = cost + climbUp + nc
      nextH = 0
    elif h-nc > H[nei]:
      # import pdb; pdb.set_trace()
      climbDown = (h-(H[nei]+nc))
      if climbDown < 0: continue
      nextCost = cost + climbDown + nc
      nextH = H[nei]
    else:
      nextCost = cost + nc
      nextH = h - nc
    
    if nextCost < costs[nei]:
      costs[nei] = nextCost
      heapq.heappush(q, (nextCost, nei, nextH))
    # print(q)

if costs[N] == INF:
  print(-1)
else:
  print(costs[N] + H[N]-last_position)



Measured memory_bytes: 87368
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#define int long long
#define ll long long
#define mod  1000000007
#define MOD  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
#define ps push_back
double pi = 3.141592653589793;
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
//ここから始めよう
using namespace std;
signed main(){
    int n,i;cin>>n>>i;
    cout<<n-i+1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define LL long long
#define maxn 200010
#define mod 1000000007
using namespace std;
int a[maxn];
LL ans=1,x,y;
int main()
{
    int n,k,i,l,r;
    scanf("%d%d",&n,&k);
    for(i=1; i<=n; i++)
        scanf("%d",&a[i]);
    sort(a+1,a+1+n);//从小到大排序
    if(a[1]>=0) //全是非负数,绝对值越大越好
    {
        for(i=n; i>=n-k+1; i--)
            ans=ans*a[i]%mod;
    }
    else if(a[n]<0)  //全是负数
    {
        if(k&1) //k是奇数,乘积结果是负数，要求绝对值越小越好
        {
            for(i=n; i>=n-k+1; i--)
                ans=ans*a[i]%mod;
            ans=(ans%mod+mod)%mod;
        }
        else  //k是偶数,乘积结果是正数，要求绝对值越大越好
        {
            for(i=1; i<=k; i++)
                ans=ans*a[i]%mod;
        }
    }
    else  //负数,0,正数交织在一起。a[n]>=0,a[1]<0
    {
        int cnt1=0,cnt2=0;
        for(i=1; i<=n; i++)
            if(a[i]<0)
                cnt1++;//负数个数
            else
                break;
        cnt2=n-cnt1;//正数与0的个数
        if(cnt1/2*2+cnt2<k) //乘积为负（就相当于差一个就是全部n个了）
        {
            for(i=1; i<=n; i++)
                ans=ans*a[i]%mod;
            ans=(ans%mod+mod)%mod;
        }
        else  //乘积为非负,要求绝对值最大
        {
            if(k&1)//k是奇数，得特殊处理一下，里面一定包含了非负最大值a[n]
                ans=a[n],n--,k--;
            l=1,r=n;//两个两个的选取
            while(k)
            {
                x=(LL)a[l]*a[l+1],y=(LL)a[r]*a[r-1];
                if(x>y)
                    x%=mod,ans=ans*x%mod,l+=2;
                else
                    y%=mod,ans=ans*y%mod,r-=2;
                k-=2;
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

#define ALL(x) begin (x), end (x)

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

  size_t n;
  cin >> n;

  vector <string> s (n);
  for (auto && elem : s)
  {
    cin >> elem;
    sort (ALL (elem));
  }
  sort (ALL (s));

  int64_t ans = 0;
  int64_t cnt = 0;
  string pre_s = "";
  for (auto && elem : s)
  {
    if (pre_s == elem)
    {
      ++ cnt;
    }
    else
    {
      ans += cnt * (cnt - 1) / 2;
      cnt = 1;
    }
    pre_s = elem;
  }
  ans += cnt * (cnt - 1) / 2;
  cout << ans << endl;
}



Measured memory_bytes: 5760
n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
left = 0
right = n
for i in T:
    while(left < right):
        if (i < S[left]) or (i > S[right-1]): break
        mid = int((left+right)/2)
        if S[mid] == i:
            cnt +=1
            break
        elif S[mid] > i: right = mid
        else: left = mid
    left = 0
    right = n

print(cnt)


Measured memory_bytes: 16712
def main():
    N = int(input())
    S = input()
    ec = S.count('E')
    wc = 0
    min = ec
    for k in S:
        if k == 'E':
            ec -= 1
        else:
            wc += 1
        if min > ec + wc: min = ec + wc
    print(min)

if __name__ == '__main__':
    main()

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    int n;cin>>n;
    cout<<3*n*n<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;

signed main(){
    int k,n;
    cin>>k>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int cost=0,ans=0;
    for(int i=1;i<n;i++){
        cost=max(cost,a[i]-a[i-1]);
        ans+=a[i]-a[i-1];
    }

    ans=min(ans,a[0]+k-a[n-1]+ans-cost);
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

using namespace std;

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

	vector<int> L(2 * N);
	for (auto& li : L)
		cin >> li;

	int cnt = 0;
	while (L.size() > 0)
	{
		auto maxIt = max_element(L.begin(), L.end());
		L.erase(maxIt);
		auto secondIt = max_element(L.begin(), L.end());
		cnt += *secondIt;
		L.erase(secondIt);
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

// vectorの重複削除
// std::sort(test.begin(), test.end());
// test.erase(std::unique(test.begin(), test.end()), test.end());

using namespace std;
using ll = long long;
using P = pair<int, int>; // vector<P> ba(n); みたいな感じですぐ使える ba[i] = P(a, b); make_pairをしなくてもいい
// typedef vector<int> v;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}
#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(x) (x).begin(), (x).end() //sort(ALL(obj))みたいな
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値
#define pb push_back //
// const int MOD = 1000000007;
// string alpha="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// printf("%.20f\n", ans); あれ
// const double PI = 3.141592653589793238462643383;

int main() {
  //std::vector<int> v(5);
  string s; cin>>s;
  string acgt = "ACGT";
  int cnt = 0;
  int max_cnt = 0;
  rep(i, s.size()) {
    bool flag = true;
    int ii = i;
    cnt = 0;
    while (flag) {
      if (ii <= s.size()-1) {
        if (acgt.find(s[ii]) != std::string::npos) {
          cnt++;
          ii++;
        } else {
          flag = false;
          if (max_cnt < cnt) max_cnt = cnt;
        }
      } else {
          if (max_cnt < cnt) max_cnt = cnt;
          flag = false;
        }
    }
  }
  cout << max_cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <map>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define PB push_back
#define MP make_pair
int n,s,ans;
void rec(int a,int b,int sum){
  if(sum==s&&b==0){
    ans++;
    return;
  }
  if(a>=10||b<=0)return;
  rec(a+1,b,sum);
  rec(a+1,b-1,sum+a);
}
int main(){
  while(cin>>n>>s){
    if(n==0&&s==0)break;
    ans=0;
    rec(0,n,0);
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

typedef bitset<50000> bs;

int main(){
	cin.sync_with_stdio(0);
	cin.tie(0);

	int n, m, t;
	cin >> n >> m >> t;

	vi x(m), y(m);
	rep(i,0,m) cin >> x[i] >> y[i];
	trav(xx, x) --xx;
	trav(xx, y) --xx;

	if(t == 2){
		if(n == 2){
			cout << -1 << endl;
			return 0;
		} else {
			vector<stack<int>> ss(n);
			rep(i,0,n) ss[i].push(-1);
			rrep(i,0,m){
				ss[x[i]].push(y[i]);
				ss[y[i]].push(x[i]);
			}
			int a = 0;
			int b = ss[a].top() == 1 ? 2 : 1;
			string ans;
			rep(i,0,m){
				ss[x[i]].pop();
				ss[y[i]].pop();
				if(x[i] == a || x[i] == b){
					if(x[i] == b) swap(a,b);
					if(ss[b].top() == a){
						ans.push_back('v');
						a = y[i];	
					} else {
						ans.push_back('^');	
					}
				} else if(y[i] == a || y[i] == b){
					if(y[i] == b) swap(a,b);
					if(ss[b].top() == a){
						ans.push_back('^');
						a = x[i];	
					} else {
						ans.push_back('v');	
					}
				} else {
					ans.push_back('v');
				}
			}
			cout << ans << endl;
			return 0;
		}
	}

	vector<bs> cover(n, 0);
	rep(i,0,n) cover[i].set(i);

	rep(i,0,m){
		cover[x[i]] = cover[y[i]] |= cover[x[i]];
	}
	
	rep(i,0,n){
		if(int(cover[i].count()) == n){
			string ans(m, 'v');
			bs good(0);
			good.set(i);
			rrep(i,0,m){
				if(good[x[i]]){
					good.set(y[i]);
					ans[i] = '^';
				} else if(good[y[i]]){
					good.set(x[i]);
					ans[i] = 'v';
				}
			}
			cout << ans << endl;
			return 0;
		}
	}
	cout << "-1" << endl;
}


Measured memory_bytes: 306688
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define INF 1000000000
#define MOD 1000000007LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)
 
#define MN 12
int k;
int dp[MN][MN][MN];
int sm[MN][MN];
int calc(int st, int nd){
    //memset(dp, 0, sizeof dp);
    //cout << "doing " << st << " " << nd << "\n";
    dp[1][st][st] = 1;
    FOR(i, 2, nd){
        F0R(d, 10){
            if(d != 0) dp[i][st][d] += dp[i-1][st][d-1];
            dp[i][st][d] += dp[i-1][st][d];
            if(d != 9) dp[i][st][d] += dp[i-1][st][d+1];
        }
    }
    FOR(i, 1, nd){
        F0R(j, 10){
            //cout << dp[i][st][j] << " ";
            sm[i][st] += dp[i][st][j];
        }
        //cout << "\n";
    }
}
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> k; --k;
    F0R(j, 10){
        calc(j, 10);
    }
    /*FOR(i, 1, 10){
        F0R(j, 10){
            cout << sm[i][j] << " ";
        }
        cout << "\n";
    }*/
    int nd = 1;
    int std = -1;
    while(nd != 0){
        bool ok = false;
        F0R(i, 10){
            if(std == -1 && i == 0) continue;
            else if(std != -1 && abs(std-i)>1) continue;
            if(sm[nd][i] > k){
                cout << i;
                //cout << "pairing " << i << "\n";
                --nd;
                ok = true;
                std = i;
                break;
            } else{
                k -= sm[nd][i];
            }
        }
        if(!ok){ ++nd; }
        //cout << "now k " << k << "\n";
    }
 
    return 0;
}

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

void chmax(int64_t& a, int64_t b){
    a = max(a, b);
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N;
    int64_t K;
    cin >> N >> K;
    vector<int> P(N);
    for(int i=0; i<N; i++) cin >> P[i], P[i]--;
    vector<int64_t> C(N);
    for(int i=0; i<N; i++) cin >> C[i];

    static int64_t dub[30][5000], nxt[30][5000];
    for(int i=0; i<N; i++){
        dub[0][i] = C[P[i]];
        nxt[0][i] = P[i];
    }
    for(int k=1; k<30; k++){
        for(int i=0; i<N; i++){
            dub[k][i] = dub[k-1][i] + dub[k-1][nxt[k-1][i]];
            nxt[k][i] = nxt[k-1][nxt[k-1][i]];
        }
    }

    // k桁目まで、頂点iにいる、K未満確定、正
    static int64_t dp[31][5000][2][2];
    for(int k=30; k>=0; k--) for(int i=0; i<N; i++) for(int l=0; l<2; l++) for(int p=0; p<2; p++) dp[k][i][l][p] = -5e18;
    for(int i=0; i<N; i++) dp[30][i][0][0] = 0;

    for(int k=29; k>=0; k--) for(int i=0; i<N; i++) for(int l=0; l<2; l++) for(int p=0; p<2; p++){
        int64_t v = dp[k+1][i][l][p];
        for(int u=0; u<2; u++){
            if(!l && !nth_bit(K, k) && u) continue;
            int64_t v2 = v + (u ? dub[k][i] : 0);
            int i2 = (u ? nxt[k][i] : i);
            int l2 = l | (nth_bit(K, k) && !u);
            int p2 = p | u;
            chmax(dp[k][i2][l2][p2], v2);
        }
    }

    int64_t ans = -5e18;
    for(int i=0; i<N; i++) for(int l=0; l<2; l++) chmax(ans, dp[0][i][l][1]);
    cout << ans << endl;
    return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    s = (">"+s+"<");
    vector<ll> indexes;
    vector<ll> res(s.size()+1, 0);
    for(ll i=1; i < s.size(); i++)
    {
        if(s[i-1] == '>' && s[i] == '<')
            indexes.push_back(i);
    }
    for(auto i : indexes)
    {
        ll j = i-1;
        while(j >= 0 && s[j] == '>')
        {
            res[j] = max(res[j],res[j+1]+1);
            j--;
        }
        j = i+1;
        while(j <= s.size() && s[j-1] == '<')
        {
            res[j] = max(res[j],res[j-1]+1);
            j++;
        }
    }
    ll res_ = 0;
    for(int i = 1; i < s.size(); i++)
    {
        res_ += res[i];
    }
    cout << res_ << endl;
    return 0;
}

Measured memory_bytes: 6704
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

const int W = 201;

int main(void) {
  int n;
  cin >> n;
  VI t(n), v(n);
  int tot = 0;
  REP(i, 0, n) {
    cin >> t[i];
    t[i] *= 2;
    tot += t[i];
  }
  VI limit(tot);
  int cur = 0;
  REP(i, 0, n) {
    cin >> v[i];
    v[i] *= 2;
    REP(j, cur, cur + t[i]) {
      limit[j] = v[i];
    }
    cur += t[i];
  }
  vector<VL> dp(tot + 1, VL(W, -1));
  dp[0][0] = 0;
  REP(i, 0, tot) {
    REP(j, 0, limit[i] + 1) {
      if (dp[i][j] >= 0)
	dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 2 * j);
      if (j >= 1) {
	if (dp[i][j - 1] >= 0)
	  dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - 1] + 2 * j - 1);
      }
      if (j < limit[i]) {
	if (dp[i][j + 1] >= 0)
	  dp[i + 1][j] = max(dp[i + 1][j], dp[i][j + 1] + 2 * j + 1);
      }
    }
  }
  cout << setprecision(17) << dp[tot][0] / 8.0 << "\n";
}


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

int main() {
  int h, w, k;
  cin >> h >> w >> k;
  char c[h][w];
  for ( int i = 0; i < h; i++ ) {
    for ( int j = 0; j < w; j++ ) {
      cin >> c[i][j];
    }
  }

  int ans = 0;
  for ( int bit_h = 0; bit_h < (1<<h); bit_h++ ) {
    for ( int bit_w = 0; bit_w < (1<<w); bit_w++ ) {
      int b = 0;
      for ( int i = 0; i < h; i++ ) {
        for ( int j = 0; j < w; j++ ) {
          if ( bit_h & (1<<i) && bit_w & (1<<j) ) {
            if ( c[i][j] == '#' ) { b++; }
          }
        }
      }
      if ( b == k ) { ans++; }
    }
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
;; #!/usr/bin/env sbcl --script

(define-alien-routine getchar_unlocked char)

(declaim (optimize (speed 3) (safety 0) (debug 0)))
(declaim (inline getchar_unlocked))

(deftype uint8 () '(unsigned-byte 8))
(deftype int32 () '(signed-byte 32))

;; (declaim (type fixnum *ptr* *len*)
;;          (type (vector uint8 4096) *buf*))

;; (defvar *buf* (make-array 4096 :element-type 'uint8 :initial-element 0))
;; (defvar *ptr* (the fixnum 0))
;; (defvar *len* (the fixnum -1))
;; 
;; (defun refresh-buf ()
;;   (setf *len* (the fixnum (read-sequence *buf* *standard-input*)))
;;   (setf *ptr* (the fixnum 0)))
;; 
;; (declaim (ftype (function () uint8) my-read-char))
;; (defun my-read-char ()
;;   (when (>= *ptr* *len*) (refresh-buf))
;;   (if (>= *ptr* *len*)
;;       0
;;       (progn (incf *ptr*)
;;              (aref *buf* (1- *ptr*))))

(declaim (ftype (function () int32) my-read-int))
(defun my-read-int ()
  (let ((is-negative nil)
        (result 0))
    (declare (type int32 result))
    (loop for cur-char = (getchar_unlocked) then (getchar_unlocked)
       while (and (/= cur-char (char-code #\-))
                  (/= 0)
                  (or (< cur-char 48)
                      (> cur-char 57)))
       finally (if (<= 48 cur-char 57)
                   (setf result (- cur-char 48))
                   (setf is-negative t)))
    (loop for cur-char = (getchar_unlocked) then (getchar_unlocked)
       while (<= 48 cur-char 57)
       do (setf result (+ (* result 10) (- cur-char 48))))
    (when is-negative (setf result (- result)))
    result))

(defun main ()
  (let* ((n (my-read-int))
         (k (my-read-int))
         (a (make-array n :element-type 'int32))
         (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
    (dotimes (i n)
      (setf (aref a i) (my-read-int)))
    (setf (aref dp 0) 0)
    (loop for i of-type int32 from 0 below n do
      (loop with from-val of-type int32 = (aref dp i)
         for j of-type int32 from (1+ i) to (+ i k)
         while (< j n)
         for nval of-type int32 = (+ from-val (abs (- (aref a i) (aref a j))))
         if (< nval (aref dp j))
         do
           (setf (aref dp j) nval)))
    (format t "~a~%" (aref dp (- n 1)))))

(main)

;; (defun main2 ()
;;   (let* ((n (the int32 (read)))
;;          (k (the int32 (read)))
;;          (a (make-array n :element-type 'int32))
;;          (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
;;     (let ((stream (make-string-input-stream (read-line))))
;;       (loop for i from 0
;;          for j = (read stream nil) until (null j)
;;          do (setf (aref a i) (the int32 j)))
;;     (setf (aref dp 0) 0)
;;     (loop for i of-type int32 from 0 below n do
;;       (loop with from-val of-type int32 = (aref dp i)
;;          for j of-type int32 from (1+ i) to (+ i k)
;;          while (< j n)
;;          do
;;            (let ((nval (the int32 (+ from-val (abs (- (aref a i) (aref a j)))))))
;;              (setf (aref dp j) (min (aref dp j) nval)))
;;     (format t "~a~%" (aref dp (- n 1)))))



Measured memory_bytes: 8800
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {

	int K;
	scanf("%d", &K);

	if (K % 2 == 0) {
		printf("%d", K*K / 4);
	}
	else {
		printf("%d", (K - 1) / 2 * (K + 1) / 2);
	}



}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
#include <stack>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<vector<int>>
#define mii map<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define ALL(a)  (a).begin(),(a).end()

typedef long long ll;

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}

int gcd(int x, int y){
    if(x<y) swap(x,y);
    
    if(y == 0) return x;
    
    return gcd(y,x%y);
}

int main(){
    int n; cin >> n;
    
    vi x(n+1);
    rep(i,n+1) cin >> x[i];
    
    
    if(n == 1) {
        cout << abs(x[0]-x[1]) << endl;
        return 0;
    }
    
    
    Sort(x);
    
    int d[n+1];
    rep(i,n){
        d[i] = x[i+1]-x[i];
    }
    
    int g[n-1];
    rep(i,n-1){
        g[i] =gcd(d[i],d[i+1]);
    }
    
    sort(g,g+n-1);
    
    cout << g[0] << endl;
}






Measured memory_bytes: 1408
S = input()
dp = [[0 for j in range(13)]for i in range(10**5+1)]
dp[0][0] = 1
for i in range(len(S)):
    c = 0
    if S[i] == '?':
        c = -1
    else:
        c = int(S[i])

    for j in range(10):
        if c != -1 and c!= j:
            continue
        for ki in range(13):
            dp[i+1][(ki*10+j)%13] += dp[i][ki]
    for j in range(13):
        dp[i+1][j] %= 10**9+7
    
print(dp[len(S)][5])

Measured memory_bytes: 66780
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
typedef long long int ll; 
typedef long double ld; 

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

    ll s = 0;

    for(ll i=0;i<m;i++)
    {
        ll x;
        cin>>x;
        s+=x;
    }
    
    if(s>n)
    {
        cout<<-1<<endl;
    }
    else{
        cout<<(n-s)<<endl;
    }
        
}

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

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int partition(int *a, int lo, int hi)
{
	int i, j, x, t;

	x = a[hi], i = lo-1;
	for (j = lo; j < hi; j++) {
		if (a[j] <= x) i++, t = a[i], a[i] = a[j], a[j] = t;
	}
	t = a[++i], a[i] = a[hi], a[hi] = t;
	return i;
}

int a[100002];

int main()
{
	int n, i, k;
	
	n = in(); for (i = 0; i < n; i++) a[i] = in();
	k = partition(a, 0, n-1);
	printf((!k? "[%d]": "%d"), a[0]);
	for (i = 1; i < n; i++) {
		putchar(' ');
		printf((k==i? "[%d]": "%d"), a[i]);
	}
	putchar('\n');
	return 0;
}



Measured memory_bytes: 2088
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define all(x) (x).begin(),(x).end()
#define matrix vector<vector<ll>>
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const int inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf + 7;
const ll mod2 = inf + 9;
const int MAXN = 1000005;
const ld EPS = 1e-11;
int hp = 179;

signed main()
{
	fastio();
	string s, t;
	cin >> s >> t;
	map<char, int> fs;
	map<char, int> ss;
	for (int i = 0; i < s.size(); ++i)
	{
		fs[s[i]] ++;
		ss[t[i]]++;
	}
	vector<int> fss;
	vector<int> sss;
	for (auto i : fs)
	{
		fss.pbc(i.second);
	}
	for (auto i : ss)
	{
		sss.pbc(i.second);
	}
	sort(all(fss));
	sort(all(sss));
	if (fss != sss)
	{
		cout << "No";
	}
	else
	{
		cout << "Yes";
	}
}

Measured memory_bytes: 916
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head = 0, tail = 0, n;
int totalt = 0;

int isEmpty(){
  if(head == tail)
    return 1;
  else return 0;
}

int isFull(){
  if(head == (tail+1)%LEN)
    return 1;
  else return 0;
}

void enqueue(P x){
  if(isFull() == 1)
    printf("Fullerror\n");
  Q[tail] = x;
  if(tail+1 == LEN)
    tail = 0;
  else
    tail++;
}

P dequeue(){
  P x;
  if(isEmpty() == 1)
    printf("Emptyerror\n");
    x = Q[head];
    if(head+1 == LEN)
      head = 0;
    else
      head++;
    return x;
  
}


int main(){
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;
  while(isEmpty() != 1){
    u = dequeue();
    if(u.t > q){
      totalt += q;
      u.t -= q;
      enqueue(u);
    }
    else{
      totalt += u.t;
      u.t = 0;
      printf("%s %d\n", u.name, totalt);
    }
  }


  return 0;
}

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

#if defined(DEBUG)

#include <unistd.h>
#include <sys/fcntl.h>
#define DLOG(...)        cerr << dbgFormat(__VA_ARGS__) << endl
#define DCALL(func, ...) func(__VA_ARGS__)

template <class... Args>
string dbgFormat(const char* fmt, Args... args) {
  size_t len = snprintf(nullptr, 0, fmt, args...);
  char buf[len + 1];
  snprintf(buf, len + 1, fmt, args...);
  return string(buf);
}

#else  // defined(DEBUG)

#define DLOG(...)
#define DCALL(func, ...)

#endif // defined(DEBUG)
// ----------------------------------------------------------------------

// ----------------------------------------------------------------------
int main(int argc, char *argv[]) {
#if defined(DEBUG)
  // GDB on Cygwin ignores redirection at run command.
  if (argc == 2) dup2(open(argv[1], 0), 0);
#else
  // For performance.  We should not use C-style stdio functions
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
#endif
  cout << setprecision(20);

  ll N, K; cin >> N >> K;
  vector<ll> A(N), F(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> F.at(i);
  sort(A.begin(), A.end(), greater<ll>());
  sort(F.begin(), F.end());
  
  ll lo = -1;
  ll hi = (ll)(1e12) + 10;
  while (lo + 1 < hi) {
    ll mid = (lo + hi) / 2;
    ll s = 0;
    for (int i = 0; i < N; i++) {
      ll g = mid / F.at(i);
      if (A.at(i) > g) s += A.at(i) - g;
    }
    if (s <= K) {
      hi = mid;
    }else {
      lo = mid;
    }
  }
  cout << hi << endl;
  return 0;
}



Measured memory_bytes: 3456
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
ll MOD=1000000007;
int main(){
  ll n,t;
  cin >> n >> t;
  ll i,j,k;
  vector<ll> v,a;
  for(i=0;i<n;i++){
    cin >> k;
    v.push_back(k);
  }
  sort(v.begin(),v.end());
  ll ans=1;
  for(i=0;i<n;i++){
    //cout << ans << endl;
    a.push_back(v[i]);
    ans*=(i-distance(a.begin(),lower_bound(a.begin(),a.end(),v[i]-t))+1)%MOD;
    ans%=MOD;
  }
  cout << ans % MOD << endl;
  return 0;
}

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

int main() {
    bool C = false, F = false;
    string S;
    cin >> S;
    for (char ch : S) {
        if (!C) {
            if (ch == 'C') C = true;
        } else if (!F) {
            if (ch == 'F') F = true;
        } else {
            // do nothing
        }
    }
    if (C && F)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
from __future__ import division, print_function
from sys import stdin, exit
from collections import defaultdict


def main():
    index = defaultdict(list)

    for line in stdin:
        word, page = line.split()
        index[word].append(int(page))

    for word in sorted(index):
        print(word)
        print(*sorted(index[word]))
    exit()


if __name__ == '__main__':
    main()

Measured memory_bytes: 4608
N = int(input())
tasks = []
for i in range(N):
    A, B = [int(x) for x in input().split()]
    tasks.append([B, A])
tasks.sort()

ok = True
S = 0
for i in range(N):
    B, A = tasks[i][0], tasks[i][1]
    S += A
    if S > B:
        ok = False
        break

if ok == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 105128
from collections import defaultdict
import sys
input = sys.stdin.readline

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd (a, b)

def main():
    num = int(input())
    data = [list(map(int, input().split())) for i in range(num)]
    data.sort(key=lambda x: x[1])
    now_time = 0

    flg = 1
    for i in range(num):
        if now_time + data[i][0] <= data[i][1]:
            now_time += data[i][0]
        else:
            flg = 0
            break
    if flg:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()



Measured memory_bytes: 83164