akhauriyash/Code-Regression huggingface dataset:
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let a: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut b = vec![0; n];
    for i in (1..n + 1).rev() {
        let mut j = i;
        let mut cnt = 0;
        while j <= n {
            cnt += b[j - 1];
            j += i;
        }
        if cnt % 2 != a[i - 1] {
            b[i - 1] = 1;
        }
    }

    let m: i32 = b.iter().sum();
    println!("{}", m);
    for i in 0..n {
        if b[i] > 0 {
            println!("{}", i + 1);
        }
    }
}


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

signed main(){
    int n,m;cin>>n>>m;
    int a[m],b[m];
    vector<vector<int>> c(m);
    int dp[(1<<n)];
    fill(dp,dp+(1<<n),(1LL<<60));
    dp[0]=0;
    rep(i,m){
        cin>>a[i]>>b[i];
        rep(j,b[i]){
            int cc;cin>>cc;cc--;
            c[i].push_back(cc);
        }
    }
    rep(i,(1<<n)){
        rep(j,m){
            int k=i;
            rep(l,b[j])k|=(1<<c[j][l]);
            dp[k]=min(dp[k],dp[i]+a[j]);
        }
    }
    if(dp[(1<<n)-1]==(1LL<<60)){cout<<-1<<endl;return 0;}
    cout<<dp[(1<<n)-1]<<endl;
}

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

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> s(m, vector<int>(10, 0));
  for(int i = 0; i < m; i++) {
    int k;
    cin >> k;
    for(int j = 0; j < k; j++) {
      cin >> s.at(i).at(j);
    }
  }

  vector<int> p(m);
  for(int i=0;i<m;i++) cin >> p[i];
  
  int ans=0;
  for (int bit = 0; bit < (1<<n); ++bit) {
      vector<int> S;
      for (int i = 0; i < n; ++i) {
           if (bit & (1<<i)) { // 列挙に i が含まれるか
              S.push_back(i+1);
          }
      }
      int totalon=0;
      for(int i = 0; i < m; i++) {
        int non=0;
        for(int j = 0; j < 10; j++) {
          for(int h = 0; h < S.size(); h++) {
            if(S[h]==s.at(i).at(j)) non++;
          }
        }
        if(non%2==p[i]) totalon++;
      }
      if(totalon==m) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#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--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


void c_p_c()
{
	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

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vi primes;
	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}



set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}


// int power(int x, unsigned int y, int p)
// {
// 	int res = 1;     // Initialize result

// 	x = x % p; // Update x if it is more than or
// 	// equal to p

// 	if (x == 0) return 0; // In case x is divisible by p;

// 	while (y > 0)
// 	{
// 		// If y is odd, multiply x with result
// 		if (y & 1)
// 			res = (res * x) % p;

// 		// y must be even now
// 		y = y >> 1; // y = y/2
// 		x = (x * x) % p;
// 	}
// 	return res;
// }
// Graph------------------------------------------------------------------------
void max_self(int &a, int b)
{
	a = max(a, b);
}
int32_t main()
{
	FIO;
	// c_p_c();
//--------------------------------------------------



	int n, w;
	cin >> n >> w;

	vector<int> weight(n), value(n);
	for (int i = 0; i < n; i++)
	{
		cin >> weight[i] >> value[i];
	}
	int sum_value = 0;
	for (int x : value)
		sum_value += x;


	vector<int> dp(sum_value + 1, inf);
	dp[0] = 0;
	// dp[i] --- the min total weight of items with total value of items exactly i

	for (int i = 0; i < n; i++)
	{
		for (int value_already = sum_value - value[i]; value_already >= 0; value_already--)
		{
			dp[value_already + value[i]] = min(dp[value_already + value[i]], dp[value_already] + weight[i]);
		}
	}

	int answer = 0;
	int min_weight  = INT_MAX;
	for (int i = 0; i <= sum_value; i++)
	{
		if (dp[i] <= w)
		{
			answer = max(answer, i);
		}
	}
	cout << answer << endl;
}



Measured memory_bytes: 1024
const main = (standardInput) => {
    const lengthList = standardInput.split(' ');
    const A = Number.parseInt(lengthList[0]);
    const B = Number.parseInt(lengthList[1]);
    const C = Number.parseInt(lengthList[2]);
  
  	if (A * C <= B) {
      console.log(C);
    } else {
      console.log(Math.floor(B / A));
    }
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 7372
#include <cstdio>
#include <vector>
#include <set>
#include <utility>
#include <queue>
#include <functional>
using namespace std;
typedef pair<int, int> P;
const int INF = 1 << 30;
struct edge {
	int p, q, c;
	edge(int p, int q, int c) {
		this->p = p;
		this->q = q;
		this->c = c;
	}
	bool operator<(const edge &X) const{
		return (this->c) < X.c;
	}
};
set<edge> query[100000];
int ans[100000];
int par[100000];
vector<P> G[100000];
int dist[100000];
int find(int x) {
	if (par[x] == x) return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y,int c) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (query[x].size() > query[y].size()) swap(x, y);
	for (auto itr = query[x].begin(); itr != query[x].end(); itr++) {
		if (query[y].find(*itr) == query[y].end()) {
			query[y].insert(*itr);
		}
		else {
			ans[itr->c] = c;
		}
	}
	query[x].clear();
	par[x] = y;
}
bool same(int x, int y) {
	return find(x) == find(y);
}
int main() {
	int N, M, K, Q;
	scanf("%d %d %d %d", &N, &M, &K, &Q);
	for (int i = 0; i < M; i++) {
		int A, B, L;
		scanf("%d %d %d", &A, &B, &L); A--; B--;
		G[A].push_back(P(B, L));
		G[B].push_back(P(A, L));
	}
	fill(dist, dist + N, INF);
	priority_queue<P, vector<P>, greater<P> > que;
	for (int i = 0; i < K; i++) {
		int F;
		scanf("%d", &F); F--;
		dist[F] = 0;
		que.push(P(0, F));
	}
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int x = p.second, c = p.first;
		if (dist[x] < c) continue;
		for (int i = 0; i < G[x].size(); i++) {
			int to = G[x][i].first;
			int cost = G[x][i].second;
			if (dist[to] > (c + cost)) {
				dist[to] = c + cost;
				que.push(P(dist[to], to));
			}
		}
	}
	priority_queue<edge> E;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < G[i].size(); j++) {
			int to = G[i][j].first;
			E.push(edge(i, to, min(dist[i], dist[to])));
		}
	}
	for (int i = 0; i < Q; i++) {
		int S, T;
		scanf("%d %d", &S, &T); S--; T--;
		if (S > T) swap(S, T);
		query[S].insert(edge(S,T, i));
		query[T].insert(edge(S,T, i));
	}
	for (int i = 0; i < N; i++) {
		par[i] = i;
	}
	while (!E.empty()) {
		edge e = E.top(); E.pop();
		if (!same(e.p, e.q)) {
			unite(e.p, e.q,e.c);
		}
	}
	for (int i = 0; i < Q; i++) {
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 34396
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans = 0;
string S;
void dfs(int n, ll v, ll sum)
{
    if (S.length() == n) {
        sum += v;
        ans += sum;
        return;
    }
    ll next = v * 10 + S[n] - '0';
    dfs(n + 1, 0, sum + next);
    dfs(n + 1, next, sum);
}
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> S;
    dfs(0, 0, 0);
    cout << ans / 2 << endl;
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)
        cout<<s;
    else
        cout<<s.substr(0,k)<<"...";
    return 0;
}

Measured memory_bytes: 3656
//....SARANSH GUPTA....\\

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fo(p,n) for(int i=p;i<n;i++)
#define FIO ios_base::sync_with_stdio(false);   cin.tie(NULL);   cout.tie(NULL);
#define endl "\n"
#define mp make_pair
#define pb push_back
#define mod 1000000007
ll n;
vector<ll> v[100001];
vector<pair<ll,ll>> child;

int main()
{
    FIO
    ll mp;
    cin>>n>>mp;
    while(mp--)
    {
        ll x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    map<ll,ll> m;
    queue<ll> q ;
    m[1]=0;
    bool vis[n+1];
    fo(1,n+1)
    vis[i]=false;
    vis[1]=true;
    q.push(1);
    while(!q.empty())
    {
        ll node=q.front();
        ll val=node;
        q.pop();
        for(int i=0;i<v[node].size();i++)
        {
            if(vis[v[node][i]]==false)
            {
                q.push(v[node][i]);
                vis[v[node][i]]=true;
                child.pb({v[node][i],node});
            }
        }
    }
    sort(child.begin(),child.end());
    if(child.size()==n-1)
    {
        cout<<"Yes\n";
        for(int i=0;i<child.size();i++)
        cout<<child[i].second<<endl;
    }
    else
    cout<<"No\n";
    
    
    
}

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

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

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep_op(i, a, n) for (int i = a; i < n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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

const int MOD = 1000000007;

const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;

Graph G;

vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll a, b;
    cin >> a >> b;
    if (a > 0 && b > 0)
    {
        cout << "Positive" << endl;
        return 0;
    }

    if (a < 0 && b > 0)
    {
        cout << "Zero" << endl;
        return 0;
    }

    if ((b - a) % 2 == 0)
    {
        cout << "Negative" << endl;
    }
    else
    {
        cout << "Positive" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main(){
    int n;
    cin >> n;
    while(n!=0){
      int sum=0,count=0;
      vector<int> a(n);
      for(int i=0;i<n;i++){
          cin >> a[i];
          sum += a[i];
      }
      for(int j=0;j<n;j++){
          if(a[j]<=sum/n){
              count++;
          }
      }
      cout << count << endl;
      cin >> n;
    }
    return 0;
}


Measured memory_bytes: 3140
#include <stdio.h>

int f( int x ){
	return x*x;
}

int main(){
	int d, s, i;

	while( scanf("%d", &d) != EOF ){

		s=0;

		for( i=0; i<600; i+=d ){
			s += d*f(i);
		}

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

	return 0;
}

Measured memory_bytes: 596
# スペース区切りの整数入力
N,M,K = map(int, input().split())

fcnum = [ 0 for i in range(N+1)]
fring = [[] for i in range(N+1)]
frno =  [-1 for i in range(N+1)]

ab = []
for i in range(M):
    aa,bb = map(int, input().split())
    if aa > bb:
        aa,bb = bb,aa
    fcnum[aa] -= 1
    fcnum[bb] -= 1
    ab.append([aa,bb])

for aa,bb in ab:
    if frno[aa] == -1 and frno[bb] == -1:
        frn = aa
        frno[aa] = frn
        frno[bb] = frn
        fring[frn].append(aa)
        fring[frn].append(bb)
    elif frno[aa] == -1 and frno[bb] != -1:
        frn = frno[bb]
        frno[aa] = frn
        fring[frn].append(aa)
    elif frno[aa] != -1 and frno[bb] == -1:
        frn = frno[aa]
        frno[bb] = frn
        fring[frn].append(bb)
    else:
        if frno[aa] != frno[bb]:
            if len(fring[frno[aa]]) > len(fring[frno[bb]]):
                frnto = frno[aa]
                frnfrom = frno[bb]
            else:
                frnto = frno[bb]
                frnfrom = frno[aa]
            fring[frnto].extend(fring[frnfrom])
            for mvf in fring[frnfrom]:
                frno[mvf] = frnto
            fring[frnfrom] = []

for i in range(K):
    cc,dd = map(int, input().split())
    if frno[cc] == frno[dd] and frno[cc] != -1:
        fcnum[cc] -= 1
        fcnum[dd] -= 1

for k in range(1,len(fring)):
    cnum = len(fring[k]) - 1
    for ff in fring[k]:
        fcnum[ff] += cnum

for i in range(1,len(fcnum)):
    print(fcnum[i]," ",end="")

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

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> d(n, vector<int> (2));
    rep(i, 0, n) cin >> d[i][0] >> d[i][1];
    int flag = 0;
    rep(i, 0, n){
        if(d[i][0] == d[i][1]) flag++;
        else flag = 0;
        if(flag >= 3){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3632
n,k,q=map(int,input().split())
a=list(map(int,input().split()))
ans=10**10
for y in a:
	t=[[]]
	for i in a:
		if i<y:
			if len(t[-1]):t.append([])
		else:
			t[-1].append(i)
	if len(t[-1])==0:del t[-1]
	m=[]
	for i in t:
		if len(i)<k:continue
		m+=sorted(i)[:len(i)-k+1]
	if len(m)<q:continue
	m.sort()
	ans=min(ans,m[q-1]-y)
print(ans)

Measured memory_bytes: 3188
from itertools import product
a = "KIH"
b = "B"
c = "R"
A = []
for x in product((0,1),repeat=4):
    z = ""
    if x[0]==1:
        z="A"+a
    else:
        z = a
    if x[1]==1:
        z += "A"+b
    else:
        z += b
    if x[2]==1:
        z += "A"+c
    else:
        z += c
    if x[3]==1:
        z += "A"
    A.append(z)
S = input().strip()
if S in A:
    print("YES")
else:
    print("NO")

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }
    sort(v.begin(), v.end());
    int price = 0;
    for (int i = 0; i < K; i++)
    {
        price += v.at(i);
    }
    cout << price;
}

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

const int n = 5;
string cur[5][5], nxt[5][5];
int a[50],b[50];

int main(){
  int t;
  int casenum = 1;

  while(cin >> t){
    if(t==0)break;
    if(casenum!=1)cout << endl;

    rep(i,5){
      rep(j,5)cin >> cur[i][j], nxt[i][j] = cur[i][j];
    }
    
    int m1,m2;
    cin >> m1;
    rep(i,m1)cin >> a[i];
    cin >> m2;
    rep(i,m2)cin >> b[i];

    while(t--){
      rep(i,n)rep(j,n)rep(k,n){
	int cnt = 0;
	Rep(ii,-1,2)Rep(jj,-1,2)Rep(kk,-1,2){
	  if(ii==0 && jj==0 && kk==0)continue;

	  int nx = i+ii, ny = j+jj, nz = k+kk;
	  if(nx<0 || ny<0 || nz<0)continue;
	  if(nx>=n || ny>=n || nz>=n)continue;
	  cnt += (cur[nx][ny][nz]=='1')?1:0;
	}
	bool f = false;
	if(cur[i][j][k] == '0'){
	  f = false;
	  rep(l,m1){
	    if(a[l] == cnt)f = true;
	  }
	}else{
	  rep(l,m2){
	    if(b[l] == cnt)f = true;
	  }
	}
	if(f)nxt[i][j][k] = '1';
	else nxt[i][j][k] = '0';
      }
    
      rep(i,n)rep(j,n)cur[i][j] = nxt[i][j];
    }

    cout << "Case " << casenum << ":" << endl;
    rep(i,n){
      rep(j,n)cout << cur[i][j] << endl;
      if(i+1!=n)cout << endl;
    }
    casenum++;
  }
}

Measured memory_bytes: 1220
n, m = map(int, input().split())
s_c = [list(map(int,input().split())) for _ in range(m)]
s = [s_c[i][0] for i in range(m)]
c = [s_c[i][1] for i in range(m)]
for i in range(10**n):
  flag = True
  if len(str(i)) < n:
    continue
  for j, k in enumerate(s):
    if str(i)[k-1] != str(c[j]) and flag == True:
      flag = False
      break
  if flag == True:
    print(i)
    exit()
print(-1)

Measured memory_bytes: 38412
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846
#define M   1000000007
ll gcd(ll a,ll b)
{
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll res=fast(n/2,a,m)%m;
        if(n%2==0)
            return (((res%m)*(res%m))%m);
        else
            return (((((res%m)*a)%m)*res)%m);
    }
}
ll lcm(ll a,ll b)
{
    ll p=a*b;
    p/=gcd(a,b);
    return p;
}
ll isprime(ll N)
{
    if(N==2||N==3)
    {
        return 1;
    }
    if(N%2==0||N%3==0)
    {
        return 0;
    }
    for(ll i=5;i*i<=N;i+=6)
    {
        if(N%i==0||N%(i+6)==0)
            return 0;
    }
    return 1;
}

int main()
{

    ll n,k;
    cin>>n>>k;
    ll i,A[n];
    for(i=0;i<n;i++)
    {
        cin>>A[i];
    }
    if(k>=n)
    {
        cout<<0;
    }
    else
    {
        sort(A,A+n);
        ll ans=0;
        for(i=0;i<n-k;i++)
        {
            ans+=A[i];
        }
        cout<<ans;
    }

}


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

int main() {
    int cnt = 0;
    string W, T, Tlow;

    cin >> W;
    transform(W.begin(), W.end(), W.begin(), ::tolower);
    do {
        cin >> T;
        Tlow = T;
        transform(Tlow.begin(), Tlow.end(), Tlow.begin(), ::tolower);
        if(!(Tlow.compare(W))) ++cnt;
    } while(T.compare("END_OF_TEXT"));
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9+7;
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
   int n,m;
   cin >>n>>m;
   vector <string> grid(n+1);
   for (int i=0;i<n;i++){
   	 cin>>grid[i];
   }

   int dp[n+1][m+1]={};
   dp[1][1]=1;

   for (int i=1;i<=n;i++){
   	for (int j=1;j<=m;j++){
   		if (grid[i-1][j-1]=='#'){
   			dp[i][j]=0;
   			continue;
   		}
   		dp[i][j]+=(dp[i][j-1]%MOD+dp[i-1][j]%MOD)%MOD;

   	}
   }
   // for (int i=1;i<=n;i++){
   // 	for (int j=1;j<=m;j++){
   	
   // 	cout<<dp[i][j]<<" ";}
   // 	cout<<"\n";
   // }
   cout<<dp[n][m];
	return 0;

}


Measured memory_bytes: 5248
#include <stdio.h>
#include <stdlib.h>

int main(void){

  char *S;
  S = (char *)malloc(sizeof(char));
  scanf("%s", S);

  int size;
  for(size=0; S[size]!='\0'; size++);

  int i=0, j;
  int rx;
  int start;
  int count;
  while(i != size){
    //printf("start i=%d\n", i);
    start = i;
    count = 0;
    while(S[i] != 'L'){
      if(i%2 == 0)
	count++;
      i++;
    }
    //printf("end of R : %d\n", i-1);
    //printf("count : %d\n", count);
    rx = i-1;
    //printf("R_x : %d\n", rx);
    while(S[i] != 'R' && i != size){
      if(i%2 == 0)
	count++;
      i++;
    }
    //printf("end of L : %d\n", i-1);
    //printf("count : %d\n", count);
    for(j=start; j<i; j++){
      if(j == rx )
	if(j%2 == 0)
	  printf("%d ", count);
	else
	  printf("%d ", i-start-count);
      else if(j == rx+1)
	if(j%2 == 0)
	  printf("%d ", count);
	else
	  printf("%d ", i-start-count);
      else
	  printf("0 ");
    }
  }
  printf("\n");
  return 0;
}


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

int main(){
    int n,k,ans=0;
    cin >> n >> k;
    int gu,tyoki,pa;
    cin >> gu >>tyoki >> pa;
    string s;
    cin >>s;
    vector<int> a(n,0);
    for(int i=0;i<n;i++){
        if(i>=k){
            if(s.at(i)!=s.at(i-k)){
                if(s.at(i)=='r'){ans+=pa;}
                if(s.at(i)=='s'){ans+=gu;}
                if(s.at(i)=='p'){ans+=tyoki;}
            }else{
                if(a.at(i-k)==0){
                    a.at(i)=1;
                }else{
                    if(s.at(i)=='r'){ans+=pa;}
                    if(s.at(i)=='s'){ans+=gu;}
                    if(s.at(i)=='p'){ans+=tyoki;}
                }
            }
        }else{
            if(s.at(i)=='r'){ans+=pa;}
            if(s.at(i)=='s'){ans+=gu;}
            if(s.at(i)=='p'){ans+=tyoki;}
        }
    }

    cout << ans << endl;
}




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

int N,M,S,T;
int st, ed;

unordered_map<int,vector<int>> R;
unordered_map<int,vector<int>> tr;

int ghs(int a,int b){
  return a * 24*60 + b;
}

int gettime(int t1,int t2){
  return t1*60 + t2;
}

const int INF = (1<<29);
typedef pair<int,int> P;
P dp[60*24+1][1101];
void update(P &a, P b){
  if( a.first < b.first ) a.first = b.first;
  if( a.second < b.second ) a.second = b.second;
  if( a.first < a.second ) a.first = a.second;
}
int solve(){
  fill( dp[0], dp[ed+1], P(-INF,-INF) );
  dp[st][S+M] = P(0,0);  
  for(int t=st;t<=ed;t++){
    for(int i=0;i<N+M;i++){
      int id = i%(N+M);
      if( dp[t][id].first == -INF ) continue;    
      if( id < M ) { // train
        if( R.count( ghs(id,t) ) )
          for( int nid : R[ghs(id,t)] )
            update( dp[t][nid+M], P(dp[t][id].first,0) );
        update( dp[t+1][id], P(dp[t][id].first,dp[t][id].second+1) );
      } else { //station
        int x = id-M;
        if( tr.count( ghs(x,t) ) )
          for( int nid : tr[ghs(x,t)] )
            update( dp[t+1][nid], P(dp[t][id].first,1) );
        update( dp[t+1][id], P(dp[t][id].first,0) );        
      }
    }
  }
  return dp[ed][T+M].first;
}


int main(){
  while( ~scanf("%d%d",&N,&M) && (N|M) ) {
    int t1,t2,t3,t4;
    scanf("%d %d:%d %d %d:%d",&S, &t1, &t2, &T, &t3, &t4);
    --S; --T;
    st = gettime( t1, t2 ), ed = gettime( t3, t4 );
    
    for(int i=0;i<M;i++){
      int n; scanf("%d",&n);      
      for(int j=0;j<n;j++){
        int k;
        scanf("%d %d:%d",&k,&t1,&t2);
        --k;        
        R[ghs(i,gettime(t1,t2))].emplace_back(k);
        tr[ghs(k,gettime(t1,t2))].emplace_back(i);
        //cout << i << " "<< gettime(t1,t2) << " " << R[i][gettime(t1,t2)] << endl;
        // cout << k << " "<< gettime(t1,t2) << " " << tr[k][gettime(t1,t2)] << endl;
      }            
    }

    int res = solve();
    if( res < 0 ) printf("impossible\n");
    else printf("%d\n",res);
    tr.clear();
    R.clear();
  }
}

Measured memory_bytes: 30312
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define PB push_back
#define MP make_pair
#define all(x) x.begin(),x.end()
#define MOD 1000000007

//RMQ セグメント木
struct SegmentTree{
private:
	int N;
	vector<long long> node;
	const long long DEFAULT = -9223372036854775807LL;
public:
	void init(int n){ //初期化する O(N)
		node.clear();
		N = 1;
		while(N < n) N *= 2;
		for(int i=0; i<2*N-1; i++) node.push_back(DEFAULT);
	}
	void update(int i, long long x){ //値を変更する O(log N)
		i += N - 1;
		node[i] = x;
		while(i > 0){
			i = (i-1)/2; //親の取得は(i-1)/2
			node[i] = max(node[i*2+1], node[i*2+2]); //子の取得はi*2+1,i*2+2
		}
	}
	long long minimum(int a, int b, int k=0, int l=0, int r=-1){ //[a,b)の最小値を求める O(log N)
		if(r == -1) r = N;
		if(r <= a || b <= l) return DEFAULT; //交差する場合
		if(a <= l && r <= b) return node[k]; //完全に含む場合
		return max( minimum(a, b, k*2+1, l, (l+r)/2) , minimum(a, b, k*2+2, (l+r)/2, r) );
	}
	long long m;
	int find(int a, int b, int k=0, int l=0, int r=-1){ //[a,b)の最小値の場所を求める O(log N)
		if(r == -1){
			m = minimum(a, b);
			r = N;
		}
		if(r <= a || b <= l) return INT_MAX; //交差する場合
		if(r-l == 1){
			if(node[k] == m) return l;
			else return INT_MAX;
		}
		if(a <= l && r <= b){ //完全に含む場合
			long long valueL = minimum(a, b, k*2+1, l, (l+r)/2);
			long long valueR = minimum(a, b, k*2+2, (l+r)/2, r);
			if(valueL >= valueR) return find(a, b, k*2+1, l, (l+r)/2);
			else return find(a, b, k*2+2, (l+r)/2, r);
		}
		return min( find(a, b, k*2+1, l, (l+r)/2) , find(a, b, k*2+2, (l+r)/2, r) );
	}
};

int X,Y,Z,K;
vector<LL> A,B,C,D;
int now[1000] = {};
SegmentTree st;

int main(){
	cin >> X >> Y >> Z >> K;
	A.resize(X);
	for(int i=0; i<X; i++){
		cin >> A[i];
	}
	B.resize(Y);
	for(int i=0; i<Y; i++){
		cin >> B[i];
	}
	C.resize(Z);
	for(int i=0; i<Z; i++){
		cin >> C[i];
	}
	for(int i=0; i<Y; i++){
		for(int j=0; j<Z; j++){
			D.PB(B[i]+C[j]);
		}
	}
	sort(A.begin(), A.end(), greater<LL>());
	sort(D.begin(), D.end(), greater<LL>());

	st.init(X);
	for(int i=0; i<X; i++){
		st.update(i,A[i]+D[0]);
	}
	for(int i=0; i<K; i++){
		cout << st.minimum(0,X) << endl;
		int idx = st.find(0,X);
		now[idx]++;
		if(now[idx] == D.size()) st.update(idx,-1);
		else st.update(idx,A[idx]+D[now[idx]]);
	}

	return 0;
}


Measured memory_bytes: 10480
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007

//qsort用、昇順
int compare_int(const void *a, const void *b)
{
	return *(int*)a-*(int*)b;
}
//qsort(data, 10, sizeof(int), compare_int)


int main(){
	int n;
	scanf("%d", &n);
	n = n%10;
	if(n==3) printf("bon\n");
	else if((n==0) || (n==1) || (n==6) || (n==8)) printf("pon\n");
	else printf("hon\n");

	//printf("%d\n", nowtown);
	
	return 0;
}

Measured memory_bytes: 1648
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	a, b, c, x, y := nextInt(), nextInt(), nextInt(), nextInt(), nextInt()

	m := a*x + b*y

	if x < y {
		m = min(m, c*y*2)
	} else {
		m = min(m, c*x*2)
	}

	if x < y {
		m = min(m, c*x*2+b*(y-x))
	} else {
		m = min(m, c*y*2+a*(x-y))
	}

	fmt.Println(m)
}


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

typedef long long int ll;
string s;

int main() {
    cin >> s;
    ll sum = 0;
    for(ll i = 0; i < s.length(); ++i) {
        sum += s[i] - '0';
    }

    if(sum%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;

#define MAX_N 1005
#define mm(ans1,ans2) memset(ans1,ans2,sizeof(ans1))
#define ll long long

int main() {
    ll n;
    while(~scanf("%lld",&n)) {
        ll ans1 = 1, ans2 = 1;
        ll x,y;
        for (int i = 0; i < n; i++) {
            scanf("%lld %lld", &x, &y);
            ll t = 1;
            ll t1 = 1;
            ll t2 = 1;
            t = 1;
            if (x >= ans1) { ;
            } else {
                t1 = ans1 / x;
                if (ans1 % x != 0)
                    t1++;
            }
            if(y < ans2) {
                t2 = ans2 / y;
                if (ans2 % y != 0)
                    t2++;
            }
            t = max(t1, t2);
            ans1 = x * t;
            ans2 = y * t;
        }
        printf("%lld", ans1 + ans2);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#define REP(i,a,b) \
for(int i=a; i<b; i++)
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long int
typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define tr(c,i) for(typeof(c.begin()) i = (c).begin(); i != (c).end();i++)

int main()
{
	int a,b;
	cin >> a >> b;
	int diff = b-a;
	int ans = (diff*diff+diff)/2 - b;
	cout << ans;
}


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

using namespace std;

typedef uint64_t ulint;
typedef int64_t lint;

// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;

template<class T> lint sum(vector<T> a);
template<class T> double ave(vector<T> a);
template<typename T> ostream& operator << (ostream& s, const vector<T>& v);
ulint gcd(lint a, lint b);
ulint lcm(lint a, lint b);

bool flagdebug = false;





////////////////////////////////////////////////////////////////////////
// Union - Find

// グローバル変数
const int MAX_N = 100010;
int par[MAX_N];
int rnk[MAX_N];

// 関数
void initunion(int n){
    rep0(i, n){
        par[i] = i;
        rnk[i] = 0;
    }
}

//木を駆け上がりrootを探索する
int findroot(int x){
    if(par[x] == x)return x;
    else return par[x] = findroot(par[x]);
}

//結合
void uniteroot(int x, int y){
    x = findroot(x);
    y = findroot(y);
    if( x == y )return; //結合済
    if(rnk[x] < rnk[y])par[x] = y;
    else if(rnk[x] > rnk[y])par[y] = x;
    else {
        par[y] = x;
        rnk[x]++;
    }
}

bool sameroot(int x, int y){
    return findroot(x) == findroot(y);
}

int main(){
//////////////////////////////////////////////////////

    //flagdebug = true; ///本番時削除！！！！！

    //入力
    lint n, m;
    cin >> n >> m;
    initunion(n);
    lint x , y, z;
    rep0(i, m)
    {
        cin >> x >> y >> z;
        uniteroot(x,y);
        
    }

    vector<lint> isroot(n,0);
    rep0(i,n)
    {
        isroot[findroot(i)] ++;
    }

    lint rootnum = 0;
    rep0(i,n)
    {
        if(isroot[i]>0)rootnum++;
    }

    cout << rootnum << endl;
    return 0;
}

//vectorprint用
template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
    s << "[\t";
    for (auto i = v.begin(); i < v.end() - 1; i++){s << *i << "\t";}
    s << *(v.end() - 1) << "\t]\n";
	return s;
}

// 最大公約数
ulint gcd(lint a, lint b){
    if(b!=0){return gcd(b, a % b);}
    return a;    
}

//最小公倍数
ulint lcm(lint a, lint b){
    return a / gcd(a, b) * b;
}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
 

public class Main{
          
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
            
             while((line=br.readLine())!= null){//if(line.isEmpty())break;
                String[] spl=line.split(" ");
                double xa1=Double.parseDouble(spl[0]);
                double ya1=Double.parseDouble(spl[1]);
                double xa2=Double.parseDouble(spl[2]);
                double ya2=Double.parseDouble(spl[3]);
                double xb1=Double.parseDouble(spl[4]);
                double yb1=Double.parseDouble(spl[5]);
                double xb2=Double.parseDouble(spl[6]);
                double yb2=Double.parseDouble(spl[7]);

               if(ya1<yb1&&ya1<yb2&&ya2<yb1&&ya2<yb2)System.out.println("NO");
               else if(ya1>yb1&&ya1>yb2&&ya2>yb1&&ya2>yb2)System.out.println("NO");
               else if(xa1>xb1&&xa1>xb2&&xa2>xb1&&xa2>xb2)System.out.println("NO");
               else if(xa1<xb1&&xa1<xb2&&xa2<xb1&&xa2<xb2)System.out.println("NO");
               else System.out.println("YES");
                
                /*if((yb-ya)*(yd-yc)==-1*(xb-xa)*(xd-xc)    )// dy1/dx1 * dy2/dx2 = -1 -> dy1*dy2 = -dx1*dx2
                 System.out.println("YES");
                else System.out.println("NO");
                 */
                
             }br.close();
             
         }catch(Exception e){e.printStackTrace();}         
     }
   
 }

Measured memory_bytes: 16956
/*
ID: arthurc4
TASK: test
LANG: C++11
*/

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <random>
#include <stack>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;

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

typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<bool> vb;
typedef vector<vb> vvb;

typedef map<string,int> msi;
typedef map<int,int> mii;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll; // note 'single' ls

typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++)

#define REPb(j, d, c) \
for (int j = int(d); j >= int(c); j--)

#define pb \
push_back

#define ff \
first

#define ss \
second

// LL OR INT ???
// DELETED IFSTREAM ???
int main()
{
	//ifstream cin("input.txt");
	//ifstream cin("test.in");
	//ofstream cout("test.out");

	int n;
	cin >> n;

	int k;

	REP(i, 1, 10000)
	{
		if(i*(i-1) == 2*n)
		{
			k = i;
			break;
		}

		if(i*(i-1) > 2*n)
		{
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	vi claimed(n+1, -1);

	vector<priority_queue<int>> elements_in_sets;
	priority_queue<int> fake;
	elements_in_sets.pb(fake);

	priority_queue<int> elements_yet_to_be_used;

	REP(i, 1, n)
	{
		elements_yet_to_be_used.push(-i);
	}

	cout << k << endl;

	REP(subset, 1, k)
	{
		cout << k-1 << " "; // the size of the subset is k-1

		priority_queue<int> current_subset_elements;

		REP(previous_subsets, 1, subset-1) // borrow elements from previous subsets
		{
			cout << -elements_in_sets[previous_subsets].top() << " ";

			// current_subset_elements.push(elements_in_sets[previous_subsets].top());

			elements_in_sets[previous_subsets].pop();
		}

		REP(extra_elements, 1, (k-1)-(subset-1))
		{
			cout << -elements_yet_to_be_used.top() << " ";

			current_subset_elements.push(elements_yet_to_be_used.top());

			elements_yet_to_be_used.pop();
		}

		elements_in_sets.pb(current_subset_elements);

		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2552
#include <cstdio>
using namespace std;

int main() {
  int a[4];
  int b[4];
  int hit, blow;

  while (1) {
    if (scanf("%d %d %d %d", &a[0], &a[1], &a[2], &a[3]) != 4) break;
    if (scanf("%d %d %d %d", &b[0], &b[1], &b[2], &b[3]) != 4) break;

    hit = blow = 0;
    for (int i=0; i<4; i++) {
      if (a[i] == b[i]) hit++;
    }
    for (int i=0; i<4; i++) {
      for (int j=0; j<4; j++) {
        if (a[i] == b[j]) blow++;
      }
    }
    blow -= hit;
    printf("%d %d\n", hit, blow);
  }

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    string s,s1;
    
    cin>>s>>s1;
    
    int x=0;
    
    for(int i=0; i<s.size(); i++){
        
        if(s[i]!=s1[i])
            x++;
    }
    
    cout<<x<<endl;

    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	ll x; cin>>x;
	ll sum = 0;
	ll t = 1;
	while(sum<x){
		sum+=t; t++;
	}
	cout<<t-1<<endl;
	return 0;
}


Measured memory_bytes: 256
var
	inv,now,n,m,ans,mo,p,facnm:int64;
	fac:array[0..30]of int64;
	i,j:Longint;
function power(a,b:int64):int64;
var ret:int64;
begin
	if b=0 then power:=1
	else begin
		ret:=power(a*a mod 1000000007,b div 2);
		if b mod 2=1 then ret:=ret*a mod 1000000007;
		power:=ret;
	end;
end;
begin
	read(n,m);
	ans:=1;
	mo:=1000000007;
	fac[0]:=1;
	for i:=1 to 30 do fac[i]:=fac[i-1]*i mod mo;
	facnm:=1;
	for i:=2 to n-1 do facnm:=facnm*i mod mo;
	inv:=power(facnm,mo-2);
	i:=2;
	while i*i<=m do begin
		if m mod i=0 then begin
			p:=0;
			while m mod i=0 do begin
				m:=m div i;
				inc(p);
			end;
			now:=facnm;
			for j:=1 to p do now:=now*(n+j-1)mod mo;
			ans:=ans*now mod mo*power(fac[p],mo-2)mod mo*inv mod mo;
		end;
		inc(i);
	end;
	if m>1 then ans:=ans*facnm mod mo*n mod mo*inv mod mo;
	writeln(ans);
end.

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
    int s; cin >> s;
    int a, b;
    a = s / 100;
    b = s  % 100;

    if (a > 0 && b > 0 && a <= 12 && b <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if (0 < a && a <= 12){
        cout << "MMYY" << endl;
    }else if (0 < b && b <= 12){
        cout << "YYMM" << endl;
    }else {
        cout << "NA" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    sort(d.begin(), d.end());

    int l = d[n/2-1];
    int r = d[n/2];

    cout << r - l << endl;
}


Measured memory_bytes: 3704
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
ans_arr = [arr[0]]
i = 1
while i < n - 1
  ans_arr.push([arr[i-1],arr[i]].min)
  i += 1
end
ans_arr.push(arr[n-2])
puts ans_arr.sum

Measured memory_bytes: 14336
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,t; cin>>n>>t;
    vector<int> a(n),b(n);
    rep(i,n) cin>>a[i]>>b[i];
    vector<vector<int>> dp1(n+1, vector<int>(3003, 0));
    vector<vector<int>> dp2(n+1, vector<int>(3003, 0));
    rep(i,n) {
        rep(j,3003) {
            chmax(dp1[i+1][j],dp1[i][j]);
            if (a[i]+j <= t-1) {
                chmax(dp1[i+1][a[i]+j],dp1[i][j]+b[i]);
            }
        }
    }

    for (int i = n; i >= 1; --i) {
        rep(j,3003) {
            if (a[i-1]+j<=t-1) {
                chmax(dp2[i-1][a[i-1]+j],dp2[i][j]+b[i-1]);
            }
            chmax(dp2[i-1][j],dp2[i][j]);
        }
    }

    ll ans = 0;
    rep(i,n) {
        ll tmp = 0;
        rep(j,t) {
            ll x = 0;
            x += dp1[i][j];
            x += dp2[i+1][t-j-1];
            x += b[i];
            chmax(tmp,x);
        }
        chmax(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70912
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

def make_divisors(n): # nの約数を列挙
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

N = ir()
D = make_divisors(N)
answer = 10 ** 12
for d in D[:(len(D)+1)//2]:
    e = N // d
    result = (d - 1) + (e - 1)
    if result < answer:
        answer = result

print(answer)


Measured memory_bytes: 3268
n, m = map(int, input().split())
for i in range(n):
    lst = [int(j) for j in input().split()]
    lst.pop(0)
    if i == 0:
        ans = list(lst)
    else:
        tmp = list(lst)
        for x in lst:
            if x not in ans:
                tmp.remove(x)
        ans = list(tmp)
print(len(ans))

Measured memory_bytes: 3060
using System;
using System.Linq;

namespace A___Fifty_Fifty
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().GroupBy(x => x).ToArray();

            Console.WriteLine(S[0].Count() == 2 && S[1].Count() == 2 ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 13280
// x * 0.08 == a -> x == a / 0.08 -> x == a * 100 / 8
// y * 0.10 == b -> y == b / 0.10 -> y == b * 10

#include <stdio.h>

int main(void)
{
  int a, b;
  scanf("%d %d", &a, &b);
  if (a < 1 || a > 100 || b < 1 || b > 100)
  {
    printf("-1");
    return 0;
  }
  
  int i, ina, inb;
  i = 1;
  ina = 0;
  inb = 0;
  while (i < 1010)
  {
    ina = i * 0.08;
    inb = i * 0.1;
    if (ina == a && inb == b)
    {
      printf("%d", i);
      return 0;
    }
    i++;
  }
  
  printf("-1");
  return 0;
}


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)

debug = True
debug = False

def dprint(*objects):
    if debug == True:
        print(*objects)
def dmatprint(mat):

    if debug == True:
        for row in mat:
            for col in row:
                print("{0:2d} ".format(col), end="")
            print("")
        print("")

def solve():
    H, W = map(int, input().split())
    s_arr = [[-1 for w in range(W)] for h in range(H)]
    for h in range(H):
        s_row = input()
        for w in range(W):
            if s_row[w] == ".":
                s_arr[h][w] = 0
            else:
                s_arr[h][w] = 1

    # 上下左右の配列
    r_arr = [[0 for w in range(W)] for h in range(H)]
    l_arr = [[0 for w in range(W)] for h in range(H)]
    u_arr = [[0 for w in range(W)] for h in range(H)]
    d_arr = [[0 for w in range(W)] for h in range(H)]

    # 左から
    for h in range(H):
        for w in range(W):
            if s_arr[h][w] == 1:
                continue
            else:
                if w == 0:
                    val = 1
                else:
                    val = l_arr[h][w-1] + 1
            l_arr[h][w] = val

    # 上から
    for w in range(W):
        for h in range(H):
            if s_arr[h][w] == 1:
                continue
            else:
                if h == 0:
                    val = 1
                else:
                    val = u_arr[h-1][w] + 1
            u_arr[h][w] = val

    # 右から
    for h in range(H):
        for w in reversed(range(W)):
            if s_arr[h][w] == 1:
                continue
            else:
                if w == W-1:
                    val = 1
                else:
                    val = r_arr[h][w+1] + 1
            r_arr[h][w] = val

    # 下から
    for w in range(W):
        for h in reversed(range(H)):
            if s_arr[h][w] == 1:
                continue
            else:
                if h == H-1:
                    val = 1
                else:
                    val = d_arr[h + 1][w] + 1
            d_arr[h][w] = val

    mx_ans = 0
    for h in range(H):
        for w in range(W):
            ans = l_arr[h][w] + r_arr[h][w] + u_arr[h][w] + d_arr[h][w] - 3
            if ans >= mx_ans:
                mx_ans = ans

    print(mx_ans)
    dmatprint(s_arr)
solve()

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

signed main(){
	int q;
	multiset<int>s;
	cin>>q;
	while(q--){
		int x,y;
		cin>>x>>y;
		if(x==1)cout<<s.count(y)<<endl;
		else if(!x){
			s.insert(y);
			cout<<s.size()<<endl;
		}
		else if(x==2)s.erase(y);
		else{
			int l=y,r;
			cin>>r;
			set<int>::iterator end,it;
			it=s.lower_bound(l);
			end=s.upper_bound(r);
			for(;it!=end;it++){
				cout<<(*it)<<endl;
			}
		}
	}
}


Measured memory_bytes: 12272
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List
import Data.Set (Set)
import qualified Data.Set as Set

main :: IO ()
main = do
  n <- getl toInt
  solve <$> replicateM n getLine >>= mapM_ print

solve :: [String] -> [Int]
solve = map train

train :: String -> Int
train xs = Set.size $ foldl (f xs) Set.empty [1 .. length xs - 1]
  where
    f :: String -> Set String -> Int -> Set String
    f ss st i = foldl (flip Set.insert) st $ [cs ++ ds | cs <- [as, reverse as], ds <- [bs, reverse bs]] ++ [ds ++ cs | cs <- [as, reverse as], ds <- [bs, reverse bs]]
      where
        (as,bs) = splitAt i ss

toInt :: String -> Int
toInt = read

getl :: (String -> a) -> IO a
getl f = f <$> getLine

Measured memory_bytes: 6516