akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
struct Edge{
	int v,nxt;
}e[4010];int tot;
int first[2010];
void build(int u,int v)
{
	e[++tot]=(Edge){v,first[u]};
	first[u]=tot;
	return ;
}
char s[2010];
int mx[2010],mn[2010],cnt[2010];
void dfs(int u,int lst)
{
	mx[u]=mn[u]=0;
	cnt[u]=s[u]-'0';
	int M=0,sum=0;
	for(int i=first[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==lst)continue;
		dfs(v,u);
		cnt[u]+=cnt[v];
		mx[v]+=cnt[v];
		mn[v]+=cnt[v];
		mx[u]+=mx[v];
		if(mn[v]>M)M=mn[v];
	}
	for(int i=first[u];i;i=e[i].nxt)
	{
		int v=e[i].v;
		if(v==lst)continue;
		sum+=mn[v]+(min(M,mx[v])-mn[v])/2*2;
	}
	sum-=M;
	if(M>sum)mn[u]=M-sum;
	else if(M%2==sum%2)mn[u]=0;
	else mn[u]=1;
	return ;
}
const int INF=1e9;
int main()
{
	int n;scanf("%d",&n);
	scanf("%s",s+1);
	for(int i=1;i<n;i++)
	{
		int u,v;
		scanf("%d %d",&u,&v);
		build(u,v);
		build(v,u);
	}
	int ans=INF;
	for(int i=1;i<=n;i++)
	{
		dfs(i,0);
		if(mn[i]==0)
			ans=min(ans,mx[i]/2);
	}
	if(ans==INF)printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
# coding: utf-8
# Your code here!
import math
from decimal import *
getcontext().prec = 70

N,K = list(map(int,input().split()))


if N<= K:
    print(min(N,K-N))
else:

    N = N - math.floor(Decimal(N)/Decimal(K))*K 
    print(min(N, K-N)) 

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

int gcd(int p, int q)
{
  if (p % q == 0)
  {
    return q;
  }
  return gcd(q, p % q);
}

int main(void)
{
  int K;
  cin >> K;
  int ans = 0;
  for (int a = 1; a <= K; a++)
  {
    for (int b = 1; b <= K; b++)
    {
      for (int c = 1; c <= K; c++)
      {
        ans += gcd(gcd(a, b), c);
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3552
def main():
    """
    カレンダーらしいもの: 7列…

    3x3の和: 2列目x3
    2列目の平均: (2,2)
    より,(2,2)*9

    11で割った余り
    9............13
    16...........20
    ...

    9,10,0,1,2
    5,6, 7,8,9

    [以下、解説の(自分用の)補完]
    9x ≡  k mod 11
     x ≡ 5k mod 11 ?

    わからんーとTweetしたら, 引用で解説されてた(感謝)
    1. https://twitter.com/hogeover30/status/995618880830636032
    2. https://mathtrain.jp/mod

        45x     ≡ 5k mod 11 (両辺等倍しても剰余は変わらない, 性質3)
        44x + x ≡ 5k mod 11 (求めたいxと 11で割り切れる倍数に分解, 性質1)
              x ≡ 5k mod 11

    範囲の変更
        7i + j - 7 (2<=i<=n-1, 2<=j<=6)
        7i + j + 9 (0<=i<=n-3, 0<=j<=4)
            7*2 + 1*2 = 16
            16 - 7 = 9

    7i に着目(入力例4, n=100, k=8)
        j=0: 7i+9  ≡ 5k ≡ 40 (mod 11) => 7i ≡ 9 (mod 11) ※1
        j=1: 7i+10 ≡ 5k ≡ 40 (mod 11) => 7i ≡ 8 (mod 11) ※2
            ※1: 40-9 (31) mod 11 = 9 より (性質2)
            ※2: 40-10(30) mod 11 = 8 より

            i={6,17,28,39,50,61,72,83,94}
            i={9,20,31,42,53,64,75,86,97}

    j固定: i = 11q + r
        1: r=6
        2: r=9
    結局、規則はなんとなく分かるが証明しろと言われると説明できない
    """
    n, k = map(int, input().split())

    # part1(n, k)
    # f2(n, k)
    editorial(n, k)


def f2(n, k):
    """規則をなんとなく見つけた場合
    """
    table = []
    for i in range(2, 2+11):
        table.append(
            [(7*i + j - 7) * 9 % 11 for j in range(2, 6+1)]
        )

    # 最初と最後の1行ずつ不要
    n -= 2
    # 11ごとに1つ解が存在し5列分
    ans = n // 11 * 5
    # 余った行ごとに残りの判定
    x = n % 11
    for i in range(x):
        for j in range(5):
            if table[i][j] == k:
                ans += 1

    print(ans)


def editorial(n, k):
    ans = 0
    # 列ごと: 2行目2-6列目
    for j in range(2, 6+1):
        rownum = 0
        for i in range(2, n):
            s = (i * 7 + j - 7) * 9
            if s % 11 == k:
                rownum = i
                break

        if rownum == 0:
            continue

        # 11行ごとに余りkになるため、見つかった基準の分の+1
        # 最後の1行不要, rownumずらしておく
        ans += 1
        ans += (n - 1 - rownum) // 11

    print(ans)


def part1(n, k):
    ans = 0

    for i in range(1, n-3+2):
        for j in range(1, 5+1):
            s = 0
            for y in range(3):
                for x in range(3):
                    s += 7*(i+y) + (j+x) - 7
            # print(i, j, s, sep="\t")
            if s % 11 == k:
                ans += 1

    print(ans)


if __name__ == '__main__':
    main()


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	int n;
	cin >> n;
	map<ll, ll> b, c;

	for(ll i = 0; i < n; ++i)
	{
		ll a;
		cin >> a;
		b[i + 1 + a]++;
		c[i + 1 - a]++;
	}

	ll ans = 0;
	for(auto& m : b)
	{
		ll num = m.first;
		ans += m.second * c[num];
	}

	cout << ans << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 37856
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair< ll, ll > P;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007    //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

// debug
#define DEBUG(x) cout << #x << ": " << x << endl
#define DEBUG2(x, y) cout << #x << ": " << x << " " << #y << ": " << y << endl
#define DEBUG_VEC(v)   \
  cout << #v << ":";   \
  REP(i, v.size())     \
  cout << " " << v[i]; \
  cout << endl
#define DEBUG_ARR(v, n) \
  cout << #v << ":";    \
  REP(i, n)             \
  cout << " " << v[i];  \
  cout << endl

ll A, B, N;

ll f(ll x)
{
  return (A * x) / B - A * (x / B);
}

signed main()
{

  cin >> A >> B >> N;

  ll ans = -1;
  ll x = 1;

  ll mn = (N + 1) / B;
  ans = max(f(N), f(mn * B - 1));
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define pf pop_front
#define mp make_pair
using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	int n,k;
	cin>>n>>k;
	int h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	int dp[n];
	for(int i=0;i<n;i++)
		dp[i]=1e9;
	dp[0]=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<min(n,i+k+1);j++)
			dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<utility>
#include<random>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-2;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int a, b, q;
ll s[1 << 17], t[1 << 17];
int main() {
	cin >> a >> b >> q;
	s[0] = t[0] = -INF;
	rep1(i, a) {
		cin >> s[i];
	}
	rep1(i, b) {
		cin >> t[i];
	}
	s[a + 1] = t[b + 1] = INF;
	rep(i, q) {
		ll x; cin >> x;
		int ids = lower_bound(s, s + a + 2, x) - s;
		int idt = lower_bound(t, t + b + 2, x) - t;
		ll ans = max(s[ids], t[idt]) - x;
		ans = min(ans, 2 * (s[ids] - t[idt - 1]) - max(s[ids] - x, x - t[idt - 1]));
		ans = min(ans, 2 * (t[idt] - s[ids - 1]) - max(t[idt] - x, x - s[ids - 1]));
		ans = min(ans, x - min(s[ids - 1], t[idt - 1]));
		cout << ans << endl;
	}
	//stop
	return 0;
}


Measured memory_bytes: 2944
// :)
// "Khodaya, be man "Tagwaye setiz" biamooz ta
//  dar anbuh masuliat nalaghzam ..." -Shariati
#include <bits/stdc++.h>

using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

const int maxn = 2e5+10;
const int64 MO = 1e9+7;
const int64 IN = 1e18;

vector <pii> v1[maxn];

int64 seg[maxn * 4], lzy[maxn * 4];

int N, M;

void update (int x, int64 val, int l = 0, int r = N + 1, int id = 1) {
	if (x < l || x >= r)
		return;
	if (r - l == 1) {
		seg[id] += val;
		lzy[id] += val;
		return;
	}
	int mid = (l + r) >> 1;
	seg[id * 2] += lzy[id];
	seg[id * 2 + 1] += lzy[id];
	lzy[id * 2] += lzy[id];
	lzy[id * 2 + 1] += lzy[id];
	lzy[id] = 0;
	update(x, val, l, mid, id * 2);
	update(x, val, mid, r, id * 2 + 1);
	seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
	return;
}

void add (int st, int en, int64 val, int l = 0, int r = N + 1, int id = 1) {
	if (st >= r || en <= l)
		return;
	if (st <= l && en >= r) {
		seg[id] += val;
		lzy[id] += val;
		return;
	}
	int mid = (l + r) >> 1;
	seg[id * 2] += lzy[id];
	seg[id * 2 + 1] += lzy[id];
	lzy[id * 2] += lzy[id];
	lzy[id * 2 + 1] += lzy[id];
	lzy[id] = 0;
	add(st, en, val, l, mid, id * 2);
	add(st, en, val, mid, r, id * 2 + 1);
	seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
	return;
}

int64 getmx (int st, int en, int l = 0, int r = N + 1, int id = 1) {
	if (st >= r || en <= l)
		return -IN;
	if (st <= l && en >= r)
		return seg[id];
	int mid = (l + r) >> 1;
	seg[id * 2] += lzy[id];
	seg[id * 2 + 1] += lzy[id];
	lzy[id * 2] += lzy[id];
	lzy[id * 2 + 1] += lzy[id];
	lzy[id] = 0;
	return max(getmx(st, en, l, mid, id * 2), getmx(st, en, mid, r, id * 2 + 1));
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	// 
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int l, r, a;
		cin >> l >> r >> a;
		v1[r].PB( MP( l , a ) );
	}
	for (int i = 1; i <= N; i++) {
		update(i, getmx(0, i));
		for (auto x : v1[i]) {
			int l = x.F, a = x.S;
			add(l, i + 1, a);
		}
	}
	//
	cout << seg[1] << "\n";
	//
}



Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
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;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n;
    cin >> n;
    ll x = n % 10;
    if(x == 3) cout << "bon" << endl;
    else if(x == 0 || x == 1 || x == 6 || x == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <cctype>
#include <vector>

using namespace std;

typedef string::const_iterator Iterator;
const int LIM = 1<<10;

int number(Iterator &it, const Iterator &end) {
    int res = 0;
    while(it != end && isdigit(*it)) {
        res *= 2;
        res += *it - '0';
        if(res >= LIM) throw "overflow";
        ++it;
    }
    return res;
}

pair<int,bool> expr(Iterator &it, const Iterator &end);
int fact(Iterator &it, const Iterator &end) {
    if(*it == '(') {
        ++it;
        const auto res = expr(it, end);
        if(!res.second) {
            throw "no operator in paren";
        }
        if(*it != ')') {
            throw "unmatched paren";
        }
        ++it;
        return res.first;
    } else if(isdigit(*it)) {
        return number(it, end);
    } else {
        throw "paren or digit required";
    }
}

pair<int,bool> term(Iterator &it, const Iterator &end) {
    int lhs = fact(it, end);
    bool op_seen = false;
    while(it != end) {
        char op = *it;
        if(op != '*') break;
        ++it;
        const int rhs = fact(it, end);
        lhs *= rhs;
        op_seen = true;
        if(lhs < 0 || lhs >= LIM) throw "overflow";
    }
    return make_pair(lhs, op_seen);
}

pair<int,bool> expr(Iterator &it, const Iterator &end) {
    auto lhs_ = term(it, end);
    int lhs = lhs_.first;
    bool op_seen = lhs_.second;
    while(it != end) {
        char op = *it;
        if(op != '+' && op != '-') {
            break;
        }
        ++it;
        const auto rhs = term(it, end);
        op_seen = op_seen || rhs.second;
        switch(op) {
            case '+':
                lhs += rhs.first;
                break;
            case '-':
                lhs -= rhs.first;
                break;
        }
        op_seen = true;
        if(lhs < 0 || lhs >= LIM) throw "overflow";
    }
    return make_pair(lhs, op_seen);
}

bool solve() {
    string str;
    if(!(cin >> str)) return false;

    vector<int> dot_pos;
    for(int i = 0; i < str.size(); ++i) {
        if(str[i] == '.') dot_pos.push_back(i);
    }
    const string chars = "01+-*()";
    int lim = 1;
    for(int i = 0; i < dot_pos.size(); ++i) lim *= chars.size();
    int ans = -1;
    for(int pat = 0; pat < lim; ++pat) {
        int tmp = pat;
        string s = str;
        for(int pos : dot_pos) {
            s[pos] = chars[tmp % chars.size()];
            tmp /= chars.size();
        }
        try {
            Iterator it = s.begin();
            const auto res = expr(it, s.end());
            if(it != s.end()) {
                throw "premature end";
            }
            //cout << s << ' ' << res.first << endl;
            ans = max(ans, res.first);
        } catch(const char *msg) {
            //cout << s << ' ' << msg << endl;
        }
    }
    cout << ans << endl;
    return true;
}

int main() {
    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1276
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!long;

    iota(1,N+1).filter!(x => x < 10 || (100 <= x && x < 1000) || (10000 <= x && x < 100000)).walkLength.writeln;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

long long diffSum(list<int>& ls){
	vector<int> v(all(ls));
	long long sum = 0;
	rep(i,v.size() - 1){
		sum += abs(v[i] - v[i + 1]);
	}
	return sum;
}

long long solve1(vector<int>& a){
	int size = a.size();
	int l = 0, r = a.size() - 1;

	list<int> ls;
	int i = 0;
	while(size){
		if(i == 0){
			ls.emplace_back(a[l++]);
			size--;
		}else if(i % 2){
			ls.emplace_front(a[r--]);
			size--;
			if(size == 0) continue;
			ls.emplace_back(a[r--]);
			size--;
		}else{
			ls.emplace_front(a[l++]);
			size--;
			if(size == 0) continue;
			ls.emplace_back(a[l++]);
			size--;
		}
		i++;
	}

	return diffSum(ls);
}

long long solve2(vector<int>& a){
	int size = a.size();
	int l = 0, r = a.size() - 1;

	list<int> ls;
	int i = 0;
	while(size){
		if(i == 0){
			ls.emplace_back(a[r--]);
			size--;
		}else if(i % 2 == 0){
			ls.emplace_front(a[r--]);
			size--;
			if(size == 0) continue;
			ls.emplace_back(a[r--]);
			size--;
		}else{
			ls.emplace_front(a[l++]);
			size--;
			if(size == 0) continue;
			ls.emplace_back(a[l++]);
			size--;
		}
		i++;
	}

	return diffSum(ls);
}


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

	vector<int> a(n);
	rep(i,n) cin >> a[i];

	sort(all(a));

	cout << max(solve1(a), solve2(a)) << endl;
}


Measured memory_bytes: 4216
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n;
    cin>>n;
    if (n==1)
        cout<<"Hello World\n";
    else
    {
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
}

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


left = a[0]
right = sum(a[1:])
ans = abs(left - right)
for i in range(1, n-1):
    left += a[i]
    right -= a[i]
    ans = min(ans, abs(left-right))
print(ans)


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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define roop(i, n) for(int i = 0;i < n;i++)

int main(void){

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

    if(a <= b*2) cout << 0 << endl;
    else cout << a-b*2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B; cin >> A >> B;
  for(int i=1;i<=100000;i++){
    if((i*8)/100==A && i/10==B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

int main()
{
    int N, M;
    ll K;
    ll a[200005] = {0}, b[200005] = {0};

    cin >> N >> M >> K;
    for (int i = 1; i <= N; i++) {
        ll A;
        cin >> A;
        if (i == 1) {
            a[i] = A;
        } else {
            a[i] = a[i - 1] + A;
        }
    }
    for (int i = 1; i <= M; i++) {
        ll B;
        cin >> B;
        if (i == 1) {
            b[i] = B;
        } else {
            b[i] = b[i - 1] + B;
        }
    }

    int pb = M;
    int ans = 0;
    for (int i = 0; i <= N; i++) {
        if (a[i] > K) {
            break;
        }
        while (b[pb] > K - a[i]) {
            pb--;
        }
        ans = max(ans, i + pb);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6712
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define inf 1000000000000000000
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(x) (x).begin(),(x).end()
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; }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  
  ll N, M, X;
  cin >> N >> M >> X;
  vector<ll> C(N);
  vector<vector<ll>> A(N, vector<ll>(M));
  rep(i, N) {
    cin >> C[i];
    rep(j, M) {
      cin >> A[i][j];
    }
  }
  ll ans = inf;
  rep(i, pow(2, N)) {
    ll cost = 0;
    vector<ll> B(M, 0);
    rep(j, N) {
      if (i & (1 << j)) {
        cost += C[j];
        rep(k, M) {
          B[k] += A[j][k];
        }
      }
    }
    ll flag = 1;
    rep(j, M) {
      if (B[j] < X) {
        flag = 0;
        break;
      }
    }
    if (flag) ans = min(ans, cost);
  }
  ans = ans == inf? -1 : ans;
  cout << ans << endl;
}


Measured memory_bytes: 4040
using System;
using System.Text;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine().Split().Select(a => int.Parse(a)).ToArray();
		int A = input[0];
		int B = input[1];
		Console.WriteLine((B % A == 0) ? A + B : B - A);
	}
}

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

typedef long long ll;

ll A, B;

ll solve(ll a, ll b) {
    if(b == 0) return 1;
    int p;
    for(int i = 0; i <= 60; i++) {
        if(b < (1LL << i)) {
            p = i - 1;
            break;
        }
    }

    if(a >= (1LL << p)) {
        return solve(a ^ (1LL << p), b ^ (1LL << p));
    }

    b ^= (1LL << p);
    ll ret = 0;
    int x;
    for(int i = 0; i <= 60; i++) {
        if(b < (1LL << i)) {
            x = i - 1;
            break;
        }
    }
    ret += ((1LL << p) - a);
    ret += min((1LL << p), (1LL << (x + 1)) + (1LL << p) - a);
    return ret;
}

int main() {
    cin >> A >> B;
    cout << solve(A, B);
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){

  int a,b,c,k;
  scanf("%d %d %d", &a, &b, &c);

  if ( a > b ){
   k = a;
   a = b;
   b = k;
  }
  
  if ( b > c ){
    k = b;
    b = c;
    c = k;
  }

  if ( a > b ){
   k = a;
   a = b;
   b = k;
  }

  printf ("%d %d %d\n", a, b, c);

  return 0;

}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, a, b; cin >> n >> a >> b;
  string s; cin >> s;
  int k = 0;
  int l = 0;
  REP(i, SZ(s)) {
    if(s[i] == 'a') {
      if(k < a+b) {
        cout << "Yes" << endl;
        k++;
      } else {
        cout << "No" << endl;
      }
    } else if(s[i] == 'b') {
      if(k < a+b && l < b) {
        cout << "Yes" << endl;
        k++;
        l++;
      } else {
        cout << "No" << endl;
      }
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 896
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  auto s=readln.chomp.to!(char[]);

  auto cnt=new int[](3);
  foreach(c; s) cnt[c-'a']++;

  auto mn=reduce!(min)(cnt);
  auto cnt1=map!(e=>e-mn)(cnt);
  auto a=new int[](0);
  foreach(e; cnt1)if(e>0) a~=e;

  if(a.length==0){writeln("YES"); return;}
  if(a.length==1){
    if(a[0]<2){writeln("YES"); return;}
    else{writeln("NO"); return;}
  }
  if(a[0]<2 && a[1]<2){writeln("YES"); return;}
  else{writeln("NO"); return;}
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

const int N = 333;
int dp[N][N];
int lol[N + N][N];

int get_ans(const string& s, const string& t) {
	memset(lol, 0, sizeof(lol));
	int n = s.length();
	vector<vector<int>> poss(26), post(26);
	for (int i = 0; i < n; i++) {
		poss[s[i] - 'a'].push_back(i);
		post[t[i] - 'a'].push_back(i);
	}

	for (int c = 0; c < 26; c++) {
		for (int i : poss[c]) {
			for (int j : post[c]) {
				lol[n + i - j][min(i, j)] += 1;
			}
		}
	}
	for (int i = 0; i < 2 * n + 1; i++) {
		for (int j = n - 1; j >= 0; j--) {
			lol[i][j] += lol[i][j + 1];
			// cerr << i - n << " " << j << " " << lol[i][j] << "\n";
		}
	}

	for (int i = 0; i <= n; i++) {
		dp[i][0] = dp[0][i] = 0;
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			dp[i + 1][j + 1] = lol[n - i + j][n - 1 - max(i, j)] + min(dp[i][j + 1], dp[i + 1][j]);
		}
	}

	// cerr << s << " " << t << " " << dp[n][n] << "\n";

	return dp[n][n];
}

int main(){

	int n = nxt(), m = nxt();
	vector<string> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	int ans = 0;
	for (int i = 0; i < m - 1; i++) {
		string s, t;
		for (int j = 0; j < n; j++) {
			s += a[j][i];
			t += a[j][i + 1];
		}
		reverse(all(s));
		reverse(all(t));
		ans += get_ans(s, t);
	}

	printf("%d\n", ans);

	return 0;
}

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

const ll INF = 1LL << 60;

ll N;

int main() {
    cin >> N;

    ll ans = INF; 
    for (ll i = 1; i <= N - 1; i++) {
        string A = to_string(i);
        string B = to_string(N - i);

        ll tmp = 0;
        rep(j, A.size()) {
            tmp += A[j] - '0';
        }

        rep(j, B.size()) {
            tmp += B[j] - '0';
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  set<int> s;
  rep(i,3){
    int x; cin >> x;
    s.insert(x);
  }
  cout << s.size();
}

Measured memory_bytes: 3440
#include<bits/stdc++.h>
using namespace std;
#define AC ios::sync_with_stdio(0),cin.tie(0);
#define ll long long int
int main(){
	AC
	ll a,b,c;
	cin>>a>>b>>c;
	if(a>b*c)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
} 


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int main() {
	LL X, Y;
	cin >> X >> Y;
	if (abs(X - Y) <= 1) {
		cout << "Brown" << endl;
	}
	else {
		cout << "Alice" << endl;
	}
}

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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

set<ll> ans;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    set<ll> yakusuu;
    ll ulim = sqrt(N)+1;
    for(ll i = 1; i <= ulim; i++){
        if(N % i == 0){
            yakusuu.insert(i);
            yakusuu.insert(N/i);
        }
    }
    for(auto s: yakusuu){
        if(s == 1) continue;
        ll eval = N;
        while(eval % s == 0) eval /= s;
        if(eval % s == 1) ans.insert(s);
    }

    yakusuu.clear();
    N--;
    for(ll i = 1; i <= ulim; i++){
        if(N % i == 0){
            yakusuu.insert(i);
            yakusuu.insert(N/i);
        }
    }
    for(auto s: yakusuu){
        ll eval = N+1;
        if(eval % s == 1) ans.insert(s);
    }

    cout << ans.size() << endl;
    return 0;
}

Measured memory_bytes: 512
using System;
	public class pj{
      public static void Main(){
        string[] input=Console.ReadLine().Split(' ');
        int n=int.Parse(input[0]);
        int count=int.Parse(input[1]);
        if(n*500>=count){
          Console.WriteLine("Yes");
        }else{
			Console.WriteLine("No");
        }
        
      }
    }
	

Measured memory_bytes: 27368
package main
import(
	"fmt"
	"math"
	"strconv"
)
func main(){
	var s string
	var temp, ans float64
	ans=1000
	fmt.Scan(&s)
	for i:=0;i<len(s)-2;i++{
		a,_:=strconv.Atoi(s[i:i+3])
		temp=math.Abs(753-float64(a))
		if ans>temp{
			ans=temp
		}
	}
	fmt.Println(int(ans))
}


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

int main() {
    int K;
    cin >> K;
    string S = "111212152215121";
    string S2 = "1515221";
    string S3 = "2254141";
    
    if (1 <= K && K <= 15) cout << S.at(K - 1) << endl;
    else if (K == 16) cout << 14 << endl;
    else if (17 <= K && K <= 23) cout << S2.at(K - 17) << endl;
    else if (K == 24) cout << 15 << endl;
    else if (25 <= K && K <= 31) cout << S3.at(K - 25) << endl;
    else if (K == 32) cout << 51 << endl;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
l=A[0]/2.0
tmp=l
for a in A[1:]:
  tmp=a-tmp
ans=[int(l+tmp)]
for i in range(N-1):
  ans.append( int( (A[i]-ans[i]/2)*2 ) )
print(str(ans[0]),end='')
for a in ans[1:]:
  print(' '+str(a),end='')

Measured memory_bytes: 14092
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

vector<string> ok;
vector<int> p = {5, 4, 3, 0};
void dfs(string S, int N)
{
  if (N == 4) return;

  string SS = S;
  SS.insert(p.at(N), "A");
  ok.push_back(SS);
  
  dfs(SS, N + 1);
  dfs(S, N + 1);
}

signed main()
{
  string S;
  cin >> S;
  
  ok.push_back("KIHBR");
  dfs("KIHBR", 0);

  auto itr = find(ok.begin(), ok.end(), S);

  string ans = (itr != ok.end()) ? "YES" : "NO";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

struct UnionFind {
  vector<int> data;
  void init(int n) { data.assign(n, -1); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  bool same(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x), y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf;
  uf.init(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    uf.unite(a, b);
  }
  set<int> st;
  for (int i = 0; i < n; ++i) {
    st.insert(uf.root(i));
  }
  cout << st.size() - 1 << endl;
  return 0;
}

Measured memory_bytes: 7428
#include<bits/stdc++.h>
using namespace std;
int n, l, mod, dp1[157][157], dp2[307][157][157];
int main()
{
	cin >> n >> l >> mod;
	if (l % 2 == 0)
	{
		l /= 2;
		dp1[0][0] = 1;
		for (int i = 1; i <= n; i++)
		{
			for (int j = 0; j <= l; j++)
				dp1[i][0] = (dp1[i][0] + dp1[i - 1][j]) % mod;
			for (int j = 1; j <= l; j++)
				dp1[i][j] = (dp1[i][j] + dp1[i - 1][j - 1]) % mod;
		}
		int a = 0, b = 0;
		for (int i = 0; i <= l; i++)
			a = (a + dp1[n / 2][i]) % mod;
		for (int i = 0; i <= l; i++)
			b = (b + dp1[(n + 1) / 2][i]) % mod;
		cout << 1LL * a * b % mod << endl;
	}
	else
	{
		int lst = 0;
		dp2[0][0][0] = 1;
		for (int i = 2; i - l <= n; i += 2)
		{
			for (int j = 0; j <= n; j++)
				for (int k = 0; k <= l + 1; k++)
					dp2[i][0][0] = (dp2[i][0][0] + dp2[i - 2][j][k]) % mod;
			if (i <= n)
				for (int j = 0; j <= n; j++)
					for (int k = 0; k <= l + 1; k++)
						dp2[i][j + 1][0] = (dp2[i][j + 1][0] + dp2[i - 2][j][k]) % mod;
			if (i - l >= 1)
				for (int j = 0; j <= n; j++)
				{
					for (int k = 1; k <= l; k++)
						dp2[i][0][k + 1] = (dp2[i][0][k + 1] + dp2[i - 2][j][k]) % mod;
					dp2[i][0][0] = (dp2[i][0][0] + dp2[i - 2][j][0]) % mod;
				}
			if (i <= n && i - l >= 1)
				for (int j = 0; j <= n; j++)
					for (int k = 0; max(k, j + 1) <= l; k++)
						dp2[i][j + 1][max(k + 1, j + 2)] = (dp2[i][j + 1][max(k + 1, j + 2)] + dp2[i - 2][j][k]) % mod;
			lst = i;
		}
		int res = 0;
		for (int j = 0; j <= n; j++)
			for (int k = 0; k <= l + 1; k++)
				res = (res + dp2[lst][j][k]) % mod;
		cout << res << endl;
	}
	return 0;
}

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

int main(){
    int A,B;
    cin >> A >> B;
    cout << A*B << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <bits/stdc++.h>
#include<iostream>
#include<string>
using namespace std;
#define rep(i, n) for (int i = 0; i <(int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
const ll MOD=100000007;
const ll INF=1000000101001;
int main(){
string s;cin>>s;
string st[7]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
rep(i,7){
    if(s==st[i]&&s!=st[6])cout<<7-i-1<<endl;
}
if(s==st[6])cout<<7<<endl;
}

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

#define ll long long
#define pb push_back
#define fori(a,b) for(int i=a;i<b;i++)
#define ford(b,a) for(int i=b;i>=a;i--)
typedef pair<int, int> pi;
#define PI 3.14159265359
long long mod=1000000007;
//int count=INT_MAX;

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

// void solve(vector<int> a,vector<int> b,vector<int> add,vector<int> mult, int &ans,int t){
//     if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]){
//         ans=min(ans,t);
//     }
//     int d;
//     //for a[0]
//     d=add[0];
//     a[0]+=d;
//     add[0]-=d;
//     solve(a,b,add,mult,ans,t+1);
//     a[1]+=d;
//     add[1]-=d;




//     // vector<int> a1(3),vector<int> b1(3);
//     // fori(0,3){
//     //     int d=add[i];
//     //     //add to itself
//     //     a[i]+=d;
//     //     add[i]-=d;
//     //     solve(a,b,add,mult,ans,t+1);
        
//     // }
// }


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
    //cin>>t;
    //cout<<t;
    //scanf("%d",&t);
    while(t--){
        int x,y;
        cin>>x>>y;
        if(y<2*x||4*x<y){
            cout<<"No\n";
            return 0;
        }
        int a=y-(2*x);
        int b=(4*x)-y;
        if(a%2!=0||b%2!=0){
            cout<<"No\n";
            return 0;
        }
        cout<<"Yes\n";
        // vector<int> a(3);
        // vector<int> b(3);
        // cin>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];
        // int ans=3;
        // vector<int> add(3);
        // vector<int> mult(3);
        // fori(0,3){
        //     add[i]=b[i]-a[i];
        //     if(b[i]%a[i]==0){
        //         mult[i]=b[i]/a[i];
        //     }
        //     else{
        //         mult[i]=0;
        //     }
        // }
        // if(a[0]==b[0]&&a[1]==b[1]&&a[2]==b[2]){
        //     cout<<0<<endl;
        //     continue;
        // }
        // int t=0;
        // solve(a,b,add,mult,ans,t);
        // if(add[0]==add[1]&&add[1]==add[2]){
        //     cout<<1<<endl;
        //     continue;
        // }
        // if(mult[0]==mult[1]&&mult[1]==add[2]){
        //     cout<<1<<endl;
        //     continue;
        // }
        // if(a[1]==b[1]&&a[2]==b[2]){
        //     cout<<1<<endl;
        //     continue;
        // }
        // if(a[0]==b[0]&&a[2]==b[2]){
        //     cout<<1<<endl;
        //     continue;
        // }
        // if(a[1]==b[1]&&a[0]==b[0]){
        //     cout<<1<<endl;
        //     continue;
        // }

    }
    
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;


int main() {
    string s;
    cin >> s;
    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << endl;
    }
    else {      
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
const int MAX_N = 1<<18;
struct po{int l,r;};
int n;
po dat[2*MAX_N-1];

void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=(po){0,0};
}

void compute(int k,po t){
  if(t.r==0)return;
  if(dat[k].r==0) dat[k]=t;
  else if(dat[k].r==t.l-1)dat[k].r=t.r;
  else dat[k]=(po){INF,INF};
}

void query(int a,int b,int x,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return ;
  if(a<=l&&r<=b){
    compute(k,(po){x,x});
    return ;
  }
  
  int left=k*2+1,right=k*2+2;
  compute(left,dat[k]);
  compute(right,dat[k]);
  dat[k]=(po){0,0};

  query(a,b,x,left,l,(l+r)/2);
  query(a,b,x,right,(l+r)/2,r);
}

int main(){
  int N,k;
  cin>>n>>k;
  N=n;
  init(n);

  int q;
  cin>>q;
  while(q--){
    int l,r,x;
    cin>>l>>r>>x;
    query(l-1,r,x);
  }
  
  int ans=0;
  for(int i=0;i<N;i++){
    query(i,i+1,k+1);
    if(dat[i+n-1].l==1&&dat[i+n-1].r==k+1)ans++;
  }
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 7192
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#define ll long long
using namespace std;
int read()
{
    int x=0,f=1;
    char c=getchar();
    for(;c<'0'||c>'9';c=getchar()) if (c=='-') f=-1;
    for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
    return x*f;
}
const int N=301;
struct _
{
	int x,y;
	_(){}
	_(int x=0,int y=0):x(x),y(y){}
};
int n,m;
ll f[N][N][N],mo=1e9+7;
vector<_> v[N];
int pd(int i,int j,int k,int x)
{
	for(int l=0;l<v[x].size();++l)
	{
		int cnt=0;
		cnt=(v[x][l].x<=i)+(v[x][l].x<=j)+(v[x][l].x<=k);
		if(cnt!=v[x][l].y)return 0; 
	}
//	printf("%d %d %d %d\n",i,j,k,x);
	return 1;
}
int main()
{
	n=read(),m=read();
	int x,y,t;
	for (int i=1;i<=m;++i)
	x=read(),y=read(),t=read(),v[y].push_back(_(x,t));
	f[0][0][0]=1;
	ll ans=0;
	for(int i=0;i<n;++i)
	for(int j=0;j<n;++j)
	for(int k=0;k<n;++k)
	if(f[i][j][k])
	{
		x=max(i,max(j,k));
		if(pd(x+1,j,k,x+1))f[x+1][j][k]+=f[i][j][k],f[x+1][j][k]>=mo?f[x+1][j][k]-=mo:0;
		if(pd(i,x+1,k,x+1))f[i][x+1][k]+=f[i][j][k],f[i][x+1][k]>=mo?f[i][x+1][k]-=mo:0;
		if(pd(i,j,x+1,x+1))f[i][j][x+1]+=f[i][j][k],f[i][j][x+1]>=mo?f[i][j][x+1]-=mo:0;
	}
	for(int i=0;i<n;++i)
	for(int j=0;j<n;++j)
		ans+=f[i][j][n]+f[i][n][j]+f[n][i][j],ans%=mo;
//	printf("%d\n",f[3][0][1]);
	printf("%lld\n",ans);
}

Measured memory_bytes: 213248
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(long long x){
  int s=0;
  int m=0;
  char f[20];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[80];
long long dp[2][2];
long long nx[2][2];
int main(){
  int k;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  dp[0][1] = 1000;
  for(k=(0);k<(N);k++){
    int i;
    for(i=(0);i<(2);i++){
      int j;
      for(j=(0);j<(2);j++){
        nx[i][j] = dp[i][j];
      }
    }
    chmax(nx[0][1], dp[1][0] * A[k] + dp[1][1]);
    if(nx[1][0] < dp[0][1] / A[k]){
      nx[1][0] = dp[0][1] / A[k];
      nx[1][1] = dp[0][1] % A[k];
    }
    if(nx[1][0] == dp[0][1] / A[k]){
      chmax(nx[1][1], dp[0][1] % A[k]);
    }
    for(i=(0);i<(2);i++){
      int j;
      for(j=(0);j<(2);j++){
        dp[i][j] = nx[i][j];
      }
    }
  }
  wt_L(dp[0][1]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200509-1

// --- original code ---
// int N, A[80];
// ll dp[2][2], nx[2][2];
// {
//   rd(N,A(N));
//   dp[0][1] = 1000;
// 
//   rep(k,N){
//     rep(i,2) rep(j,2) nx[i][j] = dp[i][j];
//     nx[0][1] >?= dp[1][0] * A[k] + dp[1][1];
//     if(nx[1][0] < dp[0][1] / A[k]){
//       nx[1][0] = dp[0][1] / A[k];
//       nx[1][1] = dp[0][1] % A[k];
//     }
//     if(nx[1][0] == dp[0][1] / A[k]) nx[1][1] >?= dp[0][1] % A[k];
//     rep(i,2) rep(j,2) dp[i][j] = nx[i][j];
//   }
// 
//   wt(dp[0][1]);
// }


Measured memory_bytes: 3684
n, m = map(int, input().split())
AC = [0] * (n+1) #その問題で既に AC が出たか
b = [0] * (n+1) #その問題で WA が出た回数

WA = 0

for i in [0]*(m):

    s = input().split()

    if AC[int(s[0])] == 0:
        if s[1] == "AC":
            AC[int(s[0])] = 1
            WA += b[int(s[0])]
        else:
            b[int(s[0])] += 1

print(sum(AC), WA)


Measured memory_bytes: 5364
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long sum = 0;
		Map<Integer,Integer> a = new TreeMap<>();
		for(int i = 0; i < n; i++) {
			int temp = sc.nextInt();
			if(a.containsKey(temp)) {
				a.put(temp, a.get(temp)+1);
			}
			else {
				a.put(temp,1);
			}
			sum += temp;
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			int b = sc.nextInt();
			int c = sc.nextInt();
			if(a.containsKey(b)) {
			int temp = a.get(b);
			sum += (c-b)*temp;
			a.put(b,0);
			
			if(a.containsKey(c)) {
				a.put(c,a.get(c)+temp);
			}
			else {
				a.put(c,temp);
			}
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 66284
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	cin >> N >> M >> Q;
	N += 10;
	vector< vector< int > > S(N, vector< int >(N, 0));
	rep(i, M) {
		int L, R;
		cin >> L >> R;
		S[L][R]++;
	}
	rep(i, N) rep(j, N - 1) S[i][j + 1] += S[i][j];
	rep(j, N) rep(i, N - 1) S[i + 1][j] += S[i][j];
	while (Q--) {
		int p, q;
		cin >> p >> q;
		cout << S[q][q] - S[p - 1][q] - S[q][p - 1] + S[p - 1][p - 1] << endl;
		;
	}
	return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
int main(void){
  int n,t,a,h;
  int tmpr,ans=1;
  scanf("%d%d%d",&n,&t,&a);
  int min=999999;
  for(int i=1;i<=n;i++){
    scanf("%d",&h);
    tmpr=(t*1000-h*6)-a*1000;
    if(tmpr<0) tmpr=-tmpr;
    if(min>tmpr) {ans=i;min=tmpr;}
  }
  printf("%d",ans);
  return 0;
}

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

int main(){
  while(1){
    int n,i,j,key_num,temp;
    vector <int> key;
    vector <char> result;
    string angou;
    string moji="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    
    cin >> n;
    if(n==0)break;
    result.clear();
    key.clear();
    
    for(i = 0; i < n; i++){
      cin >> key_num;
      key.push_back(key_num);
    }
      
    cin >> angou;
    int len = key.size();
    int len2 = angou.size();
    int k = 0; 
    for(i = 0; i < len2; i++){
      for(j = 0; j < 52; j++){
	
	if(moji[j]==angou[i]){
	  result.push_back(moji[j+52-key[k]]);
	  // cout << "moji[j+52]" << moji[j+52] << endl;
	  //cout << "key[k] " << key[k] << endl;
	  //cout << "moji[j+52-key[k]]" << moji[j+52-key[k]] << endl;
	  // cout << "k " << k << endl;
	  k++;
	  if(k==len)k = 0;
	}
      }
    }
    int len3 = result.size();
    for(i = 0; i < len3; i++){
      cout << result[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,X;
	int L[100001];
	int sum=0;
	int ans=1;
	scan(N>>X);
	rep(i,N){
		scan(L[i]);
		sum+=L[i];
		if(sum<=X) ans++;
	}
	prin(ans);

	return 0;
}


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

using namespace std;

#define INF (100100100)

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

int main()
{
	int n;

	while (scanf("%d", &n), n){
		vector<string> step(n);

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

		int ans = 0;

		for (int i = 1; i < n; i++){
			if (step[i] == "lu" && step[i - 1] == "ru"){
				ans++;
			}
			if (step[i] == "ru" && step[i - 1] == "lu"){
				ans++;
			}
			if (step[i] == "ld" && step[i - 1] == "rd"){
				ans++;
			}
			if (step[i] == "rd" && step[i - 1] == "ld"){
				ans++;
			}
		}

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

	return (0);
}

Measured memory_bytes: 1228