akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

const lint mod = 1e9 + 7;

typedef struct Segtree_min{
    int n = 1;
    vector<int> node;

    Segtree_min(int n_){
        while(n < n_) n *= 2;
        node.resize(2*n-1, mod);
    }

    void update(int i, int x){
        i += n-1;
        node[i] = x;
        while(i){
            i = (i-1) / 2;
            node[i] = min(node[i*2+1], node[i*2+2]);
        }
    }

    int getmin(int a, int b, int i, int l, int r){
        if(r<=a || b<=l) return mod;
        if(a<=l && r<=b) return node[i];
        int vl = getmin(a, b, i*2+1, l, (l+r)/2);
        int vr = getmin(a, b, i*2+2, (l+r)/2, r);
        return min(vl, vr);
    }
}Segtree_min;

typedef struct Segtree_max{
    int n = 1;
    vector<int> node;

    Segtree_max(int n_){
        while(n < n_) n *= 2;
        node.resize(2*n-1, -mod);
    }

    void update(int i, int x){
        i += n-1;
        node[i] = x;
        while(i){
            i = (i-1) / 2;
            node[i] = max(node[i*2+1], node[i*2+2]);
        }
    }

    int getmax(int a, int b, int i, int l, int r){
        if(r<=a || b<=l) return -mod;
        if(a<=l && r<=b) return node[i];
        int vl = getmax(a, b, i*2+1, l, (l+r)/2);
        int vr = getmax(a, b, i*2+2, (l+r)/2, r);
        return max(vl, vr);
    }
}Segtree_max;

int main(){
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> p(n), d(n-1);
    rep(i, n) scanf("%d", &p[i]);
    rep(i, n-1) d[i] = p[i+1] - p[i];

    Segtree_min stmin(n), stdif(n-1);
    Segtree_max stmax(n);
    rep(i, n){
        stmin.update(i, p[i]);
        stmax.update(i, p[i]);
        if(i < n-1) stdif.update(i, d[i]);
    }

    int ans = n-k+1;
    bool flag[n-k+1];
    int cnt = 0;
    rep(i, n-k+1){
        flag[i] = stdif.getmin(i, i+k-1, 0, 0, stdif.n) >= 0;
        if(flag[i]) ++cnt;
    }
    ans -= max(0, cnt-1);

    rep(i, n-k){
        int m = stmin.getmin(i+1, i+k, 0, 0, stmin.n);
        int M = stmax.getmax(i+1, i+k, 0, 0, stmax.n);
        if((!flag[i] || !flag[i+1]) && p[i] < m && M < p[i+k]) --ans;
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 8192
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int h[1005] = { 0 };
int main()
{
	int n;
	cin >> n;
	for (int i = 2; i <= n; i++) {//ｎまでのそれぞれの数字iについて
		int k = i;
		for (int j = 2; j <= i; j++) {//iがjで割り切れるなら割り，h[j]を増やす
			
			while (k%j == 0) { 
				k = k / j;
				h[j]++;
			}
		}
		//cout << h[2] << " " << h[3] << " " << h[4] << " " << h[5] << " " << h[6] << endl;//////////////////////////////////////////
	}
	long ans = 1;
	for (int i = 2; i <= n; i++) {
	ans *=( h[i] + 1);
		if (ans > 1000000007)ans = ans % 1000000007;
	}
//	cout << h[2]<<" " <<h[3]<<" "<<h[4]<<" "<<h[5]<<" "<<h[6]<< endl;//////////////////////////////////////////
	cout << ans << endl;
}

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

dict = {}
max_count = 0
for i in range(n):
  input_line = input()
  if input_line in dict:
    dict[input_line] += 1
  else:
    dict[input_line] = 1
  if max_count < dict[input_line]:
    max_count = dict[input_line]

keys = [k for k, v in dict.items() if v == max_count]
keys.sort()
print("\n".join(keys))

Measured memory_bytes: 34140
#include <iostream>
#include <vector>
using namespace std;
struct bit{
	int size=1;
	vector<int> node;
	bit(){
		while(size<500000){
			size<<=1;
		}
		node.resize(size+1,0);
	}
	void add(int k,int a){
		k++;
		while(k<=size){
			node[k]+=a;
			k+=k&-k;
		}
	}
	int query(int k){
		int res=0;
		while(k){
			res+=node[k];
			k-=k&-k;
		}
		return res;
	}
};
int main(){
	int n;
	cin>>n;
	bit nii[26];
	string s;
	cin>>s;
	for(int i=0;i<n;i++){
		nii[s[i]-'a'].add(i,1);
	}
	int q;
	cin>>q;
	while(q--){
		int t;
		cin>>t;
		if(t==1){
			int i;
			cin>>i;
			i--;
			char c;
			cin>>c;
			nii[s[i]-'a'].add(i,-1);
			s[i]=c;
			nii[s[i]-'a'].add(i,1);
		}else{
			int l,r;
			cin>>l>>r;
			l--;
			r--;
			int ans=0;
			for(int i=0;i<26;i++){
				ans+=(nii[i].query(r+1)-nii[i].query(l)>0?1:0);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 54276
#include<iostream>


using namespace std;
int n,x,sum;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(x%2==1) continue ;
		else
		{
			while(x>=2 && x%2!=1)
			{
				x/=2;
				sum++;
			}
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
inline int GCD(int a, int b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

int main()
{
    string S;
    cin >> S;
    int cnt = 0;
    int ans = 0;
    rep (i, S.size())
    {
        if (S.at(i) == 'A' || S.at(i) == 'T' || S.at(i) == 'C' || S.at(i) == 'G')
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if (ans < cnt)
        {
            ans = cnt;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <utility>
#include <typeinfo>
#include <string>
#include <sstream>

using namespace std;

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

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

    vector<char> vec;
    vec.push_back(S[0]);
    ll count = 0;
    for (int i = 1; i < S.length(); ++i) {
        if (vec.size() == 0) {
            vec.push_back(S[i]);
        } else if (vec.front() != S[i]) {
            count += 2;
            vec.pop_back();
        } else {
            vec.push_back(S[i]);
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=3e5+20;
int n,m,c[N];
//题意:Bus从0出发,最多走到M(M<=1e5),每逢kd停下来一次(k,d为常数),有N(N<=1e5)个产品,购买范围为[li,ri],问d取1~M时,分别能买到多少个产品?
//任意一个d把区间分成 M/d段,容易发现若区间长度>=d 则bus至少停在该区间内一次.
//如果区间长度<d 只有当某个kd落在[li,ri]内才有可能停在该区间内,利用树状数组和差分,覆盖区间后,统计l<d的区间个数即可 
struct node{
	int l,r,len;
}a[N];
bool cmp(node a,node b)
{
	return a.len<b.len;
}
void update(int j,int k)
{
	for(int i=j;i<=m;i+=(i&-i))
		c[i]+=k;
}
int sum(int j)
{
	int res=0;
	for(int i=j;i>=1;i-=(i&-i))
		res+=c[i];
	return res;
}
int main()
{
	while(cin>>n>>m)
	{
		memset(c,0,sizeof(c));//
		for(int i=1;i<=n;i++)
		{
			scanf("%d%d",&a[i].l,&a[i].r);
			a[i].len=a[i].r-a[i].l+1;
		}
		sort(a+1,a+n+1,cmp);
		int k=1;
		for(int d=1;d<=m;d++)
		{
			//O(m+nlogm)
			for(;k<=n&&a[k].len<d;k++)//最多n次 
			{
				update(a[k].l,1);
				update(a[k].r+1,-1);//差分,[1..li..kd..ri,ri+1...m] 树状数组统计前缀和 
			}
			int ans=n-k+1;//区间长度>=d个数 
			//O(mlogm)
			for(int e=d;e<=m;e+=d)
			{
				ans+=sum(e);
			}
			cout<<ans<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 5632
import sys
def main():
    input = sys.stdin.readline
    def inputs():
        return (int(x) for x in input().split())
    N,M = inputs()
    E={i:[] for i in range(1,N+1)}
    for i in range(M):
        L,R,D = inputs()
        E[L].append((R,D))
        E[R].append((L,-D))
    visited = {i: False for i in range(1,N+1)}
    dis = [0]*(N+1)
    for i in range(1,N+1):
        if not visited[i]:
            stk = [( i, -1, 0)]
            while stk:
                v, p, d = stk.pop()
                #print(v,p)
                if visited[v]:
                    if dis[v]!=dis[p]+d:
                        print("No")
                        exit()
                    continue
                visited[v] = True
                dis[v]=dis[p]+d
                for u,d in E[v]:
                    if u != p:
                        stk.append((u,v,d))
    print("Yes")
main()

Measured memory_bytes: 101604
#include <bits/stdc++.h>
template<typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int from, int to, T cost) {
        this->from = from;
        this->to = to;
        this->cost = cost;
    }
};
bool operator == (Edge<int> e1, Edge<int> e2) {
    return e1.from == e2.from &&
            e1.to == e2.to &&
            e1.cost == e2.cost;
}
template<typename T>
using Edges = std::vector<Edge<T>>;
template<typename T>
using Graph = std::vector<Edges<T>>;
template <typename T>
std::vector<T> dijkstra(const Graph<T> &g, int s) {
    int sz = (int)(g.size());
    std::vector<T> dist(sz, std::numeric_limits<T>::max());
    std::priority_queue<std::pair<T, int>, std::vector<std::pair<T, int>>, std::greater<std::pair<T, int>>> pq;
    dist[s] = 0;
    pq.push({0, s});
    while(!pq.empty()) {
        T d = pq.top().first;
        int now = pq.top().second;
        pq.pop();
        if(d > dist[now]) continue;
        for(int i=0;i<(int)(g[now].size());++i) {
            int next = g[now][i].to;
            T cost = g[now][i].cost;
            if(dist[next] > dist[now] + cost) {
                dist[next] = dist[now] + cost;
                pq.push({cost, next});
            }
        }
    }
    return dist;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int main() {
  cin.tie(0);
  cout << fixed << setprecision(10);
  while(1) {
    int w, h; cin >> w >> h;
    if(w == 0) break;
    vvi s(h, vi(w));
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
        cin >> s[i][j];
      }
    }
    vi c(4);
    for(int i=0;i<4;++i) {
      cin >> c[i];
    }
    Graph<int> g(4*h*w);
    for(int i=0;i<h;++i) {
      for(int j=0;j<w;++j) {
        for(int k=0;k<4;++k) {
          for(int l=0;l<4;++l) {
            if(!(0 <= i+dx[l] && i+dx[l] < h && 0 <= j+dy[l] && j+dy[l] < w)) continue;
            int diff = (l + 4 - k) % 4;
            if(s[i][j] == diff) {
              g[4*w*i + 4*j + k].push_back(Edge<int>(4*w*i + 4*j + k, 4*w*(i+dx[l]) + 4*(j+dy[l]) + l, 0));
            } else {
              g[4*w*i + 4*j + k].push_back(Edge<int>(4*w*i + 4*j + k, 4*w*(i+dx[l]) + 4*(j+dy[l]) + l, c[diff]));
            }
          }
        }
      }
    }
    vector<int> dist = dijkstra(g, 0);
    cout << min(dist[(int)(dist.size())-3], dist[(int)(dist.size())-4]) << endl;
  }
}



Measured memory_bytes: 3372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		Dice dice1 = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
		Dice dice2 = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
		String hantei = "No";

		String shijirow = "EEENEEENEEESEEESEEENEEEN";
		for(int i =0; i<shijirow.length(); i++) {
			if(dice2.equals(dice1)) {
				hantei="Yes";
				break;
			}
			dice1.roll(shijirow.charAt(i));
		}
		System.out.println(hantei);
	}
}

class Dice {
	int up =1;
	int front = 2;
	int left = 3;
	int right = 4;
	int back = 5;
	int down = 6;

	Dice(){};

	Dice(int up,int front,int left,int right, int back, int down){
		this.up = up;
		this.front = front;
		this.left =left;
		this.right = right;
		this.back = back;
		this.down = down;

	}


	void roll(char Shiji) {
		int  tmp;
		switch(Shiji) {
		case 'N':{
			tmp = up;
			this.up = this.front;
			this.front = this.down;
			this.down = this.back;
			this.back = tmp;
			break;
		}
		case 'E':{
			tmp = this.up;
			this.up = this.right;
			this.right = this.down;
			this.down = this.left;
			this.left = tmp;
			break;
		}
		case 'W':{
			tmp = this.up;
			this.up = this.left;
			this.left = this.down;
			this.down = this.right;
			this.right = tmp;
			break;
		}
		case 'S':{
			tmp = this.up;
			this.up = this.back;
			this.back = this.down;
			this.down = this.front;
			this.front = tmp;
			break;
		}
		}

	}
	 public boolean equals(Object obj) {
		 Dice other = (Dice) obj;

		 // booleanの場合は==で比較する
		 if (up != other.up) {
		 return false;
		 }

		 // byteの場合は==で比較する
		 if (front != other.front) {
		 return false;
		 }

		 // charの場合は==で比較する
		 if (left != other.left) {
		 return false;
		 }

		 // shortの場合は==で比較する
		 if (right != other.right) {
		 return false;
		 }

		 // intの場合は==で比較する
		 if (back != other.back) {
		 return false;
		 }

		 // longの場合は==で比較する
		 if (down != other.down) {
		 return false;
		 }
		 return true;
	 }
}



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

int main()
{
  int N;
  int A[100];
  int alice=0;
  int bob=0;

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

  for(int i=0;i<=N;i++){
    for(int j=i;j<N;j++){
      if(A[i]<A[j]){
        int tmp = A[i];
        A[i] = A[j];
        A[j] = tmp; 
      }
    }
  }
  for(int i=0;i<N;i++){
    if(i%2==0){
      alice+=A[i];
    }else{
      bob+=A[i];
    }
  }
  cout << alice-bob << endl;

  return 0;
}

Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;

static const int MAXN=100005;
struct BIT{
  int val[MAXN*2+2];
  int n;
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    REP(i,n+1) val[i]=0;
  }
  void add(int k,int a){
    ++k;
    while(k<=n){
      val[k]+=a;
      k+=k&-k;
    }
  }
  int query(int k){ //[0,k)
    int res=0;
    while(k>0){
      res+=val[k];
      k-=k&-k;
    }
    return res;
  }
};

BIT bit;

int n,m;
pi range[300005];

int res[100005];
pair<pi,int> subt[2000000];
int main(){
  cin>>n>>m;
  REP(i,n) scanf("%d%d",&range[i].fr,&range[i].sc);

  int cnt=0;
  for(int i=1;i<=m;++i){
    res[i]=n;
    for(int j=0;j<m;j+=i){
      int nxt=j+i;
      subt[cnt++]={{j+1,nxt-1},i};
    }
  }
  sort(subt,subt+cnt);
  sort(range,range+n);
  bit.init(m+1);
  int j=n-1;
  for(int i=cnt-1;i>=0;--i){
    int x=subt[i].fr.fr,y=subt[i].fr.sc;
    while(j>=0 && range[j].fr>=x){
      bit.add(range[j].sc,1);--j;
    }
    int id=subt[i].sc;
    res[id]-=bit.query(y+1);
  }
  REP(i,m) printf("%d\n",res[i+1]);
  return 0;
}





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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

// Library
//

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int a,b; cin >> a >> b;
    if(a%2 == 0 || b%2 == 0){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}


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

int main()
{
	int n,k;
	cin>>k>>n;
	int a[n+1];
	
	for(int i=1;i<=n;i++)
		cin>>a[i];
		
	int minv=0x7fffffff;
	int x;
	
	x=a[n]-a[1];
	minv=min(minv,x);
	x=a[1]-a[2]+k;
	minv=min(minv,x);
	
	for(int i=1;i<=n;i++)
	{
		x=k-a[i]+a[i-1];
		minv=min(minv,x);
	}
	cout<<minv<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
using namespace std;

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if (A < B){
        if (A < C && C < B) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        if(B < C && C < A) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,ans=0;
	cin>>n;
	vl rm;
	vl a(n),b(n);
	rep(i,n)cin>>a[i];
	rep(i,n)cin>>b[i];
	ll lc=0,lcp=0;
	rep(i,n){
		if(a[i]<b[i])lc++,lcp+=b[i]-a[i];
		else if(a[i]>b[i]){
			rm.push_back(a[i]-b[i]);
		}
	}
	sort(all(rm),greater<ll>());
	ll r=0;
	for(int i=0;i<rm.size()&&lcp>0;i++){
		lcp-=rm[i];
		r++;
	}
	if(lcp>0)cout<<"-1"<<endl;
	else {
		cout<<r+lc<<endl;
	}
}

 

Measured memory_bytes: 2428
#include<iostream>
#define ll long long
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    ll n,w;
    cin>>n>>w;
    vector<vector<ll>> knapsack(n);
    ll temp;
    ll total = 0;
    for(ll i=0; i<n; ++i)
    {
        cin>>temp;
        knapsack[i].push_back(temp);
        cin>>temp;
        total += temp;
        knapsack[i].push_back(temp);

    }

    vector<ll> *ptr1 = new vector<ll> (total+1, 1000000000+1);
    vector<ll> *ptr2 = new vector<ll> (total+1, 1000000000+1);

    //sort(knapsack.begin(), knapsack.end());
    (*ptr1)[0] = 0;
    for(ll i=0; i<n; ++i)
    {
        (*ptr2)[0] = 0;
        for(ll j=1; j<=total; ++j)
        {
            if(knapsack[i][1] <= j)
            {
                if((*ptr1)[j-knapsack[i][1]] != 1000000000+1)
                {
                    (*ptr2)[j] = min((*ptr1)[j], knapsack[i][0] + (*ptr1)[j-knapsack[i][1]]);
                }
                else
                {
                    (*ptr2)[j] = (*ptr1)[j];
                }

            }
            else
            {
                (*ptr2)[j] = (*ptr1)[j];
            }
        }
        if(i != n-1)
        {
            vector<ll> *temp = ptr1;
            ptr1 = ptr2;
            ptr2 = temp;
        }
    }
    ll ans = 0;
    for(ll i=0; i<=total; ++i)
    {
        //cout<<(*ptr2)[i]<<endl;
        if((*ptr2)[i] <= w)
        {
            ans = i;
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

const ll M=1e9+7;
const int N=2e3+10;

ll myPow(ll a,ll n)
{
    ll ans=1;
    while(n>0)
    {
        if(n&1)
        {
            ans=ans*a%M;
        }
        a=a*a%M;
        n>>=1;
    }
    return ans;
}

ll fac[N],inv[N];

void init()
{
    fac[0]=1;
    for(int i=1;i<N;i++)
    {
        fac[i]=fac[i-1]*i%M;
    }
    inv[N-1]=myPow(fac[N-1],M-2);
    for(int i=N-2;i>=0;i--)
    {
        inv[i]=inv[i+1]*(i+1)%M;
    }
}

ll C(int n,int m)
{
    if(n<m) return 0;
    return fac[n]*inv[n-m]%M*inv[m]%M;
}

int main()
{
    init();
    int n,k;
    while(cin>>n>>k)
    {
        cout<<C(n-1,k-1)<<endl;
    }

    return 0;
}




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

int n,m,a;
int gi;

int main(void){
	while(cin>>n,n){
		std::vector<int> day[31];
		std::list<int> member[51];
		for(int i=0;i<n;i++)member[i].push_front(i);
		for(int i=0;i<n;i++){
			cin>>m;
			for(int j=0;j<m;j++){
				cin>>a;
				day[a].push_back(i);
			}
		}

		for(int gi=0;gi<31;gi++){
			if(day[gi].size()<=1)continue;
			for(int i=1;i<day[gi].size();i++) member[day[gi][0]].merge(member[day[gi][i]]);
			member[day[gi][0]].unique();
			if(member[day[gi][0]].size()==n){
				cout<<gi<<endl;
				goto LAB;
			}
			for(int i=1;i<day[gi].size();i++) member[day[gi][i]]=member[day[gi][0]];
		}
		cout<<"-1"<<endl;
LAB:;
	}
	return 0;
}

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

int main() {
  int a, cnt;

  cin >> a;

  if (a >= 100) {
    cnt++;
    a -= 100;
  }
  if (a >= 10) {
    cnt++;
    a -= 10;
  }
  if (a >= 1) {
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int n, q;
    cin >> n;
    VI A(n);
    REP(i,n) cin >> A[i];
    cin >> q;
    VI m(q);
    REP(i,q) cin >> m[i];

    map<int, int> sum;
    int temp;
    REP(bit,1<<n){
        temp = 0;
        REP(i,n){
            if (bit & (1<<i)){
                temp += A[i];
            }
            sum[temp] = 1;
        }
    }

    REP(i,q){
        if(sum[m[i]]){
            cout << "yes" << endl;
        }
        else{
            cout << "no" << endl;;
        }
    }
}


Measured memory_bytes: 3160
N, M = map(int, input().split(' '))
L = []
R = []
for i in range(M):
    Li, Ri = map(int, input().split(' '))
    L.append(Li)
    R.append(Ri)

Lmax = 1
Rmin = N
for i in range(M):
    if Lmax < L[i]:
        Lmax = L[i]
    if Rmin > R[i]:
        Rmin = R[i]

num = Rmin - Lmax + 1
if num < 0:
    num = 0
print(num)

Measured memory_bytes: 11028
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	int p,q,r;
	class Token{
		/**
		 * 0 0 
		 * 1 1 
		 * 2 2
		 * + 3
		 * * 4
		 * p 5
		 * q 6
		 * r 7
		 * - 8
		 */
		int type;
		
		
		Token(String str){
			if(str.length() == 1){
				if(str.equals("0")){
					this.type = 0;
					return;
				}
				if(str.equals("1")){
					this.type = 1;
					return;
				}
				if(str.equals("2")){
					this.type = 2;
					return;
				}
				if(str.equals("P")){
					this.type = 5;
					return;
				}
				if(str.equals("Q")){
					this.type = 6;
					return;
				}
				if(str.equals("R")){
					this.type = 7;
					return;
				}
			}
			if(str.startsWith("-")){
				this.type = 8;
				this.child1 = new Token(str.substring(1));
				return;
			}
			int depth = 0;
			int tp = 0;
			for(int i = 1; i < str.length() - 1 ; i++){
				if(str.charAt(i) == '('){
					depth++;
					continue;
				}
				if(str.charAt(i) == ')'){
					depth--;
				}
				if(depth == 0){
					if(str.charAt(i) == '+'){
						this.type = 3;
						tp = i;
					}
					if(str.charAt(i) == '*'){
						this.type = 4;
						tp = i;
					}
				}
			}
			this.child1 = new Token(str.substring(1,tp));
			this.child2 = new Token(str.substring(tp+1,str.length()-1));
		}
		
		Token child1;
		Token child2;
		
		int getValue(){
			switch(type){
			case 0:
				return 0;
			case 1 :
				return 1;
			case 2 : 
				return 2;
			case 3 :
				return Math.max(child1.getValue() , child2.getValue());
			case 4 :
				return Math.min(child1.getValue() , child2.getValue());
			case 5 :
				return p;
			case 6 :
				return q;
			case 7 :
				return r;
			case 8 :
				return 2 - child1.getValue();
			}
			return -1;
		}
	}
	public void run() {
		Scanner sc = new Scanner(System.in);

	
		for (;;) {
			String in = sc.next();
			if(in.equals(".")){
				break;
			}
			int sum = 0;
			Token t = new Token(in);
			for(p = 0; p < 3; p++){
				for(q = 0; q < 3; q++){
					for(r = 0; r < 3; r++){
						if(t.getValue() == 2){
							sum++;
						}
					}					
				}				
			}
			System.out.println(sum);
		}

	}

	public static void main(String[] Aregs) {
		Main a = new Main();
		a.run();
	}
}

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

using namespace std;

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

    std::vector<long int> Ai;
    std::vector<long int> Bi;

    for (int i = 0; i < A; ++i) {
        long int temp;
        cin >> temp;
        Ai.push_back(temp);
    }

    for (int i = 0; i < B; ++i){
        long int temp;
        cin >> temp;
        Bi.push_back(temp);
    }



    long int price = *min_element(Ai.begin(),Ai.end()) + *min_element(Bi.begin(),Bi.end());


    for(int i = 0; i < M; ++i){
        long int xi,yi,ci;
        cin >> xi >> yi >> ci;

        long int temp_price;
        temp_price = Ai[xi-1] + Bi[yi-1] - ci;

        if(price > temp_price){
            price = temp_price;
        }
    }

    cout << price << endl;


    return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

int main() {
    string s; 
    cin >> s;
    vector<char> buf;
    for(char c: s) {
        if (c=='B') {
            if (buf.size()) buf.pop_back();
        } else buf.push_back(c);
    }
    string ret(buf.begin(), buf.end());
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
N= int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=0
for x in range(0,N):
    if A[x]-B[x]>0:
        C=C+B[x]
    elif A[x+1]<B[x]-A[x]:
        C=C+A[x]+A[x+1]
        A[x+1]=0
    else:
        A[x+1]=A[x+1]-(B[x]-A[x])
        C=C+B[x]
print(C)

Measured memory_bytes: 18476
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    long long k,sum1=0,sum2=0,sum3=0;
    while(cin>>s>>k)
    {
        sum1=0;
        sum2=0;
        sum3=0;
        int len=0;
        len=s.size();
        for(int i=0;i<len-1;i++)
        {
            if(s[i]==s[i+1])
            {
                sum1+=1;
                i++;
            }
        }
        s+=s;
        for(int i=0;i<(len*2)-1;i++)
        {
            if(s[i]==s[i+1])
            {
                sum2+=1;
                i++;
            }
        }
        s+=s;
         for(int i=0;i<(len*3)-1;i++)
        {
            if(s[i]==s[i+1])
            {
                sum3+=1;
                i++;
            }
        }



      long long total=0;
      sum3-=sum2;
      sum2-=sum1;
      //cout<<"sum1="<<sum1<<"  sum2="<<sum2<<" sum3="<<sum3<<endl;

      if(k==1)
      {
          cout<<sum1<<endl;
      }
      else
      {
            total+=sum1;
            total+=(k/2)*sum2;
            if(k%2==0)
            {
                total+=((k/2)-1)*sum3;
            }
            else
            {
                total+=(k/2)*sum3;
            }
            cout<<total<<endl;

      }



    }
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
Hs = list(mapint())+[0]

ans = 0
while 1:
    cnt = 0
    start = False
    for i in range(N+1):
        if Hs[i]!=0:
            start = True
            Hs[i] -= 1
        else:
            if start:
                cnt += 1
            start = False
    ans += cnt
    if sum(Hs)==0:
        break
print(ans)

Measured memory_bytes: 64956
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    string s;
    cin>>s;
    s.push_back('q');
    char c = 'w';
    vector<ll> lv,rv;
    ll l=0,r=0;
    ll tmp = 0;
    FOR(i,0,n+1){
      if(c != s[i]){
        if(c == 'L'){
          lv.push_back(2);
          l+=tmp;
        }
        else if(c == 'R'){
          rv.push_back(2);
          r+=tmp;
        }
        c = s[i];
        tmp = 0;
      }
      else tmp++;
    }
    if(s[0] == 'L' && s[n-1] == 'L'){
      lv[0]--;
      lv[1]--;
    }
    if(s[0] == 'L' && s[n-1] == 'R'){
      lv[0]--;
      rv[0]--;
    }
    if(s[0] == 'R' && s[n-1] == 'L'){
      lv[0]--;
      rv[0]--;
    }
    if(s[0] == 'R' && s[n-1] == 'R'){
      rv[0]--;
      rv[1]--;
    }

    ll ls = 0;
    ll rs = 0;
    sortAlr(lv);
    sortAlr(rv);
    FOR(i,0,min(m,(ll)lv.size()))ls += lv[i];
    FOR(i,0,min(m,(ll)rv.size()))rs += rv[i];
    if(lv.size() + rv.size() == 1)l--;
    cout<<max(ls,rs) + l+r<<endl;
//    cout<<l<<" "<<r<<" "<<ls<<" "<<rs<<" "<<lv.size()<<" "<<rv.size()<<endl;


}


Measured memory_bytes: 1356
#include <stdlib.h>     /* srand, rand */
#include <time.h>       /* time */
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
#include <iterator> 
using namespace std;

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);


#define PI 3.14159265

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

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//~ const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};

int main() { 
	string s; cin>> s;
	if (s.compare("ABC") == 0) {
		cout<< "ARC";
	}
	else
		cout<<"ABC";
	return 0;
} 




Measured memory_bytes: 3596
#!/usr/bin/env python3
import sys


def solve(S: str):
    count = 0
    answer = 0

    for i in range(len(S)):
        if S[i] == "W":
            count += 1
            answer += i+1-count
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3508
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
//大胆な気持ちで考える
//プラスはプラスのまま答えに足したいし
//マイナスはプラスにして答えに足したい
//でもx-yという操作をする必要があるので
//すべてをプラスにしたりマイナスにすることは絶対にできない
//必ず+と-の要素が必要
//つまり最大値と最小値を+と-に固定すれば，あとの数字はどのような
//符号の付け方でも良い
int main() {
    //ifstream in("23.txt");
    //cin.rdbuf(in.rdbuf());

    ll N;
    cin >> N;

    vector<ll > minus;
    vector<ll > plus;


    for(ll i = 0; i < N; i++){
        ll t; cin >> t;
        vec.push_back(t);
    }
    sort(vec.begin(), vec.end());

    ll sum = 0;
    //-から+に数字が分布しているならすべての符号を+にできる
    //A_N(最大でプラス) - (A_1(最小でマイナス) - プラスの奴ら ) - マイナスの奴ら
    //ですべての符号をプラスに揃えることができる！！！！
    for(ll i = 0; i < N; i++){
        sum += abs(vec[i]);
    }
    //-または+しか存在しない数列だとはみ出た分考慮する
    if(vec[0] > 0) sum -= vec[0] * 2;
    if(vec[vec.size()-1] < 0) sum += vec[vec.size()-1] * 2;

    cout << sum << endl;

    //操作を復元する
    //最小の値から操作していく
    ll tmp = vec[0];

    //まずはプラスのやつらを引いていく
    //ここ(A_1(最小でマイナス) - プラスの奴ら ) の操作
    for(ll i = 1; i < N - 1; i++){
        if(vec[i] >= 0){
            cout << tmp << " " << vec[i] << endl;
            //更新
            tmp -= vec[i];
        }
    }
    //次にマイナスの奴らを引いていく
    //A_N(最大でプラス) - (tmp) - マイナスの奴ら
    cout << vec[vec.size()-1] << " " << tmp << endl;
    tmp = vec[vec.size()-1] - tmp;
    for(ll i = 1; i < N - 1; i++){
        if(vec[i] < 0){
            cout << tmp << " " << vec[i] << endl;
            tmp -= vec[i];
        }
    }

}

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

#define fast_cin() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX 1000000
#define ll long long
#define db double
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)

#define vl vector<ll>
#define vs vector<string>

#define mapll map<ll,ll>
#define mapss map<string,string>
#define mapsl map<string,ll>
#define mapls map<ll,string>

#define pll pair<ll,ll>
#define pss pair<string,string>
#define psl pair<ll,string>
#define pls pair<string,ll>

#define minheap priority_queue<ll>
#define maxheap priority_queue<ll,vector<ll> ,greater<ll>>

#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
const ll mod=1e9 + 7;


ll takemod(ll a) {
    return ((a%mod)+mod)%mod;
}

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

ll fast_exp(ll base, ll expo) {
    ll res=1;
    while(expo>0) {
        if(expo&1) res=(res*base)%mod;
        base=(base*base)%mod;
        expo>>=1;}
    return res;
}

ll modinv(ll a) {
    return takemod(fast_exp(takemod(a), mod-2));
}

ll arr1[400][400];
ll visit[400][400];
ll ans,n,m;
ll val1,val2;

void dfs(ll x1,ll y1,ll count)
{
    if(x1>0 and arr1[x1][y1]!=arr1[x1-1][y1] and visit[x1-1][y1]==0)
    {
        if(arr1[x1-1][y1]==0)
            ++val2;
        else
            ++val1;
        visit[x1-1][y1]=count;
        dfs(x1-1,y1,count);
    }
    if(y1>0 and arr1[x1][y1]!=arr1[x1][y1-1] and visit[x1][y1-1]==0)
    {
        if(arr1[x1][y1-1]==0)
            ++val2;
        else
            ++val1;
        visit[x1][y1-1]=count;
        dfs(x1,y1-1,count);
    }
    if(x1+1<n and arr1[x1][y1]!=arr1[x1+1][y1] and visit[x1+1][y1]==0)
    {
        if(arr1[x1+1][y1]==0)
            ++val2;
        else
            ++val1;
        visit[x1+1][y1]=count;
        dfs(x1+1,y1,count);
    }
    if(y1+1<m and arr1[x1][y1]!=arr1[x1][y1+1] and visit[x1][y1+1]==0)
    {
        if(arr1[x1][y1+1]==0)
            ++val2;
        else
            ++val1;
        visit[x1][y1+1]=count;
        dfs(x1,y1+1,count);
    }
    return;
}

signed main() 
{
    fast_cin();
    
    cin>>n>>m;
    ans=0;
    ll count=1;
    For(i,0,n)
    {
        string s1;
        cin>>s1;
        For(j,0,m)
        {
            if(s1[j]=='.')
                arr1[i][j]=0;
            else
                arr1[i][j]=1;
            visit[i][j]=0;
        }

    }
    For(i,0,n)
    {
        For(j,0,m)
        {
            if(visit[i][j]==0)
            {
                val1=0;
                val2=0;
                visit[i][j]=count;
                if(arr1[i][j]==1)
                    ++val1;
                else
                    ++val2;
                dfs(i,j,count);
                ++count;
                ans+=(val1*val2);
            }

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

Measured memory_bytes: 17792
import math
n,y = map(int,input().split())
y = y//1000
k = math.ceil(2*(y-n)/9)
if k*4 <= (y-n) and 5*k <= y:
  print(-4*k+y-n,9*k-2*(y-n),y-5*k)
else:
  print(-1,-1,-1)

Measured memory_bytes: 39792
n = int(input())
s = [input() for _ in range(n)]
result = 0
for i in range(n):
    a = 1
    for x in range(n):
        if any(s[(x+i)%n][y] != s[(y+i)%n][x] for y in range(x, n)):
            a = 0
            break
    result += a
print(result*n)

Measured memory_bytes: 44636
/*Author : Sambhu show(jgec)*/
#include<bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define itc ll t;cin>>t;while(t--)
#define PI 3.141592653589793238
#define Max(a,b,c) max(a,max(b,c));
#define Min(a,b,c) min(a,min(b,c));
#define all(v) v.begin(),v.end()
#define ll long long int
#define ld long double
#define pb push_back
#define eb emplace_back
#define gcd(a,b) __gcd(a,b)
#define fi first
#define se second
#define endl "\n"
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int XX[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
ll price[85];
ll n;
void solve()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> price[i];

	ll s = 0, sum = 1000;
	for (int i = 1; i < n; i++)
	{
		if (price[i] > price[i - 1])
		{
			ll buy = sum / price[i - 1];
			s += buy;
			sum -= (buy * price[i - 1]);
			sum += price[i] * s;
			s = 0;
		}
	}
	cout << sum;
}
int main()
{
	fio
	//itc
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3680
module Main where

import Control.Applicative
import Control.Monad
import Control.Monad.State
import Data.Int
import qualified Data.ByteString.Lazy.Char8 as L

type Tokenizer = State [L.ByteString]

nextInt :: Tokenizer Int
nextInt = state $ \(s:ss) -> case L.readInt s of
                               Just (x, _) -> (x, ss)
                               Nothing -> error $ "Can't parse Int from: " ++ (L.unpack s)

solve :: [(Int64, Int64)] -> Int64
solve abs = foldr update 0 abs
    where update (a, b) steps | a' == 0 = steps
                              | otherwise = steps + b - a'
              where a' = (a + steps) `mod` b

go :: Tokenizer Int64
go = do
  n <- nextInt
  abs <- replicateM n $ do
           a <- nextInt
           b <- nextInt
           return (fromIntegral a, fromIntegral b)
  return $ solve abs

main :: IO ()
main = do
  contents <- L.words <$> L.getContents
  let result = evalState go contents
  print result


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

#define REP(i, n) for (int i = 0; i < n; i++)
int main(void)
{
    double d;
    cin >> d;
    d = 2 * 3.1415926535 * d;
    cout << fixed << setprecision(10) << d <<  endl;
}

Measured memory_bytes: 3788
#include<iostream>
using namespace std;
const int N=100+50;
char s[N];
int main ()
{
	int k;
	cin>>s>>k;
	int i;
	for(i=0;i<k;++i){
		if (s[i]=='1') continue;
		else{
			cout<<s[i]<<endl;
			break;
		   }
	   }
	if (i==k) cout<<"1"<<endl; 
}

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

set<char> aops[3];  // 演算子の優先順位

template<class T> struct Parser {
    typedef string::const_iterator State;

    T solve(const string &S) {
        State begin = S.begin();
        return expr(begin, 0);
    }

    T expr(State &begin, int depth) {
        if (depth == 3) return factor(begin);
        T ret = expr(begin, depth + 1);
        for (;;) {
            if (*begin == '+' && aops[depth].count('+')) {
                begin++;
                ret += expr(begin, depth + 1);
            } else if (*begin == '-' && aops[depth].count('-')) {
                begin++;
                ret -= expr(begin, depth + 1);
            } else if (*begin == '*' && aops[depth].count('*')) {
                begin++;
                ret *= expr(begin, depth + 1);
            } else {
                break;
            }
        }
        return ret;
    }

    T factor(State &begin) {
        if (*begin == '(') {
            begin++; // skip '('
            T ret = expr(begin, 0);
            begin++; // skip ')'
            return ret;
        } else {
            return number(begin);
        }
    }

    T number(State &begin) {
        T ret = 0;
        while (isdigit(*begin)) {
            ret *= 10;
            ret += *begin - '0';
            begin++;
        }
        return ret;
    }
};

int main() {
    string S; cin >> S;
    long long res = -LONG_MAX;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                for (int it = 0; it < 3; it++) aops[it].clear();
                aops[i].insert('+');
                aops[j].insert('-');
                aops[k].insert('*');
                Parser<long long> ps;
                res = max(res, ps.solve(S));
            }
        }
    }
    cout << res << endl;
    return 0;
}


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

int main() {
	int a[7],i,n;
	for(i=0;i<7;i++)
	  {
	  	  a[i]=pow(2,i);
	  }
	cin>>n;
	cout<<a[upper_bound(a,a+7,n)-a-1];
	// your code goes here
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
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(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,M,L,R,K,Q,X,Y,Z;
multiset<int> pre,post;
int ans = 0;
int sum[2] = {0,0};

void solve() {
    cin>>Q;
    int t,a,b;
    while(Q--) {
        cin>>t;
        if (t==1) {
            cin>>a>>b;
            ans += b;
            if (pre.empty()) {
                pre.insert(a);
                sum[0] = a;
                continue;
            }
            if (pre.size()==post.size()) {
                int v = *post.begin();
                if (v < a) {
                    post.erase(post.begin());
                    post.insert(a);
                    pre.insert(v);
                    sum[1] += a-v;
                    sum[0] += v;
                } else {
                    pre.insert(a);
                    sum[0] += a;
                }
                continue;
            }
            // pre.size() > post.size()
            int v = *pre.rbegin();
            if (a < v) {
                sum[0] += a - v;
                sum[1] += v;
                pre.erase(--pre.end());
                pre.insert(a);
                post.insert(v);
            } else {
                post.insert(a);
                sum[1]+=a;
            }
        } else {
            int x = *(pre.rbegin());
            int s = ans + (int)pre.size()*x - sum[0] + sum[1] - (int)post.size()*x;
            out("%lld %lld\n",x,s);
        }
    }
}



Measured memory_bytes: 13008
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#define mp make_pair
using namespace std;
int main(){
  for(int d;cin>>d,d;){
    vector<pair<int,int> > result;
    for(int i=0;i<d;i++){
      int name,score=0,a,b,k=0;
      cin>>name;
      for(int i=0;i<10;i++){
	cin>>a;score+=a;
	if(k&4) score+=a,k&=3;
	if(k&2) score+=a;
	if(k&1) score+=a,k&=6;
	if(a==10){
	  if(k&2)k|=4;
	  k|=2;
	}
	else{cin>>b;score+=b;
	  if(k&2)score+=b,k&=5;
	  if(a+b==10)k|=1;}
      }
      if(k&2){cin>>a>>b;score+=k&4?2*a+b:a+b;}
      if(k&1){cin>>a;score+=a;}
      result.push_back(mp(-score,name));
    }
    sort(result.begin(),result.end());
    for(int i=0;i<d;i++)cout<<result[i].second<<" "<<-result[i].first<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int n, a;
ll dp[55][2550] = {0};
ll ndp[55][2550] = {0};
vector<int> x;
int mv = INT_MIN;
ll ans = 0;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> a;
    x.resize(n);
    
    rep(i, n) {
        cin >> x[i];
        mv = max(mv, x[i]);
    }
    
    dp[0][0] = 1;
    ndp[0][0] = 1;
    
    rep(i, n) {
        reps(ii, 1, n + 1) {
            rep(iii, n * mv + 1) {
                if ((iii >= x[i]) && (dp[ii - 1][iii - x[i]] > 0)) {
                    ndp[ii][iii] += dp[ii - 1][iii - x[i]];
                }
            }
        }
        
        memcpy(dp, ndp, sizeof(ndp));
    }
    
    reps(i, 1, n + 1) {
        rep(ii, n * mv + 1) {
            if (ii == (a * i)) {
                ans += dp[i][ii];
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (a[i] != a[j])
            {
                int key = a[i] + a[j];
                for (int k = j + 1; k < n; k++)
                {
                    if (a[k] != a[i] && a[k] != a[j])
                    {
                        if (key > a[k])
                        {
                            if (a[k] + a[j] > a[i] && a[k] + a[i] > a[j])
                            {

                                cnt++;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 3592