akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
    float d,t,s;
    cin>>d>>t>>s;
    if(d==0 || t==0 || s==0)
    {
        cout<<"No"<<endl;
    }
    if ((d/s)<=t)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

Measured memory_bytes: 3716
#include <stdio.h>


int main()
{
	int a[101][101], b[101], c[101];
	int i, j;
	int n, m;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (j = 0; j < m; j++) scanf("%d", &b[j]);

	for (i = 0; i < n; i++) {
		c[i] = 0;
		for (j = 0; j < m; j++) c[i] += a[i][j] * b[j];
	}

	for (i = 0; i < n; i++) {
		printf("%d\n", c[i]);
	}
	return 0;
}






Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define maxN 1000000
int n,A[maxN],B[maxN],C[maxN],f1[maxN],f2[maxN],f3[maxN],Res;
signed main()
{
    ios_base::sync_with_stdio(false);
    
    cin>>n;
    for (int i=1;i<=n;i++) cin>>A[i]>>B[i]>>C[i];
    f1[0]=0; f2[0]=0; f3[0]=0;
    for (int i=1;i<=n;i++)
    {
        f1[i]=max(f2[i-1],f3[i-1])+A[i];
        f2[i]=max(f1[i-1],f3[i-1])+B[i];
        f3[i]=max(f2[i-1],f1[i-1])+C[i];
        Res=max(max(f2[i],f3[i]),max(Res,f1[i]));
    }
    cout<<Res;
}


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

int const N = 5000, md = 1e9 + 7;
int dp[2][N + 1][N + 1], s[2][N + 1][N + 1], p2[N + 1];

void ad(int &x, int y) { if ((x += y) >= md)x -= md; }

int gt(int tp, int a, int b) { return b >= 0 ? s[tp][a][b] : 0; }

int sm(int tp, int a, int b, int l, int r){
	int an = gt(tp, a - l, b - l) - gt(tp, a - r - 1, b - r - 1);
	ad(an, md);
	return an;
}

int main(){
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	p2[0] = 1;
	f(i, 1, n + 1)ad(p2[i] = p2[i - 1], p2[i - 1]);
	if (a < b)swap(a, b);
	
	f(tp, 0, 2)dp[tp][0][0] = s[tp][0][0] = 1;
	f(i, 1, n + 1)f(j, 0, i + 1)f(tp, 0, 2){
		if (j < a){
			if (tp == 0)dp[tp][i][j] = sm(1, i, j, 1, j);
			else {
				dp[tp][i][j] = sm(0, i, j, min(j + 1, b), j);
				if (j == 0)f(k, 0, i + 1)ad(dp[tp][i][j], sm(0, i, k, 1, min(b - 1, k)));
			}
		}
		ad(s[tp][i][j] = dp[tp][i][j], j == 0 ? 0 : s[tp][i - 1][j - 1]);
	}
	int an = 0;
	f(i, 0, 2)f(j, 0, a)ad(an, dp[i][n][j]);
	an = p2[n] - an;
	ad(an, md);
	printf("%d\n", an);
}

Measured memory_bytes: 270912
#include<bits/stdc++.h>
#define read() Read<int>()
namespace pb_ds{   
    namespace io{
        const int MaxBuff=1<<15;
        const int Output=1<<23;
        char B[MaxBuff],*S=B,*T=B;
		#define getc() ((S==T)&&(T=(S=B)+fread(B,1,MaxBuff,stdin),S==T)?0:*S++)
        char Out[Output],*iter=Out;
        inline void flush(){
            fwrite(Out,1,iter-Out,stdout);
            iter=Out;
        }
    }
    template<class Type> inline Type Read(){
        using namespace io;
        register char ch;
        register Type ans=0; 
        register bool neg=0;
        while(ch=getc(),(ch<'0' || ch>'9') && ch!='-');
        ch=='-'?neg=1:ans=ch-'0';
        while(ch=getc(),'0'<= ch && ch<='9') ans=ans*10+ch-'0';
        return neg?-ans:ans;
    }
    template<class Type> inline void Print(register Type x,register char ch='\n'){
        using namespace io;
        if(!x) *iter++='0';
        else{
            if(x<0) *iter++='-',x=-x;
            static int s[100]; 
            register int t=0;
            while(x) s[++t]=x%10,x/=10;
            while(t) *iter++='0'+s[t--];
        }
        *iter++=ch;
    }
}
using namespace pb_ds;
using namespace std;
typedef long long ll;
const int N=(1<<21)+5;
int n,V,tot,now,all;
int a[N],f[N],g[N];
int l[20][N],r[20][N];
int mx[N],vis[N];
inline void work(int x){
	l[tot][1]=now=1;
	for (int i=2;i<=n;++i){
		if (a[i]-a[i-1]>x)
			l[tot][i]=now=i;
		else l[tot][i]=now;
	}
	r[tot][n]=now=n;
	for (int i=n-1;i;--i){
		if (a[i+1]-a[i]>x)
			r[tot][i]=now=i;
		else r[tot][i]=now;
	}
}
int main(){
	//freopen("d.in","r",stdin);
	//freopen("d.out","w",stdout);
	n=read(),V=read();
	for (int i=1;i<=n;++i) a[i]=read();
	while (V) ++tot,work(V),V>>=1; 
	++tot,work(V);
	all=(1<<tot)-1;
	for (int i=0;i<=all;++i)
		f[i]=0,g[i]=n+1;
	for (int i=0;i<all;++i){
		for (int j=2;j<=tot;++j){
			if (i&(1<<(j-1))) continue;
			f[i|(1<<(j-1))]=max(f[i|(1<<(j-1))],r[j][min(f[i]+1,n)]);
			g[i|(1<<(j-1))]=min(g[i|(1<<(j-1))],l[j][max(g[i]-1,1)]);
		}
	}
	for (int i=0;i<=n;++i) mx[i]=n+1;
	for (int i=0;i<=all;++i)
		mx[f[i]]=min(mx[f[i]],g[all^i]),vis[f[i]]=1;
	for (int i=n-1;~i;--i)
		f[i]=min(f[i],f[i+1]),vis[i]|=vis[i+1];
	for (int i=1;i<=n;++i){
		int L=l[1][i]-1,R=r[1][i]+1;
		if (vis[L] && mx[L]<=R) puts("Possible");
		else puts("Impossible");
	}
	return 0;
}

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

int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-b)<=d&&abs(b-c)<=d){
    cout<<"Yes"<<endl;
  }else if(abs(a-c)<=d){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n,m;
bool G[8][8];
int ans = 0;
bool reached[8];

void DFS(int v, int cnt){
    if(cnt == n){
        ans++;
        return;
    }
    reached[v] = true;
    REP(i,n){
        if(reached[i] == false && G[v][i] == true) DFS(i,cnt + 1);
    }
    reached[v] = false;
    return;
}

signed main(){
    cin >> n >> m;
    int a,b;
    REP(i,m){
        cin >> a >> b;
        a--;
        b--;
        G[a][b] = true;
        G[b][a] = true;
    }
    DFS(0,1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, k; cin >> n >> k;
  int t = n / k;
  int ans = n - t * k;
  cout << min(ans, abs(ans - k)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	for(int i=0;i<3;i++){
		int ih,im,is,oh,om,os;
		cin>>ih>>im>>is>>oh>>om>>os;
		int t=3600*(oh-ih)+60*(om-im)+(os-is);
		cout<<t/3600<<' '<<t%3600/60<<' '<<t%60<<endl;
	}
}



Measured memory_bytes: 3096
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int max_profit(vector<int> &price)
{	
	int profit;
	long long int max = -999999999;
	int min = 1;
	for(int i = 1; i <= price.size() - 1; i++){
		
		if(i == 1){
			min = price[0];
		}
		else if(min >= price[i - 1]){
			min = price[i - 1];
		}
		
		profit = price[i] - min;
		
		if(max < profit){
			max = profit;
		}
	}
	return max;
}
int main(void)
{
	int n;
	cin >> n;
	
	vector<int> price(n);
	
	for(int i = 0; i < n; i++){
	
		cin >> price[i];
	}
	
	int max = max_profit(price);
	
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;
    for(int i=0;i<n/4+1;i++)
        for(int j=0;j<n/7+1;j++){
            if(n==4*i+7*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner fs = new FastScanner(System.in);
        long x = Math.abs(fs.nextLong());
        long k = fs.nextLong();
        long d = fs.nextLong();
        long threashold = Math.floorDiv(x, d);
        long ans;
        if (k%2 == threashold%2) {
            if (k >= threashold) ans = Math.abs(x - d*threashold);
            else ans = x - d*k;
        } else {
            if (k >= threashold) ans = Math.abs(x - d*(threashold+1));
            else ans = x - d*k;
        }
        System.out.println(ans);
    }
    
    static class FastScanner {
        StringTokenizer st;
        BufferedReader br;

        public FastScanner(InputStream system) {
            br  = new BufferedReader(new InputStreamReader(system));
        }

        public FastScanner(File file) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(file));
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public String nextLine() throws IOException { return br.readLine(); }
        public int nextInt() throws IOException { return Integer.parseInt(next()); }
        public long nextLong() throws IOException { return Long.parseLong(next()); }
        public double nextDouble() throws IOException { return Double.parseDouble(next()); }
        public char nextChar() throws IOException { return next().charAt(0); }
        public int[] nextArrInt(int n) throws IOException {
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = nextInt();
            return a;
        }
        public long[] nextArrLong(int n) throws IOException {
            long[] a = new long[n];
            for (int i = 0; i < n; i++) a[i] = nextLong();
            return a;
        }
        public double[] nextArrDouble(int n) throws IOException {
            double[] a = new double[n];
            for (int i = 0; i < n; i++) a[i] = nextDouble();
            return a;
        }
        public boolean ready() throws IOException { return br.ready(); }
        public void waitForInput() throws InterruptedException  { Thread.sleep(3000); }
    }
}

Measured memory_bytes: 32716
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int inf = 1000000007;

int a[maxn];
int n,m;

int main() {
 // freopen("in.cpp","r",stdin);
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int x,y;
    cin>>x>>y;
    if(x>y)swap(x,y);
    if(x==1)a[y]|=1;
    else if(y==n)a[x]|=2;
  }
  bool sign=0;
  for(int i=1;i<=n;i++)if(a[i]==3)sign=1;
  if(sign)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 1024
use std::collections::VecDeque;

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

#[allow(unused_macros)]
macro_rules! getl_vec {
    ( $t:ty ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).unwrap();
            let s = s.trim_right();
            s.split_whitespace().map(|x| x.parse().unwrap()).collect::<Vec<$t>>()
        }
    };
}

fn main() {
    let k = getl!(usize);

    let mut q = VecDeque::new();
    for i in 1..10 {
        q.push_back(i as u64);
    }
    let mut count = 0;
    loop {
        count += 1;
        let now = q.pop_front().unwrap();
        if count == k {
            println!("{}", now);
            return
        }
        let d = now % 10;
        if d != 0 {
            q.push_back(now * 10 + d - 1);
        }
        q.push_back(now * 10 + d);
        if d != 9 {
            q.push_back(now * 10 + d + 1);
        }
    }
}


Measured memory_bytes: 6396
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = 0, b = 0;
		for (int i = 0; i < n; ++i) {
			String str1 = sc.next(), str2 = sc.next();
			int res = str1.compareTo(str2);
			if (res > 0) {
				a += 3;
			} else if (res < 0) {
				b += 3;
			} else {
				a += 1;
				b += 1;
			}
		}
		System.out.printf("%d %d\n", a, b);
		sc.close();
	}
}


Measured memory_bytes: 30372
class PriorityQueue
  def initialize
    @heap = []
  end

  def push value
    @heap.push value
    update_heap_to_up
  end

  def empty?
    @heap.empty?
  end

  def shift
    min, last = @heap[0], @heap.pop
    unless @heap.empty?
      @heap[0] = last
      update_heap_to_down
    end
    min
  end

  alias pop shift

  private

  def update_heap_to_up
    index    = @heap.size - 1
    up_value = @heap[index]
    while 0 <= (parent_index = (index - 1) / 2)
      parent_value = @heap[parent_index]
      break if parent_value <= up_value

      @heap[index] = parent_value
      index        = parent_index
    end
    @heap[index] = up_value
  end

  def update_heap_to_down
    index      = 0
    down_value = @heap[0]
    size       = @heap.size
    while (child_index = 2 * index + 1) < size
      # 右の子がいて、右の子が小さければ、右の子を使う
      child_index += 1 if child_index + 1 < size and @heap[child_index + 1] < @heap[child_index]
      child_value = @heap[child_index]
      break if down_value <= child_value

      @heap[index] = child_value
      index        = child_index
    end
    @heap[index] = down_value
  end
end

MAX_V = 50 # 制約の最大値。
MAX_S = MAX_V * 50 + 5
INF   = Float::INFINITY

#　頂点
Edge = Struct.new(:to, :a, :b)
#　両替所
Exchange = Struct.new(:v, :s, :x) do
  include Comparable
  def <=>(other)
    self.x <=> other.x
  end
end

g    = Array.new(MAX_V) { Array.new { Edge.new } }
dist = Array.new(MAX_V) { Array.new(MAX_S + 5) { INF } }

def input
  gets.split.map &:to_i;
end

# メイン
n, m, s = input
#　都市の入力
m.times do
  u, v, a, b = input
  u          = u.pred
  v          = v.pred
  g[u] << Edge.new(v, a, b)
  g[v] << Edge.new(u, a, b)
end

# プライオリティキューのライブラリを利用
# require 'pqueue'
# 銀貨は最大でもMAX_S
s = [s, MAX_S].min
# プライオリティーキュー
q = PriorityQueue.new
# 入力用ラムダ
push = lambda { |v, s, x|
  return if s < 0
  return if dist[v][s] <= x

  dist[v][s] = x
  q.push(Exchange.new(v, s, x))
}

c = []
d = []
n.times do |i|
  cc, dd = input
  c[i]   = cc
  d[i]   = dd
end
push.call(0, s, 0)
until q.empty?
  hoge = q.pop
  v    = hoge.v; s = hoge.s; x = hoge.x
  next if dist[v][s] != x

  ns = [s + c[v], MAX_S].min
  push.call(v, ns, x + d[v])

  g[v].each do |e|
    push.call(e.to, s - e.a, x + e.b)
  end
end


(1 ... n).each do |i|
  ans = INF
  (0 ... (MAX_S + 5)).each do |j|
    ans = [ans, dist[i][j]].min
  end
  puts ans
end


Measured memory_bytes: 21524
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>

#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1844674407370955161
typedef long long unsigned int ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a * b / g;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}



int main()
{
  int P, Q, R;
  cin >> P >> Q >> R;
  int mi = 10000;
  mi = min(mi, P + Q);
  mi = min(mi, P + R);
  mi = min(mi, R + Q);

  cout << mi << endl;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))

ans = 0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            len = l[i] + l[j] + l[k]
            ma = max(l[i],l[j],l[k])
            rest = len - ma
            if ma < rest and l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i]:
                ans += 1
print(ans)

Measured memory_bytes: 68344
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
typedef pair<int,int> pi;

ll A, B;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}

int main() {
	ios_base::sync_with_stdio(0); 
	cin.tie(0);
	cin >> A >> B;
	cout << A * B / gcd(A,B);
	return 0;
}

Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d %d %d", $n, $A, $B, $C);
for($i = 0; $i < $n; $i++){
    $l[] = trim(fgets(STDIN));
}

echo dfs(0,0,0,0) - 30;

function dfs($pos, $a, $b, $c){
    global $n, $l, $A, $B, $C;
    if($pos == $n){
        if(min($a, $b, $c) == 0){
            return 999999;
        }else{
            return abs($a-$A) + abs($b-$B) + abs($c-$C);
        }
        return 0;
    }
    $v[] = dfs($pos + 1, $a, $b, $c);
    $v[] = dfs($pos + 1, $a + $l[$pos], $b, $c) + 10;
    $v[] = dfs($pos + 1, $a, $b + $l[$pos], $c) + 10;
    $v[] = dfs($pos + 1, $a, $b, $c + $l[$pos]) + 10;
    return min($v);
}


Measured memory_bytes: 4728
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // abs()
#include <string.h>         // memset()
#include <stdbool.h>

#define MAX_N 15
#define MAX_S (1 << MAX_N)

const double INF = 1e10;

int n;
int s[MAX_N], l[MAX_N], v[MAX_N];
double dp[MAX_N][MAX_S];
int w[MAX_N][MAX_S];
short prev[MAX_N][MAX_S][2];
int ord[MAX_N];

int
main(int argc, char **argv)
{
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d%d%d", &s[i], &l[i], &v[i]);

	memset(prev, -1, sizeof(prev));
	int S = 1;
	for (int i = 0; i < n; i++, S <<= 1)
		w[i][S] = v[i];

	int e = 1 << n;
	for (int k = 0; k < e; ++k)
	{
		S = 1;
		for (int i = 0; i < n; ++i, S <<= 1)
		{
			if (k & S)
				continue;

			int t = k | S;
			for (int j = 0; j < n; ++j)
			{
				if (i == j || w[j][k] == 0)
					continue;

				int d = abs(l[i] - l[j]);
				double x = dp[j][k] + (d * (7 + 2 * w[j][k])) / 200.0;
				if (dp[i][t] == 0 || x < dp[i][t])
				{
					dp[i][t] = x;
					w[i][t] = w[j][k] + v[i];
					prev[i][t][0] = j;
					prev[i][t][1] = k;
				}
			}
		}
	}

	double min = INF;
	int u = 0;
	for (int i = 0; i < n; ++i)
	{
		double y = dp[i][e - 1];
		if (y == 0)
			continue;

		if (y < min)
		{
			min = y;
			u = i;
		}
	}

	ord[0] = u;
	int v = e - 1;
	for (int k = 1; k < n; ++k)
	{
		ord[k] = prev[u][v][0];
		v = prev[u][v][1];
		u = ord[k];
	}

	for (int i = n - 1; i >= 0; --i)
		printf("%d%c", s[ord[i]], (i != 0) ? ' ' : '\n');

	return 0;
}

Measured memory_bytes: 8652
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<u64>();
    let (n, k) = (line[0], line[1]);
    let mm: u64 = 1_000_000_007;
    let mut ans : u64 = 0;
    for i in k..n+2{
        let cmax = i*(n+n+1-i)/2;
        let cmin = (i-1)*(i)/2;
        ans += cmax - cmin + 1;
        ans %= mm;
    }

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


Measured memory_bytes: 2120
#include<iostream>
#include<algorithm>
#define MAX 20001
using namespace std;

class Data{
public:
  int t,s,d;
  bool operator<(const Data&a)const{
    return t < a.t;
  }
};


int main(){
 
  int n,m;
  while(1){
    cin >> n >> m;
    if(n == 0 && m == 0)break;
    Data data[m];
    bool node[n+1];
    for(int i = 0 ; i < m ; i++){
      cin >> data[i].t >> data[i].s >> data[i].d;
    }
    sort(data,data + m);
    for(int i = 0 ; i < n+1 ; i++)node[i] = false;
    node[1] = true;
    for(int i = 0 ;i < m ; i++){
      if(node[data[i].s])node[data[i].d] = true;
    }

    int cnt = 0 ;
    for(int i = 0 ; i < n+1 ; i++){
      if(node[i])cnt++;
    }
    cout << cnt << endl;
  }  
  return 0;
}

Measured memory_bytes: 1120
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String s = String.valueOf(N);

        if((s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2) && s.charAt(2) == s.charAt(3) && s.charAt(3) == s.charAt(0)||
            (s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2) && s.charAt(2) == s.charAt(0))||
            (s.charAt(1) == s.charAt(2) && s.charAt(2) == s.charAt(3) && s.charAt(3) == s.charAt(1)))){
                System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

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

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

  vector<int> depth(N, -1);
  stack<int> st;
  st.push(0);
  depth[0] = 0;
  while(!st.empty()){
    int now = st.top();
    st.pop();
    for(auto next: adj[now]){
      if(depth[next] == -1){
        st.push(next);
        depth[next] = depth[now] + 1;
      }
    }
  }
  /*
  for(int i = 0; i < N; i++){
    cout << depth[i] << endl;
  }
  */

  int depth_cnt[2] = {}; // even or odd
  for(int i = 0; i < N; i++){
    depth_cnt[depth[i] % 2]++;
  }

  int next_1 = 1, next_2 = 2, next_0 = 3;
  vector<int> ans(N);
  bool rev = (depth_cnt[0] < depth_cnt[1]);
  if(!rev){ // depth_cnt[0] >= depth_cnt[1]
    if(depth_cnt[1] <= N / 3){
      // even depth for any, odd depth for 0
      for(int i = 0; i < N; i++){
        if(depth[i] % 2 == 1){
          ans[i] = next_0;
          next_0 += 3;
        }else{
          if(next_1 <= N){
            ans[i] = next_1;
            next_1 += 3;
          }else if(next_2 <= N){
            ans[i] = next_2;
            next_2 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }
      }
    }else{
      // even depth for 1, odd depth for 2
      for(int i = 0; i < N; i++){
        if(depth[i] % 2 == 0){
          if(next_1 <= N){
            ans[i] = next_1;
            next_1 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }else{
          if(next_2 <= N){
            ans[i] = next_2;
            next_2 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }
      }
    }
  }else{ // depth_cnt[0] < depth_cnt[1]
    if(depth_cnt[0] <= N / 3){
      // odd depth for any, even depth for 0
      for(int i = 0; i < N; i++){
        if(depth[i] % 2 == 0){
          ans[i] = next_0;
          next_0 += 3;
        }else{
          if(next_1 <= N){
            ans[i] = next_1;
            next_1 += 3;
          }else if(next_2 <= N){
            ans[i] = next_2;
            next_2 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }
      }
    }else{
      // odd depth for 1, even depth for 2
      for(int i = 0; i < N; i++){
        if(depth[i] % 2 == 1){
          if(next_1 <= N){
            ans[i] = next_1;
            next_1 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }else{
          if(next_2 <= N){
            ans[i] = next_2;
            next_2 += 3;
          }else{
            ans[i] = next_0;
            next_0 += 3;
          }
        }
      }
    }
  }

  for(int i = 0; i < N; i++){
    if(i){
      cout << ' ';
    }
    cout << ans[i];
  }
  cout << endl;
    
}



Measured memory_bytes: 15216
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define mpp make_pair
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;

const int N=2e3+5;
const ll infi=1e9+5;
const ll mod=1e9+7;

int main()
{
	ll n,i,j;
	cin>>n;
	ll ans=0;
	ll a[15][15]={0};
	for(i=1;i<=n;i++)
	{
		string s=to_string(i);
		ll sz=s.size();
		ll fi=s[0]-'0';
		ll se=s[sz-1]-'0';
	//	cout<<fi<<" "<<se<<"\n";
		a[fi][se]++;
	}
	// for(i=0;i<10;i++)
	// {
	// 	for(j=0;j<10;j++)
	// 	cout<<a[i][j]<<" ";
	// 	cout<<"\n";
	// }
	
	ll val=0;
	for(i=0;i<10;i++)
		for(j=0;j<10;j++)
			ans=ans + a[i][j]*a[j][i];
			
	cout<<ans<<"\n";
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

void inverse(ll n,vector<ll> &inv){
    //要素数:n+1 (0~n)
    inv[0]=1;
    inv[1]=1;
    for(ll i=2;i<=n;i++){
        inv[i]=(MOD-inv[MOD%i]*(MOD/i))%MOD;
    }
}

int main() {
    ll n; cin>>n;
    vector<ll> a(n,0),inv(1000001,0);
    inverse(1000001,inv);
    rep(i,n) cin>>a[i];
    map<ll,ll> m;
    rep(i,n){
        ll t=a[i];
        map<ll,ll> s;
        for(ll j=2;j*j<=a[i];j++){
            while(t%j==0){
                t/=j;
                if(s.count(j)) s[j]++;
                else s[j]=1;
            }
        }
        if(t!=1){
            if(s.count(t)) s[t]++;
            else s[t]=1;
        }
        for(auto q : s){
            if(m.count(q.first)) m[q.first]=max(m[q.first],q.second);
            else m[q.first]=q.second;
        }
    }
    ll mu=1,ans=0;
    for(auto q : m){
        rep(i,q.second) mu=(mu*q.first)%MOD;
    }
    rep(i,n) ans=(MOD+ans+(mu*inv[a[i]])%MOD)%MOD;
    cout<<(ans+MOD)%MOD<<endl;
}

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

const ll mod = ll(1e9) + 7;
const int INF = 1<<29;
const ll lINF = 1l<<40;

int main(){
    int D;
    cin >> D;
    vecInt c(26);
    rep(i,0,26) cin >> c[i];
    vector<vecInt> s(D,vecInt(26));
    rep(i,0,D) rep(j,0,26) cin >> s[i][j];
    vecInt last(26);
    vecInt ans(D);
    rep(i,0,D){
        ll score = -lINF;
        rep(j,0,26){
            ll res = s[i][j];
            rep(k,0,26){
                if (k==j) continue;
                res -= c[k] * ((j + 1) - last[k]);
            }
            if (res>score){
                score = res;
                last[j] = i + 1;
                ans[i] = j;
            }
        }
    }
    rep(i,0,D) cout << ans[i] + 1 << endl;
    /*
    rep(i,0,D){
        score += s[i][t[i]-1];
        last[t[i]-1] = i + 1;
        rep(j,0,26){
            if (j==t[i]-1) continue;
            score -= c[j] * ((i + 1) - last[j]);
        }
        cout << score << endl;
    }
    */

    return 0;
}

Measured memory_bytes: 3684
#include <stdio.h>

int main()
{
	int a,K;
	char S[1000];

	scanf("%d",&K);

	scanf("%s",S);

	for(int i=0;i<1000;i++)
	{
		if(S[i]=='\0')
		{
			a=i;
			break;
		}
	}

	if(a<=K)
	{
		printf("%s",S);
	}
	else
	{
		for(int i=0;i<K;i++)
		{
			printf("%c",S[i]);
		}
		printf("...");
	}
	return 0;
	
}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    string s = "No";
    if (a == b) {
        if (a != c) {
            s = "Yes";
        }
    } else if (b == c) {
        if (b != a) {
            s = "Yes";
        }
    } else if (c == a) {
        if (c != b) {
            s = "Yes";
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;


void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

int32_t main()
{
	c_p_c();


	string s;
	cin >> s;
	if (s == "ABC")
	{cout << "ARC";}
	else {
		cout << "ABC";
	}
	//cout << "aaa0";

	return 0;
}
//


Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int nxt[400001],head[400001],to[400001],cnt;
void add(int u,int v)
{
	cnt++;
	nxt[cnt]=head[u];
	head[u]=cnt;
	to[cnt]=v;
}
int n,m;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		add(a,b);
		add(b,a);
	}
	for(int i=head[1];i!=0;i=nxt[i])
	{
		if(to[i]==n)
		{
			cout<<"POSSIBLE";
			return 0;
		}
		else{
			for(int j=head[to[i]];j!=0;j=nxt[j])
			{
				if(to[j]==n) {
					cout<<"POSSIBLE";
					return 0;
				}
			}
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}

Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
using namespace std;

#define DEBUG(x) cerr << "L" << __LINE__ << " " << #x << " = " << x << endl

const int MAX_N = 300000;

const int INF = 1e9;
const int sqrtN = 500;

int data[(MAX_N + sqrtN - 1) / sqrtN * sqrtN];
int add[(MAX_N + sqrtN - 1) / sqrtN];
int min1[(MAX_N + sqrtN - 1) / sqrtN];

struct SegmentArray {
  const int B;
  SegmentArray(int n) : B((n + sqrtN - 1) / sqrtN) { }
  void update(int a, int b, int v) {
    for(int k = 0; k < B; ++k) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if(r <= a || b <= l) continue;
      if(a <= l && r <= b) {
        add[k] += v;
        continue;
      }
      min1[k] = INF;
      int st = std::max(a, l), en = std::min(b, r);
      for(int i = k * sqrtN; i < (k + 1) * sqrtN; ++i) {
        if(st <= i && i < en) data[i] += v;
        if(min1[k] > data[i]) min1[k] = data[i];
      }
    }
  }
  int search(int p) {
    int a = 0;
    int b = p + 1;
    for(int k = B - 1; k >= 0; k--) {
      int l = k * sqrtN, r = (k + 1) * sqrtN;
      if(r <= a || b <= l) continue;
      if(a <= l && r <= b) {
        if(add[k] + min1[k] < 2) {
          for(int j = sqrtN - 1; j >= 0; --j) {
            if(add[k] + data[k * sqrtN + j] < 2) {
              return k * sqrtN + j + 1;
            }
          }
        }
      }
      else {
        int st = std::max(a, l), en = std::min(b, r);
        for(int i = en - 1; i >= st; --i) {
          if(add[k] + data[i] < 2) {
            return i + 1;
          }
        }
      }
    }
  }
};

char S[300001];

int main() {
  int N, Q; scanf("%d%d", &N, &Q);
  scanf("%s", S);
  SegmentArray seg1(N);
  set<int> seg2;
  for(int i = 0; i < N; ++i) { 
    seg1.update(i, N, (S[i] == '(' ? 1 : -1));
    if(S[i] == ')') seg2.insert(i);
  }
  for(int q = 0; q < Q; ++q) {
    int p; scanf("%d", &p);
    --p;
    if(S[p] == '(') {
      S[p] = ')';
      seg2.insert(p);
      seg1.update(p, N, -2);
      int np = *seg2.begin();
      S[np] = '(';
      seg2.erase(np);
      seg1.update(np, N, +2);
      printf("%d\n", np + 1);
    }
    else {
      S[p] = '(';
      seg2.erase(p);
      seg1.update(p, N, +2);
      int np = seg1.search(p);
      S[np] = ')';
      seg2.insert(np);
      seg1.update(np, N, -2);
      printf("%d\n", np + 1);
    }
  }
}

Measured memory_bytes: 9676
#include <bits/stdc++.h>
#define pb push_back
#define vt vector
#define ll long long
using namespace std;

const int INF = 1e9 +5;
const ll LLINF = 1e18 +5;

int i4[4] = {1,0,-1,0};
int j4[4] = {0,1,0,-1};


void solve()
{
	int a,b;
	cin >> a >> b;
    int len = to_string(b).size();
    int num = a;
    for(int i = 0; i < len;i++)
        num *= 10;
    num += b;
    double ans = sqrt(num);
    if(floor(ans) == ans)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;


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

  return 0;
}


Measured memory_bytes: 3736
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e18;

int main(){
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    bool flag=true;
    ll ans=0;
    int cnt=0;
    while(flag){
        flag=false;
        for(int i=0;i<n;i++){
            if(a[i]<n)continue;
            ll t=a[i]/n;
            flag=true;
            ans+=t;
            for(int j=0;j<n;j++){
                if(i!=j){
                    a[j]+=t;
                }
            }
            a[i]%=n;
        }
    }
    cout<<ans<<endl;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

ll mod_pow(ll x, ll n, ll mod) {
	if (n == 0) return 1;
	ll res = mod_pow(x * x % mod, n / 2, mod);
	if (n & 1) res = res * x % mod;
	
	return res;
}

vector<ll> fact, inv;
void fact_inv(int n, ll mod) {
	fact.resize(n + 1);
	inv.resize(n + 1);
	
	fact[0] = 1;
	FOR(i, 1, n + 1) fact[i] = fact[i - 1] * i % mod;
	inv[n] = mod_pow(fact[n], mod - 2, mod);
	for (int i = n; i > 0; i--) inv[i - 1] = inv[i] * i % mod;
}

int main() {
	int N, M;
	cin >> N >> M;
	
	fact_inv(112345, MOD);
	
	ll ans = fact[N] * fact[M] % MOD;
	if (N == M) ans = ans * 2 % MOD;
	if (abs(N - M) >= 2) ans = 0;
	
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main()
{
    string a;
    cin >> a;    

    int tmp=0;

    if(a[0]=='1')
    {
        tmp += 1;
    }
    if(a[1]=='1')
    {
        tmp += 1;
    }
    if(a[2]=='1')
    {
        tmp += 1;
    }

    cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 256
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N,M,C = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
A = []
for _i in range(N):
    A.append([int(x) for x in input().split()])

ans = 0
for a in A:
    sum = 0
    for i in range(len(a)):
        sum += a[i] * B[i]
    sum += C
    if sum > 0:
        ans += 1
print(ans)


Measured memory_bytes: 14596
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <algorithm>
#include <math.h>

using namespace std;

string s1,s2;
int main()
{
	cin>>s1>>s2;
	
	if(s1.size()!=s2.size()){
		printf("No\n");
		return 0;
	}
	int l = s1.size();
	s2 += s2;
	int flag = 0;
	for(int i=0;i<s2.size()&&flag==0;i++){
		int f = 1;
		for(int j=0;j<l;j++){
			if(s1[j]!=s2[i+j]) f = 0;
		}
		if(f){
			flag = 1;
			break;
		}
	}
	if(flag) printf("Yes\n");
	else printf("No\n");
	
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
int main() {
  int y,m,d;
  scanf("%04d/%02d/%02d",&y,&m,&d);
  bool isTBD=false;
  if(y>2019){
    isTBD=true;
  }else if(y==2019&&m>=5){
    isTBD=true;
  }
  cout<<(isTBD?"TBD":"Heisei")<<endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  vector<int> y(n);
  for (int i = 0; i < n; ++i) cin >> x.at(i);
  for (int i = 0; i < n; ++i) cin >> y.at(i);
  double p1 = 0.0;
  double p2 = 0.0;
  double p3 = 0.0;
  double max = 0.0;
  for (int i = 0; i < n; ++i) {
    double dist = abs(x.at(i) - y.at(i));
    p1 += dist;
    p2 += dist * dist;
    p3 += dist * dist * dist;
    if (dist > max) max = dist;
  }
  p2 = sqrt(p2);
  p3 = pow(p3, 1.0/3.0);
  cout << fixed << setprecision(5);
  cout << p1 << endl;
  cout << p2 << endl;
  cout << p3 << endl;
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 3488
import numpy as np
n,k = map(int,input().split())
s = input()
lr_cnt = 0
rl_cnt = 0
mnt = 0
for i in range(len(s)-1):
    if s[i] == 'L' and s[i+1] == 'R':
        lr_cnt += 1
        
    if s[i] == 'R' and s[i+1] == 'L':
        rl_cnt += 1
mnt  = rl_cnt + lr_cnt+1
mnt = np.max([1,mnt-2*k])
if mnt == 1:
    print(n-1)
else:
    print(n-rl_cnt-lr_cnt+2*k-1)

Measured memory_bytes: 12648
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
	int n, x=0,situ,min;
	scanf("%d%d", &n,&situ);
	min = abs(situ);
	for (int i = 0; i < n;i++) {
		x += situ;
		
		if (abs(situ) < abs(min))
			min = situ;
		situ += 1;
	}
	printf("%d", x-min);
	return 0;
}

Measured memory_bytes: 128
icase=0
if icase==0:
    n,k=map(int,input().split())
    s=input()
    if k==1:
        s1=""
        s2=s[0]
        s3=s[1:]
    elif k==n:
        s1=s[:n-1]
        s2=s[n-1]
        s3=""
    else:
        s1=s[:k-1]
        s2=s[k-1]
        s3=s[k:]
    if s2=="A":
        s2="a"        
    elif s2=="B":
        s2="b"        
    elif s2=="C":
        s2="c"        
    print(s1+s2+s3)

Measured memory_bytes: 3064
S = input()

G0 = 0
K1 = 0

total = len(S)

g = False
for i in S:
    if i == "0" and g:
        G0 += 1
    if i == "1" and not g:
        K1 += 1
    g = not g

res = total - (G0 +  K1)
res = min(res, (G0 +  K1))       
print(res)



Measured memory_bytes: 39664
n=int(input())
A=[list(map(int,input().split()))for _ in range(n)]

S=[0]*(1<<n)
for i in range(1<<n):
    for j in range(n):
        if i&(1<<j):
            for k in range(n):
                if i&(1<<k):
                    S[i]+=A[j][k]
dp=[-10**9]*(1<<n)
dp[0]=0
for i in range(1,1<<n):
    j=i
    b=i.bit_length()
    while j.bit_length()==b:
        dp[i]=max(dp[i],S[j]+dp[i-j])
        j=i&(j-1)
print(dp[-1]//2)

Measured memory_bytes: 44124
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

struct Data{
    char a;
    char b;
};

int main(){
    int n;
    while(cin >> n, n){
        Data data[1024];
        rep(i,n){
            cin >> data[i].a >> data[i].b;
        }
        int m;
        cin >> m;
        rep(i,m){
            char inp;
            bool outp = true;
            cin >> inp;
            rep(j, n){
                if(data[j].a == inp){
                    cout << data[j].b;
                    outp = false;
                    break;
                }
            }
            if(outp)
                cout << inp;
        }
        cout << endl;
    }
}

Measured memory_bytes: 1152
p[1<<21]={1};a[999],I,j,A;main(x){while(~scanf("%d",a+j++));for(;I<1<<*a;I++)for(j=0;j<*a;!a[*a*__builtin_popcount(I)+j]|I&x?:(p[I|x]+=p[I],p[I|x]%=A=1e9+7))x=1<<j++;printf("%d",p[I-1]);}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int x;
	cin >> x;
	YES(x == 7 || x == 5 || x == 3);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int N;
    cin >> N;

    for (int i=1; i<10; i++) {
        for (int j=1; j<10; j++) {
            if (i*j == N) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

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

  int a = 0;
  int z = static_cast<int>(s.size() - 1);
  while (s[a] != 'A') a++;
  while (s[z] != 'Z') z--;
  cout << z - a + 1 << endl;

  return 0;
}


Measured memory_bytes: 720
#include <bits/stdc++.h>
#define int long long
const int MOD=1e9+7;
using pii=std::pair<int,int>;
using namespace std;

int s, w;
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> s >> w;
    if(s > w)
        cout << "safe\n";
    else
        cout << "unsafe\n";
    return 0;
}

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

int main() {
  int n;
  string str;
  cin >> n >> str;
  
  stack<char> s;
  for (char c : str) {
    if (s.empty() || s.top() != c) s.push(c);
  }
  
  cout << s.size() << "\n";
}

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

int c[3][3], a[3], b[3];

int main(){
    for(int i=0;i<3;i++) for(int j=0;j<3;j++) cin >> c[i][j];

    b[0] = c[0][0] - a[0]; b[1] = c[0][1] - a[0]; b[2] = c[0][2] - a[0];
    a[1] = c[1][0] - b[0]; a[2] = c[2][0] - b[0];

    bool ok = true;
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++) if(a[i]+b[j] != c[i][j]) ok = false;
    
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
N, M, *A = map(int, open(0).read().split())

match = {1: 2, 2: 5, 3: 5, 4: 4, 5: 5, 6: 6, 7: 3, 8: 7, 9: 6}
dp = [[0] * M for _ in range(N + 1)]

for i in range(N + 1):
    for j in range(M):
        for k in range(M):
            if (i - match[A[k]] == 0) or \
                   (i - match[A[k]] > 0 and dp[i - match[A[k]]][j] != 0):
                dp[i][k] = max(dp[i][k], 
                               dp[i - match[A[k]]][j] * 10 + A[k])

print(max(dp[-1]))



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

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

	return 0;
}


Measured memory_bytes: 3092
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        n: i32,
        c: [(i32, i32, i32); n],
    };
    let mut d = c.clone();
    d.insert(0, (0, 0, 0));
    let ans =  d[..].windows(2).all(|w|{
        let (t, x, y) = w[0];
        let (nt, nx, ny) = w[1];
        let time = nt - t;
        let dist = (nx - x).abs() + (ny - y).abs();
        dist <= time && time % 2 == dist % 2
    });
    println!("{}", if ans{"Yes"}else{"No"})
}


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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define rep(i, n) for(i = 0; i < n; i++)

int main(){
    string s, front, end;
    int i;
    int Q, q, f;
    bool reversed = false;
    char c;

    cin >> s;
    cin >> Q;
    rep (i, Q) {
        cin >> q;
        if (q == 1) {
            reversed ^= 1;
        } else {
            cin >> f;
            f = (f + reversed - 1) % 2 + 1;
            if (f == 1) {
                cin >> c;
                front += c;
            } else {
                cin >> c;
                end += c;
            }
        }
    }
    
    reverse(front.begin(), front.end());
    string ans = front + s + end;
    if (reversed) {
        reverse(ans.begin(), ans.end());
    }
    cout << ans;

    return 0;
}

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

int main() {
  int n; cin >> n;
  int mn[n],mx[n];
  for (int i=0; i<n; i++) cin >> mn[i] >> mx[i];
  sort(mn,mn+n);
  sort(mx,mx+n);
  if (n%2 == 0) {
    int l = mn[n/2]+mn[(n-1)/2],r = mx[n/2]+mx[(n-1)/2];
    cout << 2*(r/2) - 2*((l+1)/2) + 1 + (l%2) + (r%2)<< endl;
  }else {
    cout << mx[n/2] - mn[(n-1)/2] + 1 << endl;
  }
}

Measured memory_bytes: 4720
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<cstdio>
using namespace std;

int main(){


    int n;
    vector<int> v(n);
    vector<int> c(n);

    cin >> n;

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

    int out = 0;

    for(int i = 0; i < n; ++i){
        if(v[i] > c[i]){
            out += v[i]-c[i];
        }
    }

    cout << out << endl;

    return 0;
}

Measured memory_bytes: 512
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------

A,B = map(int,input().split())

ans = 0
if 13 <= A:
    ans = B
elif 6 <= A <= 12:
    ans = B//2

print(ans)

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){

	string s1 = "", s2 = "";
	cin >> s1 >> s2;

	int count = 0;

	for(int i = 0; i < s1.size(); i++){
    	if(s1[i] != s2[i]){
        	count++;
        }
    }
	cout << count;
}

Measured memory_bytes: 3828
def dif(x,y):
    if x<y:
        x,y = y,x
    return min(x-y,24-(x-y))
from itertools import combinations
N = int(input())
D = sorted(list(map(int,input().split())))
T = [0 for _ in range(N)]
for i in range(N):
    d = D[i]
    if i%2==0:
        T[i] = d
    else:
        T[i] = 24-d
cmin = min(D)
for z in combinations(range(N),2):
    i,j = z[0],z[1]
    cmin = min(cmin,dif(T[i],T[j]))
print(cmin)

Measured memory_bytes: 38896