akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n, t;
  cin >> n >> t;
  vector<ll> a(n); // cost
  vector<ll> b(n); // profit
  rep(i, n) {
    ll aa, bb;
    cin >> a[i] >> b[i];
  }
  // printvec(a);
  // printvec(b);

  vector<P> dishes;
  rep(i, n) {
    dishes.emplace_back(b[i], a[i]);
  }
  sort(all(dishes));
  reverse(all(dishes));
  // Now, dishes are sorted in decreasing order of profit. If profit is same, then higher t is in ftont.

  // cout << "dishes: " << endl;
  // rep(i, n) {
  //   cout << dishes[i].fr << ", " << dishes[i].sc << endl;
  // }

  ll ans = 0;
  rep(selected_i, 10) {
    if (selected_i >= n) { continue; }

    P p = dishes[selected_i];
    // Now, we use dished[1..-1] for napsack dp.

    // Limit is t-1.

    set<ll> selected;

    vector<ll> dp(t + 1, 0);
    // dp[i][j] .. the maximum profit by using item <= i and cost <= j.
    for (int i = 0; i < n; ++i) {
      if (i == selected_i) { continue; } // skip

      ll cost = dishes[i].sc; // cost
      ll profit = dishes[i].fr; // profit

      for (int j = t - 1; j >= 0; --j) { // reverse because only one in each item
        if ((j - cost) >= 0) {
          dp[j] = max(dp[j], dp[j - cost] + profit);
        }
      }
    }
    // cout << "dp: "; printvec(dp);
    // Here, dp[n-1][t] is the maximum profit.

    chmax(ans, dp[t-1] + p.fr);
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int ans=0;
  sort(a.begin(),a.end(),greater<int>());
  int flag=1;
  for(int i=0;i<N-1;i++){
    if(i==N-2){
      if(a[i]==a[i+1]){
	ans+=(flag+1)%2;
	flag=1;
      }else{
	ans++;
	ans+=flag%2;
      }
    }else if(a[i]==a[i+1]){
      flag++;
    }else{
      ans+=(flag)%2;
      flag=1;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    int cnt = 0;
    cin >> n;
    REP(i,n){
        int a;
        cin >> a;
        if(i%2==0){
            if(a%2==1){
                cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }
 
ll rec(int i, ll cur, ll sum, const string &S) {
    if(i == S.size()) {
        return sum;
    }
    int d = S[i] - '0';
    ll res = 0;
    if(i + 1 != S.size())
        res += rec(i + 1, cur * 10 + d, sum, S);  
    res += rec(i + 1, 0, sum + cur * 10 + d, S);
    return res;
}
 
int main() {
    string S;
    while(cin >> S) {
        ll ans = rec(0, 0, 0, S);
        printf("%lld\n", ans);
    }
    return 0;
}

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

using namespace std;

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

    double a = 0;
    for (int i = 0; i < N; i++) {
        a += x[i];
    }
    a /= N;

    int p = round(a);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans += (x[i]-p) * (x[i]-p);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;

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

type Graph = Vec<Vec<usize>>;

struct Solver {
    visited: Vec<bool>,
    preord: Vec<Option<usize>>,
    postord: Vec<Option<usize>>,
    i_count: usize,
}

impl Solver {
    fn dfs(&mut self, g: &Graph, v: usize) {
        self.visited[v] = true;
        self.preord[v] = Some(self.i_count);
        self.i_count += 1;

        for &w in g[v].iter() {
            if self.visited[w] {
                continue;
            }
            self.dfs(g, w);
        }

        self.postord[v] = Some(self.i_count);
        self.i_count += 1;
    }

    fn dfs_wrapped(&mut self, g: &Graph) {
        for s in 0..g.len() {
            if self.visited[s] {
                continue;
            }
            self.dfs(g, s);
        }
    }
}

// impl Solver {
//     fn solve(&mut self) {
//         let n = self.g.len();

//         // Construct a graph
//         for _ in 0..n {
//             let u: usize = read();
//             let k = read();
//             for _ in 0..k {
//                 let v: usize = read();
//                 self.g[u - 1].push(v - 1);
//             }
//         }

//         // Perform a depth first search
//         for s in 0..n {
//             if self.preord[s].is_some() {
//                 continue;
//             }
//             self.dfs(s);
//         }

//         // Print the result
//         for i in 0..self.g.len() {
//             if self.preord[i].is_some() {
//                 println!(
//                     "{} {} {}",
//                     i + 1,
//                     self.preord[i].unwrap() + 1,
//                     self.postord[i].unwrap() + 1
//                 );
//             } else {
//                 unreachable!();
//             }
//         }
//     }
// }

fn main() {
    let n = read();

    let mut g: Graph = vec![vec![]; n];
    for _ in 0..n {
        let u: usize = read();
        let k = read();
        for _ in 0..k {
            let v: usize = read();
            g[u - 1].push(v - 1);
        }
    }

    let mut s = Solver {
        visited: vec![false; n],
        preord: vec![None; n],
        postord: vec![None; n],
        i_count: 0,
    };

    s.dfs_wrapped(&g);

    for i in 0..n {
        println!(
            "{} {} {}",
            i + 1,
            s.preord[i].unwrap() + 1,
            s.postord[i].unwrap() + 1
        );
    }
}



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


int main()
{
    int n,k;
    cin>>n>>k;
    vector<int> ar(n,0);
    for(int i=0;i<n;++i)
    cin>>ar[i];
    vector<int> dp(n,INT32_MAX);
    dp[0]=0;
    for(int i=1;i<n;++i)
    {
        for(int j=max(i-k,0);j<i;++j)
        {
            dp[i]=min(dp[i],dp[j]+abs(ar[i]-ar[j]));
        }
    }
   cout<<dp[n-1]<<'\n';
 }



Measured memory_bytes: 3960
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int,int> P;
int N,M,K,a,b,l,k,inf = 2e9;
int C[3010] = {},use[3010] = {};
int cost[3010][3010] = {};
//vector<vector<P>> v(3010);
int main(){
    cin >> N >> M >> K;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            if(i!=j) cost[i][j] = inf;
        }
    }
    for(int i=0;i<M;i++){
        cin >> a >> b >> l;
        cost[a][b] = l;
        cost[b][a] = l;
    }
    for(int i=1;i<=N;i++) C[i] = inf;
    for(int i=1;i<=K;i++){
        cin >> k;
        C[k] = 0;
    }
    while(true){
        int id = -1;
        for(int i=1;i<=N;i++){
            if(use[i]==0 && (id==-1 || C[id]>C[i])) id = i;
        }
        if(id==-1) break;
        use[id] = 1;
        for(int i=1;i<=N;i++){
            C[i] = min(C[i],C[id]+cost[id][i]);
        }
    }
    int ans = 0;
    //for(int i=1;i<=N;i++) cout << C[i] << endl;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            int c = 0;
            if(cost[i][j]!=inf){
                if(C[i]+cost[i][j]<=C[j]) c = C[j];
                else if(C[j]+cost[i][j]<=C[i]) c = C[i];
                else c = (C[i]+C[j]+cost[i][j]+1)/2;
                ans = max(ans,c);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 38364
/*
 * atcoder/abc170/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

#include <set>
void solve() {
  int x, n;
  cin >> x >> n;
  set<int> S;
  for (int i=-110; i<=110; i++) {
    S.insert(i);
  }
  loop(i,0,n) {
    int a;
    cin >> a;
    S.erase(a);
  }

  int min_ = 10000000;
  int val = 0;
  for (int i=110; i>=-110; i--) {
    if (S.count(i) == 0) continue;
    if (min_ >= abs(x-i)) {
      min_ = abs(x-i);
      val = i;
    }
  }
  cout << val << endl;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("Ofast")
#include <iostream>
using namespace std;
 
inline void fastin(int &num) {
    int c;
    num = 0;
    c = getchar_unlocked();
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
}
 
inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}
 
int main(){   
    int n; fastin(n); 
    char c = 'E';
    int cnt = 1;
    
    int t1; fastin(t1);
    for (int i = 1; i < n; ++i){
        int t2; fastin(t2);
        if (t2 > t1){
            if (c == 'E') c = 'U';
            else if (c == 'D'){
                ++cnt; c = 'E';
            }
        }
        else if (t2 < t1){
            if (c == 'U'){
                ++cnt; c = 'E';
            }
            else if (c == 'E') c = 'D';
        }
        t1 = t2;
    }

    fastout(cnt);
    
    return 0;
}

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

int main() {
 
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B == C + D) {
    cout << "Balanced" << endl;
  } else if (A + B < C + D) {
    cout << "Right" << endl;
  } else {
    cout << "Left" << endl;
  }

}

Measured memory_bytes: 256
package main

import (
        "fmt"
        "math"
)

func main() {
        var v, t, h float64
        for {
                _, err := fmt.Scanf("%f", &v)
                if err != nil {
                        break
                }
                t = v / 9.8
                h = 4.9 * t * t
                n := math.Floor(h/5+1.0) + 1.0
                fmt.Printf("%d\n", int(n))
        }
}



Measured memory_bytes: 1104
#include<stdio.h>
#define MAX 100
#define INF 10000000
int min(int a,int b)
{
  if(a<b)
    return a;
  else return b;
}

int main()
{
  int n,i,j,l,k,q;
  int m[MAX+1][MAX+1];
  int p[MAX+1];
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d%d",&p[i],&p[i+1]);
    }

  for(i=1;i<=n;i++)
    {
      m[i][i]=0;
    }
  for(l=2;l<=n;l++)
    {
      for(i=1;i<=n-l+1;i++)
        {
          j=i+l-1;
          m[i][j]=INF;
          for(k=i;k<=j-1;k++)
            {
              q=m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j];
              m[i][j]=min(m[i][j],q);
            }
        }
    }
  printf("%d\n",m[1][n]);
          


  return 0;
}
  



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

int main(){
	int n,m,s;
	cin>>n>>m>>s;
	for(int i=0;i<n+1;++i){
		for(int k=0;k<m+1;++k){
			//cout<<k*n+i*m-i*k<<endl;
			if(k*n+i*m-2*i*k==s){
				//cout<<k*n+i*m-i*k<<endl;
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

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

#define ll long long

using namespace std;

ll n,k,m,ans;

int main(){
    ios::sync_with_stdio(false);
    cin>>n>>k;
    m=n/k;
    ans=m*m*m;
    if(!(k&1)){
        m=(n+k/2)/k;
        ans+=m*m*m;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

int main(){
  int n;

  cin>>n;

  for(int i=0;i<n;++i){
    int y,m,d;
    int cnt=0;

    cin>>y>>m>>d;

    if(d!=1){
      if(y%3==0 || m%2!=0)
	cnt=20-d+1;
      else
	cnt=19-d+1;
      m++;
      if(m==11){
	m=1;
	y++;
      }
    }

    if(m!=1){
      if(y%3==0)
	cnt=cnt+(10-m+1)*20;
      else
	while(m!=11){
	  if(m%2==0)
	    cnt+=19;
	  else
	    cnt+=20;
	  m++;
	}
      y++;
    }

    while(y!=1000){
      if(y%3==0)
	cnt+=20*10;
      else
	cnt=cnt+20*5+19*5;
      y++;
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 3108
import math
n = int(input())
alst = list(map(int, input().split()))
lst = []
ind = 0
num = 0
while ind < n - 1:
  if alst[ind] == alst[ind + 1]:
    num += 1
  else:
    if num != 0:
      lst.append(num + 1)
    num = 0
  ind += 1
if num != 0:
  lst.append(num + 1)

ans = 0
for i in lst:
  if i % 2:
    ans += (i - 1) // 2
  else:
    ans += i // 2
print(ans)  

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int s1,s2,s3,s4;
  
  cin >> n;
  
  s4=n%10;
  s3=(n/10)%10;
  s2=(n/100)%10;
  s1=n/1000;
  
  if(((s1==s2)&&(s2==s3))||((s2==s3)&&(s3==s4))){
    cout<< "Yes"<<endl;
  }
  
  else{
  cout << "No"<< endl;
  }
  
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (int i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define fi first
#define se second
#define int long long
using namespace std;
using ll = long long;
using II = pair<int, int>; using VII = vector<II>; using VVII = vector<VII>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
template <class T> using V = vector<T>; template <class T> using VV = V<V<T>>; template <class T> using VVV = V<VV<T>>;
template <class T = int> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T = int> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
template <class T> ostream& operator<<(ostream &s, const vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, const vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, const pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, const map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1e9 + 7;

int dif(int type, int x) {
  if (type == 0 || type == 4) return x;
  if (type == 1 || type == 3) return x == 0 ? 2 : x % 2;
  return (x + 1) % 2;
}
signed main() {
  int n; cin >> n;
  VI a(n); REP (i, n) cin >> a[i];
  VVI dp(n + 1, VI(5, 1e18));
  REP (j, 5) dp[0][j] = 0;
  REP (i, n) {
    REP (j, 5) {
      REP (k, j + 1) {
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][k] + dif(j, a[i]));
      }
    }
  }
  int ans = 1e18;
  REP (j, 5) ans = min(ans, dp[n][j]);
  cout << ans << endl;
}


Measured memory_bytes: 16000
#!/usr/bin/env python3
#ABC59 C
n = int(input())
a = list(map(int,input().split()))

ans1 = 0
s1 = 0
for i in range(n):
    s1 += a[i]
    if i % 2 == 0:
        if s1 > 0:
            continue
        else:
            ans1 += 1 - s1
            s1 = 1
    else:
        if s1 < 0:
            continue
        else:
            ans1 += s1 + 1
            s1 = -1
ans2 = 0
s2 = 0
for i in range(n):
    s2 += a[i]
    if i % 2 == 0:
        if s2 < 0:
            continue
        else:
            ans2 += s2 + 1
            s2 = -1
    else:
        if s2 > 0:
            continue
        else:
            ans2 += 1 - s2
            s2 = 1

print(min(ans1,ans2))


Measured memory_bytes: 14468
N,K=map(int,input().split())
A=[]
for i in range(N):
    h=int(input())
    A.append(h)
A.sort()

ans=1000000000
for j in range(N-K+1):
    if abs(A[j]-A[j+K-1])<ans:
        ans=abs(A[j]-A[j+K-1])
print(ans)

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

using namespace std;

int red[501][510];
int blue[501][510];

int main () {
	int n, m;
	cin >> n >> m;
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			char x;
			cin >> x;
			red[i][j] = x - '.';
			blue[i][j] = x - '.';
		}
	}
	for (int i = 1;i <= n;i ++) {
		red[i][1] = '#' - '.';
		blue[i][m] = '#' - '.';
	}
	for (int i = 1;i <= n;i += 2) {
		for (int j = 2;j < m;j ++) {
			red[i][j] = '#' - '.';
		}
	}
	for (int i = 2;i <= n;i += 2) {
		for (int j = 2;j <= m;j ++) {
			blue[i][j] = '#' - '.';
		}
	}
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			cout << (char) (red[i][j] + '.');
		}
		cout << endl;
	}
	for (int i = 1;i <= n;i ++) {
		for (int j = 1;j <= m;j ++) {
			cout << (char) (blue[i][j] + '.');
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=1<<30;
const double pi=acos(-1);

int x,y,sum=0,num=0,n=0;
char t;

int main(){
//	cout<<shosu(0);
	while(cin>>x>>t>>y){
		sum+=x*y;
		num+=y;
		n++;
	}
	cout<<sum<<endl;
	if(!n) cout<<0<<endl;
	else{
		double ans=(double)num/n;
		int tmp=ans;
		if(ans-tmp>=0,5) cout<<tmp+1<<endl;
		else cout<<tmp<<endl;
	}
}

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

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;

typedef std::pair<int,int> PII;

const LL MOD = 1e9 + 7;

int N;
int main() {
    std::cin >> N;
    std::vector<int> mp(N/2 + (N%2 != 0), 0);
    REP(i, N) {
        int A;
        std::cin >> A;
        mp[A/2]++;
    }
    if(N % 2 != 0) {
        mp[0]++;
    }
    if(std::count_if(ALL(mp), [](int x){return x == 2;}) == mp.size()) {
        int ans = 1;
        REP(i, N/2) {
            ans = (ans*2) % MOD;
        }
        std::cout << ans << std::endl;
    } else {
        std::cout << 0 << std::endl;
    }
}

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

typedef long long int ll;

long long int modPow(long long int a, long long int n){//繰り返し自乗法(a^n mod p)。計算量 O(logN)
    long long int p = pow(10, 9) + 7;//任意のp(素数) modのやつで使える 
    if(n == 0){
        return 1;
    }
    if(n == 1){
        return a % p;
    }
    if (n % 2 == 1){ 
        return (a * modPow(a, n - 1)) % p;
    }      
    long long t = modPow(a, n / 2);
    return (t * t) % p;
}

int main(){
    int x;
    cin >> x;
    if(x >= 400 && x <= 599){
        cout << 8 << endl;
    }else if(x >= 600  && x <= 799){
        cout << 7 << endl;
    }else if(x >= 800 && x <= 999){
        cout << 6 << endl;
    }else if(x >=   1000&& x <= 1199){
        cout << 5 << endl;
    }else if(x >=  1200&& x <= 1399){
        cout << 4 << endl;
    }else if(x >= 1400 && x <= 1599){
        cout <<  3<< endl; 
    }else if(x >= 1600 && x <= 1799){
        cout << 2 << endl;
    }else if(x >=  1800 && x <= 1999){
        cout << 1<< endl;
    }
}

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


const int MAX_V = 10000;
const int MAX_E = 100000;
int finde[MAX_V];

struct Edge {
	int first;
	int second;
	int weight;
};
vector<Edge> e;

bool operator < (const Edge a, const Edge b) {
	return a.weight < b.weight;
}

bool Judge(int m, int n) {
	while (finde[m] != m) m = finde[m];
	while (finde[n] != n) n = finde[n];
	if (m == n) {
		return false;
	}
	 finde[n]= m;
	return true;
}

int min_span_tree(int n, int m) {

	for (int i = 0; i < m; i++) finde[i] = i;
	int count = 0;
	int ret = 0;
	int f, s;
	for (int i = 0;count<m-1; i++) {
		f = e[i].first;
		s = e[i].second;
		if (Judge(f,s)) {		
			ret += e[i].weight;
			count++;
		}
	}
	return ret;
}
int main() {
	int n, m;
	cin >> m >> n;
	for (int i = 0; i < n; i++) {
		int s, t, w;
		cin>>s>>t>>w;
		e.push_back(Edge{ s, t, w });
	}
	sort(e.begin(), e.end());
	int ret = min_span_tree(n, m);
	cout << ret << endl;
	return 0;
}


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

typedef long long ll;
const int N=3*100005;
int aa[N],bb[N],cc[N];

int main() 
{
	int x,y,a,b,c;
	cin >>x>>y>>a>>b>>c; 
	for(int i=0;i<a;i++) cin >> aa[i];
	for(int i=0;i<b;i++) cin >> bb[i];
	for(int i=0;i<c;i++) cin >> cc[i];
	sort(aa,aa+a,greater<int>());
	sort(bb,bb+b,greater<int>());

	for(int i=0;i<x;i++) cc[c+i]=aa[i];
	for(int i=0;i<y;i++) cc[c+x+i]=bb[i];

	sort(cc,cc+c+x+y,greater<int>());
	ll ans=0;
	for(int i=0;i<x+y;i++) ans+=cc[i];
	cout <<ans;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int mod = 1000000000+7;

vector<vector<int>>G;
vector<vector<int>>T;
vector<int>visited;

void dfs(int v){
    visited[v] = 1;
    rep(i, G[v].size()){
        int next = G[v][i];
        if(visited[next])   continue;
        T[v].push_back(next);
        dfs(next);
    }
}

vector<vector<ll>>dp;
void solve(int v){
    rep(i, T[v].size()){
        int c = T[v][i];
        if(T[c].size()) solve(c);
        (dp[v][0] *= (dp[c][0] + dp[c][1])) %= mod;
        (dp[v][1] *= dp[c][0]) %= mod;
    }
}

int main(){
    int n;  cin >> n;
    G.resize(n);
    T.resize(n);
    visited.resize(n);
    dp.resize(n, vector<ll>(2, 1));
    rep(i, n-1){
        int x,y;    cin >> x >> y;
        --x;    --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    /*
     *make tree
     */
    dfs(0);
    /*
     * dp
     */
    solve(0);
    cout << (dp[0][0] + dp[0][1])%mod << endl;
}


Measured memory_bytes: 21248
import collections
def counter_list(A):
  counter = collections.Counter(A)
  counter =  [list(e) for e in counter.items()]
  counter.sort() #sortしたい場合はつける
  return counter

N = int(input())
D = list(map(int,input().split()))
#print(D)

#ans = ans*(D[i][1]**D[i+1][1]) (mod 998244353)
if(D[0] != 0): ans = 0 #一番最初が0でないなら
else: 
  D = counter_list(D) # [[0,1],[1,3],...] → 0:1個,1:3個,...
  if(D[0][1] != 1):
    ans = 0
  else:
   ans = 1
   for i in range(len(D)-1):
      if(D[i+1][0] - D[i][0] != 1):
        ans = 0
        break
      a = D[i][1]%998244353
      b = D[i+1][1]
      ans = ans%998244353
      ans = ans*(a**b)
      ans = ans%998244353
print(ans)

Measured memory_bytes: 25564
import java.util.Scanner;


public class Main {

		public static class BIT{
				int[] dat;
				
				public BIT(int n){
						dat = new int[n + 1];
				}
				
				public void add(int k, int a){
						for(int i = k + 1; i < dat.length; i += i & -i){
								dat[i] += a;	
						}
				}
				
				public int sum(int s, int t){
						if(s > 0) return sum(0, t) - sum(0, s);
						
						int ret = 0;
						for(int i = t; i > 0; i -= i & -i) {
								ret += dat[i];
						}
						return ret;
				}
				
				public int get(int k){
						int p = Integer.highestOneBit(dat.length - 1);
						for(int q = p; q > 0; q >>= 1, p |= q){
								if( p >= dat.length || k < dat[p]) p ^= q;
								else k -= dat[p];
						}
						return p;
				}
		}
		
		public static void main(String[] args){
				Scanner sc = new Scanner(System.in);
				
				while(true){
						final int n = sc.nextInt();
						final int k = sc.nextInt();

						if(n == 0 && k == 0){
								break;
						}

						BIT bit = new BIT(n);
						for(int i = 0; i < n; i++){
								bit.add(i, sc.nextInt());
						}

						int max = Integer.MIN_VALUE;
						for(int start = 0; start < n - k + 1; start++){
								max = Math.max(max, bit.sum(start, start + k));
								//System.out.println("[" + start + " " + (start + k) + ") = " + bit.sum(start, start + k));
						}
						
						System.out.println(max);
				}
		}
}

Measured memory_bytes: 63992
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main{
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int M = sc.nextInt();
		
		final int size = N + 2;
		int[] sum = new int[size];
		
		for(int i = 0; i < M; i++){
			final int from = sc.nextInt();
			final int to = sc.nextInt();
			
			sum[from] += 1;
			sum[to] -= 1;
		}
		for(int i = 1; i < size; i++){
			sum[i] += sum[i - 1];
		}
		
		//System.out.println(Arrays.toString(sum));
		int ans = N + 1;
		for(int i = 0; i < size; i++){
			if(sum[i] > 0){
				ans += 2;
			}
		}
		
		System.out.println(ans);
		
		
		sc.close();
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		// 他のnextXXXもXXX.parseXXX()メソッドを使って作れるので省略

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 18500
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <sstream>
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i,n) for(int i = 1; i <= n; i++)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
using namespace std;
ll mod = 1e9 + 7;
ll INF = 1e10;

int main()
{
	int maxA = 100000;
	vector<int> table(maxA + 1, 0);
	int n;
	cin >> n;
	rep(i, n)
	{
		int tmp;
		cin >> tmp;
		table[tmp]++;
	}
	int num2 = 0;
	int ans = 0;
	rep1(i, maxA)
	{
		int t = table[i];
		if (t >= 3) t = (t % 2 == 0) ? 2 : 1;
		if (t == 2) num2++;
		ans += t;
	}
	int dec = (num2 % 2 == 0) ? num2 : num2 + 1;
	ans -= dec;
	co(ans);
	return 0;
}


Measured memory_bytes: 768
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <sstream> 
#include <cctype>

using namespace std; 

typedef unsigned long long ULL;

int main(){

	ios::sync_with_stdio(false);
	string s;

	while(cin>>s,s!="#"){

		//各文字が置換されたものか，そうでないのかを
		//全パターン試すと各ケースでO(2^n),n<=20であり，
		//ICPCルールなら十分であるが，AOJだとTLE

		//半分全列挙
		//前半ss1,n,N 後半ss2,m,M
		//前半と後半を結合すると結局O(2^n)になるが，
		//全列挙よりは多少はマシになるはず(?)
		set<string> ss1,ss2;
		int n=s.size()/2;
		int m=s.size()-n;
		ULL N=(1ULL<<n);
		ULL M=(1ULL<<m);

		vector<string> ans;

		//前半
		for(ULL state=0;state<N;++state){
			string str=s.substr(0,n);
			for(int i=0;i<n;++i){
				if((1<<i)&state && str[i]!='z') str[i]++;
			}
 
			ss1.insert(str);
		}

		//後半
		for(ULL state=0;state<M;++state){
			string str=s.substr(n);
			for(char i=0;i<m;++i){
				if((1<<i)&state && str[i]!='z') str[i]++;
			}

			ss2.insert(str);
		}

		//前半と後半の結合
		for(auto it1=ss1.begin();it1!=ss1.end();++it1){
			for(auto it2=ss2.begin();it2!=ss2.end();it2++){

				//再度置換して，入力と同じになればansへ
				string str=(*it1)+(*it2);
				bool app[26]={false};
				for(char i=0;i<n+m;++i){
					char c=str[i]-'a';
					if(!app[c] && c!=0){
						--str[i];
						app[c]=true;
					}
				}
				if(str==s) ans.push_back((*it1)+(*it2)+"\n");

			}
		}

		const ULL sz=ans.size();
		cout<<sz<<endl;

		if(sz<=10){
			for(char i=0;i<sz;i++)
				cout<<ans[i];
		}else{
			cout<<ans[0]+ans[1]+ans[2]+ans[3]+ans[4]
			+ans[sz-5]+ans[sz-4]+ans[sz-3]+ans[sz-2]<<ans[sz-1];
		}


	}

	return 0;
}

Measured memory_bytes: 2844
#include <bits/stdc++.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};

// Problem Specific Parameter:

int main(void){
	int n,k;
	cin >> n >> k;
	int tmp;
	rep(i,n) cin >> tmp;

	int cur = 1, ans = 0;
	while(cur < n){
		cur += k-1;
		ans++;
	}

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

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

int main() {
	int n,d,x; cin >> n >> d >> x;
	int a[110];
	for (int i = 1; i <= n; ++i) cin >> a[i];
	int total = n + x;
	for (int i = 1; i <= n; ++i) {
		total += (d - 1) / a[i];
	}
	
cout << total << endl;
}

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

int main(){
    int N;
    cin>>N;
    vector<ll> A(N);
    ll ans=0;
    for(int i=0; i<N; i++){cin>>A[i];ans+=A[i];}
    sort(A.begin(),A.end());
    vector<ll> C(N/2);
    for(int i=0; i<N/2; i++)C[i]=A[2*i]+A[2*i+1];
    for(int i=0; i<N/2; i++){
        if(C[i]<0) ans-=2*C[i];
        else break;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
int Max(int(a), int(b), int(c)) {
	return max(max(a, b), c);
}
int Min(int(a), int(b), int(c)) {
	return min(min(a, b), c);
}





int main() {

	int N;
	cin >> N;
	string an = "No";
	if (N <11|| N == 12  || N == 14 || N == 15 || N == 16 || N == 18 || N == 20 || N == 21 || N == 24 || N == 25 || N == 27 || N == 28 || N == 30 || N == 32 || N == 35 || N == 40 || N == 42 || N == 36 || N == 45 || N == 48 || N == 49 || N == 54 || N == 56 || N == 63 || N == 64 || N == 72 || N == 81) {
		an = "Yes";
	}
	
	
	cout << an << endl;
}

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

using namespace std;

int n, sol, usu;
int main()
{
    ios::sync_with_stdio(false);

    cin >> n;

    if(n % 2 == 0)
    {
        cout << -1;
        return 0;
    }

    sol = 1;
    usu = 7;
    while(true)
    {
        if(usu % n == 0)
        {
            cout << sol;
            return 0;
        }

        usu = usu % n;
        usu = usu * 10 + 7;

        ++sol;
        if(sol == 1000000)
        {
            cout << -1;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3644
import java.util.Scanner;
import java.util.Arrays;

public class Main {

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

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N=sc.nextInt();
        long[] X=new long[N];
        long[] X1=new long[N];
        long sum=0;
        for(int i=0;i<N;i++){
            X[i]=sc.nextLong();
            X1[i]=X[i];
        }
        Arrays.sort(X1);
        long ans=X1[N/2-1];
        for(int i=0;i<N;i++){
            if(X[i]>ans){
                System.out.println(X1[(N/2)-1]);
            }else{
                System.out.println(X1[(N/2)]);
            }
        }
        
    }
}

Measured memory_bytes: 94696
#include <stdio.h>

int main(void)
{
	int d, i;
	int v;
	
	while (scanf("%d", &d) != EOF){
		
		v = 0;
		i = 0;
		
		for (i = 1; i < 600 / d; i++){
			
			v = v + d * i * d * i * d;
		}
 		
		printf("%d\n", v);
	}
	
	return (0);
}
	

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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;


void solve()
{
	int n;
	cin >> n;
	set<string>st;
	loop(i, 0, n)
	{
		string s;
		cin >> s;
		st.insert(s);
	}
	cout << sz(st) << endl;
	return;

}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}

Measured memory_bytes: 19200
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::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 == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S;
	cin >> S;
	vi W(N), B(N);
	int w = 0;
	int b = 0;
	REP(i, N) {
		B[i] = b;
		if (S[i] == '#') {
			b++;
		}
	}
	REPR(i, N) {
		W[i] = w;

		if (S[i] == '.') {
			w++;
		}
	}
	int ans = 1e9;
	REP(i, N) {
		chmin(ans, B[i] + W[i]);
	}
	cout << ans << endl;
	return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

vector<ll> l(8);
ll N, A, B, C;

ll dfs(ll now, ll a, ll b, ll c){
	if(now==N){
		if(a==0||b==0||c==0) return LLONG_MAX/3;
		return abs(a-A) + abs(b-B) + abs(c-C);
	}
	ll res = dfs(now+1, a, b, c);
	res = min(res, dfs(now+1, a+l[now], b, c)+(a!=0)*10);
	res = min(res, dfs(now+1, a, b+l[now], c)+(b!=0)*10);
	res = min(res, dfs(now+1, a, b, c+l[now])+(c!=0)*10);
	return res;
}

int main(){
	cin >> N >> A >> B >> C;
	REP(i, N) cin >> l[i];
	cout << dfs(0, 0, 0, 0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
int main(){
    string heap;
    int m;
    while(true){
        cin>>heap;
        if(heap=="-")break;
        cin>>m;
        int x;
        for(int i=0;i<m;i++){
            cin>>x;
            string heap1=heap.substr(0,x);
            heap.erase(0,x);
            heap=heap+heap1;
        }
        cout<<heap<<endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <cstring>
#include <algorithm>
#include <vector>
//#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
using namespace std;
#define fin << '\n'
#define finl << '\n';
#define finn cout << '\n'
#define unless(flg) if(!(flg))
#define alles(obj) obj.begin(), obj.end()
// bashise
#define elif else if
#define echo cout <<
#define read cin >>
// javaise
#define bash push_back
#define makePair make_pair
#define isEmpty empty
// germanise
#define drucken(obj) cout << obj << '\n'
#define lesen(obj) cin >> obj
#define fur for
#define wenn if
#define sonst else
#define Zahl int
// type-define
#define String string
#define Stack stack
#define Queue queue
#define pQueue priority_queue
#define Vector vector
#define Pair pair
#define Map map
typedef long long llong;
typedef bool boolean;
typedef Pair<int,int> Pii;
typedef Vector<int> Vi;
// utils
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
boolean isMovable(int x,int y,int w,int h){return (x>=0&&y>=0&&x<w&&y<h);};
const int INF = 1 << 29;

int a[48], b[48], c[48];

    int n, ma, mb;
int dp[48][500][500];

int gcd ( int x, int y ) {
    return y ? gcd(y, x%y) : x;
}

int dfs ( int pos, int a_hi, int b_hi ) {
    if ( a_hi && a_hi%ma == 0 && a_hi && b_hi%mb == 0 
            && a_hi * mb == b_hi * ma ) return 0;

    if ( pos == n ) return INF;

    if ( ~dp[pos][a_hi][b_hi] ) return dp[pos][a_hi][b_hi];

    int great = gcd ( a_hi+a[pos], b_hi+b[pos]);

    return dp[pos][a_hi][b_hi] = min (
        dfs ( pos+1, a_hi, b_hi ),
        dfs ( pos+1, a_hi+a[pos], b_hi+b[pos]) + c[pos]);
}

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

    read n >> ma >> mb;
    for ( int i = 0; i < n; i++ ) {
        read a[i] >> b[i] >> c[i];
    }
    memset(dp, -1, sizeof(dp));
    int ans = dfs(0, 0, 0);
    if ( ans >= INF ) echo -1 fin;
    else echo ans fin;

    return 0;
}


Measured memory_bytes: 47104
# -*- coding: utf-8 -*-

def main():
    input_string = raw_input().strip()
    down_positions = []
    ponds = []
    for index, value in enumerate(input_string):
        if value == '\\':
            down_positions.append(index)
        elif value == '/' and down_positions:
            right = index
            left = down_positions.pop()
            area = right - left
            candidate_pond = []
            while ponds and left < ponds[-1][0]:
               candidate_pond.append(ponds.pop(-1))

            new_pond = (left, area + sum([x[1] for x in candidate_pond]))
            ponds.append(new_pond)
    
    print sum(x[1] for x in ponds)
    print len(ponds), 
    for pond in ponds:
        print pond[1], 

if __name__ == '__main__':
    main()

Measured memory_bytes: 6888
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>

#define FOR(i, a) for(int i=0;i<(int)a;++i)
typedef long long ll;
using namespace std;

void solver() {
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (0 <= x - r && x + r <= W &&
        0 <= y - r && y + r <= H) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    solver();
    return 0;
}

Measured memory_bytes: 3096
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <functional>
#include <numeric>
#include <cassert>
#include <algorithm>
#include <functional>
//#include "bits/stdc++.h"
using namespace std;
//using namespace std::vector;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)

#define huge 1000000007
typedef long long int ll;
ll gcd(ll a, ll b);

int main(void) {

	ll N = 0;
	ll A = 0;
	ll B = 0;
	ll C = 0;
	ll D = 0;
	ll M = 0;
	//ll T = 0;
	//ll M = 0;
	ll h[1000] = {};
	ll b[100] = {};
	//ll c[100] = {};
	//ll d[100] = {};

	//ll v[3] = {};
	//ll *c, *s, *n;
	string S,T,U[52];
	ll count = 10;
	ll count2 = 0;
	float sum = 0;
	ll min = 1000000000000;
	ll max = 0;
	ll smax = 0;
	ll max2 = 0;
	ll smax2 = 0;
	int tmax = 0;
	int tmax2 = 0;
	int flag = 0;
	char temp,head;
	//int is = 0;
	
	
	//char p;


	

	

	//cin >> S;
	
	//b = (ll *)malloc(M * sizeof(ll));
	//vector<pair<int,int>> ch(50);

	cin >> S;
	
	

	rep(i,0, S.length() - 2) {

		T = S.substr(i,3);

		tmax = (atoi(T.c_str()));

		smax = abs(753-tmax);

		//cout <<min << "," <<smax << endl;

		if (min > smax) {
			min = smax;
		}

	}
	cout << min << endl;

	//x = (ll *)malloc((N+1) * sizeof(ll));
	//c = (ll *)malloc((N) * sizeof(ll));
	//cin >> D >> G;
	//vector<pair<int,int>> tr(M);
	//vector<pair<int,int>> qes(Q);
	//sort(c.begin(), c.end());
	
	//cout << c[2] - c[1] << endl;

	
	/*A = N / 1000;
	N %= 1000;
	B = N / 100;
	N %= 100;
	C = N / 10;
	N %= 10;
	D = N;*/
	


	//cin >> N >> M;

	//vector<pair<int,int>> c(M);
	////vector<pair<int, int>> e(M);
	//vector<ll> d(M);

	//rep(i, 0, M) {
	//	cin >> c[i].first >> c[i].second;
	//	//e[i].first = c[i].first;
	//	//e[i].second = c[i].second;

	//}
	////sort(c.begin(), c.end());

	//

	//rep(i, 0, M) {

	//	
	//	
	//	rep(j, 0, M) {
	//		if (c[i].first == c[j].first && c[j].second < c[i].second) {
	//			d[i]++;
	//			//cout << j << endl;
	//		}
	//	}
	//	cout << std::setfill('0') << std::right << std::setw(6) << c[i].first;
	//	cout << std::setfill('0') << std::right << std::setw(6) << d[i]+1 << endl;
	//}

	return 0;

}

ll gcd(ll a, ll b) {
	
	/* 自然数 a > b を確認・入替 */
	if (a<b) {
		ll tmp = a;
		a = b;
		b = tmp;
	}
	ll x = b;
	ll y = a;
	/* ユークリッドの互除法 */
	ll r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}


	return y/b*x;
}



Measured memory_bytes: 256