akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

LL add(LL a, LL b) { return (a + b) % kMod; }
LL sub(LL a, LL b) { return (a - b + kMod) % kMod; }

int main() {
  int N, K; cin >> N >> K;
  vector<int> a(N); cin >> a;
  vector<vector<LL>> dp(N + 1, vector<LL>(K + 1, 0));

  dp[0][0] = 1;
  for (int i = 0; i < N; ++i) {
    dp[i + 1][0] = 1;
    for (int j = 1; j <= K; ++j) {
      dp[i + 1][j] = add(dp[i][j], dp[i+1][j-1]);
      if (j > a[i]) {
        dp[i + 1][j] = sub(dp[i + 1][j], dp[i][j-a[i]-1]);
      }
    }
  }
  cout << dp[N][K] << endl;
}


Measured memory_bytes: 83120
#include <algorithm>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
typedef long long ll;

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>

using namespace std;

int main(){
  const int n = getInt();
  vector<ll> a(n);
  vector<ll> b(n);

  vector<pair<ll, int> > c(n);

  REP(i,n){
    a[i] = getInt();
    b[i] = getInt();

    c[i] = make_pair(a[i] + b[i], i);
  }
  ll ans = 0;
  sort(c.rbegin(), c.rend());

  REP(i,n){
    int j = c[i].second;
    if(i % 2 == 0) ans += a[j];
    else ans -= b[j];
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
  int n;
  cin >> n;
  long minimum = 10000000;
  long maximum = -10000000;
  long s = 0;
  long a[10010];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < n;i++){
    minimum = min(minimum,a[i]);
    maximum = max(maximum,a[i]);
    s += a[i];
  }

  cout << minimum << " " << maximum << " " << s << endl;
  return 0;
}



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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}

signed main() {
	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		string s;
		cin >> s;
		if (s == "E869120") {
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3212
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      String s1 = sc.next();
      String s2 = sc.next();
      String s3 = sc.next();
      System.out.println(s1.substring(0,1)+s2.substring(1,2)+s3.substring(2,3));
      sc.close();
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265
#define seive_len 1000001

bool seive[seive_len];
int primeSeive[seive_len];

typedef long long int lli;

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

lli lcm(lli a, lli b) {
  lli gcd_ = gcd(a, b);
  lli lcm_ = (a*b)/gcd_;
  return lcm_;
}

lli fastPower(lli a, lli b) {
  lli res=1;
  while(b > 0) {
    if(b&1)
      res *= a;
    a *= a;
    b >>= 1;
  }
  return res;
}

lli fastPowerM(lli a, lli b, lli mod) {
  a %= mod;
  lli res = 1;
  while(b) {
    if(b%2 == 1)
      res = (res*a)%mod;
    a = (a*a)%mod;
    b >>= 1;
  }
  return res;
}

void multiply(lli a[][2], lli b[][2], int mod) {
  int res[2][2];
  memset(res, 0, sizeof(res));
  for(int i=0;i<2;i++) {
    for(int j=0;j<2;j++) {
      for(int k=0;k<2;k++) {
        res[i][j] += a[i][k]*b[k][j]%mod;
      }
    }
  }
  for(int i=0;i<2;i++)
    for(int j=0;j<2;j++)
      a[i][j] = res[i][j];
}

void matrixExpo(lli a[][2], lli n, int mod) {
  if(n == 0 || n == 1)
    return;
  lli b[][2] = {{1,1}, {1,0}};
  matrixExpo(a, n/2, mod);
  multiply(a, a, mod);
  if(n%2)
    multiply(a, b, mod);
}

void makeSeive() {
  for(int i=2;i*i<=seive_len;i++) {
    if(seive[i]) {
      for(int j=i*i;j<=seive_len;j+=i)
        seive[j] = false;
    }
  }
}

void makePrimeSeive() {
  for(int i=1;i<seive_len;i++)
    primeSeive[i] = i;
  for(int i=4;i<seive_len;i+=2)
    primeSeive[i] = 2;
  for(int i=3;i*i<seive_len;i++) {
    if(primeSeive[i] == i) {
      for(int j=i*i;j<seive_len;j+=i) {
        if(primeSeive[j] == j)
          primeSeive[j] = i;
      }
    }
  }
}

bool isPrime(lli n) {
  for(int i=2;i<=sqrt(n);i++) {
    if(n%i == 0)
      return false;
  }
  return true;
}

void getInput(vector<lli>& a, int n) {
  lli x;
  for(int i=0;i<n;i++) {
    cin >> x;
    a.push_back(x);
  }
}

void testCase() {
    lli i, n;
    vector<lli> a;
    cin >> n;
    getInput(a, n);
    map<lli, lli> m;
    int flag = 1, is_p = 1;
    for(i=0;i<n;i++) {
      lli x = a[i];
      while(x != 1) {
        if(m.find(primeSeive[x]) != m.end()) {
          flag = 0;
          break;
        }
        m[primeSeive[x]]++;
        lli y = primeSeive[x];
        while(x%y == 0)
          x /= y;
      }
      if(flag == 0) {
        is_p = 0;
        break;
      }
    }
    if(is_p) {
      cout << "pairwise coprime";
      return;
    }
    lli gcd_ = a[0];
    for(i=1;i<n;i++) {
      gcd_ = gcd(gcd_, a[i]);
    }
    if(gcd_ == 1) {
      cout << "setwise coprime";
      return;
    }
    cout << "not coprime";
}

int main() {
	int t=1;
	// cin >> t;
  // FILE* fp;
  // fp = fopen("out.txt", "w");
  makePrimeSeive();
	for(int i=1;i<=t;i++) {
    // fprintf(fp, "Case #%d: ", i);
		testCase();
    cout << '\n';
	}
	return 0;
}


Measured memory_bytes: 15540
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <math.h>
#include <vector>

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

#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define TRUE (0)
#define FALSE (1)

// This value shold be close to used maximum value.  
#define NUM_MAX 20000000005

// void sort(uint32_t *num, uint32_t size);

int main()
{
    vector<vector<uint64_t>> arr(0);
    vector<uint64_t> temp_vec(2);
    vector<uint64_t> num_vec(0);
    string result = "00000";
    // vector<long long> res_vec(0);
    // uint64_t res_arr[NUM_MAX];
    // uint32_t sum = 0;
    uint64_t num1, num2;
    uint64_t num;
    // uint64_t result;
    uint64_t sum;

    // uint32_t res_i = 0;
    // string str_temp, str_temp2;
    uint64_t temp, temp2;
    uint64_t i, j, k, l, count, n, o, size;
    // uint32_t count = 0;
    // string str;
    // uint8_t k_flag;
 
    cin >> num1 >> num2;

    num = num1 * (num1 - 1) + num2 * (num2 -1);
    num = num / 2;

    // for (i=0; i<num; i++) {
    //     cin >> temp_vec.at(0) >> temp_vec.at(1);
    //     arr.push_back(temp_vec);
    // }

    // for (i=0; i<num; i++) {
    //     temp = arr.at(i).at(0);
    //     result[temp] = arr.at(i).at(1);
    // }

    cout << num << endl;

    return 0;
}

uint64_t silver_fox(vector<vector<int64_t>>& monster_arr, uint64_t range, uint64_t attack, uint64_t count)
{
    int64_t life, pos, num;
    int64_t i, short_i;

    while (monster_arr.size() != 0) {
        pos = monster_arr[0][0];
        life = monster_arr[0][1];
        count++;
        short_i = 0;

        for (i = 0; i < monster_arr.size(); i++) {
            short_i++;
            if (monster_arr[i][0] < pos + range) {
                monster_arr[i][1] -= attack;
            } else {
                break;
            }
        }

        for (i = short_i - 1; i >= 0; i--) {
            if (monster_arr[i][1] <= 0) {
                monster_arr.erase(monster_arr.begin() + i);
            }
        }
    }

    return count;
}

// void sort(uint32_t *num, uint32_t size) {
//     uint32_t i, j, k;
//     uint32_t sorted_num;
//     uint32_t array[NUM_MAX] = {0};

//     for (i = 1; i < size + 1; i++) {
//         array[num[i - 1]]++;
//     }

//     sorted_num = 0;

//     for (i = 0; i < NUM_MAX; i++) {
//         for (j = 0; j < array[i]; j++) {
//             num[j + sorted_num] = i;
//         }
//         sorted_num += j;
//         j = 0;
//     }

//     return;
// }


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using static System.Console;

namespace AtCoder
{
    class AtCoderrrrrr
    {
        static void Main(string[] args)
        {
            int N = int.Parse(ReadLine());
            long power = 1;
            for (int i = 1; i <= N; i++)
            {
                power *= i;
                power %= 1000000007;
            }
            WriteLine(
                power
                );
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
 
#define MAX 200000
#define M 1000000001
 
long long cnt;
 
int merge (int A[], int left, int mid, int right){
  int n1, n2, i, j, k;
  int L[MAX / 2 + 2], R[MAX / 2 + 2];
  n1 = mid - left;
  n2 = right - mid;
  // L=n1+1;
  // R=n2+1;
  for(i = 0; i <= n1 - 1; i++){
    L[i] = A[left + i];
  }
  for(j = 0; j <= n2 - 1; j++){
    R[j] = A[mid + j];
  }
  L[n1] = M;
  R[n2] = M;
  i = 0;
  j = 0;
  for(k = left; k <= right - 1; k++){
   if(L[i] <= R[j]){
      A[k] = L[i];
      i++;
    }
    else{
      A[k] = R[j];
      j++;
      cnt += (n1 - i);
    }
  }
  return 0;
}

int mergeSort(int A[], int left , int right ) {
    int i, mid;
    if(left + 1 < right) {
        mid = (right + left) / 2;
        mergeSort(A,left,mid);
        mergeSort(A,mid,right);
        merge(A,left,mid,right);
    }
    return 0;
}


int main(void) {
    int A[MAX],n,i;
    scanf("%d", &n);
    for(i=0; i < n; i++) {
        scanf("%d",&A[i]);
    }
    cnt = 0;
    mergeSort(A,0,n);
    printf("%lld\n",cnt);
    return 0 ;
    
}


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

int main() {
  int A, B;
  char s[12];
  scanf("%d%d", &A, &B);
  scanf("%s", s);
  for (int i = 0; i < A; i++) {
      if(!('0'<=s[i]&&s[i]<='9')) {
          puts("No");
          return 0;
      }
  }
  if(s[A]!='-') {
    puts("No");
    return 0;
  }
  for (int i = A+1; i < A+B+1; i++) {
      if(!('0'<=s[i]&&s[i]<='9')) {
          puts("No");
          return 0;
      }
  }
  puts("Yes");
}

Measured memory_bytes: 256
import sys
mapin = lambda: map(int, sys.stdin.readline().split())
listin = lambda: list(map(int, sys.stdin.readline().split()))
inp = lambda: sys.stdin.readline()
A,B,C,D = mapin()
l = A + B;r = C + D
if l < r:print("Right")
elif l > r:print("Left")
else:print("Balanced")

Measured memory_bytes: 9076
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <bitset>
#include <limits.h>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF (LL)1e15
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

//#define int long long

/*************** using variables ***************/
int n;
/**********************************************/

signed main(){
    cin >> n;
    
    REP(i, n){
        char s;
        cin >> s;
        if(s == 'Y'){
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header

int main() {
	int x, y;
	cin >> x >> y;
	if(x == 2 || y == 2) puts("No");
	else if(x == 4 || x == 6 || x == 9 || x == 11){
		if(y == 4 || y == 6 || y == 9 || y == 11){
			puts("Yes");
		}else puts("No");
	}else{
		if(y == 4 || y == 6 || y == 9 || y == 11){
			puts("No");
		}else puts("Yes");
	}
 	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <time.h>
#include <stdio.h>
using namespace std;

int main()
{
    int a, b, c;
    int count = 0;
    cin >> a >> b >> c;
    for (int i = a; i <= b; i++)
    {
        if (c % i == 0)
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextLine()){
			double[] stack=new double[80];
			int ptr=0;
			String[] str=sc.nextLine().split(" ");
			for(int i=0;i<str.length;i++){
				try{
					stack[ptr]=Double.parseDouble(str[i]);
					ptr++;
				}catch(NumberFormatException e){
					if(str[i].equals("+")){
						stack[ptr-2]+=stack[ptr-1];
						ptr--;
					}else if(str[i].equals("-")){
						stack[ptr-2]-=stack[ptr-1];
						ptr--;
					}else if(str[i].equals("*")){
						stack[ptr-2]*=stack[ptr-1];
						ptr--;
					}else if(str[i].equals("/")){
						stack[ptr-2]/=stack[ptr-1];
						ptr--;
					}
				}
			}
			System.out.println(stack[0]);
		}
	}
}

Measured memory_bytes: 17240
#複数の整数入力を受け付ける関数
def datain(num):

    data = []
    iscnt = True

    while iscnt:
        for val in map(int,input().split()):
            data.append(val)
            if len(data) == num:
                iscnt = False
                break
        
    return data

INF = 10**12
data = datain(5)
ans = INF

for i in range(0,max(data[3],data[4])*2+1,2):   #ab
    
    j = data[3]-i/2 if data[3] >= i/2 else 0   #a
    k = data[4]-i/2 if data[4] >= i/2 else 0   #b
    ans = min(ans,i*data[2]+j*data[0]+k*data[1])
    #print(i,j,k)

print(int(ans))



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

int main(){
    using namespace std;
    unsigned long N;
    cin >> N;
    vector<vector<unsigned long>> edge(N);
    vector<unsigned long> jisuu(N), ans(N);
    for(unsigned long i = 1, a, b; i < N; ++i){
        cin >> a >> b;
        edge[--a].push_back(--b);
        edge[b].push_back(a);
        ++jisuu[a];
        ++jisuu[b];
    }
    vector<unsigned long> c(N);
    for(auto& i : c)cin >> i;
    sort(c.begin(), c.end());
    stack<unsigned long> stc;
    for(unsigned long i = 0; i < N; ++i)if(jisuu[i] == 1)stc.push(i);
    auto it = c.begin();
    while(!stc.empty()){
        auto t = stc.top();
        stc.pop();
        ans[t] = *it++;
        for(auto i : edge[t])if(--jisuu[i] == 1)stc.push(i);
    }
    unsigned long a{0};
    for(unsigned long i = 0; i < N; ++i)for(const auto& j : edge[i])a += min(ans[i], ans[j]);
    cout << a / 2 << endl;
    for(const auto& i : ans)cout << i << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<stdio.h>
#include<math.h>
#define N 100

int main()
{
  int i,j,k,n,a,A[N],B[N][N];
  scanf("%d",&n);
  for(i=1; i<=n; i++){
    scanf("%d",&A[i-1]);
    scanf("%d",&A[i]);
  }

  for(i=1; i<=n; i++)B[i][i] = 0;
  for(a=2; a<=n; a++){
    for(i=1; i<=n-a+1; i++){
      j = i+a-1;
      B[i][j] = 1<<21;
      for(k=i; k<=j-1; k++){
	B[i][j] = fmin(B[i][j],B[i][k]+B[k+1][j]+A[i-1]*A[k]*A[j]);
      }
    }
  }
  printf("%d",B[1][n]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n,m;
int a[301][301];
int now[301];
int cnt[301];
int del[301];

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			scanf("%d",&a[i][j]);
			a[i][j]--;
		}
	}
	for(int i=0;i<n;i++){
		cnt[a[i][0]]++;
	}
	int res=cnt[0];
	for(int i=0;i<m;i++){
		res=max(cnt[i],res);
	}
	for(int i=0;i<m-1;i++){
		int v=-1;
		for(int j=0;j<m;j++){
			if(del[j]==1)continue;
			if(v==-1)v=j;
			if(cnt[j]>cnt[v]){
				v=j;
			}
		}
		cnt[v]=0;
		del[v]=1;
		for(int j=0;j<n;j++){
			if(a[j][now[j]]==v){
				now[j]++;
				while(del[a[j][now[j]]]==1)now[j]++;
				cnt[a[j][now[j]]]++;
			}
		}
		int mini=0;
		for(int j=0;j<m;j++){
			mini=max(mini,cnt[j]);
		}
		res=min(res,mini);
	}
	printf("%d\n",res);
	return 0;
}

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

int main() {
    int n; cin >> n;
    int ans = 0;
    if (n % 10 == 1) ans += 9;
    else ans++;
    if ((n / 10) % 10 == 1) ans += 90;
    else ans += 10;
    if (n / 100 == 1) ans += 900;
    else ans += 100;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#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)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int,int> P;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

mint dp[105][100005];
mint cum[105][100005];

int main(){
  int n,K;
  cin >> n >> K;
  int a[n];
  rep(i,n)cin >> a[i];
  dp[0][0]=1;
  rep(i,n){
    rrep(j,K+1)cum[i][j]=cum[i][j-1]+dp[i][j-1];
    rep(j,K+1)dp[i+1][j]=cum[i][j+1]-cum[i][max(0,j-a[i])];
  }
  cout << dp[n][K] << endl;
}


Measured memory_bytes: 164352
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b)
{
  if (b < a)
  {
    a = b;
    return true;
  }
  return false;
}

//10^9 + 7
#define yojo 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b)
{
  // a >= b && b != 0
  std::int64_t c;
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb)
{
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0)
  {
    return -1;
  }
  do
  {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str)
{
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++)
  {
    if (i == str.size())
    {
      data.push_back(make_pair(str[i - 1], count));
      break;
    }
    else if (now != str[i])
    {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 200001

void Main()
{
  int n;
  cin >> n;
  if (n % 2 == 0)
  {
    std::cout << ((double)n / 2.0) / (double)n << std::endl;
  }
  else
  {
    std::cout << ((double)(n + 1) / 2.0) / (double)n << std::endl;
  }

  return;
}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
    int p[10001];
    p[0] = 0;
    p[1] = 2;
    for(int i=2; i<=10000; i++){
        for(p[i]=p[i-1]+1; true; p[i]++){
            bool prm = true;
            for(int j=1; j<=i-1; j++){
                if(p[i]%p[j]==0){
                    prm = false;
                    break;
                }
            }
            if(prm)
                break;
            else
                continue;
        }
    }
 
    int s[10001];
    s[0] = p[0];
    for(int i=1; i<=10000; i++)
        s[i] = s[i-1]+p[i];
 
    while(true){
        int n;
        cin >> n;
        if(n==0)
            break;
 
        cout << s[n] << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1236
# coding: utf-8

import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
W = [int(x) for x in input().split()]
# N, M = map(int, input().split())
# S = input()

w_sum = sum(W)

ans = 10 ** 5
ws = 0
for i in range(N - 1):
    ws += W[i]
    ans = min(ans, abs(2 * ws - w_sum))

print(ans)


Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <utility>
#include <string>
#include <queue>

using namespace std;

typedef pair<string, int> P;

int main() {
        int n, quantum, time;
        string name;
        queue<P> q;

        cin >> n >> quantum;
        
        while (n--) {
                cin >> name >> time;
                q.push(P(name, time));
        }

        time = 0;
        while ( !q.empty() ) {
                P cp = q.front();
                q.pop();
                if (cp.second > quantum){
                        cp.second -= quantum;
                        q.push(cp);
                        time += quantum;
                } else {
                        time += cp.second;
                        cout << cp.first << " " << time << endl;
                }
        }

        return 0;
}

Measured memory_bytes: 4404
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <typeinfo>

using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i=0;i<N;i++)  cin >> A.at(i);

  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  int x=0,y=0;
  for(int i=0;i<N;i++){
    if(i<N-1 && A.at(i)==A.at(i+1)){
      if(x==0)  x=A.at(i);
      else if(y==0) y=A.at(i);
      i++;
    }
    if(x!=0 && y!=0)  break;
  }
  long long ans=(long long)x*y;
  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main() {
  int64_t N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
  vector<int> P(N, -1);
  int T0 = 0;
  int T = 0;
  int current = 0;
  P[0] = 0;
  for (int t = 1; t < N * 2; t++) {
    int next = A[current];
    if (P[next] != -1) {
      T0 = P[next];
      T = t - P[next];
      break;
    }

    P[next] = t;
    current = next;
  }
  if (K > T0) {
    int64_t k = K - T0;
    k %= T;
    K = T0 + k;
  }

  current = 0;
  for (int t = 0; t < K; t++) {
    current = A[current];
  }
  cout << current + 1 << endl;

  return 0;
}


Measured memory_bytes: 4828
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{

  ll x;
  cin>>x;
  x<1200?cout<<"ABC"<<endl:cout<<"ARC"<<endl;
  return 0;
}


Measured memory_bytes: 3632
n, m, x = gets.split("\s").map(&:to_i)
c = []
a = []
min_price = nil

n.times do
  input = gets.split("\s").map(&:to_i)
  c << input.shift
  a << input
end

1.upto(n) do |choose|
  (0..n-1).to_a.combination(choose) do |book_indexies|
    skill_sum = Array.new(m, 0)
    price_sum = 0
    book_indexies.each do |book_index|
      price_sum += c[book_index]
      textbook = a[book_index]
      m.times do |i|
        skill_sum[i] += textbook[i]
      end
    end
    if skill_sum.min >= x
      if !min_price || min_price > price_sum
        min_price = price_sum
      end
    end
  end
end

p min_price || -1
    
    

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

int main(){
	int n,k;
	cin>>n>>k;
	vector<int>arr(n+1);
	for (int i=1; i<=n; i++) cin>>arr[i];
	vector<int>dp(k+1,0);
	for (int i=1; i<=k; i++){
		for (int j=1; j<=n; j++)
			if (i>=arr[j] && dp[i-arr[j]]==0)
				dp[i]=1;
	}
	if (dp[k]) cout<<"First"<<endl;
	else cout<<"Second"<<endl;
	return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, c = 1;
  cin >> n;
  vector <int> h(n);
  for (int i = 0; i < n; ++i){
	cin >> h[i];
  }
  int m = h[0];
  for (int i = 1; i < n; ++i){
	if (h[i] >= m){
		++c;
		m = h[i];
	}
  }
  cout << c << "\n";
return 0;
}

Measured memory_bytes: 256
#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;

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

ll t1,t2;
ll a1,a2,b1,b2;

int C(ll t){
	int cnt=0;
	ll A=(t1*a1+t2*a2)*t,B=(t1*b1+t2*b2)*t;
	double x=(B-A)/(double)(a1-b1);
	if(x>0&&x<=t1)cnt++;
	A+=t1*a1;B+=t1*b1;
	x=(B-A)/(double)(a2-b2);
	if(x>0&&x<=t2)cnt++;
	return cnt;
}

int main(){
	cin>>t1>>t2;
	cin>>a1>>a2>>b1>>b2;
	if(t1*a1+t2*a2==t1*b1+t2*b2){
		puts("infinity");return 0;
	}
	ll ok=-1,ng=1e15;
	while(ng-ok>1){
		ll t=(ok+ng)/2;
		if(C(t))ok=t;
		else ng=t;
	}
	ll ans=ok+1;
	ok=0;ng=1e15;
	while(ng-ok>1){
		ll t=(ok+ng)/2;
		if(C(t)==2)ok=t;
		else ng=t;
	}
	ans+=ok;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,l,r) for(int (i)=(l);(i)<(r);(i)++)
using namespace std;
int main(){
    int n,ans=0;
    cin>>n;
    string s;
    cin>>s;
    rep(i,2,(int)s.length()){
        if(s[i]=='C'&&s[i-1]=='B'&&s[i-2]=='A')ans++;
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

int main() {
    int A, B;
    cin >> A >> B;
    cout << "100 100\n";
    rep(i, 50) {
        rep(j, 100) {
            if (A == 1 || (i * j) % 2 == 0) cout << "#";
            else {
                cout << ".";
                A--;
            }
        }
        cout << "\n";
    }
    rep(i, 50) {
        rep(j, 100) {
            if (B == 1 || (i * j) % 2 == 0) cout << ".";
            else {
                cout << "#";
                B--;
            }
        }
        cout << "\n";
    }
}

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

int main(){
        int x[101] = {};
        int in[3];
        int ans = 0;
        rep(i,3) cin >> in[i];
        rep(i,3) x[in[i]]=1;
        rep(i,101) if(x[i]>0) ans++;
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	while(scanf("%d%d",&a,&b)!=EOF)
	{
			if((a+b)%3==0||a%3==0||b%3==0)
				printf("Possible\n");
			else
				printf("Impossible\n");
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

static const int INTINF = (2147483647 >> 1); // 10^9 + 5000
static const ll LLINF = (9223372036854775807 >> 1);
static const int MAX = 1e5+1;
static const ll MOD = 1e9+7;

namespace Kunitaka{
    template<
        typename TYPE,
        std::size_t SIZE
    >
    std::size_t array_length(const TYPE (&array)[SIZE])
    {
        return SIZE;
    }
}
using namespace Kunitaka;
namespace Printer{
    void br(){
        cout << endl;
    }

    void loop_cnt(int i){
        cout << "i = " << i << endl;
    }

    void loop_cnt(int i, int j){
        cout << "i = " << i << ", " << "j = " << j << endl;
    }

    template<class T>
    void print(T x){
        cout << x << endl;
    }

    template<class T, class S>
    void print(T x, S y){
        cout << x << "," << y << endl;
    }

    template<class T, class S, class U>
    void print(T x, S y, U z){
        cout << x << "," << y << "," << z << endl;
    }

    template<class T, class S>
    void print(pair<T, S> p){
        cout << p.first << ", " << p.second << endl;
    }

    template<
        typename TYPE,
        std::size_t SIZE
    >
    void print(const TYPE (&array)[SIZE]){
        int lim = array_length(array);
        for(int i=0; i<lim; i++){
            if(i) cout << " ";
            cout << array[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<S> v){
        for(int i=0; i<v.size(); i++){
            if(i) cout << " ";
            cout<< v[i];
        }
        cout << endl;
    }

    template<class S>
    void print(vector<vector<S> > vv){
        for(int i=0; i<vv.size(); i++){
            for(int j=0; j<vv[i].size(); j++){
                if(j) cout << " ";
                cout << vv[i][j];
            }
            cout << endl;
        }
    }

    void yesno(bool x){
        if(x) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
};
using namespace Printer;

int main(int argc, const char * argv[]) {
    //提出時、消す----//
  
    //--------------//


    // input
    cout << fixed << setprecision(10);
    ll a, b, c; cin >> a >> b >> c;

    // if(a+b == c){
    //     print("No");
    //     return 0;
    // }

    ll tmp = c- a -b;

    if(0 <= tmp){
        ll l = (tmp) * tmp;
        ll r = 4 * a * b;
        yesno(r < l);
    }
    else{
        yesno(false);
    }

    
    
    
    return 0;
}


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

int main(){
    
    // input
    ll N;
    cin >> N;
    vector<ll> A(N), B(N), C(N);
    rep(i, 0, N) cin >> A[i];
    rep(i, 0, N) cin >> B[i];
    rep(i, 0, N) cin >> C[i];

    // sort
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    // b
    vector<ll> sb(N);
    for(ll i = N-1; i >= 0; i--){
        auto itr = lower_bound(C.begin(), C.end(), B[i]+1);
        auto pos = distance(C.begin(), itr);
        if(i != N-1) sb[i] = sb[i+1] + N - pos;
        else sb[i] = N - pos;
    }
    
    // a
    ll ans = 0;
    rep(i, 0, N){
        auto itr = lower_bound(B.begin(), B.end(), A[i]+1);
        auto pos = distance(B.begin(), itr);
        if(pos != N) ans += max(sb[pos], 0LL);
    }

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

Measured memory_bytes: 3328
N = int(input())
if N < 3:
  print(0)
else:
  triangle = 0
  L = list(map(int, input().split()))
  for i in range(N-2):
    for j in range(i+1, N-1):
      for k in range(j+1, N):
        lines = [L[i], L[j], L[k]]
        lines.sort()
        if lines[0] != lines[1] and lines[1] != lines[2] and lines[2] < lines[0] + lines[1]:
          triangle += 1
  print(triangle)

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

#define FOR0(i,n) for (int i = 0; i < n; i++)
#define FOR(i,j, n) for (int i = j; i < n; i++)
// bool isEven(ll n) {return (n%2!=0)?false:true;};
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
// #define int ll

using namespace std;

//atcoder ABC 141

//b

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


	for (int i = 0; i < s.length(); ++i)
	{
		if((i+1)%2!=0)
		{
			if(s[i]=='L')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
		else
		{
			if(s[i]=='R')
			{
				cout<<"No"<<endl;
				return 0;
			}
		}
	}

	cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
def rect(h, w):
    while h > 0:
        print('#' * w)
        h -= 1
    print()
    return

while True:
    n = list(map(int, input().split()))
    H = n[0]
    W = n[1]
    if (H == 0 and W == 0):
        break
    rect(H, W)

Measured memory_bytes: 7732
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	int a, b, c;
	cin >> a >> b >> c;
	if(b - a == c - b){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i=1;i<=n;i++){
        int t = i*108/100;
        if(t==n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
/**
*    created: 10.05.2020 17:57:56
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

struct Node {
    int parent, left, right, degree, sibling, depth, height;
    string type;
};

vector<Node> T(25); //node数は高々25

// depth
int dpt(int i) {
    if (T[i].parent == -1) return 0;
    else return dpt(T[i].parent) + 1;
}

//height
int hit(int i) {
    if (T[i].left == -1 && T[i].right == -1) return 0;
    else if (T[i].left == -1) return hit(T[i].right) + 1;
    else if (T[i].right == -1) return hit(T[i].left) + 1;
    else return max(hit(T[i].left), hit(T[i].right)) + 1; 
}

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;

    //初期化
    rep(i,n) {
        T[i].parent = -1;
        T[i].sibling = -1;
    }
    
    //input
    int k, l, r;
    rep(i,n) {
        cin >> k >> l >> r;
        T[k].left = l;
        T[k].right = r;
        if (r != -1) T[l].sibling = r;
        if (l != -1) T[r].sibling = l;
        if (l != -1) T[l].parent = k;
        if (r != -1) T[r].parent = k;
    }
    
    //height and depth
    rep(i,n) {
        T[i].depth = dpt(i);
        T[i].height = hit(i);  
    }
    
    //degree
    rep(i,n) {
        if (T[i].left == -1 && T[i].right == -1) T[i].degree = 0;
        else if  (T[i].left != -1 && T[i].right == -1) T[i].degree = 1;
        else if  (T[i].left == -1 && T[i].right != -1) T[i].degree = 1;
        else T[i].degree = 2;
    }
    
    //type
    rep(i,n) {
        if (T[i].parent == -1) T[i].type = "root";
        else if (T[i].left == -1 && T[i].right == -1) T[i].type = "leaf";
        else T[i].type = "internal node";
    }
    
    //出力
    rep(i,n) {
        cout << "node " << i;
        cout << ": parent = " << T[i].parent;
        cout << ", sibling = " << T[i].sibling;
        cout << ", degree = " << T[i].degree;
        cout << ", depth = " << T[i].depth;
        cout << ", height = " << T[i].height;
        cout << ", " << T[i].type;
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int N, M, Q;
vector<int> a, b, c, d;
int ans = 0;
void dfs(vector<int>& A){
  if (A.size() == N){
    int sum = 0;
    for (int i = 0; i < Q; ++i){
      if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
    }
    ans = max(ans, sum);
    return;
  }
  int prev_last = (A.empty()? 1 : A.back());
  for (int v = prev_last; v <= M; ++v){
    A.push_back(v);
    dfs(A);
    A.pop_back();
  }
}

int main(){
  cin >> N >> M >> Q;
  a.resize(Q), b.resize(Q), c.resize(Q), d.resize(Q);
  rep(i, Q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--, b[i]--;
  }

  vector<int> A;
  dfs(A);
  cout << ans << endl;
}


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

int main(){
  int H,W;cin>>H>>W;
  string A[H];
  for(int i=0;i<H;i++) cin>>A[i];
  char ans[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(A[i][j]=='#') ans[i][j]='#';
      else{
        int count=0;
        int up=max(0,i-1);
        int down=min(i+1,H-1);
        int left=max(0,j-1);
        int right=min(j+1,W-1);
        for(int k=up;k<=down;k++){
          for(int l=left;l<=right;l++){
            if(k==i && l==j) continue;
            if(A[k][l]=='#') count++;
          }
        }
        ans[i][j]=count+'0';
      }
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++) cout<<ans[i][j];
    cout<<"\n";
  }
}

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

struct RARS {
	using ll = long long;
	struct t1 {
		ll val, size;
		t1(ll v, ll s = 1) : val(v), size(s) {}
	};
	using t2 = ll;
	static t1 id1() { return t1(0, 0); }
	static t2 id2() { return 0; }
	static t1 op1(const t1& l, const t1& r) { return t1(l.val + r.val, l.size + r.size); }
	static t1 op2(const t1& l, const t2& r) { return t1(l.val + l.size * r, l.size); }
	static t2 op3(const t2& l, const t2& r) { return l + r; }
};

template <typename M>
class LazySegmentTree {
	using T1 = typename M::t1;
	using T2 = typename M::t2;
	const int h, n;
	vector<T1> data;
	vector<T2> lazy;
	void push(int node) {
		if (lazy[node] == M::id2()) return;
		if (node < n) {
			lazy[node * 2] = M::op3(lazy[node * 2], lazy[node]);
			lazy[node * 2 + 1] = M::op3(lazy[node * 2 + 1], lazy[node]);
		}
		data[node] = M::op2(data[node], lazy[node]);
		lazy[node] = M::id2();
	}
	void update(int node) {
		data[node] = M::op1(M::op2(data[node * 2], lazy[node * 2]), M::op2(data[node * 2 + 1], lazy[node * 2 + 1]));
	}
public:
	LazySegmentTree(int n_)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {}
	LazySegmentTree(int n_, T1 v1, T2 v2)
		: h(ceil(log2(n_))), n(1 << h), data(n * 2, v1), lazy(n * 2, v2) {}
	LazySegmentTree(const vector<T1>& data_)
		: h(ceil(log2(data_.size()))), n(1 << h), data(n * 2, M::id1()), lazy(n * 2, M::id2()) {
		init(data_);
	}
	void init() {
		for (int i = n - 1; i >= 1; i--) data[i] = M::op1(data[i * 2], data[i * 2 + 1]);
	}
	void init(const vector<T1>& data_) {
		for (int i = 0; i < (int)data_.size(); i++) data[i + n] = data_[i];
		init();
	}
	void update(int l, int r, T2 val) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		int tl = l, tr = r;
		r++;
		while (l < r) {
			if (l & 1) lazy[l] = M::op3(lazy[l], val), l++;
			if (r & 1) r--, lazy[r] = M::op3(lazy[r], val);
			l /= 2; r /= 2;
		}
		while (tl > 1) {
			tl >>= 1, tr >>= 1;
			if (lazy[tl] == M::id2()) update(tl);
			if (lazy[tr] == M::id2()) update(tr);
		}
	}
	T1 find(int l, int r) {
		l += n, r += n;
		for (int i = h; i > 0; i--) push(l >> i), push(r >> i);
		r++;
		T1 res1 = M::id1(), res2 = M::id1();
		while (l < r) {
			if (l & 1) res1 = M::op1(res1, M::op2(data[l], lazy[l])), l++;
			if (r & 1) r--, res2 = M::op1(M::op2(data[r], lazy[r]), res2);
			l /= 2; r /= 2;
		}
		return M::op1(res1, res2);
	}
};

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, q;
	cin >> n >> q;
	LazySegmentTree<RARS> lst(n, RARS::t1(0, 1), RARS::id2()); lst.init();
	for (int i = 0, type, s, t, x; i < q; i++) {
		cin >> type >> s >> t; s--; t--;
		if (type) {
			printf("%lld\n", lst.find(s, t));
		}
		else {
			cin >> x;
			lst.update(s, t, x);
		}
	}
	return 0;
}

Measured memory_bytes: 9064
#include <bits/stdc++.h>
#define int long long int
#define MOD(x) ((x % MOD_N) + MOD_N) % MOD_N
#define FS first
#define SC second
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define RFORE(i,a,b) for(int i=(b);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(c) (int)((c).size())
#define EACH(i,v) for (auto i=v.begin();i!=v.end();++i)
#define REACH(i,v) for (auto i=v.rbegin();i!=v.rend();++i)
#define LB(c,x) distance((c).begin(),lower_bound(ALL(c),x))
#define UB(c,x) distance((c).begin(),upper_bound(ALL(c),x))
#define COUNT(c,x) (lower_bound(ALL(c),x)-upper_bound(ALL(c),x))
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (bool)((s).find(e)!=(s).end())
#define PB push_back
#define MP make_pair
#define DEL(v) decltype(v)().swap(v)
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;
#define NL cerr<<endl;
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T sum(vector<T>&v){return accumulate(ALL(v),T());}
template<typename T>T sum(vector<T>&v,int a,int b){return accumulate(v.begin()+a,v.begin()+b,T());}
template<typename T>T max(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T min(vector<T>&v){return *max_element(ALL(v));}
template<typename T>T max_index(vector<T>&v){return distance((v).begin(),max_element(ALL(v)));}
template<typename T>T min_index(vector<T>&v){return distance((v).begin(),min_element(ALL(v)));}

struct edge { int to, cost; };

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}

const int INF = 1e18;
const int MOD_N = 1e9+7;

signed main()
{
   int a, b; cin >> a >> b;
   if (b % a == 0) {
      cout << a + b << endl;
   } else {
      cout << b - a << endl;
   }

   return 0;
}


Measured memory_bytes: 256
from collections import deque

def bfs_tree(graph, v=1):
    """
    graph: グラフ
    v: スタート
    """
    # 矢印がどこを向いているか
    # -1だと未探索
    arrow = [-1]*len(graph) 
    q = deque()
    q.append(v)
    arrow[v] = 0
    while q:
        now = q.popleft()
        for next_v in graph[now]:
            if arrow[next_v] != -1:
                continue
            else:
                q.append(next_v)
                arrow[next_v] = now
    return arrow

N, M = map(int, input().split())
graph = [[] for _ in range(N)]
pre = []

for _ in range(M):
    A, B = map(int, input().split())
    graph[A-1].append(B-1)
    graph[B-1].append(A-1)

arrow = bfs_tree(graph, 0)

print('Yes')
for i in range(1, N):
    print(arrow[i]+1)

Measured memory_bytes: 33960
#include<bits/stdc++.h>
using namespace std; 
int main(){
 ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   int t;
   t=1;
   while(t--){
   	long long int l,r,d;
   	cin>>l>>r>>d;
   	long long int a=ceil((float)l/d)*d;
   	long long int ans=0;
   	if(a>r){
   		cout<<"0\n";
   		continue;
	}
	else{
		ans=(r-a)/d;
		ans+=1;
	}
	cout<<ans<<"\n";
   }
   return 0;
}

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

const int N=5e5+5;
int n,a[N];
char s[N];

int main()
{
	scanf("%d",&n);int i,ans=1e9+7;
	scanf("%s",s+1);
	for(i=1;i<=n;++i) a[i]=a[i-1]+(s[i]=='#');
	for(i=0;i<=n;++i) ans=min(ans,a[i]+(n-i-(a[n]-a[i])));
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int arr[N];
int pre[N];
int post[N];
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, ans;
    cin >> n;
    for(int i=0; i<n; ++i){
        cin >> arr[i];
    }
    pre[0] = arr[0];
    //cout << "pre: " << pre[0] << " ";
    for(int i=1; i<n; ++i){
        pre[i] = __gcd(pre[i-1], arr[i]);
        //cout << pre[i] << " ";
    }
    //cout << "\n";
    post[n-1] = arr[n-1];
    //cout << "post: " << post[n-1] << " ";
    for(int i=n-2; i>=0; --i){
        post[i] = __gcd(post[i+1], arr[i]);
        //cout << post[i] << " ";
    }
    //cout <<" \n";
    ans = 1;
    for(int i=1; i<n; ++i){
        ans = max( __gcd(pre[i-1], post[i+1]), ans);
    }
    ans = max(pre[n-2], max(post[1], ans))  ;
    cout << ans << "\n";
}
/***
5
4  2 3 2 4
*/


Measured memory_bytes: 1408