akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;

public class Main{
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int k = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = input.nextInt();
        Arrays.sort(a);
        int sum = 0;
        for(int j = 0; j < k; j++)
            sum+=a[j];
        System.out.println(sum);
    }
}


Measured memory_bytes: 38600
import java.util.Scanner;

class Main{
  static int answer(int a, int b) {
    int answer = 0;
    for(int i = 0; i < 2; i++) {
      if(a>=b) {
        answer += a;
        a--;
      }else {
        answer += b;
        b--;
      }
    }
    return answer;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int a = stdIn.nextInt();
    int b = stdIn.nextInt();
    System.out.println(answer(a, b));
  }
}

Measured memory_bytes: 22612
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val s = sc.next

  if (s.contains("RRR")) {
    println("3")
  } else if (s.contains("RR")) {
    println("2")
  } else if (s.contains("R")) {
    println("1")
  } else {
    println("0")
  }
}


Measured memory_bytes: 55164
N = int( input())
A = [ int( input()) for _ in range(N)]
A = [ a-1 for a in A]
L = [ 0 for _ in range(N)]
L[0] = 1
cnt = 0
now = 0
while True:
    if now == 1:
        break
    now = A[now]
    if L[now] == 0:
        L[now] = 1
        cnt += 1
    else:
        cnt = -1
        break
print(cnt)

Measured memory_bytes: 11052
from collections import Counter

n=int(input())
s=[]
for i in range(n):
    x=input()
    y=[]
    for i in x:
        y.append(i)
    y.sort()
    s.append(''.join(y))

a=Counter(s)
ans=0
for v in a.values():
    if v>=2:
        ans+=v*(v-1)/2
print(int(ans))

Measured memory_bytes: 19824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

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

  cout << (N + 1) / 2 << endl;
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

class LazySegmentTree
{
  public:
    LazySegmentTree(ll n)
    {
        ll c = 1;
        while (c < n)
            c <<= 1;
        REP(i, 2 * c - 1)
        {
            node.push_back(0);
            lazy.push_back(0);
        }
        mN = c - 1;
    }

    //! 0-index 区間加算
    void add(ll value, int left, int right, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = mN;
        LazyProgation(k);
        if (r < left || right < l)
            return;
        if (left <= l && r <= right)
        {
            //! 区間を完全被覆しているのでlazyに区間和を入れる
            lazy[k] += value;
            LazyProgation(k);
        }
        else
        {
            add(value, left, right, 2 * k + 1, l, (l + r) / 2);
            add(value, left, right, 2 * k + 2, (l + r) / 2 + 1, r);
            node[k] = std::min(node[2 * k + 1], node[2 * k + 2]);
        }
    }

    //! 0-index 最小値
    ll min(ll left, ll right, int k = 0, int l = 0, int r = -1)
    {
        if (r < 0)
            r = mN;
        if (r < left || right < l)
            return INF;

        LazyProgation(k);
        if (left <= l && r <= right)
            return node[k];
        return std::min(min(left, right, 2 * k + 1, l, (l + r) / 2), min(left, right, 2 * k + 2, (l + r) / 2 + 1, r));
    }

    void dev()
    {
        FOR(i, node.size(), 0)
        {
            cout << node[i] << ":" << lazy[i] << " ";
        }
        cout << endl;
    }

  private:
    //! index番目のnodeの遅延評価
    void LazyProgation(int index)
    {
        if (lazy[index] == 0)
            return;
        node[index] += lazy[index];
        if (2 * index + 1 < node.size())
        {
            lazy[2 * index + 1] += lazy[index];
            lazy[2 * index + 2] += lazy[index];
        }

        lazy[index] = 0;
    }

    ll mN;
    vector<ll> node;
    //! 遅延評価配列
    vector<ll> lazy;
};

int main()
{
    ll N, Q;
    cin >> N >> Q;
    LazySegmentTree seg(N);
    REP(i, Q)
    {
        ll c, s, t;
        cin >> c >> s >> t;
        if (c == 0)
        {
            ll x;
            cin >> x;
            seg.add(x, s, t);
        }
        else if (c == 1)
        {
            cout << seg.min(s, t) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 7132
package main

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

type counter struct {
	a map[string]int
}

func (c *counter) Add(val string) {
	if _, ok := c.a[val]; ok {
		c.a[val]++
	}
}

func (c *counter) Output() {
	for _, v := range []string{"AC", "WA", "TLE", "RE"} {
		fmt.Println(v, "x", c.a[v])
	}
}

func newCounter(a map[string]int) *counter {
	return &counter{a: a}
}

var (
	initial = map[string]int{
		"AC":  0,
		"WA":  0,
		"TLE": 0,
		"RE":  0,
	}
)

func main() {
	var n int
	fmt.Scan(&n)

	m := newCounter(initial)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		m.Add(s.Text())
	}

	m.Output()
}


Measured memory_bytes: 2144
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 N;
  std::cin >> N;
  std::vector<i64> A;
  tools::read(A, N);

  const std::array<std::function<bool(i64, i64)>, 2> comps = {
    std::less<i64>(),
    std::greater<i64>()
  };
  const std::array<std::function<i64(i64, i64)>, 2> zigzags = {
    [](const i64& i, const i64& n) {
      return (n - 1) / 2 + (i % 2 * 2 - 1) * (i + 1) / 2;
    },
    [](const i64& i, const i64& n) {
      return n / 2 + (i % 2 * (-2) + 1) * (i + 1) / 2;
    }
  };
  const std::array<i64, 2> sizes = {
    (N + 1) / 2,
    N / 2
  };

  i64 answer = 0;
  for (const auto& comp : comps) {
    for (const auto& zigzag1 : zigzags) {
      for (const auto& zigzag2 : zigzags) {
        std::vector<i64> aligned(N);
        std::sort(A.begin(), A.end(), comp);
        for (i64 i = 0; i < sizes[0]; ++i) {
          aligned[zigzag1(i, sizes[0]) * 2] = A[i];
        }
        std::reverse(A.begin(), A.end());
        for (i64 i = 0; i < sizes[1]; ++i) {
          aligned[zigzag2(i, sizes[1]) * 2 + 1] = A[i];
        }
        std::vector<i64> diffs;
        std::adjacent_difference(aligned.begin(), aligned.end(), std::back_inserter(diffs));
        diffs.erase(diffs.begin());
        std::transform(diffs.begin(), diffs.end(), diffs.begin(), [](const i64& diff) { return std::abs(diff); });
        answer = std::max(answer, std::accumulate(diffs.begin(), diffs.end(), static_cast<i64>(0)));
      }
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

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

int main()
{
	int count = 1;

	while (true)
	{
		int num;
		cin >> num;

		if (num == 0)
		{
			break;
		}

		cout << "Case " << count << ": " << num << '\n';

		count++;
	}
	return 0;
}


Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define mset(a, b) memset(a, b, sizeof(a))
#define mcpy(a, b) memcpy(a, b, sizeof(a))
#define pii pair<int, int>
#define MP make_pair
using namespace std;
typedef long long LL;
const int N = 20;
const LL INF = 0x3f3f3f3f3f3f3f3f;

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

int n;
LL a[N];

LL DP(int l, int r, int p, int q) {
    if (l + 1 == r) return 0;
    LL ret = INF;
    for (int k = l + 1; k < r; ++k) {
        ret = min(ret, DP(l, k, p, p + q) + DP(k, r, p + q, q) + a[k] * (p + q));
    }
    return ret;
}

void solve() {
    read(n);
    for (int i = 1; i <= n; ++i) {
        read(a[i]);
    }
    printf("%lld\n", DP(1, n, 1, 1) + a[1] + a[n]);
}

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 100;
const int MAXPOIDS = 100 * 1000;

int valeurMax[MAXN + 1][MAXPOIDS + 1];
int32_t main()
{
	int nbObjets , poidsTotal;
	cin >> nbObjets >> poidsTotal;
	int solution = 0;
	for (int i = 0 ; i < nbObjets ; i++)
	{
		int poids , valeur;
		cin >> poids >> valeur;
		for (int j = 0 ; j <= poidsTotal ; j++)
		{
			valeurMax[i + 1][j] = valeurMax[i][j];
			if (j >= poids)
			{
				valeurMax[i + 1][j] = max(valeurMax[i + 1][j] , valeurMax[i][j - poids] + valeur);
			}
			solution = max(solution , valeurMax[i + 1][j]);
		}
	}
	cout << solution << endl;
}

Measured memory_bytes: 78336
#include <stdio.h>
int main() {
	int H, W, i;
	while (1) {
		scanf("%d%d", &H, &W);
		if (H == 0 && W == 0)
			break;
		for (int i = 0; i < H; i++)
		{
			for (int j = 0; j < W; j++)
			{
				if ((i + j) % 2 == 0)
				{
					printf("#");
				}
				else
					printf(".");

			}
			printf("\n");
		}
		printf("\n");
	}return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int K, n;
    cin >> K >> n;

    vector<int> a(n + 1);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a[n] = a[0] + K;
    
    int ans = K;
    for (int i = 0; i < n; ++i) {
        ans = min(ans, K - (a[i + 1] - a[i]));
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL << 60;

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

uintmax_t combination(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int modPow(long long a, long long n, long long p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}

int main()
{
    ll n;
    cin >> n;
    ll a,b;
    a = sqrt(n);

    ll ans = 1;

    for(ll i = a; i > 0; i--){
        if(n % i == 0){
            b = n/i;
            break;
        }
    }

    while(b/10 != 0){
            b/=10;
            ans++;
    }

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

Measured memory_bytes: 384
#include <stdio.h>
#include<math.h>
int main()
{
 long int x[26]={0},y,z,sum,i=0,k;
 char a[100000];
 gets(a);
 k=0;
 for(i=0;i<strlen(a);i++)
 {
     if(x[a[i]-97]==0)
     {
         x[a[i]-97]=1;
         k++;
     }
 }
 if(k==26)
 {
     printf("None");
 }else{
     for(i=0;i<26;i++)
     {
         if(x[i]==0)
         {
             printf("%c",i+97);
             
             break;
         }
        
     }
 }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <stack>
#include <functional>
#include <numeric>
#include <complex>
#include <queue>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <unordered_set>
#include <assert.h>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <iostream>
 
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define X first
#define Y second
#define pb(x) push_back(x)
#define FOR(k, n) for (int k = 0; k < n; k++)
#define FORN(k, s, n) for (int k = s; k < n; k++)
#define debug(x) printf("x = %d\n", x);
#define debug2(x, y) printf("x = %d, y = %d\n", x, y);
#define debug3(x, y, z) printf("x = %d, y = %d, z = %d\n", x, y, z);
#define debug4(x, y, z, t) printf("x = %d, y = %d, z = %d, t = %d\n", x, y, z, t);
 
#pragma warning(disable : 6031)
#pragma warning(disable : 4101)
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;
typedef complex<double> cd;
 
const int INF = 1e9;
const long long LINF = 1e18;
const double PI = acos(-1);
 
// Solution

const int MAXN = 2005;

int n, m, x, ans, A[MAXN][MAXN], H[MAXN][MAXN], V[MAXN][MAXN];
char s[MAXN];

int main() {
    scanf("%d%d", &n, &m);

    for (int i = 0; i < n; i++) {
        scanf(" %s", s);

        for (int j = 0; j < m; j++) {
            A[i][j] = s[j] == '#';
        }
    }

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (A[i][j] == 1) {
                H[i][j] = V[i][j] = 0;
            } else {
                if (!H[i][j]) {
                    x = 1;

                    while (j + x < m && A[i][j + x] == 0) {
                        x++;
                    }

                    for (int k = 0; k < x; k++) {
                        H[i][j + k] = x;
                    }
                }

                if (!V[i][j]) {
                    x = 1;

                    while (i + x < n && A[i + x][j] == 0) {
                        x++;
                    }

                    for (int k = 0; k < x; k++) {
                        V[i + k][j] = x;
                    }
                }

                ans = max(ans, H[i][j] + V[i][j] - 1);
            }
        }
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 47360
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll a, b;
    char op;
    cin >> a>> op >> b;
    switch (op)
    {
        case ('+'):
        { 
            cout << a + b << endl;
            break;
        }
        case ('-'):
        {
            cout << a - b << endl;
            break;
        }
        default:
            ;
    }
    return 0;
}


Measured memory_bytes: 256
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n = sc.read();
    let m = sc.read();
    let mut g = vec![vec![]; n];
    for _ in 0..m {
        let a: usize = sc.read();
        let b: usize = sc.read();
        g[a - 1].push(Edge::new(b - 1, 1));
        g[b - 1].push(Edge::new(a - 1, 1));
    }
    let dist = distance_nonweight(&g, 0);
    let mut ans = vec![0; n];
    for i in 1..n {
        for e in g[i].iter() {
            if dist[e.to] + 1 == dist[i] {
                ans[i] = e.to;
                break;
            }
        }
    }
    println!("Yes");
    for i in 1..n {
        println!("{}", ans[i] + 1);
    }
}

#[derive(Debug, Copy, Clone)]
struct Edge {
    to: usize,
    cost: i64,
}
impl Edge {
    pub fn new(to: usize, cost: i64) -> Edge {
        Edge { to: to, cost: cost }
    }
}

fn distance_nonweight(graph: &Vec<Vec<Edge>>, start: usize) -> Vec<i32> {
    let mut res = vec![std::i32::MAX; graph.len()];
    res[start] = 0;
    let mut bfs = std::collections::VecDeque::new();
    bfs.push_back(start);
    while !bfs.is_empty() {
        let now = bfs.pop_front().unwrap();
        for e in graph[now].iter() {
            if res[now] + 1 < res[e.to] {
                res[e.to] = res[now] + 1;
                bfs.push_back(e.to);
            }
        }
    }
    res
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 15784
#include <stdio.h>

int main(){
    int N, M, a[50], b[50], i, j, ans[51], cnt;

    for(i=0; i<51; i++){
        ans[i]=0;
    }

    scanf("%d %d", &N, &M);
    for(i=0; i<M; i++){
        scanf("%d %d", &a[i], &b[i]);
        ans[a[i]]++;
        ans[b[i]]++;
    }

    for(i=1; i<=N; i++){
        printf("%d\n", ans[i]);
    }

    return 0;
}

Measured memory_bytes: 128
n, m, c = [int(x) for x in input().split()]
blist = [int(x) for x in input().split()]
alists = []
count = 0
for i in range(n):
    alists.append([int(x) for x in input().split()])
for alist in alists:
    clist = [x * y for (x, y) in zip(alist, blist)]
    if sum(clist) > c * (-1):
        count += 1
print(count)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
   int a,b,i;
   scanf("%d %d",&a,&b);
   if(a>=b){
      for(i=0;i<a;i++){
         printf("%d",b);
      }
   }else{
      for(i=0;i<b;i++){
         printf("%d",a);
      }
   }
   return 0;
}

Measured memory_bytes: 1728
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1

struct Node
{
	int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u)
{
	int i, c;
	cout << "node " << u << ": ";
	cout << "parent = " << T[u].p << ", ";
	cout << "depth = " << D[u] << ", ";

	if (T[u].p == NIL) {
		cout << "root, ";
	}
	else if (T[u].l == NIL) {
		cout << "leaf, ";
	}
	else {
		cout << "internal node, ";
	}

	cout << "[";

	for (int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
		if (i > 0) {
			cout << ", ";
		}
		cout << c;
	}

	cout << "]" << endl;

}

void rec(int u, int p) {
	D[u] = p;
	if (T[u].r != NIL) {
		rec(T[u].r , p);
	}

	if (T[u].l != NIL) {
		rec(T[u].l, p + 1);
	}
}

int main(void)
{
	int i, j, d, v, c, l, r;
	cin >> n;

	for (i = 0; i < n; i++) {
		T[i].p = T[i].l = T[i].r = NIL;
	}

	for (i = 0; i < n; i++) {
		cin >> v >> d;
		for (j = 0; j < d; j++) {
			cin >> c;
			if (j == 0) {
				T[v].l = c;
			}
			else{
				T[l].r = c;
			}
			l = c;
			T[c].p = v;
		}
	}

	for (i = 0; i < n; i++) {
		if (T[i].p == NIL) {
			r = i;
			break;
		}
	}

	rec(r, 0);

	for (i = 0; i < n; i++) {
		print(i);
	}

	return 0;
}

Measured memory_bytes: 7676
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
const double EPS = 1e-10;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


template<typename T>
struct BIT {
	int n;
	vector<T>dat;
	BIT(int n = 0) {
		initialize(n);
	}
	void initialize(int temp) {
		n = temp;
		dat.resize(n);
		rep(i, 0, n)dat[i] = 0;
	}
	T sum(int i) {
		T s = 0;
		while (i >= 0) {
			s += dat[i];
			i = (i & (i + 1)) - 1;
		}
		return s;
	}
	T sum_between(int i, int j) {
		if (i > j)return 0;
		return sum(j) - sum(i - 1);
	}
	void plus(int i, T x) {
		while (i < n) {
			dat[i] += x;
			i |= i + 1;
		}
	}
	int lower_bound(T x) {
		if (sum(n - 1) < x)return -1;
		else if (sum(0) >= x)return 0;
		int ng = 0, ok = n - 1;
		while (ok - ng > 1) {
			int mid = (ok + ng) / 2;
			if (sum(mid) >= x)ok = mid;
			else ng = mid;
		}
		return ok;
	}
};




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

	int N, Q;
	cin >> N >> Q;
	BIT<ll>bit;
	bit.initialize(N);

	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		bit.plus(i,a);
	}


	for (int i = 0; i < Q; i++) {
		int q;
		cin >> q;
		if (q == 0) {
			ll p, x;
			cin >> p >> x;
			bit.plus(p, x);
		}
		else {
			int l, r;
			cin >> l >> r;
			puts(bit.sum_between(l,r-1));
		}
	}
	return 0;
}

Measured memory_bytes: 8252
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    long long int sm=0;
    for(long long int i=0;i<s.length();i++)
        {
        	int k=48-s[i];
        	sm=sm+ k;
           
		}

if( sm%9==0 || sm==0)
	   cout<<"Yes"<<endl;
else 
cout<<"No"<<endl;
	
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int n, k;
	cin >> n >> k;
	vector<ll> v(n);
	rep(i,n) cin >> v[i];
	for (int i = k; i < n; i++) {
		if (v[(i - 1) - (k - 1)] < v[i]) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
}

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

Measured memory_bytes: 4840
#include <cstdio>
#include <iostream>
#include <cmath>
#include <set>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("a.in","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    for(int i=1;i<=2000;i++){
    	if(int(i*0.08)==a&&int(i*0.10)==b){
    		cout<<i<<"\n";
    		return 0;
    	}
    }
    cout<<-1<<"\n";
    return 0;
}

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

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long> vll;
typedef pair<int, int> pi;
typedef pair<long long, long long> pll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<long long, long long>> vpll;

#define F first
#define S second
#define PB push_back
#define MP make_pair

int main() {
    int n, m, a;
    cin >> n >> m;

    for (int i = 0; i < m; i++) {
        cin >> a;
        n -= a;
    }

    cout << max(-1, n);
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 300000;
vector<int> prime;
vector<int> MSnumber;

void make_MS(){
    MSnumber.push_back(6);
    for(int i=1; i<=MAX; i++){
        if(i*7+1 > MAX) break;
        MSnumber.push_back(i*7+1);
        MSnumber.push_back(i*7+6);
    }
}

bool make_prime(int number){
    for(int i=0; MSnumber[i]<=sqrt(number); i++){
        if(number % MSnumber[i] == 0) return false;
    }
    return true;
}

int main(){
    make_MS();
    for(int i=0; i<MSnumber.size(); i++){
        if(make_prime(MSnumber[i])){
            prime.push_back(MSnumber[i]);
        }
    }
    while(1){
        int n;
        cin>>n;
        if(n == 1) break;
        cout<<n<<":";
        for(int i=0; i<prime.size(); i++){
            if(n % prime[i] == 0) cout<<" "<<prime[i];
        }
        cout<<endl;
    }

    return 0;
}


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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    int *child;
    int ccnt = 0;
};

int get_depth(Node *node, int index) {
    if (node[index].parent < 0) {
        return 0;
    } else if (node[index].depth > 0){
        return node[index].depth;
    } else {
        int p = node[index].parent;
        int d = get_depth(node, p) + 1;
        for (int i = 0; i < node[p].ccnt; ++i) { node[node[p].child[i]].depth = d;}
        return node[index].depth;
    }
}

int main() {
    int n;
    cin >> n;
    Node a[n];
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a[x].index = x;
        a[x].child = new int[y];
        a[x].ccnt = y;
        for (int j = 0; j < a[x].ccnt; ++j) {
            int b;
            cin >> b;
            a[x].child[j] = b;
            a[b].parent = x;
        }
    }
    
    for (auto& i : a) {
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << get_depth(a, i.index) << ", ";
        cout << (i.parent < 0 ? "root" : (i.ccnt < 1 ? "leaf" : "internal node")) << ", ";
        cout << "[";
        for (int j = 0; j < i.ccnt-1; ++j) {
            cout << i.child[j] << ", ";
        }
        if (i.ccnt) { 
            cout << i.child[i.ccnt-1] << "]" << endl;
        } else {
            cout << "]" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 9704
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> x(3);
  cin >> x.at(0) >> x.at(1) >> x.at(2);
  
  sort(x.begin(), x.end());
  
  x.at(0) + x.at(1) == x.at(2)? cout << "Yes" << endl : cout << "No" << endl;  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > > 
#define pq_pair_ts priority_queue <pair<ll,ll> > //第二成分の大きさが関係ない
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


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

    ll N ;
    cin >> N ;
    ll one= 0, two=0, four=0;
    rep(i,N){
        ll inp; cin >> inp;
        if(inp%4 == 0) four ++;
        else if(inp %2 == 0) two ++;
        else one++;
    }
    if(two == 0){
        if(one <= (four+1)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        if(one <= four) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

#define N_MAX 100000

int desc(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 main(void){
  int i, j;

  int n;
  scanf("%d", &n);

  int a[N_MAX] = {}, plus = 0, minus = 0;
  long sum = 0;
  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if(a[i] > 0){
      plus++;
      sum += a[i];
    }else if(a[i] < 0){
      minus++;
      sum -= a[i];
    }
  }

  qsort(a, n, sizeof(int), desc);

  if(plus == 0) sum += a[0]*2;
  else if(minus == 0) sum -= a[n-1]*2;
  printf("%ld\n", sum);

  if(plus == 0){
    for(i = 1; i < n ;i++){
      printf("%d %d\n", a[0], a[i]);
      a[0] -= a[i];
    }
    return 0;
  }else if(minus == 0){
    for(i = 1; i < n-1; i++){
      printf("%d %d\n", a[n-1], a[i]);
      a[n-1] -= a[i];
    }
    printf("%d %d\n", a[0], a[n-1]);
    return 0;
  }

  for(i = 0; i < plus-1; i++){
    printf("%d %d\n", a[n-1], a[i]);
    a[n-1] -= a[i];
  }
  for(i = plus; i< n; i++){
    printf("%d %d\n", a[plus-1], a[i]);
    a[plus-1] -= a[i];
  }

  return 0;
}


Measured memory_bytes: 2232
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

void sort(int x[],int num){
    int ret[num];
    int count=0;
    bool flag=false;
    for(int i=0;i<num;i++){
        ret[i]=x[i];
        for(int j=0;j<=i;j++){
            if(ret[i]==ret[j])
                count++;
        }
        if(count>1)
            ret[i]=393939;
        count=0;
    }
    memcpy(x,ret,num*sizeof(int));
}

int main(){
    int* array1,*array2;
    int n,q,counter=0;

    scanf("%d",&n);
    array1=malloc(sizeof(int)*n);
    for(int i=0;i<n;i++){
        scanf("%d",&array1[i]);
    }
    sort(array1,n);

    scanf("%d",&q);
    array2=malloc(sizeof(int)*q);
    for(int j=0;j<q;j++){
        scanf("%d",&array2[j]);
    }
    for(int k=0;k<q;k++){
        for(int l=0;l<n;l++){
            if(array1[l]==393939)
                continue;
            if(array2[k]==array1[l]){
                counter++;
            }
        }
    }
    printf("%d\n",counter);

   /* for(int t=0;t<n;t++){
        printf("%d ",array1[t]);
    }*/

    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n,k; cin>>n>>k;
    int cnt = 0;
    rep(i,n){
        int a; cin>>a;
        if(a>=k) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 384
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates


int main()
{
    ll n;
    cin >> n;
    ll result = (1000 - (n % 1000)) % 1000;
    cout << result << endl;
    return 0;
}


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

#define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++)
#define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++)
#define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--)
#define rep(i, n) FOR(i, 0, n)
#define repn(i, n) FORN(i, 1, n)
#define repr(i, n) FORR(i, n, 0)
#define repnr(i, n) FORR(i, n, 1)
#define co(n) cout << (n) << endl
#define cosp(n) cout << (n) << ' '
#define setp(n) cout << fixed << setprecision(n);
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> Vec;

const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const double PI = acos(-1);
const double EPS = 1e-9;

int main(void){
	int n;
	cin >> n;
	string s;
	cin >> s;

	if(n%2){
		puts("No");
		return 0;
	}

	rep(i, n/2){
		if(s[i] != s[i+n/2]){
			puts("No");
			return 0;
		}
	}

	puts("Yes");
	return 0;
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;
typedef tuple<long long, long long, long long> tllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
bool compTuple(const tllint& arg1, const tllint& arg2) { return get<2>(arg1) > get<2>(arg2); }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

vector<vector<pint>> g;
vector<vector<int>> w;
vector<int> ans;

void bfs(int s) {
    queue<pint> q;
    q.push({s, 0});

    while(!q.empty()) {
        auto uw = q.front(); q.pop();
        for(auto vw:g[uw.first]) {
            if(ans[vw.first]!=-1) continue;
            if(vw.second%2==0) ans[vw.first] = ans[uw.first];
            else ans[vw.first] = 1 - ans[uw.first];
            q.push(vw);
        }
    }
}

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

    g.resize(n);
    ans.resize(n, -1);

    int u, v, w;
    for(int in=0;in<n-1;++in) {
        cin >> u >> v >> w; u--; v--;
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }

    ans[0] = 0;
    bfs(0);

    for(auto ians:ans) cout << ians << endl;
    return 0;
}


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

using namespace std;
using lli = long long int;

vector<lli> input(int N) { vector<lli> r(N); for (int i = 0; i < N; i++)cin >> r[i]; return r; }

int main() {
	lli N, K;
	cin >> N >> K;
	vector<lli> h = input(N);
	vector<lli> dp(N + 10);
	for (int i = 0; i < N; i++)dp[i] = INT64_MAX;
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int k = 0; k <= K; k++) {
			if (i >= k) {
				dp[i] = min(dp[i], dp[i - k] + abs(h[i - k] - h[i]));
			}
		}
	}
	cout << dp[N - 1] << endl;
}


Measured memory_bytes: 1920
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define INF 1000000;
#include <map>
#include <math.h>

using ll = long long;
using namespace std;

int main(){
 int n, m, count=0;
 cin >> n >> m;
 int a = n*(n-1)/2;
 int b = m*(m-1)/2;
 cout << a+b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

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

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll a, bi;
    ld b;
    cin >> a >> b;
    bi = (ll)(b * 100 + EPS);
    // err(a, bi);
    cout << a * bi / 100 << endl;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int INF=1e9;
 
ll N,A,B;
ll h[100005],m[100005];
 
bool check(ll n){
 
    for(int i=0; i<N; i++) m[i]=h[i]-n*B;
 
    ll cnt=0LL;
    for(int i=0; i<N; i++){
        if(m[i]>0){
            if(m[i]%(A-B)==0){
                cnt+=m[i]/(A-B);
            }else{
                cnt+=m[i]/(A-B)+1;
            }
        }
    }
 
    if(cnt<=n) return 1; 
    else return 0;
 
}
 
int main(){
 
cin>>N>>A>>B;
 
for(int i=0; i<N; i++) scanf("%lld",&h[i]);
 
ll lb=0,ub=INF,mid;
while(ub-lb>1){
    mid=(lb+ub)/2;
    if(check(mid)) ub=mid;
    else lb=mid;
}
 
cout<<ub<<endl;
 
}

Measured memory_bytes: 1792
#include <iostream>


void p(char *str, int a, int b) {
  for (int i = a; i <= b; i ++)
    std::cout << str[i];
  std::cout << std::endl;
}

void replace(char *str, int a, int b, char *replace_str) {
  for (int i = a; i <= b; i ++)
    str[i] = replace_str[i - a];
}

void reverse(char *str, int a, int b) {
  char temp;
  for (int i = 0; i < (b - a + 1) / 2; i ++) {
    temp = str[a + i];
    str[a + i] = str[b - i];
    str[b - i] = temp;
  }
}

int main() {
  char str[1000], replace_str[1000], command[100];
  int q, a, b;
  std::cin >> str >> q;

  for (int i = 0; i < q; i ++) {
    std::cin >> command >> a >> b;
    // std::cout << str << "\n\n";
    switch (command[2]) {
      case 'p':
        std::cin >> replace_str;
        replace(str, a, b, replace_str);
        break;
      case 'v':
        reverse(str, a, b);
        break;
      case 'i':
        p(str, a, b);
        break;
    }
    // std::cout << command << " " << a << " " << b << std::endl;
    // std::cout << str << std::endl;;
  }
  return 0;
}



Measured memory_bytes: 3092
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Wed Jan  9 22:40:21 2019
//
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(string(s[0]) + strconv.Itoa(len(s)-2) + string(s[len(s)-1]))
}


Measured memory_bytes: 512
n = int(input())
a = list(map(lambda x : int(x) -1 ,input().split()))
b = list(map(int,input().split()))
c = [0]
c.extend(list(map(int,input().split())))
prev = 20
ans = 0
for i in range(n):
    if a[i] -1 == prev:
        ans += b[a[i]] + c[a[i]]
    else:
        ans += b[a[i]]
    prev = a[i]
print(ans)

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

int main() {
	int n, x;
	while (1) {
		cin >> n >> x;
		if (n == 0 && x == 0) break;
		int count = 0;
		for (int i = 1; i <= n; i++) {
			for (int j = i+1; j <= n; j++) {
				if (i == j) continue;
				for (int k = j+1; k <= n; k++) {
					if (i == k || j == k) continue;
					if (i + j + k == x) count++;
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>    
int main(void) 
{     
	int i, j, n, tmp;     
	char s;     
	int card[4][13];     
	for(i=0; i<4; i++)
	{         
		for(j=0; j<13; j++)             
		card[i][j] = 0;     
	}            
		scanf("%d", &n);     
		for(i=0; i<n; i++)
		{         
			scanf("%s%d", &s, &tmp);         
		    if(s == 'S')             
		    card[0][tmp-1] = 1;         
		    else if(s == 'H')            
		    card[1][tmp-1] = 1;         
		    else if(s == 'C')             
		    card[2][tmp-1] = 1;         
		    else            
		    card[3][tmp-1] = 1;                
		}     
		for(i=0; i<4; i++)
		{         
			for(j=0; j<13; j++)
			{             
				if(card[i][j] == 0)
				{                 
					if(i==0)                     
					printf("S %d\n", j+1);                 
					else if(i==1)                     
					printf("H %d\n", j+1);                 
					else if(i==2)                     
					printf("C %d\n", j+1);                 
					else                    
					printf("D %d\n", j+1);                
				}         
			}     
		}     
	return 0; 
}

Measured memory_bytes: 596
import sys
import numpy as np
input = sys.stdin.readline

def main():
  N, K = map(int, input().split())
  h = np.array(list(map(int, input().split())))
  
  # dp[i] := 0からiまでいくのにかかる最小コスト
  dp = np.zeros(N, dtype=np.int)  
  
  for i in range(1, N):
    start = max(0, i-K)
    dp[i] = min(dp[start:i] + abs(h[start:i] - h[i]))
  
  print(dp[N-1])

if __name__ == "__main__":
  main()

Measured memory_bytes: 22800
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define case(i) cout<<"Case #"<<i<<": ";
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;

ll modpow(ll n, ll p) {
	if (p == 0) {
		return 1;
	}
	if (p % 2 == 0) {
		ll half = modpow(n, (p / 2));
		return (half * half) % mod;
	}
	else {
		return n * modpow(n, p - 1) % mod;
	}
}

int b, w; ll fac[200010],ifac[200010];
ll comb(int a, int b) {
	if (a < b) return 0;
	if (b > a - b) return comb(a, a - b);
	ll ans = fac[a] * ifac[b] % mod;
	return ans * ifac[a - b] % mod;
}

int main() { 
	cin >> b >> w;
	fac[0] = 1; ifac[0] = 1;
	rep(i, 1, b + w) {
		fac[i] = (fac[i - 1] * i) % mod;
		ifac[i] = (ifac[i - 1] * modpow(i,mod-2)) % mod;
	}
	vector<int> p(b + w, 0), q(b + w, 0);
	rep(i, 1, b + w) {
		p[i] = (p[i - 1] + (ll)(comb(i - 1, b - 1) * modpow(2, mod - i - 1))%mod)%mod;
	}
	rep(i, 1, b + w) {
		q[i] = (q[i - 1] + (ll)(comb(i - 1, w - 1) * modpow(2, mod - i - 1))%mod) % mod;
	}
	rep(i, 0, b + w) {
		cout << ((ll)(1 - p[i] + q[i] + mod) * modpow(2, mod - 2)) % mod << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int n, k, c;
  cin >> n >> k >> c;
  string s;
  cin >> s;

  vector<int> days;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'x') days.push_back(0);
    else days.push_back(1);
  }

  vector<int> w_days;
  vector<int> w_days_reverse;
  for (int i = 0; i < n; i++) {
    if (!days[i]) continue;    
    w_days.push_back(i);
    i += c;
    if (w_days.size() == k) break;
  }
  for (int i = n-1; i >= 0; i--) {
    if (!days[i]) continue;    
    w_days_reverse.push_back(i);
    i -= c;
    if (w_days_reverse.size() == k) break;
  }

  sort(w_days_reverse.begin(), w_days_reverse.end());
  for (int i = 0; i < w_days.size(); i++) {
    
    if (w_days[i] == w_days_reverse[i]) cout << w_days[i] + 1 << endl;
  }

  return 0;
} 

Measured memory_bytes: 4216
#include <cstdio>
#include <regex>
#include <list>
#include <iomanip>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define FORi(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FOR(i,n) FORi(i,1,n)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mt make_tuple
#define pb push_back
#define sz size()
#define SET(__set, val) memset(__set, val, sizeof(__set))

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
using pdd=pair<double, double>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto& p: c) os << p << " ";
	return os<<']';
}

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}


template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

constexpr int INF=1e9;
constexpr int MOD=1000000007;
constexpr double EPS=1e-9;
constexpr int maxw=31;
constexpr int maxn=1000000000;

set<int> graph[51];

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

	int n, m;
	while(cin>>n>>m) {
		FOR(i, n) graph[i].clear();
		queue<int> hasone;
		rep(i, m) {
			int a, b;
			cin>>a>>b;
			graph[a].insert(b);
			graph[b].insert(a);
		}
		int cnt = 0;
		FOR(i, n) if(graph[i].size() == 1)
			hasone.push(i);
		while(!hasone.empty()) {
			int now = hasone.front();
			hasone.pop();
			int ne;
			if(graph[now].size()) {
				cnt++;
				ne = *graph[now].begin();
				graph[ne].erase(now);
				if(graph[ne].size() == 1) hasone.push(ne);
			}
			graph[now].erase(ne);
		}
		cout << cnt << endl;
	}
	return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    s=SI()
    k=I()
    u=s[k-1]
    for i in range(n):
        if s[i]==u:
            print(s[i],end="")
        else:
            print("*",end="")
    








if __name__=="__main__":
    main()



Measured memory_bytes: 65540