akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main()
{
  ios::sync_with_stdio(false);
  int n, t = 1, max;
  cin >> n;
  vector<int> v(n);

  for (int i = 0; i < n; ++i)
    cin >> v[i];

  max = v[0];
  for (int i = 1; i < n; ++i)
  {
    if (v[i] >= max)
      t++;

    if (v[i] > max)
      max = v[i];
  }

  cout << t << "\n";
  return 0;
}

Measured memory_bytes: 256
// abc_105_B

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

bool eight_odd(int n) {
	int counter = 0;
	for(int i = 1; i <= n; ++i) {
		if((n % 2 == 1) && (n % i == 0)) ++counter;
		else continue;
	}

	if(counter == 8) return true;
	else return false;
}


int main()
{
	int n;
	cin >> n;

	int counter = 0;
	for(int i = 1; i <= n; ++i) {
		if(eight_odd(i)) ++counter;
		else continue;
	} 

	cout << counter << "\n";

	return 0;

}

Measured memory_bytes: 256
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split()) 
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
mn = 1234567890123
for i in range(1,10**6+1):
  if n%i > 0:
    continue
  if i + n//i < mn:
    mn = i + n//i
print(mn-2)


Measured memory_bytes: 40428
// AOJ本を参考に(ほとんどコピー)
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    stack<int> S1;
    stack< pair<int , int> > S2;
    char ch;
    int sum = 0;
    for(int i = 0; cin >> ch; i++){
        if(ch == '\\'){
            S1.push(i);
        }else if(ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop(); // \の位置
            sum += i-j;
            int a = i-j; // 今入力された/から対応する\までの距離＝面積
            
            // 今新しくできた水たまりが過去の水たまりを包含している場合、以下のwhileループで再計算する
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; 
                S2.pop(); // 包含された水たまりの面積を今の水たまりに加え、スタックS2から削除
            }
            S2.push(make_pair(j,a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout << sum << endl;
    cout << ans.size();
    for(int i = 0; i < ans.size(); i++){
        cout << " " << ans[i];
    }
    cout << endl;

    return 0;
}



Measured memory_bytes: 3252
using System;
using System.Collections.Generic;

namespace ITP1_9_B
{
	class Program
	{
		static void Main(string[] args)
		{
			List<string> ls = new List<string>();

			string t = Console.ReadLine();
			while(t != "-") {
				Queue<char> cs = new Queue<char>();
				foreach(char c in t) {
					cs.Enqueue(c);
				}

				int n = int.Parse(Console.ReadLine());
				List<int> hs = new List<int>();
				for(int i = 0; i < n; i++) {
					hs.Add(int.Parse(Console.ReadLine()));
				}

				foreach(int h in hs) {
					for(int i = 0; i < h; i++) {
						char c = cs.Dequeue();
						cs.Enqueue(c);
					}
				}

				string l = string.Empty;
				foreach(char c in cs) {
					l += c.ToString();
				}
				ls.Add(l);

				t = Console.ReadLine();
			}

			foreach(string l in ls) {
				Console.WriteLine(l);
			}
		}
	}
}



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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 1000000007;
const lli e3 = 1 << 13;
const lli INF = 1ll << 62;

lli n,k;
vll d[e5];
unordered_set<lli> s;
priority_queue<lli,vll,greater<lli>> r;
lli mem;
lli ans;

int main(){
  cin >> n >> k;
  for(lli i = 1;i <= n;i++){
    d[i] = vll(2);
    cin >> d[i][1] >> d[i][0];
  }
  sort(d+1,d+n+1);
  lli i;
  lli j;
  for(i = n,j = 0;i > 0,j < k;i--,j++){
    if(s.count(d[i][1]) == 0){
      s.insert(d[i][1]);
      mem += d[i][0];
    }else{
      r.push(d[i][0]);
      mem += d[i][0];
    }
  }
  ans = max(ans, (lli)(mem+s.size()*s.size()));
  for(;i > 0;i--){
    if(r.empty()) break;
    if(s.count(d[i][1]) == 0){
      s.insert(d[i][1]);
      mem += d[i][0];
      mem -= r.top();
      r.pop();
      ans = max(ans, (lli)(mem+s.size()*s.size()));

    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 31628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long N;
    cin >> N;
    string c;
    cin >> c;
    string C = c;
    sort(c.begin(), c.end());
    long long ans = 0;
    for(int i = 0; i < N; i++){
        if(c[i] != C[i]) ans++;
    }
    ans /= 2;
    if(c == C) cout << 0 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3788
k=int(input())
n=1
t=1
l=0
for i in range(k):
	print(n)
	if int(n/t)%10==9:
		if n+t<=(9*l+int((n+t)/(t*10))%10+int((n+t)/(t*100))%100+int((n+t)/(t*1000))%1000)*t:
			pass
		else:
			t *= 10
			l += 1
	n += t

Measured memory_bytes: 3188
using System;
using System.Numerics;

namespace c
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());

            var ans = BigInteger.Parse(Console.ReadLine());
            for(var i = 1; i < n; i++){
                var t = BigInteger.Parse(Console.ReadLine());
                ans = Lcm(t, ans);
            }

            Console.WriteLine(ans);
        }

        static BigInteger Lcm(BigInteger m, BigInteger n){
        	return (m * n) / Gcd(m, n);
        }

        static BigInteger Gcd(BigInteger m, BigInteger n)
        {
	        while (m % n != 0){
        		var temp = n;
		        n = m % n;
		        m = temp;
	        }
        	return n;
        }
    }
}


Measured memory_bytes: 13524
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int curr=0,max=0;
    for(int i=1;i<n;i++)
    {
        if(h[i]>h[i-1])
            curr=0;
        else
            curr++;
        if(curr>max)
            max=curr;
    }
    // if(max==INT_MIN)
    //     max=0;
    cout<<max<<endl;
}

Measured memory_bytes: 640
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
using std::min; using std::max;
using std::swap; using std::sort;
using std::upper_bound;
typedef long long ll;

template<typename T>
void read(T &x) {
	int flag = 1; x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') { if(ch == '-') flag = -flag; ch = getchar(); }
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	x *= flag;
}

const int _ = 1e5 + 10, __ = 18;
int n, m, q, x[_], fa[__][_], Log[_], pw[_];

int main () {
	read(n), Log[0] = -1, pw[0] = 1;
	for(int i = 1; i <= n; ++i) read(x[i]);
	read(m), read(q);
	for(int i = 1; i <= n; ++i)
		Log[i] = Log[i >> 1] + 1, pw[i] = min(_, pw[i - 1] * 2);
	for(int i = 1; i <= n; ++i)
		fa[0][i] = upper_bound(x + 1, x + n + 1, x[i] + m) - x - 1;
	for(int i = 1; i <= Log[n]; ++i)
		for(int j = 1; j <= n; ++j)
			fa[i][j] = fa[i - 1][fa[i - 1][j]];
	for(int i = 1; i <= q; ++i) {
		int x, y; read(x), read(y);
		if(x > y) swap(x, y);
		if(x == y) { printf("%d\n", 0); continue; }
		int now = x, ret = 0;
		for(int j = Log[n]; j >= 0; --j)
			if(fa[j][now] < y) ret += pw[j], now = fa[j][now];
		printf("%d\n", ret + 1);
	}
	return 0;
} 

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

int main() {
  int n, result=0; cin >> n;
  vector<int> l(n);
  for(int i=0;i<n;i++) cin >> l.at(i);
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      for(int k=j+1;k<n;k++){
          int a=l.at(i), b=l.at(j), c=l.at(k);
          if((a<b+c && b<a+c && c<a+b) && (a != b && b != c && c != a)) result++;
      }
    }
  }
  cout << result << endl;
  return 0;
}

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

bool NG(int target, int NGs[], int NGsNum){
  while(target>0){
    int i;
    for(i=0;i<NGsNum;i++){
	    if(target%10 == NGs[i])return true;
    }
    target/=10;
  }
  return false;
}

int main(){
  int payment,K;
  
  cin >> payment >> K;
  
  int NGs[K];
  int i;
  
  for(i=0;i<K;i++){
    cin >> NGs[i];
  }
  
  int digit=0;
  
  while(NG(payment,NGs,K)){
    payment++;
  }
  
  cout << payment;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,k;cin >> a >> b >> k;
  if(a>=k){
    cout << a-k << " " << b << endl;
  }
  else if(b+a>=k){
    cout << 0 << " " << b-(k-a) << endl;
  }
  else{
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define MAXN 100010
int n, s, x[MAXN];
long long p[MAXN], ans = 0;
int main() {
	scanf("%d%d", &n, &s);
	for (int i = 1; i <= n; i++) scanf("%d%lld", &x[i], &p[i]);
	int l = 1, r = n, last = 0;
	while (l < r && x[l] < s && x[r] > s) {
		if (p[l] < p[r]) {
			ans += last == 1 ? 0 : (x[r] - x[l]);
			last = 1;
			p[r] += p[l];
			l++;
		} else {
			ans += last == 2 ? 0 : (x[r] - x[l]);
			last = 2;
			p[l] += p[r];
			r--;
		}
	}
	printf("%lld\n", ans + std::max(s - x[l], x[r] - s));
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,q,x;
    string s,l,r;
    std::multimap<string, long long int> map;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>q;
        if (q==0) {
            cin>>s>>x;
            map.emplace(make_pair(s,x));
        } else if (q==1) {
            cin>>s;
            using iterator = decltype(map)::iterator;
            pair<iterator,iterator>ret=map.equal_range(s);
            for (auto it1=ret.first;it1!=ret.second;it1++) {
                cout<<it1->second<<endl;
            }
        } else if (q==2) {
            cin>>s;
            map.erase(s);
        } else if (q==3) {
            cin>>l>>r;
            auto itr3=map.lower_bound(l);
            auto itr4=map.upper_bound(r);
            for (auto it=itr3;it!=itr4;it++) {
                cout<<it->first<<" "<<it->second<<endl;
            }
        }
    }
}



Measured memory_bytes: 24736
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
typedef long long ll;
const int INF = 100100100;
using namespace std;

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

    int N;
    cin >> N;
    vector<int> A;
    A.push_back(0);
    REP(i, N) {
        int a;
        cin >> a;
        A.push_back(a);
    }
    A.push_back(0);

    int sum = 0;
    vector<int> V(N + 1);
    REP(i, A.size() - 1) {
        sum += abs(A[i] - A[i + 1]);
        V[i] = A[i] - A[i + 1];
    }
    REP(i, N) {
        int ans = sum - abs(V[i]) - abs(V[i + 1]) + abs(A[i] - A[i + 2]);
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 2168
import Control.Applicative ((<$>))
import qualified Control.Monad as Monad (forM_)
import qualified Data.Char as Char (toLower)
import qualified Data.List as List (sort, group)
import qualified Data.Map as Map (Map, fromList, lookup)

type AlphabetCountMap = Map.Map Char Int

main = do
    s <- getContents
    let acl = alphabetCounts $ groupAlphabet s
    Monad.forM_ ['a'..'z'] $ \c -> do
        putStrLn $ case Map.lookup c acl of
            Nothing -> c : " : 0"
            Just n  -> c : " : " ++ show n

groupAlphabet :: String -> [String]
groupAlphabet s = List.group . List.sort $ filter (\x -> x `elem` ['a'..'z']) $ Char.toLower <$> s

alphabetCounts :: [String] -> AlphabetCountMap
alphabetCounts cs = Map.fromList $ [(head c, length c) | c <- cs]

Measured memory_bytes: 3904
using System;

namespace ConsoleApp21
{
    class Program
    {
        static void Main(string[] args)
        {
            var hp = long.Parse(Console.ReadLine());
            long aCount = 0;
            long bCount = 1;
            long h = hp;
            if (h == 1)
            {
                Console.WriteLine(1);
            }
            else { 

            while (true)
            {               
                if (h == 1)
                {
                        aCount += 1;   
                    break;
                }
                    h /= 2;
                    
                    bCount*= 2;
                    aCount+= bCount;
                }
                Console.WriteLine(aCount);
            }
        }
    }
}


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

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

int main(){
	    int Q;
    cin >> Q;
    for (int q = 0; q < Q; ++q) {
        ll A, B;
        cin >> A >> B;
        if (A > B) {
            swap(A, B);
        }  // A <= B

        ll ok = A, ng = B + 1;
        // K = Aのときは前半と同様にマッチングすればいい
        
        while (ng - ok > 1) {
            ll K = (ok + ng) / 2;
            ll m = (K + A) / 2;
            
            // コーナーケース
            if (K == A) --m;
            
            if (m * (A + K - m) < A * B) {
                ok = K;
            } else {
                ng = K;
            }
        }
        cout << ok + A - 2 << endl;
    }
    return 0;
	
}

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

int main()
{
    int a, b, c, res1, res2;
    cin >> a >> b >> c;
    res1 = abs(a-b);
    res2 = abs(a-c);
    if(res1 <= res2) cout << "A" << endl;
    else cout << "B" << endl;
    return 0;
}

Measured memory_bytes: 3632
n,k = map(int,input().split())
a = list(map(int,input().split()))
r = [0 for _ in range(n)]
for i in a:
    r[i-1] += 1
u = []
for i in r:
    if i:
        u.append(i)
u.sort(reverse=True)
print(n-sum(u[:k]))

Measured memory_bytes: 25644
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 14;

const int MAX_BITS = 1 << MAX_N;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int n, m;
int bs[MAX_N], as[MAX_N];
int asums[MAX_BITS], dsums[MAX_BITS], dp[MAX_BITS];

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    for (int i = 0; i < n; i++)
      cin >> bs[i] >> as[i];
    
    int maxbits = 1 << n;
    int allbits = maxbits - 1;
    
    memset(asums, 0, sizeof(asums));
    memset(dsums, 0, sizeof(dsums));

    for (int bits = 0; bits < maxbits; bits++) {
      asums[bits] = dsums[bits] = 0;
      for (int i = 0, b = 1; i < n; i++, b <<= 1)
	if (bits & b)
	  asums[bits] += as[i], dsums[bits] += bs[i] - as[i];
      dp[bits] = INF;
    }

    dp[0] = 0;
    
    for (int bits = 0; bits < maxbits; bits++) {
      int asize = m + dsums[bits];
      int cmask = allbits ^ bits;
      int cbits = 0;
      
      for (;;) {
	cbits = ((cbits | bits) + 1) & cmask;
	if (cbits == 0) break;

	if (asums[cbits] <= asize) {
	  int bits0 = bits | cbits;
	  dp[bits0] = min(dp[bits0], dp[bits] + 1);
	}
      }
    }

    if (dp[allbits] >= INF)
      cout << "Impossible" << endl;
    else
      cout << dp[allbits] << endl;
  }

  return 0;
}

Measured memory_bytes: 1360
import java.util.Scanner

import scala.annotation.tailrec

object Main {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val A, B = sc.nextInt()

    val a = if (A <= 5) 0
    else if (A >= 6 && A <= 12) B/2
    else B

    println(a)
  }
}

Measured memory_bytes: 27316
#include <iostream>

int main(void)
{
    int a, b, c;
    std::cin >> a >> b >> c;
    bool flag = ((a == 5) && (b == 5) && (c == 7)) ||
    ((a == 5) && (b == 7) && (c == 5)) ||
    ((a == 7) && (b == 5) && (c == 5));
    std::cout << (flag ? "YES" : "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 504
while True:
        list = input().split()
        m = int(list[0])
        f = int(list[1])
        r = int(list[2])
        if m == -1 and f == -1 and r == -1:
                break
        elif m == -1 or f == -1:
                print('F')
        elif m + f >= 80:
                print('A')
        elif m + f >= 65:
                print('B')
        elif m + f >= 50:
                print('C')
        elif m + f >= 30:
                if r >= 50:
                        print('C')
                else:
                        print('D')
        else:
                print('F')



Measured memory_bytes: 5596
#include<iostream>
#define int long long
using namespace std;
const int P=1e9+7,inv2=5e8+4;
int f[3100][3100],A[3100],bs,Q,n,ans;
signed main()
{
	cin>>n>>Q;
	for(int i=1;i<=n;i++) cin>>A[i];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(A[i]<A[j]) f[i][j]=1;
	for(int w=1;w<=Q;w++)
	{
		int x,y;cin>>x>>y;
		for(int i=1;i<=n;i++)
		{
			if(x==i||y==i) continue;
			int t1=inv2*(f[i][x]+f[i][y])%P;
			int t2=inv2*(f[x][i]+f[y][i])%P;
			f[i][x]=f[i][y]=t1;
			f[x][i]=f[y][i]=t2;
		}
		f[x][y]=f[y][x]=inv2*(f[x][y]+f[y][x])%P;
	}
	for(int i=bs=1;i<=Q;i++) bs=2*bs%P;
	for(int i=1;i<=n;i++)
		for(int j=1;j<i;j++)
			(ans+=bs*f[i][j])%=P;
	cout<<ans<<endl;
}


Measured memory_bytes: 73984
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY puts("Yes")
#define NN puts("No")
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  int n;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  rep(i,n)cin >> s[i] >> t[i];
  string tmp;
  cin >> tmp;
  ll ans = 0;
  bool flag = false;
  rep(i,n){
    if(flag)ans += t[i];
    if(tmp == s[i])flag = true;
  }
  cout << ans << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d%d", $H, $W);
for($i = 0; $i < $H; $i++){
  $str = trim(fgets(STDIN));
  for($j = 0; $j < $W; $j++){
    $map[$i][$j] = $str[$j];
    $p[$i][$j] = 0;
  }
  $map[$i][$W] = "#";
}
for($j = 0; $j < $W; $j++){
  $map[$H][$j] = "#";
}
for($i = 0; $i < $H; $i++){
  $h = 0;
  for($j = 0; $j < $W+1; $j++){
    if($map[$i][$j] === "#"){
      for($k = 0; $k < $h; $k++){
        $p[$i][$j - 1 - $k] = $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
for($i = 0; $i < $W; $i++){
  $h = 0;
  for($j = 0; $j < $H+1; $j++){
    if($map[$j][$i] === "#"){
      for($k = 0; $k < $h; $k++){
        $p[$j - 1 - $k][$i] += $h;
      }
      $h = 0;
    }else{
      $h++;
    }
  }
}
$max = 0;
for($i = 0; $i < $H; $i++){
  $max = max($max, max($p[$i]));
}
echo $max - 1;

Measured memory_bytes: 401912
#include <cstdio>
int main() {
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++) {
    int k,p;
    scanf("%d %d",&k,&p);
    int winner = k % p;
    if(winner == 0) winner = p;
    printf("%d\n",winner);
  }
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Permutation - Permutation
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_5_C&lang=jp

"""
from itertools import permutations

n = int(input())
A = tuple(map(int, input().split()))
res = [p for p in permutations(sorted(A), n)]
i = res.index(A)
for a in res[max(0, i-1):i+2]:
    print(*a)



Measured memory_bytes: 52376
#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_macros)]
macro_rules! invec {
    ( $ t : ty ) => {{
        let mut s = String::new();
        match std::io::stdin().read_line(&mut s) {
            Ok(0) => Vec::<$t>::new(),
            Ok(n) => s
                .trim()
                .split_whitespace()
                .map(|s| s.parse::<$t>().unwrap())
                .collect::<Vec<$t>>(),
            Err(_) => Vec::<$t>::new(),
        }
    }};
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (n, k) = input!(usize, usize);
    let mut h = invec!(u64);

    h.sort();
    
    if n <= k {
        println!("0");
    } else {
        let total: u64 = h.iter().take(n - k).sum();
        println!("{}", total);
    }
}

fn main() {
    solve();
}


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

int main(){
  int K, S; cin >> K >> S;
  int ans=0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      if(S-i-j>=0 && S-i-j<=K){
        ans++;
      }
    }
  }
  cout << ans << 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>
#include <list>
using namespace std;
static const double EPS = 1e-10;
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
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};



typedef struct _state{
  int from,vis;
  double cost;
  _state(double ic,int ifr,int iv):cost(ic),from(ifr),vis(iv){
  };
  bool operator<(const _state&r)const{
    return cost>r.cost;
  };
}state;

vector<PI> V[30];


main(){
  ios::sync_with_stdio(false);
  int n,m,p,a,b;
  while(cin>>n>>m>>p>>a>>b,n){
    --a,--b;
    int ti[n];
    rep(i,n)cin>>ti[i];

    rep(i,m)V[i].clear();

    rep(i,p){
      int x,y,z;
      cin>>x>>y>>z;
      --x,--y;
      V[x].pb(mp(y,z));
      V[y].pb(mp(x,z));
    }

    priority_queue<pair<double,PI> > Q;
    Q.push(pair<double,PI>(0,PI(a,0)));

    bool cost[1<<n][m];
    memset(cost,0,sizeof(cost));
    double ans=-1;

    while(!Q.empty()){
      int from=Q.top().S.F,cti=Q.top().S.S;
      double ccost=-Q.top().F;
      Q.pop();
      if(cost[cti][from])continue;
      cost[cti][from]=true;
      if(from==b){
        ans=ccost;
        break;
      }

      rep(i,n){
        if(cti>>i&1)continue;
        rep(j,V[from].size()){
          int to=V[from][j].first;
          int cc=V[from][j].second;
          if(cost[cti|1<<i][to])continue;
          double ncost=ccost+1.0*cc/ti[i];
          Q.push(pair<double,PI>(-ncost,PI(to,cti|1<<i)));
        }
      }
    }
    if(ans<0)cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}

Measured memory_bytes: 5584
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI=3.1415926535897932384626433;
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }

typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

ll atol(string &s) {
    istringstream iss(s);
    ll i;
    iss>>i;
    return i;
}

void atoli(string &s, vll &a) {
    istringstream iss(s);
    int i=0;
    while(iss.good())
        cin>>a[i++];
}

int cntBits(int i) {
    int ans=0;
    while(i) {
        ans+=(i&1);
        i>>=1;
    }
    return ans;
}

void solve() {
    cini(n);
    vvi a(n, vi(n, 2));

    for(int i=0; i<n; i++) {
        cini(A);
        for(int j=0; j<A; j++) {
            cini(x);
            x--;
            cini(y);
            a[i][x]=y;
        }
    }

// a[i][j]== person i says person j is honest==1, unkind==0, unknown==2

    int ans=0;
    for(int i=0; i<(1<<n); i++) {  // the truth

        // check all statements of all persons
        // if all is ok then i is possible truth
        bool ok=true;
        for(int j=0; j<n && ok; j++) {    
            if(i&(1<<j)) {  // if jth bit is set j is honest, 
                // so all j says must be true
                for(int k=0; k<n && ok; k++) {
                    if(a[j][k]!=2) {    // j says something about k
                        if(a[j][k]!=((i>>k)&1))
                            ok=false;
                    }
                }
            }
        }
        if(ok)
            ans=max(ans,cntBits(i));
    }
    cout<<ans<<endl;
        
}

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



Measured memory_bytes: 256
N=int(input())
for i in range(N):
    a,b,c=map(int,input().split())
    if a>b:
        a,b=b,a
    if b>c:
        b,c=c,b
    if a>b:
        a,b=b,a
    if a*a+b*b==c*c:
        print("YES")
    else:
        print("NO")


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

int main()
{
    string s; cin>>s;
    string t[8]={"","SAT","FRI","THU","WED","TUE","MON","SUN"};
    for(int i=1;i<=7;i++) if(s==t[i]){
        cout<<i<<endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LiangJiaJun main
#define ll long long
using namespace std;
ll A,B,C,ans;
int LiangJiaJun(){
    cin>>A>>B>>C;
    ans=0;
    ll OK=min(A,C);
    ans+=OK;
    A-=OK;
    C-=OK;
    OK=min(B,C);
    ans+=OK*2;
    B-=OK;
    C-=OK;
    if(B>0)ans+=B;
    if(C>0)ans++;
    printf("%lld\n",ans);
    return 0;
}


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

signed main(){
  int N,L;
  cin>>N>>L;
  std::vector<int> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  int ok=0;
  int j;
  for(int i=0;i<N-1;i++)if(v[i]+v[i+1]>=L){ok++;j=i;}
  if(ok==0)cout<<"Impossible"<<endl;
  else{
    cout<<"Possible"<<endl;
    for(int i=0;i<j;i++)cout<<i+1<<endl;
    for(int i=N-2;i>j;i--)cout<<i+1<<endl;
    cout<<j+1<<endl;
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
    cin>>S;
    vec al(26,-100);
    rep(i,4){
        rep(j,26){
            if(ALPHA.at(j) ==S.at(i)){
                if(al.at(j)!=-100) al.at(j) = 1;
                else al.at(j) = 0;
            }
        }
    }
    ll ans = 0;
    rep(j,26){
        if(al.at(j)!=-100) ans += al.at(j);
    }
    cout<<(ans==2 ? "Yes" : "No")<<endl;
}

Measured memory_bytes: 256
N = int(input())
D = [int(i) for i in input().split()]
M = int(input())
T = [int(i) for i in input().split()]

if N < M:
    print('NO')
    exit()

from collections import Counter
 
d_count = Counter(D)
t_count = Counter(T)
for k,v in t_count.items():
    if k not in d_count:
        print('NO')
        exit()
    if d_count[k]< v:
        print('NO')
        exit()
print('YES') 

Measured memory_bytes: 56788
//Daniel Grzegorzewski
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define MP make_pair
#define PB push_back
#define ST first
#define ND second
#define int long long

using namespace std;

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef long long LL;

void init_ios() {
     ios_base::sync_with_stdio(0);
     cin.tie(0);
}

const int N = (int)1e5 + 10;

int n, m, res, wyn[N], s[N], p[N], low[N];
VI child[N];
bool vis[N];
VII edg;

int Find(int x) {
  if (x == p[x])
    return x;
  return p[x] = Find(p[x]);
}

void Union(int x, int y) {
  x = Find(x);
  y = Find(y);
  if (x == y)
    return;
  res -= s[x]*s[y];
  s[x] += s[y];
  s[y] = 0;
  p[y] = x;
}

signed main() {
  init_ios();
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int a, b;
    cin >> a >> b;
    child[a].PB(b);
    child[b].PB(a);
    edg.PB({a, b});
  }
  for (int i = 1; i <= n; ++i) {
    p[i] = i;
    s[i] = 1;
  }
  res = (n*(n-1))/2;
  wyn[m] = res;
  for (int i = m-1; i >= 0; --i) {
    Union(edg[i].ST, edg[i].ND);
    wyn[i] = res;
  }
  for (int i = 1; i <= m; ++i)
    cout<<wyn[i]<<"\n";
}

Measured memory_bytes: 12264
#include <bits/stdc++.h>
using namespace std;
int N;
int raise(int l, int r,vector<int>&h) {
	int minh = 101;
	int maxh = -1;
	vector<int> index;
	if (l == r) {
		return h[l];
	}
	else if (l > r)return 0;
	for (int i = l; i <= r; i++) {
		minh = min(h[i], minh);
		maxh = max(h[i], maxh);
	}
	if (maxh == minh)return maxh;
	for (int i = l; i <= r; i++) {
		if (h[i] == minh)index.push_back(i);
		h[i] -= minh;
	}
	int ret = minh;
	ret += raise(l, index[0] - 1,h);
	for (int i = 1; i < index.size(); i++) {
		ret += raise(index[i-1]+1, index[i]-1, h);
	}
	ret += raise(index[index.size() - 1] + 1, r, h);
	return ret;
}

int main() {
	cin >> N;
	vector<int> h(N);
	for (int i = 0; i < N; i++)cin >> h[i];
	cout << raise(0, N - 1, h) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();
		String c = sc.next();

		String next =a.substring(0, 1);
		a = a.substring(1, a.length());

		for(;;) {
			if (next.equals("a")) {
				if (a.isEmpty()) {
					System.out.println("A");
					return;
				}
				next = a.substring(0, 1);
				a = a.substring(1, a.length());
			}else if (next.equals("b")) {
				if(b.isEmpty()) {
					System.out.println("B");
					return;
				}
				next = b.substring(0, 1);
				b = b.substring(1, b.length());
			} else {
				if(c.isEmpty()) {
					System.out.println("C");
					return;
				}
				next = c.substring(0, 1);
				c = c.substring(1, c.length());
			}
		}
	}
}


Measured memory_bytes: 35196
#include <stdio.h>

int main(void) {
	int suuretu[25];
	int suuretulen;
	int nowsuuretu;
	int ohajikinum;
	int i;
	while(1) {
		scanf("%d",&suuretulen);
		if(suuretulen==0)break;
		for(i=0;i<suuretulen;i++)scanf("%d",&suuretu[i]);
		ohajikinum=32;
		nowsuuretu=0;
		while(ohajikinum>0) {
			ohajikinum-=(ohajikinum-1)%5;
			printf("%d\n",ohajikinum);
			ohajikinum-=suuretu[nowsuuretu++];
			if(nowsuuretu>=suuretulen)nowsuuretu=0;
			if(ohajikinum<0)ohajikinum=0;
			printf("%d\n",ohajikinum);
		}
	}
	return 0;
}

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

using namespace std;

const int mod = 1e9 + 7;
int n, x, y, z, dp[45][1 << 20], maxmask, needmask;

int main () {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> x >> y >> z;
    maxmask = (1 << (x + y + z) );
    needmask = (1 << (z - 1) ) + (1 << (y + z - 1) ) + (1 << (x + y + z - 1) );
    dp[0][0] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int mask = 0; mask <= maxmask; ++mask) {
            if(!dp[i - 1][mask]) continue;
            for (int nex = 1; nex <= 10; ++nex) {
                if(mask == maxmask) {
                    dp[i][mask] += dp[i - 1][mask]; dp[i][maxmask] %= mod;
                    continue;
                }
                int nmask = ( (mask << nex) | (1 << (nex - 1) ) ) & (maxmask - 1);
                if( (nmask & needmask) == needmask) nmask = maxmask;
                dp[i][nmask] += dp[i - 1][mask]; dp[i][nmask] %= mod;
            }
        }
    }

    cout << dp[n][maxmask];

    return 0;
}


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

typedef long long ll;
const int N = 1000010;
int n, mx;
int a[N];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	ll ans = 1ll, cnt = 0;
	for(int i = n; i; i--) {
		if(a[i] == a[i - 1]) ans *= a[i], ++cnt, --i;
		if(cnt == 2) break; 
	}
	if(cnt == 2) printf("%lld\n", ans);
	else printf("0");
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

vector<string>maze;
int H, W;
int x = 0, y = 0;
void dfs(Graph& vec) {
	if (y == H)return;
	vec[y][x]++;
	if (y + 1 < H && maze[y + 1][x] == '#') {
		++y;
		dfs(vec);
	}
	else if (x + 1 < W && maze[y][x + 1] == '#') {
		++x;
		dfs(vec);
	}
	return ;
}
int main() {
	init();

	cin >> H >> W;
	maze.resize(H);
	rep(i, 0, H)cin >> maze[i];
	Graph G(H, vector<int>(W, 0));
	dfs(G);
	bool is = true;
	rep(i, 0, H) {
		rep(j, 0, W) {
			if (maze[i][j] == '#' && G[i][j] == 0)is = false;
		}
	}
	cout << (is ? "Possible" : "Impossible") << "\n";


	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#ifdef LOCAL
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#else
#define eprintf(...) 42
#endif
#define y0 y12345
#define y1 y54321
typedef unsigned long ul;
typedef long long ll;
//typedef pair<int, int> mpair;
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;}
using namespace std;

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
   	int r,d,x;
	cin >>r>>d>>x;
	rep(i, 10){
		x = x * r - d;
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int cntDivisor(int n)
{
	int cnt = 0;
	for(int i=1; i<=n; i++)
		if(n%i == 0)
			cnt++;

	return cnt;
}

int main(void)
{
	int N;
	cin >> N;

	int ret = 0;
	for(int i=1; i<=N; i+=2){
		if(cntDivisor(i) == 8)
			ret++;
	}

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int a, b;
	
	scanf("%d %d", &a, &b);
	
	if(a>=13)printf("%d", b);
	else if(a>=6 && a<=12)printf("%d", b/2);
	else if(a<=5)printf("0");
	
return 0;
}

Measured memory_bytes: 128
// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

const long long bigNum = 1000000007;

int gcd(int a, int b)
{
	int buffer = a;
	if (b > a)
	{
		a = b;
		b = buffer;
	}

	int remainder = a%b;
	while (remainder != 0)
	{
		a = b;
		b = remainder;
		remainder = a%b;
	}
	return b;
}

long long comb(int n, int k)
{
	vector<int> setofNums;
	long long ret = 1;
	for (int i = 1; i <= k; i++)
	{
		setofNums.push_back(i);
	}
	for (int i = 0; i < k; i++)
	{
		ret = ret * (n - i);
		for (auto it : setofNums)
		{
			if (ret % it == 0)
			{
				ret /= it;
				it = bigNum;
			}
		}
		if (ret > bigNum)
			ret %= bigNum;
	}
	return ret;
}

map<long long, long long> factors;

int main()
{
	long long N;
	long long P;
	cin >> N >> P;

	long long remainder = P;
	long long output = 1;

	if (N == 1)
	{
		cout << P << endl;
		return 0;
	}

	for (long long i = 2; remainder != 1 && i < sqrt(P); i++)
	{
		while (remainder % i == 0)
		{
			factors[i] += 1;
			remainder /= i;
		}
	}

	for (auto it = factors.begin(); it != factors.end(); it++)
	{
		long long a = it->second / N;
		if (a == 0)
			continue;
		output *= pow(it->first, a);
	}

	cout << output << endl;
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    var ans = -1;
    var input = input.split("\n");
    input[0] = input[0].split("");
    input[1] = input[1].split("");
    for(var i=0;i<input[0].length;i++){
        if(input[0].join()==input[1].join()){
            ans = i
            break;
        }
        input[0].unshift(input[0][input[0].length-1]);
        input[0].pop();
       // console.log(input[0])
    }
    console.log(ans==-1?"No":"Yes");
}Main(require("fs").readFileSync("/dev/stdin","utf8").trim());


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

int main(){
    string s;
    cin>>s;
    
    int cnt1 = 0;
    int cnt2 = 0;
    for(int i = 0; i < s.length(); i++){
        if(i%2==0 && s[i]!='0') cnt1++;
        if(i%2 && s[i]!='1') cnt1++;
        if(i%2==0 && s[i]!='1') cnt2++;
        if(i%2 && s[i]!='0') cnt2++;
    }

    cout<<min(cnt1,cnt2);
}


Measured memory_bytes: 512
N=io.read"*n"

function dfs(s)
	if(tonumber(s)>N)then return 0 end
	local ret=s:match"3"and s:match"5"and s:match"7"and 1 or 0
	ret=ret+dfs(s.."3")
	ret=ret+dfs(s.."5")
	ret=ret+dfs(s.."7")
	return ret
end

print(dfs("0"))

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

int main(void)
{
    long int n;
    long int i,j;
    long int ans=0;


    scanf("%ld",&n);

    i=n/500;
    j=n%500/5;

    ans = i*1000+j*5;

    printf("%ld",ans);





	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head

void solve(){
    char b = getchar();
    if (b == 'A') b = 'T';
    else if (b == 'T') b = 'A';
    else if (b == 'C') b = 'G';
    else b = 'C';
    cout << b << '\n';
}

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

    //int t; cin >> t; while (t--)
        solve();
}

Measured memory_bytes: 3612
def main():
    n = int(input())
    a = set([int(a) for a in input().split()])
    m = int(input())
    b = set([int(a) for a in input().split()])

    c = a.union(b)
    sorted_c = sorted(c)
    for i in sorted_c:
        print(i)
main()



Measured memory_bytes: 69084
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n; cin >> n;
    int v[n+1];
    for (int i=0; i<n; i++) cin >> v[i];
    sort(v, v+n);
    double ans = v[0];
    for (int i=1; i<n; i++) ans = (ans+v[i])/2.0; 
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <sstream>

using namespace std;
istringstream iss;
long long sum, num, c;
string S, S2;

bool cal(string s, int x){
    //cout << s << " " << s.size() << " " << x << endl;
    if(x == s.size()){
        sum = 0;
        iss = istringstream(s.substr(0,1));
        iss >> num;
        //cout << "num = "  << num << endl;
        //cout << x;
        for(int i=1;i<s.size();i++){
            if(s.substr(i,1)=="+"){
                sum += num;
                num = 1;
            }
            else if(s.substr(i,1)=="-"){
                sum += num;
                num = -1;
            }
            else{
                iss = istringstream(s.substr(i,1));
                iss >> c;
                num *= c;
                //if(s == "3141592653")cout << "num = "  << num << "c = "  << c << endl;
            }
            //cout << "num = "  << num << endl;
        }
        //cout << "num = "  << num << endl;
        sum += num;
        //cout << sum << endl;
        if(sum == 7){
            S2 = s;
            //cout << "good" << endl;
            return true;
        }
        else {
            //cout << "bad" << endl;
            return false;
        }
        //cout << "sum=" << sum << endl;
    }
    
    else {
        string s2 = s;
        if(cal(s.insert(x,"+"), x+2)) return true;
        s = s2;
        if(cal(s.insert(x,"-"), x+2)) return true;
        else return false;
    }


}

int main(){
    
    cin >> S;
    if(cal(S, 1)){
        cout << S2 << "=7";
    };
    
    //S.insert(1,"+");
    //cout << S;

    cout << endl;
}

Measured memory_bytes: 256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
vector<vector<int>> g;
vector<int> height;
ll ans = 0;
void dfs(ll idx){
    for(int i : g[idx]){
        if(height[i] >= height[idx])
            return ;
    }
    ++ans;
}
void solve(){
    ll n, m;
    cin>>n>>m;
    g.resize(n+1);
    height.resize(n+1);
    for(int i = 1; i <= n; i++)
        cin>>height[i];
    for(int i = 0; i < m; i++){
        int f, s;
        cin>>f>>s;
        g[f].push_back(s);
        g[s].push_back(f);
    }
    for(int i = 1; i <= n; i++){
        // vector<int> vis(n+1, 0);
        dfs(i);
    }
    cout<<ans;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

Measured memory_bytes: 8744
process.stdin.setEncoding('utf-8');
process.stdin.on('data', (input) => {

  var arr = input.split('\n')

  for (var i = 0; i < arr.length && arr[i] != 0; i++) {
    var result = 'Case ' + (i + 1 )+ ': ' + arr[i];
    console.log(result);
  }
})


Measured memory_bytes: 22580
import sys
def input():return sys.stdin.readline()[:-1]
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
def YesNo(x):print("Yes")if x==True else print("No")
k=N()
s=input()
if len(s)<=k:
    print(s)
else:
    print(s[:k]+"...")

Measured memory_bytes: 9124
#include <iostream>
#include <numeric>
#include <vector>

/*
  B(1) >= max(A(1), A(2))
  B(2) >= max(A(2), A(3))

  ↓

  B(1) >= A(1)
  B(1) >= A(2)

  B(2) >= A(2)
  B(2) >= A(3)

  ↓

  A(1) <= B(1)

  A(2) <= B(1)
  A(2) <= B(2)

  A(3) <= B(2)

  ↓

  A(1) <= B(1)
  A(2) <= min(B(1), B(2))
  A(3) <= B(2)

  ↓

  A(1) <= B(1)
  A(i) <= min(B(i-1), B(i))
  A(N) <= B(N-1)

 */

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::vector<int> b(n - 1), a(n);
  for (int i = 0; i < n-1; ++i)
    std::cin >> b.at(i);
  for (int i = 0; i < n; ++i) {
    if (i == 0)
      a.at(i) = b.at(i);
    else if (i + 1 == n)
      a.at(i) = b.at(i - 1);
    else
      a.at(i) = std::min(b.at(i), b.at(i - 1));
  }

  std::cout << std::accumulate(a.begin(), a.end(), 0) << std::endl;
}


Measured memory_bytes: 888
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
    int H, W;
    cin>>H>>W;
    vector<string> A(H);
    for(int i=0;i<H;++i){
        cin>>A[i];
    }
    queue<pair<int, int> > que;
    queue<int> numque;
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            if(A[i][j]=='#'){
                que.push(mp(i, j));
                numque.push(0);
            }
        }
    }
    pair<int, int> state;
    int num;
    int ans = 0;
    while(!que.empty()){
        state = que.front();que.pop();
        num = numque.front();numque.pop();
        if(ans<num) ans = num;
        if((state.fi>0) && (A[state.fi-1][state.se]=='.')){
            A[state.fi-1][state.se] = '#';
            que.push(mp(state.fi-1, state.se));
            numque.push(num+1);
        }
        if((state.fi<H-1) && (A[state.fi+1][state.se]=='.')){
            A[state.fi+1][state.se] = '#';
            que.push(mp(state.fi+1, state.se));
            numque.push(num+1);
        }
        if((state.se>0) && (A[state.fi][state.se-1]=='.')){
            A[state.fi][state.se-1] = '#';
            que.push(mp(state.fi, state.se-1));
            numque.push(num+1);
        }
        if((state.se<W-1) && (A[state.fi][state.se+1]=='.')){
            A[state.fi][state.se+1] = '#';
            que.push(mp(state.fi, state.se+1));
            numque.push(num+1);
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 13584
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < int(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < int(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = int(n) - 1; (i) >= int(m); -- (i))
#define ALL(x) begin(x), end(x)
#define dump(x) cerr << #x " = " << x << endl
#define unittest_name_helper(counter) unittest_ ## counter
#define unittest_name(counter) unittest_name_helper(counter)
#define unittest __attribute__((constructor)) void unittest_name(__COUNTER__) ()
using ll = long long;
using namespace std;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
template <class T> inline void chmax(T & a, T const & b) { a = max(a, b); }
template <class T> inline void chmin(T & a, T const & b) { a = min(a, b); }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }

const int dy[] = { -1, 1, 0, 0 };
const int dx[] = { 0, 0, 1, -1 };
const char *type = "||--";
vector<vector<int> > parse(int h, int w, vector<string> const & f) {
    auto is_on_field = [&](int y, int x) { return 0 <= y and y < h and 0 <= x and x < w; };
    vector<vector<int> > g(26);
    REP (y, h) REP (x, w) if (isupper(f[y][x])) {
        REP (i, 4) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            while (is_on_field(ny, nx) and (f[ny][nx] == 'o' or f[ny][nx] == type[i])) {
                ny += dy[i];
                nx += dx[i];
            }
            if (is_on_field(ny, nx) and isupper(f[ny][nx])) {
                g[f[y][x] - 'A'].push_back(f[ny][nx] - 'A');
            }
        }
    }
    return g;
}

vector<int> breadth_first_search(int root, vector<vector<int> > const & g) {
    int n = g.size();
    vector<int> dist(n, INT_MAX);
    queue<int> que;
    dist[root] = 0;
    que.push(root);
    while (not que.empty()) {
        int i = que.front(); que.pop();
        for (int j : g[i]) if (dist[j] == INT_MAX) {
            dist[j] = dist[i] + 1;
            que.push(j);
        }
    }
    return dist;
}

int main() {
    // input
    int h, w; cin >> h >> w;
    char start, goal; cin >> start >> goal;
    vector<string> f(h);
    REP (y, h) cin >> f[y];

    // solve
    vector<vector<int> > g = parse(h, w, f);
    vector<int> dist = breadth_first_search(start - 'A', g);
    int result = dist[goal - 'A'];

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



Measured memory_bytes: 3236