akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
#define mp(x,y) make_pair((x),(y))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
inline ll read(){
    register ll x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

const int inf=1e9;
const ll INF=1e16;
int n,m;char ch[10];
struct node{int x,y;ll v;} a[85];
struct query{int op,a,b;} q[325];
inline void chkmax(int& x,int y){x=x>y?x:y;}
inline void chkmin(int& x,int y){x=x<y?x:y;}

int s,t,num,head[325],vis[325],flow[325],id[325],pre[325];
ll dis[325],ans;
struct edge{int to,next,flo;ll val;} e[200005];
inline void add(int u,int v,int f,ll w){
	e[++num]=(edge){v,head[u],f,w},head[u]=num;
	e[++num]=(edge){u,head[v],0,-w},head[v]=num;
}

bool bfs(){
	queue<int> q;
	REP(i,1,324)dis[i]=-INF;
	memset(vis,0,sizeof vis);
	dis[s]=0,flow[s]=inf,q.push(s),vis[s]=1;
	while(!q.empty()){
		int u=q.front();q.pop(),vis[u]=0;
		for(int i=head[u];i;i=e[i].next){
			int v=e[i].to;
			if(!e[i].flo||dis[v]>=dis[u]+e[i].val)continue;
			dis[v]=dis[u]+e[i].val;
			flow[v]=min(flow[u],e[i].flo);
			id[v]=i,pre[v]=u;
			if(!vis[v])vis[v]=1,q.push(v);
		}
	}
	return dis[t]>-INF;
}
ll network(){
	ll ans=0;
	while(bfs()){
		ans+=dis[t]*flow[t];
		int p=t;
		while(p^s)e[id[p]].flo-=flow[t],e[id[p]^1].flo+=flow[t],p=pre[p];
	}
	return ans;
}

void work(int K){
	int L[165],R[165];
	num=1,memset(head,0,sizeof head);
	s=n+n+K+K+1,t=s+1;
	REP(i,1,n)add(i,n+i,1,a[i].v);
	memset(L,0,sizeof L),memset(R,0x3f,sizeof R);
	REP(t,1,m){
		if(q[t].op==0)REP(i,q[t].b+1,K)chkmax(L[i],q[t].a+1);
		else if(q[t].op==1)REP(i,1,K-q[t].b)chkmin(R[i],q[t].a-1);
		else if(q[t].op==2)REP(i,q[t].b+1,K)chkmax(L[K+i],q[t].a+1);
		else REP(i,1,K-q[t].b)chkmin(R[K+i],q[t].a-1);
	}
	REP(i,1,K){
		add(s,n+n+i,1,0);
		REP(j,1,n)if(L[i]<=a[j].x&&a[j].x<=R[i])add(n+n+i,j,1,0);
	}
	REP(i,K+1,K+K){
		add(n+n+i,t,1,0);
		REP(j,1,n)if(L[i]<=a[j].y&&a[j].y<=R[i])add(n+j,n+n+i,1,0);
	}
	ans=max(ans,network());
}

int main(){
	n=read();
	REP(i,1,n)a[i]=(node){read(),read(),read()};
	m=read();
	REP(i,1,m){
		scanf("%s",ch);int o;
		if(ch[0]=='L')o=0;
		else if(ch[0]=='R')o=1;
		else if(ch[0]=='D')o=2;
		else o=3;
		q[i]=(query){o,read(),read()};
	}
	REP(i,1,n)
		work(i);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N,M = map(int,input().split(" "))
    if N==0 and M==0:
        break
    P = [list(map(int,input().split(" "))) for i in range(0,N)]
    ans = 0
    for p in sorted(P,key=lambda x:x[1],reverse=True):
        ans += (p[0] - M)*p[1] if p[0] - M > 0 else 0
        M = M - p[0] if M - p[0] > 0 else 0
    print(ans)
            

Measured memory_bytes: 8888
l = list(map(int,input().split()))
n,k = l[0],l[1]
d = list(map(int,input().split()))
for i in range(n,10*n+1):
    flag = 0
    s = list(str(i))
    for j in s:
        if int(j) in d:
            flag = 1
            break
    if flag == 0:
        print(i)
        break


Measured memory_bytes: 3060
#include "stdio.h"

main(){

  int H, W;
  int i, j;

  scanf("%d %d", &H, &W);

  while(H != 0 && W != 0){

    for(i = 0; i < H; i++){
      for(j = 0; j < W; j++){

        if(i == 0 || j == 0 || i == H-1 || j == W-1)printf("#");
        else printf(".");


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

    scanf("%d %d", &H, &W);
  }


  return 0;

}



Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define ll long long int
#define ve vector<int>
#define vl vector<long long int>
#define vs vector<string>
#define vve vector<vector<int>>
#define all(a) a.begin(),a.end()
using namespace std;

int main(){
  int n,m;
  cin>>n>>m;
  cout<<(n-1)*(m-1)<<endl;
}
 

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    int a,b,c,d,e,f,g,h,i,j,k;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    scanf("%d%d%d%d",&e,&f,&g,&h);
     i=a+b+c+d;
     j=e+f+g+h;
     if(i>j){
     k=i; 
     }
     else{
     k=j;
     }
     printf("%d\n",k);
     return 0;
}

Measured memory_bytes: 592
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		ABC051DSolve solve = new ABC051DSolve();
		solve.main();
	}
}

class ABC051DSolve {
	
	int N;
	int M;
	int[][] adj;
	
	ABC051DSolve() {
		Scanner cin = new Scanner(System.in);
		this.N = cin.nextInt();
		this.M = cin.nextInt();
		this.adj = new int[N][N];
		for (int i = 0; i < M; i++) {
			int a = cin.nextInt() - 1;
			int b = cin.nextInt() - 1;
			int c = cin.nextInt();
			adj[a][b] = c;
			adj[b][a] = c;
		}
	}
	
	void main() {
		int INF = Integer.MAX_VALUE / 2;
		int[][] dist = new int[N][N];
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				dist[i][j] = INF;
				if (adj[i][j] > 0) {
					dist[i][j] = adj[i][j];
					dist[j][i] = adj[i][j];
				}
			}
			dist[i][i] = 0;
		}
		
		for (int k = 0; k < N; k++) {
			for (int i = 0; i < N; i++) {
				for (int j = 0; j < N; j++) {
					dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}
		
		int count = 0;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (dist[i][j] < adj[i][j]) {
					count++;
				}
			}
		}
		System.out.println(count / 2);
	}
	
}


Measured memory_bytes: 14004
n, x = map(int, input().split())

a, p = [1], [1]
for i in range(n):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(n, x):
    if n == 0:
        if x <= 0:
            return 0
        else:
            return 1
    elif x <= 1 + a[n - 1]:
        return f(n-1, x-1)
    else:
        return p[n-1] + 1 + f(n-1, x-2-a[n-1])

print(f(n, x))

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

int main(){
	int h,w;
	char temp;
	cin >> h >> w;
	for (int i = 0 ;i<w+2; i++){
		cout << '#';
	}
	cout << endl;
	for (int i=0;i<h;i++){
		cout << '#';
		for (int j=0; j<w; j++){
			cin >> temp;
			cout << temp;
		}
		cout << '#' << endl;
	}
	for (int i = 0 ;i<w+2; i++){
		cout << '#';
	}
	cout << endl;
		
}


Measured memory_bytes: 256
use std::cmp;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

#[allow(dead_code)]
fn find_min(x: &[u64]) -> u64 {
    let mut min: u64 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        min = cmp::min(*i, min);
    }
    return min;
}

#[allow(dead_code)]
fn find_max(x: &[u64]) -> u64 {
    let mut max: u64 = x[0];
    let mut x_iter = x.iter();
    while let Some(i) = x_iter.next() {
        max = cmp::max(*i, max);
    }
    return max;
}

fn solve(x: Vec<u64>) -> Vec<u64> {
    let min = find_min(&x);
    let mut ans_base: Vec<u64> = x.clone().into_iter().map(|v| v%min).collect();
    ans_base.push(min);
    ans_base.retain(|&v| v!=0);
    ans_base
}

fn main() {
    let _n: u32 = read();
    let mut a: Vec<u64> = read_vec();

    while a.len() > 1 {
        a = solve(a);
    }

    println!("{}", a[0]);
}


Measured memory_bytes: 10232
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
using namespace std;
typedef long long ll;
template <class T> inline bool dpmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool dpmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

void solve(long long N, vector<long long> v) {
    sort(v.begin(), v.end());
    vector<double> x(N);
    rep(i, N) {
        x[i] = double(v[i]);
    }

    double tmp_val;
    while (x.size() > 1) {
        tmp_val = x[0] + x[1];
        tmp_val /= 2;
        x.erase(x.begin());
        x.erase(x.begin());
        x.push_back(tmp_val);
        sort(x.begin(), x.end());
    }
    cout << x[0] << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  cin >> N;
  vector<long long> v(N);
  for (int i = 0; i < N; i++) {
    cin >> v[i];
  }
  solve(N, move(v));
  return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int>   PI;
typedef vector<int> VI;
typedef long long int LL;
int main() {
    // your code goes here
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
        long long int n,m,x;
        cin>>n>>m>>x;
        long long int a[n],b[m];
        for(long long int i=0;i<n;i++)
        cin>>a[i];
        for(long long int i=0;i<m;i++)
        cin>>b[i];
        
        long long int k=0,i=0;
        while(i<n && k+a[i]<=x)
        {
            k=k+a[i];
            i++;
        }
        long long int ans=i,j=0;
        
        long long int sum=k;
        while(j<m && i>=0)
        {
            sum=sum+b[j];
            j++;
            while(sum>x && i>0)
            {
                i--;
                sum=sum-a[i];
            }
            if(sum<=x && i+j>ans)
            ans=(i+j);
        }
        cout<<ans<<en;
    
    return 0;
}


Measured memory_bytes: 6788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846



int main(void) {
	
	char S[10];
	scanf("%s", S);
	int count1 = 0;
	int count2 = 0;
	int count3 = 0;
	int a = strlen(S);

	if (S[0] == 'A') {
		count1++;
	}
	
	for (int i = 2; i <a-1 ;i++) {
		if (S[i] == 'C') {
			count2++;
		}
	}

	for (int i = 0; i < a; i++) {
		if (S[i] >= 'A'&&S[i] <= 'Z') {
			count3++;
		}
	}




	if (count1 == 1 && count2 == 1 &&count3==2 ) {
		printf("%s", "AC");
	}
	else {
		printf("%s", "WA");
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44


/*const int MOD = (int) 1e9 + 7;

inline void mod(int &x) {
    if(x >= MOD)
        x -= MOD;
}

inline void add(int &x, int y) {
    x += y;
    mod(x);
}

inline void mul(int &x, int y) {
    x = (1LL * x * y) % MOD;
}*/

using namespace std;



int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    cin >> n;

    vector <int> arr(n);
    map <int, int> fr;

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

    sort(arr.begin(), arr.end());
    arr.resize(unique(arr.begin(), arr.end()) - arr.begin());

    if(n % 3 == 0) {
        if(arr.size() == 1 && arr[0] == 0) {
            cout << "Yes";
            return 0;
        }
        if(arr.size() == 2 && arr[0] == 0 && fr[arr[1]] == 2 * (n / 3)) {
            cout << "Yes";
            return 0;
        }
        if(arr.size() == 3 && (arr[0] ^ arr[1] ^ arr[2]) == 0 && fr[arr[0]] == n / 3 && fr[arr[1]] == n / 3) {
            cout << "Yes";
            return 0;
        }
        cout << "No";
    }
    if(n % 3) {
        if(arr.size() == 1 && arr[0] == 0) {
            cout << "Yes";
        }
        else {
            cout << "No";
        }
        return 0;
    }

    return 0;
}


Measured memory_bytes: 4224
//#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
#define il inline
#define re register
#define pb push_back
#define db double
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define MP make_pair
#define lowbit(x) x&(-x)
#define fi first
#define se second
const int mod = 1e9+7;
il ll read()
{
	char ch = getchar();
	ll p = 1,data = 0;
	while(ch<'0'||ch>'9')
	{
		if(ch == '-')p = -1;
		ch = getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		data = data*10+(ch^48);
		ch = getchar();
	}
	return p*data;
}
il ll qpow(ll a,ll b)
{
	ll r = 1;
	while(b)
	{
		if(b&1)r = a*r;
		a = a*a;
		b>>=1;
	}
	return r;
}
il ll gcd(ll a,ll b)
{
	while(b ^= a ^= b ^= a %= b);
	return a;
}
il ll lcm(ll a,ll b)
{
	return a*b/gcd(a,b);
}
il void exgcd(ll a,ll b,ll &x,ll &y)
{
	if(!b)
	{
		x = 1,y = 0;
		return;
	}
	exgcd(b,a%b,y,x);
	y -= (a/b)*x;
}
il ll inv(ll a,ll p)
{
	return qpow(a,p-2);
}
int main()
{
	ll n = read(),m = read();
	if(n % m == 0)
	{
		puts("0");
		return 0;
	}
	while(n)
	{
		ll t = abs(n-m);
		if(n > t && n > m)
			n %= m;
		else if(n > t)
			n = t;
		else
			break;
	}
	printf("%lld\n",n);
	return 0;
}


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

int main () {
  string N;
  cin >> N;
  int temp = 0;
  for (int i = 0; i < N.size(); i++) {
    temp += (int)N.at(i) - '0';
  }
  if (temp % 9) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return 0;
}

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

const int N = 3e5 + 5;
map<pair<int,int>, int> mpp;
int h, w, m;
int x[N], y[N];

int main() {
	
	cin >> h >> w >> m;
	vector<pair<int,int>> v(m);  
	for(int i=0;i<m;i++)
	{
		cin>>v[i].first>>v[i].second;
		x[v[i].first]++;
		y[v[i].second]++;
		mpp[{v[i].first, v[i].second}]=1;
	}
	
	int ma_x = *max_element(x+1, x+h+1);
	int ma_y = *max_element(y+1, y+w+1);
	
	vector<int>fx,fy;
	for(int i=1;i<=h;i++) if(x[i]==ma_x) fx.push_back(i);
	for(int i=1;i<=w;i++) if(y[i]==ma_y) fy.push_back(i);
	
	int ans=0;
	for(int i:fx)
	{
		for(int j:fy)
		{
			int z=0;
			if(mpp[{i,j}]) z=1;
			ans=max(ans, x[i]+y[j]-z);
			if(z==0)
			{
				cout<<ans;
				return 0;
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 30832
class Entry
  attr_reader :prefix, :value

  def initialize(prefix, value)
    @prefix = prefix
    @value = value
  end
end

class PrefixQueue
  def initialize
    @list = []
  end

  def empty?
    @list.empty?
  end

  def shift
    result = @list.shift
    @list.first.prefix.insert(0, result.prefix) unless @list.empty?
    [result.prefix, result.value]
  end

  def push(key, value)
    key = key.dup
    (0...@list.size).each do |i|
      prefix = @list[i].prefix
      case prefix <=> key
      when -1
        return nil unless key.start_with?(prefix)
        key.slice!(0, prefix.size)
      when 0
        return @list[i].value
      else
        if prefix.start_with?(key)
          prefix.slice!(0, key.size)
          @list.insert(i, nil)
        else
          @list.slice!(i+1..-1)
        end
        @list[i] = Entry.new(key, value)
        return value
      end
    end
    @list << Entry.new(key, value)
    return value
  end
end

class Arrow
  attr_reader :source, :sink, :label

  def initialize(source, sink, label)
    @source = source
    @sink = sink
    @label = label
  end
end

def collect(n, arrows, goal)
  come_from = Array.new(n){[]}
  arrows.each do |arrow|
    come_from[arrow.sink] << arrow.source
  end

  reachable_from = [false] * n
  stack = [goal]
  until stack.empty?
    node = stack.pop
    reachable_from[node] = true
    come_from[node].each do |source|
      stack << source unless reachable_from[source]
    end
  end
  reachable_from
end

def work(n, arrows, start, goal)
  reachable_from = collect(n, arrows, goal)
  return nil unless reachable_from[start]

  go = Array.new(n){[]}
  arrows.each do |arrow|
    go[arrow.source] << arrow if reachable_from[arrow.sink]
  end

  queue = PrefixQueue.new
  queue.push('', {start => true})
  until queue.empty?
    spell, map = queue.shift
    return spell if map[goal]

    return nil if spell.size > 500

    map.each do |node, tainted|
      go[node].each do |arrow|
        t = queue.push(spell + arrow.label, {})
        t[arrow.sink] = true if t
      end
    end
  end
  nil
end

loop do
  n, a, s, g = gets.split.map(&:to_i)
  break if n == 0

  arrows = (0...a).map do |i|
    x, y, lab = gets.split
    Arrow.new(x.to_i, y.to_i, lab)
  end

  puts work(n, arrows, s, g) || 'NO'
end

Measured memory_bytes: 10576
import sys
import math
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
N,X,T=MAP()
if N%X==0:
  print((N//X)*T)
else:
  print(((N//X)+1)*T)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define ref(i,n) for (ll i=0;i<n;i++)
 
 
using namespace std;
typedef long long ll;
 
ll n,a,b,c,d;
map<ll,ll> mp;
 
ll dfs(ll x){
    if(x==0) return 0;
 
    if(mp.find(x)!=mp.end()) return mp[x];
    ll a2=2,a3=3,a5=5,a1=1,a4=4;
 
    ll k=dfs(x/a2)+a+x%a2*d;
    if((x+a1)/a2<x) k=min(k,dfs((x+a1)/a2)+a+x%a2*d);
    ll j=dfs(x/a3)+b+x%a3*d;
    if((x+a2)/a3<x)j=min(j,dfs((x+a2)/a3)+b+(a2-(x+a2)%a3)*d);
    ll q=dfs(x/a5)+c+x%a5*d;
    if((x+a4)/a5<x) q=min(q,dfs((x+a4)/a5)+c+(a4-(x+a4)%a5)*d);
    ll h;
    if(k/x<d) h=k; else h=x*d;
    h=min(h,j);
    h=min(h,q);
    mp[x]=h;
 
    if(h<0) cout<<"ERR";
    return mp[x];
}
 
int main()
{
    cin>>n;
    ref(i,n){
        ll f;
        cin>>f>>a>>b>>c>>d;
        cout<<dfs(f)<<endl;
        mp.clear();
        }
 
 
    return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int main() {

    int n, m;

    cin >> n >> m;

    vector<vector<int>> switches(m, vector<int>());

    for(int i = 0; i < m; ++i) {
        int k;
        cin >> k;

        for(int j = 0; j < k; ++j) {
            int num;
            cin >> num;
            switches[i].push_back(num - 1);
        }
    }

    vector<int> lights(m);
    for(int i = 0; i < m; ++i) {

        cin >> lights[i];
    }

    int ans = 0;

    int maxN = 1 << n;

    for(int bit = 0; bit < maxN; ++bit) {

        int i;
        for(i = 0; i < m; ++i) {
            int count = 0;
            for(int j = 0; j < switches[i].size(); ++j) {

                int b = 1 << switches[i][j];
                if(bit & b)
                    count++;
            }

            if(count % 2 != lights[i])
                break;
        }

        if(i == m)
            ans++;
            
    }


    cout << ans << endl;
    return 0;

}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;
  cin >> n;
  cout << n*(n-1)/2LL << endl;
  return 0;
}


Measured memory_bytes: 256
#ifdef ConanYu
#include "E:\yuzining\code\local.hpp"
#else
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define debug(...) do { } while(false)
void Main();
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie();
  Main();
  return 0;
}
#endif

int a[3][4005];
char s[4005];
void Main() {
  int n; cin >> n;
  cin >> (s + 1);
  for(int i = 1; i <= n; i++) {
    if(s[i] == 'R') s[i] = '0';
    else if(s[i] == 'G') s[i] = '1';
    else s[i] = '2';
  }
  for(int i = 1; i <= n; i++) {
    for(int j = 0; j < 3; j++) a[j][i] = a[j][i - 1];
    a[int(s[i] - '0')][i]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    for(int j = i + 1; j <= n; j++) {
      if(s[i] == s[j]) continue;
      for(int k = 0; k < 3; k++) {
        if(s[i] == '0' + k || s[j] == '0' + k) continue;
        ans += a[k][n] - a[k][j];
        if(j + j - i <= n && s[j + j - i] == '0' + k) ans--;
      }
    }
  }
  cout << ans << '\n';
}

Measured memory_bytes: 3668
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;

class Myon
{
    static Scanner cin;
    public Myon() { }
    public static int Main()
    {
        //Console.SetOut(new Printer(Console.OpenStandardOutput()));
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }


    public void calc()
    {
        string S = cin.next();
        bool A = (S[0] == S[S.Length - 1]);
        bool B = (S.Length % 2 == 1);
        if (A ^ B) Console.WriteLine("First");
        else Console.WriteLine("Second");
    }
}

class Printer : StreamWriter
{
    public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
    public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { }
    public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { }
}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        while (i >= s.Length)
        {
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
        }
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

}

Measured memory_bytes: 3416
# from math import factorial,sqrt
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import scipy as scp

# 入力の受け取り
a,b,t = map(int,input().split())

ans = t//a * b

print(ans)
# print("{:.10f}".format(ans))
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する



Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;
const ll INF = 1LL << 60;
#define MOD 1000000007
#define MAX_V 100010
#define MAX_N 100010

bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}

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

ll junnretu(ll n){
    ll ans=1;
    for (ll i=1;i<=n;i++){
        ans*=i;
    }
    return ans;
}

int main(){
    ll n,ans=INF;
    cin >> n;
    ll x[n];
    for (ll i=0;i<n;i++)cin >> x[i];
    for (ll i=-100;i<=100;i++){
        ll count=0;
        for (ll j=0;j<n;j++){
            count+=(i-x[j])*(i-x[j]);
        }
        ans=min(ans,count);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
ll const INF = 1LL << 60;

int main() {
    ll N;
    ll x[100];
    cin >> N;

    rep(i, N) cin >> x[i];

    ll sqsum_min = INF;

    for (int p = 1; p <= 100; p++) {
        ll sqsum = 0;
        for (int i = 0; i < N; i++) {
            sqsum += (x[i] - p) * (x[i] - p);
        }

        if (sqsum_min > sqsum) {
            sqsum_min = sqsum;
        }
    }

    cout << sqsum_min << endl;
    return 0;
}

Measured memory_bytes: 256
"use strict";
(function(input){
  input=input.trim();
  input=input.split(/\n/).map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0],
        D=input[0][1];
  let ans=0;
  for(let i=1;i<=N;i++){
    for(let j=i+1;j<=N;j++){
      let dsquare=0,d=0;
      for(let k=0;k<D;k++){
        dsquare+=(input[i][k]-input[j][k])*(input[i][k]-input[j][k]);
      }
      d=Math.sqrt(dsquare);
      if(Math.abs(d-Math.round(d))<0.00000001)
        ans++;
    }
  }
  console.log(ans);
})(require("fs").readFileSync("/dev/stdin","utf8"));


Measured memory_bytes: 21064
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=100,MAXW=100;

int h,w;
int a[MAXH][MAXW];
int b[MAXH][MAXW];
int c[MAXH][MAXW];

vector<int> vals[MAXH][MAXH];

bool can[MAXH][MAXH];

int lmatch[MAXH],rmatch[MAXH];
bool ldone[MAXH];

bool augment(int x) {
	if(ldone[x]) return false; else ldone[x]=true;
	REP(xx,h) if(can[x][xx]&&(rmatch[xx]==-1||augment(rmatch[xx]))) { rmatch[xx]=x,lmatch[x]=xx; return true; }
	return false;
}

int maxmatch() {
	REP(x,h) lmatch[x]=rmatch[x]=-1,ldone[x]=false;
	int ret=0; REP(x,h) if(augment(x)) { ++ret; REP(xx,h) ldone[xx]=false; }
	return ret;
}


void solve() {
	REP(x,h) REP(xx,h) vals[x][xx].clear();
	REP(x,h) REP(y,w) vals[x][a[x][y]/w].PB(a[x][y]);
	REP(y,w) {
		REP(x,h) REP(xx,h) can[x][xx]=SZ(vals[x][xx])>0;
		//printf("can:\n"); REP(x,h) { REP(xx,h) printf("%c",can[x][xx]?'V':'.'); puts(""); }
		assert(maxmatch()==h);
		REP(x,h) { int xx=lmatch[x]; assert(xx!=-1&&SZ(vals[x][xx])!=0); int v=vals[x][xx].back(); vals[x][xx].pop_back(); b[x][y]=v; c[xx][y]=v; }
	}

}

void run() {
	scanf("%d%d",&h,&w);
	REP(x,h) REP(y,w) scanf("%d",&a[x][y]),--a[x][y];
	solve();
	REP(x,h) { REP(y,w) { if(y!=0) printf(" "); printf("%d",b[x][y]+1); } puts(""); }
	REP(x,h) { REP(y,w) { if(y!=0) printf(" "); printf("%d",c[x][y]+1); } puts(""); }
}

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


Measured memory_bytes: 1024
n,q=map(int,raw_input().split())

lst = []
for idx in xrange(n):
    name, time = raw_input().split()
    lst.append([name, int(time)])

idx = 0
tot = 0
while True:
  lst[idx][1] = lst[idx][1] - q
  if lst[idx][1] <= 0:
    tot += q + lst[idx][1]
    lst[idx][1] = 0
    print "%s %d" % (lst[idx][0], tot)
    lst.pop(idx)
    if len(lst)==0:
        break
  else:
    tot += q
    idx+=1
  if (idx >= len(lst)):
    idx = 0

Measured memory_bytes: 13936
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pb push_back
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	ll a,b,c;
	cin>>a>>b>>c;
	if(a>=c){
		cout<<a-c<<" "<<b;
		return 0;
	}
	if(a+b<=c){
		cout<<0<<" "<<0;
	}
	else{
		c-=a;
		a=0;
		cout<<a<<" "<<b-c;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

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

istream& operator>>(istream& istr, __float128& obj) { double d; istr >> d; obj = d; return istr; };
ostream& operator<<(ostream& ostr, __float128& obj) { ostr << static_cast<double>(obj); return ostr; };

ll dp[2][100100];

int main() {
	ll N;
	cin >> N;
	vector<ll> a(N*3);
	rep(i,N*3) cin >> a[i];
	priority_queue<ll,vector<ll>,std::greater<ll> > qa;
	priority_queue<ll> qb;

	ll sum = 0;
	rep(i,N) {
		sum += a[i];
		qa.push(a[i]);
	}
	dp[0][0] = sum;
	rep(i,N) {
		qa.push(a[i+N]);
		sum += a[i+N];
		sum -= qa.top();
		qa.pop();
		dp[0][i+1] = sum;
	}

	sum = 0;
	rep(i,N) {
		sum += a[N*2+i];
		qb.push(a[N*2+i]);
	}
	dp[1][N] = sum;
	rrep(i,N) {
		qb.push(a[i+N]);
		sum += a[i+N];
		sum -= qb.top();
		qb.pop();
		dp[1][i] = sum;
	}
	ll res = -1e15;
	rep(i,N+1) {
		res = max(res, dp[0][i] - dp[1][i]);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 5876
#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>;

const int INF = 1001001001;

int a[12][12];

int main() {
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  rep(i,n) {
    cin >> c[i];
    rep(j,m) cin >> a[i][j];
  }

  int ans = INF;
  rep(s,1<<n) {
    int cost = 0;
    vector<int> d(m);
    rep(i,n) {
      if (s>>i&1) {
        cost += c[i];
        rep(j,m) d[j] += a[i][j];
      }
    }
    bool ok = true;
    rep(j,m) if (d[j] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) cout << -1 << endl;
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int a,b,c,i,j,k;
string str;
int main(){
	cin>>str;
	i=0;
	str+='*';
	while(i!=str.length()-1){
		if(str.substr(i,7)=="dreamer" && str[i+7]!='a'){
			i+=7;
		}else if(str.substr(i,5)=="dream"){
			i+=5;
		}else if(str.substr(i,6)=="eraser"&&str[i+7]!='a'){
			i+=6;
		}else if(str.substr(i,5)=="erase"){
			i+=5;
		}else{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
	return 0;
}

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


int main() {
  int h, w, n;
  cin >> h >> w >> n;
  deque<int> a;
  rep(i,n) {
    int x;
    cin >> x;
    rep(j,x) a.push_back(i+1);
  }
  int R=1;
  rep(i,h) {
    if(R==1) {
      for(int j=i*w; j<(i+1)*w; j++) {
        cout << a[j] << " ";
      }
    }
    else {
      for(int j=(i+1)*w-1; j>=i*w; j--) {
        cout << a[j] << " ";
      }
    }
    cout << endl;
    R*=-1;
  }
  return 0;
}

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

vector <vector <long long>> dp[4];
int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, 1, -1, 0};
vector <string> M;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int H, W;
	cin >> H >> W;
	for (int i = 0; i < 4; i++){
		dp[i].resize(H);
		for (int j = 0; j < H; j++){
			dp[i][j].resize(W);
		}
	}
	M.resize(H);
	for (int i = 0; i < H; i++){
		cin >> M[i];
	}
	for (int k = 0; k < 4; k++){
		if (dx[k] == -1){
			for (int i = 0; i < H; i++){
				for (int j = 0; j < W; j++){
					int x = i + dx[k], y = j + dy[k];
					if (x != H && x != -1 && y != W && y != -1 && M[i][j] == '.'){
						dp[k][i][j] = dp[k][x][y] + 1;
					}
					else if (M[i][j] == '.'){
						dp[k][i][j] = 1;
					}
				}
			}
		}
		else{
			if (dy[k] == -1)
				for (int i = 0; i < H; i++){
					for (int j = 0; j < W; j++){
						int x = i + dx[k], y = j + dy[k];
						if (x != H && x != -1 && y != W && y != -1 && M[i][j] == '.'){
							dp[k][i][j] = dp[k][x][y] + 1;
						}
						else if (M[i][j] == '.'){
							dp[k][i][j] = 1;
						}
					}
				}
			else{
				for (int i = H - 1; i >= 0; i--){
					for (int j = W - 1; j >= 0; j--){
						int x = i + dx[k], y = j + dy[k];
						if (x != H && x != -1 && y != W && y != -1 && M[i][j] == '.'){
							dp[k][i][j] = dp[k][x][y] + 1;
						}
						else if (M[i][j] == '.'){
							dp[k][i][j] = 1;
						}
					}
				}
			}
		}
	}
	long long ans = 0;
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			// cout << i << ' ' << j << ' ' << dp[0][i][j] + dp[1][i][j] + dp[2][i][j] + dp[3][i][j] - 3 << '\n';
			ans = max(ans, dp[0][i][j] + dp[1][i][j] + dp[2][i][j] + dp[3][i][j] - 3);
		}
	}	
	cout << ans;
}

Measured memory_bytes: 129792
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

string pred[3] = {"Sunny", "Cloudy", "Rainy"};

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

	string s;
	cin >> s;
	for (int i = 0; i < 3; i++) {
		if (s == pred[i]) {
			cout << pred[(i+1)%3] << endl;
			return 0;
		}
	}
	assert(false);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n, s[101], s2[101], i, j, min, sum2;
  int sum=0, count=0;

  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%d", &s[i]);
    s2[i]=s[i];
    sum+=s[i];

    if(s[i]%10!=0)
    count=1;
  }

  sum2=sum;

  if(sum%10!=0)
  printf("%d\n", sum);

  else{
  while(sum%10==0){
    min=101;

  for(i=0;i<n;i++){
    if(min>s[i]&&s[i]!=0){
    min=s[i];
    j=i;
  }
  }

  sum-=min;
  s[j]=0;

  if(sum==0)
  break;
}

  if(sum2%10==0){
    min=101;

  if(count==1){
    while(1){
    for(i=0;i<n;i++){
      if(s2[i]%10!=0&&s2[i]<min){
        min=s2[i];
        j=i;
      }
    }

    sum2-=min;
    break;
  }
}
else{
  sum2=0;
}
}

  if(sum>=sum2)
  printf("%d\n", sum);
  else
  printf("%d\n", sum2);
}
  return 0;
}


Measured memory_bytes: 128
#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, M;
  std::cin >> N >> M;
  std::cout << N * (N - 1) / 2 + M * (M - 1) / 2 << std::endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())-1
y = 26
idx = []

c = [chr(i + ord("a")) for i in range(26)]

while True:
    idx.append(n % y)
    n //= y
    if n <= 0:
        break
    n -= 1

idx.reverse()
ans = []
for i in idx:
    ans.append(c[i])
print("".join(ans))


Measured memory_bytes: 9156
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>

using namespace std;

bool comp(const pair<int, int> x, const pair<int, int> y) {
    return x.second > y.second;
}

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

    // (number, count)
    // number: 1 to n
    // count: count the number appears in A_i
    map<int, int> as;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        auto it = as.find(x);
        if (it == as.end()) {
            as[x] = 1;
        } else {
            as[x] = as.at(x) + 1;
        }
    }

    // sort as
    vector<pair<int, int>> bs;
    for (auto p : as) {
        bs.push_back(p);
    }

    sort(bs.begin(), bs.end(), comp);

    // ds[0] means the size of numbers which appears once in A_i.
    // ds[1] means ...                               twice in A_i.
    // ...
    vector<int> ds(n, 0);
    for (auto p : as) {
        ds[p.second-1]++;
    }

    // cout << "[ds]" << endl;
    // for (size_t i = 0; i < ds.size(); i++) {
    //     cout << i+1 << ":" << ds[i] << endl;
    // }
    // cout << endl;

    // calculate f(x) (see answer pdf)
    vector<int> fs(n);
    int m = bs.size(); // how many distinct numbers are in A_i
    int g = m;
    fs[0] = g / 1; // f(1)
    int acc = ds[0];
    for (int i = 1; i < n; i++) {
        g += (m - acc);
        fs[i] = g / (i+1);
        acc += ds[i];
    }

    // cout << "[fs]" << endl;
    // for (size_t i = 0; i < fs.size(); i++) {
    //     cout << i+1 << ":" << fs[i] << endl;
    // }
    // cout << endl;

    for (int k = 1; k <= n; k++) {
        int s = 0, e = n-1, mid, prev = -1;
        while (e - s >= 0) {
            mid = (s + e) / 2;
            if (fs[mid] >= k) {
                s = mid+1;
                prev = mid;
            } else {
                e = mid-1;
            }
        }
        if (prev < 0) {
            cout << 0 << endl;
        } else {
            cout << prev+1 << endl;
        }
    }

    return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,m; cin>>a>>b>>m;
	vector<int>aa(a); for(auto&&i:aa)cin>>i;
	vector<int>bb(b); for(auto&&i:bb)cin>>i;
	int ans=*min_element(aa.begin(),aa.end())+*min_element(bb.begin(),bb.end());
	for(int i=0;i<m;++i){
		int x,y,c; cin>>x>>y>>c;
		ans=min(ans,aa.at(x-1)+bb.at(y-1)-c);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 1024
H,W,K = map(int,input().split())

S = [input() for _ in range(H)]

ans = 10**10
for i in range(2**(H-1)):   # iはbit
    rel = [0 for h in range(H)]
    a,b = 0,0
    for h in range(H-1):
        if i>>h&1:
            b += 1
        rel[h+1] = b

    a += b

    cnt = [0 for j in range(b+1)]
    for w in range(W):
        for h in range(H):
            if S[h][w] == '1':
                cnt[rel[h]] += 1
        
        OK = True
        for j in range(b+1):
            if cnt[j] > K:
                OK = False
                break
        
        if OK:
            continue

        a += 1
        cnt = [0 for j in range(b+1)]
        for h in range(H):
            if S[h][w] == '1':
                cnt[rel[h]] += 1

        OK2 = True
        for j in range(b+1):
            if cnt[j] > K:
                OK2 = False
                break
        
        if OK2:
            continue
        a = 10**10
        break
    ans = min(ans,a)
print(ans)



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

int main(){
    long long int x;
    cin >> x;
    long long int num=100;

    int cnt=0;
    for(int i=0; i<1000000000; i++){
        num = num * 1.01;
        cnt++;
        if(num>=x) break;
    } 
    cout << cnt << endl;
}

Measured memory_bytes: 3632
//INCLUDE
//------------------------------------------
#include <iostream>
#include <algorithm>
#include <vector>
//DEFINE
//------------------------------------------
#define ll long long
#define ALLv(a)  (a).begin(),(a).end()
#define vi vector<long long>
//REPEAT
//------------------------------------------
#define REP(i,n) for(ll(i)=0;(i)<(n);(i)++)
#define REPS(i,x) for(ll(i)=1;(i)<=(x);(i)++)
#define WREP(i,in,j,jn) REP(i,in)REP(j,jn)
using namespace std;
//-------------------------------------------
void solve(ll N,ll M){
  vi p(N+1);p[0]=0;REPS(i,N)cin>>p[i];
  vi pp;WREP(i,N+1,j,N+1)pp.push_back(p[i]+p[j]);
  sort(ALLv(pp));
  ll ans=0;
  REP(i,pp.size()){
    ll idx=upper_bound(ALLv(pp),M-pp[i])-pp.begin()-1;
    if(idx<0)continue;
    ans=max(ans,pp[i]+pp[idx]);
  }
  cout<<ans<<"\n";
}
int main(void){
  ll N,M;
  while(cin>>N&&cin>>M){
  	if(N==0&&M==0)break;
    solve(N,M);
  }
}



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

typedef long long ll;

int main()
{
    ll i,j;
    int h,w;
    cin >> h >> w;
    vector<string> m(h);
    for(i = 0;i < h;++i){
        cin >> m.at(i);
    }
    vector<vector<int>> dp(h,vector<int>(w,0));
    for(i = 0;i < h;++i){
        for(j = 0;j < w;++j){
            if(i == 0 && j == 0){
                if(m.at(i).at(j) == '#'){
                    dp.at(i).at(j) = 1;
                }
            }else if(i == 0){
                if(m.at(i).at(j-1) == '#'){
                    dp.at(i).at(j) = dp.at(i).at(j-1);
                }else{
                    if(m.at(i).at(j) == '#'){
                        dp.at(i).at(j) = dp.at(i).at(j-1) + 1;
                    }else{
                        dp.at(i).at(j) = dp.at(i).at(j-1);
                    }
                }
            }else if(j == 0){
                if(m.at(i-1).at(j) == '#'){
                    dp.at(i).at(j) = dp.at(i-1).at(j);
                }else{
                    if(m.at(i).at(j) == '#'){
                        dp.at(i).at(j) = dp.at(i-1).at(j) + 1;
                    }else{
                        dp.at(i).at(j) = dp.at(i-1).at(j);
                    }
                }
            }else{
                int tmp1,tmp2;
                if(m.at(i).at(j-1) == '#'){
                    tmp1 = dp.at(i).at(j-1);
                }else{
                    if(m.at(i).at(j) == '#'){
                        tmp1 = dp.at(i).at(j-1) + 1;
                    }else{
                        tmp1 = dp.at(i).at(j-1);
                    }
                }
                if(m.at(i-1).at(j) == '#'){
                    tmp2 = dp.at(i-1).at(j);
                }else{
                    if(m.at(i).at(j) == '#'){
                        tmp2 = dp.at(i-1).at(j) + 1;
                    }else{
                        tmp2 = dp.at(i-1).at(j);
                    }
                }
                dp.at(i).at(j) = min(tmp1,tmp2);
            }
        }
    }
    cout << dp.at(h-1).at(w-1) << endl;
    return 0;
}

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

using namespace std;
using ll=long long;

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  int n;
  cin>>n;
  int a=1,b=n-1,cnt=0;
  while(a<b){
      cnt++;
      a++;
      b--;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Cmondai
{
    static void Main()
    {
        var hw = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var H = hw[0];
        var W = hw[1];
        var array = new int[H,W];
        for (int i=0;i<H;++i)
        {
            var line = Console.ReadLine();
            for (int j=0;j<W;++j)
            {
                array[i, j] = line[j];
            }
        }
        var disable = false;
        for (int i=0;i<H;++i)
        {
            for (int j=0;j<W;++j)
            {
                if(array[i,j]== '#')
                {
                    if ((i != 0 && array[i - 1, j] == '#')
                        || (i != H - 1 && array[i + 1, j] == '#')
                        || (j != 0 && array[i, j - 1] == '#')
                        || (j != W - 1 && array[i, j + 1] == '#')) ;
                    else
                    {
                        disable = true;
                        break;
                    }
                }
            }
            if (disable) break;
        }
        Console.WriteLine(disable?"No":"Yes");
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin>>n;
  vector<int> v(n);
  for(int i=0;i<n;i++)cin>>v[i];
  cout<<accumulate(v.begin(),v.end(),0)-*max_element(v.begin(),v.end())/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main()
{
    int a, b, t;
    int sum = 0;
    scanf("%d %d %d", &a, &b, &t);
    for (; t >= a;)
    {
        t = t - a;
        sum = sum + b;
    }
    printf("%d\n", sum);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

class SegTree { // index starts at 0.
public:
  int N;
  int* dat;
  static int INFTY; // (1 << 31) - 1;
  
  SegTree(int n) {
    N = 1;
    while (N < n) N *= 2;
    dat = new int[2 * N - 1];
    for (auto i = 0; i < 2 * N - 1; ++i) {
      dat[i] = INFTY;
    }
  }

  ~SegTree() {
    delete[] dat;
  }

  void update(int k, int a) {
    k += N - 1;
    dat[k] = a;
    while (k > 0) {
      k = (k - 1)/2;
      dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
  }

  int find(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return INFTY;
    if (a <= l && r <= b) return dat[k];
    int vl = find(a, b, k * 2 + 1, l, (l + r) / 2);
    int vr = find(a, b, k * 2 + 2, (l + r) / 2, r);
    return min(vl, vr);
  }

  int find(int a, int b) {
    return find(a, b, 0, 0, N);
  }
  
};

int SegTree::INFTY = 2147483647; // (1 << 31) - 1;

int N;
int b[200020];
int Q;
vector<int> V[200020];

int score(int x) {
  if (b[x] == 0) return -1;
  return 1;
}

int main () {
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    cin >> b[i];
  }
  cin >> Q;
  for (auto i = 0; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    V[l].push_back(r);
  }
  for (auto i = 0; i < N; ++i) {
    sort(V[i].begin(), V[i].end());
  }
  int zeros = 0;
  for (auto i = 0; i < N; ++i) {
    if (b[i] == 0) ++zeros;
  }
  SegTree S(N+1);
  S.update(0, zeros);
  for (auto i = 0; i < N; ++i) {
    for (auto x : V[i]) {
      S.update(x+1, S.find(i, x+2));
    }
    S.update(i+1, min(S.find(i, i+1) + score(i), S.find(i+1, i+2)));
    // cerr << "DP[" << i+1 << "] = " << S.find(i+1, i+2) << endl;
  }
  cout << S.find(N, N+1) << endl;
}


Measured memory_bytes: 11776