akhauriyash/Code-Regression huggingface dataset:
package main

import "fmt"

func main() {
	for{
		var str string
		var m int
		fmt.Scan(&str)
		if str == "-"{
			break
		}
		fmt.Scan(&m)
		h := make([]int, m)
		for i:=0; i<len(h); i++{
			fmt.Scan(&h[i])
			str = str[h[i]:] + str[:h[i]]
		}
		fmt.Println(str)
	}
}


Measured memory_bytes: 1116
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e5+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

struct node{
	int x,y;
}a[maxn];
int cmp(node x,node y){
	if(x.x==y.x)return x.y>y.y;
	return x.x<y.x;
}

priority_queue<int> q;
int main(){
	int k,m,n;
	n=read();m=read();
	for(register int i=1;i<=n;i++){
		a[i].x=read();a[i].y=read();
	}
	sort(a+1,a+n+1,cmp);
	int now=1,ans=0,t=1;
	for(register int i=1;i<=m;i++){
		while(a[now].x<=i && now<=n){
			q.push(a[now].y);
			now++;
		}
		if(!q.empty()){
			ans+=q.top();
			q.pop();
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1660
import math

n = int(input())
mod = 10**9+7
d = {}

zero = 0
for i in range(n):
    a,b = map(int,input().split())
    if a == 0 and b == 0:
        zero += 1
    else:
        g = math.gcd(a,b)
        a //= g
        b //= g
        if b < 0:
            a = -a
            b = -b
        if b == 0 and a == -1:
            a = 1
        if a > 0:
            if (a,b) in d:
                d[(a,b)][0] += 1
            else:
                d[(a,b)] = [1,0]
        else:
            if (b,-a) in d:
                d[(b,-a)][1] += 1
            else:
                d[(b,-a)] = [0,1]
ans = 1
for (a,b),(c,d) in d.items():
    count = (pow(2,c,mod)+pow(2,d,mod)-1)%mod
    ans *= count
    ans %= mod


print((ans+zero-1)%mod)




Measured memory_bytes: 60272
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	var n, m int
	fmt.Fscan(r, &n, &m)
	to := make([][]int, n)
	for i := 0; i < m; i++ {
		var s, t int
		fmt.Fscan(r, &s, &t)
		s--
		t--
		to[s] = append(to[s], t)
	}

	dp := make([][]float64, n)
	for i := 0; i < n; i++ {
		dp[i] = make([]float64, n)
		for j := 0; j < n-1; j++ {
			dp[i][j] = math.Inf(0)
		}
	}

	for i := n - 1; i >= 0; i-- {
		for j := n - 2; j >= 0; j-- {
			var max, sum float64
			for _, t := range to[j] {
				x := dp[i][t] + 1
				if max < x {
					max = x
				}
				sum += x
			}
			dp[i][j] = sum / float64(len(to[j]))
			if i == j && len(to[j]) >= 2 {
				dp[i][j] = math.Min(dp[i][j], (sum-max)/float64(len(to[j])-1))
			}
		}
	}

	ans := math.Inf(0)
	for i := 0; i < n; i++ {
		if ans > dp[i][0] {
			ans = dp[i][0]
		}
	}
	fmt.Fprintln(w, ans)
}


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

using namespace std;

vector < vector <int> > G;

int dfs(int, int *, int, int);

int main()
{
	int N, M;
	cin >> N >> M;

	G.resize(N + 1);

	for (int i = 0; i < M; i++)
	{
		int x, y;
		cin >> x >> y;

		G[x].push_back(y);
		G[y].push_back(x);
	}

	int vis[N + 1];
	memset(vis, 0, sizeof(vis));

	cout << dfs(1, vis, 1, N) << endl;

	return (0-0);
}

int dfs(int node, int * vis, int depth, int N)
{
	if (depth == N)
		return 1;

	vis[node] = 1;

	int ans = 0;

	for (int i = 0; i < G[node].size(); i++) {
		int adj = G[node][i];

		if (not vis[adj]) {
			ans += dfs(adj, vis, depth + 1, N);
		}
	}

	vis[node] = 0;

	return ans;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rep(i,x) for(int i=0;i<(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

struct SegTree { // ??????min,max
	int n;
	vector<int> Max;
	vector<int> Min;

	void init(int n_)
	{
		n = 1;
		while (n < n_) n *= 2;

		Max.resize(2 * n);
		Min.resize(2 * n);

		for (int i = 0; i < 2 * n - 1; ++i) {
			Max[i] = -inf;
			Min[i] = inf;
		}
	}

	void update(int idx, int val)
	{
		idx += n - 1;
		Min[idx] = val;
		Max[idx] = val;

		while (idx > 0) {
			idx = (idx - 1) / 2;
			Min[idx] = min(Min[idx * 2 + 1], Min[idx * 2 + 2]);
			Max[idx] = max(Max[idx * 2 + 1], Max[idx * 2 + 2]);
		}
	}

	int get_min(int a, int b, int k = 0, int l = 0, int r = -1) // [a, b)???min
	{
		if (r == -1) r = n;
		if (r <= a || b <= l) return inf;
		if (a <= l && r <= b) return Min[k];

		int vl = get_min(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_min(a, b, k * 2 + 2, (l + r) / 2, r);

		return min(vl, vr);
	}

	int get_max(int a, int b, int k = 0, int l = 0, int r = -1) // [a, b)???max
	{
		if (r == -1) r = n;
		if (r <= a || b <= l) return -inf;
		if (a <= l && r <= b) return Max[k];

		int vl = get_max(a, b, k * 2 + 1, l, (l + r) / 2);
		int vr = get_max(a, b, k * 2 + 2, (l + r) / 2, r);

		return max(vl, vr);
	}
};

int X[200020], Y[200020];

signed main()
{
	int N, d; scanf("%d%d", &N, &d);

	SegTree x_seg, y_seg;

	x_seg.init(N), y_seg.init(N);

	vpii sorted;

	rep(i, N) {
		int x, y, b; scanf("%d%d%d", &x, &y, &b);
		X[i] = x, Y[i] = y;

		sorted.PB(pii(b, i));
	}

	sort(all(sorted));

	rep(i, N) {
		x_seg.update(i, X[sorted[i].scd]);
		y_seg.update(i, Y[sorted[i].scd]);
	}

	ll ans = -inf;

	rep(i, N) {
		if (i > 0 && sorted[i].fst == sorted[i - 1].fst) continue;

		int b = sorted[i].fst;

		int idx = upper_bound(all(sorted), pii(b + d, inf)) - sorted.begin();

		int min_x = x_seg.get_min(i, idx);
		int max_x = x_seg.get_max(i, idx);

		int min_y = y_seg.get_min(i, idx);
		int max_y = y_seg.get_max(i, idx);

		ans = max(ans, (ll)(max_x - min_x) * (max_y - min_y));
	}

	printf("%lld\n", ans);
}

Measured memory_bytes: 12440
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

    vector<vector<int>> g(n, vector<int>(0));
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    int res = 0;
    for (int i = 0; i < n; i++) {
        int m = 0;
        for (int j = 0; j < static_cast<int>(g[i].size()); j++) {
            m = max(m, h[g[i][j]]);
        }

        if (h[i] > m) {
            res++;
        }
    }

    cout << res << endl;
}


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

using namespace std;

using int64 = long long;
const int64 INF = 1LL << 59;

unordered_map< int64, int > prime_factor(int64 n)
{
  unordered_map< int64, int > ret;
  for(int64 i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return (ret);
}

int Q;
pair< unordered_map< int64, int >, int > vv[300];

int64 rec(vector< pair< int, int > > &conv, vector< int > &candidate, int idx, bool flag)
{
  int64 ret = 0;

  if(candidate.empty()) {
    return (ret);
  }

  if(flag) {
    for(auto &j : candidate) ret += vv[j].second;
  }

  if(idx < conv.size()) {

    if(conv[idx].first >= 17 && flag) {

      vector< int > used(Q, 0);
      int64 calc = 0;
      for(int i = idx; i < conv.size(); i++) {
        int64 beet = 0;
        if(conv[idx].first == 17) {
          int64 beet2 = 0;
          for(auto &j : candidate) {
            if(vv[j].first.count(conv[i].first)) {
              if(vv[j].first[conv[i].first] == 2) beet += vv[j].second;
              else beet2 += vv[j].second, beet += vv[j].second;
              used[j] = true;
            }
          }
          calc += max(0LL, max(beet, beet2));
          continue;
        }

        for(auto &j : candidate) {
          if(vv[j].first.count(conv[i].first)) {
            beet += vv[j].second;
            used[j] = true;
          }
        }
        calc += max(0LL, beet);
      }
      for(auto &j : candidate) {
        if(!used[j]) calc += vv[j].second;
      }
      ret = max(ret, calc);

    } else {
      set< vector< int > > used;
      for(int i = 0; i <= conv[idx].second + 1; i++) {
        vector< int > nt;
        for(int j : candidate) {
          if(vv[j].first.count(conv[idx].first)) {
            if(vv[j].first[conv[idx].first] > i) continue;
          }
          nt.emplace_back(j);
        }
        if(used.count(nt)) continue;
        used.emplace(nt);
        ret = max(ret, rec(conv, nt, idx + 1, flag | (i > 0)));
      }
    }
  }
  return (ret);
}


int main()
{
  cin >> Q;
  map< int, int > mx;
  for(int i = 0; i < Q; i++) {
    int m, x;
    cin >> m >> x;
    auto latte = prime_factor(m);
    for(auto &p : latte) {
      mx[p.first] = max(mx[p.first], p.second);
    }
    vv[i] = {latte, x};
  }
  vector< pair< int, int > > convert(begin(mx), end(mx));
  vector< int > candidate(Q);
  iota(begin(candidate), end(candidate), 0);
  cout << rec(convert, candidate, 0, false) << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

int N,M;
vector<ll> A,B;

int main(){
  cin>>N>>M;
  A.resize(N);
  B.resize(N);
  rep(i,N) cin>>A[i]>>B[i];

  vector<pair<int,int>> v;
  rep(i,N) v.push_back(mkp(A[i],i));
  sort(v.begin(),v.end());

  int now=0;
  ll ans=0;
  priority_queue<pair<int,int>> PQ;
  for(int i=1;i<=M;i++){
      while(now<N&&v[now].first<=i){
          int tar=v[now].second;
          PQ.push(mkp(B[tar],tar));
          now++;
      }
      if(PQ.empty()) continue;
      auto f=PQ.top();
      PQ.pop();
      ans+=f.first;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 4084
#include <iostream>
using namespace std;
int main(){  
  char c;
  cin >> c;
  char a[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
  for(int i;i<26;i++){
    if(c==a[i]){
      cout << a[i+1];
      break;
    }
  }
  return 0;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    ll A,B;
    cin >> A >> B;
    ll C = min(A,B);
    ll g = 1;
    for(int i = C; i > 0; --i){
        if(A%i == 0 && B%i == 0){
            g = i;
            break;
        }
    }
    ll x = A / g;
    ll y = B / g;
    ll ans = x * y * g;
    cout << ans << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n, a, b;
    cin >> n >> a >> b;

    ll res = n / (a+b) * a;
    res += min(n % (a+b), a);

    cout << res << endl;

    return 0;
}

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

using namespace std;
typedef long long ll;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main(){
    double N, D;
    cin >> N >> D;
    cout << ceil(N / (2 * D + 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
r, c = (int(x) for x in input().split())
a = []
rsum =[]

for i in range(r):
  a.append(list(map(int, input().split())))#配列aに入力値を格納
  a[i].append(sum(a[i]))#その行の最終列にそれまでの和を格納

for i in range(r):
    print(" ".join(list(map(str, a[i]))))#a[i]はsumを経ているので一度文字列に変換し、joinで配列aに格納し、出力

csum =[]#r+1行目
for j in range(c+1):
  s = 0
  for i in range(r):
    s += a[i][j]
  csum.append(s)

print(" ".join(list(map(str, csum))))


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


def main():
    n, m, d = map(int, input().split())

    # KeyInsight
    # 期待値の線形性
    # See:
    # https://img.atcoder.jp/soundhound2018-summer-qual/editorial.pdf
    # https://mathtrain.jp/expectation

    # 気がつけた点
    # 愚直解を書き出した
    # 隣り合う2項がm - 1通りある

    # 解答までのギャップ
    # dが0かどうかで場合分け
    # 整数のペアを考える
    ans = m - 1

    if d == 0:
        # d = 0: (1, 1), ..., (n, n)のn通り
        ans /= n
    else:
        # d ≠ 0: (1, d + 1), ..., (n  -d, n)と(d - 1, 1), ..., (n, n - d)で2 * (n - d)通り
        ans *= 2 * (n - d)
        ans /= n ** 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
	
	int h,w;cin>>h>>w;
	string s[h+2];

	string t = "";
	for(int i=0;i<w;i++)t+='x';

	s[0] = t;
	s[h+1] = t; 

	for(int i=1;i<=h;i++){
		cin>>s[i];
		s[i]+='x';
		s[i]='x'+s[i];
	}

	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){

			if( s[i][j]=='#' ){
				bool good = 0;

				if( s[i-1][j]=='#' )good = true;
				if( s[i+1][j]=='#' )good = true;
				if( s[i][j+1]=='#' )good = true;
				if( s[i][j-1]=='#' )good = true;

				if( !good ){
					cout<<"No\n";
					return 0;
				}
			}
		}
	}
	cout<<"Yes\n";
	return 0;

	/*
	1. Check for output format
	2. CHeck for corner cases
	3. Compile and run given TC first
	*/

}

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

//unionfind
const int MAX_N = 100010;
ll m, n;
int par[MAX_N];    //親
int deapth[MAX_N]; //木の深さ
ll cnt[MAX_N];
ll num;

//n要素で初期化
void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        par[i] = i;
        deapth[i] = 0;
        cnt[i] = 1;
    }
}
//木の根を求める
int find(int x)
{
    if (par[x] == x)
    {
        return x;
    }
    else
    {
        return par[x] = find(par[x]);
    }
}

//xとyの属する集合を併合
void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;
    if (deapth[x] < deapth[y])
    {
        par[x] = y;
        cnt[y] += cnt[x];
    }
    else
    {
        par[y] = x;
        cnt[x] += cnt[y];
        if (deapth[x] == deapth[y])
            deapth[x]++;
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int main()
{
    cin >> n >> m;
    init(n + 1);
    vector<int> p(n + 1, 0);
    rep(i, n)
    {
        cin >> p[i + 1];
    }
    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        unite(x, y);
    }
    int ans = 0;
    rep(i, n + 1)
    {
        if (i == 0)
            continue;
        if (same(p[i], i))
        {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.InputStreamReader;

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

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt(); // 500
        int b = scanner.nextInt(); // 100
        int c = scanner.nextInt(); //  50
        int x = scanner.nextInt(); // target
        int tmp500;
        int tmp100;
        int tmp50;
        int cnt = 0;

        for (int i=0;i<=a;i++) {
        	if(x<(500*i)) {
        		break;
        	}else if(x==(500*i)){
        		cnt++;
        		break;
        	}else{
        		tmp500 = x - (500*i);
        		for (int j=0;j<=b;j++) {
        			tmp100 = tmp500;
        			if(tmp100<(100*j)) {
        				break;
        			}else {
        				tmp50 = tmp100 - (100*j);
        				for(int k=0;k<=c;k++) {
        					if((tmp50-(50*k))==0) {
        						cnt++;
        					}
        				}
        			}
        		}
        	}

        }
        System.out.println(cnt);

    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {line = br.readLine();}
                s = line.split(reg, 0);
                i = 0;return s[i++];
            } catch (Exception e) {e.printStackTrace();}
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if(a == b && b != c || a == c && a != b || b == c && a != c) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
SIZE=2*10**5; MOD=10**9+7 #998244353 #ここを変更する

SIZE += 1
fac = [0]*SIZE  # fac[j] = j! mod MOD
fac[0] = fac[1] = 1
for i in range(2,SIZE):
    fac[i] = fac[i-1]*i%MOD

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,m = map(int,read().split())

if abs(n-m) >= 2:
    print(0)
elif abs(n-m)==1:
    print(fac[n]*fac[m]%MOD)
elif n==m:
    print(2*fac[n]*fac[m]%MOD)





Measured memory_bytes: 16936
pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        return Scanner {
            line: vec![],
            idx: 0,
        };
    }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.idx == self.line.len() {
            let mut buffer = String::new();
            std::io::stdin().read_line(&mut buffer).ok();
            let a: Vec<&str> = buffer.trim().split(' ').collect();
            self.line = a.iter().map(|&s| String::from(s)).collect();
            self.idx = 0;
        }
        let ret: T = self.line[self.idx].parse::<T>().ok().expect("Parse error.");
        self.idx += 1;
        ret
    }
    fn next_string(&mut self) -> Vec<char> {
        let s: String = self.next();
        return s.chars().collect::<Vec<char>>();
    }
    fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
}

#[allow(dead_code)]
fn gcd(a: u32, b: u32) -> u32 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

fn main(){
    let mut scan = Scanner::new();
    let n:usize = scan.next();
    let s = scan.next_string();
    let mut ans : u64 = 0;

    let (mut r1,mut g1,mut b1,mut r2,mut g2,mut b2)=(0,0,0,0,0,0);


    for i in 0..n{
        match s[i] {
            'R' => r2 += 1,
            'G' => g2 += 1,
            'B' => b2 += 1,
            _ => {},
        }
    }
    for i in 0..n{
        match s[i] {
            'R' => r2 -= 1,
            'G' => g2 -= 1,
            'B' => b2 -= 1,
            _ => {},
        }
        if s[i] == 'R'{
            ans += g1 * b2;
            ans += b1 * g2;
        }else if s[i] =='G'{
            ans += r1 * b2;
            ans += b1 * r2;
        }else{
            ans += r1 * g2;
            ans += g1 * r2;
        }

        match s[i] {
            'R' => r1 += 1,
            'G' => g1 += 1,
            'B' => b1 += 1,
            _ => {},
        }
    }

    for i in 1..n+1{
        if n < 2*i{
            break
        }
        for j in 0..(n-2*i){
            if s[j] != s[j+i] && s[j+i] != s[j+2*i] && s[j] != s[j+2*i]{
                ans -= 1;
            }
        }
    }
    
    println!("{}", ans);
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll mod = 10e9+7;

#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prtd(n, var)  cout << setprecision(n) << var << endl
#define prt2(var1, var2) cout << var1 << " " << var2 << endl

//----------------------------------------------------------------
struct Weight{
  int to;
  ll weight;
  Weight(int t, ll w) : to(t), weight(w) {}
};

class WeightGraph{

public:
  vector<vector<Weight>> tree;
  vector<int> check;
  vector<ll> dist;

  ll d, oldd;
  WeightGraph(int n){
    tree.resize(n);
    initCheck(n);
  }
  ~WeightGraph(){}

  void addpath(int m){
    int a, b;
    ll c;
    rep(i,m){
      cin >> a >> b >> c;
      a--;b--;
      tree[a].push_back(Weight(b, c));
      tree[b].push_back(Weight(a, c));
    }
  }

  void initCheck(int n){
    check.assign(n, false);
    dist.assign(n, LONG_MAX);
  }

  void dfs(int v){
    check[v] = true;
    dist[v] = d;

    for(auto next_v : tree[v]){
      if(check[next_v.to]){
        continue;
      }
      d = dist[v] + next_v.weight;
      dfs(next_v.to);
    }
  }
};

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

  WeightGraph g(n);
  g.addpath(n-1);
/*
  prt("path check");
  rep(i,n){
    prt("-----");
    rep(j,g.tree[i].size()){
      prt2(g.tree[i][j].to+1, g.tree[i][j].weight);
    }
  }
  prt("initial check");
  rep(i,n){
    prt(g.check[i]);
  }
  prt("initial dist");
  rep(i,n){
    prt(g.dist[i]);
  }
*/
  g.dist[0]=0;
  g.d=0;
  g.dfs(0);
/*
  prt("dist");
  rep(i,n){
    prt(g.dist[i]);
  }
*/
  //prt("color");
  rep(i,n){
    prt(g.dist[i]%2);
  }



}


Measured memory_bytes: 9344
n = input()
d = {"S":[None]*13, "H":[None]*13, "C":[None]*13, "D":[None]*13}

for i in range(n):
	x, y = raw_input().split()
	d[x][int(y)-1] = True

for k in ["S","H","C","D"]:
	for i in range(13):
		if d[k][i]:
			continue
		print ("%s %d"%(k, i+1))

Measured memory_bytes: 6368
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define ull unsigned long long

using namespace std;

const ll INF = 100100100100;

int main() {
	int N, K;
	cin >> N >> K;

	vector <ll> a(N);
	for (int ii = 0; ii < N; ++ii){
		cin >> a[ii];
	}

	ll ans = INF;
	for (int n = 0; n < (1<<N); ++n){
		bitset< 1<<15 > bs(n);
		if (bs.count()!=K) continue;

		ll sum = 0;
		ll h = a[0];
		for (int ii = 1; ii < N; ++ii){
			if (bs[ii]){
				ll need;
				if (h < a[ii]){
					h = a[ii];
					need = 0;
				} else {
					h += 1;
					need = h - a[ii];
				}
				sum += need;
			} else {
				h = max(h, a[ii]);
			}
		}
		ans = min(ans, sum);
	}

	cout << ans << "\n";

	return 0;
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

void compute() {

}

int main() {
  string a,b,c;
  cin >> a >> b >> c;
  cout << "A" << (char)toupper(b[0]) << "C" << endl;
  compute();
  return 0;
}


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

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

	int N, M; cin >> N >> M;
	vector<int> edges[N];
	for (int i=0; i<M; ++i) {
		int a, b; cin >> a >> b;
		edges[a].push_back(b);
	}

	bool bad[N];
	for (int i=1; i<N; ++i) bad[i] = (edges[i].size() <= 1);
	double dp[N+1][N];
	for (int i=0; i<N; ++i) dp[N][i] = 0;

	for (int x=N-1; x>=1; --x) {
		double result = 0, worst = -1;
		for (int y : edges[x]) {
			result += dp[y][0];
			if (dp[y][0] > worst) worst = dp[y][0];
		}
		double newresult = result/edges[x].size() + 1;
		for (int i=0; i<x; ++i) dp[x][i] = newresult;
		if (bad[x]) dp[x][x] = -1;
		else dp[x][x] = (result-worst)/(edges[x].size()-1) + 1;
		for (int i=x+1; i<N; ++i) {
			if (bad[i]) {
				dp[x][i] = -1;
				continue;
			}
			double result = 0;
			for (int y : edges[x]) result += dp[y][i];
			dp[x][i] = result/edges[x].size() + 1;
		}
	}
	
	double best = -1;
	for (int i=0; i<N; ++i) {
		if (dp[1][i] != -1 && (best == -1 || dp[1][i] < best)) best = dp[1][i];
	}
	cout << setprecision(12) << best;
}

Measured memory_bytes: 4224
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
ll factorial(ll x){
  if(x==0)return 1;
  return x*factorial(x-1)%MOD;
}
int main(){
  ll n,l;cin>>n>>l;
  vector<string>vec(n);
  rep(i,n)cin>>vec[i];
  sort(vec.begin(),vec.end());
  string ans="";
  rep(i,n)ans+=vec[i];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
#define ff first
#define ss second
#define PB push_back
#define MP make_pair
#define ll long long
#define llu unsigned long long
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))
#define ABS(X) ((X)< 0 ? -(X): (X))
#define LCM(X, Y)  ( ( (X) / (GCD( (X)  , (Y) ))) * (Y) )
#define MEM( A,  B) memset((A), (B), sizeof(A))
#define MEM_VEC(V, FILL ) fill( V.begin(), V.end(), FILL)
#define FOR_EACH(IT, V) for (auto IT = V.begin(); IT != V.end(); IT++)
#define DEBUG_ARRAY_PRINT(A,I) cout<<"at pos "<< I <<"  value is: "<< A[I]
#define TURBO ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0)
const double EPS =1e-9 ;
const double PI = 3.1415926535897932384626433832795 ;
using namespace std ;
inline ll GCD(ll A, ll B){
      if ( B == 0 ) return A;
      return GCD( (B) ,  (A % B) );
}
inline ll POW(ll BASE, ll EXP) {
   ll RES = 1;
   for(ll I= 0; I < EXP; I++) RES *= BASE ;
   return RES;
}

inline ll BIGMOD  ( ll a, ll p, ll m ) {
   ll res = 1 % m;
   ll x = a % m;
   while ( p > 0 ) {
       if ( (p & 1) > 0 ) res = ( res * x ) % m;
       x = ( x * x ) % m; p >>= 1;
   }
   return res;
}
inline void FILE_HANDLE( ){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

}

int main()
{
            //FILE_HANDLE() ;
            string str ;
            cin >> str ;
            for(int i = 0 ; i < str.size() ; i++) cout <<"x";
            cout << endl ;
}



Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    int n, q; cin >> n >> q;
    queue<pair<string, int> > qu;
    rep(i, n) {
        string name; int time;
        cin >> name >> time;
        qu.push({name, time});
    }
    int c = 0;
    while (!qu.empty()) {
        
        int co = min(q, qu.front().second);
        qu.front().second -= co;
        c += co;
        if (qu.front().second == 0) {
            cout << qu.front().first << " " << c << endl;
        } else {
            qu.push({qu.front().first, qu.front().second});
        }
        qu.pop(); //先頭を削除
    }
}



Measured memory_bytes: 6172
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
//#define int long long int 
const int MAXN = (int)2e5 + 10;
const int MOD = (int) 1e9;

void solve(){
    double r; cin >> r;
    double pi = 3.141592653;
    cout << fixed << setprecision(6);
    cout <<  2.0 * pi * r << '\n';
    

}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}
/*
Sample inp
*/

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

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        mp[s]++;
    }
    
    cout << mp.size() << endl;
    return 0;
}

Measured memory_bytes: 19260
N,K=map(int,input().split())
S=str(input())
if S[K-1]=='A':
    print(S[:K-1]+'a'+S[K:])
elif S[K-1]=='B':
    print(S[:K-1]+'b'+S[K:])
else:
    print(S[:K-1]+'c'+S[K:])

Measured memory_bytes: 3060
import unittest
import functools


class TestE(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([2, 3, 4]), 13)

    def test_2(self):
        self.assertEqual(think([12, 12, 12, 12, 12]), 5)

    def test_3(self):
        self.assertEqual(think([1000000, 999999, 999998]), 996989508)

    def test_4(self):
        self.assertEqual(gcd(3, 2), 1)


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    return read_int(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    mode = 10 ** 9 + 7

    lcm_of_all_a = functools.reduce(lambda x, y: lcm(x, y), a, 1)
    lcm_of_all_a %= mode

    result = 0
    for e in a:
        result += lcm_of_all_a * inverse(e, mode) % mode
        result %= mode
    return result


def write(result):
    print(result)


def lcm(a, b):
    return a // gcd(a, b) * b 


def gcd(a, b):
    if a < b:
        return gcd(b, a)

    while True:
        if a % b == 0:
            return b
        a, b = b, a % b


def inverse(x, mode):
    return pow(x, mode - 2, mode)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 54760
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long mod = (long)Math.pow(10,9)+7;
        int n = sc.nextInt();
        int m = sc.nextInt();
        int ans = 0;
        long xtotal = 0;
        for(int i = 0; i < n; i++){
            long x = sc.nextLong();
            xtotal += (i * x) - ((n-i-1) * x);
            xtotal %= mod;
        }
        long ytotal = 0;
        for(int i = 0; i < m; i++){
            long y = sc.nextLong();
            ytotal += (i * y) - ((m-i-1) * y);
            ytotal %= mod;
        }
        System.out.println((xtotal*ytotal)%mod);
    }
}


Measured memory_bytes: 63900
//xが偶数のとき, 移動方法が定まる(右に移動すればいい)ので簡単.
//xが奇数のとき, 1ターン止まったあと, xが偶数のパターンになる。
//x-1, x+1どちらになっても(最適な)動き方は同じ・不完全情報ゲームより(?)、止まるタイミングは最初にして良いので簡単。

#include <iostream>
#include <cstdio>
using namespace std;

int main() {
	int x, p;
	cin >> x >> p;
	double P = p * 0.01;
	
	if (x % 2 == 0) {
		printf("%.14f\n", x / (2 * P));
	}
	else {
		double e1 = (x - 1) / (2 * P);
		double e2 = (x + 1) / (2 * P);
		printf("%.14f\n", P * e1 + (1 - P) * e2 + 1);
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll N, K;
    cin>>N>>K;
    ll V[100];
    rep(i, N) cin>>V[i];
    ll Maxim=0;
    rep(i, K+1) rep(j, K+1-i){
        if(i+j>N) continue;
        ll count=0;
        vector<ll> je;
        //cout<<i<<sp<<j<<endl;
        rep(k, i) je.push_back(V[k]);
        rep(k, j) je.push_back(V[N-1-k]);
        sort(all(je));
        rep(k, K-i-j){
            if(k<je.size()) if(je[k]<0) je[k]=0;
        }
        rep(i, je.size()){
            count+=je[i];
        }
        Maxim=max(Maxim, count);
    }
    cout<<Maxim<<endl;
    return 0;
}


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

int main(void)
{
    int64_t n;

    std::cin >> n;

    auto check = [&]() -> int64_t {
        if (n == 1) return 1;
        int64_t l_2 = 2;
        int64_t l_1 = 1;
        int64_t l = 0;
        for (auto i=2; i <= n; ++i) {
            l = l_2 + l_1;
            l_2 = l_1;
            l_1 = l;
        }
        return l;
    };

    std::cout << check() << std::endl;

    return 0;
}


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

long fact(long n) {
    if (n <= 1) return 1;
    return (n * fact(n - 1)) % BASE;
}

int main() {
    int n, m;
    cin >> n >> m;
    if (n - m > 1 || m - n > 1) {
        cout << 0 << endl;
        return 0;
    }

    long ans = fact(n) * fact(m);
    if (n == m) {
        ans <<= 1;
    }
    cout << ans % BASE << endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        long ln = n;
        long[] div = new long[10000001];
        Arrays.fill(div,2);
        div[1] = 1;
        for(int i = 2; i <= n; i++){
            long now = i;
            long li = i;
            for(int j = 2; j <= n/i; j++){
                div[(int)i*j]++;
            }
        }
        //rintArr(div,n);
        long ans = 0;
        for(int i = 1; i <= n; i++){
            ans += i*div[i];
        }
        System.out.println(ans);
    }
    
    public static void printArr(long[] arr, int n){
        for(int i = 1; i <= n; i++){
            System.out.print(arr[i] + " ");
        }
        System.out.println();
        return;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 105300
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();

        ArrayList<String> arr = new ArrayList<String>();
        for(int i = 0; i < h; i++) {
        	String s = sc.next();
        	arr.add(s);
        }

        for (int i = 0; i < h ;) {
        	boolean flag = false;
        	String q = arr.get(i);
        	for(int j = 0; j < w ; j++) {
        		if (q.charAt(j) != '.') {
        			flag = true;
        		}
        	}
        	if(!flag) {
        		arr.remove(i);
        		h--;
        	}else {
        		i++;
        	}
        }

        for (int j = 0; j < w;) {
        	boolean flag = false;
        	for(int i = 0; i < h ; i++) {
        		String q = arr.get(i);
        		if (q.charAt(j) != '.') {
        			flag = true;
        		}
        	}
        	if(!flag) {
        		for(int k = 0; k < h; k ++) {
        			String p = arr.get(k);
        			arr.set(k, p.substring(0, j) + p.substring(j + 1, p.length()));
        		}
        		w--;
        	}else {
        		j++;
        	}
        }
        for(String s: arr) {
        	System.out.println(s);
        }
	}
}


Measured memory_bytes: 24012
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
ll n,m;
ll a[110000];
ll cntmtk(ll k){
  ll lb=-1,ub=n;
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    if(a[mid]>=k) ub=mid;
    else lb=mid;
  }
  return n-ub;
}

int main()
{
  cin >> n >> m;
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  ll lb = -1,ub = 2e+5+10;
  while(ub-lb>1){
    ll mid = (lb+ub)/2;
    ll cnt = 0;
    rep(i,n) cnt += cntmtk(mid-a[i]);
    if(cnt>=m) lb = mid;
    else ub = mid;
  }
  ll x = lb;
  ll mm = 0;
  rep(i,n) mm += cntmtk(x-a[i]);
  
  vector<ll> sum(n+1);
  sum[0] = 0;
  rep(i,n) sum[i+1] = sum[i] + a[i];
  ll res = 0;
  rep(i,n){
    ll j = cntmtk(x-a[i]);
    res += sum[n] - sum[n-j] + a[i]*j;
  }
  res -= (mm-m)*x;
  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = [input() for i in range(n)]
dict = {"M":0, "A":0, "R":0, "C":0, "H":0}
ans = 0
for c in a:
    if(c[0] in "MARCH"):
        dict[c[0]] += 1
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += dict["MARCH"[i]] * dict["MARCH"[j]] * dict["MARCH"[k]]
print(ans)

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

class MainClass
{
    public static void Main(string[] args)
    {
        string S = Console.ReadLine();
        char[] C = S.ToCharArray();

        C[0] = '2';
        C[1] = '0';
        C[2] = '1';
        C[3] = '8';


        for (int i = 0; i < C.Count(); i++)
        {
            Console.Write("{0}", C[i]);
        }

        Console.WriteLine();
    }
}


Measured memory_bytes: 13268
x=int(input())
if 400<=x<=599:
    print("8")
elif 600<=x<=799:
    print("7")
elif 800<=x<=999:
    print("6")
elif 100<=x<=1199:
    print("5")
elif 1200<=x<=1399:
    print("4")
elif 1400<=x<=1599:
    print("3")
elif 1600<=x<=1799:
    print("2")
elif 1800<=x<=1999:
    print("1")


Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define PI 3.14159265358979323846


double deg2rad(double degree)
{
    return degree * PI / 180.0;
}

int main()
{
  double a, b, h, m; cin >> a >> b >> h >> m;
  double A = h * 30.0 + m * 0.5;
  double B = m * 6.0;
  double w = A - B;
  double radian = deg2rad(w);
  double k = cos(radian);
  double d = a * a + b * b - (2.0 * a * b * k);
  d = sqrt(d);
  cout << setprecision(20) << d << endl;
}

Measured memory_bytes: 4136
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

using P=pair<int,int>;
void solve(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<string>s(h);
  int ans=numeric_limits<int>::max();
  rep(i,h)cin>>s[i];
  rep(bit,1<<(h-1)){
    int cnt=0;
    int pre=0;
    bool bad=false;
    vector<P>v;
    rep(i,h-1){
      if(bit&(1<<i)){
        ++cnt;
        v.eb(pre,i+1);//[pre,i+1)
        pre=i+1;
      }
    }
    v.eb(pre,h);//番兵を忘れない
    vector<int>sum(cnt+5);
    int j=0;
    int prej=j;
    while(j<w){
      rep(a,v.size()){
        REP(i,v[a].first,v[a].second){
          sum[a]+=s[i][j]=='1';
        }
      }
      bool ng=false;
      rep(a,v.size()){
        if(sum[a]>k)ng=true;
      }
      if(ng){
        ++cnt;
        if(prej==j){
          bad=true;
          break;
        }
        rep(a,v.size())sum[a]=0;
      }
      else ++j;
    }
    if(bad)continue;
    chmin(ans,cnt);
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 256
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto dud(C *x)->decltype(os << *x, 0);
template<class C> static char dud(...);
template<class C> typename enable_if<sizeof dud<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof dud<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 105;
#define yes return cout << "Possible\n", 0
#define no return cout << "Impossible\n", 0
#define YN(x) return cout << ((x) ? "Possible\n" : "Impossible\n"), 0

int n, a[mxn];
vector<int> nodeWithEcc[mxn];
list<int> g[mxn];
void addEdge(int u, int v) {//bug(u, v);
    g[u].push_back(v), g[v].push_back(u);
}

int lvl[mxn];

void dfs(const int &u, const int &p) {
    lvl[u] = p ? lvl[p]+1 : 0;
    for (auto &v : g[u]) if (v!=p) {
        dfs(v, u);
    }
}

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a+1, a+1+n);//bug(a);
    if (a[1] == a[3]) no;
    for (int i = 1; i <= n; i++) {
        nodeWithEcc[a[i]].push_back(i);
    }
    if (a[1]==a[2]) addEdge(1, 2);
    for (int i = a[1]+1; i <= a[n]; i++) {
        int sz = sz(nodeWithEcc[i]);
        if (sz < 2) no;
        addEdge(nodeWithEcc[i].back(), nodeWithEcc[i-1].back());
        for (int j = 0; j < sz-1; j++) {
            addEdge(nodeWithEcc[i][j], nodeWithEcc[i-1][0]);
        }
    }

    for (int i = 1; i <= n; i++) {
        dfs(i, 0);//bug(i, lvl);
        if (a[i] != *max_element(lvl+1, lvl+1+n)) no;
    }
    yes;
}

Measured memory_bytes: 256
//noob
#include<bits/stdc++.h>
using namespace std;
#define fori(x) for(int i=0;i<x;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long int 
#define ld long double
#define ull unsigned long long int
#define pi acos(-1)
#define test() int T,t=1;cin>>T;
#define all(x) (x).begin(),(x).end()
#define sz(x) (int(x.size()))
typedef vector<int> vi;
typedef pair<int,int> PI;
const int N = (int)1e6 + 7;

void solve()
{
	int n;cin>>n;
	int c=0;
	bool d=false;
	while(n--){
		int a,b;cin>>a>>b;
		if(a==b){
			c++;
			if(c>=3) d=true;
		}
		else{
			c=0;
		}
	}
	if(d) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	//freopen("input.txt","r",stdin);
	
solve();
	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll num;
int now=7,cnt=1;
map<int,int>mp;
int main(){
	cin>>num;
	now%=num;
	do{
		mp[now]=1;
		if(now==0){
			cout<<cnt;return 0;
		}
		now=now*10+7;now%=num;cnt++;
		if(mp[now]){
			puts("-1");return 0;
		}
	}while(1);
}

Measured memory_bytes: 50492
package main

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

func parse() (int, []int) {

	stdin := bufio.NewScanner(os.Stdin)
	stdin.Split(bufio.ScanWords)

	stdin.Scan()
	n, _ := strconv.Atoi(stdin.Text())

	stdin.Scan()
	k, _ := strconv.Atoi(stdin.Text())

	xs := make([]int, n)
	for i := 0; i < n; i++ {
		stdin.Scan()
		x, _ := strconv.Atoi(stdin.Text())
		xs[i] = x
	}

	return k, xs
}

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

func abs(a int) int {
	if a < 0 {
		return -a
	} else {
		return a
	}
}

func calculate(k, x int, xs *[]int) int {
	last := x + k - 1
	return min(abs((*xs)[x]), abs((*xs)[last])) + ((*xs)[last] - (*xs)[x])
}

func main() {
	k, xs := parse()

	ret := calculate(k, 0, &xs)

	for i := 1; i <= len(xs)-k; i++ {
		tmp := calculate(k, i, &xs)
		if tmp < ret {
			ret = tmp
		}
	}

	fmt.Println(ret)
}


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

int main() {
  int N,M;
  cin >>N>>M;
  vector<vector<int>> jobs(M);
  for(int i=0;i<N;i++){
    int a,b;
    cin>>a>>b;
    if(M>=a) jobs[M-a].push_back(b);
    }
  // a日後に振り込まれる→M-a日目までにやる必要がある

  // 降順ソートつきキュー
  priority_queue<int> que;
  int s=0;
  // 後ろから見ていく
  //
  for(int i=M-1;i>=0;i--){
    for(int j:jobs[i]){
      // i日目までにできる仕事(i日後に振り込まれる仕事)を追加
      que.push(j);

    }
    if(!que.empty()){

      // 追加された仕事うち最も給料が高いものを取り出す
      s += que.top();
      que.pop();
    }

  }
cout <<s<<endl;


}


Measured memory_bytes: 5504