akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
#define INF 1e9
#define PI (acos(-1))
#define mod (int)1e9+7
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
int main() {
    string n;
    cin>>n;
    int d=n.size();
    vector<int> v(d);
    int k;
    cin>>k;
    REP(i,d){
        v[i]=n[i]-'0';
    }
    int dp[101][2][101];//今見てる桁数,N未満フラグ,K=？
    Fill(dp,0);
    dp[0][0][0]=1;
    REP(i,d){
        REP(f,2){
            REP(j,d){
                for(int x=0; x<=(f ? 9 : v[i]); x++){
                    if(x!=0){
                        dp[i+1][f || x < v[i]][j+1]+=dp[i][f][j];
                    }
                    else {
                        dp[i+1][f || x < v[i]][j]+=dp[i][f][j];
                    }
                }
            }
        }
    }
    cout<<dp[d][0][k]+dp[d][1][k]<<endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int in[201000];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int k, n, i;
    cin >> k >> n;
    rep(i, n) {
        cin >> in[i];
    }
    int ans(-1);
    xrep(i, 1, n) {
        ans = max(ans, in[i] - in[i-1]);
    }
    ans = max(ans, k - in[n-1] + in[0]);
    cout << k - ans << endl;
}


Measured memory_bytes: 1024
A,B = map(int,input().split())
def xor(n):
  m = 0
  if n % 4 == 0:
    m = n
  elif n % 4 == 1:
    m = 1
  elif n % 4 == 2:
    m = n + 1
  return m
a = xor(A-1)
b = xor(B)
print(a ^ b)

Measured memory_bytes: 3060
from collections import deque
N, C = map(int, input().split())
que = []
Que = []
channel = [[] for i in range(C+1)]
for i in range(N):
    s, t, c = map(int, input().split())
    channel[c].append((s, t))
for i in range(C+1):
    channel[i].sort()
    tmp_que = deque(channel[i])
    left_que = deque([])
    if tmp_que:
        x, y = tmp_que.popleft()
        left_que.append((x, y))
        while tmp_que:
            lx, ly = left_que.pop()
            rx, ry = tmp_que.popleft()
            if ly == rx:
                left_que.append((lx, ry))
            elif ly < rx:
                left_que.append((lx, ly))
                left_que.append((rx, ry))
    for x, y in left_que:
        Que.append((2*x-1, 1))
        Que.append((2*y, -1))
ans = 0
value = 0
Que.sort(reverse=True)
while Que:
    v, command = Que.pop()
    value += command
    ans = max(ans, value)
print(ans)



Measured memory_bytes: 45040
package main

import (
	"bufio"
	"errors"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

// NextLine reads a line text from stdin, and then returns its string.
func NextLine() string {
	sc.Scan()
	return sc.Text()
}

// NextIntsLine reads a line text, that consists of **ONLY INTEGERS DELIMITED BY SPACES**, from stdin.
// And then returns intergers slice.
func NextIntsLine() []int {
	ints := []int{}
	intsStr := NextLine()
	tmp := strings.Split(intsStr, " ")
	for _, s := range tmp {
		integer, _ := strconv.Atoi(s)
		ints = append(ints, integer)
	}
	return ints
}

func NextStringsLine() []string {
	strs := []string{}
	stringsStr := NextLine()
	tmp := strings.Split(stringsStr, " ")
	for _, s := range tmp {
		strs = append(strs, s)
	}
	return strs
}

// NextRunesLine reads a line text, that consists of **ONLY CHARACTERS ARRANGED CONTINUOUSLY**, from stdin.
// Ant then returns runes slice.
func NextRunesLine() []rune {
	return []rune(NextLine())
}

// Max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// Min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func Min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// PowInt is integer version of math.Pow
func PowInt(a, e int) int {
	if a < 0 || e < 0 {
		panic(errors.New("[argument error]: PowInt does not accept negative integers"))
	}
	fa := float64(a)
	fe := float64(e)
	fanswer := math.Pow(fa, fe)
	return int(fanswer)
}

// AbsInt is integer version of math.Abs
func AbsInt(a int) int {
	fa := float64(a)
	fanswer := math.Abs(fa)
	return int(fanswer)
}

// DeleteElement returns a *NEW* slice, that have the same and minimum length and capacity.
// DeleteElement makes a new slice by using easy slice literal.
func DeleteElement(s []int, i int) []int {
	if i < 0 || len(s) <= i {
		panic(errors.New("[index error]"))
	}
	// appendのみの実装
	n := make([]int, 0, len(s)-1)
	n = append(n, s[:i]...)
	n = append(n, s[i+1:]...)
	return n
}

// Concat returns a *NEW* slice, that have the same and minimum length and capacity.
func Concat(s, t []rune) []rune {
	n := make([]rune, 0, len(s)+len(t))
	n = append(n, s...)
	n = append(n, t...)
	return n
}

// sort package (snippets)
//sort.Sort(sort.IntSlice(s))
//sort.Sort(sort.Reverse(sort.IntSlice(s)))
//sort.Sort(sort.Float64Slice(s))
//sort.Sort(sort.StringSlice(s))

// copy function
//a = []int{0, 1, 2}
//b = make([]int, len(a))
//copy(b, a)

/*******************************************************************/

var k, s int

func main() {
	tmp := NextIntsLine()
	k, s = tmp[0], tmp[1]
	answer := 0
	for x := 0; x <= k; x++ {
		for y := 0; y <= k; y++ {
			z := s - x - y
			if 0 <= z && z <= k {
				answer++
			}
		}
	}
	fmt.Println(answer)
}


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

using namespace std;

int main() {
	string s;
	int n;
	cin >> s;
	n = (int)s.length();
	for (int i = 0; i < n; i += 2) {
		if (s[i] == 'L') {
			cout << "No" << endl;
			return 0;
		}
		else if (s[i + 1] == 'R') {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int m = max(max(a,b),c);

    int cnt = 0;
    bool pl;
    for (int i = 0; i < 2; i++){
        int a_sub = m - a;
        int b_sub = m - b;
        int c_sub = m - c;
        if ((a_sub + b_sub + c_sub) % 2 == 0){
            while(a_sub != 1 && a_sub != 0){
                cnt++;
                a_sub -= 2;
            }
            while(b_sub != 1 && b_sub != 0){
                cnt++;
                b_sub -= 2;
            }
            while(c_sub != 1 && c_sub != 0){
                cnt++;
                c_sub -= 2;
            }
            if (a_sub == 1 || b_sub == 1 || c_sub == 1){
                pl = true;
            }else {
                pl = false;
            }
            break;
        }
        m++;
    }
    if (pl){
        cout << cnt + 1 << endl;
    }else {
        cout << cnt << endl;
    }
}


Measured memory_bytes: 256
n, k = gets.split.map(&:to_i)
h = n.times.map do
  gets.to_i
end.sort
i = 0
j = k-1
min = h[j] - h[i]
while j < h.length
  min = [h[j] - h[i], min].min
  j += 1
  i += 1
end

puts min

Measured memory_bytes: 4656
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl;
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

int main() {
	bool first = true;
	while (true) {
		int n; cin >> n;
		if (n == 0)break;

		if (!first)puts("");
		first = false;

		vector<pair<int, pair<int, string>>> ans;
		rep(i, n) {
			string s; int a, b, c;
			cin >> s >> a >> b >> c;
			ans.pb(mp(a * 3 + c, mp(n - i, s)));
		}
		SORT(ans); REVE(ans);

		rep(i, n) {
			cout << ans[i].second.second << "," << ans[i].first << endl;
		}
	}
}


Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define ft first
#define sd second
#define mp make_pair
#define fr(i,n) for(int i=0;i<(n);i++)
#define Fr(i,n) for(int i=0;i++<(n);)
#define ifr(i,n) for(int i=(n)-1;i>=0;i--)
#define iFr(i,n) for(int i=(n);i>0;i--)
ll n,u,v,w;
vector<P> e[100010];
bool vis[100010]={},cl[100010];

void rec(int i=1,bool c=0){
    if(vis[i]) return;
    vis[i]=1;
    cl[i]=c;
    for(auto a:e[i]){
        if(vis[a.ft]) continue;
        if(a.sd%2){
            rec(a.ft,!c);
        }
        else{
            rec(a.ft,c);
        }
    }
}

int main(){
    cin>>n;
    fr(i,n-1){
        cin>>u>>v>>w;
        e[u].pb(mp(v,w));
        e[v].pb(mp(u,w));
    }
    rec();
    Fr(i,n) cout<<cl[i]<<endl;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

void Main() {
    int n;
    cin >> n;
    cout << n * n * n << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,m,o;
    scanf("%d%d%d",&n,&m,&o);

    if(n==m&&n!=o)
        printf("Yes\n");
        else if(n==o&&n!=m)
            printf("Yes\n");
        else if(m==o&&m!=n)
            printf("Yes\n");
        else
            printf("No\n");
    return 0;


}


Measured memory_bytes: 128
n = int(input())
w = list(map(int, input().split()))
summa1 = 0
summa2 = 0
sum41 = sum(w)
minimal = 5000000

for i in range(n):
	summa1 = sum(w[0:i+1])
	summa2 = sum41-summa1
	if abs(summa1-summa2) < minimal:
		minimal=abs(summa1-summa2)

print(minimal)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N,L;
  cin >> N >> L;
  vector<int> vec(N);
  int eat;
  if (L > 0){
    eat = L;
  }
  
  else if ( L + N - 1 < 0){
    eat = L+N-1;
  }
  
  else{
    eat = 0;
  }
  
  cout << (L+L+N-1)*N/2 - eat << endl;
     
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int min = n;
        for (int i = 0; i <= n; i++) {
            int count = 0;
            int x = i;
            while (x > 0) {
                count += x % 6;
                x /= 6;
            }
            x = n - i;
            while (x > 0) {
                count += x % 9;
                x /= 9;
            }
            min = Math.min(min, count);
        }
		System.out.println(min);
	}
}


Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;



int MOD=1000000007;
int main(void){
	int N,ans=0;
	cin >> N;
	int d[N+10];
	for(int i=0; i<N; i++){
		cin >> d[i];
	}
	for(int i=0; i<N-1; i++){
		for(int j=i+1; j<N; j++){
			ans+=d[i]*d[j];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<string.h>
int main() {
	int x,y,z;
	int k,s;
	scanf("%d %d",&k,&s);
	int sum=0;
	for(x=0; x<=k; x++) {
		for(y=0; y<=k; y++) {
			if((s-x-y)<=k&&(s-x-y)>=0) {
				sum++;
			}
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstring>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sizeof(m))

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a = 0, b = 0, c = 0, d, e, ans = 0,j=0, n, ret = M, m, x = 0, y = 0;
	//bool x = false;
	string s,t;
	cin >> a >> b >> c >> d;
	rep(i, c - a) cout << "R";
	rep(i, d - b) cout << "U";
	rep(i, c - a) cout << "L";
	rep(i, d - b +1) cout << "D";
	rep(i, c - a + 1) cout << "R";
	rep(i, d - b + 1) cout << "U";
	cout << "LU";
	rep(i, c - a + 1) cout << "L";
	rep(i, d - b + 1) cout << "D";
	cout << "R\n";
	return 0;
}

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

using namespace std;

int main(void) {
    int L, R;
    cin >> L >> R;
    int end = min(R, L+2019);
    long long int ans = 1000000000;
    for(long long int i=L; i<end; i++) {
        for(long long int j=i+1; j<=end; j++) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

ll N;
ll cnt = -1;
vector<ll> divisor(ll n){
    vector<ll> res;
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i * i != n) res.push_back(n / i);
        }
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    vector<ll> vs = divisor(N);
    for(auto  u : vs){
        ll cp = N;
        if(u == 1) continue;
        while(cp >= u){
            if(cp % u == 0) cp /= u;
            else cp %= u;
        }
        if(cp == 1) cnt++;
    }

    vs = divisor(N - 1);
    cout << cnt + vs.size() << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
  int A, B;
  cin >> A >> B;

  int ans = 0;
  if(A==B) ans = A * 2;
  else ans = max(A,B) * 2 -1;

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main() {
	int n;
	cin >> n;

	long* a;
	a = new long[n];

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

	long r = 0;

	long t[100000] = { 0 };
	int c[100000] = { 0 };
	int num = 1;

	c[0] = 1;
	t[0] = a[0];

	for (int i = 1; i < n; i++) {
		bool b = false;

		if (n < a[i]) {
			r++;
			continue;
		}

		for (int j = 0; j < num; j++) {
			if (a[i] == t[j]) {
				c[j]++;
				b = true;
				break;
			}
		}
		if (!b) {

			t[num] = a[i];
			c[num] = 1;
			num++;
		}
	}

	for (int i = 0; i < num; i++) {
		if (t[i] < c[i]) {
			r += (c[i] - t[i]);
		}
		else if (t[i] > c[i]) {
			r += c[i];

		}
	}

	cout << r << endl;
	return 0;
}


Measured memory_bytes: 2176
def resolve():
    import sys
    input = sys.stdin.readline
    n, k = map(int, input().split())
    p = list(map(int, input().split()))
    p1 = list(map(lambda x: (x+1)/2, p))
    ans = 0
    if k==1:
        print(max(p1))
        exit()
    else:
        initial = sum(p1[0:k])
        if ans <= initial:
            ans = initial
            cal = initial
        for i in range(n-k):
            cal = cal-p1[i]+p1[i+k]
            if ans <= cal:
                ans = cal
    print(ans)
resolve()

Measured memory_bytes: 73480
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * (N+1)
for i, a in enumerate(A):
    B[i+1] = B[i] + a%K
for i in range(N+1):
    B[i] -= i
    B[i] %= K
ans = 0
# compress
C = B[::]
C.sort()
I = dict()
itmp = 0
I[C[0]] = 0
for i in range(1, N+1):
    if C[i] != C[i-1]:
        itmp += 1
        I[C[i]] = itmp

tbl = [0] * (N+1)
for i in range(min(K,N+1)):
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
for i in range(K, N+1):
    tbl[I[B[i-K]]] -= 1
    tbl[I[B[i]]] += 1
    ans += tbl[I[B[i]]] - 1
print(ans)


Measured memory_bytes: 117452
#include <algorithm>
#include <stdio.h>
#include <functional>
using namespace std;

int N, M, a[300004];

template<typename ...> static inline int gc(void) { return getchar(); }
static inline void read(int &x){int k=gc();x=0;for(;;k=gc()){if(isdigit(k)){x=k-48;break;}}for(;;){k=gc();if(!isdigit(k))break;x=x*10+k-48;}}

int main(){long long int r = 0;
    read(N);
    M = N;
    M += (N << 1);
    for(int i = 0; i ^ M; ++i){
        read(a[i]);
    }
    sort(a, a + M, greater<int>());
    N <<= 1;
    ++N;
    for(int i = 1; i ^ N; i += 2){
        r += a[i];
    }
    printf("%lld", r);
    return 0;
}


Measured memory_bytes: 1280
loop do 
    h, w = gets.chomp.split.map(&:to_i)
    if (h + w).zero?
        break
    end
    (0...h).each do |i|
        if i.between?(1, h - 2)
            puts '#' + '.' * (w - 2) + '#'
        else
            puts '#' * w
        end
    end
    puts
end


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

using namespace std;

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0;i<3;i++){
    	if(s[i]==t[i]) ans++;
	}
	cout << ans << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >> n;
    ll ans=1;
    vl v(n);
    rep(i,n)cin >> v[i];
    rep(i,n){
        if(!v[i])cout << 0 <<endl,exit(0);
    }
    rep(i,n){
        if(1000000000000000000/ans<v[i])cout << -1 <<endl,exit(0);
        ans*=v[i];
    }
    cout << ans <<endl;
}

Measured memory_bytes: 4416
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,i;
  long long s;
  cin>>n;
  vector<long long> a(n),b(n);
  for(i=0;i<n;i++) {
    cin>>a.at(i);
    b.at(a.at(i)-1)++;
  }
  s=0;
  for(i=0;i<n;i++) s+=b.at(i)*(b.at(i)-1)/2;
  for(i=0;i<n;i++) cout<<s-(b.at(a.at(i)-1)-1)<<endl;
}

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

#define ll long long
#define ar array

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

	int n, m;
	cin >> n >> m;
	cout << n * (n - 1) / 2 + m * (m - 1) / 2 << "\n";
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> P;
typedef long long ll;
typedef unsigned long long ull;

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

  vector<char> S(N);
  rep(i,N) cin >> S.at(i);

  int Rs =0, Ws = 0;
  rep(i,N){
    if(S.at(i) == 'W') ++Ws;
    else Rs++;
  }

  int Ru = 0;
  rep(i,Rs){
    if(S.at(i)=='R') ++Ru;
  }

  cout << Rs - Ru << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){

  int n,count;
  int a,b,c,d;

  while(cin >> n){
    if(n <= 50){
      count = 0;
      for(a=0;a<10;a++)
	for(b=0;b<10;b++)
	  for(c=0;c<10;c++)
	    for(d=0;d<10;d++)
	      if(a+b+c+d == n)
		count++;
      cout << count << endl;
    }
  }

  return 0;
}

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

int main() {
    int n; cin >> n;
    vector<Int> a(n);
    map<Int, Int> mp;
    rep(i, n) {
         cin >> a[i];
         mp[a[i]]++;
    }
    Int sum_all = 0;
    for (auto m : mp) {
        sum_all += (m.second * (m.second-1))/2;
    }
    rep(i, n) {
        Int before = (mp[a[i]] * (mp[a[i]] - 1)) / 2;
        Int after = (mp[a[i]]-1) * (mp[a[i]] -2) / 2;
        cout << sum_all - (before - after) << endl;
    }

}

Measured memory_bytes: 12724
A,B,C,K=map(int,input().split())
d=A-K
e=B-abs(d)
if d>0:
    print(K)
if d==0:
    print(A)
if d<0:
    if e>0:
        print(A+abs(d)*0)
    if e==0:
        print(A+B*0)
    if e<0:
        print(A+B*0+abs(e)*(-1))

Measured memory_bytes: 8940
#include <iostream>
#include <cmath>
#include <limits>
using namespace std;

int calc_distance2(int *X1, int *X2, int D) {
    int d = 0;
    for (int i = 0; i < D; ++i) {
        int diff = (X1[i] - X2[i]);
        d += diff * diff;
    }
    return d;
}

int main() {
    int N, D;
    cin >> N >> D;
    int X[N][D];
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < D; ++j) {
            cin >> X[i][j];
        }
    }
    int s = 0;
    for (int i = 0; i < N - 1; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int d2 = calc_distance2(X[i], X[j], D);
            double d = sqrt((double)d2);
            int d_int = (int)d;
            double diff = abs(((double)d_int) - d);
            if (diff < 0.001) {
                s++;
            }
        }
    }
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    //题目还是蛮水的，第一题送分。
	double n,a,b,x,max,min;
	cin>>a>>b>>x;
	if(a>=b){
		max=a;
		min=b;
	}
	else{
		max=b;
		min=a;
	}
	n=ceil(x/max);
	cout<<n;
    }
    



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define double long double
#define rep(i,n) for(ll i=0;i<n;i++)
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define repii(i,a,b) for(ll i=a;i<=b;i++)
#define pb push_back
#define in insert
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
int main()
{
    fastIO;
    int a,b;
    cin>>a>>b;
    if(b==1)
        cout<<0;
    else if(b<a)
        cout<<1;
    else{
        int ans=a,c=1;
        while(b>ans)
        {
            ans+=(a-1);
            //cout<<ans<<" ";
            c++;
        }
        cout<<c;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
ll tako[55]={0};
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll ans=0;
  char last='(';
  for(int i=0;i<n;i++){
    if(s[i]!=last) ans++;
    last=s[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int X, A;

int main() {
	cin >> X >> A;
	if (X < A)cout << 0 << endl;
	else cout << 10 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int i,j,a,ara[10];
    for(i=0;i<10;i++){
        scanf("%d",&ara[i]);
    }
    for(i=0;i<10;i++){
        for(j=i+1;j<10;j++){
            if(ara[i]<ara[j]){
                a=ara[i];
                ara[i]=ara[j];
                ara[j]=a;
            }
        }
    }
    for(i=0;i<3;i++){
        printf("%d\n",ara[i]);
    }
    return 0;
}

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

struct Node {
    int key;
    Node *prev, *next;
};

void deleteNode(Node *t){
}

class List {
    private:
    Node *nil;
    int size;
    public:
    List();
    void _deleteNode(Node *t);
    Node* _listSearch(int key);
    void _insert(int key);
    void _delete(int key);
    void _deleteFirst();
    void _deleteLast();
    void _show();
};

List::List(){
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
    size=0;
}

void List::_deleteNode(Node *t){
    if(t==nil) return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    size--;
    free(t);
}

Node* List::_listSearch(int key){
    Node *cur=nil->next;
    while(cur != nil && cur->key != key){
        cur=cur->next;
    }
    return cur;
}


void List::_insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
    size++;
}

void List::_delete(int key){
    Node* cur=nil;
    _deleteNode(_listSearch(key));
}

void List::_deleteLast(){
    _deleteNode(nil->prev);
}

void List::_deleteFirst(){
    _deleteNode(nil->next);
}

void List::_show(){
    Node *cur=nil->next;
    while(cur != nil){
        printf("%d",cur->key);
        if(cur->next != nil) printf(" ");
        cur=cur->next;
    }
}

int main(){
    int n;
    char com[20];
    int a;
    List L=List();
    cin >> n;
    for(int i=0;i<n;i++){
        scanf("%s%d",com, &a);
        if(com[0]=='d'){
            if(com[6]=='F')L._deleteFirst();
            else if(com[6]=='L')L._deleteLast();
            else L._delete(a);;
        }else if(com[0]=='i'){
            L._insert(a);
        }
    }

    L._show();
    cout << endl;
}



Measured memory_bytes: 34440
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;
const ll MOD = 1000000007;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int k, x;
	cin >> k >> x;

	vector<int> ans;
	for (int v = x - k + 1; v < x; v++) {
		ans.push_back(v);
	}

	for (int v = x; v <= x + k - 1; v++) {
		ans.push_back(v);
	}

	for (int i = 0; i < (int)ans.size(); i++) {
		if (i) cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}


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

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;

    if (s.size() <= k ) {
        cout << s << endl; 
    }  else {
        rep (i, k) {
            cout << s[i];
        }
        cout << "..." << endl;
    }

}


Measured memory_bytes: 3608
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = Integer.parseInt(sc.next());
    int b = Integer.parseInt(sc.next());
    if(a < b * 2){
      System.out.println(0);
    }else{
      System.out.println(a - 2 * b);
    }
  }
}
    

Measured memory_bytes: 23892
N=int(input())
X=[0]*N
for i in range(N):
    X[i]=[list(map(int,input().split())) for _ in range(int(input()))]
print(max(['{:03b}'.format(i).count('1')for i in range(2**N) if all([i>>j&1 and all([y[1]==i>>(y[0]-1)&1 for y in X[j]]) for j in range(N) if (i>>j&1)])]))

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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int v, e; cin >> v >> e;
    vector<vector<int>> g(v, vector<int>(v, inf));
    for (int i = 0; i < e; i++) {
        int s, t, d; cin >> s >> t >> d;
        g[s][t] = d;
    }

    vector<vector<int>> dp(1 << v, vector<int>(v, inf));
    dp[0][0] = 0;
    for (int i = 0; i < (1 << v); i++) {
        for (int j = 0; j < v; j++) {
            if ((i >> j) & 1) continue;
            for (int k = 0; k < v; k++) {
                if (g[j][k] >= inf) continue;
                dp[i | (1 << j)][k] = min(dp[i | (1 << j)][k], dp[i][j] + g[j][k]);
            }
        }
    }
    cout << (dp[(1 << v) - 1][0] < inf ? dp[(1 << v) - 1][0] : -1) << endl;
    return 0;
}



Measured memory_bytes: 6240
# -*- coding: utf-8 -*-
import itertools
from collections import Counter

N,A,B,C=map(int,raw_input().split())
ORG=[A,B,C]
ORG.sort(reverse=True)

L=[ input() for i in range(N) ]
L.sort()

P=[]
for i in itertools.product(range(4), repeat=N):	#a:0 , b:1 , c:2 , unused:3
	P.append(i)				#Permutation


ans=float("inf")

for u in P:
	t=0	#答えの候補
	a=0; b=0; c=0	#3本の竹の長さの候補
	for i,x in enumerate(u):
		if x==0: a+=L[i]
		elif x==1: b+=L[i]
		elif x==2: c+=L[i]

	if a!=0 and b!=0 and c!=0:	#候補の数が３つできることは必須
		T=[a,b,c]
		T.sort(reverse=True)
		for x, y in zip(ORG, T):
			t+=abs(x-y)

		CT=Counter(u)
		for num, cnt in CT.items():
			if num in (0,1,2):
				t+=(cnt-1)*10
		ans=min(ans, t)


print ans


Measured memory_bytes: 43292
#include <bits/stdc++.h>
using namespace std;
int main() {
	string a, b;
	int n, m;
	cin >> a >> b;
	a += b;
	n = stoi(a);
	m = sqrt(n);
	
	if(m * m == n) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


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

using namespace std;

#define MIN_OPERANDS 2
#define MAX_OPERANDS 100
#define MIN_OPERATOR 1
#define MAX_OPERATOR 99

class Stack {
public:
  Stack() {
  }
  ~Stack() {
  }
  void push(int operand) {
    operands[ptr++] = operand;
  }
  int pop() {
    return operands[--ptr];
  }
  void print() {
    cout << "[";
    cout << "ptr=" << ptr << "|";
    for(int i=0; i<ptr; i++) {
      cout << operands[i] << ",";
    }
    cout << "]" << endl;
  }
private:
  int ptr;
  int operands[MAX_OPERANDS + 1];
};

int main() {
  Stack stack;

  string input;
  while(cin >> input) {

    int value = atoi(input.c_str());
    if(value > 0) {
      stack.push(value);
      continue;
    }

    int r = stack.pop();
    int l = stack.pop();
    if(input == "+") {
      stack.push(l+r);
    } else if(input == "-") {
      stack.push(l-r);
    } else if(input == "*") {
      stack.push(l*r);
    } else if(input == "/") {
      stack.push(l/r);
    } else {
      cout << "err: unknown operator " << input << endl;
      return 1;
    }
  }

  cout << stack.pop() << endl;

  return 0;
}

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

int main() {
	string s, t;
	int len1, len2, ans;
	cin >> s >> t;
	len1 = s.length();
	len2 = t.length();
	ans = 1005;
	for (int i = 0; i < len1; i++) {
		if (len1 - len2 < i)
			break;
		int temp = 0;
		for (int j = 0; j < len2; j++) {
			if (s[i + j] != t[j]) {
				temp++;
			}
		}
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

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

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

  int A[100010];
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }

  int pos = 0;
  int offset = 0;
  while (pos + offset < N - 1) {
    sort(A+pos, A+N);
    pos += offset;
    offset = 0;
    for (int i = pos + 1; i < N; ++i) {
      A[i] %= A[pos];
      if (!A[i]) ++offset;
    }
  }

  cout << A[pos] << endl;

  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_V = 210;

vvl G;
vl color;  // color[i] : 0は白、1は黒、-1は未訪問

bool dfs(ll v, ll now = 0) {
    color[v] = now;
    for(auto u : G[v]) { 
        if(color[u] != -1) {
            if(color[u] == now) {
                return false;
            }
            continue;
        }
        if(!dfs(u, 1-now)) {
            return false;
        }
    }
    return true;
}

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

    vvl dist(MAX_V, vl(MAX_V));
    rep(i, n) {
        rep(j, n) {
            if(i != j) {
                dist[i][j] = INF;
            }
        }
    }

    G.resize(n);
    rep(i, n) {
        string s;
        cin >> s;
        rep(j, n) {
            if(s[j] == '1') {
                G[i].pb(j);
                dist[i][j] = 1;
            }
        }
    }
    
    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    color.assign(n, -1);
    bool nibuGraph = true;
    rep(v, n) {
        if(color[v] != -1) {
            continue;
        }
        if(!dfs(v)) {
            nibuGraph = false;
        }
    }

    if(nibuGraph) {
        ll ans = 0;
        rep(i, n) {
            rep(j, n) {
                if(dist[i][j] == INF) {
                    continue;
                }
                chmax(ans, dist[i][j]);
            }
        }
        ans++;
        out(ans);
    }
    else {
        out(-1);
    }
    
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
string s;
ll n;
ll dp[100005][13];
ll solve(int ind, int rem){
	if(ind>=n){
		if(rem==5)
			return 1;
		return 0;
	}
	if(dp[ind][rem]!=-1)
		return dp[ind][rem];
	if(s[ind]!='?')
		return dp[ind][rem]=solve(ind+1,(10*rem+(s[ind]-'0'))%13)%modulo;
	ll res=0;
	for (int i = 0; i <= 9; ++i){
		res=(res+solve(ind+1,(10*rem+i)%13))%modulo;
	}
	dp[ind][rem]=res;
	return dp[ind][rem];
}
int main(){
	fast_io;
	cin>>s;
	n=s.length();
	memset(dp,-1,sizeof(dp));
	ll ans=solve(0,0);
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 21696
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <queue>

using namespace std;

using ll=long long;

ll X;

ll p5(ll a)
{
    return a*a*a*a*a;
}

int main()
{
    cin >> X;
    for(ll A = 0; A <= 1000; A++)
    {
        for(ll B = 0; B <= 1000; B++)
        {
            if(p5(A) - p5(B) == X)
            {
                cout << A << ' ' << B << endl;
                return 0;
            }
            else if(p5(A) + p5(B) == X)
            {
                cout << A << ' ' << -B << endl;
                return 0;
            }
        }
    }
   return 0;
}

Measured memory_bytes: 3196
from sys import stdin

S = stdin.readline().rstrip()
N = int(len(S))

S_reversed = "".join(list(reversed(S)))

S1 = S[0:int((N-1)/2)]
S1_reversed = "".join(list(reversed(S1)))


S2 = S[int((N+3)/2)-1:N]
S2_reversed = "".join(list(reversed(S2)))

answer = "Yes"

for i in range(N):
    if S[i] == S_reversed[i]:
        pass
    else:
        answer = "No"

for i in range(int((N-1)/2)):
    if S1[i] == S1_reversed[i]:
        pass
    else:
        answer = "No"

for i in range(int(N-(N+3)/2)):
    if S2[i] == S2_reversed[i]:
        pass
    else:
        answer = "No"

print(answer)


Measured memory_bytes: 3064
/*----------------------------------------------------*
* लेखक --> अमित सिंह
* संस्थान --> राष्ट्रीय प्रौद्योगिकी संस्थान, कुरुक्षेत्र
*-----------------------------------------------------*/
   #include <bits/stdc++.h>
   using namespace std;
   #define ll long long
   #define w(t) int t; cin>>t; while(t--)
   #define fo(i,n) for(int i=0;i<n;i++)
   #define endl "\n" 
   #define MOD 1000000007
   void Tez(){
      ios::sync_with_stdio(0);
      cin.tie(0);
      cout.tie(0);
   }
   ll cache[2001];
   ll fun(int s){
      if(s==0) return 1;
      if(s<0) return 0;
      if(cache[s]!=-1) return cache[s];
      ll ans=0;
      for(int i=3;i<=s;i++){
         ans=(ans+fun(s-i))%MOD;
      }
    return cache[s]=ans;
   }
   int main(){
      Tez();
      int n;
      cin>>n;
      memset(cache,-1,sizeof(cache));
      cout<<fun(n);
      return 0;
   }



Measured memory_bytes: 3664
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
	static int lcm (int a, int b) {return a*b/gcd(a,b);}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		int b=scan.nextInt();
		int a[]=new int[b];
		for(int i=0;i<b;i++) {
			a[i]=scan.nextInt();
		}
		Arrays.sort(a);
		int co=0;
		int ans=0;
		for(int i=1;i<b;i++) {
			if(a[i]==a[i-1]) {
				co++;
			}
			else {
				if(co%2==0) {
					ans++;
				}
				co=0;
			}
		}
		if(co%2==0) {
			ans++;
		}
		System.out.println(ans);
	}

}


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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int now = 0;
        rep(i,q){
            if(A[b[i]] - A[a[i]]==c[i]) now += d[i];
        }
    ans = max(ans,now);
    return;
    }
    
    A.push_back(A.back());
    while(A.back() <= m){
        dfs(A);
        A.back()++;
    }
}
int main() {
    cin>>n>>m>>q;
    a = b = c = d =vector<int>(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout<<ans<<endl;
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#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 pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;

//-----------------------------------------------------------------------------

int n;
ll x,a[2000],sum,mi=LINF;
ll dp[2000];

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

	cin>>n>>x;
	REP(i,n) {
		cin>>a[i];
	}
	ll ans=0;
	REP(i,n) dp[i]=a[i],ans+=a[i];
	FOR(i,1,n) {
		ll sum=0;
		REP(j,n) dp[j]=min(dp[j],a[(j-i+n)%n]),sum+=dp[j];
		ans=min(ans,sum+x*i);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int L; string s; cin >> L >> s;

  vector<int> consWL(L+2), consBL(L+2);
  vector<int> consWR(L+2), consBR(L+2);
  vector<int> Bs, Ws;
  const int INF = 2 * L;
  Bs.emplace_back(-INF);
  Ws.emplace_back(-INF);
  for(int i=0; i<L; i++) {
    if(s[i] == 'W') consWL[i+1] = consWL[i] + 1;
    else consWL[i+1] = 0;

    if(s[i] == 'B') consBL[i+1] = consBL[i] + 1;
    else consBL[i+1] = 0;
    
    if(s[i] == 'B') Bs.emplace_back(i);
    if(s[i] == 'W') Ws.emplace_back(i);
  }
  for(int i=L-1; i>=0; i--) {
    if(s[i] == 'W') consWR[i+1] = consWR[i+2] + 1;
    else consWR[i+1] = 0;

    if(s[i] == 'B') consBR[i+1] = consBR[i+2] + 1;
    else consBR[i+1] = 0;
  }
  Bs.emplace_back(INF);
  Ws.emplace_back(INF);

  int ans = 0;
  for(int i=0; i<L; i++) {
    if(s[i] != '.') continue;
    int cand = 0;

    // self: i+1

    // left
    int cl = consBL[i];
    if(i - cl - 1 >= 0 and s[i - cl - 1] == 'W') cand = max(cand, cl);

    // right
    int cr = consBR[i+2];
    if(i + cr + 1 < L and s[i + cr + 1] == 'W') cand = max(cand, cr);

    // invalid?
    int wl = consWL[i];
    int wr = consWR[i+2];

    bool invalid = true;
    invalid &= (i - wl - 1 >= 0 and s[i - wl - 1] == 'B');
    invalid &= (i + wr + 1 < L and s[i + wr + 1] == 'B');
    if(invalid) continue;

    ans = max(ans, cand);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 3204
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
 
/*
    Author: Koushik Sahu
    Created: 02 September 2020 Wed 20:50:02
*/

public class Main {

    static FastScanner fs=new FastScanner();

    static int n, l[];

    public static void main(String[] args){
        n = fs.nextInt();
        l = new int[n];
        for(int i=0; i<n; i++) l[i] = fs.nextInt();
        int ans = 0;
        for(int i=0; i<n; i++){
            for(int j=i+1; j<n; j++){
                for(int k=j+1; k<n; k++){
                    if(isTriangle(i, j, k)){
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
    }

    static boolean isTriangle(int a, int b, int c){
        if(l[a]!=l[b] && l[b]!=l[c] && l[c]!=l[a] && l[a]+l[b]>l[c] && l[b]+l[c]>l[a] && l[c]+l[a]>l[b]) return true;
        return false;
    }
        
    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
                            
        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        public String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
                                        
        public int nextInt() {
            return Integer.parseInt(next());
        }
                                                
        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
                                                        
        public long nextLong() {
            return Long.parseLong(next());
        }
                                                                
        public long[] readLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
     
}

Measured memory_bytes: 33428
import java.util.Scanner;

public class Main{
	static Node[] T;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		T = new Node[n + 1];
		for(int i = 0; i <= n; i++) {
			T[i] = new Node(-1);
		}
		for(int i = 0; i < n; i++) {
			int v = scan.nextInt();
			int l = scan.nextInt();
			int r = scan.nextInt();
			T[v].setL(l);
			T[v].setR(r);
			if(l != -1) {
				T[l].setP(v);
			}
			if(r != -1) {
				T[r].setP(v);
			}
		}
		scan.close();
		int root = 0;
		for(int i = 0; i < n; i++) {
			if(T[i].getP() == -1) {
				root = i;
			}
		}
		System.out.println("Preorder");
		preParse(root);
		System.out.println();
		System.out.println("Inorder");
		inParse(root);
		System.out.println();
		System.out.println("Postorder");
		postParse(root);
		System.out.println();
	}
	// 先行順巡回
	static void preParse(int u) {
		if(u == -1) return;
		System.out.print(" " + u);
		preParse(T[u].getL());
		preParse(T[u].getR());
	}
	// 中間順巡回
	static void inParse(int u) {
		if(u == -1) return;
		inParse(T[u].getL());
		System.out.print(" " + u);
		inParse(T[u].getR());
	}
	// 後行順巡回
	static void postParse(int u) {
		if(u == -1) return;
		postParse(T[u].getL());
		postParse(T[u].getR());
		System.out.print(" " + u);
	}
	static class Node{
		int p,l,r;
		public Node(int p) {
			this.p = p;
		}
		int getP() {
			return p;
		}
		int getL() {
			return l;
		}
		int getR() {
			return r;
		}
		void setP(int p) {
			this.p = p;
		}
		void setL(int l) {
			this.l = l;
		}
		void setR(int r) {
			this.r = r;
		}
	}
}


Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    char s;
    cin >> s;
    cout << char(s+1) << endl;
    return 0;
}

Measured memory_bytes: 256