akhauriyash/Code-Regression huggingface dataset:
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
from collections import deque
INF=10**6
m=[[10**6]*W for _ in range(H)]
dx=[1,-1,0,0]
dy=[0,0,1,-1]

def bfs(y,x):
  q=deque()
  q.append((y,x))  
  
  while len(q)>0:
    y,x=q.popleft()
    dx=[1,-1,0,0]
    dy=[0,0,1,-1]
    for i in range(4):
      nx=x+dx[i]
      ny=y+dy[i]
      if  0<=nx<W and 0<=ny<H and A[ny][nx]=="." and m[ny][nx]==INF:
        q.append((ny,nx))
        m[ny][nx]=m[y][x]+1

m[0][0]=0
bfs(0,0)
cnt=(m[-1][-1])
if cnt>2500:
  print(-1)
else:
  cntd=0
  for i in range(H):
    for j in range(W):
      if A[i][j]=='#':
        cntd+=1
  print(H*W-cnt-cntd-1)

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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> a(H);
    for (int i=0; i<H; i++){
        cin >> a.at(i);
    }

    string s = "";
    for (int i=0; i<W+2; i++) s += "#";
    cout << s << endl;
    for (int i=0; i<H; i++){
        cout << "#"+a.at(i)+"#" << endl;
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())

for i in range(1,10):
    if n <= i:
        print(i)
        exit()
for i in range(1, 10):
    if n <= i*11:
        print(i*11)
        exit()
for i in range(1, 10):
    if n <= i*111:
        print(i*111)
        exit()


Measured memory_bytes: 3316
N, Q = map(int, input().split())
S = input()
AC = [int(S[i:i+2] == 'AC') for i in range(len(S)-1)]
for i in range(1, len(AC)):
    AC[i] = AC[i] + AC[i-1]
AC.insert(0, 0)
for i in range(Q):
    l, r = map(int, input().split())
    # print(AC[r-1], AC[l-1])
    print(AC[r-1]-AC[l-1])


Measured memory_bytes: 7692
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5;
const int inf=0x3f3f3f3f;
int n,ans;
int a[maxn];
map<int,int> mp;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		mp[a[i]]++;
	}
	map<int,int>::iterator it;
	for(it=mp.begin();it!=mp.end();it++)
	{
		int x=it->first,y=it->second;
		if(x<y)
			ans+=y-x;
		if(x>y)
			ans+=y;
	}
	cout<<ans<<endl;
	return 0;
}




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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

struct UnionFind {
  vector<int> par, s; 
  UnionFind(int N) : par(N), s(N) { rep(i,N) { par[i] = i; s[i] = 1; } }
  int root(int x) { return par[x]==x ? x : par[x] = root(par[x]); }
  int size(int x) { return par[x]==x ? s[x] : s[x] = size(root(x)); }
  void unite(int x, int y) { int rx=root(x), ry=root(y); if (rx!=ry) { s[rx] += s[ry]; par[ry] = rx; } }
  bool same(int x, int y) {  int rx=root(x), ry=root(y); return rx==ry; }
};

int main() {
  ll N, M, Q; cin >> N >> M >> Q;
  UnionFind uf(N);
  vector<p_ll> notsame;
  rep(i,Q) {
    int A, B, C; cin >> A >> B >> C;
    if (C==0) uf.unite(A,B);
    else notsame.push_back(make_pair(A,B));
  }
  map<int, int> tr; rep(i,N) tr[uf.root(i)]++;
  ll ts = tr.size();
  // cout << ts << endl;

  for (auto x: notsame) {
    if (uf.same(x.first,x.second)) {
      cout << "No" << endl;
      return 0;
    }
  }

  string result;
  if (M==N-1) result = notsame.empty() ? "Yes" : "No";
  else if (ts<=2) result = "No";
  else result = (M<=N+ts*(ts-3)/2) ? "Yes" : "No";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 7280
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    int ans=0;
    
    while(n-->0)
    {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a>=h&&b>=w)
      {
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 25808
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int h, w;
    cin >> h >> w;
    V<string> s(h);
    rep(i, h) cin >> s[i];
    V<V<int>> dp(h, V<int>(w, 1e9));
    dp[0][0] = s[0][0] == '#';
    rep(i, h) rep(j, w) {
        if(i) chmin(dp[i][j], dp[i - 1][j] + (s[i - 1][j] != s[i][j]));
        if(j) chmin(dp[i][j], dp[i][j - 1] + (s[i][j - 1] != s[i][j]));
    }
    cout << (dp[h - 1][w - 1] + 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 384
#pragma region

#include "bits/stdc++.h"
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin), i##_end = (end); i < i##_end; i++)
#define _irep3(i, begin, end) for (register int i = (end)-1, i##_begin = (begin); i >= i##_begin; i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<long long>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<long long>>;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &pair) {
  cin >> pair.first >> pair.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

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

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

void init() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16) << boolalpha;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  init();

  int N;
  cin >> N;
  vi A(N);
  cin >> A;

  rep(i, N) {
    if (A[i] % 2 == 0 && (A[i] % 3 != 0 && A[i] % 5 != 0)) {
      out("DENIED");
      return 0;
    }
  }
  out("APPROVED");
  return 0;
}


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

int main() {
 int N,K;
 cin >>N>>K;
  
 vector<ll> x(N);
 for(int i= 0;i<N;i++){
    cin >>x[i];
  }
 vector<ll> p;
  for(int i = 0;i<=N-K;i++){
    int xl = x[i];
    int xr = x[i+K-1];
    int t1 = abs(xl) + abs(xr-xl);
    int t2 = abs(xr) + abs(xr-xl);
   p.push_back(min(t1,t2));
  }
   sort(p.begin(),p.end());
   cout << p[0] << endl;
}


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

int main()
{
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;

    for (int i = 1; i < 4; i++)
    {
        if ((a * b * i) % 2 != 0)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}

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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

const int D=20;
ll dp[300000][D][2];
ll a[300000];

int main(){
	int n;cin>>n;
	rep(i,n)scanf("%lld",&a[i]);
	rep(i,n+1)rep(j,D)rep(k,2){
		dp[i][j][k]=-INFL;
	}
	dp[0][D/2][0]=0;
	rep(i,n)rep(j,D)rep(k,2){
		if(dp[i][j][k]==-INFL)continue;
		if(k==0&&j+1<20){
			dp[i+1][j+1][1]=max(dp[i+1][j+1][1],dp[i][j][k]+a[i]);
		}
		if(j-1>=0)dp[i+1][j-1][0]=max({dp[i+1][j-1][0],dp[i][j][k]});
	}
	if(n%2==0){
		cout<<max(dp[n][D/2][0],dp[n][D/2][1])<<endl;
	}
	else cout<<max(dp[n][D/2-1][0],dp[n][D/2-1][1])<<endl;
}

Measured memory_bytes: 67820
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9

ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n;cin>>n;
    if(n<=9)cout<<n;
    else if(n<=99)cout<<9;
    else if(n<=999)cout<<n-90;
    else if(n<=9999)cout<<999-90;
    else if(n<=99999)cout<<n-9000-90;
    else cout<<n-9000-90-1;
    return 0;  
} 


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define rep(i,strt,end) for(long long i = strt;i < end;i++)


int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int startMin = h1 * 60 + m1;
    int endMin = h2*60 + m2;
    int lng = endMin - startMin - k;
    if(0<lng){
        cout << lng << endl;
    }else{
        cout << "0" << endl;
    }

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

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

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

const int INF = 1<<30;

int main(){
  int n, C;cin>>n>>C;
  vector<vector<int>> color(3, vector<int>());
  vector<vector<int>> w(C, vector<int>(C));
  rep(i, C)rep(j, C)cin>>w[i][j];
  rep(i, n)rep(j, n){
    int c;cin>>c;
    color[(i+j)%3].push_back(--c);
  }
  vector<vector<int>> cost(3, vector<int>(C, 0));
  rep(i, 3){
  	rep(c, C){
      for(int j=0;j<(int)color[i].size();j++){
      	if(color[i][j]!=c)cost[i][c]+=w[color[i][j]][c];
      }
    }
  }
  int ans=INF;
  rep(i, C)rep(j, C)rep(k, C){
  	if(i==j || j==k || k==i)continue;
    ans=min(ans, cost[0][i]+cost[1][j]+cost[2][k]);
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 1524
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////


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

	vector<vector<vector<double>>> dp(N + 1, vector<vector<double>>(N + 1, vector<double>(N + 1, 0)));

	rep(i, N + 1)rep(j, N + 1)rep(k, N + 1) {
		ll s = i + j + k;
		if (s == 0||s>N) { continue; }
		ll l = N - s;

		double pi = (double)i / (double)s;
		if(i>0)dp[i][j][k] += (dp[i - 1][j + 1][k] + 1) * pi;
		
		double pj = (double)j / (double)s;
		if(j>0)dp[i][j][k] += (dp[i][j - 1][k + 1] + 1) * pj;

		double pk = (double)k / (double)s;
		if(k>0)dp[i][j][k] += (dp[i][j][k - 1] + 1) * pk;

		double pl = (double)l / (double)N;
		dp[i][j][k] += 1/(1 - pl)-1;

		//cout << i << j << k << " " << dp[i][j][k] << endl;

	}

	vll c(4, 0);
	repn(i, N) {
		ll a;
		cin >> a;
		c[a]++;
	}
	cout << fixed << setprecision(13);
	cout << dp[c[3]][c[2]][c[1]] << endl;

}



Measured memory_bytes: 219968
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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


int main(){
    priority_queue<pair<ll,pair<ll,ll> > >p,q;
    int n;
    cin >> n;
    vector<pair<int,int> > a;
    rep(i,n){
        int b,c;
        cin >> b >> c;
        a.push_back({b,c});
    }
    sort(all(a));
    ll mx = 0;
    rep(i,n){
        ll x = a[i].first;
        ll y = a[i].second;
        if(i!=0){
            auto A = p.top();
            auto B = q.top();
            
            chmax(mx,abs(x-A.second.first) + abs(y-A.second.second));
            chmax(mx,abs(x-B.second.first) + abs(y-B.second.second));
        }
        p.push(MP(-y-x,MP(x,y)));
        q.push(MP(y-x,MP(x,y)));
    }
    cout << mx << endl;
    return 0;
}

Measured memory_bytes: 16848
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n; cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a, a + n);
    int cnt = 1;
    for (int i = 1; i < n; ++i) {
        if (a[i] != a[i - 1]) {
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}



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

using namespace std;

using ll = long long int;

// GCDを計算します
template <typename NumType>
NumType calcGCD(NumType a, NumType b) {
    if (a < b) {
        NumType tmp = a;
        a = b;
        b = tmp; 
    }

    NumType r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

// 約数を数えます
template <typename NumType>
NumType cntDivisor(const NumType & num) {
    NumType cnt = 0;
    for(NumType i = 1; i * i <= num; ++i) {
        if(num % i == 0) {
            cnt++;
            if(i * i != num) cnt++;
        }
    }

    return cnt;
}

// [beg, end)の範囲を，添え字indexでループするfor文に置換します
#define FOR_RANGE(index, beg, end)     for (ll index = beg; index < N; ++index)

#define DEBUG(x)     std::cout << #x << " : " << x << "\n"

template<class T>
T min(T a, T b) {
    return (a < b) ? a : b;
}

template<class T>
T max(T a, T b) {
    return (a > b) ? a : b;
}

int main() {
    int N;
    array<int, 50> p;

    cin >> N;
    for (int i = 0; i < N; i++) cin >> p[i];

    int cnt = 0;
    for (int i = 0; i < N; i++) {
        int cor_num = i + 1;

        if (p[i] != cor_num) {
            cnt++;
            if (cnt > 2) break;
        }
    }

    if (cnt <= 2) cout << "YES";
    else cout << "NO";

    return 0;
}



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

int main(){
  int a,b,c,d;
  cin >> a >> b >>c >>d;

  if((abs(a-b)<=d&&abs(b-c)<=d)||abs(a-c)<=d){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

vector<int> v;

void dfs(int r)
{
  if(r==0){
    for(int i=0; i<v.size()-1; i++){
      cout << v[i] << " ";
    }
    cout << v.back() << endl;
    return;
  }

  for(int i=r; i>0; i--){
    if(!v.empty()) if(v.back()<i) continue;
    v.push_back(i);
    dfs(r-i);
    v.pop_back();
  }
}

int main()
{
  int n;
  while(cin >> n, n){
    dfs(n);
  }
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
    int n;cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,0,n-1)cin>>a[i]>>b[i]>>c[i];
    vector<vector<int>> dp(n+1,vector<int>(3,0));
    rep(i,0,n-1){
        rep(j,0,2){
            rep(k,0,2){
                if(j==k)continue;
                
                switch(k){
                    case 0:
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i]);
                        break;
                    case 1:
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+b[i]);
                        break;
                    case 2:
                        dp[i+1][k]=max(dp[i+1][k],dp[i][j]+c[i]);
                        break;
                }
            }
        }
    }
    int ans = max(max(dp[n][1],dp[n][2]),dp[n][0]);
    cout<<ans<<endl;
}


Measured memory_bytes: 6912
uses SysUtils;
var i,y,i1,x,a,b:Longint;
    ans,n:Longint;

begin
 
 readln(n);
 ans:=9999999;
 for i:=1 to n-1 do begin
      a:=trunc(i); b:=trunc(n)-a;
      //writeln('a=',a,'b=',b);
      x:=0;
      for i1:=1 to length(inttostr(a)) do inc(x,strtoint(copy(inttostr(a),i1,1)));
      //writeln('a ',a,' kakui wa=',x);
      y:=0;
      for i1:=1 to length(inttostr(b)) do inc(y,strtoint(copy(inttostr(b),i1,1)));
      //writeln('b ',b,' kakui wa=',y);
      if ans>x+y then ans:=x+y;
      end;
writeln(trunc(ans));
end.

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;




int main()
{
  int n,val ;
  cin >> n ;
while(n != 0 ){
  val = n%10 ;
  if(val == 7 ) {
    cout<<"Yes" ;
    return 0 ;
  }
  n /= 10 ;
}
cout<<"No";

  return 0 ;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <queue>
#include <math.h>
#include <set>
#include <stack>
#include <deque>
#include <bitset>
using namespace std;

int main()
{
	int x, a, b;
	cin >> x >> a >> b;

	cout << (x - a) % b << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  
  int arr[100];
  int a=0,i,j,temp,count=0,x;
  scanf("%d",&x);
  for(i=0;i<x;i++){
    scanf("%d",&arr[i]);
  }
  
  for(i=0;i<x-1;i++){
  
    for(j=0;j<x-1;j++){

      if (arr[j]>arr[j+1]){

	temp=arr[j];
	arr[j]=arr[j+1];
	arr[j+1]=temp;
	count=count++;
      }
      
      /*	for(a=0;a<x;a++){
		printf("%d",arr[a]);
	  if(a<x-1)printf(" ");
	  }
	printf("\n");
 
      */

    }
  }
  
  for(i=0;i<x;i++){
    printf("%d",arr[i]);
    if(i<x-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 4
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	m := getNextInt(scanner)
	fmt.Fprintln(writer, n*(n-1)/2+m*(m-1)/2)
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int a, b, gcd;
  scanf("%d%d", &a, &b);
  if(a < b){
    a = a+b;
    b = a-b;
    a = a-b;
  }

  while(b > 0){
    gcd = a%b;
    a = b;
    b = gcd;
  }

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

  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
using namespace std;
int main() {
	int n, x;
	cin >> n >> x;
	vector<int> l(n);
	for (int i = 0; i < n; i++)cin >> l[i];
	int count = 0;
	int d = 0;

	for (count = 0; d <= x; count++) {
		if (count >= n) {
			count++;
			break;
		}
		d += l[count];
	}
	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
//----->|try=0; while(!success) try++;|<------
//----->|Belief Yourself,Respect Yourself|<----
//----->|Be Proud Of Yourself,You're Doing Your best|<-----
#include<bits/stdc++.h>
using namespace std;
#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search;
#define lower(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Lower value search;
#define max3(a,b,c) max(max(a,b),c)//maximum value find three value;
#define min3(a,b,c) min(min(a,b),c)//minimum value find three value;
#define PI acos(-1.0)//PI Calculation
#define LL long long
#define AND(a,b) ((a) & (b))
#define OR(a,b) ((a)|(b))
#define XOR(a,b) ((a) ^ (b))
#define mp make_pair
#define sqr(x) ((x)*(x))
#define sqrt(x) sqrt(1.0*(x))
#define INF_MAX 2147483647
#define INF_MIN -2147483647
#define MX 1000005
#define MOD 1000000007
template<typename T> T POW(T b,T p)          //Pow calculation
 {
    T r=1;
    while(p) {
        if(p&1)r=(r*b);
        b=(b*b);
        p>>=1;
    }
    return r;
}

template<typename T> T BigMod(T b,T p,T m) //BigMod Calculation
{
    T r=1;
    while(p) {
        if(p&1)r=(r*b)%m;
        b=(b*b)%m;
        p>>=1;
    }
    return r;
}

//||--------------------------->||Main_Code_Start_Here||<---------------------------------||
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    int a,b,h;
    while(cin>>a>>b>>h)
    {
        cout<<((a+b)*h)/2<<endl;
    }
}




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

using namespace std;

int main(){
  int N;
  while(scanf("%d", &N) > 0){
    int ans = 0;
    for(int i = 1; i <= N; i++){
      int a;
      scanf("%d", &a);
      ans += (i%2 != 0 and a%2 != 0);
    }
    printf("%d\n", ans);
  }
}


Measured memory_bytes: 3760
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string a[105];
    string b[105];

    int n,m;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }

    cin>>m;

    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }

    int ans=0;
    for(int i=0;i<n;i++)
    {
        int w=0;
        for(int j=0;j<n;j++)
        {
            if(a[i]==a[j])
               w++;
        }

        int p=0;
        for(int j=0;j<m;j++)
        {

            if(a[i]==b[j])
               p++;

        }

        if(w-p>ans)
            ans=w-p;

    }


    cout<<ans<<endl;


    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>

long long mod = 1000000007;

long long f (long long a, long long b)
{
	long long result = 1;
	
	while (b > 0)
	{
		if (b % 2)
		{
			result *= a;
			result %= mod;
		}
		
		a *= a;
		a %= mod;
		b /= 2;
	}
	
	return result;
}

int main() {
	
	long long a = 1, b = 1, bi = 1;
	long long x, y, xx, yy, cntx = 0, cnty = 0, flag = 0, i;
	
	scanf("%lld %lld", &x, &y);
	
	if ((x + y) % 3 != 0)
		flag = -1;
	
	xx = (2 * x - y) / 3;
	yy = (2 * y - x) / 3;
	
	if (xx < 0 || yy < 0)
		flag = -1;
	
	
	if (flag == -1)
	{
		printf("0\n");
		
		return 0;
	}
	
	for (i = 1; i <= xx + yy; i++)
		a = (a * i) % mod;
	
	for (i = 1; i <= xx; i++)
		b = (b * i) % mod;
	
	for (i = 1; i <= yy; i++)
		b = (b * i) % mod;
	
	bi = f(b, mod - 2);
	
	printf("%lld", (a * bi) % mod);
	
	return 0;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define IPT(t, x) t ipt; cin >> ipt; x.push_back(ipt);
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
ll n, cnt, ans, tmp, sum, a, b, c, d, k, m, h, w, q, x, y;
string s, t;

int main() {
    ll t;
    cin >> x >> t;
    MSG(max(x - t, (ll)0))
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  int l[200010], r[200010], x[510][510], c[510][510];
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i];
    x[l[i]][r[i]]++;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) c[i][j] = c[i][j - 1] + x[i][j];
  }
  for (int i = 1; i <= q; i++) {
    int p, q;
    cin >> p >> q;
    int sum = 0;
    for (int j = p; j <= q; j++) {
      sum += c[j][q] - c[j][p - 1];
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 4480
#include <bits/stdc++.h>
using namespace std;
#define forinc(i,a,b) for(int i=a;i<=b;++i)
#define fordec(i,a,b) for(int i=a;i>=b;--i)
int n,l,w[110],v[110],f[110][100010],k=0;
int main()
{
    cin >> n >> l;
    forinc(i,1,n)
    {
        cin >> w[i] >> v[i];
        k += v[i];
    }
    forinc(i,0,n)
    {
        forinc(t,0,1e5) f[i][t]=INT_MAX;
    }
    f[0][0]=0;
    forinc(i,0,n-1)
    {
        forinc(t,0,1e5) if(f[i][t]<INT_MAX)
        {
            if(f[i][t]+w[i+1]<=l) f[i+1][t+v[i+1]]=min(f[i+1][t+v[i+1]],f[i][t]+w[i+1]);
            f[i+1][t]=min(f[i+1][t],f[i][t]);
        }
    }
    fordec(i,1e5,0)
    {
        if(f[n][i]<INT_MAX)
        {
            cout << i;
            return 0;
        }
    }
}


Measured memory_bytes: 41216
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int cnt = 0;
	string S,T;
	int s, t,min1;
	cin >> S >> T;
	s = S.size();
	t = T.size();
	min1 = min(s, t);
	for (int i = 0; i < min1; i++) {
		if (S[i] == T[i])
			cnt++;
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std ;
int32_t main()
{
    int n ; cin>>n ;
    vector<int>v ;
    for(int i = 0 ; i < n ; i++){int x ; cin>>x ; v.push_back(x) ; }
    sort(v.begin(),v.end()) ;
    reverse(v.begin(),v.end()) ;
    int ans=v[0],rm=n-2 ;
    //cout<<ans<<endl ;
    if(rm>0)
    for(int i = 1 ; i < v.size() ; i++)
    {
        if(rm<2)
        {
            ans+=v[i] ;
            rm-=2 ;
            if(rm<=0) break ;
        }
        else
        {
            ans+=(v[i]*2) ;
            rm-=2 ;
            if(rm<=0) break ;
        }
    }
    cout<<ans<<endl ;
}


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

ll dp[101][8];

int main(){
    int h, w, k; cin >> h >> w >> k;
    dp[0][0] = 1;
    rep(i,h){
        rep(j,w){
            rep(k,1<<(w-1)){
                // 2つの横線が繋がっていないか調べる
                bool ok = true;
                rep(l,w-2) if(((k>>l) & 1) && ((k >> (l+1)) & 1)) ok = false;
                
                if(ok){
                    // 左方向へ辿る
                    if(j >= 1 && ((k >> (j-1)) & 1)){
                        dp[i+1][j-1] = (dp[i+1][j-1] + dp[i][j]) % MOD;
                    }else if(j <= w-2 && ((k >> j) & 1)){ // 右方向へ辿る
                        dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD;
                    }else{ // 辿らない
                        dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD;
                    }
                }
            }
        }
    }

    cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define int long long
using namespace __gnu_pbds;
using namespace std;

signed main()
{
	ios::sync_with_stdio(false);
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int val1=a*c,val2=a*d,val3=b*c,val4=b*d;
	cout<<max(max(val1,val2),max(val3,val4))<<endl;
	return 0;
}

Measured memory_bytes: 3620
let counting_sort a b k n =
  let c = Array.make (k + 1) 0 in
  Array.iter (fun e -> c.(e) <- c.(e) + 1) a;
  Array.iteri (fun i _ -> if i <> 0 then c.(i) <- c.(i) + c.(i-1)) c;
  for i = n - 1 downto 0 do
    b.(c.( a.(i) ) - 1) <- a.(i);
    c.( a.(i) ) <- c.( a.(i) ) - 1;
  done

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let b = Array.make n 0 in
  counting_sort a b 10000 n;
  print_int b.(0);
  for i = 1 to n - 1 do
    print_string " ";
    print_int b.(i);
  done;
  print_newline ()

Measured memory_bytes: 36248
#include <bits/stdc++.h>
#include<math.h>
#include<queue>
#include<cstdio>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
    int N;
    cin >> N;
    vector<ll> L(N);
    for(int i=0; i<N; i++){
        cin >> L.at(i);
    }
    ll ans=0;
    for(int i=0; i<N-2; i++){
        for(int j=i+1; j<N-1; j++){
            for(int k=j+1; k<N; k++){
                if(L.at(i)!=L.at(j) && L.at(j)!=L.at(k) && L.at(k)!=L.at(i)){
                    if(L.at(i)+L.at(j)>L.at(k) && L.at(k)+L.at(j)>L.at(i) && L.at(i)+L.at(k)>L.at(j)){
                        ans++;
                    }
                }
            }
        }
    }
  cout << ans;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int i, j, k;
		int n = sc.nextInt();
		int a[] = new int[n];
		
		for(i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}
		
		selectionsort(n, a);
	}
	public static void selectionsort(int n, int a[]){
		int count = 0;
		for (int i = 0; i <= n - 1; i++){
			int minj = i;
			for(int j = i; j <= n - 1; j++){
				if(a[j] < a[minj]){
					minj = j;
				}
			}
			if(a[i] != a[minj]) count++;
			int temp = a[i];
			a[i] = a[minj];
			a[minj] = temp;
		}
		for(int i = 0; i < n; i++){
			if(i == n - 1) System.out.println(a[i]);
			else System.out.print(a[i] + " ");
		}
		System.out.println(count);
	}
}



Measured memory_bytes: 26152
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", ans);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	string o, e;
	cin >> o >> e;

	string ans = "";
	int i = 0, j = 0;
	rep (k, o.size() + e.size()) {
		if (k % 2 == 0) {
			ans.pb(o[i]);
			i++;
		}
		else {
			ans.pb(e[j]);
			j++;
		}
	}

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

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    long h,w;
    scanf("%ld %ld", &h, &w);
    if(h == 1 || w == 1 ){
        printf("%d", 1);
    } else {
        printf("%ld", (h * w + 1)/2);
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
        string a, b, c;
        cin >> a >> b >> c;
        map<char, char> m;
        ll x = 0;
        for (char i = 'a'; i <= 'z'; i++) {
                ll y = 0;
                for (char j = 'A'; j <= 'Z'; j++) {
                        if (x == y) m[i] = j;
                        y++;
                }
                x++;
        }
        cout << m[a[0]] << m[b[0]] << m[c[0]] << endl;
}

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

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

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> neg, nneg;
    for (int i=0;i<n;++i) {
        int x; cin >> x;
        if (x < 0) neg.push_back(x);
        else nneg.push_back(x);
    }
    sort(neg.begin(), neg.end());
    reverse(neg.begin(), neg.end());
    sort(nneg.begin(), nneg.end());
    if (nneg.empty()) {
        if (!(k & 1)) {
            reverse(neg.begin(), neg.end());
        }
        LL prod = 1;
        for (int i=0;i<k;++i) {
            prod = (prod * neg[i])%MOD;
        }
        if (prod < 0) prod += MOD;
        cout << prod << '\n';
        return;
    }
    if (n == k) {
        LL prod = 1;
        for (auto it : neg) {
            prod = (prod * it)%MOD;
        }
        for (auto it : nneg) {
            prod = (prod * it)%MOD;
        }
        if (prod < 0) prod += MOD;
        cout << prod << '\n';
        return;
    }
    LL prod = 1;
    if (k & 1) {
        prod = (prod * nneg.back())%MOD;
        nneg.pop_back();
        k--;
    }
    int psz = nneg.size(), nsz = neg.size();
    while(k > 0) {
        if (psz > 1 && nsz > 1) {
            LL x = (neg[nsz-1] * 1LL * neg[nsz-2]);
            LL y = (nneg[psz-1] * 1LL * nneg[psz-2]);
            if (x > y) {
                neg.pop_back();
                neg.pop_back();
                prod = (prod * (x%MOD))%MOD;
                nsz -= 2;
                k -= 2;
            } else {
                nneg.pop_back();
                nneg.pop_back();
                prod = (prod * (y%MOD))%MOD;
                psz -= 2; 
                k -= 2;
            }
            continue;
        }
        if (nsz > 1) {
            LL x = (neg[nsz-1] * 1LL * neg[nsz-2]);
            neg.pop_back(); neg.pop_back();
            prod = (prod * (x%MOD))%MOD;
            nsz -= 2;
            k -= 2;
            continue;
        }
        if (psz > 1) {
            LL y = (nneg[psz-1] * 1LL * nneg[psz-2]);
            nneg.pop_back(); nneg.pop_back();
            prod = (prod * (y%MOD))%MOD;
            psz -= 2;
            k -= 2;
            continue;
        }
        assert(false);
    }
    if (prod < 0) prod += MOD;
    cout << prod << '\n';
} 

int main() {
    FASTIO;
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

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

int main(){
    ll n,m;
    cin>>n>>m;
    vector<pair<ll,ll>> task(n);
    rep(i,n){
        ll a,b;
        cin>>a>>b;
        task[i]=make_pair(a,b);
    }
    sort(task.begin(),task.end());
    priority_queue<ll> que;
    ll pos=0;
    ll ans=0;
    for(ll i=1;i<=m;i++){
        for(ll j=pos;j<n;j++){
            if(task[j].first<=i){
                que.push(task[j].second);
                if(j==n-1)pos=n;
            }else{
                pos=j;
                break;
            }
        }
        if(!que.empty()){
            ans+=que.top();
            que.pop();
        }
    }
    cout<<ans<<endl;
}


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

#define VMAX 10000

int main()
{
	int n;
	cin >> n;
	vector<int> w( n );
	vector<int> b( n );
	int s = VMAX;
	for( int i = 0; i < n; i++ ) {
		cin >> w[i];
		s = min( s, w[i] );
		b[i] = w[i];
	}

	vector<bool> V( n );
	vector<int> T( VMAX + 1 );
	sort( b.begin(), b.end() );
	for( int i = 0; i < n; i++ ) {
		T[ b[i] ] = i;
	}
	int ans = 0;
	for( int i = 0; i < n; i++ ) {
		if( V[i] ) continue;
		int cur = i;
		int S = 0;
		int m = VMAX;
		int an = 0;
		while( 1 ) {
			V[cur] = true;
			an++;
			int v = w[cur];
			m = min( m, v );
			S += v;
			cur = T[v];
			if( V[cur] ) break;
		}
		ans += min( S + (an - 2)*m, m + S + (an + 1)*s );
	}

	cout << ans << endl;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rrep(i, n, g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define len(x) (int)(x).size()
#define dup(x, y) (((x) + (y)-1) / (y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a <= c && c <= b) cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <string>
#include <functional> 
#include <vector>
#include <numeric>
#include <stack>
#include <queue>
#include <utility>


using namespace std;

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

    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];

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

    int alice = 0;
    int bob = 0;

    for(int i=0;i<n;i++){
        if(i%2) bob += a[n-1-i];
        else alice += a[n-1-i];
    }

    cout << alice -bob;

    return 0;
}

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

#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define FOR(i,n,m) for (ll i=n; i<(ll)(m); i++)
#define pb push_back
#define INF 1000000007LL
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)

typedef long long ll;
typedef pair<int,int> p;

int dy[4]={-1,1,0,0};
int dx[4]={0,0,1,-1};

int main(){
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    cout << N / 3 << endl;
    return 0;
}


Measured memory_bytes: 764
/**
 *      purpose : ABC 85 D
 *      author  : kyomukyomupurin
 *      created : 2018-11-08 20:06:21
**/

#include <bits/stdc++.h>
using namespace std;
#define int64 long long
#define print(x) cout << (x) << '\n'

int divide(int x, int y){
    if (x % y == 0) return x / y;
    else return x / y + 1;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N, H; cin >> N >> H;
    int a[N] = {}; int b[N] = {};
    for (int i = 0; i < N; ++i) cin >> a[i] >> b[i];

    int x = *max_element(a, a + N);

    sort(b, b + N);
    auto it = lower_bound(b, b + N, x);     // a の max(x) より大きい b は投げる

    int temp = 0; int cnt = 0;

    for (int i = N - 1; i >= (int) (it - b); --i){
        temp += b[i]; ++cnt;
        if (temp >= H){
            print(cnt); return 0;
        }
    }
    print(cnt + divide((H - temp), x));
    
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
H = list(map(int,input().split()))

ans = 0
for i in range(N):
 judge = 1
 for j in range(0,i+1):
   if(H[i] < H[j]): 
     judge = 0
 if(judge == 1):
  ans += 1
print(ans)


Measured memory_bytes: 3060
//#include"stdc++.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define cases ll t;cin>>t;while(t--)
#define f1(a,n) for(int i=a;i<n;i++)
#define f2(b,n) for(int j=b;j<n;j++)
#define INF 1000000000000009
#define pb push_back
ll ar[100005];
#define MAX 1000005
int main() {
    fast
    string s1,s2;
    ll dp[3005][3005];
    cin>>s1>>s2;
    memset(dp,0,sizeof(dp));
    ll ans=0;
    
    f1(1,s1.length()+1)
    {
        f2(1,s2.length()+1)
        {
            dp[i][j]=max(dp[i-1][j-1],max(dp[i-1][j],dp[i][j-1]));
            if(s1[i-1]==s2[j-1])
                dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
        }
    }
    //cout<<dp[s1.size()][s2.size()]<<endl;
    string t;
    int i = s1.size(), j = s2.size();
    while (dp[i][j])
    {
        if (dp[i][j] == dp[i - 1][j])
            i--;
        else if (dp[i][j] == dp[i][j - 1])
            j--;
        else if (dp[i][j] > dp[i - 1][j - 1])
            i--, j--, t += s1[i];
    }
    reverse(t.begin(), t.end());
    cout << t;
    
    return 0;
}



Measured memory_bytes: 70784
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { //USE LONGS TO AVOID OVERFLOW THEN CAST
 
	public static void main(String[] args) { 
		FastScanner input = new FastScanner();
		PrintWriter w = new PrintWriter(System.out);
		int N = input.nextInt();
		int M = input.nextInt();
		int[][] pref = new int[M][3]; //[prefecture,year,index]
		int[] cnts = new int[N+1]; //how many cities were assigned to prefecture i by year Y
		String[] ans = new String[M];
		for (int i = 0; i < M; i++) {
			int P = input.nextInt();
			int Y = input.nextInt();
			pref[i][0]=P;
			pref[i][1]=Y;
			pref[i][2]=i;
		}
		Arrays.sort(pref,(a,b)->Integer.compare(a[1], b[1])); //Sorting by time
		/*for (int i = 0; i < M; i++) {
			System.out.println(pref[i][0]+","+pref[i][1]+","+pref[i][2]);
		}*/
		for (int i = 0; i < M; i++) {
			int in = pref[i][2];
			int pr = pref[i][0];
			cnts[pr]++;
			int ci = cnts[pr];
			String curans = "";
			int PrefDigit = 0;
			int CityDigit = 0;
			while (pr>0) {
				pr/=10;
				PrefDigit++;
			}
			while (ci>0) {
				ci/=10;
				CityDigit++;
			}
			//System.out.println(cnts[pr]);
			int PZ = 6-PrefDigit; //Prefecture 0s and city 0s in ID number
			int CZ = 6-CityDigit;
			
			for (int j = 0; j < PZ; j++) {
				curans+="0";
			}
			curans+=Integer.toString(pref[i][0]);
			for (int j = 0; j < CZ; j++) {
				curans+="0";
			}
			curans+=Integer.toString(cnts[pref[i][0]]);
			ans[in]=curans; //Have to ultimately reorder ID in jumbled initial format 
			//(not chronological necessarily)
		}
		for (int i = 0; i < M; i++) {
			w.println(ans[i]);
			w.flush();
		}
	}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 66076