akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;



map<pair<int,int>, bool> dp;
bool solve(int a, int b) {
        if (a < 0) return false;
        if (a == 0) return !b;
        if (dp.count({a, b})) return dp[{a, b}];
        return dp[{a, b}] = solve(a - 1, b - 2) || solve(a - 1, b - 4);
}


void _main() {
        int x, y; cin >> x>> y;
        cout << (solve(x, y) ? "Yes" : "No") << '\n';
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

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

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    int s[] = {a, b, c};
    sort(s, s+3);
    cout << (s[2] * 10 + s[1] + s[0]) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int dfs(int n, int s, int x){
  int sum=0;
  if(n==0 && s==0)    return 1;
  if(n>0){
      for(int i=x; i<10; i++){
          if(s-i>=0)  sum+=dfs(n-1, s-i, i+1);
      }
  }
  return sum;
}

int main(void){
  int n, s;
  while(scanf("%d %d",&n,&s)!= EOF){
      if(n==0 && s==0)    break;
      printf("%d\n",dfs(n, s, 0));
  }
  return 0;
}


Measured memory_bytes: 2044
import sys

# 関数 solve は，もちろん，問題に応じて書き換える
def solve(x,y):
    return x+y//2
    
# ここから下は，入力・出力形式が同じであれば，変えなくて良い．
def readQuestion():
    line = sys.stdin.readline().rstrip()
    [str_a, str_b] = line.split(' ')
    return (int(str_a), int(str_b))

def main():
    a, b = readQuestion()
    answer = solve(a, b)
    print(answer)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define pragi(a,b) for(ll i = a;i<b;i++)
#define pragj(a,b) for(ll j = a;j<b;j++)
#define pragk(a,b) for(ll k = a;k>=b;k--)
#define all(v) (v.begin(),v.end())
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define KAKA ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
const int mod = 1e9 + 7;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef long double ld;
typedef pair<int, int> pii;
//typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;

void Compute(ll h)
{
    KAKA
    ll sum = 0;
    ll level = 1;
    while(h > 0)
    {
        sum+=level;
        h/=2;
        level*=2;
    }
    cout<<sum<<"\n";
}
int main()
{
    KAKA
    ll h;
    cin>>h;
    Compute(h);
}

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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)41000;
int N, fact[9];


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    fact[0] = 1;
    for(int i=1; i<=8; i++)
    {
        fact[i] = i*fact[i-1];
    }
    int ans1 = 0, ans2 = 0;
    int x;
    vector<int> s1, s2;
    for(int i=1; i<=8; i++)
    {
        s1.PB(i);
        s2.PB(i);
    }
    for(int i=1; i<=N; i++)
    {
        cin >> x;
        int pos = find(s1.begin(), s1.end(), x) - s1.begin();
        ans1 += (pos-1)*fact[N-i];
        s1.erase(find(s1.begin(), s1.end(), x));
    }

    for(int i=1; i<=N; i++)
    {
        cin >> x;
        int pos = find(s2.begin(), s2.end(), x) - s2.begin();
        ans2 += (pos-1)*fact[N-i];
        s2.erase(find(s2.begin(), s2.end(), x));
    }
    cout << abs(ans1-ans2);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long 
using namespace std;
typedef pair<int,int> ii;


signed main(){
	//freopen("i.txt","r",stdin);
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int a, b; cin >>a  >> b; cout << a*b;
	
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::cin >> N;
  std::set<std::string> s;
  for(int i = 0; i < N; ++i) {
    std::string S; std::cin >> S;
    s.insert(S);
  }
  fin(s.size());
  return 0;
}


Measured memory_bytes: 19256
<?php
while ($line = fgets(STDIN)) {
    $line = rtrim($line);
    $data = explode(" ", $line);
    
    if ($data[2] < 0 || $data[3] < 0) {
        echo "No" . PHP_EOL;
    } else {
        if ($data[2] + $data[4] <= $data[0] && $data[3] + $data[4] <= $data[1]) {
            echo "Yes" . PHP_EOL;
        } else {
            echo "No" . PHP_EOL;
        }
    }
}



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

struct data{
    char name;
    int sell;
    data(char n, int s) : name(n), sell(s) {}
    bool operator<(const data other) const{
        return sell < other.sell;
    }
};

int main(){
    while(1){
        int a, b;
        cin >> a >> b;
        if(a + b == 0)  break;

        vector<data> res;
        res.push_back(data('A', a+b));

        for(int i = 1; i < 5; i++){
            cin >> a >> b;
            res.push_back(data((char)('A'+i), a+b));
        }

        sort(res.rbegin(), res.rend());

        cout << res[0].name << " " << res[0].sell << endl;
    }
    return 0;
}


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

int main() {
	
	string s;
	cin>>s;
	long long sum = 0;
	
	for(int i = s.size()-1; i >= 0; i--)
	{
		sum+=((long long)s[i]-48);
	}
	
	if(sum % 9 == 0)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 3652
#define _CRT_SECURE_NO_WARNINGS  
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include<string>
#include <math.h>
#include<vector>
#include <math.h>
#include <map>
#include <functional>
using namespace std;


int main() {
	int a[10] = { 0 };
	for (int i = 0; i < 3; i++) {
		int t;
		cin >> t;
		a[t]++;
	}
	if (a[5] == 2 && a[7] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 256
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>

#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) //[l, r)
#define rep(i,n) REP(i,0,n)           //[0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showslr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl //[l, r)

#define yes puts("Yes")
#define no puts("No")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

inline void io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}

void _DEBUG(){cerr<<endl;}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<",";_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<endl;out(b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;

int n;

vi vec;
map<int,int> a,b;
int ans=0;

signed main(){
    io();
    in(n);
    vec.resize(n);
    rep(i,n) in(vec[i]);

    rep(i,n){
        if(i&1){
            a[vec[i]]++;
        }else{
            b[vec[i]]++;
        }
    }
    int maxa=-1;
    int nexta=0;
    int val;
    for(auto e:a){
        if(maxa<e.second){
            nexta=max(nexta,maxa);
            maxa=e.second;
            val=e.first;
        }else if(nexta<e.second){
            nexta=e.second;
        }
    }
    int maxb=-1;
    int nextb=0;
    int var;
    for(auto e:b){
        if(maxb<e.second){
            nextb=max(nextb,maxb);
            maxb=e.second;
            var=e.first;
        }else if(nextb<e.second){
            nextb=e.second;
        }
    }
    //show(maxa,maxb,nexta,nextb);
    //show(val,var);
    if(val!=var){
        ans=n/2-maxa+n/2-maxb;
    }else{
        int resa=n/2-maxb+n/2-nexta;
        int resb=n/2-maxa+n/2-nextb;
        //show(resa,resb);
        ans=min(resa,resb);
    }
    out(ans);

    return 0;
}


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

int main() {
  int H, W; cin >> H >> W;
  int c[10][10];
  int dist[10][10];
  for(int i = 0; i < 10; ++i) {
    for(int j = 0; j < 10; ++j) {
      cin >> c[i][j];
      dist[i][j] = c[i][j];
    }
  }
  int A[H][W];
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> A[i][j];
    }
  }
  for(int k = 0; k < 10; ++k) {
    for(int i = 0; i < 10; ++i) {
      for(int j = 0; j < 10; ++j) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      if(A[i][j] == -1) continue;
      ans += dist[A[i][j]][1];
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
//#define fi first
//#define se second
#define be begin()
#define en end()
#define reverse
const int mod=1000000007;
const int INFi=2147483647;
const long long INFl=9223372036854775807LL;
template<typename T> T abs(T a,T b){
  return max(a,b)-min(a,b);
}
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      cout<<"No\n";
      return 0;
    }
  }
  cout<<"Yes\n";
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair

#define REP(i, n) for(int i=0;i<(int)(n);++i)
#define FOR(i,l,h) for(int i=(int)(l);i<=(int)(h);++i)
#define FORD(i,h,l) for(int i=(int)(h);i>=(int)(l);--i)

#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

#define dump(x)  cerr << #x << " = " << (x) << endl
#define ALL(t) (t).begin(),(t).end()

using namespace std;


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

        ll int n,m;
        cin>>n>>m;
        string s;
        map< int, int> mp;
        set<int>st;
        ll int cac = 0 , cwa = 0, a;
        for (size_t i = 0; i < m; i++) {
            cin>>a>>s;
            st.insert(a);
            if(mp[a] <= 0){
                if(s == "AC"){
                    mp[a] = 1;
                    cac++;
                }
                else if(s == "WA"){
                    //neg--;
                    mp[a]--;
                    cwa++;
                }
            }

        }
        set<int>:: iterator it;
        for (it = st.begin(); it != st.end(); ++it)
       {
         int val = *it;
        // dump(val);
          if( mp[val] != 1){
              //dump(mp[val]);
              cwa = cwa + mp[val];
          }
       }
        cout<<cac<<" "<<cwa<<"\n";
        return 0;
    }


Measured memory_bytes: 9600
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    ll h[n];
    for (auto &hi:h) cin >> hi;
    sort(h, h+n, greater<ll>());
    ll ans = 0;
    for (int i=k; i<n; i++) {
        ans += h[i];
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int main() {
    int N; cin >> N;
    string S, T; cin >> S >> T;
    for (int i = 0; i < N; i++) {
        cout << S[i] << T[i];
    }
    cout << endl;
    return 0;
}


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

/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define isin(a, b, c) (b <= a && a <= c)
#define println cout << "\n";
#define sz(v) (int)v.size()
#define bin(x) static_cast<bitset<16> >(x)


/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef tuple<int, int, int> ti;
typedef map<int, int> mi;
typedef set<int> si;


/* constant */
const int inf = 1LL << 62;
const int mod = 1e9 + 7;
const int dx[8]={1,0,-1,0,-1,1,-1,1};
const int dy[8]={0,1,0,-1,-1,-1,1,1};
const string alphabet = "abcdefghijklmnopqrstuvwxyz";

/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T, class U, class V> void printx(tuple<T, U, V> t){cout << "{" << get<0>(t) << "," << get<1>(t) <<"," << get<2>(t) << "}" << endl;}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}
template<class T> void printans(vec<T> v){rep(i,0,sz(v)){cout << v[i] << (i == sz(v) - 1 ? "" : " ");}cout << endl;}


/* general_method */
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>T cut(T &a, int l, int r){return T(a.begin()+l, a.begin()+r);}


/* math_method */
int ceil(int a, int b){return a / b + (a % b > 0);}


/* main */

int n;
string t;
void in(){
cin >> n >> t;
}

void solve(){

    int r = 0; int b = 0;
    rep(i,0,n){
        if(t[i] == 'R'){
            r++;
        }else{
            b++;
        }
    }

    if(r > b){
        print("Yes");
    }else{
        print("No");
    }
}

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);
    in();
    solve();
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define flb(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define mp make_pair
#define pb push_back
#define inf (long long)(1e18+1e15)
typedef pair<int,int> ii;
typedef vector <ll> vi;
typedef vector <pair<int,int> > vii;
typedef vector <vector <int> > vvi;
int calculated[3001][3001];
string s,t;
int n,m;
int solve(int i,int j)
{
    if(i==n||j==m)
        return 0;
    if(calculated[i][j]!=-1)
        return calculated[i][j];
    if(s[i]==t[j])
    {
        calculated[i][j]=1+solve(i+1,j+1);
    }
    else
    {
        calculated[i][j]=max(solve(i+1,j),solve(i,j+1));
    }
    return calculated[i][j];
}
int main()
{
    cin>>s>>t;
    n=s.size();
    m=t.size();
    int ans=0;
    memset(calculated,-1,sizeof(calculated));
    solve(0,0);
    string temp;
    int i=0,j=0;
    while(i<n&&j<m)
    {
        if(s[i]==t[j])
        {
            temp.push_back(s[i]);
            i++;
            j++;
        }
        else if(calculated[i+1][j]>calculated[i][j+1])
        {
            i++;
        }
        else
            j++;
    }
    cout<<temp;
}


Measured memory_bytes: 35712
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <vector>

using namespace std;


void Out(vector<int>& b, vector<int>& c)
{
	for (int i = c.size()-1; i >= 0; --i)
		cout << c[i] << " ";
	for (int i = 0; i < b.size(); ++i)
	{
		if (i == b.size() - 1)
			cout << b[i] << "\n";
		else
			cout << b[i] << " ";
	}
}

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

	int n;
	cin >> n;
	int a;
	vector<int> b;
	vector<int> c;

	for (int i = 0; i < n; ++i)
	{
		cin >> a;
		if (i % 2 == 0)b.push_back(a);
		else c.push_back(a);
	}

	if (n % 2 == 0)
	{
		Out(b, c);
	}
	else
	{
		Out(c, b);
	}


	return 0;
}


Measured memory_bytes: 3188
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N, M;
  cin>>N>>M;
  vector<int> A(N);
  vector<pint> CB(M);
  REP(i,N) cin>>A[i];
  REP(i,M) {
    int	b, c; cin>>b>>c;
    CB[i] = make_pair(c, b);
  }
  //  pp(A, N);                                                                              
  sort(A.begin(), A.end());
  //  reverse(A.begin(), A.end());                                                           
  //  pp(A, N);                                                                              
  sort(CB.begin(), CB.end());
  reverse(CB.begin(), CB.end());
  int idx = 0;
  REP(i,M) {
    if(idx >= N) break;
    int B = CB[i].second;
    int C = CB[i].first;
    REP(j,B) {
      if(idx >= N) break;
      chmax(A[idx], C);
      idx++;
    }
  }
  //  pp(A, N);                                                                              
  ll ans = 0;
  REP(i,N) {
    ans += (ll)A[i];
  }
  cout << ans << endl;
  return 0;
}


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

#define f(i, a, b, c) for(int i = a ; i < b ; i += c)
#define fr(i, a, b, c) for(int i = a ; i >= b ; i -= c)
#define fit(it, v) for(auto it = v.begin() ; it != v.end() ; ++it)
#define frit(it, v) for(auto it = v.rbegin() ; it != v.rend() ; ++it)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define lli long long int
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define NL '\n'
#define modn 1000000007
#define EPS 1e-9

using namespace std;

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< lli > vli;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< char > vc;
typedef vector< string > vs;
typedef vector< bool > vb;
typedef set< int > si;
typedef set< ii > sii;

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

	#ifdef LOCAL_TEST
		ifstream h("in");
		ofstream g("out");
		clock_t z = clock();
	#else
		#define h cin
		#define g cout
	#endif//LOCAL_TEST

	int n;
	h >> n;
	vi v(n);
	lli ans = 0;
	f(i, 0, n, 1)
		h >> v[i];
	int mx = v[0];
	f(i, 1, n, 1){
		if (mx > v[i]){
			ans = ans + mx - v[i];
			v[i] = mx;
		}
		mx = max(mx, v[i]);
	}
	g << ans;

	#ifdef LOCAL_TEST
		cerr << "Time taken is: " << double(clock() - z) / CLOCKS_PER_SEC << NL;
		h.close();
		g.close();
	#endif//LOCAL_TEST
}


Measured memory_bytes: 3984
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 998244353
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
bool x[MAX_N];
vector<ll> num;
void eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]){
            num.push_back(i);
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
    }
    return;
}

int main(){
    ll q;
    cin >> q;
    eratosthenes(100000);
    ll rui[100100];
    fill(rui,rui+100010,0);
    for (ll i=1;i<100010;i++){
        if (i%2!=0 and x[i] and x[((i+1)/2)]){
            rui[i]=rui[i-1]+1;
            continue;
        }
        rui[i]=rui[i-1];
    }
    for (ll i=0;i<q;i++){
        ll l,r;
        cin >> l >> r;
        cout << rui[r]-rui[l-1] << endl;
    } 
    return 0;
}

Measured memory_bytes: 1664
# https://beta.atcoder.jp/contests/arc098/tasks/arc098_a
# C - Attention

# C_Attention.py

N = int(input())
S = input()

e = [0 for i in range(N)]
w = [0 for i in range(N)]
d = [0 for i in range(N)]

# 累積和を求める
for i in range(N):
    # そこからE側の人で、Wを向くべきなのにEを向いている人
    if i > 0:
        w[i] += w[i-1]
    if i < N-1:
        if S[i] == "W":
            w[i+1] += 1
    # そこからW側の人で、Eを向くべきなのにWを向いている人
    if i > 0:
        e[N-1-i] += e[N-1-(i-1)]
    if i < N-1:
        if S[N-1-i] == "E":
            e[N-1-(i+1)] += 1

min = 10 ** 6
for i in range(N):
    total = e[i] + w[i]
    if total < min:
        min = total
print(min)


Measured memory_bytes: 29692
#include <iostream>
#include <cstring>

using namespace std;

int dp[10][10][101];

int dfs(int now, int use, int sum)
{
    if (use == 0 && sum == 0)
    {
        return 1;
    }
    if (use == 0 || now == 10 || sum < now)
    {
        return 0;
    }
    if (~dp[now][use][sum])
        return dp[now][use][sum];
    return dp[now][use][sum] = dfs(now + 1, use, sum) + dfs(now + 1, use - 1, sum - now);
}

int main()
{
    int n, s;
    memset(dp, -1, sizeof dp);
    while (cin >> n >> s && n)
    {
        cout << dfs(0, n, s) << "\n";
    }
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int n, m;
  cin >> n >> m;
  vector<int> nearest(n + 1, INT_MAX);
  for (int i = 0; i < m; ++i) {
    int left, right;
    cin >> left >> right;
    nearest[left] = min(nearest[left], right);
  }

  int cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (nearest[i] == i+1) {++cnt;}
    else {
      nearest[i+1] = min(nearest[i+1], nearest[i]);
    }
  }

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


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int visited[50];
int graph[50][50];
int N;
void dfs(int v){
	visited[v] = 1;
	for(int v2=0;v2<N;v2++){
		if(graph[v][v2] == -1) continue;
		if(visited[v2] == 1)continue;
		dfs(v2);
	}
}

int main(void){
	int M,i,ans = 0;
	scanf("%d%d",&N,&M);
	int a[M],b[M];
	for(i=0;i<N;i++){
		for(int j=0;j<N;j++){
			graph[i][j] = -1;
		}
	}
	for(i=0;i<M;i++){
		scanf("%d%d",&a[i],&b[i]);
		a[i]--;
		b[i]--;
		graph[a[i]][b[i]] = 1;
		graph[b[i]][a[i]] = 1;
	}
	
	for(i=0;i<M;i++){
		graph[a[i]][b[i]] = -1;
		graph[b[i]][a[i]] = -1;
		for(int j=0;j<N;j++)visited[j] = -1;
		dfs(0);
		int bridge = -1;
		for(int j=0;j<N;j++){
			if(visited[j] == -1) bridge = 1;
		}
		if(bridge==1) ans++;
		graph[a[i]][b[i]] = 1;
		graph[b[i]][a[i]] = 1;
	}
	
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
N, X = gets.chomp.split.map(&:to_i)
cities = gets.chomp.split.map(&:to_i).push(X).sort
distances = (cities.length - 1).times.map{|i| cities[i + 1] - cities[i]}
ans = distances[0]
distances.each do |distance|
  ans = ans.gcd(distance)
end
puts ans

Measured memory_bytes: 11760
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  	string input;
  	cin >> input;
    int a[4];
  	for(int i = 0; i < 4; ++i) a[i] = input[i] - '0';
    for(int x = 0; x < 8; ++x){
		int sum = a[0];
      	string s;
      	s += (char)('0' + a[0]);
      	for(int i = 0; i < 3; ++i){
			if(x & (1 << i)){
              sum += a[i + 1];
              s += '+';
              s += (char)('0' + a[i+1]);
            }
          else{
            sum -= a[i + 1];
              s += '-';
              s += (char)('0' + a[i+1]);
          }
        }
      if(sum == 7){
         cout << s << '=' << '7' << endl;
        return 0;
      }
    }
}

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

const int MAXN = 0;

map<int,int> st;

int n, a;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a), st[a]++;
	int ans = 0;
	for (map<int,int>::iterator i = st.begin(); i != st.end(); ++i) {
		if (i->second < i->first) ans += i->second;
		else ans += i->second-i->first;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;
using ll = long long;
using v1 = vector<int>;
using vl = vector<long long>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	ll v;
	ll l;
	cin >> l;
	v = l*l*l;
	double a;
	a = v / 27.0;
	printf("%lf\n", a);
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9+10)
#define ll_MIN (ll)(-1e9*1e9-10)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
//using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX
 

bool v[1001][1001]; 

void solve()
{
  int n,m;
  cin >> n >> m;
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  string s[n];
  inp(s, n);
  deque<pii> q;
  x1--, x2--, y1--, y2--;
  q.push_front({x1, y1});
  int ans = 0;
  while(q.size())
  {
    int s1 = q.size();
    while(s1>0)
    {
      pii c = q.front();
      q.pop_front();
      s1--;
      int x = c.fr, y = c.sc;
      if(x < 0 or x>=n or y<0 or y>=m)
        continue;
      if(v[x][y])
        continue;
      if(s[x][y]=='#')
        continue;
      v[x][y] = 1;
      if(x==x2 and y==y2)
      {
        cout << ans;
        return;
      }
      for(int i=max(c.fr-2, (int)0); i<= min(c.fr+2, n-1); i++)
        for(int j=max(c.sc-2, (int)0); j<=min(c.sc+2, m-1); j++)
        {
          if(s[i][j]=='.')
            q.push_back({i,j});
        }
      q.push_front({x+1, y});
      q.push_front({x, y-1});
      q.push_front({x-1, y});
      q.push_front({x, y+1});
      s1 += 4;
    }
    ans++;
  }

  cout << -1 << endl;

}


 
signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 7884
package main

import (
	"fmt"
)

func main() {
	var p, q, r int
	fmt.Scan(&p, &q, &r)

	min := p + q
	if q+r < min {
		min = q + r
	}
	if r+p < min {
		min = r + p
	}

	fmt.Println(min)
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  string s;
  cin >> s;
  int N = s.size();

  int ans1 = 0;
  for(int i=0;i<N;i++){
    if(i % 2 == 0 && s[i] == '0') ans1++;
    if(i % 2 == 1 && s[i] == '1') ans1++;
  }

  int ans2 = 0;
  for(int i=0;i<N;i++){
    if(i % 2 == 0 && s[i] == '1') ans2++;
    if(i % 2 == 1 && s[i] == '0') ans2++;
  }

  cout << min(ans1, ans2) << endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#define N 500
#define INFTY 3000000

int main(){
  int n,i,j;
  int G[N][N];
  int min,s,t,u,v;
  int a[N];
  int b[N];

  scanf("%d",&n);
  for(i=0 ; i<n ; i++){
    for(j=0 ; j<n ; j++){
      G[i][j] = INFTY;
    }
  }

  for(i=0 ; i<n ; i++){
    scanf("%d %d",&s,&t);
    for(j=0 ; j<t ; j++){
      scanf("%d %d",&u,&v);
      G[s][u] = v;
    }
  }

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

    a[0] = 0;

    while(1){
      min = INFTY;
      s = -1;

      for(i=0 ; i<n ; i++){
        if(min > a[i] && !b[i]){
        s = i;
        min = a[i];
      }
    }

    if(s == -1){
      break;
    }
    b[s] = 1;

    for(u=0 ; u<n ; u++){
      if(!b[u] && G[s][u]!=INFTY){
        if(a[u] > a[s] + G[s][u]){
          a[u] = a[s] + G[s][u];
        }
      }
    }
  }

  for(i=0 ; i<n ; i++){
   printf("%d %d\n",i,(a[i]==INFTY?-1:a[i]));
 }

 return 0;

}



Measured memory_bytes: 2064
import sys
def p(c,l,b):
 for i in l:c[i]+=[-1,1][b]
def f(c):
 if sum(c)in c:return 1
 if 5 in c:return 0
 if 4 in c:
  k=c.index(4);c[k]-=3
  if f(c):return 1
  c[k]+=3
 if 3 in c:
  k=c.index(3);c[k]-=3
  if f(c):return 1
  c[k]+=3
 for i in range(7):
  if c[i]and c[i+1]and c[i+2]:
   p(c,[i,i+1,i+2],0)
   if f(c):return 1
   p(c,[i,i+1,i+2],1)
n='123456789'
for e in sys.stdin:
 e=list(e)
 a=[i for i in n if f([(e+[i]).count(j)for j in n])]
 if a:print(*a)
 else:print(0)


Measured memory_bytes: 5580
#include <iostream>
#include <algorithm>
#include <vector>
#include <tuple>
#include <string>
#include <queue>
using namespace std;
int n;
int T;
int t[10];
string s;
void rotate(char ch) {
  if (ch == 'S') {
    int tmp = t[2];
    t[2] = t[1];
    int tmp2 = t[5];
    t[5] = t[6];
    t[6] = tmp;
    t[1] = tmp2;
  } else if (ch == 'N'){
    int tmp = t[5];
    t[5] = t[1];
    int tmp2 = t[2];
    t[2] = t[6];
    t[6] = tmp;
    t[1] = tmp2;
  } else if (ch == 'W') {
    int tmp = t[4];
    t[4] = t[1];
    int tmp2 = t[3];
    t[3] = t[6];
    t[6] = tmp;
    t[1] = tmp2;
  } else if (ch == 'E'){
    int tmp = t[3];
    t[3] = t[1];
    int tmp2 = t[4];
    t[4] = t[6];
    t[6] = tmp;
    t[1] = tmp2;
  }
}
int main() {

  cin.tie(0);
  ios::sync_with_stdio(0);
  for (int i = 1; i <= 6; i++) cin >> t[i];
  cin >> s;
  for (int i = 0; i < s.size(); ++i) {
    rotate(s[i]);
  }
  cout << t[1] << endl;
}





Measured memory_bytes: 3240
def dfs(i,k,s):
    if k == s == 0: return 1
    if i > n or s < i*k+k-1: return 0
    return dfs(i+1,k,s)+dfs(i+1,k-1,s-i)
 
while 1:
    n,k,s = map(int,raw_input().split())
    if n == 0: break
    print dfs(1,k,s)

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


int main(){
    ll a, b;
    int k;
    cin >> a >> b >> k;
    if(b-a+1 > k*2){
        rep(i,k){
            cout << a+i << endl;
        }
        rep(i,k){
            cout << b-(k-i-1) << endl;
        }
    }else{
        rep(i,b-a+1){
            cout << a+i << endl;
        }
    }

}


Measured memory_bytes: 256
#include <stdio.h>
 
int main()
{
  int N,n;
  scanf("%d",&N);
 
  n = N%10;
 
  if(n == 3)
    printf("bon");
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    printf("pon");
  else
    printf("hon");
 
  return 0;
}

Measured memory_bytes: 1632
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
A=[0 for i in range(n)]
B=[0 for i in range(m)]
A[0]=a[0]
B[0]=b[0]
for i in range(n-1):
    A[i+1]=a[i+1]+A[i]

for i in range(m-1):
    B[i+1]=b[i+1]+B[i]

ans=0
A.insert(0,0)
B.insert(0,0)

for i in range(n+1):
    x=0
    y=m
    j=(x+y)//2
    if A[i]+B[m]<=k:
        ans=max(ans,i+m)
    elif not A[i]+B[0]>k:
        
        
        while y-x>1:
            if A[i]+B[j]<=k:
                x=j
            else:
                y=j
            j=(x+y)//2
        ans=max(ans,i+x)
    
print(ans)
    
    


Measured memory_bytes: 135512
n = int(input())
T = [i for i in range(n)]
def root(x):
    path_to_root = []
    while T[x] != x:
        path_to_root.append(x)
        x = T[x]
    for node in path_to_root:
        T[node] = x
    return x
def is_same_set(x,y):
    return root(x) == root(y)
def unite(x,y):
    T[root(x)] = root(y)

A = []
W = []
for i in range(n):
    A.append(list(map(int,input().strip().split(' '))))
    for j in range(i+1,n):
        if A[i][j] != -1:
            W.append([A[i][j],i,j])
W.sort()
sum = 0
for i in range(len(W)):
    if not is_same_set(W[i][1],W[i][2]):
        unite(W[i][1],W[i][2])
        sum += W[i][0]
print(sum)



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

int main() {
  int N,a,b,c,d;
  cin >> N;
 a=N/1000;
  b=N/100-10*a;
  d=N%10;
  c=(N%100-d)/10;
    
  if ((a==b && b==c) ||(b==c && c ==d)) {
    cout << "Yes"<< endl;
  }
  else {
  cout << "No" <<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

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

void solve(int N, int M, vector<long> a, vector<long> b, vector<long> c, vector<long> d) {
  rep(i, N) {
    long min_dist = 4 * 1E8;
    int nearest_cp = 0;
    rep(j, M) {
      long dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if (dist < min_dist) {
	min_dist = dist;
	nearest_cp = j + 1;
      }
    }
    cout << nearest_cp << endl;
  }
    
}

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

  int N, M;
  cin >> N >> M;

  vector<long> a(N), b(N);
  rep(i, N)
    cin >> a[i] >> b[i];

  vector<long> c(M), d(M);
  rep(i, M)
    cin >> c[i] >> d[i];

  solve(N, M, move(a), move(b), move(c), move(d));
  return 0;
}


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

#define rep(i, n)    for(ll i = 0; i < (n); ++i)
#define repA(i, a, n)  for(ll i = a; i <= (n); ++i)
#define repD(i, a, n)  for(ll i = a; i >= (n); --i)
#define pb push_back
#define X first
#define Y second

typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vii;
const ll INF = 1e18+1;
const ll MOD = 1000000007L;

#ifdef umang99m
    #include "/home/umang/.templates/header.h"
#else
    #define dbg(args...)
    #define timer()
#endif

int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);

    ll n,l;
    cin>>n>>l;
    vector<string>s(n);
    rep(i,n) cin>>s[i];
    sort(s.begin(), s.end());
    for(auto x: s) cout<<x;
    cout<<endl;
    timer();
    return 0;
}


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

int main()
{
    int X, A, B;
    cin >> X >> A >> B;

    if(A >= B) {
        cout << "delicious" << endl;
    } else if(A + X >= B) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }

    return (0);
}


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

int main(){
  string x;
  int s;
   
  while(1){
    cin >> x ;
    if(x[0]=='0')break;
    s=0;
    for(int i=0;i<x.size();i++){

      s += x[i]-'0';}

      cout << s << endl;}
  
    
    
  return 0;}
    
    

Measured memory_bytes: 1184
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	edge(int _t) : t(_t) {}
};
bool use[100010];


vector<edge> te[100010];
vector<edge> fe[100010];
int d[100100];
ll rec(int num) {
	if (num == 0) return 0;
	return rec(num - 1) + num;
}
ll gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}


void Solve() {

	int n, k;
	cin >> n >> k;
	ll a[100010];
	ll r[100010];
	ll r2[100010];
	a[0] = 0;
	r[0] = 0;
	r[n + 1] = 0;
	r2[0] = 0;
	r2[n + 1] = 0;

	for (size_t i = 1; i <= n; i++)
	{
		cin >> a[i];

		r[i] = r[i - 1] + a[i];
		r2[i] = r2[i - 1] + max(a[i], 0LL);
	}
	ll res = 0;
	for (size_t i = 1; i <= n - k + 1; i++)
	{
		ll fix = r[i + k - 1] - r[i - 1];
		ll left = r2[i - 1] - r2[0];
		ll right = r2[n] - r2[i + k - 1];
		res = max(res, max(fix, 0LL) + left + right);
	}


	cout << res << endl;
}


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



Measured memory_bytes: 8320
#include <iostream>
#include <algorithm>
#include <complex>
#include <cmath>

using namespace std;

typedef complex<double> P;

const double INF = 1e77;
const double EPS = 1e-8;

int n, m, ans[10];
P dogs[10];
double dv[10];

double dot(P a, P b){ return real(conj(a) * b); }

void calc(P fp, P fv){
  double time[10];
  for(int i=0;i<n;i++){
    double a = norm(fv) - dv[i] * dv[i];
    double b = -dot(fv, dogs[i] - fp);
    double c = norm(dogs[i] - fp);
    if(abs(a) > EPS){
      time[i] = INF;
      if(b * b > a * c){
        double d1 = (-b + sqrt(b * b - a * c)) / a;
        double d2 = (-b - sqrt(b * b - a * c)) / a;
        if(d1 > -EPS) time[i] = min(time[i], d1);
        if(d2 > -EPS) time[i] = min(time[i], d2);
      }
    }
  }
  int id = min_element(time, time+n) - time;
  if(time[id] > EPS){
    for(int i=0;i<n;i++){
      if(time[i] < INF / 2){
        P v = (fp + fv * time[i]) - dogs[i];
        v /= abs(v);
        dogs[i] += v * dv[i] * time[id];
      }
    }
  }
  ans[id]++;
}

main(){
  while(cin >> n >> m && (n|m)){
    fill(ans, ans+10, 0);
    for(int i=0;i<n;i++) cin >> dogs[i].real() >> dogs[i].imag() >> dv[i];
    for(int i=0;i<m;i++){
      P fp, fv;
      cin >> fp.real() >> fp.imag() >> fv.real() >> fv.imag();
      calc(fp, fv);
    }
    for(int i=0;i<n;i++) cout << ans[i] << (i+1<n ? " " : "\n");
  }
}

Measured memory_bytes: 1256
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double

map<ll, int> prime_factor(ll n){
    map<ll, int> ret;
    for (ll i = 2; i * i <= n; ++i){
        while (n % i == 0){
            ++ret[i]; n /= i;
        }
    }
    if (n != 1) ret[n] = 1;
    return ret;
}

ll cnt(ll e){
    ll ok = 0, ng = e + 1;
    while (ng - ok > 1){
        ll mid = (ok + ng) / 2;
        if (mid * (mid + 1) / 2 <= e) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main(void){
    ll N; cin >> N;
    if (N == 1){
        cout << 0 << endl;
        return 0;
    }
    map<ll, int> pf = prime_factor(N);
    ll res = 0;
    for (auto& e : pf)
        res += cnt(e.second);
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) ((a)>=0?(a):-(a))
#define sqr(x) ((x)*(x))
#define pb push_back
#define mp make_pair
#define INF (0x3f3f3f3f)
#define EPS (1e-5)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a-1;i>=b;i--)
#define lb lower_bound
#define ub upper_bound
#define N 100005
using namespace std;
typedef long long ll;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
int n,k;
int a[N];
int _1;
int ans=INF;
void Init()
{
	scanf("%d%d",&n,&k);
	_1=n;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==1)_1=i;
	}
}
void Solve()
{
	for(int i=1;i<=k;i++)
	{
		if(_1>=i and n-_1>=k-i)
		{
			ans=min(ans,(ceil(1.0*(_1-i)/(k-1))+1+ceil(1.0*(n-(_1+k-i))/(k-1))));
		}
	}
}
void Print()
{
	printf("%d\n",ans);
}
int main()
{
	Init();
	Solve();
	Print();
	return 0;
}


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

int64_t gcd(int64_t A,int64_t B){
  if(B==0){return A;}
  return gcd(B,A%B);
}

int main(){
  int64_t N,X;
  cin>>N>>X;
  vector<int64_t> x(N);
  for(int i=0;i<N;++i){
    cin>>x.at(i);
  }

  int ans=0;
  for(int i=0;i<N;++i){
    ans=gcd(ans,x.at(i)-X);
  }

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

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


struct init{init(){ios::sync_with_stdio(false);cin.tie(0);}}INIT;
typedef __int128 LL;
ostream& operator<<(ostream& os,LL n){
    os<<(long long)n;
    return os;
}
LL fz(LL m){
    return m-m/3-m/5+m/15;
}
LL calc(LL num){
    LL ten=1,res=0;
    int d=1;
    while(ten*10<=num){
	ten*=10;
	LL m=ten-1;
	res+=d*(fz(m)-fz(m/10));
	d++;
    }
    res+=d*(fz(num)-fz(ten-1));
    res+=4*(num/3+num/5);
    return res;
}

string f(LL num){
    if(num<10)return to_string((int)num);
    else{
	string res;
	while(num>0){
	    res+=to_string((int)(num%10));
	    num/=10;
	}
	reverse(res.begin(),res.end());
	return res;
    }
}
string fizzbuzz(LL num){
    if(num%15==0)return "FizzBuzz";
    if(num%3==0)return "Fizz";
    if(num%5==0)return "Buzz";
    return f(num);
}

istream& operator>>(istream& os,LL& n){
    long long t;
    os>>t;
    n=t;
    return os;
}
int main(){
    LL s,id,sz;
    cin>>s;
    s--;
    {
	LL can=0,cannot=s;
	while(cannot-can>1){
	    const LL mid=(can+cannot)/2;
	    if(calc(mid)<s)can=mid;
	    else cannot=mid;
	    //cout<<"(mid,calc)="<<mid<<","<<calc(mid)<<endl;
	}
	id=can;
	sz=calc(id);
    }
    string t;
    for(int i=1;i<=20;i++){
	t+=fizzbuzz(id+i);
    }
     
    cout<<t.substr(s-sz,20)<<endl;
    return 0;
}

Measured memory_bytes: 3268
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <regex>
#include <set>

using namespace std;

int main()
{
    int k;
    std::cin >> k;
    int a, b;
    std::cin >> a >> b;
    bool ans(false);

    for(int i = a; i <= b; i++)
    {
        if(i % k == 0)
        {
            ans = true;
            break;
        }
    }

    if(ans)
    {
        std::cout << "OK";
    } else
    {
        std::cout << "NG";
    }
    

    return EXIT_SUCCESS;
} 


Measured memory_bytes: 3052
#include <stdio.h>
int main(void){
    char ch;
    int n,m;
    scanf("%d\n",&n);
    int cards[4][13]={0};
    for(int i=0;i<n;i++){
        scanf("%c %d\n",&ch,&m);
    if(ch=='S'){
        cards[0][m-1]=m;
    }else if(ch=='H'){
        cards[1][m-1]=m;    
    }else if(ch=='C'){
        cards[2][m-1]=m;
    }else if(ch=='D'){
        cards[3][m-1]=m;
    }
    }
    
    for(int k=0;k<4;k++){
        for(int j=0;j<13;j++){
            if(cards[k][j]==0){
                if(k==0){
                    printf("S %d\n",j+1);
                }else if(k==1){
                    printf("H %d\n",j+1);
                }else if(k==2){
                    printf("C %d\n",j+1);
                }else if(k==3){
                    printf("D %d\n",j+1);
                }
            }
            
        }
    }
    return 0;
}


Measured memory_bytes: 2100
from heapq import heappush, heappop
from collections import deque
n, r = map(int, input().split())
G = [[] for i in range(n)]
for i in range(r):
    s, t, d = map(int, input().split())
    G[s-1].append((t-1, d))
    G[t-1].append((s-1, d))

INF = 10**18
def dijkstra(s):
    dist = [INF]*n
    dist[s] = 0
    que = [(0, s)]
    while que:
        cost, s = heappop(que)
        if dist[s] < cost:
            continue
        for t, d in G[s]:
            if cost + d < dist[t]:
                dist[t] = cost + d
                heappush(que, (cost + d, t))
    ma = max(dist)
    assert ma != INF
    goal = [i for i in range(n) if dist[i] == ma]
    used = set(goal)
    deq = deque(goal)
    while deq:
        s = deq.popleft()
        for t, d in G[s]:
            if dist[t] + d == dist[s] and t not in used:
                used.add(t)
                deq.append(t)
    return ma, used

A = [dijkstra(s) for s in range(n)]
B = max(ma for ma, used in A)
ans = {i for i in range(n)}
for ma, used in A:
    if ma == B:
        ans -= used
print(len(ans))
for e in sorted(ans):
    print(e+1)

Measured memory_bytes: 266468