akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename T,T MOD = 1000000007>
struct Mint{
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }
  
  Mint inv(){return pow(MOD-2);}
  
  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}
  
  Mint operator+(Mint a) const{return Mint(v)+=a;};
  Mint operator-(Mint a) const{return Mint(v)-=a;};
  Mint operator*(Mint a) const{return Mint(v)*=a;};
  Mint operator/(Mint a) const{return Mint(v)/=a;};

  Mint operator-(){return v?MOD-v:v;}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}
  
};

//INSERT ABOVE HERE
const int MAX = 303;
using M = Mint<int>;
M dp[MAX][MAX*2];
int used[MAX*2];
int side[MAX*2];
signed main(){
  int n;
  cin>>n;
  vector<int> a(n*2);
  for(int i=0;i<n*2;i++) cin>>a[i];
  
  memset(used,0,sizeof(used));
  for(int i=0;i<n*2;i++)
    if(~a[i]) used[a[i]]=1;

  int cnt=0;  
  memset(side,0,sizeof(side));
  for(int i=0;i<n;i++){
    if(a[i*2]<0&&a[i*2+1]<0){
      cnt++;
      continue;
    }
    if(a[i*2]>0&&a[i*2+1]>0) continue;
    if(a[i*2]>0) side[a[i*2]]=1;
    if(a[i*2+1]>0) side[a[i*2+1]]=1;
  }
  
  for(int j=0;j<MAX;j++)
    for(int k=0;k<MAX*2;k++)
      dp[j][k]=0;

  dp[0][0]=1;
  
  int num=0,laz=0;
  for(int i=n*2;i>=1;i--){
    if(used[i]&&!side[i]) continue;
    
    if(used[i]){
      assert(side[i]);
      for(int j=n;j>=0;j--)
        for(int k=n*2;k>=0;k--)
          if(j*2+k+1<=laz) dp[j][k+1]+=dp[j][k];
      num++;
      continue;
    }
    
    if(!used[i]){      
      for(int j=n;j>=0;j--){
        for(int k=n;k>=0;k--){         
          if(j*2+k+1<=laz&&j+1<=cnt) dp[j+1][k]+=dp[j][k]*M(cnt-j);
          if(k+1<=num) dp[j][k+1]+=dp[j][k]*M(num-k);          
        }
      }
      laz++;
      continue;
    }
  }
  
  M ans=dp[cnt][num];
  cout<<ans.v<<endl;
  return 0;
}


Measured memory_bytes: 1024
S=gets.chomp.bytes
n=S.size
L=[nil]*(n+0)
l=[n]*26
(n-1).downto(0){|i|
	L[i]=l.dup
	l[S[i]-97]=i
}
L[-1]=l
q=[-1]
z={-1=>[nil,0]}
while q[0]&&q[0]!=n
	v=q.shift;l=L[v];26.times{|c|!z[l[c]]&&(z[l[c]]=[v,c];q<<l[c])}
end
r=''
(n,c=z[n];r<<(c+97))while n
$><<r.reverse[1..-1]

Measured memory_bytes: 88888
g = [[-1 for _ in range(15)] for _ in range(15)]
n = int(input())
ans=0
for i in range(n):
  m = int(input())
  for j in range(m):
    x,y = map(int, input().split())
    g[i][x-1] = y
for i in range(1<<n):
  honests = [0 for _ in range(n)]
  for j in range(n):
    if (i>>j) &1:
      honests[j] = 1     
  ok = True  
  for j in range(n):
    if honests[j]:
      for k in range(n):
        if g[j][k] == -1: continue
        if g[j][k] != honests[k]: ok = False
  if ok:
    ans = max(ans, honests.count(1))
print(ans)
'''
・正直者の人の組を全ての組合せで仮定する。
・正直者と仮定した人の証言が仮定に矛盾するとき、
その正直者の選び方の組はあり得ない。
・正直者と仮定した人の証言同士の矛盾は調べる必要はない。
ある人に対して矛盾する二つの証言があるとき、
どちらか一方の証言は必ず仮定に矛盾する。したがって、
この仮定があり得ないことを調べるには仮定と証言の矛盾を調べるだけでよい。
・全ての証言が矛盾しない正直者の選び方の組のうち、
正直者が最も多い組の正直者の人数を求めれば良い。
人xの人yに対する証言のデータを二次元配列gへ次のような対応関係で
格納しておく。なお、ここでは人の番号は配列のオフセットに合わせるため
0から始めるものとする。
・人xが人yに対して正直者であると証言するとき、
二次元配列g[x][y]を1にする。
・人xが人yに対して不親切な人であると証言するとき
二次元配列g[x][y]を0とする。
・人xが人yに対して言及していないとき、
二次元配列g[x][y]を-1にする。
・入力よりNの最大が15なので、
15行15列の二次元配列gをデフォルト値-1用意しておく
・全員の人数を表す値を受け取る。
・用意した配列に人iが人jに対して述べる証言のデータを格納していく。
・人iの証言の数mを受け取る。
・人iの証言を受け取るためm回次のループを回す。
・証言を表す二つの値を受け取り二次元配列gに格納する。
人iが「人xはyである」と証言しているときg[i][x]=yである。
（入力で受け取る「人の番号」は1から始まるため、
コードでは受け取った値から1引いている。）
g = [[-1 for _ in range(15)] for _ in range(15)]
n = int(input())
for i in range(n):
 m = int(input())
 for j in range(m):
   x,y = map(int, input().split())
   g[i][x-1] = y
二次元配列gの作成と入力の受け取りは以上である。
次に問題を解く中心となるコードを実装していく。
まず、全ての正直者の組を表現するために二進数表記を用いることを考える。
二進数の右端の桁を0桁目とする。またkを0から14までの整数とする。
・「k桁目が1である」を「人kは正直者である」
・「k桁目が0である」を「人kは不親切な人である」
作り出した正直者の組それぞれに対して何らかの処理を行うため、
これは全bit探索である。
「正直者の組を作りだす」部分のコード。
・カウンタ変数iを1から2^15まで変化させ、次の処理を繰り返す。
・正直者の番号を格納する要素数nの配列honestsをデフォルト値0で作る。
・iを二進数で表現したときj桁目が1であればhonests[j]に1を追加する。
for i in range(1<<n):
 honests = [0 for _ in range(n)]
 for j in range(n):
   if (i>>j) &1:
     honests[j] = 1 
honests[j]が1であることは,人jは正直者であると仮定することに対応する。
次はhonestsの仮定と証言gに矛盾がないか調べ、求める値「N人のうち
正直者であり得る最大人数」を出力するまでの実装をおこなう。
仮定と証言に矛盾があればそのhonestsで表現された組はあり得ない。
・求める値「N人のうち正直者であり得る最大人数」を格納するための
変数ansをデフォルト値0で用意しておく。
求める値は0以上の値であり以下のループ処理によって、
より大きな値で更新され得る。最終的に最大値が格納される。
・ある正直者の組に矛盾がなかったことを表す変数okをデフォルト値
Trueで用意しておく
・外側のループで配列honestsを作る。作ったhonestsの要素を順に調べる。
honests[j]が1ならば証言g[j]は正しいのでg [j]を以下のように調べる。
・g[j][k]が-1ならば何もしなくてよいので次の証言を調べるループへ移る。
・g[i][k]がhonests[k]の値と異なるならばこの正直者の組はあり得ないので
変数okをFalseにする。
・okがTureのときhonestsの要素の値が1であるものの数（つまり正直者の数）を
数えてansより大きいならばその値をansに代入する。
・最終的なansの値を出力する。
'''

Measured memory_bytes: 9208
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def d(a, b):
    ans = 0
    n = len(a)
    for i in range(n):
        ans += (a[i] - b[i]) ** 2
    return int(ans**0.5) == ans**0.5

def solve():
    n, _ = [int(x) for x in input().split()]
    ans = 0
    points = []
    for _ in range(n):
        arr = [int(x) for x in input().split()]   
        points.append(arr)
    for i in range(n):
        for j in range(i+1, n):
            ans += d(points[i], points[j])
    print(ans)

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()




"""

4
1 2
2 4
1 3
3
2 2 4
4 5 6

6
1 2
2 3
3 4
4 5
4 6
3
3 5 6
2 17 31 5 11

"""





Measured memory_bytes: 9596
class Node
  attr_accessor :id, :left, :right, :parent, :sibling
  def initialize(id, left=nil, right=nil)
    @id, @left, @right = id, left, right
    @sibling, @parent = nil, nil
  end

  def height
    return -1 if @id == -1
    return @left.height < @right.height ? @right.height+1: @left.height+1
  end

  def depth(root)
    return 0 if @id==root.id
    return @parent.depth(root) + 1
  end

  def type
    if @parent.id == -1
      return "root"
    elsif @left.id==-1 && @right.id==-1
      return "leaf"
    else
      return "internal node"
    end
  end

  def degree
    if @left.id>=0 && @right.id>=0
      return 2
    elsif @left.id==-1 && @right.id==-1
      return 0
    else
      return 1
    end
  end
end

n = gets.to_i
nodes = []
(0..n-1).each do |i|
  id, l, r = gets.split.map(&:to_i)
  nodes[id] = Node.new(id, l, r)
end

nodes.each do |i|
  i.left = i.left==-1 ? Node.new(-1):nodes[i.left]
  i.right = i.right==-1 ? Node.new(-1):nodes[i.right]
  i.left.sibling, i.right.sibling = i.right, i.left
  i.left.parent = i.right.parent = i
end

root = nil
nodes.each do |i|
  if i.parent == nil
    root = i
    root.sibling, root.parent = Node.new(-1), Node.new(-1)
  end
end

(0..nodes.size-1).each do |i|
  c = nodes[i]
  puts "node #{i}: parent = #{c.parent.id}, sibling = #{c.sibling.id}, degree = #{c.degree}, depth = #{c.depth(root)}, height = #{c.height}, #{c.type}"
end


Measured memory_bytes: 6884
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define INF 2147483647
using namespace std;
using Graph=vector<vector<int>>;

int main(){
  int n,ans=0; cin>>n;
  int a[n],moto[n],zaatu[n];
  rep(i,n){
    cin>>a[i];
    moto[i]=a[i];
  }
  sort(a,a+n);
  map<int,int> mp;
  rep(i,n){
    mp[a[i]]=i;
  }
  rep(i,n){
    zaatu[i]=mp[moto[i]];
  }
  rep(i,n){
    int x=zaatu[i];
    if(x%2!=i%2){
      ans++;
    }
  }
  cout<<ans/2;
}


Measured memory_bytes: 6144
#include <stdio.h>

int n;
int count;

int main(void)
{
	scanf("%d", &n);
	
	for(int i = 1 ; i <= n ; i++)
	{
		if(1 <= i && i <= 9)
			count++;
		else if(100 <= i && i <= 999)
			count++;
		else if(10000 <= i && i <= 99999)
			count++;
		else if(1000000 <= i && i <= 9999999)
			count++;
	}
	
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int H, W, N;
	cin >> H >> W >> N;
	vector<pair<int,int> > A;
	pair<int, int> p;
	int res = 0;
	//set <pair<int, int>>  st;
	vector<int> mn(H + 1 , (int)1 << 60);
	for (int i = 0; i < N; i++) {
		cin >> p.first >> p.second;
		//st.insert(p);
		mn[p.first] = min(mn[p.first], p.second);
	}
	int mx = 1;
	res = H;
	for (int i = 2; i <= H; i++) {
		if (mn[i] <= mx) {
			res = i - 1;
			break;
		}
		if (mn[i] != mx + 1) {
			mx++;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
  int N, ans = 0;
  scanf("%d", &N);
  int A[N+1], B[N+1], C[N+1];
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &A[i]);
  }
  for (int i = 1; i <= N; ++i) {
    scanf("%d", &B[i]);
  }
  for (int i = 1; i <= N-1; ++i) {
    scanf("%d", &C[i]);
  }
  for (int i = 1; i <= N; ++i) {
    ans += B[A[i]];
    if (i <= N-1 && A[i]+1 == A[i+1]) ans += C[A[i]];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

if e-d<=k and d-c<=k and c-b<=k and b-a<=k and e-c<=k and e-b<=k and e-a<=k and d-b<=k and d-a<=k and c-a<=k:
    print("Yay!")
else:
    print(":(")


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
const int MaxN = 1e5;

int a, b;
int s[55];
int main()
{
	while(scanf("%d %d", &a, &b) != EOF)
	{
		for(int i = 1; i <= a; i++)
			scanf("%d", &s[i]);
		sort(s + 1, s + a + 1);
		int ans = 0;
		for(int i = a; i >= a - b + 1; i--)
			ans += s[i];
		printf("%d\n", ans);
		memset(s, 0, sizeof(s));
	}
	return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const double PI = acos(-1);

//dp[i][j] : 
//先頭i文字として考えられるのものうち,
//13で割った余りがjであるもの.
ll dp[MAX_N][13];

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int a, b, c;
	cin >> a >> b >> c;

	if (a <= c && c <= b) {
		out("Yes");
	}
	else {
		out("No");
	}

	return 0;
}

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

using namespace std;
const string temp = "01+-*()";
int f1(int&, bool&);
int f2(int&, bool&);
int f3(int&, bool&);

vector< int > undefined;
string S;

bool isout(int val)
{
  return(val < 0 || val >= 1024);
}
int f1(int& idx, bool& f)
{
  int val = f2(idx, f);

  while(S[idx] == '+' || S[idx] == '-') {
    if(S[idx] == '+') {
      ++idx;
      val += f2(idx, f);
    } else {
      ++idx;
      val -= f2(idx, f);
    }
    if(isout(val)) throw(1);
    f = true;
  }
  return (val);
}

int f2(int& idx, bool& f)
{
  int val = f3(idx, f);

  while(S[idx] == '*') {
    idx++;
    val *= f3(idx, f);
    if(isout(val)) throw(1);
    f = true;
  }
  return (val);
}

int f3(int& idx, bool& f)
{
  int val = 0;
  if(S[idx] == '(') {
    ++idx;
    int now = idx;
    bool flag = false;
    val = f1(idx, flag);
    if(!flag) throw(1);
    ++idx;
    return (val);
  } else if(isdigit(S[idx])) {
    while(isdigit(S[idx])) {
      val = val * 2 + S[idx] - '0';
      ++idx;
      if(isout(val)) throw(1);
    }
  } else {
    throw (1);
  }
  return (val);
}

int make(int idx)
{
  int ret = -1;
  if(idx == undefined.size()) {
    try {
      int pos = 0;
      bool f = false;
      int val = f1(pos, f);
      if(pos + 1 != S.size()) throw (1);
      ret = max(ret, val);
    } catch(int e) {}
  } else {
    for(char c : temp) {
      S[undefined[idx]] = c;
      ret = max(ret, make(idx + 1));
    }
  }
  return (ret);
}

int main()
{
  cin >> S;
  S += "~";
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == '.') undefined.push_back(i);
  }
  cout << make(0) << endl;
}

Measured memory_bytes: 3296
S= input()
for i in range(len(S)):
  if (i+1)%2==0 and (S[i]=="L" or S[i]=="U" or S[i]=="D"):
    continue
  elif (i+1)%2==1 and (S[i]=="R" or S[i]=="U" or S[i]=="D"):
    continue
  else:
    print("No")
    exit()
print("Yes")

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

int main() {
  int N, A, B;
  cin >> N >> A >>B;
  int c;
  c = N * A;
  if(B < c){ 
    cout << B << endl;
  
  }
  
  else{
    cout << c << endl;
  }



}

Measured memory_bytes: 3604
#include <complex>
#include <cstdio>
#include <cmath>
using namespace std;

// ?????§?¨?????????¨??????
typedef complex<double> P;

//XY??§?¨?
#define X real()
#define Y imag()

// ??´???p1,p2??¨??????p3,p4???????????????
// (n < 0)<=>?????? , (n == 0)<=>??´??????, (n > 0)<=>?????????????????????  
double isIntersect(P p1, P p2, P p3, P p4){  
    return ( (p1.X-p2.X)*(p3.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p3.X)) * ((p1.X-p2.X)*(p4.Y-p1.Y) + (p1.Y-p2.Y)*(p1.X-p4.X));  
}

int main(){
	double xa, xb, xc, xd, ya, yb, yc, yd;

	while( scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf", &xa, &ya, &xb, &yb, &xc, &yc, &xd, &yd) != EOF ){
		P a( xa , ya );
		P b( xb , yb );
		P c( xc , yc );
		P d( xd , yd );
		
		if( isIntersect(a,c,b,d) > 0.0 || isIntersect(b,d,a,c) > 0.0 ){
			printf("NO\n");
		}else{
			printf("YES\n");
		}
	}
}

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

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

    if (!K) return cout << 1LL * N * N << endl, 0;

    long long cnt = 0;
    for (int b = 1; b <= N; b++) {
        cnt += 1LL * N / b * max(0, b - K) + max(0, N % b - K + 1);
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0);cout<<fixed<<setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

#define pii pair<int,int>
#define ff first
#define ss second
#define endll '\n'

using ll = long long int;
using intt = long long int;

int main()
{
    ll n;cin>>n;
    set<string>ss;
    while(n--)
    {
        string s;cin>>s;
        ss.insert(s);
    }
    cout<<ss.size()<<endll;
}


Measured memory_bytes: 19236
#include <iostream>
#include <cmath>

using namespace std;

int n;

int main() {
	int t1 = 0, t2 = 0;
	int a1 = 0, a2 = 0;
	int b1= 0, b2 = 0;

	cin >> n;
	for (int i = 1; i <= n; i ++) {
		cin >> t1 >> a1 >> b1;
		int s = (int)abs((a1 - a2) + (b1 - b2));
		if (s > (t1 - t2) || ((s % 2) != ((t1 - t2) % 2))) {
			cout << "No" << endl;

			return 0;
		}
		a2 = a1;
		b2 = b1;
		t2 = t1;
	}
	cout << "Yes" << endl;

	return 0;
}

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

using namespace std;

#define int long long

const int big = 1e18;

void solve() {
    int n;
    cin >> n;
    pair <int, int> a[n];
    for (int i = 0; i < n; ++i) cin >> a[i].first >> a[i].second;
    int ans = 0;
    vector <int> b(n);
    for (int i = 0; i < n; ++i) b[i] = a[i].first + big + a[i].second + big;
    sort(b.begin(), b.end());
    ans = b[n - 1] - b[0];
    for (int i = 0; i < n; ++i) b[i] = big - a[i].first + a[i].second + big;
    sort(b.begin(), b.end());
    ans = max(ans, b[n - 1] - b[0]);
    cout << ans;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0;
}


Measured memory_bytes: 7948
import sys
input = sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log
from heapq import heapify, heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from decimal import Decimal
inf = float('inf')
MOD = 1000000007
def INT_(n): return int(n) - 1
def MI(): return map(int, input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n: int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')

n, m, q = MI()
abcd = LLIN(q)

arr = []
def dfs(A: list):
    if len(A) == n:
        arr.append(A)
        return
    
    if len(A) == 0:
        s = 1
    else:
        s = A[-1]
    
    while s <= m:
        dfs(A + [s])
        s += 1
       

def main():
    dfs([])
    ans = 0
    for A in arr:
        tmp = 0
        for a,b,c,d in abcd:
            if A[b-1] - A[a-1] == c:
                tmp += d
        ans = max(ans, tmp)
    
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 97808
#include <stdio.h>

int main(void)
{
	int N = 0,W = 0,S = 0,E = 0;
	int i = 0,j = 0;
	char str[1001] = "\0";
	
	scanf("%s",str);
	
	for(i = 0;i < 1001;i++){
		if(str[i] == 'N')
			N++;
		else if(str[i] == 'W')
			W++;
		else if(str[i] == 'S')
			S++;
		else if(str[i] == 'E')
			E++;
		else
			break;
	}
	
	if((N == 0 && S != 0) || (S == 0 && N != 0) || (W == 0 && E != 0) || (E == 0 && W != 0))
		printf("No\n");
	else
		printf("Yes\n");
	
	return 0;
}

Measured memory_bytes: 128
import math

N, W = map(int,input().split(' ') )
#print(N,W)
v=[]
w=[]

for i in range(N):
    v1,w1 =map(int,input().split(' ') )
    v.append(v1)
    w.append(w1)
    
inf = 0
# dp[i]: i番目以降の最大のvalue
dp = [ [ inf for j in range(W+1) ] for i in range(N+1) ]

for i in range(N):
    for j in range(W+1):
        #print(i)
        if j >= w[i]:
            dp[i+1][j]=max( dp[i][j] , dp[i][j-w[i]]+v[i] )
        else:
            dp[i+1][j]=dp[i][j]
        #print(i,j,dp[i+1][j])

print(dp[N][W])



Measured memory_bytes: 25776
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF=1LL<<60;

ll n,d;

int main(){
    cin>>n>>d;
    vector<ll> x(n),y(n);
    rep(i,0,n) cin>>x[i]>>y[i];
    int ans=0;
    rep(i,0,n){
        ll dis=x[i]*x[i]+y[i]*y[i];
        if(dis<=d*d) ans++;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 6372
import re
n=int(input())
A=[]
for i in range(n):
    B=["."]*n
    for x,y in [list(map(int,input().split())) for k in range(int(input()))]:
        B[x-1]=str(y)
    A.append("".join(B))
ans=0
for i in range(2**n):
    num=format(i,"b").zfill(n)
    cnt,flag=0,1
    for k,j in enumerate(num):
        result=re.search(r"".join(A[k]),num)
        if result is not None and j=="1":
            cnt +=1
        elif (result is not None and j=="0") or (result is None and j=="1"):
            flag=0
            break
    if flag:
        ans=max(ans,cnt)
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	int a, b;
	cin >> a >> b;
	a %= 500;
	if (a > b){
		cout << "No" << endl;
	}
	else{
		cout << "Yes" << endl;
	}
	return 0;
}


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

Measured memory_bytes: 580
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static int depth(int cur, int[] visited, boolean visiting[], boolean[][] adj){
		if(visited[cur] != -1){
			return visited[cur];
		}
		
		if(visiting[cur]){
			return Integer.MIN_VALUE;
		}
		visiting[cur] = true;
		
		int deep = 0;
		for(int i = 0; i < adj[cur].length; i++){
			if(!adj[cur][i]){
				continue;
			}
			
			deep = Math.max(deep, depth(i, visited, visiting, adj));
		}
		
		visiting[cur] = false;
		
		//System.out.println(cur + " => " + (deep + 1));
		
		return visited[cur] = deep + 1;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[] h_1 = new int[n];
			int[] r_1 = new int[n];
			
			for(int i = 0; i < n; i++){
				h_1[i] = sc.nextInt();
				r_1[i] = sc.nextInt();
			}
			
			final int m = sc.nextInt();
			
			int[] h_2 = new int[m];
			int[] r_2 = new int[m];

			for(int i = 0; i < m; i++){
				h_2[i] = sc.nextInt();
				r_2[i] = sc.nextInt();
			}
			
			final int size = n + m;
			
			int[] h_c = new int[size];
			int[] r_c = new int[size];
			
			boolean[][] adj = new boolean[size][size];
			
			for(int i = 0; i < size; i++){
				h_c[i] = i < n ? h_1[i] : h_2[i - n];
				r_c[i] = i < n ? r_1[i] : r_2[i - n];
			}
			
			//outer
			for(int i = 0; i < size; i++){
				//inner
				for(int j = 0; j < size; j++){
					if(h_c[i] > h_c[j] && r_c[i] > r_c[j]){
						adj[i][j] = true;
					}
				}
			}
			
			int[] visited = new int[size];
			Arrays.fill(visited, -1);
			int max = Integer.MIN_VALUE;
			boolean[] visiting = new boolean[size];
			for(int i = 0; i < size; i++){
				if(visited[i] >= 0){
					continue;
				}
				
				max = Math.max(max, depth(i, visited, visiting, adj));
			}
			
			System.out.println(max);
		}
		
	}

}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;

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

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = unsigned long long;
template<class T>bool CHMAX(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool CHMIN(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int n; cin >> n;
  ll a[n], ans = 1;

  REP(i,n) {
    cin >> a[i];
    if (a[i] == 0) { COUT(0); return 0; }
  }

  REP(i,n) {
    if (a[i] > LINF / ans) { COUT(-1); return 0; }
    ans *= a[i];
  }

  COUT(ans);
  return 0;
}

Measured memory_bytes: 4380
#include <iostream>
#include <algorithm>

using namespace std;

int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = min(a, b); i > 0; i--) {
		if (a % i == 0 && b % i == 0)
			k--;
		if (k == 0) {
			cout << i << "\n";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}

func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}

func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a := Scan()
	b := Scan()
	if len(a) > len(b) {
		fmt.Println("GREATER")
	} else if len(a) < len(b) {
		fmt.Println("LESS")
	} else {
		ans := "EQUAL"
		for i := 0; i < len(a); i++ {
			if stringToInt(string(a[i])) > stringToInt(string(b[i])) {
				ans = "GREATER"
				break
			} else if stringToInt(string(a[i])) < stringToInt(string(b[i])) {
				ans = "LESS"
				break
			}
		}
		fmt.Println(ans)
	}
}


Measured memory_bytes: 1776
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"

def main():
    h,n = map(int,ipt().split())
    atks = [tuple(map(int,ipt().split())) for i in range(n)]
    dam = [10**18]*(h+1)
    dam[0] = 0
    for i in range(1,h+1):
        for aj,bj in atks:
            if aj > i:
                if dam[i] > bj:
                    dam[i] = bj
            elif dam[i] > dam[i-aj]+bj:
                dam[i] = dam[i-aj]+bj

    print(dam[h])

    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 75576
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll Mypow(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

ll digit(ll x){
  ll res = 0;
  while(x > 0){
    res++;
    x /= 10;
  }
  return res;
}


ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};


int main(){
  ll N; cin >> N;
  vector<ll> div = divisor(N);
  ll ans = INF;
  rep(i, div.size()) ans = min(ans, max(digit(div[i]), digit(N/div[i])));
  cout << ans << endl;
}


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

typedef long long ll;

/* メモリ食い過ぎ注意 */
#define int ll
#define ALL(v) v.begin(), v.end()
#define _REP(i, n) for (int i = 0; i < n; i++)
#define REP(n) _REP(i, n)

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

std::vector<int> enum_div(int n)
{
    std::vector<int> ret;
    for (int 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);
            }
        }
    }
    ret.push_back(n);
    return ret;
}

signed main()
{
    ll n;
    cin >> n;

    vector<int> v = enum_div(n);
    sort(v.begin(), v.end());

    int sum = 0;
    for (int i = 0; i < v.size(); i++)
    {
        if (v[i] - 1 >= n)
            break;
        if (v[i] - 1 > 2 && n / (v[i] - 1) == n % (v[i] - 1))
        {
            // cout << "=" << v[i] - 1 << " ";
            sum += (v[i] - 1);
        }
        // cout << v[i] << " ";
        // endl;
    }
    // cout << endl;

    cout << sum << endl;
}

Measured memory_bytes: 384
class Tree:
    root = None

    def insert(self, node):
        y = None
        x = self.root
        while x:
            y = x
            x = x.left if node.key < x.key else x.right

        if not y:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

    def print(self):
        print(' ', end='')
        print(*self.root.print_in())
        print(' ', end='')
        print(*self.root.print_pre())


class Node:
    def __init__(self, key):
        self.left = None
        self.right = None
        self.key = key

    def print_pre(self):
        yield self.key
        if self.left:
            for k in self.left.print_pre(): yield k
        if self.right:
            for k in self.right.print_pre(): yield k

    def print_in(self):
        if self.left:
            for k in self.left.print_in(): yield k
        yield self.key
        if self.right:
            for k in self.right.print_in(): yield k


tree = Tree()
m = int(input())

while m:
    l = input().split()
    if len(l) == 2:
        tree.insert(Node(int(l[1])))
    else:
        tree.print()
    m -= 1

Measured memory_bytes: 114824
h,w=map(int,input().split())
grid=[list(input()) for _ in range(h)]

def hantei(i,j,grid):
  flag=False
  if i>0:
    flag=flag or grid[i-1][j]=='#'
  if j>0:
    flag=flag or grid[i][j-1]=='#'
  if i<h-1:
    flag=flag or grid[i+1][j]=='#'
  if j<w-1:
    flag=flag or grid[i][j+1]=='#'
  return flag

for i in range(h):
  for j in range(w):
    if grid[i][j]=='.':
      continue
    if hantei(i,j,grid)==False:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 39408
package main

import(
    "fmt"
)



func main() {
    var n int
    fmt.Scan(&n)
    var v,c = make([]int,n),make([]int,n)
    for i:=0; i<n; i++{
        fmt.Scan(&v[i])
    }
    for i:=0; i<n; i++{
        fmt.Scan(&c[i])
    }
    ans := -10000000
    for i:=0; i<(1<<uint(n)); i++{
        sumv:=0
        sumc:=0
        for j:=0; j<n; j++{
            if (i>>uint(j))&1 == 1{
                sumv += v[j]
                sumc += c[j]
            }
        }
        ans = max32(ans, sumv-sumc)
    }
    fmt.Println(ans)
}





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

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}


Measured memory_bytes: 512
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

const int maxn = 1e5 + 7;
const LL mod = 1e9 + 7;

LL fac[maxn],finv[maxn],inv[maxn];
LL a[maxn];

void Cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2 ; i < maxn ; i++) {
        fac[i] = (fac[i-1]*i)%mod;
        inv[i] = mod - (inv[mod%i]*((mod/i)))%mod;
        finv[i] = (finv[i-1]*inv[i])%mod;
    }
}

LL Com(int n,int m) {
    if(n < m) return 0;
    if(n < 0 || m < 0) return 0;
    return (fac[n]*((finv[m]*finv[n-m])%mod))%mod;
}

int main() {
    Cominit();
//    for(int i = 0 ; i <= 6 ; i++) {
//        for(int j = 0; j <= i ; j++) {
//            cout << Com(i,j) << " ";
//        }
//        cout << endl;
//    }
	int n,k;
	while(~scanf("%d%d",&n,&k)) {
        for(int i = 1 ; i <= n ; i++) {
            scanf("%lld",&a[i]);
        }
        sort(a+1,a+n+1);
        LL MIN = 0 , MAX = 0;
        for(int i = k ; i <= n ; i++) {
//            cout << Com(i-1,k-1) << " ";
            MAX = ((MAX%mod) + (Com(i-1,k-1)*a[i])%mod)%mod;
        }
//        cout << endl;
        for(int i = 1 ; i <= n - k + 1 ; i++) {
            MIN = ((MIN%mod) + (Com(n-i,k-1)*a[i])%mod)%mod;
        }
//        cout << MAX << " " << MIN << endl;
        printf("%lld\n",(MAX - MIN + mod)%mod);
	}
	return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#define N 10000
using namespace std;
struct s{
  int d;
  int p;
  int dcnt;
};
int main(){
  int n,m,i,j,flag,kitaiti;
  struct s data[N];
  while(1){
    flag=0;
    kitaiti=0;
    cin >> n >> m;
    if(n==0&&m==0) break;
    for(i=0;i<n;i++){
      cin >> data[i].d >> data[i].p;
      data[i].dcnt=data[i].d;
    }
    for(i=0;i<n;i++){
      for(j=1;j<n;j++){
	if(data[j].p>data[j-1].p) swap(data[j],data[j-1]);
      }
    }
    for(i=0;i<n;i++){
      if(flag==0){
	if(m>=data[i].dcnt) m-=data[i].dcnt;
	else{
	  flag=1;
	  kitaiti=(data[i].dcnt-m)*data[i].p;
	}
      }
      else{
	kitaiti=kitaiti+data[i].dcnt*data[i].p;
      }
    }
    cout << kitaiti << endl;
  }
  return 0;
}

Measured memory_bytes: 1276
A,B = map(int,input().split())
S = input()
flag = True
k = [str(i) for i in range(10)]
for i in range(A):
    if S[i] in k:
        continue
    else:
        flag = False
if S[A]=='-':
    pass
else:
    flag = False

for i in range(B):
    if S[A+1+i] in k:
        continue
    else:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

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

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> tree(N, vector<int>());
    vector<int> A(N);
    vector<int> B(N);
    for(int i=0;i<N-1;i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        tree[A[i]].push_back(B[i]);
        tree[B[i]].push_back(A[i]);
    }
    int root = distance(tree.begin(), max_element(tree.begin(), tree.end(), [](vector<int> a, vector<int> b){ return a.size() < b.size();}));
    map<array<int,2>,int> color;
    queue<array<int,2>> q;
    q.push(array<int,2>{root, -1});
    set<int> used;
    while(!q.empty()){
        auto v = q.front(); q.pop();
        used.insert(v[0]);
        int c = 1;
        for(auto e : tree[v[0]]){
            if (used.count(e)) continue;
            auto v1 = min(v[0], e);
            auto v2 = max(v[0], e);
            if (c==v[1]) c++;
            color[array<int,2>{v1, v2}] = c;
            q.push(array<int,2>{e,c});
            c++;
        }
    }

    cout<<tree[root].size()<<endl;
    for(int i=0;i<N-1;i++){
        auto v1 = min(A[i], B[i]);
        auto v2 = max(A[i], B[i]);
        cout<<color[array<int,2>{v1, v2}]<<endl;
    }

    return 0;
}

Measured memory_bytes: 17792
#ランレングス圧縮とは RLE(Run Length Encoding)とも言われます。
#連続したデータを、ひとつ分のデータと連続した長さで表現します。
def rle(s):
    tmp, count, ans_c,ans_n = int(s[0]),1,[] , []
    for i in range(1,len(s)):
        if tmp == int(s[i]):
            count += 1
        else:
            ans_c.append(tmp)
            ans_n.append(count)
            tmp = int(s[i])
            count = 1
    ans_c.append(tmp)
    ans_n.append(count)
    return ans_c,ans_n

# 初期入力
import sys
input = sys.stdin.readline
N,K = (int(x) for x in input().split())
S =input().strip()

#0と1が何回続くか
a_c,a_n =rle(S)
a_len =len(a_c)
a_n +=[0]
count =[0]*a_len
ans =0

#
if K >= (a_len +1)//2:
    ans =N
elif a_len==2:
    ans =N
elif a_len ==3 and a_c[0]==1:
    ans=N
else:
    if a_c[0] ==1:
        i=2
        indx =i +2*K 
        count[0] =sum(a_n[:0 +2*K +1])
        while not(indx ==a_len+2 or indx ==a_len+1):
            count[i] =count[i-2] -a_n[i-2] -a_n[i-1] + a_n[indx-1] +a_n[indx]
            i +=2
            indx =i +2*K 
    else:
        count[0] =sum(a_n[:2*K])
        count[1] =sum(a_n[1: 1+2*K+1])
        i=3
        indx =i +2*K 
        while not(indx ==a_len+2 or indx ==a_len+1):
            count[i] =count[i-2] -a_n[i-2] -a_n[i-1] + a_n[indx-1] +a_n[indx]
            i +=2      
            indx =i +2*K 
    ans =max(count)
print(ans)

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

using namespace std;

int n, ans, b[99];

int main(){
	cin >> n;
	for(int i = 0; i < n - 1; ++i) cin >> b[i];
	ans += b[0] + b[n-2];
	for(int i = 1; i < n - 1; ++i) ans += min(b[i-1], b[i]);
	cout << ans << endl;
}

Measured memory_bytes: 256
/*
* @Author Silviase(@silviasetitech)
* For ProCon
*/

import java.util.*;
import java.lang.*;
import java.math.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] num = new int[n+1];
        int ans = 0;
        int tmp;
        num[0] = 10000000;
        for (int i = 1; i <= n; i++) {
            num[i] = sc.nextInt();
        }
        for (int i = 1; i <= n; i++) {
            if (i == n) {
                if (num[i] == i) {
                    tmp  = num[i];
                    num[i] = num[i-1];
                    num[i-1] = tmp;
                    ans++;
                }
            } else {
                if (num[i] == i) {
                    tmp  = num[i];
                    num[i] = num[i+1];
                    num[i+1] = tmp;
                    ans++;
                }
            }
        }
        System.out.println(ans);

        sc.close();
    }

}

Measured memory_bytes: 50864
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 2e5+10;
char s[N];
vector<int>a[26];
int n, f[N], num[N];
long long ans;
inline int lowbit(int x){return x&-x;}
inline void add(int x,int k)
{
	while(x<=n)
	{
		f[x]+=k;
		x+=lowbit(x);
	}
	return ;
}
inline int sum(int x)
{
	int ans=0;
	while(x)
	{
		ans+=f[x];
		x-=lowbit(x);
	}
	return ans;
}
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1; i<=n; i++)
	{
		a[s[i]-'a'].push_back(i);
		add(i, 1);
	}
	for(int i=0; i<26; i++)
		if(a[i].size()&1)ans++;
	if(ans>1)
	{
		puts("-1");
		return 0;
	}
	else ans=0;
	for(int i=0; i<26; i++)
		for(int j=0; j<(int)a[i].size(); j++)
			num[a[i][j]]=a[i][a[i].size()-j-1];
	for(int i=1; i<=n; i++)
	{
		ans+=sum(n)-sum(num[i]);
		add(num[i], -1);
	}
	printf("%lld",ans>>1);
	return 0;
}

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

double dp[301][301][301];

int32_t main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(10);
    int n,k;
    cin>>n>>k;
    int arr[n];
    for(int i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    int dp[k+1][n];
    memset(dp,0,sizeof(dp));
    for(int i=0; i<=k; i++)
    {
        if(arr[n-1] - i >=0)
            dp[i][n-1] = 1;
    }
    for(int i=n-2; i>=0; i--)
    {
        for(int j=0; j<=k; j++)
        {
            if(j>0)
            {
                dp[j][i] = dp[j-1][i];
                if(j-1-arr[i] >=0)
                    dp[j][i] -= dp[j-1-arr[i]][i+1];               
            }
            dp[j][i] += dp[j][i+1];
            dp[j][i] %= 1000000007;
            if(dp[j][i] < 0)
                dp[j][i] += 1000000007;
            //cout<<dp[j][i]<<" "<<j<<" "<<i<<endl;
        }
    }
    cout<<dp[k][0];
    return 0;
}

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


int main() {
  string s;
  string res = "A";

  getline(cin, s);

  for(uint i = 7; i < s.size(); i++) {
    if(s.at(i) >= 'A' && s.at(i) <= 'Z') {
      res += s.at(i);
      res += "C";
      break;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    ll N,X;
    cin >> N >> X;
    ll x[N+1];
    x[0] = X;
    rep(i,N) cin >> x[i+1];
    sort(x,x+N+1);
    ll A[N];
    rep(i,N) A[i] = x[i+1]-x[i];
    sort(A,A+N);
    ll out = A[0];
    rep(i,N){
        if(A[i]%out!=0) out = __gcd(A[i],out);
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

long long int Ans[101];

int main(void) {
	int Q;
	long long int A, B;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A >> B;
		if (A > B) {
			long long int temp = A;
			A = B;
			B = temp;
		}
		long long int C = (long long int)sqrt(A * B);
		if (C * C == A * B) {
			C--;
		}
		long long int ans = 0;
		if (A == B || A + 1 == B) {
			ans = 2 * A - 2;
		}
		else if (C * (C + 1) < A * B) {
			ans = 2 * C - 1;
		}
		else {
			ans = 2 * C - 2;
		}
		Ans[i] = ans;
	}
	for (int i = 0; i < Q; i++) {
		cout << Ans[i] << endl;
	}
	//system("pause");
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author RiaD
 */

#include <iostream>
#include <fstream>

#include <iostream>
//#define PROBLEM "problem_name.h"
//#include PROBLEM
//#include <message.h>
//#include <spcppl/dgcj.h>

using namespace std;

class TaskA {
public:
	void solve(std::istream& in, std::ostream& out) {
		string s;
		in >> s;
		out << s.substr(0, s.size() - string("FESTIVAL").size());
	}
};


int main() {
	std::ios_base::sync_with_stdio(false);
	TaskA solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
	out << std::fixed;
	out.precision(20);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int n,T,ans=-1,i;
  cin >>n>>T;
  vector<int>c(n,0);
  vector<int>t(n,0);
  for(i=0;i<n;i++)cin>>c.at(i)>>t.at(i);
  for(i=0;i<n;i++){
    if(T>=t.at(i)){
      if(ans==-1){
        ans=c.at(i);
      }
      else if(ans>c.at(i))ans=c.at(i);
    }
  }
  if(ans==-1)cout<<"TLE"<<endl;
  else cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>

template<class T> inline bool chmin(T& a, T b) {
  if ( a > b ) {
    a = b;
    return true;
  }
  return false;
}

const long long INF = 1LL << 60;
const long MAX_NUM = 100010;
const int MAX_INDEX = 7;

int main()
{
  int N;
  std::cin >> N;
  std::vector<long long> dp(MAX_NUM, INF);
  dp[0] = 0;
  for ( int now = 0; now <= N; now++ ) {
    chmin(dp[now + 1], dp[now] + 1);
    for ( int i = 1; i <= MAX_INDEX; i++ ) {
      if (now + std::pow(6, i) <= MAX_NUM) chmin(dp[now + std::pow(6, i)], dp[now] + 1);
      if (now + std::pow(9, i) <= MAX_NUM) chmin(dp[now + std::pow(9, i)], dp[now] + 1);
    }
  }
  std::cout << dp[N] << std::endl;
  return 0;
}


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

int main(void)
{
  int n;
  string s;
  cin >> n;
  cin >> s;
  if(n % 2 == 1)
  {
    cout << "No" << endl;
    return (0);
  }
  string c = s;
  
  for(int i = 0; i < n/2; i++)
  {
    if(n % 2 == 0)
    {
      if(c.at(i) != s.at(n/2 + i))
      {
        cout << "No" << endl;
        return (0);
      }
    }else{
      if(c.at(i) != s.at(n/2 + i + 1))
      {
        cout << "No" << endl;
        return (0);
      }
    }
  }
  cout << "Yes" << endl;
}

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

class Program
{
    public void slove()
    {
        var inputs = Console.ReadLine().Split();
        int n = int.Parse(inputs[0]);
        int m = int.Parse(inputs[1]);
        var result = Enumerable.Range(1, m);
        foreach(int i in Enumerable.Range(0, n))
        {
            var lst = Console.ReadLine().Split().Skip(1).Select(int.Parse);
            result = result.Where(x => lst.Contains(x));
        }
        System.Console.WriteLine(result.Count());
    }
    
    static void Main(string[] args)
    {
        new Program().slove();
    }
}


Measured memory_bytes: 13408
#include <cstdio>
#include <algorithm>
typedef long long int64;
static const int MAXN = 50;

int64 k;
int64 a[MAXN];

int main()
{
    scanf("%lld", &k);
    for (int i = 0; i < MAXN; ++i) a[i] = k / MAXN;
    for (int i = 0; i < k % MAXN; ++i) ++a[i];

    printf("%d\n", MAXN);
    for (int i = 0; i < MAXN; ++i) {
        int64 sel = a[i], unsel = k - a[i];
        printf("%lld%c", (int64)MAXN - 1 - unsel + sel * MAXN, i == MAXN - 1 ? '\n' : ' ');
    }

    return 0;
}


Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>

#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

int main()
{
    int r;
    cin >> r;
    cout << r * r << endl;
}

Measured memory_bytes: 256
from sys import stdin
import numpy as np
a,b,c,x,y= [int(x) for x in stdin.readline().rstrip().split()]

if x >= y:
    print(min(a*x+b*y,c*2*y+a*(x-y),c*2*x))
else:
    print(min(a*x+b*y,c*2*x+b*(y-x),c*2*y))

Measured memory_bytes: 12508