akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    int n;cin >> n;
    int m = n % 10;
    if(m == 3) cout << "bon" << endl;
    else if(m == 0 || m == 1 || m == 6 || m == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

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

int main() {
    ll N;
    cin >> N;
    vector<ll> A(N+1);
    vector<ll> B(N);

    for (ll i=0; i<N+1; i++) {
        cin >> A.at(i);
    }
    for (ll i=0; i<N; i++) {
        cin >> B.at(i);
    }

    ll count = 0;
    for (ll i=0; i<N; i++) {
        if (A.at(i) >= B.at(i)) {
            count += B.at(i);
        }
        else {
            count += A.at(i);
            if (A.at(i+1) >= B.at(i)-A.at(i)) {
                count += B.at(i)-A.at(i);
                A.at(i+1) -= B.at(i)-A.at(i);
            }
            else {
                count += A.at(i+1);
                A.at(i+1) = 0;
            }
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   ll n,m;
   cin>>n>>m;
   if(n%m==0)
   	cout<<"0"<<endl;
   else
   {
   	ll mid=n%m;
   	ll mid3=abs(n-m);
    mid=min(mid,mid3);
   	ll mid2=n/m;
   	mid2=mid2+1;
   	mid2=m*mid2;
   	cout<<min(mid,mid2-n);
   }
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.*;
import java.lang.*;

class Main{
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int x = scanner.nextInt(); 
    int y = scanner.nextInt();  
    int z = scanner.nextInt();  
    System.out.print(z);
    System.out.print(" ");
    System.out.print(x);
    System.out.print(" ");
    System.out.print(y);
  }
}

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

const int N = 1010;
int n, m, a, b;
vector<int> g[N], ans(N + 1);

vector<int> minCircle(int s) {
    int d[N] = {0}, f[N] = {0};
    queue<int> q;
    q.push(s);
    while(!q.empty()) {
        int p = q.front();q.pop();
        for(int c : g[p]) {
            if(!d[c]) {
                f[c] = p;
                d[c] = 1;
                q.push(c);
            }
        }
        if(d[s]) break;
    }
    int p = f[s];
    vector<int> ret;
    ret.push_back(s);
    while(p && p != s) {
        ret.push_back(p);
        p = f[p];
    }
    return ret;
}

int main() {
    cin >> n >> m;
    while(m--) {
        cin >> a >> b;
        g[a].push_back(b);
    }
    for(int i = 1; i <= n; i++) {
        vector<int> t = minCircle(i);
        if(t.size() > 1 && t.size() < ans.size()) ans = t;
    }
    if(ans.size() == N + 1) cout << -1;
    else {
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long int;
using namespace std;
ll mod=1e9+7;
       

int main() {
  int a,b;
  cin  >> a >>b;
  int ans=100000;
  int q=0;
  for(int i=0;i<5000;i++){
    for(int r=0;r<5000;r++){
      if(i*2/25==a && r/10==b && i==r){ans=min(ans,i);
                                       q++;}
      
    }
  }
  if(q>0){cout << ans << endl;}else{cout << -1 << endl;}
}


Measured memory_bytes: 256
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let it = stdin.lock().bytes().map(|c| c.unwrap() as char);
    let (fs, ft) = (|c: &char| c.is_whitespace(), |c: &char| !c.is_whitespace());
    let token = it.skip_while(fs).take_while(ft).collect::<String>();
    token.parse().ok().unwrap()
}
#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    f(std::io::BufWriter::new(out.lock()));
}
#[allow(unused_macros)]
macro_rules! debug {
    ($($var:expr),*) => { #[cfg(debug_assertions)] {
        $({ match &$var { v => eprint!("{}={:?} ", stringify!($var), v) } })*
        eprintln!();
    }};
}

fn main() {
    let k: usize = input();

    let dsum = |x: i64| {
        let (mut t, mut s) = (x, 0);
        while t > 0 {
            s += t % 10;
            t /= 10;
        }
        s
    };
    let snuke = |x: i64| x as f64 / dsum(x) as f64;

    let mut mul = 1;
    let mut ans = vec![];
    for _ in 1..16 {
        let mut rng: Vec<i64> = (1..10).rev().collect();
        let mut base = mul;
        while base > 1 {
            let mut supinf = snuke(10 * mul - 1);
            let mut nx = vec![];
            for &x in &rng {
                let nmn = (x * base) as f64 / (dsum(x) + dsum(base - 1)) as f64;
                let nmn_c = (x * base + base - 1) as f64 / (dsum(x) + dsum(base - 1)) as f64;
                debug!(base, supinf, x, nmn, nmn_c);
                if nmn <= supinf {
                    for j in 0..10 {
                        nx.push(x * 10 + 9 - j);
                    }
                    supinf = f64::min(supinf, nmn_c);
                }
            }
            std::mem::swap(&mut rng, &mut nx);
            debug!(rng);
            debug!(nx);
            base /= 10;
        }

        let mut inf = snuke(10 * mul - 1);
        for &x in &rng {
            if snuke(x) <= inf {
                ans.push(x);
                inf = snuke(x);
            }
        }

        mul *= 10;
        if ans.len() >= k {
            break;
        }
    }

    ans.sort();
    with_stdout_lock(|mut w| {
        for a in ans.iter().take(k) {
            writeln!(w, "{}", a).unwrap();
        }
    });
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
int i, a[4];
int main() {
	for (i = 1; i <= 3; i++) a[i] = read();
	sort(a + 1, a + 1 + 3);
	cout << a[1] * a[2] / 2;
	return 0;
}

Measured memory_bytes: 3604
function Main(input) {
  var inputs = input.split("\n")[1].split(" ");

  var isEven = function isEven(array) {
    return array.every(function (number) {
      return parseInt(number) % 2 === 0;
    });
  };

  var divide = function divide(array) {
    return array.map(function (number) {
      return parseInt(number) / 2;
    });
  };

  var iteration = 0;

  while (true) {
    if (!isEven(inputs)) break;
    inputs = divide(inputs);
    iteration++;
  }

  console.log(iteration);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
a=list(map(int,input().split()))
n=a[0]
k=a[1]
if n>=k:
    if n%k==0:
        print("0")
    else:
        if (n%k)<=(k-(n%k)):
            print(n%k)
        else:
            print(k-(n%k))
else:
    c=k-n
    if c<=n:
        print(c)
    else:
        print(n)

Measured memory_bytes: 3064
#include <iostream>
#include <string>

using namespace std;

int main() {

	int d;
	string num;

	for (int i = 0;; i++) {
		getline(cin, num);
		if (num[0] == '0')break;
		d = 0;
		for (int j = 0; j < num.length(); j++) {
			d += num[j] - '0';
		}
		cout << d << "\n";
	}

	return 0;
}

Measured memory_bytes: 1176
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define forin(in) for(int i=0; i<(int)in.size(); i++) cin>>in[i]
#define forout(out) for(int i=0; i<(int)out.size(); i++) cout<<out[i]<<endl
#define rep(i, n) for(int i=0; i<(n); i++)

int main(){
    int N;
    ll K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N){
        cin>> A[i];
        A[i]--;
    }

    deque<int> a;
    vector<bool> seen(N, false);
    int cur = 0;

    while(true){
        if(seen[cur]){
            while(a[0] != cur){
                K--;
                a.pop_front();

                if(K == 0){
                    cout<< a[0] + 1 << endl;
                    return 0;
                }
            }
            break;
        }
        a.push_back(cur);
        seen[cur] = true;
        cur = A[cur];
    }
    cout<< a[K % a.size()] + 1 << endl;
}


Measured memory_bytes: 4724
Q = int(input())
R = 10**5 + 10

def getPrimes():
    isPrime = [True] * R
    ret = []
    for i in range(2, R):
        if not isPrime[i]:
            continue
        ret.append(i)
        for j in range(i, R, i):
            isPrime[j] = False
    return set(ret)

P = getPrimes()

def isOk(n):
    return n in P and (n + 1) // 2 in P

A = [0] * R
for i in range(R):
    if isOk(i):
        A[i] += 1

for i in range(1, R):
    A[i] += A[i - 1]

ans = []
for _ in range(Q):
    l, r = map(int, input().split())
    ans.append(A[r] - A[l - 1])

print(*ans, sep='\n')

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

#define ll long long int
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0);

int main()
{
	FASTIO;
	ll n,k;
	 cin>>n>>k;
	 vector<ll>vect(n);
	 f(i,0,n)
        cin>>vect[i];


    //dp[i][j]->false if the player taking the first turn
    //losses the game if there are i stones in the pile ans
    //j ele in the set.

    bool dp[k+1][n];

    f(i,0,n)
     dp[0][i]=false;


    f(i,0,k+1)
    {
        if(i<vect[0])
            dp[i][0]=false;
        else
            dp[i][0]= !dp[i-vect[0]][0];

    }




    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<n;j++)
        {
            if(i<vect[j])
                dp[i][j]=dp[i][j-1];
            else
            {
                dp[i][j]=  (!dp[i-vect[j]][j]);
                for(int k=0;k<=j;k++)
                    dp[i][j]= ((!dp[i-vect[k]][j]) || dp[i][j]);

            }

        }
    }




    if(dp[k][n-1])
        cout<<"First\n";
    else
        cout<<"Second\n";



	return 0;
}













Measured memory_bytes: 9984
n=int(input())
arr=[]
for _ in range(n):
  k=int(input())
  tmp=[list(map(int,input().split())) for _ in range(k)]
  arr.append(tmp)
ans=0
for i in range(2**n):
  tmp=format(i,'b')
  if len(tmp)<n:
    tmp='0'*(n-len(tmp))+tmp
  flag=True
  for i in range(n):
    c=int(tmp[i])
    if c==0:
      continue
    for a,b in arr[i]:
      if int(tmp[a-1])!=b:
        flag=False
        break
  if flag==True:
    ans=max(ans,tmp.count('1'))
print(ans)

Measured memory_bytes: 43868
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
long mod=1e9+7;
int N,M,S,T;
vector<pair<int,int> >G[1<<17];
long d[2][1<<17],w[2][1<<17];
void calc(int S,long*d,long*w)
{
	for(int i=0;i++<N;)d[i]=1e18;
	priority_queue<pair<long,int> >P;
	d[S]=0;
	w[S]=1;
	P.push(make_pair(0,S));
	while(!P.empty())
	{
		long c=-P.top().first;
		int u=P.top().second;
		P.pop();
		if(d[u]<c)continue;
		for(pair<int,int>p:G[u])
		{
			int v=p.first;
			long nxt=c+p.second;
			if(d[v]>nxt)
			{
				d[v]=nxt;
				w[v]=w[u];
				P.push(make_pair(-d[v],v));
			}
			else if(d[v]==nxt)(w[v]+=w[u])%=mod;
		}
	}
}
main()
{
	cin>>N>>M>>S>>T;
	for(int i=0;i<M;i++)
	{
		int u,v,d;cin>>u>>v>>d;
		G[u].push_back(make_pair(v,d));
		G[v].push_back(make_pair(u,d));
	}
	calc(S,d[0],w[0]);
	calc(T,d[1],w[1]);
	long ans=w[0][T]*w[0][T]%mod;
	for(int i=0;i++<N;)
	{
		if(2*d[0][i]==d[0][T])
			(ans-=w[0][i]*w[0][i]%mod*w[1][i]%mod*w[1][i])%=mod;
		for(pair<int,int>p:G[i])
		{
			int v=p.first;
			if(2*d[0][i]<d[0][T]&&2*d[0][v]>d[0][T]&&d[0][i]+d[1][v]+p.second==d[0][T])
				(ans-=w[0][i]*w[0][i]%mod*w[1][v]%mod*w[1][v])%=mod;
		}
	}
	cout<<(ans+mod)%mod<<endl;
}

Measured memory_bytes: 16852
while True:
  H,W=map(int,input().split())
  listS=[]
  if H==0 and W==0:
      break
  else:
      for i in range(W):
          if i%2==0:
              listS+=["#"]
          else:
              listS+=["."]
      S="".join(listS)
      listS.insert(0,".")
      del listS[W]
      T="".join(listS)
      for i in range(H):
          if i%2==0:
              print(S)
          else:
              print(T)
      print("")          



Measured memory_bytes: 5612
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int INF=0x3f3f3f3f;
const int maxn=105;
const int maxq=1005;

struct edge{int to,cap,cost,rev;};

int n,m,k;
int d[maxn];
int a[maxn];
int p1[maxn];
int p2[maxn];
bool inq[maxn];
vector<edge>G[maxn];

void add_edge(int u,int v,int c,int w) {
	G[u].pb(edge{v,c,w,int(G[v].size())});
	G[v].pb(edge{u,0,-w,int(G[u].size()-1)});
}

int mcmf(int s,int t) {
	int flow=0 , cost=0;
	while (1) {
		memset(d,0x3f,sizeof(d));
		d[s]=0; a[s]=max(0,k-flow);
		int qh=0,qt=0,q[maxq];
		q[qt++]=s; inq[s]=1;
		while (qh<qt) {
			int u=q[qh++];
			inq[u]=0;
			for (int i=0;i<G[u].size();i++) {
				edge e=G[u][i];
				if (d[e.to]>d[u]+e.cost && e.cap) {
					d[e.to]=d[u]+e.cost;
					a[e.to]=min(a[u],e.cap);
					p1[e.to]=u;
					p2[e.to]=i;
					if (!inq[e.to]) {
						q[qt++]=e.to;
						inq[e.to]=1;
					}
				}
			}
		}
		if (d[t]==INF || !a[t]) break;
		flow+=a[t];
		cost+=a[t]*d[t];
		for (int v=t;v!=s;v=p1[v]) {
			int u=p1[v] , i=p2[v];
			G[u][i].cap-=a[t];
			i=G[u][i].rev;
			G[v][i].cap+=a[t];
		}
	}
	if (flow<k) return -1;
	else return cost;
}

int main() {
	cin>>n>>m>>k;
	for (int i=0;i<m;i++) {
		int u,v,c,w; cin>>u>>v>>c>>w;
		add_edge(u,v,c,w);
	}
	cout<<mcmf(0,n-1)<<'\n';
}



Measured memory_bytes: 3216
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		sc.close();
		
		Pattern p = Pattern.compile("^(hi)+$");
		Matcher m = p.matcher(line);
		if(m.find()) {
			System.out.println("Yes");
		}else {
			System.out.println("No");			
		}
	}
}

Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)

using namespace std;

struct P
{
  int to,cap,rev;
  P(int to=-1,int cap=-1,int rev=-1):to(to),cap(cap),rev(rev){}
};
typedef vector<int> VI;
typedef vector<P> VP;
typedef vector<VP> VVP;
typedef pair<int,int> Pes;
int N,M,s,t; 
VVP G;
vector<int> level,iter;
vector<Pes> vec;
vector<int> pvec;
bool sign;

void add_edge(int from,int to,int i)
{
  if(sign)vec.push_back(Pes(from,G[from].size())),
	    pvec.push_back(i);
  G[from].push_back(P(to,1,G[to].size()));
  G[to].push_back(P(from,0,G[from].size()-1));
}

void bfs()
{
  deque<int> deq;
  deq.push_back(s);
  level[s] = 0;
  while(!deq.empty())
    {
      int p = deq.front(); deq.pop_front();
      rep(i,G[p].size())
	{
	  P pes = G[p][i];
	  int v = pes.to;
	  if(level[v] == -1 && pes.cap > 0)
	    {
	      level[v] = level[p]+1;
	      deq.push_back(v);
	    }
	}
    }
}

int dfs(int v,int flow)
{
  if(v == t)return flow;

  for(int &i = iter[v];i < G[v].size();i++)
    {
      P p = G[v][i];

      if(p.cap <= 0)continue;
      if(level[v] < level[p.to])
	{
	  int d = dfs(p.to,min(flow,p.cap));
	  if(d <= 0)continue;
	  G[v][i].cap -= d;
	  G[p.to][p.rev].cap += d;
	  return d;
	    
	}
    }
  return 0;
}

int maximum_flow()
{
  int res = 0;
  iter.resize(N);
  level.resize(N);
  while(1)
    {
      rep(i,N)
	iter[i] = 0,level[i] = -1;
       bfs();
      
       if(level[t] < 0)return res;
       int f;
  
       while((f = dfs(s,(1<<29))) > 0)
	 res += f;
	 
    }
  return res;
}

int main()
{
  cin >> N >> M;
  G.resize(N);
  rep(i,M)
    {
      int from,to;
      cin >> from >> to;
      from--,to--;
      sign = false;
      add_edge(from,to,i);
      sign = true;
      add_edge(to,from,i);
    }
  cin >> s >> t;
  s--,t--;
  
  int mexico = maximum_flow();
  int cnt = 0;
  rep(i,vec.size())
    {
      int p1 = vec[i].first,p2= vec[i].second;
      if(G[p1][p2].cap != 1)cnt++;
    }

  cout << mexico << endl;
  cout << cnt << endl;
  rep(i,vec.size())
    {
      int p1 = vec[i].first,p2= vec[i].second;
      if(G[p1][p2].cap != 1)
	cout << pvec[i]+1 << endl;
    }

  return 0;
}

Measured memory_bytes: 1332
(defvar *N* (read))
(defvar *x* (read))
(defvar *count* 0)

(defun run (lst)
  (setq *x* (- *x* (car lst)))
  (cond ((> 0 *x*)
         (return-from run nil))
        ((= 0 *x*)
         (incf *count*)
         (return-from run nil))
        (t
         (incf *count*)
         (unless (null (cadr lst))
           (run (cdr lst))))))


(defun main ()
  (let ((lst (list nil)))
    (dotimes (n *N*)
      (push (read) lst))
    (setq lst (sort (cdr (reverse lst)) #'<))
    (run lst)
    (when (> *x* 0)
      (decf *count*))
    (princ *count*)))

(main)

Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a[3];
  for(int i=0;i<3;i++) cin>>a[i];
  sort(a,a+3);
  int sum=a[2]-a[1]+a[2]-a[0];
  if(sum%2==0) cout<<sum/2;
  else cout<<(sum+3)/2;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int a, b;
    while(cin >> a >> b) {
        cout << a + b << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
#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>;



int main(void){
  int N;
  cin >> N;
  vector<string> S(N);
  rep(i, N) cin >> S.at(i);

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

  S.erase(unique(S.begin(), S.end()), S.end());
  cout << S.size() << endl;

}


Measured memory_bytes: 9512
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int pre = scanner.nextInt();
        int sum = pre;
        for (int i = 2; i < n; ++i) {
            int cur = scanner.nextInt();
            sum += Math.min(pre, cur);
            pre = cur;
        }
        sum += pre;
        writer.println(sum);
        writer.close();

    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        private void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        private char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        private String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        private int nextInt() {
            return Integer.parseInt(next());
        }

        private long nextLong() {
            return Long.parseLong(next());
        }

        private double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 21204
import sys

def input():
    return sys.stdin.readline()[:-1]

class M_Kun:
    def __init__(self):
        self.money = 1000
        self.stock = 0
        
    def buy(self, value):
        num = self.money // value
        self.money -= value * num
        self.stock += num
        
    def sell(self, value):
        self.money += value * self.stock
        self.stock = 0


def main():
    N = int(input())
    A = list(map(int, input().split()))

    local_min = [False]*N
    local_max = [False]*N

    is_ascending = False
    for a in A[1:]:
        if a > A[0]:
            is_ascending = True
            break
        elif a < A[0]:
            break

    if is_ascending:
        local_min[0] = True
    else:
        local_max[0] = True

    for i in range(N-1):
        if A[i] == A[i+1]:
            continue
        elif is_ascending and A[i] > A[i+1]:
            local_max[i] = True
            is_ascending = False
        elif (not is_ascending) and A[i] < A[i+1]:
            local_min[i] = True
            is_ascending = True

    if is_ascending:
        local_max[-1] = True


    m_kun = M_Kun()

    for i in range(N):
        if local_min[i]:
            m_kun.buy(A[i])
        if local_max[i]:
            m_kun.sell(A[i])

    print(m_kun.money)
    
main()

Measured memory_bytes: 62200
/*
個数制限なしのDP
今回だと1次元でできるので、下から順にしていくのがいいと思う。

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
/*
初期化が最もめんどくさい部分である。
dp(0)＝0でそれ以外の部分は最初無限になっている。
dp(1)とかの場合は？

*/
ll h, n;
vector<ll> a(10005), b(10005);
vector<ll> memo(10005);
ll dp(ll u)
{
    // cout << "dfs";
    if (u <= 0)
    {
        return 0;
    }
    if (memo[u] != 0)
    {
        return memo[u];
    }
    ll res = 0;
    ll min1 = 0;
    rep(i, n)
    {

        if (i == 0)
        {
            min1 = dp(u - a[i]) + b[i];
        }
        else
        {
            min1 = min(min1, dp(u - a[i]) + b[i]);
        }
    }
    memo[u] = min1;
    return min1;
}
int main()
{

    cin >> h >> n;
    a.resize(n);
    b.resize(n);
    rep(i, n)
    {
        cin >> a[i] >> b[i];
    }
    cout << dp(h); //h以上の体力を減らした時の最小のダメージ
}

Measured memory_bytes: 896
s=input()

while 'BC' in s:
    s=s.replace('BC','D')
ans=0
a=0
for i in range (len(s)):
    if s[i]!='A' and s[i]!='D':
        a=0
        continue
    elif s[i]=='A':
        a+=1
    elif s[i]=='D':
        ans+=a
print(ans)

Measured memory_bytes: 3500
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  char c;
  cin >> c;
  char d = c + 1;
  cout << d << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue> 
#include<algorithm>
#define INF 0x3f3f3f3f
#define maxn 200000
#define maxm 1000000
using namespace std;
template<typename T> void qread(T &x){
	x=0;
	T sign=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') sign=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	x=x*sign; 
} 

struct edge{
	int from;
	int to;
	int next;
	int flow;
}E[maxm*2+5];
int sz=1;
int head[maxn+5];
int cur[maxn+5];//当前弧优化 
void add_edge(int u,int v,int w){
//	printf("%d->%d %d\n",u,v,w);
	sz++;
	E[sz].from=u;
	E[sz].to=v;
	E[sz].next=head[u];
	E[sz].flow=w;
	head[u]=sz;
	sz++;
	E[sz].from=v;
	E[sz].to=u;
	E[sz].next=head[v];
	E[sz].flow=0;
	head[v]=sz;
}
int deep[maxn+5];
bool bfs(int s,int t){
	for(int i=s;i<=t;i++) deep[i]=0;
	queue<int>q;
	q.push(s);
	deep[s]=1;
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=head[x];i;i=E[i].next){
			int y=E[i].to; 
			if(E[i].flow&&!deep[y]){
				deep[y]=deep[x]+1;
				q.push(y);
			}
		}
	}
	return deep[t]>0;
} 
int dfs(int x,int t,int minf){
	if(x==t) return minf;
	int rest=minf,k;
	for(int &i=cur[x];i;i=E[i].next){
		int y=E[i].to;
		if(E[i].flow&&deep[y]==deep[x]+1){
			k=dfs(y,t,min(rest,E[i].flow));
			E[i].flow-=k;
			E[i^1].flow+=k;
			rest-=k; 
			if(k==0) deep[y]=0;
			if(rest==0) break;
		}
	}
	return minf-rest;
}
int dinic(int s,int t){
	int ans=0,now=0;
	while(bfs(s,t)){
		for(int i=s;i<=t;i++) cur[i]=head[i];
		while((now=dfs(s,t,maxm+1))) ans+=now;
	}
	return ans;
} 

int n;
int p[maxn+5],q[maxn+5];
int cnt=0;//环个数 
int idp[maxn+5],idq[maxn+5];//所在环编号
void mark(int *id,int *a,int x){
	while(!id[x]){
		id[x]=cnt;
		x=a[x];
	}
}
int main(){
	qread(n);
	for(int i=1;i<=n;i++){
		qread(p[i]);
		p[i]++; 
	}
	for(int i=1;i<=n;i++){
		qread(q[i]);
		q[i]++;
	}
	for(int i=1;i<=n;i++){//找出每个环 
		if(!idp[i]){
			cnt++;
			mark(idp,p,i);
		} 
	}
	for(int i=1;i<=n;i++){
		if(!idq[i]){
			cnt++;
			mark(idq,q,i);
		}
	}
	int s=0,t=cnt+1;
	int eq=0;//相等的个数 
	for(int i=1;i<=n;i++){
		if(p[i]==i&&q[i]==i) eq++;
		else if(p[i]==i&&q[i]!=i) add_edge(idq[i],t,1);
		else if(p[i]!=i&&q[i]==i) add_edge(s,idp[i],1);
		else if(p[i]!=q[i]) add_edge(idq[i],idp[i],1);
		else{
			add_edge(idq[i],idp[i],1);
			add_edge(idp[i],idq[i],1);
		}
	}
	eq+=dinic(s,t);
	printf("%d\n",n-eq);
}


Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>
const int N = 2e5 + 10;

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    string s;
    cin >> s;
    int n = sz(s);
    int cntc = 0, cntl = 0;
    for(int i = 0; i < n; i++) {
        if('a' <= s[i] && s[i] <= 'z') {
            cntl++;
        }
    }
    for(int i = 2; i < n - 1; i++) {
        if(s[i] == 'C') {
            cntc++;
        }
    }
    if(s[0] == 'A' && cntc == 1 && cntl == n - 2) {
        cout << "AC\n";
    } else {
        cout << "WA\n";
    }
}

Measured memory_bytes: 256
from fractions import gcd
n, k = map(int,input().split())
balls = list(map(int,input().split()))
balls.sort()
p = max(balls)
if k in balls:
    print("POSSIBLE")
    exit()
elif  p < k:
    print("IMPOSSIBLE")
    exit()
for i in range(n-1):
    p = gcd(p, balls[i])
if k % p == 0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

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

int main() {
  int S;
  cin >> S;
  int s1 = S / 100;
  int s2 = S / 10 % 10;
  int s3 = S % 10;
  
  cout << s1 + s2 + s3 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[4]={0,0,1,1};
int dy[4]={0,1,0,1};
const int SIZE=1000050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	string S;
	cin>>S;
	int Q;
	cin>>Q;
	while(Q--){
		int k;
		cin>>k;
		ll ans=0;
		ll d=0,m=0,dm=0;
		//Sを前から見る
		for(int i=0;i<N;i++){
			if(i-k>=0 && S[i-k]=='D'){
				d--;
				dm-=m;
			}
			if(S[i]=='D')
				d++;
			if(S[i]=='M'){
				dm+=d;
				m++;
			}
			if(i-k>=0 && S[i-k]=='M')
				m--;
			if(S[i]=='C')
				ans+=dm;

			//cout<<S[i]<<" "<<d<<" "<<m<<" "<<dm<<endl;
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1412
import numpy as np

if __name__ == "__main__":

	N,K = map(int,input().split())
	P = [ int(p)-1 for p in input().split() ]
	C = list(map(int,input().split()))

	# print(P)
	# 一度計算したサイクル情報をキャッシュしておくための配列
	cycleIDs = np.full( N, -1, np.int64 )
	cycleInfs = []
	cycleID = 0
	procCnt = 0

	for n in range(N):
		v = n

		if cycleIDs[v] != -1:
			continue
		else:
			currentCycleCosts = []
			while True:
				# 全頂点について、属するサイクルを計算する
				currentCycleCosts.append( C[v] )
				cycleIDs[v] = cycleID

				v = P[v]
				if cycleIDs[v] != -1:
					# サイクル終了
					# ループを含めない最大の処理回数
					procCnt = K % len( currentCycleCosts )
					# それで足りてるのかわからないが、Last2周分は、ループするものとして確定させない
					# その部分は、ちゃんと計算する
					# -------------------------------------------------
					# 4 101
					# 2 3 4 1
					# 50 -49 -50 50
					# 上記のようなパターンの場合、
					# 最大25回ループ + 1回処理可能だが、その場合、25 + 50 = 75
					# 24回ループ + 2回処理でやめると、124になる
					# 無条件でループする回数は、最大の回数だけでなく、
					# 最大の回数-1も考慮の必要あり
					# -------------------------------------------------
					# あるいは、割り切れて、尚且つサイクル合計がマイナスのパターンで、最低１個は処理するのにもここで対応
					if len( currentCycleCosts ) + procCnt <= K:
						procCnt += len( currentCycleCosts )

					cycleInfs.append( ( procCnt, len(currentCycleCosts), np.array( currentCycleCosts + currentCycleCosts ) ) )
					cycleID += 1
					break



	# scores = []
	# procCnt = 0
	ans = -10 ** 9
	for procCnt, currentCycleSize, currentCycleCosts in cycleInfs:

		# サイクル内でループしてスコアを稼ぐ場合の考慮
		loopScore = 0
		fullMinus1CntLoopScore = 0
		if np.sum(currentCycleCosts) > 0:
			cycleLoopCnt =  ( K - procCnt ) // currentCycleSize
			loopScore = cycleLoopCnt * np.sum(currentCycleCosts[:currentCycleSize])
			# print("loopScore",loopScore,procCnt)

		# このサイクルに属する全頂点分をまとめて計算する
		for i in range(currentCycleSize):
			# scores.append( np.roll( currentCycleCosts, i )[:procCnt].cumsum().max() + loopScore )
			# print(np.roll( currentCycleCosts, i ).cumsum()[:procCnt])
			ans = max( ans, np.roll( currentCycleCosts, i ).cumsum()[:procCnt].max() + loopScore )


	print(ans)
	# print(max(scores))


Measured memory_bytes: 28212
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 26;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int V;
vector<int> G[1024];

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

int match[1024];
bool used[1024];
void add_edge(int u, int v)
{
    G[u].push_back(v);
    G[v].push_back(u);
}

bool dfs(int v)
{
    used[v] = true;
    rep(i, G[v].size())
    {
        int u = G[v][i];
        int w = match[u];
        if (w < 0 || !used[w] && dfs(w))
        {
            match[v] = u;
            match[u] = v;
            return true;
        }
    }
    return false;
}

int bipartite_matching()
{
    int res = 0;
    memset(match, -1, sizeof(match));
    rep(v, V)
    {
        if (match[v] < 0)
        {
            memset(used, 0, sizeof(used));
            if (dfs(v))
                res++;
        }
    }
    return res;
}

void solve(int m, int n)
{
    V = n + m;
    rep(i, 1024)
    {
        G[i].clear();
    }
    vector<int> blue(m);
    vector<int> red(n);
    rep(i, m) cin >> blue[i];
    rep(i, n) cin >> red[i];
    rep(i, n) rep(j, m)
    {
        if (gcd(blue[j], red[i]) != 1)
        {
            //  cerr << i << " " << n + j << endl;
            add_edge(i, n + j);
        }
    }
    cout << bipartite_matching() << endl;
}

int main()
{
    int m, n;
    while (cin >> m >> n, n)
    {
        solve(m, n);
    }
    return 0;
}


Measured memory_bytes: 4960
import sys

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

K = int(input())
A, B = map(int, input().split())

ok = False
for i in range(A, B + 1):
    if i % K == 0:
        ok = True


if ok:
    print("OK")
else:
    print("NG")



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

#define X first
#define Y second
int dp[16][16];

bool bx[16][16];
bool by[16][16];

int main()
{
	int T;
	cin >> T;
	while (T--)
	{
		int GX, GY, P;
		cin >> GX >> GY >> P;
		
		memset(bx, 0, sizeof(bx));
		memset(by, 0, sizeof(by));

		for (int i=0; i<P; i++)
		{
			int x1, x2, y1, y2;
			cin >> x1 >> y1 >> x2 >> y2;

			if (x1==x2)
				by[min(y1, y2)][x1] = 1;
			else
				bx[y1][min(x1, x2)] = 1;
		}

		memset(dp, 0, sizeof(dp));
		dp[0][0] = 1;

		for (int y=0; y<=GY; y++)
		for (int x=0; x<=GX; x++)
		{
			if (x < GX && !bx[y][x])
				dp[y][x+1] += dp[y][x];

			if (y < GY && !by[y][x])
				dp[y+1][x] += dp[y][x];

		}

		if (dp[GY][GX] != 0)
			cout << dp[GY][GX] << endl;
		else
			cout << "Miserable Hokusai!" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
a,b,c = map(int, input().split(" "))
k = (int)(input())
while(k != 0):
  if a >= b:
    b *= 2
    k -= 1
  else:
    break
while(k != 0):
  if b >= c:
    c *= 2
    k -= 1
  else:
    break
if a < b < c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 61736
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, m;
    map<ll,ll>mp;
    string s;
    cin >> s;
    n = s.size();
    m = 2019;
    reverse(s.begin(),s.end());
    mp[0] = 1;
    ll now = 0;
    ll ans = 0;
    ll cur = 1;
    int ptr = n;
    for (auto i:s) {
        if (m == 2 || m == 5) {
            if ((i - '0') % m == 0) {
                ans += ptr;
            }
            ptr--;
            continue;
        }
        cur *= 10;
        cur %= m;
        now += (i - '0') * cur;
        now %= m; 
        ans += mp[now];
        mp[now]++;
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string.h>
#include<cstdlib>
#include<map>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<cmath>

using namespace std;

long long dp[3][100100] = {};
const long long INF = 1LL << 60;
#define MOD 1000000007

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

/**
* @fn
* 最大値を取ります.Vector<int>を渡すこと.
*/
long long int imax(vector<int> a) {
	int MAX = -10000000;
	for (int i = 0; i < a.size(); i++) {
		if (MAX < a.at(i)) MAX = a.at(i);
	}
	return MAX;
}

/**
* @fn
* 最小値を取ります.Vector<int>を渡すこと.
*/
long long int imin(vector<int> a) {
	int MIN = 1000000000;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
	}
	return MIN;
}


long long int absmin(vector<int> a, long long int b) {
	int mini = 100000000;
	int d = 0;
	for (int i = 0; i < a.size(); i++) {
		if (mini > abs(a.at(i) - b)) {
			mini = abs(a.at(i) - b);
			d = i;
		}
	}
	return d;
}

int gcd(int a, int b)
{
	if (a < b) swap(a, b);
	if (b < 1) return -1;
	if (a % b == 0) return b;
	return gcd(b, a % b);
}

//ここまでライブラリ
//ここから本文

long long int tpimin(vector<int> a) {
	int MIN = 1000000000;
	int number = 0;
	for (int i = 0; i < a.size(); i++) {
		if (MIN > a.at(i)) MIN = a.at(i);
		number = i;
	}
	return number;
}
int dore(char a) {
	return a - 'a';
}


int main() {
	vector<string> a(3);
	cin >> a.at(0) >> a.at(1) >> a.at(2);
	int ima = 0;
	int ima2 = 0;
	while (true) {
		if (a.at(ima).length() == 0) {
			cout << (char)(ima + 'A') << endl;
			return 0;
		}
		ima2 = dore(a.at(ima).at(0));
		a.at(ima).erase(a.at(ima).begin());

//		cout << "A:" <<a.at(0) << " B:" << a.at(1) << " C:" << a.at(2) << endl;
		ima = ima2;
	}
}

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

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

Measured memory_bytes: 3088
A, B, K = [int(i) for i in input().split()]
result_list = []

def divisor_list(n):
    i = 1
    array = []
    while i * i <= n:
        if n % i == 0:
            array.append(i)
            array.append(n//i)
        i += 1
    array = list(set(array))
    return array

for i in divisor_list(A):
    for j in divisor_list(B):
        if i == j:
            result_list.append(i)

print(sorted(result_list)[-K])

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

#ifdef WIN32
    #define lld "%I64d"
#else
    #define lld "%lld"
#endif

#define mp make_pair
#define pb push_back
#define put(x) { cout << #x << " = "; cout << (x) << endl; }

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef double db;

const int M = 1e6 + 15;
const int Q = 1e9 + 7;

ll a[M];
ll su[M], val[M], pr_ma[M], su_ma[M];

int main() {
    srand(time(NULL));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	reverse(a, a + n);
	su[n] = 0;
	for (int i = n - 1; i >= 0; i--) su[i] = su[i + 1] + 2 * a[i];
	for (int i = n - 1; i >= 0; i--) val[i] = a[i] - su[i + 1];
	su_ma[n - 1] = val[n - 1];
	pr_ma[0] = val[0]; 
	for (int i = 1; i < n; i++) pr_ma[i] = max(pr_ma[i - 1], val[i]);
	for (int i = n - 2; i >= 0; i--) su_ma[i] = max(su_ma[i + 1], val[i]);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (i && pr_ma[i - 1] > 0) continue;
		if (i < n - 1 && su_ma[i + 1] > 2 * a[i]) continue;
		ans++;
	}
	cout << ans << endl;


    return 0;
}   

Measured memory_bytes: 13312
#include <iostream>
using namespace std;
int card[255][14]={{0}};
int main(void){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        char c;
        int num;
        cin>>c>>num;
        card[(int)c][num]=1;
    }
    for(int i=1;i<=13;i++){
        if(card[(int)'S'][i]==0){
            cout<<"S "<<i<<endl;
        }
    }
    for(int i=1;i<=13;i++){
        if(card[(int)'H'][i]==0){
            cout<<"H "<<i<<endl;
        }
    }
    for(int i=1;i<=13;i++){
        if(card[(int)'C'][i]==0){
            cout<<"C "<<i<<endl;
        }
    }
    for(int i=1;i<=13;i++){
        if(card[(int)'D'][i]==0){
            cout<<"D "<<i<<endl;
        }
    }
}


Measured memory_bytes: 3076
from sys import stdin, stdout
input = stdin.readline
print = stdout.write

import heapq as hq
pq = []
hq.heapify(pq)
n, m = map(int, input().split())
arr = []
for _ in range(n):
    a, b = map(int, input().split())
    arr.append((a, b))
arr = sorted(arr, key=lambda x: x[0])
i = 0
ans = 0
for d in range(1, m + 1):
    while i < n and arr[i][0] <= d:
        hq.heappush(pq, -arr[i][1])
        i += 1
    if pq:
        ans -= hq.heappop(pq)
print(str(ans))


Measured memory_bytes: 65884
i=61,c,f[],m,x,s;main(y){for(;s?++f[y*12+x+"=>?2J13IK<@V&"[--s]]:~scanf("%d,%d,%d",&x,&y,&s)?s=s*4+1:++i<180?i%12>1?m=fmax(m,f[i]),f[i]||++c:1:!printf("%d\n%d\n",c,m););}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

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

int gcd(int a, int b){
    while( b ){
        int m = a % b;
        a = b;
        b = m;
    }
    return a;
}

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

int isPrim(int a){
    if(a==1){
        return 0;
    }
    for(int i=2;i<=(a+1)/2;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}

long long mod_pow(long long x, long long n, long long mod){
    //xのn乗を計算するのにn乗を2進表記にして計算
    //x^22 = x^16 + x^4 + x^2
    long long ret=1;
    while(n>0){
        if(n%2==1){
            ret=(ret*x)%mod;//答えに付加
        }
        x=(x*x)%mod;//2乗
        n=n/2;
    }
    return ret;
}

struct VV{
    int x;
    int y;
    int z;
};

class LessInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        if(riLeft.x == riRight.x){
            return riLeft.y > riRight.y;
        }
        return riLeft.x > riRight.x;
        
    }
};

class indInt {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        return riLeft.x < riRight.x;
        
    }
};

struct XX{
    int zenbu=0;
    int kidoku=0;
};

class xxIntu {
public:
    bool operator()(const VV& riLeft, const VV& riRight) const {
        //第1条件
        if(riLeft.z != riRight.z){
            return riLeft.z < riRight.z;//<:昇順(小さい順)、>:降順(大きい順)
        }
        //第2条件
        return riLeft.x < riRight.x;
    }
};
bool operator< (const VV &riLeft, const VV &riRight){
    return riLeft.z < riRight.z;
};
/*bool operator> (const XX &riLeft, const XX &riRight){
    return riLeft.a > riRight.a;
};*/



int main(int argc, const char * argv[])
{
    //std::ios::sync_with_stdio(false);
    //scanf("%s",S);
    //scanf("%d",&N);
    //getline(cin, target);
    //cin >> x >> y;
    //ここから
    
    int N;
    cin >> N;
    int a[100000];
    map<int,int> b;
    b.clear();
    for(int i=0;i<N;i++){
        cin >> a[i];
        b.insert(map<int,int>::value_type(a[i],i));
    }
    
    sort(a,a+N);
    int ans1=0;
    int ans2=0;
    for(int i=0;i<N;i++){

        int tmp=b[a[i]];
        
        if(i%2==0){
            if(tmp%2!=0){
                ans1++;
            }
        }else{
            if(tmp%2==0){
                ans2++;
            }
        }
    }
    int ans=ans1+ans2;
    
    cout << ans/2<< endl;
    
    //ここまで
    //cout << "ans" << endl;改行含む
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);
    //printf("%f\n",pow(2,ans.size()));
    
    return 0;
}

Measured memory_bytes: 5376
W, H, N = map(int, input().split())
sx, sy, ex, ey = 0, 0, W, H
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        sx = max([x, sx])
    elif a == 2:
        ex = min([x, ex])
    elif a == 3:
        sy = max([y, sy])
    else:
        ey = min([y, ey])

w, h = ex-sx, ey-sy
if w < 0 or h < 0:
    print(0)
else:
    print((ex-sx)*(ey-sy))


Measured memory_bytes: 38256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String s = new String(in.readLine());

		String[] strings = new String[4];
		strings = s.split("\\s+");

		BigDecimal d1 = new BigDecimal(strings[0]);
		BigDecimal d2 = new BigDecimal(strings[1]);
		BigDecimal d3 = new BigDecimal(strings[2]);
		BigDecimal d4 = new BigDecimal(strings[3]);

		BigDecimal left = d1.add(d2);
		BigDecimal right = d3.add(d4);

		if (left.compareTo(right) > 0) {
			System.out.println("Left");
		} else if (left.equals(right)) {
			System.out.println("Balanced");
		} else {
			System.out.println("Right");
		}

	}
}

Measured memory_bytes: 21588
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;

    cout << 2*b - a << endl;
}


Measured memory_bytes: 256
#include<iostream>

std::pair<char,bool> data[101][101];

int main(){
	int h,w;
	while(std::cin>>h>>w){
		if(w==0&&h==0)break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				std::cin>>data[i][j].first;
				data[i][j].second=false;
			}
		}
		int x=0,y=0;
		while(true){
			if(data[y][x].second){
				std::cout<<"LOOP"<<std::endl;
				break;
			}else data[y][x].second=true;

			if(data[y][x].first=='^')y--;
			if(data[y][x].first=='>')x++;
			if(data[y][x].first=='v')y++;
			if(data[y][x].first=='<')x--;

			if(data[y][x].first=='.'){
				std::cout<<x<<" "<<y<<std::endl;
				break;
			}
		}
	}
	return 0;
}

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

#define MIN_INT -2147483648
#define MAX_INT 2147483647
#define MIN_LONG -9223372036854775808L
#define MAX_LONG 9223372036854775807L

#define long long long int

using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> d(1 << n, MAX_INT);
    d[0] = 0;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        int x = 0;
        for (int j = 0; j < b; j++) {
            int y;
            cin >> y;
            x |= (1 << (y - 1));
        }
        for (int j = 0; j < d.size(); j++) {
            if (d[j] < MAX_INT) {
                d[j | x] = min(d[j | x], d[j] + a);
            }
        }
    }
    if (d.back() == MAX_INT) {
        cout << -1;
    } else {
        cout << d.back();        
    }
    

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int num, k;
	int digit;

	scanf("%d%d", &num, &k);

	digit = 1;
	while(num / k != 0)
	{
		num = num / k;
		digit++;
	}
	printf("%d\n", digit);
	return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const ll INF = 1LL << 60;

int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];

    for(int i=0; i<n-k; i++){
        if(a[i]>=a[i+k]){
            cout << "No" << endl;
        }
        else cout << "Yes" << endl;
    }
}

Measured memory_bytes: 4840
"""
https://atcoder.jp/contests/abc165/tasks/abc165_c

C - Many Requirements /

制約
2 <= N <= 10
1 <= N <= 10
1 <= Q <= 50
"""
from collections import deque

deq = deque()
al = []

def solve(n,m,q,x):

    max = 0

    for a_list in al:
        cnt = 0
        for a in x:
            if a_list[ a[1]-1 ] - a_list[ a[0]-1 ] == a[2]:
                cnt += a[3]
        if max < cnt:
            max = cnt

    return max

if __name__ == '__main__':
    n, m, q = map(int, input().split())
    x = [list(map(int, input().split())) for i in range(q)]

    #初期値を設定
    deq.append([1])

    #解になる可能性のある数列を生成
    while(deq):
        item = deq.popleft()
        if len(item) != n:
            for i in range(item[-1],m+1):
                deq.append(item + [i])
        else:
            al.append(item)

    #print(*al, sep='\n')
    ans = solve(n,m,q,x)

    print(ans)


Measured memory_bytes: 17092
#include<stdio.h>

#define N 10000

int main(void){
	int n,max,min,i,j=0;
	int a[N]={0};
	long sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		if(i>0)scanf(" ");
		scanf("%d",&a[i]);
	}
	min=a[0];
	max=a[0];
	for(j=0;j<n;j++){
		if(a[j]<min)min=a[j];
		if(a[j]>max)max=a[j];
		sum=sum+a[j];
		}  
		printf("%d %d %ld\n",min,max,sum);
return 0;
}


Measured memory_bytes: 2100