akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
N = int(input())
S = input()
ans = 0
for v in range(1000):
    v = str(v).zfill(3)
    flag = [False for _ in range(3)]
    for i in range(len(S)):
        if not flag[0] and v[0] == S[i]:
            flag[0] = True
            continue
        if not flag[1] and v[1] == S[i]and flag[0]:
            flag[1] = True
            continue
        if not flag[2] and v[2] == S[i] and flag[1]:
            flag[2] = True
            break
    if sum(flag) == 3:
        ans += 1
print(ans)

Measured memory_bytes: 46044
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef long long ll;
int main()
{
    int N, P; cin >> N >> P;
    ll ans = 1;
    vector<int> A(N);
    for(int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    int X = 0, Y = 0;
    for(int i = 0; i < N; i++)
    {
        if(A.at(i) % 2 == 0)
        {
            X++; //A中の偶数袋の個数
        }
        else
        {
            Y++; //A中の奇数袋の個数
        }
    }
    for(int i = 0; i < N-1; i++)
    {
        ans *= 2;
    }
    if(X == N && P == 0)
    {
        cout << 2*ans <<endl;
    }
    else if(X == N && P == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for i in range(n)]

p, q = 0, 0
judge = 1000
for v in a:
  if v%10:
    p += v
    judge = min(judge, v)
  else:
    q += v

ans = p + q
if ans % 10 == 0:
  if judge == 1000:
    ans = 0
  else:
    ans -= judge

print(ans)
      



Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define bit(n) (1LL << (n))
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    char S;
    map<char, char> mp;
    mp['A'] = 'T', mp['T'] = 'A', mp['G'] = 'C', mp['C'] = 'G';
    cin >> S;
    cout << mp[S] << "\n";
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long h = sc.nextLong();   
        int res = 0;
        for (int i = 0; i <= 50; i++) {
            if (h >= Math.pow(2, i) && h < Math.pow(2, i+1)) {
                res = i;
                break;
            }
        }
        long sum = 0;
        for (int i = 0; i <= res; i++) {
            sum += Math.pow(2, i);
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 23252
n = int(input())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))

initial_monsters = sum(a_list)

for index, kill in enumerate(b_list):
    if a_list[index] > kill:
        a_list[index] = a_list[index] - kill
    else:
        remain_kill = kill - a_list[index]
        a_list[index] = 0
        a_list[index + 1] = a_list[index + 1] - remain_kill
        if a_list[index + 1] < 0:
            a_list[index + 1] = 0

print(initial_monsters - sum(a_list))

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

int judge(string str) {
  string headStr, tailStr;
  int rtn = -1;
  
  headStr = str.substr(0, 5);
  tailStr = str.substr(5, 3);
  if(headStr == "dream") {
    if(tailStr == "er" ||
       tailStr == "ere" ||
       tailStr == "erd") {
      rtn = 7;
    }
    else {
      rtn = 5;
    }
  }
  else if(headStr == "erase") {
    if(tailStr.size() > 0 && tailStr.at(0) == 'r') {
      rtn = 6;
    }
    else {
      rtn = 5;
    }
  }
  return rtn;
}


int main() {
  string str;
  uint curPos = 0;
  int rtn;
  string result = "YES";
  cin >> str;

  while(curPos < str.size()) {
    if(str.size() - curPos < 5) {
      result = "NO";
      break;
    }
    rtn = judge(str.substr(curPos));
    if(rtn < 0) {
      result = "NO";
      break;
    }
    else {
      curPos += rtn;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
    // freopen("1.txt", "r", stdin);
    int N;
    cin >> N;

    vector<double> p(N + 1);
    for(int i = 1; i <= N; ++i) cin >> p[i];

    int L = N / 2;
    vector<double> dp(L + 1, 0.0);
    dp[0] = 1.0;

    for(int i = 1; i <= N; ++i) {
        for(int j = min(i, L); j >= 0; --j) {
            dp[j] *= (1.0 - p[i]);
            if(j > 0)
                dp[j] += dp[j - 1] * p[i];
        }
    }
    double sum = 0;
    for(int i = 0; i <= L; ++i) sum += dp[i];
    printf("%.10f\n", 1 - sum);
    return 0;
}


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

int main(void){
    string s, t;
    cin >> s >> t;

    int ans = t.length();
    rep(i,s.length()-t.length()+1) {
        int cnt = 0;
        rep(j,t.length()) {
            if (s[i+j] != t[j]) {
                cnt++;
            }
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n-1){
        if (s[i] == 'A' && s[i+1] =='C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;
  int n = s.size();
  
  bool ok = true;
  if (s[0] != 'A') ok = false;
  rep(i,26) if (s[1] == 'A' + i || s[n-1] == 'A' + i) ok = false;
  string t = s.substr(2,n-3);
  int cnt = 0;
  rep(i,t.size()) {
    if (t[i] == 'C') cnt++;
    rep(j,26) {
      if (t[i] == 'A' + i && t[i] != 'C') ok = false;
    }
  }
  if (cnt != 1) ok = false;
  
  if (ok)
    cout << "AC" << endl;
  else
    cout << "WA" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)

int main(){
    int n, q;
    cin >> n >> q;
    LL st = 0;
    REP(i, q){
        int a, k;
        cin >> a >> k;
        if(a==0){
            LL ans = (k+st)%n;
            if(ans == 0) ans = n;
            cout << ans << endl;
        }else{
            st = (st+k)%n;
        }
    }

        return 0;
}



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

using namespace std;

#define endl '\n'

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

  int n, k;
  cin >> n >> k;
  vector<int> stones(n);
  vector<int> dp(n, 1e9);
  for (int i = 0; i < n; i++) {
    cin >> stones[i];
  }
  dp[0] = 0;
  dp[1] = abs(stones[0] - stones[1]);
  for (int i = 2; i < n; i++) {
    for (int j = 1; (i - j) >= 0 && j <= k; j++) {
      dp[i] = min(dp[i], dp[i - j] + abs(stones[i] - stones[i - j]));
    }
  }
  cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 3972
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {

	int X, Y, A, B, C;
	cin >> X >> Y >> A >> B >> C;
	vector<int> p(A);
	vector<int> q(B);
	vector<int> r(C);
	rep(i, A)cin >> p[i];
	rep(i, B)cin >> q[i];
	rep(i, C)cin >> r[i];

	priority_queue<int> P;
	priority_queue<int> Q;
	priority_queue<int> R;

	rep(i, A)P.push(p[i]);
	rep(i, B)Q.push(q[i]);
	rep(i, C)R.push(r[i]);

	int rX = X;
	int rY = Y;
	int rSum = X + Y;

	int a = P.top();
	int b = Q.top();
	int c = R.top();

	long long ans = 0;
	while (true)
	{		
		int abcmax = max(a, b);
		abcmax = max(abcmax, c);
		if (a == abcmax) {
			P.pop();
			ans += a;
			rX--; rSum--;
			if (rX == 0) a = -1;	
			else a = P.top();			
		}
		else if (b == abcmax) {
			Q.pop();
			ans += b;
			rY--; rSum--;
			if (rY == 0) b = -1;
			else b = Q.top();		
		}
		else if (c == abcmax) {
			R.pop();
			ans += c;
			rSum--;
			if (R.empty())c = -1;
			else c = R.top();	
		}	
		if (rSum == 0) {
			break;
		}
 	}

	cout << ans << endl;
}

Measured memory_bytes: 2936
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.next();
        }
        Map<String, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(s[i], map.getOrDefault(s[i], 0) + 1);
        }

        int max = 0;
        for (Integer value : map.values()) {
            max = Math.max(max, value);
        }
        List<String> ans = new ArrayList<>();
        for (Map.Entry<String, Integer> e : map.entrySet()) {
            if (e.getValue() == max) {
                ans.add(e.getKey());
            }
        }
        Collections.sort(ans);
        for (int i = 0; i < ans.size(); i++) {
            System.out.println(ans.get(i));
        }
    }

}


Measured memory_bytes: 83608
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
ll gcd(ll a,ll b)
{
	if(a%b==0)
		return b;
	else
		return gcd(b,a%b);
}
void solve()
{
    ll sol=0;
    ll k,a,b;
    cin>>k>>a>>b;
    sol=k+1;
    if(b-a>2)
    {
        if(k+1<=a)
        {
            cout<<sol;
            return;
        }
        k=k-a+1;
        sol=a+(k/2)*(b-a);
        if(k%2==1)
            sol=sol+1;
    }
    cout<<sol;
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
		solve();
	return(0);
}


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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> pic(H);
  for (int i=0; i<W+2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i=0; i<H; i++) {
    cin >> pic.at(i);
    cout << '#' << pic.at(i) << '#' << endl;
  }
  for (int i=0; i<W+2; i++) {
    cout << '#';
  }
}

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

int main(){


    std::vector<int> result_sum(4,0); // 結果格納

    int N;
    std::cin >> N;

     for(std::string judge_result; std::cin >> judge_result;){

         if(judge_result == "AC"){
             ++result_sum[0]; 
         }else if(judge_result == "WA"){
             ++result_sum[1];
         }else if(judge_result == "TLE"){
            ++result_sum[2];
         }else if(judge_result == "RE"){
            ++result_sum[3];
         }
     }
    
    std::cout << "AC x " << result_sum[0]<< std::endl;
    std::cout << "WA x " << result_sum[1]<< std::endl;
    std::cout << "TLE x " << result_sum[2]<< std::endl;
    std::cout << "RE x " << result_sum[3]<< std::endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n,k,q,i,x;
	int a[100010]={0};
	cin >> n >> k >> q;
	for(i=0;i<q;i++){
		cin >> x;
		a[x]++;
	}
	for(i=1;i<=n;i++){
		if(k+a[i]-q>0)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}


Measured memory_bytes: 1024
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
 
signed main() {
    int N;
    while(cin >> N, N) {
        vector<int> dp(N+1);
        dp[0] = 1;

        for(int i=0; i<N; i++) {
            for(int k=1; k<=3; k++) {
                if(i + k > N) continue;
                dp[i+k] += dp[i];
            }
        }
        const int YEAR = 3650;
        cout << (dp[N] + YEAR - 1) / YEAR << endl;
    }
    return 0;
}


Measured memory_bytes: 3000
/// input macro
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
///
/// # Example
///
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::io::Write;

macro_rules! eprintln (
    ($($arg:tt)*) => { {
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

fn main() {
    input! {
        nab: [u32; 3],
    }

    let n = nab[0];
    let a = nab[1];
    let b = nab[2];

    let mut ans = 0;
    for i in 1..n + 1 {
        let sum = i.to_string().chars().into_iter()
            .fold(0, |sum, x| sum + x.to_digit(10).unwrap());

        if a <= sum && sum <= b {
            ans += i;
            eprintln!("{}: {} <= {} <= {}", i, a, sum, b);
        }
    }

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



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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

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

  int n, k;
  cin >> n >> k;

  int ans = 0;
  reps(i, 1, n) {
    int x;
    cin >> x;
    ans += min(x * 2, abs(k - x) * 2);
  }

  cout << ans << "\n";

  return 0;
}

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

int main(){
    int n,k,q,a,p[(int)1e5]={};
    cin>>n>>k>>q;
    for(int i=0; i<q; i++){
        cin>>a;
        p[a-1]++;
    }
    for(int i=0; i<n; i++){
        if(p[i] + k > q)
            cout<<"Yes\n";
        else
            cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;
int main()
{
  int  r,c ;
  cin >> r >> c ;
  
  int a[r+1][c+1] ;
  
    for(int i=0;i<(r+1);i++){
      for(int j=0;j<(c+1);j++){
         a[i][j] = 0 ; 
      }
  }

  for(int i=0;i<r;i++){
      int tmp =0;
      for(int j=0;j<c;j++){
          cin >> a[i][j] ; 
          tmp += a[i][j];
          a[r][j] += a[i][j];
      }
          a[i][c] += tmp;
          a[r][c] += tmp;
  }
  
  for(int i=0;i<r+1;i++){
      for(int j=0;j<c;j++){
          cout <<  a[i][j] << " " ; 
      }
        cout <<  a[i][c] << "\n" ; 
  }
  
    return 0;
}



Measured memory_bytes: 3116
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("fma,avx")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

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

    int n;
    cin >> n;
    vector<int> ans(n + 1);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j * i <= n; j++) {
            ans[i * j]++;
        }
    }
    int res = 0;
    for (int i = 1; i <= n; i++) {
        res += i * ans[i];
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 81300
import sys
from collections import deque

input = sys.stdin.readline

n, q = map(int, input().split())
path = [[] for _ in range(n + 1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    path[a].append(b)
    path[b].append(a)

ans = [0] * (n + 1)

for i in range(q):
    p, x = map(int, input().split())
    ans[p] += x

alr = [0] * (n + 1)
alr[1] = 1

que = deque([[1, 0]])
while len(que) > 0:
    now = que.popleft()
    ans[now[0]] += now[1]
    for j in path[now[0]]:
        if alr[j] == 0:
            que.append([j, ans[now[0]]])
            alr[j] = 1

for i in range(1, n + 1):
    print(ans[i], end=' ')
print()


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

using namespace std;

using pii = pair<int, int>;
using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n;
string s[1003];

bool comp(string a, string b, int k) { // a > b
  if(b.length() == k) {
    return (a.length() > k);
  }else if(a.length() == k)return false;

  if('0' <= b[k] && b[k] <= '9') {
    if('0' <= a[k] && a[k] <= '9') {
      int na = 0, nb = 0, j = 0;
      for(j=k;'0' <= a[j] && a[j] <= '9';++j)na = na*10 +(a[j]-'0');
      for(j=k;'0' <= b[j] && b[j] <= '9';++j)nb = nb*10 +(b[j]-'0');
      if(na > nb)return true;
      else if(na < nb)return false;
      else return comp(a, b, j);
    }else return true;
  }else if('0' <= a[k] && a[k] <= '9') return false;
  else {
    if(a[k] > b[k])return true;
    else if(a[k] < b[k])return false;
  }
  return comp(a, b, k+1);
}

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

  cin >> n;
  rep(i, n+1)cin >> s[i];

  rep(i, n)cout << ( comp(s[0], s[i+1], 0) ? '-' : '+' ) << endl;

	return 0;
}



Measured memory_bytes: 3280
given = ["dreamer", "dream", "eraser", "erase"]
S = input()
while len(S) > 0:
    judge = [S.endswith(i) for i in given]
    if any(judge):
        target = given[judge.index(True)]
        S = S[:-len(target)]
        if len(S) == 0:
            print("YES")
            break
    else:
        print("NO")
        break

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

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> A(H);
  for(int i=0; i<H; i++){
    cin >> A.at(i);
  }
  vector<int> P(W+H-1, 0);
  for(int i=0; i<W; i++){
    for(int j=0; j<H; j++){
      if(A.at(j).at(i)=='#'){
        P.at(i+j)++;
      }
    }
  }
  int Ans=1;
  for(int i=0; i<W+H-1; i++){
    if(P.at(i)!=1){
      Ans=0;
    }
  }
  if(Ans==1){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};



main(){
  int n;
  while(cin>>n,n){
    vector<int> in;
    int sum=0;
    rep(i,n){
      int t;
      cin>>t;
      sum+=t;
      in.pb(t);
    }
    sort(ALL(in));
    sum-=in[0]+in.back();
    cout<<sum/(n-2)<<endl;
    
    
  }
}

Measured memory_bytes: 0
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong MOD = 1_000_000_007;
ulong INF = 1_000_000_000_000;
ulong MIDDLE = 100_000;
alias Pair = Tuple!(long, "flag", long, "num");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    auto prime = new long[](n);
    long len;
    foreach (i; iota(2, n + 1))
    {
        long flag = 1;
        foreach (j; iota(2, i))
            flag = flag && i % j;

        if (flag)
            prime[len++] = i;
    }
    auto prime_fact = new long[](n + 1);
    foreach (i; iota(1, n + 1))
    {
        foreach (j; iota(len))
        {
            while (i > 0 && !(i % prime[j]))
            {
                i /= prime[j];
                prime_fact[prime[j]]++;
            }
        }
    }
    long ans = 1;
    foreach (e; prime_fact)
    {
        if (e)
        {
            ans *= e + 1;
            ans %= MOD;
        }
    }
    ans.writeln();
}


Measured memory_bytes: 256
n = int(input()) + 2
a = [0] + list(map(int, input().split())) + [0]
b = [0] + list(map(int, input().split())) + [0]
a_sum = sum(a)
b_sum = sum(b)
ans = 0
a_count = [a[0]] + [0]*(n-1)
b_count = [b[0]] + [0]*(n-1)
for i in range(1, n) :
  a_count[i] = a[i] + a_count[i-1]
  b_count[i] = b[i] + b_count[i-1]
for i in range(1, n-1) :
  ans = max(ans, a_count[i] + b_sum - b_count[i-1])
print(ans)

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

int main() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  ll ans = 0;
  vector<bool> win(n, false);
  rep(i, n) {
    if (i >= k && t[i] == t[i - k] && win[i - k]) {
      continue;
    }
    if (t[i] == 'r') {
      ans += p;
    } else if (t[i] == 's') {
      ans += r;
    } else {
      ans += s;
    }
    win[i] = true;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull; 
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define SQ(a) (a)*(a)

template <class T, class U> ostream& operator<< (ostream &out, pair<T,U> c) { out << "(" << c.first << " "; out << c.second << ")"; return out; }
template <class T> ostream& operator<< (ostream &out, vector<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
template <class T> ostream& operator<< (ostream &out, set<T> c) { for (auto it = c.begin(); it != c.end(); ++it) { if (it != c.begin()) out << " "; out << *it; } return out; }
const double PI  = 3.141592653589793238463;


int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, d, x, a, day, p;
    cin >> n >> d >> x;
    FOR(i,0,n){
        cin >> a;
        x++;
        p = 1;
        day = 1;
        while(day <= d - a){
            x++;
            day = p*a + 1;
            p++;
        }
    }
    cout << x << endl;
}   

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll r, g, b;
    cin >> r >> g >> b;

    if( (10*g + b)%4 == 0 ) {
        out("YES");
    }
    else {
        out("NO");
    }
    
    re0;
}

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

#define stirng string
#define vvi vector<vector<int>>
#define vi vector<int>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const int inf = 1e9 + 7;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
  return 0;
}


Measured memory_bytes: 256
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s,t;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>n;
    cin>>m;
    cout<<6-n-m<<endl;

}   aryanc403();
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


char board[100][100];


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

	int a, b;
	cin >> a >> b;

	rep(i,100) {
		if (i < 50) {
			rep(j, 100)board[i][j] = '.';
		}
		else {
			rep(j, 100)board[i][j] = '#';
		}
	}
	a--; b--;
	rep(i,INF) {
		for (int j = 1; j < 99;j++) {
			if (b == 0)break;
			if (j % 2)board[i * 3 + 1][j] = '#';
			else board[i * 3 + 2][j] = '#';
			b--;
		}
		if (b == 0)break;
	}
	rep(i, INF) {
		for (int j = 1; j < 99; j++) {
			if (a == 0)break;
			if (j % 2)board[50 + i * 3 + 1][j] = '.';
			else board[50 + i * 3 + 2][j] = '.';
			a--;
		}
		if (a == 0)break;
	}
	cout << 100 << ' ' << 100 << endl;
	rep(i,100) {
		rep(j, 100)cout << board[i][j];
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#coding:utf-8
import numpy as np

n = int(input())
d = list(map(int, input().split()))
d.sort()
#print(d)


if n % 2 == 1:
    print(0)
else:
    i = n // 2
    border1 = d[i]
    border2 = d[i- 1]
    if (border1 - border2) == 0:
        print(0)
    else:
        print(border1 - border2)

Measured memory_bytes: 23460
#include <stdio.h>

int main(int argc, char* argv[]) {
    int num=0, least=0, passed=0;
    scanf("%d %d", &num, &least);
    for(int i=0; i < num; ++i) {
        int tmp = 0;
        scanf("%d", &tmp);
        if(tmp >= least) passed += 1;
    }
    printf("%d\n", passed);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

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

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  REP(x, k + 1) {
    REP(y, k + 1) {
      int z = max(0, min(s - x - y, k));
      if (x + y + z == s) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

map<ll,int> primeFact(ll n) {
	map<ll,int> r;
	for(ll i=2; i*i<=n; i++)
		while(n%i == 0) {
		r[i]++;
		n /= i;
		}
	if(n != 1)
		r[n] = 1;
	return r;
}

int main() {
	ll N,r=0;
	cin >> N;
	map<ll,int> m = primeFact(N);

	for(auto p : m) {
		int x = (int)sqrt(p.second*2);
		if(x*(x+1) > p.second*2)
			--x;
		r += x;
	}

	cout << r << endl;
}

Measured memory_bytes: 3640
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define Precise cout.precision(7);
using namespace std;

int main()
{
   ll n,i,j;
    cin>>n;
    ll a[n];
    for( i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    bool ok=1;
    for( i=0;i<n-1;i++)
    {
    if(a[i]==a[i+1]){ok=0;break;}
    }
    if(ok)
    cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}





Measured memory_bytes: 5064
#include<stdio.h>
#include<string>
#include<iostream>
using namespace std;

int main(){

char x,y,c,p[1025];
int N;
string str,S;
scanf("%d",&N);
for(int i=0;i<N;i++){
cin>>str;
int R=1024,L=1024,T=1024;
for(int i=0;i<str.size();i+=3)
{if(i==0)S=str[0];
else {
if(str[i-1]=='>'){T++;if(T>R){S=S+str[i];R=T;}}
else if(str[i-1]=='-'){T--;if(T<L){S=str[i]+S;L=T;}}
}
}
cout<<S<<endl;
}
return 0;
}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    V<ll> a(n), b(n);
    V<P<ll, ll> > ab(n);
    ll sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        ab[i] = make_pair(b[i], a[i]);
        sum += a[i];
    }

    sort(ALL(b));
    if(b[n - 1] < sum){
        cout << "No" << endl;
        return 0;
    }

    sort(ALL(ab));
    ll suma = 0;
    for(int i = 0; i < n; i++){
        suma += ab[i].second;
        if(suma <= ab[i].first) continue;
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

}


Measured memory_bytes: 6656
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}


int main(void){
    int r;
    int g;

    scanf("%d %d", &r, &g);
    printf("%d\n", 2*g-r);

    return 0;
    
}


Measured memory_bytes: 128
(let* ((n (read))
       (m (read))
       (shift (- n m))
       (a (make-array n))
       (b (make-array m))
       (matchp nil))
  (dotimes (i n)
    (setf (aref a i) (read-line)))
  (dotimes (i m)
    (setf (aref b i) (read-line)))
  (loop for y from 0 to shift until matchp do
    (loop for x from 0 to shift until matchp do
      (setf matchp
            (loop for i from 0 below m always
                  (loop for j from 0 below m always
                        (eq (char (aref b i) j)
                            (char (aref a (+ i y)) (+ j x))))))))
  (format t "~A~%" (if matchp "Yes" "No")))

Measured memory_bytes: 6504
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
constexpr std::array<int, 6> coin_value{ 1, 5, 10, 50, 100, 500 };

int coin_for_pay(int pay, const std::array<int, 6> & coins) {
	int sum = 0;
	for (int i = 5; i >= 0; --i) {
		auto need = pay / coin_value[i];
		sum += std::min(coins[i], need);
		pay -= std::min(coins[i], need) * coin_value[i];
	}
	if (pay == 0) return sum;
	else return -1;
}
int coin_for_change(int change) {
	int sum = 0;
	for (int i = 5; i >= 0; --i) {
		sum += change / coin_value[i];
		change %= coin_value[i];
	}
	return sum;
}
int min_coin(const int pay, const std::array<int, 6> &coins) {
	int min = INT_MAX;
	for (auto p = pay; p < pay + 501; ++p) {
		auto for_pay = coin_for_pay(p, coins);
		if (for_pay >= 0) {
			auto sum = for_pay + coin_for_change(p - pay);
			min = std::min(sum, min);
		}
	}
	return min;
}

int main() {
	while (true) {
		int p; std::cin >> p; if (p == 0) return 0;
		std::array<int, 6> coin; for (auto& c : coin) std::cin >> c;
		std::cout << min_coin(p, coin) << std::endl;
	}
}




Measured memory_bytes: 3004
n, m = map(int, input().split())
h = [int(i) for i in input().split()]
g = [1]*n
b = [[int(i) for i in input().split()] for _ in range(m)]
for i in b:
  if h[i[0]-1] >= h[i[1]-1]:
    g[i[1]-1] = 0
  if h[i[0]-1] <= h[i[1]-1]:
    g[i[0]-1] = 0
print(n-g.count(0))

Measured memory_bytes: 30312
N, K = map(int, input().split())
H = [int(h) for h in input().split()]
dp = [N*10**4]*N
dp[0] = 0
for i in range(1,N):
    x = max(0, i-K)
    minimam = N*10**4
    for j in range(x, i):
        if i == 1:
            minimam = dp[0] + abs(H[i]-H[i-1])
        minimam = min(minimam, dp[j] + abs(H[i]-H[j]))
    dp[i] = minimam
print(dp[N-1])

Measured memory_bytes: 52448
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int H,W;
    cin>>H>>W;
    char a[101][101];
    for(int i=0; i<H; i++)
        for(int j=0; j<W; j++)
            cin>>a[i][j];
    for(int i=0; i<=H+1; i++)
    {
        if(i==0 || i==H+1)
            for(int j=0; j<=W+1; j++)
                cout<<'#';
        else{
            for(int j=0; j<=W+1; j++)
            {
                if(j==0 || j==W+1)
                    cout<<'#';
                else
                    cout<<a[i-1][j-1];
            }
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s[] = sc.nextLine().split(" ");
		double a = Integer.parseInt(s[0]);
		double b = Integer.parseInt(s[1]);
		double C = Integer.parseInt(s[2]);
		double radC = Math.toRadians(C);
		double sinC = Math.sin(radC);
		double cosC = Math.cos(radC);
		double tanC = Math.tan(radC);
		double cc = (a * a + b * b) - (2 * a * b * cosC);
		double S = ((double) 1 / 2) * a * b * sinC;
		double L = a + b + (Math.sqrt(cc));
		double h = b * sinC;
		System.out.println(String.format("%.8f", S));
		System.out.println(String.format("%.8f", L));
		System.out.println(String.format("%.8f", h));
	}
}


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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

ll dx[]={0,0,1,-1,1,1,-1,-1};
ll dy[]={1,-1,0,0,1,-1,1,-1};

int main()
{
    ll n,m;
    cin >> n >> m;
    char a[n][m];
    ll b[n][m];
    mset(b,0);
    for(ll i = 0; i < n; i++)
    {

        for(ll j = 0; j < m; j++)
            scanf(" %c", &a[i][j]);
    }
    for(ll i = 0; i < n; i++)
        for(ll j =0;j<m;j++){
            if(a[i][j]=='.')
            {

                for(ll k = 0;k<8;k++)
                {

                    ll x=i+dx[k];
                    ll y = j+dy[k];
                    if(x >=0 && x < n && y >=0 && y < m && a[x][y]=='#') b[i][j]++;
                }
            }
        }
    for(ll i=0;i<n;i++)
    {

        for(ll j = 0;j<m;j++)
        {

            if(a[i][j]=='.') cout << b[i][j];
            else cout << a[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
///2nd problem atcoder contest
///Bismillahir Rahmanir Rahim...
#include<iostream>
#include<algorithm>
using namespace std;

#define endl "\n"
#define ar array
#define ma 1000

int main()
{
    int n,k,i,ar[ma],sum=0;
    cin>>n>>k;

    for(i=0;i<n;i++)
    {
        cin>>ar[i];
    }

    sort(ar,ar+n);

    for(i=0;i<k;i++)
    {
        sum=sum+ar[i];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 3164
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>

using namespace std;

typedef long long llint;
typedef long double ld;

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; }

int n;



void solve(){
  cin >> n;
  llint dp[n];
  int h[n];
  for(int i=0;i<n;i++){
    cin >> h[i];
    dp[i]=1LL<<60;
  }
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  for(int i=2;i<n;i++){
    chmin(dp[i],dp[i-1]+abs(h[i]-h[i-1]));
    chmin(dp[i],dp[i-2]+abs(h[i]-h[i-2]));
  }
  cout << dp[n-1] << endl;

}

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


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  int n;
  cin >> n;
  vector<double> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  
  double q = v[0];
  rep(i,n-1){
    q = (v[i+1]+q)/2;
  }
  cout << fixed << setprecision(8)<< q << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
string s;
cin>>s;
string t="CODEFESTIVAL2016";
ll k=0;
ll n=s.size();
for(ll i=0; i<n; i++){
if(s.at(i)!=t.at(i))
k++;}
cout<<k<<endl;}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if(S == "SSS"){
    cout << 0 << endl;
  }else if(S == "SSR" || S == "SRS" || S == "RSS" || S == "RSR"){
    cout << 1 << endl;
  }else if(S == "RRR"){
    cout << 3 << endl;
  }else{
    cout << 2 << endl;
  }
  return 0;
}


Measured memory_bytes: 3596
import sys
import numpy as np


#  sys.setrecursionlimit(10**7)
#  inf = 10 ** 20
#  eps = 1.0 / 10**10
#  mod = 10**9+7
#  dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
#  ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    N = I()
    h = LI()
    h = np.array(h)
    #  print(N, h)
    # 0以上の塊をみつける
    # その塊に水をやる
    # 以上を繰り返す
    count = 0
    while True:
        #  print(h)
        first_non_zero_idx = [idx for idx, i in enumerate(h) if i != 0]
        if len(first_non_zero_idx) == 0:
            # 終了
            print(count)
            return
        else:
            first_non_zero_idx = first_non_zero_idx[0]

        first_zero_idx = [idx for idx, i in enumerate(h) if idx > first_non_zero_idx and i == 0]
        if len(first_zero_idx) == 0:
            # 0がないので最後まで水をやる
            first_zero_idx = len(h)
        else:
            first_zero_idx = first_zero_idx[0]

        # 水をやる
        h[first_non_zero_idx:first_zero_idx] -= 1
        count += 1





main()


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

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

  int max_bell = max(a, max(b, c));
  if (max_bell == a){
    cout << b + c << endl;
  }
  else if (max_bell == b)
  {
    cout << a + c << endl;
  }
  else
  {
    cout << a + b << endl;
  }
  
  
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
P = list(map(int, input().split()))
for i in range(N):
    P[i] -= 1
M = 60
step = [[0]*(M+1) for _ in range(N)]

for i in range(N):
    step[i][0] = P[i]

for i in range(1, M+1):
    for j in range(N):
        c = step[j][i-1]
        c = step[c][i-1]
        step[j][i] = c

c = 0
for j in range(M+1):
    if K % 2:
        c = step[c][j]
    K //= 2
print(c+1)


Measured memory_bytes: 201168
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    int n,k;
    cin >> n >> k;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    sort(a.begin(),a.end());
    ll ans =0;
    for(int i=0;i<k;i++)ans+=a.at(i);
    cout<<ans<<endl;
}
    



Measured memory_bytes: 3632