akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();

template <int depth> struct Segment_tree {
	const static int h = depth;
	const static int n = 1 << h;

	using T = long long;
	T data[2 * n];
	const T out = 0LL;

	inline T vmerge(T l, T r) {return max(l, r);}

	void init() {
		fill_n(data, 2 * n, out);
	}

	void update(int p, T x) { // set value at position p
		for (data[p += n] = x; p > 1; p >>= 1){
			data[p >> 1] = vmerge(data[p], data[p ^ 1]);
		}
	}

	T query(int l, int r) {  
		T resl = out, resr = out;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (l & 1) resl = vmerge(data[l++], resl);
			if (r & 1) resr = vmerge(resr, data[--r]);
		}
		return vmerge(resl, resr);
	}
};

Segment_tree<18> seg;

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

	using pii = pair<int,int>;
	vector<pii> ary;
	rep(i,n) ary.push_back(pii(h[i],i));
	sort(begin(ary),end(ary));

	seg.init();
	for(auto &elem:ary){
		const int idx = elem.second;
		const ll cmax = seg.query(0,idx);
		seg.update(idx, cmax + a[idx]);
	}

	cout << seg.query(0,n) << endl;

	return 0;
}

Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ctoi(x) x-'0'
#define pshb(a) cin >> x;a.push_back(x)
#define fr(i,n) for(ll i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false);
using namespace std;
int main()
{
    ll n, k, r, s, p, cnt=0  ;
    cin>>n>>k>>r>>s>>p ;
    string t,ans="";
    cin>>t ;
    for (int i =0 ; i<n ; i++)
    {
        if (i<k)
        {
            if (t[i]=='r')
                ans.push_back('p') ;
            if (t[i]=='s')
                ans.push_back('r');
            if (t[i]=='p')
                ans.push_back('s') ;
        }
        else
        {
            if (t[i]!=t[i-k])
            {
                if (t[i]=='r')
                ans.push_back('p') ;
            if (t[i]=='s')
                ans.push_back('r');
            if (t[i]=='p')
                ans.push_back('s') ;
            }
            else
            {
                if (ans[i-k]==t[i-k])
                {
                    if (t[i]=='r')
                ans.push_back('p') ;
            if (t[i]=='s')
                ans.push_back('r');
            if (t[i]=='p')
                ans.push_back('s') ;
                }
                else
                    ans.push_back(t[i]);
            }
        }
    }
    for (int i =0 ; i<n ; i++)
    {
        if (ans[i]!=t[i])
        {
            if (ans[i]=='r')
                cnt+=r ;
            else if (ans[i]=='p')
                cnt+=p ;
            else
                cnt+=s ;
        }
    }
    cout<<cnt;
}




Measured memory_bytes: 512
import sys
from collections import deque
def input(): return sys.stdin.readline().strip()


def main():
    K = int(input())
    q = deque([1,2,3,4,5,6,7,8,9])
    for _ in range(K - 1):
        n = q.popleft()
        # print(n)
        if n % 10 == 0:
            q.append(n * 10)
            q.append(n * 10 + 1)
        elif n % 10 == 9:
            q.append(n * 10 + 8)
            q.append(n * 10 + 9)
        else:
            k = n % 10
            q.append(n * 10 + k - 1)
            q.append(n * 10 + k)
            q.append(n * 10 + k + 1)
    print(q[0])


    

if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
// Problem : B - Frog 2
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define fs second
#define lb lower_bound
#define ub upper_bound

#define int long long
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector< vi >
#define vpii vector< pii >
#define vb vector<bool>
#define si set<int>
#define mii map<int, int>
#define mci map<char, int>
#define md 1000000007
#define pb push_back
#define eb emplace_back
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL);  cout.tie (NULL);
#define qw1(x) cerr<<#x<<": "<<x<<" "<<endl
#define qw2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define qw3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define qw4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl


#define f(i,a,b) for(int i=(int)a;i<=(int)b;i++)
#define rl(i,a,b) for(int i=(int)a;i>=(int)b;i--)
#define all(x) x.begin(),x.end()
#define endl '\n'
void printv(vector<int>  v){ for(int i=0;i<v.size();i++) cout<<v[i]<<' '; cout<<endl;   }
int bem(int m , int n, int mod) { int res=1; while(n){
	     			        if(n%2!=0) { res*=m; res%=mod; }
	    			        m*=m;   m%=mod;   n/=2;
			                          }
				return res;	}
int be(int a, int b) { int res=1; 	while(b){
				if(b%2!=0) res*=a;
				a*=a; b/=2;
				}
			return res;	}
void sieve(int n, vb &prime){
    prime[0]=false;     prime[1]=false;
    for(int i=2;i*i<=n;i++){
         if(prime[i]==true){
              for(int j=i*i;j<=n;j+=i)    prime[j]=false;
             	  }
    	 }
	}
vi v;
vi dp;
int k;
int fun( int n)
{
	if(dp[n]!=-1) return dp[n];
	if(n==0) return dp[n]=0;
	int z=max((int)0, n-k);
	dp[n]=fun(z)+abs(v[z]-v[n]);
	f(i, 1, min(k-1, n-2)) dp[n]=min(dp[n], fun(n-i)+abs(v[n]-v[n-i]));
	return dp[n];
}
void solve()
{
int n; cin>>n>>k;
v.resize(n); f(i, 0, n-1) cin>>v[i];
dp.resize(n, -1);
cout<<fun(n-1)<<endl;
// printv(dp);
}
/*void solve()
  {
int n, k; cin>>n>>k;
v.resize(n); f(i, 0, n-1) cin>>v[i];
dp.resize(n, 0);
dp[0]=0;
int maxi=v[0];
f(i, 1,min(k, n-1))
{
	int j=i;
	dp[j]=dp[0]+abs(v[0]-v[j]);
	// qw2(j, dp[j]);
	f(k, 1, j-1) dp[i]=min(dp[i],dp[k]+abs(v[j]-v[k]));
}
f(i,k+1, n-1)
{
	int z=i;
	dp[i]=dp[i-k]+abs(v[i]-v[i-k]);
	f(j, 1, z-1)
	dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
}
 // printv(dp);
cout<<dp[n-1]<<endl;
}*/


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








Measured memory_bytes: 8064
/**
**	author : Raghav
**	codechef:raghav_456
**	codeforces:raghavramola7
**/
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long int
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void Raghav()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
//int x = 1e6;
int a[1000000];
bool isPrime(int n)
{
	for (int i = 2; i <= sqrt(n) + 1; i++)
	{
		if (n % i == 0 && i != n)
		{
			return false;
		}
	}
	return true;
}
int32_t main()
{
	Raghav();
	int k,n;
	cin>>k>>n;
	if((k*500)>=n)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3680
import java.io.*;
 
class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] strArr = br.readLine().split(" ");
        int w = Integer.parseInt(strArr[0]);
        int h = Integer.parseInt(strArr[1]);
        int x = Integer.parseInt(strArr[2]);
        int y = Integer.parseInt(strArr[3]);
        int r = Integer.parseInt(strArr[4]);
 
        if ( (x - r >= 0 && x + r <= w) && (y - r >= 0 && y + r <= h) ) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 24396
"""ICGNYN 17D8103016H 土屋　怜"""
import random
import math

def hura (a):
    ind=1
    for i in range(len(a)-1):
        c= [(a[i*4+1][0]-a[i*4][0])/3+a[i*4][0], (a[i*4+1][1]-a[i*4][1])/3+a[i*4][1]]
        d=[(a[i*4+1][0]-a[i*4][0])*2/3+a[i*4][0], (a[i*4+1][1]-a[i*4][1])*2/3+a[i*4][1]]
        cos=math.cos(math.pi/3)
        sin=math.sin(math.pi/3)
        f = [d[0]-c[0],d[1]-c[1]]
        b= [f[0]*cos-sin*f[1]+c[0],sin*f[0]+cos*f[1]+c[1]]
        a.insert(ind,c)
        a.insert(ind+1,b)
        a.insert(ind+2,d)
        ind=ind+4
        

N = int(input())
x=[[0,0],[100,0]]
for i in range(N):
    hura(x)
for i in range(len(x)):
  print(x[i][0],end="")
  print(" ",end="")
  print(x[i][1])


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

using namespace std;

void FAST_IO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

#define REP(_i, _a) for(int _i = 0; _i < (int)_a; ++_i)
#define FOR(_i, _a, _b) for(int _i = (int)_a; _i <= (int)_b; ++_i)
#define FORD(_i, _a, _b) for(int _i = (int)_a; _i >= (int)_b; --_i)
#define RESET(_a, _value) fill_n(_a,sizeof(_a)/sizeof(_a[0]),_v)
#define ALL(_a) _a.begin(), _a.end()
#define SIZE(_a) _a.size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define newline '\n';

// DEBUG UTIL
#define DEBUG(args...) { cerr << "> "; \
						 string _s = #args; \
						 replace(_s.begin(), _s.end(), ',', ' '); \
						 stringstream _ss(_s); istream_iterator<string> _it(_ss); \
						 err(_it, args); }

void err(istream_iterator<string> it) { cerr << endl; }
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << ": " << a << " ";
	err(++it, args...);
}

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

string format(const string& s, ...) {
    va_list args;
    va_start (args, s);
    size_t len = vsnprintf(NULL, 0, s.c_str(), args);
    va_end (args);
    std::vector<char> vec(len + 1);
    va_start (args, s);
    vsnprintf(&vec[0], len + 1, s.c_str(), args);
    va_end (args);
    return &vec[0];
}

const double PI = acos(-1.0);
const int MOD = 1e9 + 7;
const int INF = 2e9;

int a[3];

void read() {
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[2] - a[0] << endl;
}

void solve() {
	
}

int main() {
	FAST_IO();

	int TC = 1;
	// cin >> TC;
	FOR(tc, 1, TC) {
		read();
		solve();
	}

	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def resolve():
    n, m, k = map(int, input().split())
    u = UnionFind(n)
    d = defaultdict(int)
    e = defaultdict(int)
    for _ in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        u.union(a, b)
        d[a] += 1
        d[b] += 1
    for _ in range(k):
        a, b = [int(x) - 1 for x in input().split()]
        if u.same(a, b):
            e[a] += 1
            e[b] += 1
    ans = [0] * n
    for i in range(n):
        ans[i] = u.size(i) - 1 - d[i] - e[i]
    print(*ans)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 35856
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

bool prime[200005];
bool ok[200005];
int dp[200005];
int q;

int main(void){
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	for(int i=2;i<=100000;i++){
		if(prime[i]){
			for(int j=i*2;j<=100000;j+=i){
				prime[j]=false;
			}
		}
	}
	for(int i=0;i<=100005;i++){
		if(prime[i] && prime[(i+1)/2] && i%2==1){
			//printf("%d\n",i);
			ok[i]=true;
		}
	}
	for(int i=0;i<=100005;i++){
		dp[i+1]+=dp[i];
		if(ok[i])dp[i+1]++;
	}
	scanf("%d",&q);
	for(int i=0;i<q;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		printf("%d\n",dp[b+1]-dp[a]);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <stdio.h>
#include <stdlib.h>
#define MAX 100010
#define NIL -1
typedef struct{
  int par;
  int left;
  int right;
}node;

node N[MAX];
int n,dep[MAX];

void print_all(int me){
  int i,c,j=0;
  printf("node %d: ",me);
  printf("parent = %d, ",N[me].par);
  printf("depth = %d, ",dep[me]);

  if(N[me].par==NIL){
    printf("root, ");
  }
  else if(N[me].left==NIL){
    printf("leaf, ");
  }
  else {
    printf("internal node, ");
  }
  printf("[");
  for(c=N[me].left;c!=NIL;c=N[c].right){
    if(j!=0){
      printf(", %d",c);
    }
    else {
      printf("%d",c);
      j++;
    }
  }
  printf("]\n");
}

int depth_cal(int me,int g){
  dep[me]=g;
  if(N[me].right != NIL){depth_cal(N[me].right, g);}
  if(N[me].left != NIL){depth_cal(N[me].left,g+1);}
}

int main(){
  int i,j,k,me,si,left,right;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    N[i].par=N[i].left=N[i].right=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&me,&k);
    for(j=0;j<k;j++){
      scanf("%d",&si);
      if(j==0){
	N[me].left=si;
      }
      else{
	N[left].right=si;
      }
      left=si;
      N[si].par=me;
    }
  }
  for(i=0;i<n;i++){
    if(N[i].par==NIL){
      right=i;
    }
  }

  depth_cal(right,0);
  for(i=0;i<n;i++){
    print_all(i);
  }
  return 0;
}

  
      
    
    
    
    
  



Measured memory_bytes: 6416
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
  let mut ab: Vec<u32> = read_vec();
  let mut ans: u32 = 0;

  for _ in 0..2 {
    if ab[0] > ab[1] {
      ans += ab[0];
      ab[0] -= 1;
    } else {
      ans += ab[1];
      ab[1] -= 1;
    }
  }

  println!("{}", ans);
}


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

int main() {
	int n;
	while (cin >> n, n) {
		int index;
		double Min = (double)INT_MAX;
		rep(i, n) {
			int I; double h, w; cin >> I >> h >> w; h /= 100;
			double d = abs(22. - (w / (h*h)));
			if (d < Min) {
				index = I; Min = d;
			}
			if (d == Min) {
				index = min(index, I);
			}
		}
		cout << index << endl;
	}
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  string s;
  string t="";
  cin>>s;
  int n=s.size();
  int index=0;
  vector<string> ss;
  while(index<n){
    if(s[index]=='A'){
      t += "A";
      index++;
      if(index==n){
        ss.push_back(t);
      }
    }else if(index+1<n && s[index]=='B' && s[index+1]=='C'){
      t += "D";
      index += 2;
      if(index==n){
        ss.push_back(t);
      }
    }else{
      index++;
      if(t != ""){
        ss.push_back(t);
        t = "";
      }
    }
  }
  int cnt = ss.size();
  long long ans=0;
  long long temp;
  long long en;
  REP(i,cnt){
    temp=ss[i].size()-1;
    en=ss[i].size()-1;
    for(long long j=en;j>=0;j--){
      if(ss[i][j]=='A'){
        ans += temp-j;
        temp--;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3196
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
const int tx[] = {0,1,0,-1};
const int ty[] = {-1,0,1,0};

class Book{
public:
  int read;
  int write;
  Book(int _r,int _w) : read(_r), write(_w) {}
  bool operator <(const Book& b) const {
    return (read != b.read ? (read < b.read) : (write < b.write));
  }
  bool operator >(const Book& b) const {
    return (read != b.read ? (read > b.read) : (write > b.write));
  }
};

bool dp[1000010];

int main(){
  int N;
  while(~scanf("%d",&N)){
    if(N == 0) break;

    vector<Book> books;

    int total_reading = 0;
    int total_writing = 0;
    for(int book_idx = 0; book_idx < N; book_idx++){
      int read,write;
      scanf("%d %d",&read,&write);
      books.push_back(Book(read,write));
      total_reading += read;
      total_writing += write;
    }

    sort(books.begin(),books.end());
    int longest_reading = (books.end()-1)->read;
    int remaining = total_reading - longest_reading;

    if(remaining < longest_reading){
      int fill_space = longest_reading - remaining;
      memset(dp,false,sizeof(dp));
      dp[0] = true;
      int max_fill = 0;
      for(int i=0; i < N - 1; i++){
        for(int j=fill_space; j>=0; j--){
          if(j + books[i].write > fill_space) continue;

          dp[j + books[i].write] = dp[j];
          if(dp[j + books[i].write]){
            max_fill = max(max_fill,j+books[i].write);
          }
        }
      }

      printf("%d\n",total_reading + total_writing + (fill_space - max_fill));
    }
    else{
      printf("%d\n",total_reading + total_writing);
    }
  }
}

Measured memory_bytes: 2192
#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() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); i += 2) ans += s[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3700
import java.util.*;

public class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        double[] l = new double[n];
        double[] a = new double[n];
        double[] b = new double[n];
        for(int i=0; i<n; i++){
            l[i] = sc.nextDouble();
            a[i] = sc.nextDouble();
            b[i] = sc.nextDouble();
        }

        double[][] dist = new double[n][n];
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                double ll = Math.abs(l[i]-l[j]);
                double aa = Math.abs(a[i]-a[j]);
                double bb = Math.abs(b[i]-b[j]);
                double sum = ll*ll+aa*aa+bb*bb;
                dist[i][j] = sum;
                dist[j][i] = sum;
            }
        }

        double max = 0.0;
        for(int bit=0; bit<1<<n; bit++){
            if(Integer.bitCount(bit)!=m) continue;
            double sum = 0.0;
            for(int i=0; i<n; i++){
                if((bit&(1<<i))>0){
                    for(int j=i+1; j<n; j++){
                        if((bit&(1<<j))>0) sum += dist[i][j];
                    }
                }
            }
            max = Math.max(max, sum);
        }

        System.out.printf("%.9f\n",max);
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 20860
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};


/*
 * 0©çm-1ÜÅÌfÉÖ·éCu
 * templateÅTCYðwè·éÌÅá±¢?
 * Prime<1000> p; Å999ÜÅÌfÌe[uªÅ«é
 * p[k] : kÔÚÌfÍ½©
 * p.isPrime(k) : kªf©Ç¤©
 */
template<int m>
class Prime{
  std::vector<bool> p;
  std::vector<int> ps;
public:
  Prime(){
    p = std::vector<bool>(m,true);
    assert(m>1);
    p[0]=p[1]=false;
    for(int i=4;i<m;i+=2)
      p[i]=false;
    ps.push_back(2);
    for(int i=3;i<m;i+=2){
      if(p[i]){
        ps.push_back(i);
        for(int j=i+i;j<m;j+=i)
          p[j]=false;
      }
    }
  }

  bool isPrime(int n){
    assert(m>n);
    return p[n];
  }

  int operator [] (int n){
    if(n<ps.size()) return ps[n];
    else return 0;
  }

  int size(){
    return ps.size();
  }
};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  Prime<30200> p;
  int n;
  while(n = getInt()){
    int ans = 0;
    for(int i = 0; p[i]+p[i]+p[i] <= n; i++){
      for(int j = i; p[i]+p[j]+p[j] <= n; j++){
        int a = p[i];
        int b = p[j];
        int c = n - p[i] - p[j];
        if(c >= a + b) continue;
        if(c <= b - a) continue;
        if(!p.isPrime(c)) continue;
        ans++;
      }
    }
    print(ans);
  }
  return 0;
}

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

using namespace std;
using ll = long long;

ll const MAX_N = 1e5+1;
vector<ll> par(MAX_N);
vector<ll> treesize(MAX_N);

void init(ll n){
    for(ll i=0;i<n;i++){
        par[i]=i;
        treesize[i]=1;
    }
}

ll root(ll x){
    if(par[x] == x) return x;
    else return par[x] = root(par[x]);
}

bool same(ll x,ll y){
    return root(x)==root(y);
}

void unite(ll x,ll y){
    x = root(x);
    y = root(y);
    if(x == y) return;
    else{
        treesize[y] += treesize[x];
        par[x] = y;
    }
}

int main(){
    ll n,m;
    cin>>n>>m;
    vector<ll> a(m),b(m);
    init(n);

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

    vector<ll> ans(m+1,0);
    ans[m] = n*(n-1)/2;

    for(ll i=m-1;i>=0;i--){
        if(same(a[i],b[i])) ans[i] = ans[i+1];
        else{
            ans[i] = ans[i+1] - treesize[root(a[i])] * treesize[root(b[i])];
        }
        unite(a[i],b[i]);
    }

    for(ll i=1;i<m+1;i++){
        cout<<ans[i]<<endl;
    }
}


Measured memory_bytes: 5248
N = int(input())
A, B = map(int, input().split())
P = [int(i) for i in input().split()]
q1 = [i for i in P if i <= A]
q2 = [i for i in P if A < i <= B]
q3 = [i for i in P if B < i]
print(min(len(q1), len(q2), len(q3)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int N,a[2][101];
int count(int n)
{
    int sum=0;
    for(int i=0;i<=n;i++)
        sum+=a[0][i];
    sum+=a[1][n];
    if(n==N)
        return sum;
    for(int i=n+1;i<N;i++)
        sum+=a[1][i];
    return sum;
}
int main()
{
    scanf("%d",&N);
    for(int i=0;i<2;i++)
        for(int j=0;j<N;j++)
            scanf("%d",&a[i][j]);
    int max=0;
    for(int i=0;i<N;i++)
    {
        if(count(i)>max)
            max=count(i);
    }
    printf("%d",max);
    return 0;
}


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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

struct Comp {
    bool operator()(string & lf, string & rg) {
        return lf < rg;
    }
};

int n, le;
vector<string> ss;

int read() {
    if (!(cin >> n >> le)) {
        return 0;
    }
    ss.clear();
    for (int i = 0; i < n; i++) {
        string x; cin >> x;
        ss.push_back(x);
    }
    return 1;
}

void solve() {
    sort(ss.begin(), ss.end());
    for (int i = 0; i < n; i++) {
        cout << ss[i];
    }
    cout << '\n';
}

int main() {
//    freopen(in, r, stdin);
    while (1) {
        if (!read()) break;
        solve();
    }
}


Measured memory_bytes: 256
// Hopcroft-Karp Algorithm
// O(|E| * |V|^(1/2))
// http://en.wikipedia.org/wiki/Hopcroft%E2%80%93Karp_algorithm
// aoj 1163

#include <vector>
#include <queue>
#include <iostream>
using namespace std;

int NIL;
const int inf = 1<<29;

typedef vector<int> vi;
typedef vector<vector<int> > Graph;

bool bfs(const Graph &g,vi &dist,const vi &pair,int m) {
    queue<int> q;

    for(int i=0; i<m; ++i)
        if(pair[i] == NIL) {
            dist[i] = 0;
            q.push(i);
        }else dist[i] = inf;
    dist[NIL] = inf;

    while(!q.empty()) {
        int v = q.front(); q.pop();
        if(v == NIL) continue;
        for(int i=0; i<g[v].size(); ++i) {
            int u = pair[g[v][i]];
            if(dist[u] == inf) dist[u] = dist[v]+1, q.push(u);
        }
    }
    return dist[NIL] != inf;
}

bool dfs(int v,const Graph &g,vi &dist,vi &pair) {
    for(int i=0; i<g[v].size(); ++i) {
        int u = g[v][i];
        if(dist[pair[u]] == dist[v]+1)
            if(pair[u] == NIL || dfs(pair[u],g,dist,pair)) {
                pair[u] = v, pair[v] = u;
                return true;
            }
    }
    dist[v] = inf;
    return false;
}

// 0ツつゥツづァm-1ツづ慊づづ個静淞点ツづツつゥツづァn-1ツづ慊づづ個静淞点ツづづ個催妥・ツマツッツチツδ督グツづーツ仰づ淞づゥ
int hopcroft_karp(Graph &graph,int m) {
    NIL = graph.size();
    vi pair(NIL+1, NIL), dist(NIL+1, 0);
    int ret = 0;
    while(bfs(graph,dist,pair,m))
        for(int i=0; i<m; ++i)
            if(pair[i] == NIL)
                if(i == NIL || dfs(i,graph,dist,pair)) ret++;
    return ret;
}

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

int main() {
    ios::sync_with_stdio(false);
    int m,n;
    while(cin>>m>>n, m|n) {
        Graph g(m+n);
        vector<int> b(m), r(n);
        for(int i=0; i<m; ++i) cin>>b[i];
        for(int i=0; i<n; ++i) cin>>r[i];

        for(int i=0; i<m; ++i)
            for(int j=0; j<n; ++j)
                if(gcd(b[i],r[j]) > 1)
                    g[i].push_back(j+m);
        cout<<hopcroft_karp(g,m)<<endl;
    }
}

Measured memory_bytes: 1644
#include <stdio.h>
int main(void){
	int a = 0, b = 0, c = 0;
	int cnt = 0;
	scanf("%d %d %d", &a, &b, &c);
	for (int x = a; x <= b; x++){
		if (c%x == 0){
			cnt++;
		}
	}
	printf("%d\n", cnt);
}

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

using namespace std;

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

  if (a == b && a == c) {
    cout << 1;
  } else if (a == b || b == c || c == a) {
    cout << 2;
  } else {
    cout << 3;
  } cout << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N,l[1000],r[1000],sum=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>l[i]>>r[i];
        sum += (r[i]-l[i]+1);
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
word = []

for i in range(n):
    w = input()
    if w in word:
        print("No")
        exit()
    if i != 0:
        if w[0] != word[i-1][-1]:
            print("No")
            exit()
    word.append(w)

print("Yes")

Measured memory_bytes: 61676
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    if (c-(a-b)>0) {
      System.out.println(c-(a-b));
    }else{
      System.out.println(0);
    }
  }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
long long power(long long a, long long b,long long m) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a %m;
        a = a * a %m;
        b >>= 1;
    }
    return res;
}
 

signed main()
{
 
ios_base::sync_with_stdio(false);
cin.tie(NULL);  
cout.tie(0);   
 
#ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
#endif      

    int n,k;
    cin>>n>>k;
    int ans=0;
    if(k==0)
    {
        cout<<(n*n);
        return 0;
    }

    for(int i=k+1;i<=n;i++)
    {
        for(int j=0;j*i<=n;j++)
        {
            int z=(j*i)%i;
            if(j*i+i<=n)
            {
                if(z>=k)
                    ans+=(i-z);
                else
                    ans+=(i-k);
                // cout<<"yo\n";
            }
            else
            {
                // cout<<"lol\n";
                int tt=(n%i);
                if(z>=k)
                    ans+=max(0LL,(tt-z+1));
                else
                    ans+=max(0LL,(tt-k+1));
            }       
            // cout<<i<<" "<<j*i<<" "<<" "<<ans<<'\n';     
        }
    }
    cout<<ans;

} 

Measured memory_bytes: 3612
#include<bits/stdc++.h>
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define lli long long int
#define rep(i,n) for(lli i=0; i<n; i++)
#define loop(i, j, n) for(lli i=j; i<n; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const double PI = acos(-1);
//Function
lli combi(lli n, lli r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
lli sigma1(lli n){return n*(n+1)/2;}
lli sigma2(lli s, lli n){return sigma1(n) - sigma1(s -1);}
using namespace std;
// }}} End Header

int main()
{
	lli a, b, c, d;
	cin >> a >> b >> c >> d;
	lli L = (c*d)/__gcd(c, d);
	lli ans1 = b/c + b/d - b/L;
	lli ans2 = (a-1)/c + (a-1)/d - (a-1)/L;
	ans1 -= ans2;
	cout << b-a+1-ans1 << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        //String s = sc.next();
        
        if(n < 105){
            System.out.println(0);
        }else if(n<135){
            System.out.println(1);
        }else if(n<165){
            System.out.println(2);
        }else if(n<189){
            System.out.println(3);
        }else if(n<195){
            System.out.println(4);
        }else{
            System.out.println(5);
        }
        
        //System.out.println(max);
    }
}

Measured memory_bytes: 23252
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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

long long N,K;
long long ans[100002]={};

int main(){
    cin>>N>>K;
    int a[N],b[N];
    rep(i,N){
        cin>>a[i]>>b[i];
        ans[a[i]]+=b[i];
    }
    rep(i,100002){
        K-=ans[i];
        if(K<=0){
            out(i);
            return 0;
        }
    }
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int N;
int a[100000];
vector<int> as;
int main(){
	cin>>N;
	rep(i,N) cin>>a[i];
	rep(i,N) as.pb(a[i]);
	sort(all(as));
	rep(i,N) a[i]=lower_bound(all(as),a[i])-as.begin();
	int c=0;
	rep(i,N) if(i%2==0&&a[i]%2==1) c++;
	cout<<c<<endl;
}


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

int main() {
  string S;
  cin >> S;
  int count = 0;
  for (int i = 0; i < 3; ++i) {
    if (S.at(i) == 'o') {
      count = count + 100 ;
    }
  }
  cout << 700 + count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);
    vector<long> a(3*n);
    long i;
    for(i=0; i<3*n; i++) {
        scanf("%ld", &a[i]);
    }

    vector<ll> s0(n+1);
    {
        ll sum0=0;
        set<pair<long,long> > zz;
        for(i=0; i<n; i++) {
            zz.insert( make_pair( a[i], i) );
            sum0+=a[i];
        }
        s0[0]=sum0;
        for(i=n; i<n*2; i++) {
            zz.insert( make_pair( a[i], i) );
            sum0+=a[i];

            auto it=zz.begin();
            sum0-=(it->first);
            zz.erase( it );
            s0[i+1-n]=sum0;
        }
    }

    vector<ll> s1(n+1);
    {
        reverse(a.begin(), a.end());
        ll sum0=0;
        set<pair<long,long> > zz;
        for(i=0; i<n; i++) {
            zz.insert( make_pair( a[i], i) );
            sum0+=a[i];
        }
        s1[0]=sum0;
        for(i=n; i<n*2; i++) {
            zz.insert( make_pair( a[i], i) );
            sum0+=a[i];

            auto it=zz.end();
            it--;
            sum0-=(it->first);
            zz.erase( it );
            s1[i+1-n]=sum0;
        }
    }

    ll max=-LINF;
    for(i=0; i<=n; i++) {
        ll val = (s0[i] - s1[n-i]);
        max = MAX(max, val);
    }

    printf("%lld\n", max);

    return 0;
}



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

/*-------------------Define Start-------------------*/
typedef bool BL;    					// 布尔类型
typedef char SB;    					// 有符号1字节,8位
typedef unsigned char UB;    			// 无符号1字节,8位
typedef short SW;    					// 有符号短整型,16位
typedef unsigned short UW;    			// 无符号短整型,16位
typedef long SDW;    					// 有符号整型,32位
typedef unsigned long UDW;   			// 无符号整型,32位
typedef long long SLL;    				// 有符号长整型,64位
typedef unsigned long long ULL;			// 无符号长整型,64位
typedef char CH;    					// 单个字符
typedef float R32;    					// 单精度浮点数
typedef double R64;    					// 双精度浮点数

#define Rep(i, n) for (register SDW i = 0; i < (n); ++i)
#define For(i, s, t) for (register SDW i = (s); i <= (t); ++i)
#define rFor(i, t, s) for (register SDW i = (t); i >= (s); --i)
#define foreach(i, c) for (__typeof(c.begin()) i = c.begin(); i != c.end(); ++i)
#define ms0(a) memset(a,0,sizeof(a))
#define msI(a) memset(a,0x7f,sizeof(a))
#define LOWBIT(x) ((x)&(-x))

#define MP make_pair
#define PB push_back
#define ft first
#define sd second
#define ALL(x) x.begin(),x.end()

#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl

const ULL mod = 1e9 + 7;				//常用模数(可根据题目需要修改)
const ULL inf = 0x7fffffff;				//用来表示无限大
const ULL infLL = 0x7fffffffffffffffLL;	//用来表示无限大
/*-------------------Define End-------------------*/

const UDW maxN = 1e6 + 7;
string N;
SLL ans;

void input(){
	cin >> N;
	N = "0" + N; 
}

void solve(){
	rFor(i, N.size() - 1, 0) {
		SLL x = N[i] - '0';
		
		if(x > 5 || x == 5 && N[i - 1] >= '5') {
			ans += 10 - x;
			++N[i - 1];
		}
		else {
			ans += x;
		}
	}
}

void output(){
	cout << ans << endl;
}

int main() {
	input();
	solve();
	output();
	return 0;
}


Measured memory_bytes: 2308
while True:
    y,x = [int(i) for i in input().split()]
    if y == 0:
        break
    r = y-1
    z = x-2
    for i in range(y):
        if (i==0 or i==r):
            print('#'*x)
        else:
            print('#' + '.'*z+ '#')
            #print(int(x)-2)
    print()

Measured memory_bytes: 7724
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pii> vp;

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


signed main(void) {
    int n,m;
    cin >> n >> m;
    vi p(m);
    rep(i,m)cin >> p[i], p[i]--;
    vi imos(n,0);
    rep(i,m-1){
        int l = min(p[i],p[i+1]);
        int r = max(p[i],p[i+1]);
        imos[l]++;
        imos[r]--;
    }
    rep(i,n-1)imos[i+1] += imos[i];
    int ans = 0;
    rep(i,n-1){
        int a,b,c;
        cin >> a >> b >> c;
        //cout << i << " " << imos[i] << " ";
        int cost = min(a*imos[i],b*imos[i]+c);
        //cout << cost << endl;
        ans += cost;
    }
    cout << ans << endl;
}



Measured memory_bytes: 4372
#include <iostream>
#include <string>
#include <vector>

using namespace std;

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

  vector<bool> nusuke(N, false);

  for (auto i = 0; i < K; i++) {
    int num_of_snack;
    cin >> num_of_snack;
    for (auto j = 0; j < num_of_snack; j++) {
      int in;
      cin >> in;
      nusuke[in - 1] = true;
    }
  }

  int ans(0);
  for (const auto &has_snack : nusuke) {
    if (!has_snack) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3564
#include <iostream>

using namespace std;

int
main()
{
  int n;
  cin >> n;
  int s = 0;
  int l, r;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    s += (r - l + 1);
  }
  cout << s << endl;
  return 0;
}

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

const int N = 1000;

int lcs(string x, string y);

int main(){
  string s1,s2;
  int n;

  cin >> n;

  for(int i = 0; i < n; i++){
    cin >> s1 >> s2;
    cout << lcs(s1,s2) << endl;
  }
  
  return 0;
}

int lcs(string x, string y){
  int c[N+1][N+1];
  int m = x.size();
  int n = y.size();
  int maxl = 0;
  x = ' ' + x;
  y = ' ' + y;

  for(int i = 0; i <= m; i++) c[i][0] = 0;
  for(int i = 1; i <= n; i++) c[0][i] = 0;

  for(int i = 1; i <= m; i++){
    for(int j = 1; j <= n; j++){
      if(x[i] == y[j]) c[i][j] = c[i-1][j-1]+1;
      else c[i][j] = max(c[i-1][j], c[i][j-1]);

      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}



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

#define ll  long long int
#define ld  long double
#define MAX 1000001
#define MOD 1000000007
#define pi  3.14159265358979323846264338
#define mp  make_pair
#define pb  push_back
#define pll pair<ll,ll>
#define vl  vector<ll>
#define vi  vector<int>
#define vs  vector<string>
#define vc  vector<char>
#define fst first
#define sec second
#define foi(i, a, b)   for(ll i = a; i<b;i++)
#define fod(i, a, b)   for(ll i = a;i>=b;i--)
#define all(v)         (v).begin(), (v).end()
#define max3(a, b, c)  max(max(a,b), c)
#define min3(a, b, c)  min(min(a,b), c)
#define ump  unordered_map<ll,ll>
#define us   unordered_set<ll>
#define nl  "\n"
#define INF  (ll)1e18
#define s(v) (ll)(v).size()
#define e(v) (v).empty

using namespace std;

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


void solve(){
    int n;
    cin>>n;

    vector<ld> p(n);
    foi(i,0,n) cin>>p[i];

    ld dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i=1;i<n+1;i++){
        for(int j=0;j<n+1;j++){
            if(j==0){
                dp[i][j] = dp[i-1][j]*(1 - p[i-1]);
            }else{
                dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*(p[i-1]);
            }
        }
    }
    ld ans = 0.0;
    foi(i,(n/2)+1,n+1){
        ans += dp[n][i];
    }
    cout<<setprecision(10)<<ans<<"\n";
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("../input.txt", "r", stdin);
    //     freopen("../output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t = 1;
    //cin>>t;
    while(t--){
        solve();
    }

    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

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

int main(){
    int n, x, l;

    cin >> n >> x;

    int sum = 0;
    int cnt = 1;

    for(int i = 0; i < n; i++){

        cin >> l;

        sum += l;
        if(sum > x) break;
        cnt++;
    }
    cout << cnt << endl;
}

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

int n,k;
vi a;

bool test(int m){
    int cuts = 0;
    rep(i,0,n){
        cuts += (a[i]-1) / m;
    }
    return cuts <= k;
}

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

    cin >> n >> k;
    a = vi(n);
    rep(i,0,n){
        cin >> a[i];
    }
    
    int lo = 0;
    int hi = 1e9+1;
    int mi;
    while(lo+1 < hi){
        mi = (lo+hi)/2;
        if(test(mi)){
            hi = mi;
        }else{
            lo = mi;
        }
    }
    cout << hi << endl;

    return 0;
}


Measured memory_bytes: 3924
#include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  cin >> n;
  while (n != 0) {
    double ss[n];
    double sum = 0.0;
    for (int i = 0; i < n; i++) {
      double s;
      cin >> s;
      ss[i] = s;
      sum += s;
    }
    double ave = sum / (double)n;
    sum = 0.0;
    for (int i = 0; i < n; i++) {
      sum += ((ss[i] - ave) * (ss[i] - ave));
    }
    double a = sqrt(sum / (double)n);
    printf("%.6f\n", a);
    cin >> n;
  }
}


Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>


using namespace std;



int main() {

	int N, M, K, * count, ans = 0, f;

	cin >> N >> M;

	count = new int[M];

	for (int i = 0; i < M; i++) {
		count[i] = 0;
	}

	for (int i = 0; i < N; i++) {
		cin >> K;
		for (int j = 0; j < K; j++) {
			cin >> f;
			count[f - 1]++;
		}
	}

	for (int i = 0; i < M; i++) {
		if (count[i] == N) {
			ans++;
		}
	}

	cout << ans;

	return 0;

}

Measured memory_bytes: 256
from math import ceil
lst = []
ten = []
for i in range(5):
  t = int(input())
  if t % 10 == 0:
    ten.append(t)
  else:
    lst.append(t)
if lst == []:
  print(sum(ten))
  exit()
x = min(lst, key=lambda x: x % 10)
lst.remove(x)
for i in range(len(lst)):
  lst[i] = 10 * (lst[i] // 10 + 1)
print(x + sum(lst) + sum(ten))

Measured memory_bytes: 9192