akhauriyash/Code-Regression huggingface dataset:
// ConsoleApplication8.cpp : Этот файл содержит функцию "main". Здесь начинается и заканчивается выполнение программы.
//

#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> a(N);

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

	long long sum = 0;
	for (int i = 0; i < N; i++)
		for (int j = i + 1; j < N; j++)
		{
			sum += a[i] * a[j];
		}

	std::cout << sum;
}


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

int main() {
    int N, maxnum = 1, maxcount = 0;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        int j = 0;
        int num = i;
        while (num % 2 == 0) {
            num /= 2;
            j++;
        }
        if (j > maxcount) {
            maxnum = i;
            maxcount = j;
        }
    }
    cout << maxnum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    ll a,b; char op; cin >> a >>op >> b;

    if(op == '+') cout << a+b << endl;
    else cout << a-b << endl;
}
    
 
    

Measured memory_bytes: 256
/*
向前走K步的时候，
跳A步的点：(n-1)-(k-1)*C (n-1)-(k-2)*c ... n-1;
跳B步的点：c 2*c 3*c ... (k-1)*c;
向前走K+1步的时候，
跳A步的点：(n-1)-k*c (n-1)-(k-1)*c ... n-1;
跳B步的点：c 2*c 3*c ... k*c;
而且会发现跳AB步的点的递增大小都是c.
所以可以发现多了一步其实就是多了 跳A步的 (n-1)-k*c 和 跳B步的 k*c.
而且把 跳B步的点反过来，可以发现是一一对应的。即
(n-1)-k*c (n-1)-(k-1)*c ... n-1
k*c        (k-1)*c      ....c
所以每次增加一步的时候，就只是多了当前点的边上这两个点。
所以枚举k的时候，从两边开始加，意思就是步数最小的，然后往里面收缩，步数增大。 
其实这里应该要反过来想，本来应该是从最里面开始往外面枚举，步数每增加一步，左右两边就加上
但是这里才用反着的思想，效果都是一样的。
*/
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORX(i,n) for(int i=1;i<=n;i++)
#define lscan(x) scanf("%lld",&x);
#define scan(x) scanf("%d",&x);
#define print(x) printf("%d",x);
#define lprint(x) printf("%lld",x);
typedef long long ll;
const int N=1e5+200;
ll s[N],x[N],n,temp,l,r,cnt=0; 
ll ans=0;
int main(){
	scanf("%d",&n);
	FOR(i,n) lscan(s[i]);
	for(int c=1;c<n-1;c++){//枚举每一个c，c的范围就是[1,n-2]. 不可能为n-1，A=N B=1是不成立 
		ll temp=0;
		l=0,r=n-1;
		cnt++;//cnt 的作用就是防止走到了空的地方 
		//对k进行枚举 
		while(l!=r&&r>c&&l<n-1&&x[l]!=cnt&&x[r]!=cnt){
			temp+=s[l];temp+=s[r];
			x[l]=x[r]=cnt;
			l+=c;r-=c;
			ans=max(ans,temp);
		} 
	}
	lprint(ans);
} 
 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n, x, y, mn[200007], a, b, tot, res = 1, ires = 1, inv[200007];
vector<int>num[200007];
int read()
{
	int num = 0;
	char c = getchar();
	while (c < '0' || c>'9')c = getchar();
	while (c >= '0' && c <= '9')num = num * 10 + c - '0', c = getchar();
	return num;
}
int main()
{
	n = read();
	x = read();
	y = read();
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; i++)
		inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	memset(mn, 0x3f, sizeof mn);
	for (int i = 1; i <= n; i++)
	{
		int a = read(), b = read();
		num[a].push_back(b);
		mn[a] = min(mn[a], b);
	}
	for (int i = 1; i <= n; i++)
		if (mn[i] < mn[a])
			a = i;
	for (int i = 1; i <= n; i++)
		if (mn[i] < mn[b] && i != a)
			b = i;
	if (!b || mn[a] + mn[b] > y)
	{
		cout << 1 << endl;
		return 0;
	}
	for (int i = 1; i <= n; i++)
		if (!num[i].empty() && mn[i] + mn[a] <= y)
		{
			int cnt = 0;
			for (int j = num[i].size() - 1; j >= 0; j--)
				if (i == a)
					cnt += (num[i][j] + mn[b] <= y || num[i][j] + mn[i] <= x);
				else cnt += (num[i][j] + mn[a] <= y || num[i][j] + mn[i] <= x);
			tot += cnt;
			for (int j = 1; j <= cnt; j++)
				ires = 1LL * ires * inv[j] % mod;
		}
	for (int i = 1; i <= tot; i++)
		res = 1LL * res * i % mod;
	cout << 1LL * res * ires % mod << endl;
	return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    ll n,k;
    cin>>n>>k;
    vector<pair<ll, ll> >ab(n);
    for(int i=0;i<n;i++){
        cin>>ab.at(i).first>>ab.at(i).second;
    }
    sort(ab.begin(),ab.end());
    ll tmp=0;
    ll ans=0;
    for(int i=0;i<n;i++){
        tmp+=ab.at(i).second;
        if(tmp>=k){
            ans=i;
            break;
        }
    }
    cout<<ab.at(ans).first<<endl;






    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=2e5+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const double eps=1e-8;
const double pi=acos(-1);
LL n,m;
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
LL qpow(LL a,LL p)
{
    LL res=1;
    while(p){
        if(p&1) res=res*a%mod;
        a=a*a%mod;
        p>>=1;
    }
    return res;
}
LL inv(LL x)
{
    return qpow(x,mod-2);
}
LL hhh(LL a,LL b)
{
    a++; b++;
    LL res=1;
    FOR(i,1,a){
        res=res*(a+b-i+1)%mod;
    }
    FOR(i,1,a){
        res=res*inv(i)%mod;
    }
    return (res-1+mod)%mod;
}
int main()
{
    LL r1,r2,c1,c2;
    rrr(r1,c1,r2); r(c2);
    LL a1=hhh(r2,c2);
    LL a2=hhh(r1-1,c1-1);
    LL a3=hhh(r1-1,c2);
    LL a4=hhh(r2,c1-1);
    //cout<<a1<<' '<<a2<<' '<<a3<<' '<<a4<<endl;
    cout<<(a1+a2-a3-a4+mod+mod)%mod<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    k = f()[0]

    slen = len(s)
    for i in range(k):
        if s[i] != '1':
            print(s[i])
            return
    
    print(1)
    

solve()


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<cstdio>

using namespace std;

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

int main(){
    long int const mod = 1000000007;
    long int n, m;
    cin >> n >> m;
    long int s[n];
    long int t[m];
    rep(i, n) cin >> s[i];
    rep(i, m) cin >> t[i];
    long int sm[n][m];
    long int dp[n][m];
    if (s[0] == t[0]){
        dp[0][0] = 1;
        sm[0][0] = 1;
    }else{
        dp[0][0] = 0;
        sm[0][0] = 0;  
    }
    
    
    rep(i, n-1){
        if (s[i+1] == t[0]){
            dp[i+1][0] = 1;
            sm[i+1][0] = sm[i][0] + dp[i+1][0];
        }else{
            dp[i+1][0] = 0;
            sm[i+1][0] = sm[i][0];
        }
        dp[i+1][0] %= mod;
        sm[i+1][0] %= mod;
    }
    rep(j, m-1){
        if (s[0] == t[j+1]){
            dp[0][j+1] = 1;
            sm[0][j+1] = sm[0][j] + dp[0][j+1];
        }else{
            dp[0][j+1] = 0;
            sm[0][j+1] = sm[0][j];
        }
        dp[0][j+1] %= mod;
        sm[0][j+1] %= mod;
    }

    rep(i, n - 1)rep(j, m - 1){
        if (s[i+1] == t[j+1]){
            dp[i+1][j+1] = sm[i][j] + 1;
            sm[i+1][j+1] = mod + sm[i+1][j] + sm[i][j+1] - sm[i][j] + dp[i+1][j+1];
        }else{
            dp[i+1][j+1] = 0;
            sm[i+1][j+1] = mod + sm[i+1][j] + sm[i][j+1] - sm[i][j] + dp[i+1][j+1];
        }
        dp[i+1][j+1] %= mod;
        sm[i+1][j+1] %= mod;
        // if (sm[i+1][j+1] < 0){
        //     cout << sm[i+1][j+1] << " " << sm[i+1][j] << " " << sm[i][j+1] << " " << sm[i][j] << endl;
        //     throw;
        // }
    }
    // rep(i, n){
    //     rep(j, m){
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    // rep(i, n){
    //     rep(j, m){
    //         cout << sm[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << (sm[n-1][m-1] + 1) % mod << endl;
}


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

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

Measured memory_bytes: 3972
#include<bits/stdc++.h>
using namespace std;
void Out(long long X)
{
  if(X==0)
    return ;
X--;
  long long Rem=X%26ll;
  Out(X/26ll);
  cout<<(char)(Rem+'a');
}
int main()
{
  long long X;
  cin>>X;
  Out(X);
  return 0;
}


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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


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



  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <utility>
static int isort(long *a, int n, int g) {
    int c = 0;
    for (int i = g; i < n; ++i) {
        long v = a[i];
        int j = i - g;
        for (; j >= 0 && a[j] > v; j -= g, ++c) {
            a[j + g] = a[j];
        }
        a[j + g] = v;
    }
    return c;
}
static int ssort(long *a, int n) {
    int c = 0, m = 1, g[100] = { 1 };
    for (int gm = 3 * g[0] + 1; gm < n; gm = 3 * g[++m - 1] + 1) {
        g[m] = gm;
    }
    std::cout << m << std::endl;
    for (int i = 0; i < m; ++i) {
        std::cout << ((i == 0) ? "" : " ") << g[m - i - 1];
        c += isort(a, n, g[m - i - 1]);
    }
    std::cout << std::endl;
    return c;
}
int main() {
    int n;
    long a[1000000];
    std::cin >> n;
    for (int i = 0; i < n; ++i) {
        std::cin >> a[i];
    }
    std::cout << ssort(a, n) << std::endl;
    for (int i = 0; i < n; ++i) {
        std::cout << a[i] << std::endl;
    }
}



Measured memory_bytes: 10856
import itertools

N,C =map(int,input().split())
D = [0]+[[0]+list(map(int,input().split())) for i in range(C)]

c = [list(map(int,input().split())) for i in range(N)]

grids = [[],[],[]]#振り分ける
for i in range(N):
    for j in range(N):
        grids[(i+j)%3].append(c[i][j])

iwa = [[0]*(C+1) for i in range(3)]#grids[i]を色jにした時の違和感

for i in range(3):
    for j in range(1,C+1,1):
        for k in range(len(grids[i])):
            iwa[i][j]+=D[grids[i][k]][j]

ans = float("inf")
for bits in itertools.permutations(list(range(1,C+1)),3):
    tmpans = 0
    for i in range(3):
        tmpans +=iwa[i][bits[i]]
    ans = min(tmpans,ans)

print(ans)

Measured memory_bytes: 91584
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define ins insert
#define sz(x) (long long)x.size()
typedef long long ll;
typedef long double ld;
const int N = 1e5 + 5;
const ld pi = 3.141592653;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;
const ll INF = __LONG_LONG_MAX__;

using namespace std;

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

int main()
{
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int T = 1;
        //cin>>T;
        while(T--)
        {
                string s;
                int ans=0, i;
                cin>>s;
                for(i=0; i<sz(s); i++) ans += s[i] - '0';
                if(ans%9==0) cout<<"Yes";
                else cout<<"No";
        }
        return 0;
}

Measured memory_bytes: 3728
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

struct Edge {
    int to, cost, time;
    Edge(int to_, int cost_, int time_) : to(to_), cost(cost_), time(time_){};
};

struct Vertex {
    int silver, time_per_gold;
    Vertex() = default;
    Vertex(int silver_, int time_per_gold_)
        : silver(silver_), time_per_gold(time_per_gold_){};
};

struct Data {
    int vertex, money;
    long long sum_time;
    Data(int vertex_, int money_, long long sum_time_)
        : vertex(vertex_), money(money_), sum_time(sum_time_){};
    bool operator<(const Data& rhs) const& { return sum_time > rhs.sum_time; }
};

int main()
{
    const long long INF = 1e18;
    const int MAX_V = 50;
    const int MAX_MONEY = 50 * 50 + 5;

    int numv, nume, money;
    cin >> numv >> nume >> money;

    money = min(MAX_MONEY, money);

    vector<vector<Edge>> edges(numv);
    vector<Vertex> verticies(numv);

    for (int i = 0; i < nume; i++) {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        edges[u].emplace_back(v, a, b);
        edges[v].emplace_back(u, a, b);
    }

    for (int i = 0; i < numv; i++) {
        int c, d;
        cin >> c >> d;
        verticies[i].silver = c;
        verticies[i].time_per_gold = d;
    }

    vector<vector<long long>> dp(MAX_V, vector<long long>(MAX_MONEY + 10, INF));
    priority_queue<Data> q;

    auto push = [&](int vertex_, int money_, long long sum_time) {
        if (money_ < 0) return;
        if (dp[vertex_][money_] <= sum_time) return;
        dp[vertex_][money_] = sum_time;
        q.emplace(vertex_, money_, sum_time);
    };

    push(0, money, 0);
    while (!q.empty()) {
        auto tempdata = q.top();
        q.pop();

        int tempv = tempdata.vertex;
        int tempmoney = tempdata.money;
        long long tempsum_time = tempdata.sum_time;

        if (dp[tempv][tempmoney] != tempsum_time) continue;

        push(tempv, min(verticies[tempv].silver + tempmoney, MAX_MONEY),
             tempsum_time + verticies[tempv].time_per_gold);

        for (const auto& e : edges[tempv]) {
            push(e.to, tempmoney - e.cost, tempsum_time + e.time);
        }
    }

    for (int i = 1; i < numv; i++) {
        long long ans = INF;
        for (int j = 0; j < MAX_MONEY + 10; j++) { ans = min(dp[i][j], ans); }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 5828
w,h,n = map(int,input().split())

min_w = 0
max_w = w
min_h = 0
max_h = h

for i in range(n):
    x,y,a = map(int,input().split())
    if a == 1:
        min_w = max(x,min_w)
    elif a == 2:
        max_w = min(x,max_w)
    elif a == 3:
        min_h = max(y,min_h)
    elif a == 4:
        max_h = min(y,max_h)

if (max_h - min_h) <= 0 or (max_w - min_w) <= 0:
    print(0)
else:
    print((max_h - min_h)*(max_w - min_w))

    


Measured memory_bytes: 3064
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**7) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

s = ns()
t = ns()

lens = len(s)
lent = len(t)

dp = [[0]*(lent+1) for _ in range(lens+1)]

for idx in range(lens):
    for jdx in range(lent):
        dp[idx+1][jdx+1] = max(dp[idx][jdx] + bool(s[idx] == t[jdx]),
                               dp[idx+1][jdx],
                               dp[idx][jdx+1])
    
def lcs(spos: int, tpos: int, cur: str, s:str, t:str, dp: list) -> str:

    if spos == 0 or tpos == 0:
        return cur
    
    else:
        nrth = dp[spos-1][tpos]
        west = dp[spos][tpos-1]
        ntws = dp[spos-1][tpos-1]

        mx = max(nrth, west, ntws)
        
        if mx == ntws and ntws+1 == dp[spos][tpos]:
            return lcs(spos-1, tpos-1, cur+s[spos-1], s,t,dp)
 
        
        elif mx == nrth:
            return lcs(spos-1, tpos, cur, s, t, dp)
        
        else:
            return lcs(spos, tpos-1, cur, s, t, dp)
            
           

            
            
print(lcs(lens, lent, "", s, t, dp)[::-1])

Measured memory_bytes: 128476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int INF = 1e9+10;
int main()
{
    int n;
    cin >> n;
    vector<int> a(n+1);
    for(int i = 1; i <= n; i++)
    {
        int x;
        cin >> x;
        a[x] = i;
    }
    set<int> s;
    s.insert(0);
    s.insert(n+1);
    ll ans = 0;
    for(int i = 1; i <= n; i++)
    {
        int pos = a[i];
        auto it = s.lower_bound(pos);
        ll h = *it;
        it--;
        ll l = *it;
        ans += (pos - l) * (h - pos) * i;
        s.insert(pos);
    }
    cout << ans << endl;
}


Measured memory_bytes: 13564
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;

int main(){
	int k, s, x, y, ans=0;
	cin>>k>>s;
	for(x=0; x<=k; x++){
		for(y=0; y<=k; y++){
			if(x+y<=s && x+y+k>=s) ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
ll n,m,i,j,k,l,t,a,b,c,d;
map<ll,ll>mp;
int main()
{
    scanf("%lld %lld",&n,&k);
    for(i=1;i<=k;i++)
    {
        scanf("%lld",&a);
        while(a--)
        {
            scanf("%lld",&b);
            mp[b]++;
        }
    }
    b=n-mp.size();
    printf("%lld\n",b);
}


Measured memory_bytes: 3832
/*
void allans(int i, int j, string s){
	if(i==0||j==0){
		ans.pb(s);
		return;
	}
	if(s1[i-1]==s2[j-1]){
		allans(i-1, j-1, s1[i-1]+s);
		return;
	}
	if(dp[i-1][j]>=dp[i][j-1])
		allans(i-1, j, s);

	if(dp[i-1][j]<=dp[i][j-1])
		allans(i, j-1, s);
}*/

/*
//dp for scs

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

	for(int i=1; i<=m; ++i)
		dp[0][i]=i;

	for(int i=1; i<=n; ++i){
		for(int j=1; j<=m; ++j){
			if(s1[i-1]==s2[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=min(dp[i-1][j]+1, dp[i][j-1]+1);
		}
	}


void scs(int i, int j, string sf){
	if(i==0){
		ans.pb(s2.substr(0, j)+sf); return;
	}
	if(j==0){
		ans.pb(s1.substr(0, i)+sf); return;
	}
	if(s1[i-1]==s2[j-1]){
		scs(i-1, j-1, s1[i-1]+sf); return;
	}

	if(dp[i-1][j] <= dp[i][j-1])
		scs(i-1, j, s1[i-1]+sf);

	if(dp[i-1][j] >= dp[i][j-1])
		scs(i, j-1, s2[j-1]+sf);
}*/

/*
max area of rect with all 1s
with max hist algo

int maxAr(int index){
	stack<int> s;
	int i=0, maxSf=0;
	while(i<n){
		if(s.empty() || a[index][i]>=a[index][s.top()])
			s.push(i++);
		else{
			int t=s.top(), f;
			s.pop();
			if(s.empty())
				f=i;
			else
				f=i-s.top()-1;
			maxSf=max(maxSf, a[index][t]*f);
		}

	}

	while(!s.empty()){
		int t=s.top(), f;
		s.pop();
		if(s.empty())
			f=i;
		else
			f=i-s.top()-1;
		maxSf=max(maxSf, a[index][t]*f);
	}


	return maxSf;
}
*/

/*
int ans(int i, int j){
	if(i<0||i>=n||j<0||j>=m)
		return 0;
	string key=to_string(i)+"|"+to_string(j);
	auto it = mpx.find(key);

	if(it==mpx.find(key)){
		if(i>0&&a[i-1][j]==a[i][j]+1){
			mpx[key]=ans(i-1, j)+1;
			return mpx[key];
		}
		if(j>0&&a[i][j-1]==a[i][j]+1){
			mpx[key]=ans(i, j-1)+1;
			return mpxCABA[key];
		}
		if(j<m-1&&a[i][j+1]==a[i][j]+1){
			mpx[key]=ans(i, j+1)+1;
			return mpx[key];
		}
		if(i<n-1&&a[i+1][j]==a[i][j]+1){
			mpx[key]=ans(i+1, j)+1;
			return mpx[key];
		}
		return 1;
	}

	return mpx[key];

}

*/

//const int N = 125250, mxN=1000, M = 1e9+7;

/*
void solve(){
    int n, k, p, ans=0;
	cin >> n >> k >> p;
	vector<vector<int>> dp(n+1, vector<int>(p+1, 0));

	for(int i=1; i<=n; ++i){
		int s=0;
		for(int j=1, r; j<=k; ++j){
			cin >> r;
			s+=r;
			for(int f=j; f<=p; ++f){
				dp[i][f]=m ax({dp[i-1][f], dp[i][f], s+dp[i-1][f-j]});
				ans=max(ans, dp[i][f]);
			}
		}
	}
	cout << ans << ends;
}

*/

#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define zeroend __builtin_ctz
#define ones __builtin_popcount
#define ends "\n"
#define space ' '
typedef long long ll;
typedef pair<int, int> pii;

const int N=21, M=1e9+7;

ll dp[1<<N];
int a[N][N];

int n;


int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    cin >> n;
    for(int i=0; i<n; ++i){
    	for(int j=0; j<n; ++j){
    		cin >> a[i][j];
    	}
    }
    dp[0]=1LL;
    for(int s=0; s<(1<<n)-1; ++s){
    	int i=__builtin_popcount(s);
    	for(int j=0; j<n; ++j)
    		if(a[i][j]&&!(s&(1<<j)))
    			dp[s|(1<<j)]=(dp[s|(1<<j)]+dp[s])%M;
    }

    cout << dp[(1<<n)-1] << ends;
	
}



Measured memory_bytes: 19992
#include<bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    long n, k;
    cin >> n >> k;
    vector<long> a(n);
    for(auto &x: a) cin >> x;

    unsigned long r = 0;
    for(int l=0; l<n; l++)
        r += k ^ a[l];

    for(int i=0; i<45; i++) {
        unsigned long rr = 0;

        for(int j=0; j<i; j++) {
            unsigned long s = 0, t = 0;
            for(int l=0; l<n; l++)
                if((1ULL<<j) & a[l])
                    s += 1ULL<<j;
                else
                    t += 1ULL<<j;
            rr += max(s, t);
        }

        {
            int j = i;
            if(!((1ULL<<j) & k)) continue;

            for(int l=0; l<n; l++)
                rr += (1ULL<<j) & (0ULL ^ a[l]);
        }

        for(int j=i+1; j<45; j++) {
            for(int l=0; l<n; l++)
                rr += (1ULL<<j) & (k ^ a[l]);
        }

        r = max(r, rr);
    }
    cout << r << endl;
}


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

#define IOS                           \
    std::ios::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
#define int long long
const int inf = 1 << 30;
#define INF 1e+9
#define MAX_V 100008
const int MOD = 1e9 + 7;


  vector<vector<int>> Block(MAX_V);
  vector<vector<int>> Friends(MAX_V);
  vector<int> group(MAX_V, -1);
  vector<int> group_num(100005, 0);

void dfs(int v, int n){
  if(group[v] != -1) return ;
  group[v] = n;
  group_num[n]++;
  for (auto nv: Friends[v]){
    if(group[nv] != -1) continue;
    dfs(nv, n);
  }
}


signed main(){
  IOS
  int N, M, K;
  cin >> N >> M >> K;

  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    Friends[a].push_back(b);
    Friends[b].push_back(a);
  }

  int count = 0;
  
  for (int v=0; v<N; v++){
    if(group[v] == -1){
      dfs(v, count);
    }
    count++;
  }
  // cout << count << endl;
  // vector<int> group_friend(count-1);
  // vector<int> group_block(count-1);

  
  // for (int i=0; i<N; i++){
  //   group_num[group[i]]++;
  //   // group_friend[group[i]] += (Friends[i].size());
  //   // group_block[group[i]] += (Block[i].size());
  // }

  vector<int> ans(N);
   for (int i=0; i<N; i++){
    ans[i] = group_num[group[i]] - Friends[i].size() - 1;
  }

  // for (auto it: ans){ cout << it << endl;}
  for (int i=0; i<K; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    if(group[a] == group[b]){
      ans[a]--;
      ans[b]--;
    }
  }
  for (auto it: ans){ cout << it << " ";}
  cout << endl;
  

}


Measured memory_bytes: 14360
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    long N;
    scan(N);
    auto ans = N * (N - 1) / 2;
    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
#include<cstdio>  
#include<iostream>  
#include<algorithm>  
#include<cstdlib>  
#include<cstring>
#include<string>
#include<climits>
#include<vector>
#include<cmath>
#include<map>
#define LL long long
#define pii pair<int,int>
#define mp make_pair
 
using namespace std;
 
inline char nc(){
  static char buf[100000],*p1=buf,*p2=buf;
  if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
  return *p1++;
}
 
inline void read(int &x){
  char c=nc();int b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline void read(LL &x){
  char c=nc();LL b=1;
  for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
  for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
 
inline int read(char *s)
{
	char c=nc();int len=1;
	for(;!(c>='a' && c<='z');c=nc()) if (c==EOF) return 0;
	for(;(c>='a' && c<='z');s[len++]=c,c=nc());
	s[len++]='\0';
	return len;
}
 
inline void read(char &x){
  for (x=nc();!(x>='A' && x<='Z');x=nc());
}
 
int wt,ss[19];
inline void print(int x){
	if (x<0) x=-x,putchar('-'); 
	if (!x) putchar(48); else {
	for (wt=0;x;ss[++wt]=x%10,x/=10);
	for (;wt;putchar(ss[wt]+48),wt--);}
}
inline void print(LL x){
	if (x<0) x=-x,putchar('-');
	if (!x) putchar(48); else {for (wt=0;x;ss[++wt]=x%10,x/=10);for (;wt;putchar(ss[wt]+48),wt--);}
}
 
int n,a[100010],b[100010],c[100010],d[100010],e[100010],f[100010];
int sum[100010],g[100010];

void updata(int x,int y)
{
	for (;x<=n;x+=x&(-x)) g[x]+=y;
}

int SUM(int x)
{
	int res=0;
	for (;x;x-=x&(-x)) res+=g[x];
	return res;
}

void change(int x,int y)
{
	for (;x<=n;x+=x&(-x)) sum[x]+=y;
}

int query(int x)
{
	int res=0;
	for (;x;x-=x&(-x)) res+=sum[x];
	return res;
}
 
bool check()
{
	int x,y,z,t;
	for (int i=1;i<=n;i++)
	{
		x=(a[i]-1)/3;t=x+1;
		f[i]=t;
		if (i%2!=t%2) return false;
		y=x*3+2,z=x*3+3,x=x*3+1;
		if (a[i]==x && b[i]==y && c[i]==z) {e[t]=2*n;continue;}
		if (a[i]==z && b[i]==y && c[i]==x) {e[t]=2*n+1;continue;}
		return false;
	}
	return true;
}
 
int main()
{
	read(n);
	for (int i=1;i<=n;i++)
		read(a[i]);
	for (int i=1;i<=n;i++)
		read(b[i]);
	for (int i=1;i<=n;i++)
		read(c[i]);
	if (!check()) {puts("No");return 0;}
	memset(sum,0,sizeof(sum));
	memset(g,0,sizeof(g));
	for (int i=1;i<=n;i++)
		if (i%2==1) change(i,1);
	int x;
	for (int i=n;i>=1;i--)
		if (i%2==1)
		{
			x=f[i];
			d[x]=query(n)-query(x);
			d[x]+=SUM(x);
			change(x,-1);updata(x,1);
		}
	memset(sum,0,sizeof(sum));
	memset(g,0,sizeof(g));
	for (int i=1;i<=n;i++)
		if (i%2==0) change(i,1);
	for (int i=n;i>=1;i--)
		if (i%2==0)
		{
			x=f[i];
			d[x]=query(n)-query(x)+SUM(x);
			change(x,-1);updata(x,1);
		}
	for (int i=1;i<=n;i++)
		e[i]=(e[i]-d[i])%2;
	int s=0,t=0;
	for (int i=1;i<=n;i++)
		if (i%2==0) s+=e[i];else t+=d[i];
	t/=2;
	if (s%2!=t%2) {puts("No");return 0;}
	s=0,t=0;
	for (int i=1;i<=n;i++)
		if (i%2==1) s+=e[i];else t+=d[i];
	t/=2;
	if (s%2!=t%2) {puts("No");return 0;}
	puts("Yes");
	return 0;
}

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

int par[100010];
int ra[100010];
int weight[100010];

void init(int n){
  for(int i=0;i<n;i++){
    par[i]=i;ra[i]=0;weight[i]=0;
  }
  return;
}

int root(int n){
  if(par[n]==n){
    return n;
  }
  int r=root(par[n]);
  weight[n]+=weight[par[n]];
  return par[n]=r;
}

void unite(int x,int y,int w){
  int rx=root(x),ry=root(y);
  if(rx==ry){
    return;
  }
  if(ra[rx]<ra[ry]){
    par[rx]=ry;
    weight[rx]=-w-weight[x]+weight[y];
  }  
  else{
    par[ry]=rx;
    weight[ry]=w+weight[x]-weight[y];
    if(ra[rx]==ra[ry]) ra[rx]++;
  }
  return;
}

bool same(int x,int y){
  return root(x)==root(y);
}

int diff(int x,int y){
  return weight[x]-weight[y];
}

int main() {
  int n,m;
  cin>>n>>m;
  init(n);
  for(int i=0;i<m;i++){
    int l,r,d;
    cin>>l>>r>>d;
    if(same(l-1,r-1)){
      if(d==diff(r-1,l-1)) continue;
      else {
        cout<<"No"<<endl;
        return 0;
      }
    }
    else unite(l-1,r-1,d);
  }
  cout<<"Yes"<<endl;
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> tup;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> p;
typedef vector<p> vp;
const int INF=1e9;
int main(int argc,char const* argv[])
{
  int n,k;
  cin >> n >> k;
  vector<int> a(n+5);
  int index1=0;
  int llength=0;
  int rlength=0;
  for(int i=0;i<n;i++)
    {
      cin >> a[i];
    }
  int ans=0;
  if(n==k)ans=1;
  else
    {
      ans++;
      ans+=ceil(double(n-k)/(k-1));
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define REV(v) reverse(v.begin(),v.end())
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
#define v1out(v) FOR(j,0,v.size()){cout<<v[j]; if(j!=(ll)v.size()-1)cout<<" ";else cout<<endl; }
#define v2out(v) FOR(i,0,v.size())v1out(v[i]);

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<ll> v(n,1);
    FOR(i,0,k){
        ll d;
        cin>>d;
        FOR(i,0,d){
            ll in;
            cin>>in;
            v[in-1] = 0;
        }
    }
    ll ans=0;
    FOR(i,0,n){
        ans += v[i];
    }
    cout<<ans<<endl;
}

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

	//最大公約数
	ll gcd(ll a, ll b) {
	  while (a && b) {
    if (a >= b) a %= b;
	    else b %= a;
  }
 return a + b;
}
//最小公倍数
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b;}


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

    cout << lcm(A,B) << endl;
}

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

int main() {
    ios::sync_with_stdio(false);

    int H;
    while (cin >> H, H) {
        vector<vector<int>> field(H, vector<int>(6, -1));

        for (int y = 0; y < H; ++y) {
            for (int x = 0; x < 5; ++x) {
                cin >> field[y][x];
            }
        }

        int score = 0;
        for (;;) {
            vector<vector<bool>> deleted(H, vector<bool>(6));
            bool done = true;

            for (int y = 0; y < H; ++y) {
                int run = 1;
                for (int x = 1; x < 6; ++x) {
                    if (field[y][x] == field[y][x-1]) {
                        ++run;
                    } else {
                        if (field[y][x-1] != 0 && run >= 3) {
                            score += field[y][x-1] * run;
                            done = false;
                            for (int k = 1; k <= run; ++k)
                                deleted[y][x-k] = true;
                        }
                        run = 1;
                    }
                }
            }

            for (int x = 0; x < 5; ++x) {
                int p = H-1;
                for (int y = H-1; y >= 0; --y) {
                    if (!deleted[y][x]) {
                        field[p][x] = field[y][x];
                        --p;
                    }
                }
                for ( ; p >= 0; --p)
                    field[p][x] = 0;
            }

            if (done)
                break;
        }

        cout << score << endl;
    }
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 105;
int n, m, ans, a, b, c;
vector<int> M[2010]; // at most 2000 edges
bool good[1010];
vector<int> e[N];
int dist[N];

auto cmp = [](int a, int b){
    int f1 = M[a][0], w1 = M[a][2];
    int f2 = M[b][0], w2 = M[b][2];
    int aa = dist[f1] + w1;
    int bb = dist[f2] + w2;
    return aa >= bb;
};
void run(int x) {
    memset(dist, 0x3f, sizeof dist);
    priority_queue<int, vector<int>, decltype(cmp)> que(cmp);
    dist[x] = 0;
    for (auto z : e[x]) {
        que.push(z);
    }
    while (!que.empty()) {
        int y = que.top();
        que.pop();
        int f = M[y][0], t = M[y][1], w = M[y][2];
        int ndist = dist[f] + w;
        if (dist[t] > ndist) {
            dist[t] = ndist;
            good[y % m] = true;
            for (int z : e[t]) {
                que.push(z);
            }
        } else if (dist[t] == ndist) {
            good[y % m] = true;
        }
    }
}

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> a >> b >> c;
        M[i] = {a, b, c};
        M[m + i] = {b, a, c};
        e[a].push_back(i);
        e[b].push_back(i + m);
    }
    for (int i = 1; i <= n; ++i) {
        run(i);
    }
    for (int i = 0; i < m; ++i) {
        if (good[i])
            ++ans;
    }

    cout << m - ans << endl;
    return 0;
}


Measured memory_bytes: 3756
import java.io.BufferedReader
import java.io.InputStreamReader
import kotlin.math.min

const val MOD = 998244353L

fun main() {
    val jin = BufferedReader(InputStreamReader(System.`in`))
    val line = jin.readLine().split(" ")
    val s = line[0]
    val k = line[1].toInt()
    val ones = mutableListOf<Int>()
    var curr = 0
    for (chara in s.reversed()) {
        when (chara) {
            '0' -> {
                ones.add(curr)
                curr = 0
            }
            '1' -> curr += 1
        }
    }
    ones.add(curr)
    var dp = Array(301) { LongArray(601) }
    dp[0][0] = 1L
    var j = 0
    for (nu in ones) {
        j++
        val dpUp = Array(301) { LongArray(601) }
        val dpDown = Array(301) { LongArray(601) }
        for (b in 0..300) {
            for (c in 0..600) {
                if (b > 0 && c > 0) {
                    dpUp[b][c] = dpUp[b - 1][c - 1]
                    dpUp[b][c] += dp[b - 1][c - 1]
                }
                if (b - nu - 1 >= 0 && c - nu - 1 >= 0) {
                    dpUp[b][c] -= dp[b - nu - 1][c - nu - 1]
                }
                dpUp[b][c] %= MOD
            }
        }
        for (b in 300 downTo 0) {
            for (c in 600 downTo 0) {
                if (b + 1 <= 300 && c > 0) {
                    dpDown[b][c] = dpDown[b + 1][c - 1]
                }
                dpDown[b][c] += dp[b][c]
                dpDown[b][c] %= MOD
            }
        }
        for (b in 0..300) {
            dp[b].fill(0L)
            for (c in 0..600) {
                dp[b][c] = dpDown[b][c] + dpUp[b][c]
                dp[b][c] %= MOD
            }
        }
    }
    var answer = 0L
    for (c in 0..min(600, 2 * k)) {
        answer += dp[0][c]
        answer %= MOD
    }
    answer += MOD
    answer %= MOD
    println(answer)
}

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

typedef long long int ll;
#define endl "\n"
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pair<int, int>>
#define mems(x, y) memset(x, y, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define forn(i, s, e) for(int i = s; i < (e); ++i)
#define FASTIO                                                                                     \
	ios_base::sync_with_stdio(false);                                                              \
	cin.tie(NULL);
#define FILEIO                                                                                     \
	freopen("./input.txt", "r", stdin);                                                            \
	freopen("./output.txt", "w", stdout);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d)                                                                                  \
	for(auto blockTime = make_pair(chrono::high_resolution_clock::now(), true); blockTime.second;  \
		debug("%s : %lld ms\n ",                                                                   \
			  d,                                                                                   \
			  chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() -   \
														  blockTime.first)                         \
				  .count()),                                                                       \
			 blockTime.second = false)
const int M = 1e9 + 7;

template <class T>
T ABS(const T& x) {
	return x > 0 ? x : -x;
}
ll gcd(ll n1, ll n2) { return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2); }
ll lcm(ll n1, ll n2) { return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2); }
ll ceil2(ll a, ll b) { return (a + b - 1) / b; }

int main() {
	FASTIO
#ifdef LOCAL
	FILEIO
#endif
	int n;
	cin >> n;
	int mx1 = INT_MIN, mn1 = INT_MAX, mx2 = INT_MIN, mn2 = INT_MAX;
	int x, y;
	for(int i = 0; i < n; ++i) {
		cin >> x >> y;
		mx1 = max(mx1, x + y);
		mx2 = max(mx2, x - y);
		mn1 = min(mn1, x + y);
		mn2 = min(mn2, x - y);
	}

	cout << max(mx1 - mn1, mx2 - mn2);
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>
 
int main() {
 
  long long i,j,k,n,m,l,a,b,c;
  long long A[101][101] = {0};
  long long B[101][101] = {0};
  long long C[101][101] = {0};
 
  scanf("%lld %lld %lld",&n,&m,&l);
 
  for(j=0; j<n; j++) {
    for(i=0; i<m; i++) {
 
      scanf("%lld", &a);
      A[j][i] = a;
     
    }
  }
 
  for(j=0; j<m; j++){
    for(i=0;i<l;i++){
      scanf("%lld",&b);
      B[j][i] = b;
    }
  }
 
    for(i=0 ;i<n; i++) {
      for(j=0; j<l; j++){
    C[i][j] = 0;
    for(k=0;k<m; k++) {
       C[i][j] += A[i][k]*B[k][j];  
       /*    printf("%d ",C[i][j]); */
    }
    /* printf("\n"); */
      }
    }
 
 
     for(i=0; i<n; i++) {
      for(j=0; j<l; j++) {
    printf("%lld",C[i][j]);
    if(j !=l-1) {
      printf(" ");
    }
      }
      printf("\n");
      } 
 
    return 0;
 }


Measured memory_bytes: 2104
#include <bits/stdc++.h>
using i64 = long long;

struct Edge {
    int from, to;
    i64 cost;
    Edge(int f, int t, i64 c) : from(f), to(t), cost(c) {}
};

int main() {
    int n, m;
    i64 p;
    std::cin >> n >> m >> p;
    std::vector<Edge> g;
    for (int i = 0; i < m; i++) {
        int a, b;
        i64 c;
        std::cin >> a >> b >> c;
        --a; --b;
        g.emplace_back(a, b, p - c);
    }

    constexpr i64 inf = std::numeric_limits<i64>::max();
    std::vector<i64> dist(n, inf);
    dist[0] = 0;
    for (int i = 0; i < n - 1; i++) {
        for (auto &e : g) {
            if (dist[e.from] == inf) continue;
            dist[e.to] = std::min(dist[e.to], dist[e.from] + e.cost);
        }
    }

    auto ret = dist[n - 1];
    for (int i = 0; i < n - 1; i++) {
        for (auto &e : g) {
            if (dist[e.from] == inf) continue;
            dist[e.to] = std::min(dist[e.to], dist[e.from] + e.cost);
        }
    }

    std::cout << (ret == dist[n - 1] ? std::max(-ret, 0ll) : -1) << std::endl;

    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>

using namespace std;

#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define irep(i, n) for (int64_t i = 0; i <= (int64_t)(n); i++)
#define rrep(i, n) for (int64_t i = (n)-1; i >= 0; i--)
#define rirep(i, n) for (int64_t i = n; i >= 0; i--)

void solve(vector<int> &group, int N, int M) {
  if (group.size() == N) {
    rep(i, N) { cout << (char)(group[i] + 'a'); }
    cout << "\n";
  } else {
    irep(i, M) {
      group.push_back(i);
      solve(group, N, M);
      group.pop_back();
    }

    group.push_back(M + 1);
    solve(group, N, M + 1);
    group.pop_back();
  }
}

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

  vector<int> group(1, 0);
  solve(group, N, 0);

  return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 998244353
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  rep(i,0,365){
    Out(i%26+1);
  }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 300005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN];
int l[MAXN], r[MAXN];
int main() {
	int n; read(n);
	scanf("%s", s + 1);
	for (int i = 2; i <= n; i++)
		l[i] = l[i - 1] + (s[i - 1] == 'W');
	for (int i = n - 1; i >= 1; i--)
		r[i] = r[i + 1] + (s[i + 1] == 'E');
	int ans = n;
	for (int i = 1; i <= n; i++)
		chkmin(ans, l[i] + r[i]);
	writeln(ans);
	return 0;
}

Measured memory_bytes: 2944
use std::io;

fn main() {
    let line = parse_line::<String>();
    let mut ss = line.split_whitespace();
    let a = ss.next().unwrap().parse::<i64>().unwrap();
    let b = ss.next().unwrap().parse::<i64>().unwrap();
    let k = ss.next().unwrap().parse::<i64>().unwrap();
    let (i1, i2) = resolve(a, b, k);
    println!("{} {}", i1, i2);
}

fn resolve(a: i64, b: i64, k: i64) -> (i64, i64) {
    if a >= k {
        (a - k, b)
    } else {
        let m = a + b - k;
        if m > 0 {
            (0, m)
        } else {
            (0, 0)
        }
    }
}

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

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		if(N==1){
			System.out.println("Hello World");
			return;
		}else{
			int A = sc.nextInt();
			int B = sc.nextInt();
		System.out.println(A+B);
		}
	}
}


Measured memory_bytes: 21716
<?php

$list = [];

$blue_num = (int)trim(fgets(STDIN));

for ($i = 0; $i < $blue_num; $i++)
{
    $blue_input = trim(fgets(STDIN));
    $list[$blue_input] = (isset($list[$blue_input]))? $list[$blue_input] + 1 : 1;
}

$red_num = (int)trim(fgets(STDIN));

for ($i = 0; $i < $red_num; $i++)
{
    $red_input = trim(fgets(STDIN));
    $list[$red_input] = (isset($list[$red_input]))? $list[$red_input] - 1 : -1;
}

$max = max($list);
echo ($max <= 0)? 0 : $max;


Measured memory_bytes: 4856
//In the name of ALLAH
#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
const bool DEBUG = false;
#define cerr if(DEBUG)cerr
using namespace std;

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

const long long maxn = 2e5 + 5;
const long long INF = 4e18 ;
const long long M = 1e9 + 7;
const int lg = 21;

int n, a[2][maxn], dp[2][maxn];

int main(){
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for(int i = 0; i < 2; i++)
		for(int j = 0; j < n; j++)
			cin >> a[i][j];
	dp[0][0] = a[0][0];
	for(int i = 1; i < n; i++)
		dp[0][i] = dp[0][i - 1] + a[0][i];
	dp[1][0] = a[0][0] + a[1][0];
	for(int i = 1; i < n; i++)
		dp[1][i] = max(dp[0][i], dp[1][i - 1]) + a[1][i];
	cout << dp[1][n - 1] << endl; 	
	return 0;
}


Measured memory_bytes: 256
using System;
class B_Bite_Eating{
	static void Main(string[] args){
		string[] NL = Console.ReadLine().Split(' ');
		int N = int.Parse(NL[0]);
		int L = int.Parse(NL[1]);
		int Eaten;
		if(L <= 0 && L + N - 1 >= 1)Eaten = 0;
		else{
			if(Math.Abs(L) < Math.Abs(L + N - 1))Eaten = L;
			else Eaten = L + N - 1;
		}
		Console.WriteLine(N * (2 * L + N - 1) / 2 - Eaten);
	}
}

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

int main()
{
    int N, l, r;
    cin >> N;
    int sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> l >> r;
        sum += r - l + 1;
    }
    cout << sum << endl;
}


Measured memory_bytes: 3564