akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.Write(IrohaAndHaiku_ABCEdition());
    }

    private static string IrohaAndHaiku_ABCEdition()
    {
        //句の文字数情報を読み込む
        int[] ku = new int[3];
        string[] line = Console.ReadLine().Split(' ');

        for (int i = 0; i < line.Length; i++)
        {
            ku[i] = int.Parse(line[i]);
        }

        //ソート
        Array.Sort(ku);

        //5が2つ、7が1つないと俳句作れない
        for (int i = 0; i < 2; i++)
        {
            if (ku[i] != 5) return "NO";
        }
        if (ku[2] != 7) return "NO";

        //条件を満たしたので俳句ができる
        return "YES";
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

int rr[4], aa[4];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int2(r, a);
    if(!(r | a))break;

    rr[0] = r % 10; rr[1] = (r / 10) % 10; rr[2] = (r / 100) % 10; rr[3] = r / 1000;
    aa[0] = a % 10; aa[1] = (a / 10) % 10; aa[2] = (a / 100) % 10; aa[3] = a / 1000;

    int res[2] = {0};
    rep(i, 4)if(rr[i] == aa[i])++res[0];
    rep(i, 4)rep(j, 4)if(rr[i] == aa[j]){
      ++res[1]; break;
    }

    pri2(res[0], res[1] - res[0]);

//*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 3124
#include <iostream>
#include <vector>
#include <algorithm>
typedef long long ll;
using namespace std;

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

  int H,W;
  cin >> H >> W;
  char a[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }

  int dp[H][W];//dp[i][j]:点(i,j)までの経路の数
  if(a[0][0]=='.') dp[0][0]=1;
  else dp[0][0]=0;
  for(int i=1;i<H;i++){
    if(a[i][0]=='#') dp[i][0]=0;
    else dp[i][0]=dp[i-1][0];
  }
  for(int j=1;j<W;j++){
    if(a[0][j]=='#') dp[0][j]=0;
    else dp[0][j]=dp[0][j-1];
  }

  /*for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << dp[i][j];
    }
    cout << endl;
  }*/

  for(int i=1;i<H;i++){
    for(int j=1;j<W;j++){
      if(a[i][j]=='#') dp[i][j]=0;
      else{
        dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
      }
    }
  }

  /*for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cout << dp[i][j];
    }
    cout << endl;
  }*/

  cout << dp[H-1][W-1] <<endl;
  return 0;
}


Measured memory_bytes: 5120
package main

import (
	"fmt"
)

func main() {
	var x, y int
	fmt.Scan(&x,&y)
	
	ans := 0
	ans += prize(x)
	ans += prize(y)
	
	if x == 1 && y == 1 {
		ans += 400000
	}
	fmt.Println(ans)
}

func prize(num int)int {
	money := 0
	if num == 1 {
		money = 300000
	} else if num == 2 {
		money = 200000
	} else if num == 3 {
		money = 100000
	}
	return money
}

Measured memory_bytes: 512
N, A, B = map(int, input().split())
S = input()
domestic = 0
abroad = 0
for i in range(N):
    if S[i] == 'a':
        if domestic+abroad < A+B:
            print('Yes')
            domestic += 1
        else:
            print('No')
    elif S[i] == 'b':
        if domestic+abroad < A+B and abroad < B:
            print('Yes')
            abroad += 1
        else:
            print('No')
    else:
        print('No')

Measured memory_bytes: 75756
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t N;
  cin >> N;
  int64_t a,b;
  
  for (int i = 1; i <= sqrt(N);i++) {
    if(N % i == 0) {
      a = i;
      b = N / i;
    }
  }
  
  cout << a + b - 2 << endl;
}

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


int main(){
    int a, b, c;
    int x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for(int i=0; i <= a; i++){
        for(int j=0; j <= b; j++){
            for(int k=0; k <= c; k++){
                if((500*i + 100*j + 50*k) == x) {
                    ans += 1;
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
L=sorted(list(map(int,input().split())))
memo=[0]*2000
for l in L:
  memo[l-1]+=1
for i in range(1999):
  memo[i+1]=memo[i+1]+memo[i]
ans=0
for i in range(n-2):
  for j in range(i+1,n-1):
    a=L[i]
    b=L[j]
    ans+=memo[a+b-2]-j-1
print(ans)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
int a,b,c,count=0; 
  cin>>a>>b>>c;
  if(a==b)
    count++;
  if(a==c)
    count++;
  if(b==c)
    count++;
  if(a==b&&b==c)
    count=2;
 cout<<3-count<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	long long n,sum=0,i,a[1000001];
	scanf("%lld",&n);
	for(i=1;i<=n;i++)
	{
	   a[i]=i;
	   if(i%3==0||i%5==0)
	   {
	   	a[i]=0;
	   }
	}
	for(i=1;i<=n;i++)
	{
		sum=sum+a[i];
	}
	printf("%lld",sum);
}

Measured memory_bytes: 9448
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  lol ans[100] = {};
  ans[0] = 2;
  ans[1] = 1;
  cin >> n;
  for(int i = 2;i <= n;i ++){
    ans[i] += ans[i - 1] + ans[i - 2];
  }
  cout << ans[n] << '\n';
  return 0;
}


Measured memory_bytes: 256
n, x = gets.split.map(&:to_i)
m = 2 * n - 1
if x == 1 || x == m
  puts 'No'
  exit
end
a = (1..m).to_a
if x < n
  y = x + n - 1
  a = a[y...m] + a[0...y]
elsif x > n
  y = x - n
  a = a[y...m] + a[0...y]
end
puts 'Yes'
a.each do |i|
  puts i
end


Measured memory_bytes: 7036
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str=sc.next().split("");
		int price=700;

		for(int i=0;i<3;i++) {
			if(str[i].equals("o")) {
				price+=100;
			}
		}
		System.out.println(price);
	}
}

Measured memory_bytes: 21588
#include <cstdio>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <unordered_map>

struct Node {
    Node() :
        parent(nullptr),
        left(nullptr),
        right(nullptr),
        id(-1),
        sibling(-1),
        degree(0),
        depth(0),
        height(0)
    {
    }
    Node* parent;
    Node* left;
    Node* right;
    int   id;
    int   sibling;
    int   degree;
    int   depth;
    int   height;

    bool operator<(const Node& rhs) const {
        return (this->id < rhs.id);
    }
};

void setDepth(Node& node, int d)
{
    node.depth = d;
    if (node.left != nullptr) {
        setDepth(*(node.left), d + 1);
    }

    if (node.right != nullptr) {
        setDepth(*(node.right), d + 1);
    }
}

int getHeight(Node& node)
{
    int left_height = 0;
    if (node.left != nullptr) {
        left_height = getHeight(*(node.left)) + 1;
    }

    int right_height= 0;
    if (node.right != nullptr) {
        right_height = getHeight(*(node.right)) + 1;
    }

    return std::max(left_height, right_height);
}

void printNodes(const Node* nodes, int n)
{
    for (int i = 0; i < n; ++i) {
        std::printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",
                    nodes[i].id,
                    ((nullptr == nodes[i].parent) ? -1 : nodes[i].parent->id),
                    nodes[i].sibling,
                    nodes[i].degree,
                    nodes[i].depth,
                    nodes[i].height);

        if (nodes[i].parent == nullptr) {
            std::printf("root\n");
        } else if (nodes[i].left == nullptr && nodes[i].right == nullptr) {
            std::printf("leaf\n");
        } else {
            std::printf("internal node\n");
        }
    }
}

int main()
{
    int n;
    std::cin >> n;
    Node nodes[n];

    int id, l, r;
    for (int i = 0; i < n; ++i) {
        std::cin >> id >> l >> r;
        nodes[id].id = id;
        if (l != -1) {
            nodes[id].left   = &(nodes[l]);
            nodes[id].degree += 1;
            nodes[l].parent = &(nodes[id]);
            nodes[l].sibling = r;

        }

        if (r != -1) {
            nodes[id].right = &(nodes[r]);
            nodes[id].degree += 1;
            nodes[r].parent = &(nodes[id]);
            nodes[r].sibling = l;
        }
    }

    for (int i = 0; i < n; ++i) {
        if (nodes[i].parent == nullptr) {
            setDepth(nodes[i], 0);
            break;
        }
    }

    for (int i = 0; i < n; ++i) {
        nodes[i].height = getHeight(nodes[i]);
    }

    std::sort(nodes, nodes + n);
    printNodes(nodes, n);

    return 0;
}


Measured memory_bytes: 3212
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int a,b,c,d,e,k;

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

        cin >> a >> b >> c >> d >> e >> k;

        if (e - a > k)
                cout << ":(" <<endl;
        else
                cout << "Yay!" << endl;


        return 0;
}


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

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

  int n, i;
  cin >> n >> i;
  cout << n - i + 1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef int lli;

lli P,Q,A,N,ans;

void rec(lli child, lli parent, lli th, lli pre) {
  if(th == N) return;
  for(lli i = min(pre,A/parent); i >= 1; --i) {
    lli nc = child*i+parent;
    lli np = parent*i;
    if(Q*nc > P*np) break;
    if(Q*nc == P*np) ++ans;
    else rec(nc,np,th+1,i);
  }
}

int main() {
  while(cin >> P >> Q >> A >> N && (P|Q|A|N)) {
    ans = 0;
    rec(0,1,0,A);
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 864
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.next();
		char[] s_chars = s.toCharArray();
		Arrays.sort(s_chars);
		String s_asc = new String(s_chars);
		
		String t = sc.next();
		char[] t_chars = t.toCharArray();
		Arrays.sort(t_chars);
		String t_asc = new String(t_chars);
		String t_desc = new StringBuilder(t_asc).reverse().toString();
		
		if(s_asc.compareTo(t_desc) < 0)
			System.out.println("Yes");
		else 
			System.out.println("No");
		sc.close();
	}

	void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <tuple>
#include <set>
#include <functional>

using namespace std;


int main() {
    int n, m, c;
    cin >> n >> m >> c;

    vector<int> b(m);
    vector<vector<int>> a(n, vector<int>(m));

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

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

    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bitset>
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
 
 
int main() {
	using uint32 = std::uint_fast32_t;
	using int32 = std::int_fast32_t;
	constexpr uint32 SIZ = 17000;
	std::string s;
	int32 x, y;
	std::cin >> s >> x >> y;
	const uint32 len = s.length();
	std::vector<uint32> a, b;
	uint32 it = 0;
	while (it < len)
		if (s[it] == 'F')
			--x, ++it;
		else
			break;
	for (bool f = 1;it < len;++it)
		if (s[it] == 'T')
			(f ^= 1) ? a.push_back(0) : b.push_back(0);
		else
			f ? ++a.back() : ++b.back();
	std::bitset<SIZ> dpx, dpy;
	x += std::accumulate(a.begin(), a.end(), 0);
	y += std::accumulate(b.begin(), b.end(), 0);
	if (x < 0 || y < 0) {
		puts("No");
		return 0;
	}
	dpx.set(0);
	for (const auto d : a)
		dpx |= dpx << (d << 1);
	dpy.set(0);
	for (const auto d : b)
		dpy |= dpy << (d << 1);
	puts(dpx[x] && dpy[y] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 888
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
ll C;
ll N;
ll L;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;
    cin >> L;

    ll sumA=0;
    rep(ni,N){
        ltmp = L+(ni+1)-1;
        A.push_back(ltmp);
        sumA+=ltmp;
    }
    
    ll ans = sumA;
    if(A[0]>0) ans-=A[0];
    else if(A[N-1]<0) ans-=A[N-1];
    
    cout << ans << endl;


    

}

Measured memory_bytes: 3656
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<i64>();
    let _ = read::<i64>();
    let _ = read::<i64>();
    let _ = read::<i64>();
    let e = read::<i64>();
    let k = read::<i64>();
    println!("{}", if e - a <= k { "Yay!" } else { ":(" });
}


Measured memory_bytes: 4352
n, m = gets.chomp.split.map(&:to_i)
likes = Array.new(m, 0)

n.times do
  input = gets.chomp.split.map(&:to_i)
  input[1..-1].each do |i|
    likes[i-1] += 1
  end
end

puts likes.select {|l| l == n}.length


Measured memory_bytes: 1788
def linput():
    return list(map(int,input().split(" ")))


N,K=linput()
ab=[]
for i in range(N):
    ab.append(linput())

ab=sorted(ab,key=lambda x:x[0])

k=0
for i,r in enumerate(ab):
    k+=r[1]
    if k>=K:
        print(ab[i][0])
        break


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

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> b(M);
  for(int i = 0; i < M; i++) {
    cin >> b.at(i);
  }
  vector<vector<int>> a(N, vector<int>(M));
  int count = 0;
  for(int i = 0; i < N; i++) {
    int temp = C;
    for(int j =0; j < M; j++) {
      cin >> a.at(i).at(j);
      temp += a.at(i).at(j) * b.at(j);
    }
    if(temp > 0) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const int INF = INT_MAX;
const ll MOD = 998244353;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;cin>>N;
  ll ans=0;
  ll minabs=INF;
  bool oddminus=false;
  repeat(i,N){
    ll A;cin>>A;
    ans += abs(A);
    minabs = min(minabs,abs(A));
    oddminus ^= A<0;
  }
  if(oddminus){
    ans -= 2*minabs;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;


namespace ConsoleApplication22
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] input = Console.ReadLine().Split(' ');
            long n = long.Parse(input[0]);
            long m = long.Parse(input[1]);
            long l = long.Parse(input[2]);
            if (n < 1 || m < 1 || l < 1)
            {
                if (n < 1)
                    n = 1;
                else if (m < 1)
                    m = 1;
                else if (l < 1)
                    l = 1;
            }
            else if (n > 101 && m > 101 && l > 101)
            {
                if (n > 100)
                    n = 100;
                else if (m > 100)
                    m = 100;
                else if (l > 100)
                    l = 100;
            }

            long[,] A = new long[n, m];
            long[,] B = new long[m, l];

            for (long y = 0; y < n; y++)
            {
                String[] input2 = Console.ReadLine().Split(' ');
                for (long x = 0; x < m; x++)
                {
                    long an = long.Parse(input2[x]);
                    if (an < 0)
                    {
                        an = 0;
                    }
                    
                    else if (an > 10000)
                    {
                        an = 10000;
                    }

                    A[y, x] = an;
                }
            }
            for (long y = 0; y < m; y++)
            {
                String[] input3 = Console.ReadLine().Split(' ');
                for (long x = 0; x < l; x++)
                {
                    long bn = long.Parse(input3[x]);
                    if (bn < 0)
                    {
                        bn = 0;
                    }
                    else if (bn > 10000)
                    {
                        bn = 10000;
                    }
                    B[y, x] = bn;
                }
            }
            long[,] C = new long[n, l];
            long cn = 0;
            for (long z = 0; z < n; z++)
            {
                for (long y = 0; y < l; y++)
                {
                    for (long x = 0; x < m; x++)
                    {
                        cn = A[z, x] * B[x, y];
                        C[z, y] = C[z, y] + cn;
                    }
                }
            }
            for (long y = 0; y < n; y++)
            {
                for (long x = 0; x < l; x++)
                {
                    Console.Write(C[y, x]);
                    if (x != l-1)
                        Console.Write(" ");
                }
                    Console.WriteLine("");
            }
        }
    }
}

Measured memory_bytes: 9616
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
void solve()
{
    ll n,m;cin>>n>>m; vector<ll>vc(n); ll sum=0;
    for(ll i=1;i<=n;i++)
    {
        cin>>vc[i-1];
        sum+=vc[i-1];
    }
    ll val=ceil(sum*1.0/(4*m));
    sort(vc.begin(),vc.end());
    auto it=lower_bound(vc.begin(),vc.end(),val)-vc.begin();
    if(vc[it]==val)
    {
        it--;
    }
    if(vc.size()-it<m)
        cout<<"No"<<endl;
    else
        cout<<"Yes"<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
s=[input() for i in range(n)]
# lst=[[0]*2 for i in range(n)]

sei=[]
hu=[]

for i in range(n):
    l,r=0,0
    for j in range(len(s[i])):
        if s[i][j]==")":
            if r==0:
                l+=1
            else:
                r-=1
        if s[i][j]=="(":
            r+=1
    if r-l>0:
        sei.append([l,r-l])
    else:
        hu.append([r,l-r])

sei.sort(key=lambda x: x[0])
hu.sort(key=lambda x: x[0])

tmp=0

for i in range(len(sei)):
    if tmp-sei[i][0]<0:
        print("No")
        quit()
    tmp+=sei[i][1]

tmp2=0
for i in range(len(hu)):
    if tmp2-hu[i][0]<0:
        print("No")
        quit()
    tmp2+=hu[i][1]

if tmp==tmp2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 250888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{	
	ll n,sum=0;
	cin>>n;
	vector<ll>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
		sum+=v[i];
	}
	sort(v.begin(),v.end());
	cout<<v[0]<<" "<<v[n-1]<<" "<<sum<<endl;
	return 0;	
}


Measured memory_bytes: 3212
#include <stdio.h>
int main(){
    int a,b,c,d,x=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    if (abs(a-b)<=d&&abs(b-c)<=d)
    {
        x=1;
    }else if(abs(a-c)<=d)
    {
        x=1;
    }
    if (x==1)
    {
        printf("Yes\n");
    }else
    {
        printf("No\n");
    }
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

long long num[26],tot,ans;

int main(){
	string a;
	cin>>a; ans=1;
	for(int i=0;i<a.size();i++){
		ans+=tot-num[a[i]-'a'];
		num[a[i]-'a']++; tot++;
	}
	cout<<ans<<endl;
	return 0;
}

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

void dfs(vector<vector<int>> g, bool seen[], int start, int d[], int f[], int &first)
{
    seen[start] = true;
    d[start] = first++;
    for (auto v : g[start])
    {
        if (seen[v])
        {
            continue;
        }
        dfs(g, seen, v, d, f, first);
    }
    f[start] = first++;
}

int main()
{
    int n;
    int first = 1;
    int last = 1;
    cin >> n;
    int d[n + 1], f[n + 1];
    bool seen[n + 1];
    vector<vector<int>> g(n + 1);
    for (int i = 1; i <= n; i++)
    {
        seen[i] = false;
        int u, k;
        cin >> u >> k;
        for (int j = 0; j < k; j++)
        {
            int v;
            cin >> v;
            g[u].push_back(v);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        if (!seen[i])
        {
            dfs(g, seen, i, d, f, first);
        }
    }
    for (int i = 1; i <= n; i++)
    {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }
}



Measured memory_bytes: 3608
N, T = map(int, input().split())
ct = [[] for _ in range(N)]
for i in range(N):
    ct[i] = list(map(int, input().split()))
cost =[]
for v in ct:
    if v[1] <= T:
        cost.append(v)
if len(cost) <1:
    print('TLE')
else:
    for i, v in enumerate(cost):
        if i == 0:
            least = v[0]
        else:
            if v[0] <= least:
                least = v[0]
    print(least)

Measured memory_bytes: 3064
#include <bits/stdc++.h>  
 
using namespace std;
 
//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
 
const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};
 
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int cnt[100000], mini;

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

    int n;
    cin >> n;
    int res = 0;
    rep(i, n) {
        int a;
        cin >> a;
        if(a == 0) {
            ++mini;
            chmax(res, mini);
        }
        else {
            ++cnt[a - 1];
            chmax(res, cnt[a - 1]);
        }
        ++cnt[a + 1];
        chmax(res, cnt[a + 1]);
        ++cnt[a];
        chmax(res, cnt[a]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define rep(i, a, n) for(int i=a; i<(n); ++i)
typedef long long ll;

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

    vector<int> a(n);
    map<int, int> Syain;
    rep(i, 0, n) 
    {
        cin >> a[i];
        ++Syain[a[i] - 1];
    }

    rep(i, 0, n)
    {
        cout << Syain[i] << endl;
    }
}

Measured memory_bytes: 13516
//#pragma GCC optimize ("O3")
//#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

constexpr int bm = 2500;
ll BIT[50][bm];
int zero[50];
void add(int A, int gin, ll co) {
	co = 4e12 - co;
	while (gin > 0) {
		if (BIT[A][gin] >= co) break;
		BIT[A][gin] = co;
		gin -= gin & -gin;
	}
}
ll query(int A, int gin) {
	ll kotae = 0;
	while (gin < bm) {
		kotae = max(BIT[A][gin], kotae);
		gin += gin & -gin;
	}
	return 4e12 - kotae;
}

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


	int N, M, S;
	cin >> N >> M >> S;
	if (S >= 2460) S = 2460;

	vector<ll> E[50];
	rep(i, M) {
		int u, v, a;
		ll b;
		cin >> u >> v >> a >> b;
		u--;
		v--;
		b = a << 8 | b << 16;
		E[u].pb(v | b);
		E[v].pb(u | b);
	}
	int C[50], D[50];
	rep(i, N) {
		cin >> C[i] >> D[i];
	}

	add(0, S + 1, 0);
	priority_queue<ll, vector<ll>, greater<ll> > PQ;
	PQ.push(S + 1);
	ll zenbu = 0;

	while (PQ.size()) {
		auto p = PQ.top();
		PQ.pop();
		ll ti = p >> 18;
		int i = p >> 12 & 63;
		int gin = p & 4095;

		zenbu |= 1ll << i;

		if (ti > query(i, gin)) continue;

		ll ti2 = ti + D[i];
		int gin2 = gin + C[i];
		if (gin2 > 2460) gin2 = 2460;
		if (ti2 < query(i, gin2)) {
			add(i, gin2, ti2);
			PQ.push(ti2 << 18 | i << 12 | gin2);
		}

		for (auto pp : E[i]) {
			int to = pp & 255;
			ti2 = ti + (pp >> 16);
			gin2 = gin - (pp >> 8 & 255);
			if (gin2 > 0) {
				if (ti2 < query(to, gin2)) {
					add(to, gin2, ti2);
					PQ.push(ti2 << 18 | to << 12 | gin2);
				}
			}
		}
		if (zenbu == (1ll << N + 1) - 1) break;
	}

	for (int i = 1; i < N; i++) {
		co(query(i, 1));
	}



	Would you please return 0;
}

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


bool checkans (vector<int> p,int x){
    int l = p.size();
    bool flag = true;
    for(int i = 0;i<l;++i){
        if(p.at(i)==x){
            flag =false;
        }
    }
    return flag;
}

int main(){
    int x ,n;cin>>x>>n;
    vector <int> p(n);
    rep(i,n){
        cin>>p.at(i);
    }
    bool one =checkans(p,x) ;
    if(one){
        cout<<x<<endl;
        return 0;
    }

    int ans = 0;
    int count = 1;
    while(1){
       // bool under = binary_search(p.begin(),p.end(),x-count);
       // bool top =  binary_search(p.begin(),p.end(),x+count);
       bool under = checkans(p,x-count);
       bool top = checkans(p,x+count);
        if(under){
            ans = x-count;
            break;
        }
        if(top){
            ans = x+count;
            break;
        }
        ++count;
    }
    cout<<ans<<endl;

}



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

#define MAX_S 1010
#define MAX_T 1010

template<typename T> int lcs(T s,T t){
    int lens=s.size();
    int lent=t.size();
    int dp[MAX_S+1][MAX_T+1]={};
    
    
    for(int i=0;i<lens;i++){
        for(int j=0;j<lent;j++){
            if(s[i]==t[j])  dp[i+1][j+1] = dp[i][j]+1;
            else            dp[i+1][j+1] = max(dp[i][j+1],dp[i+1][j]);
        }
    }
    return dp[lens][lent];
}

int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s,t;
        cin>>s>>t;
        cout<<lcs(s,t)<<endl;
    }
}

Measured memory_bytes: 7136
import sys
input = sys.stdin.buffer.readline
from itertools import permutations

def main():
    N,C = map(int,input().split())
    D = [list(map(int,input().split())) for _ in range(C)]
    col = [list(map(int,input().split())) for _ in range(N)]
    
    mod_color = [[0]*C,[0]*C,[0]*C]
    for i in range(N):
        for j in range(N):
            mod_color[(i+j)%3][col[i][j]-1] += 1

    ans = 10**10
    for x,y,z in permutations(range(C),3):
        ret = 0
        ret += sum(mod_color[0][i]*D[i][x] for i in range(C))
        ret += sum(mod_color[1][i]*D[i][y] for i in range(C))
        ret += sum(mod_color[2][i]*D[i][z] for i in range(C))
        ans = min(ans,ret)
        
    print(ans)
    
if __name__ == "__main__":
    main()


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());

  int ans = v[v.size()/2] - v[v.size()/2 - 1];

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


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

#define rep(i, a) for (int i = 0; i < (int) a; i++)
#define all(v) (v).begin(), (v).end()

vector<bool> ng(10);

bool ch(int x)
{
	while (x) {
		if (ng[x % 10]) return false;
		x /= 10;
	}
	return true;
}

signed main()
{
	int N, K;
	cin >> N >> K;
	rep(i, K) {
		int t;
		cin >> t;
		ng[t] = true;
	}
	int res;
	for (res = N; !ch(res); res++);
	cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h, w;
  cin >> h >> w;

  string G[h];
  for (int i = 0; i < h; i++) cin >> G[i];

// 周囲四方向の差分を持った配列
 int dx[4] = {0, 1, 0, -1};
 int dy[4] = {1, 0, -1, 0};

  bool can = true;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (G[i][j] == '#') {
        bool sharp = false;
        for (int d = 0; d < 4; d++) { //四方の確認
          if (i + dy[d] < 0 || h <= i + dy[d]) continue; //表外の確認
          if (j + dx[d] < 0 || w <= j + dx[d]) continue; //continueはそれ以下の処理は行わずfor loopを次に進める
          if (G[i + dy[d]][j + dx[d]] == '#') sharp = true; //四方の#の確認
        }
        if (sharp == false) can = false;
      }
    }
  }
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

ll solve(vector<tuple<ll,ll,ll>>& vt) {
  sort(ALL(vt));
  reverse(ALL(vt));
  ll sum = 0;
  priority_queue<ll> q;
  ll n = size(vt);
  int j = 0;
  REP(ri,n) {
    int i = n - 1 - ri;
    while (j < n) {
      auto&&[k,l,r] = vt[j];
      if (k < i) break;
      q.push(l-r);
      sum += r;
      ++j;
    }
    if (!q.empty()) {
      sum += q.top();
      q.pop();
    }
  }
  while (j < n) {
    auto&&[k,l,r] = vt[j];
    sum += r;
    ++j;
  }
  return sum;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  cin>>t;
  REP(cnum,t) {
    int n;
    cin>>n;
    vector<tuple<ll,ll,ll>> left, right;
    REP(i,n) {
      ll k,l,r;
      cin>>k>>l>>r;
      if (l >= r) {
        left.emplace_back(k-1, l, r);
      } else {
        right.emplace_back(n-k-1, r, l);
      }
    }
    ll ans = solve(left) + solve(right);
    cout<<ans<<"\n";
  }
  return 0;
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}


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

  int n;
  cin >> n;

  ll ans = 0;

  for(ll i = 1; i <= n; i++){

    ll cnt = n / i;
    ans += i * cnt * (cnt + 1) / 2;

  }

  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 3600
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
// #include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);

	const int num = s[0];

	if (0 == num % 2) {
		printf("0.5\n");
	} else {
		double buf = ((num - 1) / 2) + 1;
		double result = buf / num;
		printf("%lf\n", result);
	}

	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


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

    string s;
    int ans=0;
    cin>>s;
    for(int i=1;i<=STI(s);i++){
        string t="";
        int tmp=i;
        while(tmp>0){
            t+=tmp%10+'0';
            tmp/=10;
        }
        reverse(all(t));
        if(t.length()%2==1)ans++;
    }
    fin(ans);


//////////////////////////////////////////////////////
return 0;}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

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

static const ll INF = 1e15;

static const ll mod = 1e9 + 7;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};


int main() {
	ll n, k;
	cin >> n >> k;
	vector<ll> as(n);
	rep(i, n)cin >> as[i];
	vector<vector<ll>> dp(n, vector<ll>(k + 1, 0));
	vector<vector<ll>> sums(n, vector<ll>(k + 2, 0));
	rep(i, k + 1) {
		if (i <= as[0]) {
			dp[0][i] = 1;
		}
		sums[0][i + 1] = sums[0][i] + dp[0][i];
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			dp[i][j] = sums[i - 1][j + 1] - sums[i - 1][max(0LL, j - as[i])];
			dp[i][j] += mod;
			dp[i][j] %= mod;
		}
		rep(j, k + 1) {
			sums[i][j + 1] = sums[i][j] + dp[i][j];
			sums[i][j + 1] %= mod;
		}
	}
	cout << dp[n - 1][k] << endl;
	return 0;
}
	

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

public class Prog
{
    public void run()
    {
        int N = int.Parse(Console.ReadLine());
        var input = Console.ReadLine().Split();
        int[] B = Array.ConvertAll(input, int.Parse);
        int[] A = new int[N];
        A[0] = B[0];
        for(int i=1; i < N-1; i++)
        {
            A[i] = Math.Min(B[i], B[i - 1]);
        }
        A[N - 1] = B[N - 2];
        Console.WriteLine(A.Sum());
    }
    public static void Main()
    {
        var prog = new Prog();
        prog.run();
    }
    /*
    最小公倍数
    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }

    // ユークリッドの互除法 
    public static long Gcd(long a, long b)
    {
        if (a < b)
            // 引数を入替えて自分を呼び出す
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
    */
    //a<=c, b<=d;
}

//Array.ConvertAll(int.Parse)
//str.IndexOf("Stage",System.StringComparison.CurrentCulture)


Measured memory_bytes: 13268
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
typedef pair<ll,ll> 	pll;
#define br "\n"
#define ff first
#define ss second
#define MAXI 10000001
ll MAX = 1e10;
ll mod = 998244353;


vll tree(MAXI),lazy(MAXI),arr,bin10;
vb vis;
ll n,q,mod9;


ll bin_exp(ll a, ll b){
    a = a % mod;
    ll ans = 1;
    while(b > 0){
        if(b & 1 == 1) ans = (a * ans) % mod;
        a = (a * a) % mod;
        b = b >> 1; 
    }
    return ans;
}

ll mod_inv(ll n){
    ll a = bin_exp(n,mod - 2);
    return a;
}

ll gp(ll l,ll r){
    swap(l,r);
    r = n - 1 - r;
    l = n  - 1 - l;
    ll ans1 = ((bin10[r + 1] - 1LL)*mod9) % mod;
    ll ans2 = ((bin10[l] - 1LL)*mod9) % mod;
    if(ans1 > ans2) return (ans1 - ans2);
    else return (ans1 - ans2 + mod)%mod;
    
}

void build(ll v,ll tl,ll tr){
    if(tl == tr){
        tree[v] = gp(tl,tr); 
        return;
    }
    ll tm = (tl + tr)/2;
    build(2*v,tl,tm);
    build(2*v + 1,tm + 1,tr);
    tree[v] = (tree[2*v] + tree[2*v + 1]) % mod;
}

ll sum(ll v,ll tl,ll tr){
    if(lazy[v] > 0){
        tree[v] = (gp(tl,tr)*lazy[v])%mod;
        lazy[2*v] = lazy[v];
        lazy[2*v + 1] = lazy[v];
        lazy[v] = 0;
    }
    return tree[v];
}

void update(ll v,ll tl,ll tr,ll l,ll r,ll val){
    if(lazy[v] > 0){
        tree[v] = (gp(tl,tr)*lazy[v])%mod;
        lazy[2*v] = lazy[v];
        lazy[2*v + 1] = lazy[v];
        lazy[v] = 0;
    }
    if(l > r) return;

    if(l == tl && r == tr){
        tree[v] = (gp(tl,tr)*val)%mod;
        lazy[2*v] = val;
        lazy[2*v + 1] = val;
        return;
    }
    ll tm = (tl + tr)/2;
    update(2*v,tl,tm,l,min(tm,r),val);
    update(2*v + 1,tm + 1,tr,max(l,tm + 1),r,val);
    tree[v] = (tree[2*v] + tree[2*v + 1]) % mod;

}

void solve(){
    cin >> n >> q;
    mod9 = mod_inv(9);
    bin10.resize(n + 2);
    ll p = 1;
    rep(i,0,n + 2){
        bin10[i] = p;
        p = p*10;
        if(p > mod) p %= mod;
    }
    build(1,0,n - 1);
    ll temp = sum(1,0,n - 1);
    rep(i,0,q){
        ll l,r,val;
        cin >> l >> r >> val;
        update(1,0,n - 1,l - 1,r - 1,val);
        cout << sum(1,0,n - 1) << br;
    }
}
	
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 
 
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}	

Measured memory_bytes: 161088
#include <bits/stdc++.h>
#define INF (1LL<<50)
using namespace std;
typedef long long ll;

int main(){
  int n,m;
  cin>>n>>m;
  vector <ll> s,t,p,P;
  s.resize(n),t.resize(n),p.resize(m+2),P.resize(m+2);
  for(int i=0;i<n;i++) cin>>s[i]>>t[i];
  for(int i=1;i<=m;i++) cin>>p[i];
  P[0]=p[0]=0,p[m+1]=P[m+1]=(INF);
  sort(p.begin(),p.end());
  for(int i=1;i<P.size();i++)P[i]=p[i]-p[i-1];
  for(int i=2;i<P.size();i+=2)P[i]+=P[i-2];
  for(int i=3;i<P.size();i+=2)P[i]+=P[i-2];

  ll sum=0; 
  for(int i=0;i<n;i++){
    vector <ll> :: iterator it1=p.begin(),it2=p.end();
    int idx2=upper_bound(it1,it2,s[i])-it1;
    int idx1=idx2-1;
    int idx4=upper_bound(it1,it2,t[i])-it1;
    int idx3=idx4-1;
    if(idx2==idx4){sum+=abs(t[i]-s[i]);continue;}
    if(s[i]<t[i]){
      if(p[idx2]>s[i])sum+=(p[idx2]-s[i]),idx2++;
      if(idx3-(idx2%2==idx3%2)>=(idx2-1))sum+=P[idx3-(idx2%2==idx3%2)]-P[idx2-1];
      if(t[i]>p[idx3]&&idx2%2==idx3%2)sum+=(t[i]-p[idx3]);
    } 
    if(s[i]>t[i]){
      if(p[idx1]<s[i])sum+=(s[i]-p[idx1]),idx1--;
      if(idx1>=idx4-(idx1%2!=idx4%2))sum+=P[idx1]-P[idx4-(idx1%2!=idx4%2)];
      if(p[idx4]>t[i]&&idx1%2==idx4%2)sum+=(p[idx4]-t[i]);
    }
  }
  cout <<sum<<endl;
  
  return 0;
}

Measured memory_bytes: 4172
N = int(input())
A = [int(input()) for i in range(N)]
maxA = max(A)
secA = sorted(A)[-2]
num=A.count(maxA)
#print(N,A,maxA,secA,num)
 
for i in range(N):
  if num>1:print(maxA)
  elif A[i]==maxA:print(secA)
  else:print(maxA)

Measured memory_bytes: 13404
#include<bits/stdc++.h>
using namespace std;
int main(){
  int A;
  cin >> A;
  int B=0,C=A;
  for(;;){
    B+=A%10;
    A/=10;
    if(A<10){
      B+=A;
      break;
    }
  }
  if(C%B==0)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll N,M,C; cin >> N >> M >> C;
    vector<ll> B(M); for(auto& in:B) cin >> in;
    while(N--){
        ll Sum = C;
        for(int i = 0; i < M;i++){
            ll A; cin >> A;
            Sum += A*B[i];
        }
        if(Sum>0) res++;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 384