akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;
#define REP(i,n) for (int i = 0; i <(n); ++i)
//debug 
#ifdef _DEBUG
#define debug(var)  do{cout << #var << " :";view(var);}while(0)
#else
#define debug(...)
#endif
template<typename T> void view(T e){cout << e << endl;}
template<typename T> void view(const vector<T>& v){for(const auto& e : v){ cout << e << " "; } cout << endl;}
template<typename T> void view(const vector<vector<T> >& vv){ for(const auto& v : vv){ view(v); } }


int main(){
  int n, m;
  cin >> n >> m;
  vector<int> x(m);
  REP(i,m) cin >> x[i];

  sort(ALL(x));

  vector<ll> dist(m-1);
  REP(i,m - 1){
    dist[i] = (ll)abs(x[i] - x[i+1]);
  }

  sort(RALL(dist));
  ll sum = 0;
  REP(i,m-1){
    if(i < n - 1) continue;
    sum += (ll)dist[i];
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 4232
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define int long long
int32_t main()
{


	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	int mon[n + 1], hero[n];
	for (int i = 0; i <= n; i++)
	{
		cin >> mon[i];
	}
	for (int i = 0; i < n; i++)
	{
		cin >> hero[i];
	}
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		if (hero[i] <= mon[i])
		{

			sum += hero[i];
		}
		else
		{
			sum += mon[i];
			hero[i] -= mon[i];
			if (mon[i + 1] >= hero[i])
			{
				sum += hero[i];
				mon[i + 1] -= hero[i];
			}
			else
			{
				sum += mon[i + 1];
				mon[i + 1] = 0;
			}
		}
	}
	cout << sum;
}

Measured memory_bytes: 1792
using System;

namespace P0000_QQ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (int i = 1; i <= 9; i++ )
            {
                for (int j = 1; j <= 9; j++ ) 
                {
                    Console.WriteLine("{0}x{1}={2}", i, j, i * j);
                }
            }
        
        }
    }
}

Measured memory_bytes: 5588
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int w;
char s[100001];
int main() 
{
	cin>>s;
	cin>>w;
	int l=strlen(s);
	int x=0;
	while(x+1<=l){
		cout<<s[x];
		x+=w;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

ll st[100100];

int main(){
	int n, m; cin >> n >> m;
	for( int i = 0; i < m; ++i ){
		int tmp; cin >> tmp;
		st[tmp] = -1;
	} 
	st[0] = 1;
	for( int i = 0; i < n; ++i ){
		if( st[i] == -1 ) continue;
		if( st[i+1] != -1 ){
			st[i+1] += st[i];
			st[i+1] %= mod;
		}
		if( st[i+2] != -1 ){
			st[i+2] += st[i];
			st[i+2] %= mod;
		}
	}
	cout << st[n]%mod << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  ll ans = pow(n, 3);
  cout << ans << endl;
  return 0;
}

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

int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << x2 + (y1 - y2) << " ";
    cout << y2 - (x1 - x2) << " ";
    cout << x1 + (y1 - y2) << " ";
    cout << y1 - (x1 - x2) <<endl;
}

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

int main() {
  int days[12] = {31,29,31,30,31,30,31,31,30,31,30,31};
  string youbi[7] = {"Monday","Tuesday","Wednesday","Thursday",
		     "Friday","Saturday","Sunday"};
  while(1) {
    int mon, day;
    cin >> mon >> day;
    if(mon == 0) break;

    int sum = 0;
    for(int i = 0; i < mon-1; i++) {
      sum += days[i];
    }
    sum += day;

    cout << youbi[(sum+2)%7] << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)


int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    vector<int> Y(N);
    REP(i, N) {
        cin >> X[i];
    }
    REP(i, N) {
        cin >> Y[i];
    }
    int ppp= 0;
    REP(i, N) {
        if(X[i] > Y[i]){
            ppp = ppp + X[i] - Y[i];       
        } 
    }
    cout << ppp << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ss second
#define ff first
#define int long long
//#define double long double
#define pb push_back


const int N = 1e6 + 51 + 51, MOD = 1e9 + 7, mod = 998244353, INF = 3e18;

mt19937 Flash_new_51(51515);

using vi = vector <int>;
using vp = vector <pair <int, int>>;

//gp_hash_table<int, int> table;

vi g[N], aa;
int dp[N];


bool used[N];

void dfs (int v) {
    used[v] = 1;
    for (auto to : g[v]) {
        if (!used[to]) dfs(to);
    }
    aa.pb(v);
}

signed main() {
    #ifdef Flash
     freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++) {
        int l, r;
        cin >> l >> r;
        g[l].pb(r);
    }
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            dfs(i);
        }
    }
    int ans = 0;
    for (auto v : aa) {
        for (auto to : g[v]) dp[v] = max(dp[to] + 1, dp[v]);
        ans = max(ans, dp[v]);
    }
    cout << ans;
}


Measured memory_bytes: 31220
{**
 * Author  : Nguyen Canh Toan
 * Problem : B - Bishop
 * Link    : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_b
**}
uses math;
const std='tmp';
var h,w:int64;
    input,output:text;
procedure main();
var ans:int64;
begin
  read(h,w);
  if (h=1) or (w=1) then ans:=1 else ans:=(h*w+1) div 2;
  write(ans);
end;
BEGIN
  //assign(input,std+'.inp');reset(input);
  //assign(output,std+'.out');rewrite(output);
    main();
  //close(input);
  //close(output);
END.


Measured memory_bytes: 128
fn read<T: std::str::FromStr>(
    stdin_lock: &mut std::io::StdinLock,
    buf: &mut Vec<u8>,
    delimiter: u8,
) -> T {
    buf.clear();
    let l = std::io::BufRead::read_until(stdin_lock, delimiter, buf).unwrap();
    buf.truncate(l - 1); // remove delimiter
    let s = unsafe { std::str::from_utf8_unchecked(&buf) };
    s.parse().unwrap_or_else(|_| panic!("read"))
}

fn main() {
    let stdin = std::io::stdin();
    let mut stdin_lock = stdin.lock();
    let mut buf: Vec<u8> = Vec::new();
    let s1: String = read(&mut stdin_lock, &mut buf, b'\n');
    let s2: String = read(&mut stdin_lock, &mut buf, b'\n');
    let s3: String = read(&mut stdin_lock, &mut buf, b'\n');
    let l1: Vec<char> = s1.chars().collect();
    let l2: Vec<char> = s2.chars().collect();
    let l3: Vec<char> = s3.chars().collect();
    let ans: String = vec![l1[0], l2[1], l3[2]].into_iter().collect();
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
using namespace std;
using ll = long long;
using P = pair<int,int>;

ll gcd(ll a, ll b) {
   if(a<b) swap(a, b);
   return b?gcd(b,a%b):a;
}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

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

   ll l=lcm(a, b);
   cout<< l <<endl;
   return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>
double max(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(int *)a-*(int *)b;
}
int main(void){
	int n,a[1000],i,ab,cd;
	double ans=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	qsort(a,n,sizeof(int),cmp);
	for(i=1;i<n;i++){
		cd=a[i]-a[i-1];
		if(i==n-1)ab=a[n-3]+a[n-4];
		else if(i==n-2)ab=a[n-1]+a[n-4];
		else ab=a[n-1]+a[n-2];
		ans=max(ans,(double)ab/cd);
	}
	printf("%f\n",ans);
	return 0;
}

Measured memory_bytes: 684
program main
  
  implicit none
  integer :: i,n
  real(8) :: x,tmp500,tmp5
  
  read(*,*) x
  tmp500 = 500
  tmp5   = 5
  
  print*, int(x/tmp500)*1000+int((x-int(x/tmp500)*tmp500)/tmp5)*5  
end program main


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, a;
string s;

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	ll ans = 1;
	ll cnt[3];
	memset(cnt, 0, sizeof(cnt));
	rep(i, 1, n){
		cin >> a;
		ll cntt = 0;
		bool flag = true;
		rep(j, 0, 2){
			if(a == cnt[j]){
				cntt++;
				if(flag){
					cnt[j]++;
					flag = false;
				}
			}
		}
		ans *= cntt;
		ans %= MOD;
	}
	print(ans)
	return 0;
}

Measured memory_bytes: 256
# https://beta.atcoder.jp/contests/abc101/tasks/abc101_b
# B - Digit Sums

# B_Digit_Sums.py

N = int(input())
str_N = str(N)

S_N = 0
for i in range(len(str_N)):
    S_N += ( N % (10 ** (i+1)) ) // (10 ** i)

if N % S_N == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
import java.util.*;
import java.io.*;
import java.math.*;

class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] p = new int[M];
        String[] S = new String[M];

        for (int i = 0; i < M; i++) {
            p[i] = sc.nextInt();
            S[i] = sc.next();
        }

        boolean[] ac = new boolean[N];
        int[] nac = new int[N];
        int[] nwa = new int[N];
        for (int i = 0; i < N; i++) {
            ac[i] = false;
            nac[i] = 0;
            nwa[i] = 0;
        }

        for (int i = 0; i < M; i++) {
            int pr = p[i] - 1;

            if (!ac[pr]) {
                if (S[i].equals("AC")) {
                    nac[pr]+=1;
                    ac[pr] = true;
                } else { // "WA"
                    nwa[pr]+=1;
                }
            }

        }

        int sumac = 0;
        int sumwa = 0;
        for (int i = 0; i < N; i++) {
            if (ac[i]) {
                sumac += nac[i];
                sumwa += nwa[i];
            }
        }

        System.out.println(sumac + " " + sumwa);
    }

}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	map<char, int> dics;
	map<char, int> dict;
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int cnt1 = 1;
	int cnt2 = 1;
	for (int i=0; i<n; i++) {
		char c1 = s[i];
		int now1;
		if (dics.count(c1)) {
			now1 = dics[c1];
		} else {
			dics[c1] = cnt1;
			now1 = cnt1;
			cnt1++;
		}
		char c2 = t[i];
		int now2;
		if (dict.count(c2)) {
			now2 = dict[c2];
		} else {
			dict[c2] = cnt2;
			now2 = cnt2;
			cnt2++;
		}
		if (now1!=now2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<b; i++)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ull M=1e6,N=1e7+5,INF=1e18;

void solve()
{
   ll n,i=100,y=0;
   cin >> n;

   while(i<n)
   {
       y++;
       i = i + i/100;
   }

   cout << y << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 3608
import re

def solve(s):
	s=re.sub('eraser','',s)
	s=re.sub('erase','',s)
	s=re.sub('dreamer','',s)
	s=re.sub('dream','',s)
	if s:
		return 'NO'
	else:
		return 'YES'

s=input()
print(solve(s))

Measured memory_bytes: 3672
import java.util.*;
public class Main {
  public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      String S = sc.next();
      int A = 0;
      int Z = 0;
      A = S.indexOf("A");
      Z = S.lastIndexOf("Z");
      System.out.println(Z-A+1);
  }
}

Measured memory_bytes: 26504
#include <iostream>
#include <map>

using namespace std;

long long euc(long long a, long long b){
  long long r = a % b;
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

int main(){
  long long A,B,C,D;
  cin >> A >> B >> C >> D;

  long long sum = B - A + 1;
  long long x_max1 = B / C;
  long long x_min1 = A / C;
  if(A % C != 0) x_min1++;
  sum -= x_max1 - x_min1 + 1;

  long long x_max2 = B / D;
  long long x_min2 = A / D;
  if(A % D != 0) x_min2++;
  sum -= x_max2 - x_min2 + 1;

  long long lcm = C * D / euc(C, D);
  long long x_max3 = B / lcm;
  long long x_min3 = A / lcm;
  if(A % lcm != 0) x_min3++;
  sum += x_max3 - x_min3 + 1;

  cout << sum << endl;
}


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

int main() {
  std::int_fast64_t n, k;
  std::cin >> n >> k;
  std::vector<std::int_fast64_t> x(n);
  std::copy_n(std::istream_iterator<std::int_fast64_t>(std::cin), n, x.begin());

  std::cout << std::accumulate(x.begin(), x.end(), static_cast<std::int_fast64_t>(0), [&k](const std::int_fast64_t sum, const std::int_fast64_t x_i) {
    return sum + std::min(std::abs(0 - x_i), std::abs(k - x_i)) * 2;
  }) << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int friend, mach, target[100], jud[100][100], i, j, k, score;

  scanf("%d", &friend);
  scanf("%d", &mach);

  for(i = 0; i < mach; i++)
    scanf("%d", &target[i]);

  for(i = 0; i < mach; i++)
    for(j = 0; j < friend; j++)
      scanf("%d", &jud[i][j]);

  for(i = 0; i < friend; i++){
    score = 0;
    for(j = 0; j < mach; j++){
      if(target[j] == jud[j][i])
	score += 1;
      if(target[j] == i+1){
	for(k = 0; k < friend; k++)
	  if(target[j] != jud[j][k])
	    score += 1;
      }
    }
    printf("%d\n", score);
  }
  return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for (int i = k; i < (int)(n); i++)
#define repd(i, n) for (int i = n-1; i >= 0; i--)
#define rrepd(i, k, n) for (int i = n-1; i >= (int)(k); i--)
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
//V,Pは大文字i,l,bは小文字
using ll = long long;
using Vi = vector<int>;
using VVi = vector<Vi>;
using Vl = vector<ll>;
using VVl = vector<Vl>;
using Vb = vector<bool>;
using VVb = vector<Vb>;
using P = pair<int,int>;
using Pll = pair<ll, ll>;

const ll inf = 1000000000000;//10の12乗
const int mod = 998244353;
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 { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
};

int main() {
    ll n,k;
    cin >> n >> k;
    vector<mint> v(n+1000002,0),vv(n+1000002,0);
    v[0]=1;
    Vi vl(k),vr(k);
    rep(i,k) cin >> vl[i] >> vr[i];
    mint now=0;
    rep(i,n){
        now+=vv[i].x;
        if(i!=0)v[i]+=now.x;
        rep(j,k){
            int x=vl[j];
            int y=vr[j]+1;
            vv[i+x]+=v[i];
            vv[i+y]-=v[i];
        }
    }
    // rep(i,n) cout << v[i].x << " ";
    // cout << endl;
    // rep(i,n) cout << vv[i].x << " ";
    // cout << endl;
    cout << v[n-1].x << endl;
}

Measured memory_bytes: 22016
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cstring>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <cstdlib>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
typedef long long ll;
#define forn for(int i=0;i<n;i++) 
#define form for(int i=0;i<m;i++) 
#define pb push_back 
#define mp make_pair 
#define sc second 
#define f first 
#define kek cout<<"\n" 
#define all(v) ((v).begin()), ((v).end()) 
#define pob pop_back() 
const ll MOD = 1e9 + 7;
const int N = 1005;
const ll INF = 1e9;
using namespace std;
int main()
{
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
   ll n;
   cin>>n;
   ll ans=0;
   ll cnt=1;
   if(n==1)
   {
             cout<<1;
             return 0;
   }
   ans=1;
   n/=2;
   while(n>1)
   {
          n/=2;
          cnt*=2;
          ans+=cnt;
   }
   cnt*=2;
   cout<<ans+cnt;
   return 0;
   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  priority_queue<int> que;
  int N,M;
  cin >> N >> M;
  rep(i,N){
    int A;
    cin >> A;
    que.push(A);
  }
  rep(i,M){
    int t=que.top();
    que.pop();
    que.push(t/2);
  }
  int ans=0;
  while(!que.empty()){
    ans+=que.top();
    que.pop();
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <string.h>

int main(){
  char s[100000] = {};  scanf("%s", s);
  int i;
  int count0 = 0;
  int count1 = 0;
  int length = strlen(s);
  
  for(i = 0; i < length; i++){
    if(i % 2 == 0){
      if(s[i] == '0') count1++;
      if(s[i] == '1') count0++;
    }
    if(i % 2 == 1){
      if(s[i] == '0') count0++;
      if(s[i] == '1') count1++;
    }
  }
  printf("%d\n",(count0 <= count1) ? count0 : count1);

  return 0;
}
      


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const long long MOD = 1000000007;

void solve(long long N, std::vector<long long> C){
  
    vector<ll> D;
    for(int i=0;i<N;i++){
        if(i<N-1&& C[i] == C[i+1]){
            continue;
        }
        D.push_back(C[i]);
    }
    ll size = D.size();
    map<ll,ll> mp;
    vector<ll> dp(size+1);
    dp[0] =1;
    for(int i=0;i<size;i++){
        if(mp.find(D[i]) == mp.end()){
            dp[i+1] = dp[i];
            mp[D[i]] = i;
            continue;
        }
        int t= mp[D[i]];
        dp[i+1] = dp[i] + dp[t+1];
        dp[i+1] %= MOD; 
        mp[D[i]] =i;
    }
    // mp.clear();
    // vector<ll> rdp(size+1);
    // rdp[size] =1;
    // for(int i=size-1;i>=0;--i){
    //     if(mp.find(D[i]) == mp.end()){
    //         rdp[i] = rdp[i+1];
    //         mp[D[i]] =i;
    //         continue;
    //     }
    //     int t= mp[D[i]];
    //     rdp[i] = rdp[i+1] + rdp[t];
    //     rdp[i] %= MOD;
    //     mp[D[i]] =i;
    // }
    cout << dp[size] << endl;
    return;
    // ll ans =1;
    // for(int i=0;i<size;i++){
    //     cerr <<"dp=" << dp[i+1] <<"rdp=" << rdp[i+1] << endl;
    //     ans = (ans + dp[i+1]*rdp[i+1] -1 + MOD) % MOD;
    // }
    // cout << ans << endl;


}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> C(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(C));
    return 0;
}


Measured memory_bytes: 17392
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

int main()
{
    int n, m, l = -1, r = 1000000;
    cin >> n >> m;

    for (int i = 1; i <= m; i++)
    {
        int tmp1, tmp2;
        cin >> tmp1 >> tmp2;

        if (l < tmp1)
        {
            l = tmp1;
        }

        if (tmp2 < r)
        {
            r = tmp2;
        }
    }

    if (r < l)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << r - l + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            Console.WriteLine(
                Enumerable.Range(1, n).Where(x => x % 3 != 0 && x % 5 != 0).Sum(x => (long) x)
            );
        }
    }
}

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

int A, B, C, D;

int main() {
    cin >> A >> B >> C >> D;
    int i = 0;
    while (A > 0 && C > 0) {
        if (i % 2 == 0) C -= B;
        else A -= D;
        i++;
    }
    if (A > 0) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String[] S = s.split("/");
		int[] N = new int[3];
		for(int i = 0; i < 3; i++) {
			N[i] = Integer.parseInt(S[i]);
		}
		String ans = "Heisei";
		if(N[0] >= 2019 && N[1] >= 5) {
			ans = "TBD";
		}
		System.out.println(ans);
		sc.close();
	}
	
}


Measured memory_bytes: 23764
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;

int main(){

double a,b,c;
double s,l,h;

cin>>a>>b>>c;
c=M_PI/180*c;
s=0.5*a*b*sin(c);
l=a+b+sqrt(pow(a,2)+pow(b,2)-2*a*b*cos(c));
h=b*sin(c);

cout<<fixed<<s<<endl<<l<<endl<<h<<endl;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    setmin(h, 2 * q);
    setmin(s, 2 * h);
    setmin(d, 2 * s);
    cout << (n / 2) * d + (n % 2) * s << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
typedef unsigned us;
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

const int N=100005;
int a[305][305],x,n;
bool f[305][305];
ll ans;

int main(){
	scanf("%d",&n);
	rep(i,1,n+1) 
		rep(j,1,n+1) scanf("%d",&a[i][j]);
	rep(i,1,n+1) 
		rep(j,i+1,n+1)  {
			x=1<<30;
			rep(k,1,n+1) if (i!=k && j!=k) {
				x=min(x,a[i][k]+a[k][j]);
			
			}
			if (x<a[i][j]) {printf("-1");return 0;}
			if (x>a[i][j]) f[i][j]=1;
			}
	rep(i,1,n+1)
		rep(j,i+1,n+1) if (f[i][j]) ans+=a[i][j];
	printf("%lld",ans);
	
}

Measured memory_bytes: 640
n=int(input())
for a in range(1,3501):
    for b in range(1,3501):
        if (4*a*b-n*b-a*n)!=0:
            c=n*a*b/(4*a*b-n*b-a*n)
            if c>=1 and c.is_integer():
                print(a,b,int(c))
                exit()

Measured memory_bytes: 73572
#include<stdio.h>
int main()
{
	int n, m;
	scanf("%d %d", &n, &m);
	int i;
	int x[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &x[i]);
	int a[100005];
	for (i = 0; i < 100005; i++)
		a[i] = 0;
	for (i = 0; i < n; i++)
		a[x[i]]++;
	int b[100005];
	for (i = 0; i <= m; i++)
		b[i] = 0;
	for (i = 0; i < n; i++)
		b[x[i] % m]++;
	int ans = b[0] / 2;
	b[0] = 0;
	if (m % 2 == 0)
	{
		ans += b[m / 2] / 2;
		b[m / 2] = 0;
	}
	for (i = 0; i < m; i++)
	{
		if (b[i] < b[m - i])
		{
			ans += b[i];
			b[m - i] -= b[i];
			b[i] = 0;
		}
		else
		{
			ans += b[m - i];
			b[i] -= b[m - i];
			b[m - i] = 0;
		}
	}
	for (i = 0; i < 100005; i++)
	{
		if (a[i] > 1 && b[i % m] > 1)
		{
			ans++;
			a[i] -= 2;
			b[i % m] -= 2;
			i--;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1280
_, M = map(int, input().split())
A = list(map(float, input().split()))


h = 1/(4*M)
count = 0

for i in range(len(A)):
  if (count==M):
    break
  elif h <= A[i]/sum(A):
    count = count + 1
if count == M:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include<stdio.h>

int main(void)
{
	int a, b;
	int d, r;
	double f;

	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / b;	
	printf("%d %d %lf\n", d, r, f);

	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long long int Q, H, S, D, N;
    cin >> Q >> H >> S >> D >> N;
    
    S = min(min(Q*4, H*2), S);
    
    if(S*2<D) {
        cout << N*S << endl;
    } else {
        cout << N/2*D+N%2*S << endl;
    }


    return 0;
    
}

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


int main(){
	int ret = 0;
	char op;
	for(int i = 0; i < 4; i++){
		cin >> op;
		if(op == '+'){
			ret++;
		}else if(op == '-'){
			ret--;
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main()
{
  int N;
  cin >>N;
  if(N%10 == 3)
    cout << "bon" << endl;
  else if(N%10 == 0 || N%10 == 1 || N%10 == 6 || N%10 == 8 )
    cout << "pon" << endl;
  else
    cout << "hon" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  string s;
  cin >> s;
  ll bc= 0;
  ll ans =0;
  rep(i,s.size()){
    if(s[i]=='B') bc++;
    else ans += bc;
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 720
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
int main(){
	int n;cin >> n;
	vector<tuple<string, int, int>>data(n);
	for (int i = 0;i < n;i++) {
		string s;
		int p;
		cin >> s >> p;
		data[i] = make_tuple(s, 100 - p, i + 1);
	}
	sort(data.begin(), data.end());
	for (int i = 0;i < n;i++) {
		cout << get<2>(data[i]) << 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 int ll;

int main(void){
    int n,m;
    cin >> n >> m;
    int p[n];
    int w[n];
    rep(i,n){
        p[i] = 0;
        w[i] = 0;
    }
    int ac,wa;
    ac = 0;
    wa = 0;
    rep(i,m){
        int x;
        string s;
        cin >> x >> s;
      	x--;
        if(s=="WA"){
          	if(p[x] == 0){
           	    w[x]+=1;
            }
        }
        else{
            if(p[x] == 0){
                p[x] = 1;
                ac++;
            }
        }
    }
    rep(i,n){
        if(p[i] == 1){
            wa += w[i];
        }
    }
    
    cout << ac << " " << wa << endl;
    
    return 0;
    
}






















































Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int min = sc.nextInt();
        int max = sc.nextInt();

        int count = 0;
        for (int i = min; i <= max; i++) {
            if (isKaibun(i) == true) count++;
        }

        System.out.println(count);
    }

    private static boolean isKaibun(int n) {
        boolean isKaibun = true;

        char[] nCharArr = Integer.valueOf(n).toString().toCharArray();
        for (int i = 0; i < nCharArr.length; i++) {
            if (nCharArr[i] != nCharArr[nCharArr.length - i - 1]) {
                isKaibun = false;
                break;
            }
        }

        return isKaibun;
    }
}


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

int main() {
  int i, W, H, N;

  cin >> W >> H >> N;
  
  int up=H, down=0, right=W, left=0;
  int w, h, a;
  
  rep(i,N){
    cin >> w >> h >> a;
    if(a==1 && left<w) left=w;
    else if(a==2 &&  right>w) right=w;
    else if(a==3 && down<h) down=h;
    else if(a==4 && up>h) up=h;
  }
  
  if(right<left || up < down) cout << 0;
  else cout << (up-down)*(right-left);
}

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

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

    int n;
    cin >> n;
    int ans = 0;
    REP(i, n){
        int a;
        cin >> a;
        while(!(a % 2)){
            a /= 2;
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

  if (k == 1) {
    cout << 0 << endl;
  } else {
    cout << n - k << endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	ll N, M;
	ll x[1010], y[1010], z[1010];
	ll maxn = -(1LL << 60);
	cin >> N >> M;
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i] >> z[i];
	}
	for (int i = 0; i < 8; ++i) {
		vector<ll>vec;
		for (int j = 0; j < N; ++j) {
			ll S;
			ll A = x[j] * (i & 1 ? 1 : -1);
			ll B = y[j] * (i & 2 ? 1 : -1);
			ll C = z[j] * (i & 4 ? 1 : -1);
			S = A + B + C;
			vec.push_back(S);
		}
		sort(vec.begin(),vec.end());
		reverse(vec.begin(),vec.end());
		ll ans = 0;
		for (int j = 0; j < M; ++j) {
			ans += vec[j];
		}
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

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

using namespace std;
#define ll long long
#define clr(v,d) memset(v,d,sizeof(v))
#define loop(i,n) for(int i=0; i<n; i++)
#define loop1(i,n) for(int i=1; i<=n; i++)
#define loopi(i,s,e) for(int i=s; i < e; i++)
#define PI 3.14159265359
#define x first
#define y second

int main() {
    //freopen("dream.in" , "r" , stdin) ;
    //freopen("1.txt" , "w" , stdout) ;
    cin.tie(0);
    cin.sync_with_stdio(0);

    int n; cin>>n;
    vector<ll> a(n);

    loop(i,n) cin>>a[i];
    //brute force solution

    int ans=1e9;
    for(int i=-100; i <= 100; i++){
        int temp = 0;
        for(int j=0; j < n; j++){
            temp+= (a[j] - i)*(a[j] - i);
        }

        ans=min(ans,temp);
    }

    cout<<ans;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int n = sc.nextInt();

        for(int i = 0 ; i < n ; i++){
        	h -= sc.nextInt();
        }

        System.out.println(h <= 0 ? "Yes" : "No");
    }
}

Measured memory_bytes: 47612
#include <bits/stdc++.h>
using namespace std;
 
#define clr(i, j)     memset(i, j, sizeof(i))
#define pb            push_back
 #define PI acos(-1)
 #define MOD ((int)1e9+7)
typedef long long     ll;
 
//-*-*-*-*-*-*-*-*-
 
 

 
const int N=2e5+100;
ll visited[100005];
//ll a[200000];
 

#define lop(i,n) for(int i=0;i<n;++i)
//ll n,m,mod;

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

const int MAX = 2e5 + 10 ;
void finis(){cout<<-1;}


string arr[10]={"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"};
ll h,w,n,m,k;
ll x,y,a,b,c;
int main()
{  ios::sync_with_stdio(0);
cin.tie(0);

cin>>x>>y>>a>>b>>c;
ll r[a];ll g[b];ll l[c];
for(int i=0;i<a;i++){
    cin>>r[i];
}for(int i=0;i<b;i++){
    cin>>g[i];
}for(int i=0;i<c;i++){
    cin>>l[i];
}
sort(r,r+a);sort(g,g+b);sort(l,l+c);//reverse(r,r+a);reverse(g,g+b);reverse(l,l+c);
ll  p,p1,p2;
p=a-x;
p1=b-y;
p2=c-1;/*
2 2 2 2 2
6 8
1 9
1 2*/
/*
1 2 2 2 1
2 4
3 5
3
*/
while(p<a&&p1<b&&p2>=0){
    ll mon=min(r[p],g[p1]);if(l[p2]>mon){
        if(mon==r[p]){
            r[p]=l[p2];
            p++;p2--;
        }else if(mon==g[p1]){
            g[p1]=l[p2];
            p1++;p2--;
        }
    }else {break;}
    
}while(p<a&&p2>=0){
    ll mon=r[p];if(l[p2]>mon){
       
            r[p]=l[p2];
            p++;p2--;
        
    }else {break;}
    
}while(p1<b&&p2>=0){
    ll mon=g[p1];if(l[p2]>mon){
       
            g[p1]=l[p2];
            p1++;c--;
        
    }else {break;}
    
}
ll ans=0;
for(int i=a-x;i<a;i++){
   // cout<<r[i]<<" ";
   ans+=r[i];
}cout<<endl;for(int i=b-y;i<b;i++){
 // cout<<g[i]<<" ";
 ans+=g[i];
}

cout<<ans;

    
}


Measured memory_bytes: 5972
///بِسْمِ الّٰلهِ الرَّحْمٰنِ الرَحِيْمِ
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi acos(-1.0)
int main()
{
     ios_base::sync_with_stdio(false);cin.tie(NULL);
     ll int i,n,t,j=0,p,x,a=0,b,l=0,r=0,y,k,c,sum=0,m,d;
     cin>>a>>b;
     if(a<b){
        cout<<0<<endl;
     }
     else{
        cout<<10<<endl;
     }

     return EXIT_SUCCESS;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<int,int>;
using PP=pair<int,P>;
using Pl=pair<ll,ll>;
using PPl=pair<ll,Pl>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
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(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int N,K;
    cin>>N>>K;
    vi x(N),y(N);
    vvi sum(K*4,vi(K*4));
    REP(i,N){
        string st;
        cin>>x[i]>>y[i]>>st;
        if(st=="W"){
            x[i]+=K;
        }
        x[i]%=K*2;
        y[i]%=K*2;
        sum[x[i]][y[i]]++;
        sum[x[i]+K*2][y[i]]++;
        sum[x[i]][y[i]+K*2]++;
        sum[x[i]+K*2][y[i]+K*2]++;
    }
    REP(i,K*4){
        REP(j,K*4){
            if(i+1<K*4){
                sum[i+1][j]+=sum[i][j];
            }
        }
    }
    REP(i,K*4){
        REP(j,K*4){
            if(j+1<K*4){
                sum[i][j+1]+=sum[i][j];
            }
        }
    }
    REP(i,K*4){
        REP(j,K*4){
            int s=sum[i][j];
            if(i-1>=0){
                s-=sum[i-1][j];
            }
            if(j-1>=0){
                s-=sum[i][j-1];
            }
            if(i-1>=0&&j-1>=0){
                s+=sum[i-1][j-1];
            }
        }
    }
    int ans=0;
    REP(i,K*2){
        REP(j,K*2){
            int cnt=0;
            {
                int p=0;
                p+=sum[i+K-1][j+K-1];
                if(i-1>=0)p-=sum[i-1][j+K-1];
                if(j-1>=0)p-=sum[i+K-1][j-1];
                if(i-1>=0&&j-1>=0)p+=sum[i-1][j-1];
                cnt+=p;
            }
            {
                int q=0;
                q+=sum[i+K*2-1][j+K*2-1];
                q-=sum[i+K-1][j+K*2-1];
                q-=sum[i+K*2-1][j+K-1];
                q+=sum[i+K-1][j+K-1];
                cnt+=q;
            }
            chmax(ans,cnt);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 63744
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
// #include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for(int i=(int)(a); i<(int)(b); ++i)
#define REP(i, n) for(int i=0; i<(int)(n); ++i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dfs(int k, int n, int pn, int d){
  if (d == 0) return (k == 0) & 1;
  int res = 0;
  FOR(i, pn + 1, n + 1){
    int nk = k - i;
    if(nk < 0) continue;
    res += dfs(nk, n, i, d - 1);
  }
  return res;
}

int main() {
  int n, s, k;
  while(cin >> n >> s >> k, n | s | k) {

    cout << dfs(k, n, 0, s) << endl;
  }
}

Measured memory_bytes: 2996
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const int MOD = 1e9+7;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int main()
{
	int N;
	string S;

	cin >> N >> S;

	while(1){
		int cp = 0;
		bool flag = true;
		
		rep(i, S.size()){
			if( S[i] == '(' ) ++cp;
			else --cp;

			if( cp < 0 ){
				S = "(" + S;
				flag = false;
				break;
			}
		}

		if( cp > 0 ){
			S = S + ")";
			flag = false;
		}
		
		if( flag ) break;
	}

	cout << S << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <queue>
#include <deque>
#include <iomanip>
#include <cmath>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>

#define FOR(i,n) for(int i=0;i<n;i++)
#define FORE(i,a,b) for(int i=a;i<=b;i++)
#define ll long long 
//#define int long long
#define ld long double
#define vi vector<int>
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define iii pair<int,ii>
#define il pair<ll,ll>
#define vv vector
//#define endl '\n'
using namespace std;
const int MAXN = 700 + 5;


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,k,q;
    cin >> n >> k >> q;
    int arr[n];
    bool blocked[n];
    FOR(i,n)blocked[i] = 0;
    ii arr2[n];
    FOR(i,n)cin >> arr[i];
    FOR(i,n)arr2[i] = {arr[i],i};
    sort(arr2,arr2+n);
    int val = 2e9;
    FOR(i,n){
    	
    	vi best;
    	vi all;
    	FOR(i,n){
    		if(blocked[i]){
    			if(all.size()>=k){
    				sort(all.begin(), all.end());
    				int s = all.size();
    				FOR(i,s-k+1)best.pb(all[i]);
    			} 
    			all.clear();
    		}else{
    			all.pb(arr[i]);
    		}
    	}
    	if(all.size()>=k){
			sort(all.begin(), all.end());
			int s = all.size();
			FOR(i,s-k+1)best.pb(all[i]);
		}
		if(best.size() < q)continue;
		sort(best.begin(), best.end());

		val = min(val,best[q-1] - best[0]);
		blocked[arr2[i].ss]=true;
    }
    cout << val << endl;

    
    return 0;
}


Measured memory_bytes: 3728
/*  ex7_1
    Y_Aizaki  */

#include <stdio.h>

typedef struct point
{
    int x_elem; // x座標
    int y_elem; // y座標
}point;

point shift_point(point p, point q){
    point r;

    r.x_elem = q.x_elem + (-1)*(q.y_elem - p.y_elem);
    // qとrのx座標の差の大きさは、pとqのy座標の差の大きさに等しい
    r.y_elem = q.y_elem + (q.x_elem - p.x_elem);
    // qとrのy座標の差の大きさは、pとqのx座標の差の大きさに等しい

    return r;
}

int main(void){
    point A,B,C,D;
    scanf("%d%d%d%d", &A.x_elem, &A.y_elem, &B.x_elem, &B.y_elem);

    C = shift_point(A, B);
    D = shift_point(B, C);

    printf("%d %d %d %d\n", C.x_elem, C.y_elem, D.x_elem, D.y_elem);

    return 0;
}

Measured memory_bytes: 1716
n, t = map(int, input().split())
tn = [int(num) for num in input().split()]

sum = 0
for i in range(len(tn)):
  if i < len(tn)-1:
    if tn[i]+t < tn[i+1]:
      sum += t
    else :
      sum += tn[i+1] - tn[i]
  else :
    sum += t

print(sum)

Measured memory_bytes: 30680
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; i < (i64)(n); ++i)
#define WHOLE(x) std::begin(x), std::end(x)
#define LEN(a) int((a).size())

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

template <typename T>
using V = std::vector<T>;
template <typename T>
vector<T> make_vec(size_t n, T a) {
  return vector<T>(n, a);
}
template <typename... Ts>
auto make_vec(size_t n, Ts... ts) {
  return vector<decltype(make_vec(ts...))>(n, make_vec(ts...));
}
template <typename T>
istream &operator>>(istream &is, vector<T> &a) {
  for (auto &x : a) is >> x;
  return is;
}
template <typename Container>
ostream &pprint(const Container &a, string_view sep = " ",
                string_view ends = "\n", ostream *os = nullptr) {
  if (os == nullptr) os = &cout;
  auto b = std::begin(a), e = std::end(a);
  for (auto it = std::begin(a); it != e; ++it) {
    if (it != b) *os << sep;
    *os << *it;
  }
  return *os << ends;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
  return pprint(a, ", ", "", &(os << "[")) << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &a) {
  return pprint(a, ", ", "", &(os << "{")) << "}";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &a) {
  return os << "(" << a.first << ", " << a.second << ")";
}

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  V<tuple<i64, i64, i64>> cakes(N);
  REP(i, N) {
    i64 x, y, z;
    cin >> x >> y >> z;
    cakes[i] = {x, y, z};
  }
  i64 ans = 0;
  REP(s, 8) {
    int sx = s >> 2 & 1;
    int sy = s >> 1 & 1;
    int sz = s & 1;
    V<i64> v(N);
    REP(i, N) {
      auto [x, y, z] = cakes[i];
      v[i] += sx ? -x : x;
      v[i] += sy ? -y : y;
      v[i] += sz ? -z : z;
    }
    sort(v.rbegin(), v.rend());
    i64 sum = 0;
    REP(i, M) { sum += v[i]; }
    chmax(ans, sum);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3668