akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	while(true){
		int ma,n,d[255];
		scanf("%d",&ma);
		if(ma==0)break;
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",&d[i]);
		vector<int>G[255];
		for(int i=0;i<=n;i++){
			for(int j=1;j<=ma;j++){
				int x=i+j+d[i+j];
				if(x<0)x=0;
				if(x>n)x=n+1;
				G[i].push_back(x);
			}
		}
		bool f[255];
		for(int i=0;i<=n+1;i++){
			f[i]=false;
		}
		vector<int>vertex1;
		vertex1.push_back(0);int l=0;
		while(l<(int)vertex1.size()){
			int v=vertex1[l];l++;if(f[v])continue;
			f[v]=true;
			for(int i=0;i<(int)G[v].size();i++){
				if(!f[G[v][i]])vertex1.push_back(G[v][i]);
			}
			
		}
		bool ans=true;
		if(!f[n+1]){
			printf("NG\n");
			continue;
		}
		for(int s=1;s<=n+1;s++){
			if(f[s]){
				bool f1[255];
				for(int i=0;i<=n+1;i++)f1[i]=false;
				vertex1.clear();
				vertex1.push_back(s);l=0;
				while(l<(int)vertex1.size()){
					int v=vertex1[l];l++;if(f1[v])continue;
					f1[v]=true;
					for(int i=0;i<(int)G[v].size();i++){
						if(!f1[G[v][i]])vertex1.push_back(G[v][i]);
					}
				}
				if(!f1[n+1]){
					ans=false;
				}
			}
		}
		if(ans)printf("OK\n");
		else printf("NG\n");
	}
}

Measured memory_bytes: 1216
a, b, c, d, e, f = map(int, input().split())

max_sw = 100 * a
max_s = 0
x = f // (a * 100)
y = f // (b * 100)
for i in range(x + 1):
    for j in range(y + 1):
        if i == 0 and j == 0:
            continue
        water = i * a * 100 + j * b * 100
        if water <= f:
            z = e * water // 100 // c
            w = e * water // 100 // d
            for k in range(z + 1):
                for l in range(w + 1):
                    sugar = k * c + l * d
                    if sugar + water <= f and e * water // 100 >= sugar \
                            and water + sugar > 0:
                        density = sugar / (sugar + water)
                        if density >= max_s / max_sw:
                            max_s = int(sugar)
                            max_sw = int(sugar + water)


print("{} {}".format(max_sw, max_s))


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

#define ALL(a) (a).begin(), (a).end()
#define llong long long

using namespace std;

signed main(){
	int n,m,Q;
	scanf("%d %d %d", &n, &m, &Q);
	vector<int> q(Q), a(m);
	for(int i = 0; i < m; i++)scanf("%d", &a[i]);
	for(int i = 0; i < Q; i++)scanf("%d", &q[i]);
	list<int> l;
	auto itr = l.begin(); 
	for(int i = n-1; i >= 0; i--){
		itr = l.insert(itr, i);
	}
//	cerr << "pass" << endl;
	itr = l.begin();
	for(int i = 0; i < m; i++){
		if(a[i] & 1){
			for(int j = 0; j < a[i]; j++){
				if(itr == l.begin()) itr = prev(l.end());
				else itr = prev(itr);
			}
			itr = l.erase(itr);
			if(itr == l.end())itr = l.begin();
		}
		else{
			for(int j = 0; j < a[i]; j++){
				itr = next(itr);
				if(itr == l.end()) itr = l.begin();
			}
			itr = l.erase(itr);
			if(itr == l.end()) itr = l.begin();
		}
	}
//	cerr << "pass" << endl;
	vector<bool> isalive(n,false);
	for(auto i = l.begin(); i != l.end(); ++i)isalive[*i] = true;
//	for(auto e : isalive)cerr << e << endl;
//	cerr << "q" << endl;
	for(int i = 0; i < Q; i++){
		if(isalive[q[i]])printf("1\n");
		else printf("0\n");
	}
	return 0;
}




Measured memory_bytes: 9928
#include<iostream>
using namespace std;
int main(void)
{
  int num;
  cin >> num;
  
  int array[num];
  int all = 0;

  for(int i = 0; i < num; i++) {
    cin >> array[i];
    all = all ^ array[i];
//    cout << array[i] << '\n';
  }
  

  for(int i = 0; i < num; i++) {
    cout << (all ^ array[i]) << ' ';
  }

    return 0;
}

Measured memory_bytes: 4300
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long i, n, m, ans=1;
    cin >> n >> m;
    if(abs(m-n)>=2) ans=0;
    else{
        for(i=1;i<=n;i++){
            ans*=i;
            ans%=1000000007;
        }
        for(i=1;i<=m;i++){
            ans*=i;
            ans%=1000000007;
        }
    }
    if(abs(m-n)==0) {
        ans*=2;
        ans%=1000000007;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		
		s = s.replaceAll("eraser", "");
		s = s.replaceAll("erase", "");
		s = s.replaceAll("dreamer", "");
		s = s.replaceAll("dream", "");
		
		String ans = s.length() == 0 ? "YES" : "NO";
		System.out.println(ans);
		
		sc.close();
	}
}




Measured memory_bytes: 33360
//
#include <iomanip>
#include <utility>
#include <algorithm>
#include <type_traits>
#include <set>
#include <string>
#include <iostream>
#include <fstream>
#include <cassert>
#include <memory>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <queue>
#include <vector>
#include <array>
#include <chrono>
#include <random>
#include <forward_list>
#include <iomanip>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <sstream>
#include <numeric>


using namespace std;

#define debug(n) cout << n << endl;
#define REP(i,m,n) for(int i=m;i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define omajinai ios::sync_with_stdio(false); cin.tie(0)


int main(){
	int n,t;
	scanf("%d %d\n", &n, &t);
	vector<int> a(n);
	rep(i,n){
		scanf("%d\t", &a[i]);
	}
	int counter = 0;
	int min_v = a[0];
	int max_score = 0;
	REP(i,1,n){
		if(min_v + max_score < a[i]){
			max_score = a[i] - min_v;
			counter = 1;
			// updates max value;
		}
		else if(min_v + max_score == a[i]){
			counter++;
		}
		else{
			min_v = std::min(min_v, a[i]);
		}
	}
	printf("%d\n", counter);
	return 0;
}


Measured memory_bytes: 640
x=int(input())

if 400<=x<600:ans=8
if 600<=x<800:ans=7
if 800<=x<1000:ans=6
if 1000<=x<1200:ans=5
if 1200<=x<1400:ans=4
if 1400<=x<1600:ans=3
if 1600<=x<1800:ans=2
if 1800<=x<2000:ans=1

print(ans)

Measured memory_bytes: 61620
#include<bits/stdc++.h>
using namespace std;
bool is_prime(int x)
{
    if (x < 2) return false;
    for (int i = 2; i <= x / i; i ++ )
        if (x % i == 0)
            return false;
    return true;
}
int main()
{
long long a,b,k;
    cin>>a;
    while(a)
    {

    if(is_prime(a)){cout<<a<<endl;break;}
    else a++;
    }
    return 0;
}


Measured memory_bytes: 256
//
//AOJ 2104 Country Road
//date:20170417
//640009E
//Yang Bo
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>

using namespace std;

int main()
{
  int t = 0; //??????????????????????????°
  int n = 0, k = 0; //n:??¶????????°, k:?????????????????°

  cin >> t; //??????????????????????????°?????\???
  
  do {
    cin >> n >> k; //??¶????????°n??¨?????????????????°k?????\???
    
    vector<int> a(n); //??¶?????§?¨???????????????????
    
    for(int i = 0; i < n; i++)
      cin >> a[i]; //??¶?????§?¨??????\???
    
    if(k >= n){
      cout<< "0\n";
      continue;
    }
    
    vector<int> b(n-1); //??¶??¨??¶??????????????¢??????????????????
    for (int i = 0; i < n-1; i++)
      b[i] = a[i + 1] - a[i]; //??¶??¨??¶??????????????¢?????£??\
    
    sort(begin(b), end(b), greater<int>()); //?????¢???????????????????????????

    int ans = a[n - 1] - a[0]; //?????????????????????????????£??\
    for (int i = 0; i < k - 1; i++)
      ans = ans - b[i]; //????????????????????????????????????????????????
    
    cout << ans << '\n';
    
  } while (--t > 0);
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

int main(){
    int n;
    cin >> n;
    int g[15][15];
    rep(i, 15) rep(j, 15) g[i][j] = -1;
    rep(i,n){
        int Ai;
        cin >> Ai;
        rep(j, Ai){
            int x, y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    }

    int ans = 0;
    rep(i, 1<<n){
        vector<int> H(n);
        rep(j, n) if (i>>j&1) H[j] = 1;

        bool ok = true;
        rep(j, n){
            if(H[j] == 0) continue;
            rep(k,n){
                if (g[j][k] == -1) continue;
                if (g[j][k] != H[k]) ok = false;
            }   
        }
        if (ok) ans = max(ans, __builtin_popcount(i));
    }
    cout << ans << endl;
}

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

const int maxN = 1e5 + 5;
vector<int> adj[maxN];
bool visited[maxN];
int dist[maxN], in[maxN];

void dfs(int v) {
    assert(!visited[v]);
    visited[v] = true;
    for(int u : adj[v]) {
        dist[u] = max(dist[u], dist[v] + 1);
        in[u]--;
        if (in[u] == 0) {
            dfs(u);
        }
    }
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        adj[a].push_back(b);
        in[b]++;
    }

    for(int i = 0; i < n; i++) {
        if (!visited[i] && in[i] == 0)
            dfs(i);
    }

    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans = max(ans, dist[i]);
    }
    cout << ans;
    return 0;
}


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

int main(){
    string n;
    cin>>n;
    char h,j,i; 
    h=n.at(0);
    j=n.at(1);
    i=n.at(2);
    if(h=='7'||j=='7'||i=='7')cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    }


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

int main() {
  int N;
  cin >> N;
  vector<int>vec(N);
  for(int i=0; i<N; i++){
    cin >> vec[i];
  }
  sort(vec.begin(),vec.end());
  cout << vec[N-1] - vec[0] << endl;
}


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

#define ll long long
#define deb(x) cerr << #x << ":" << x << "\n"
#define all(x) x.begin(),x.end()
#define sz(x) x.size()

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

void solve()
{
    int h,w,m;
    cin>>h>>w>>m;
    map<int,unordered_set<int>> mpx;
    map<int,unordered_set<int>> mpy;
    for(int i=0;i<m;i++){
        int x,y;
        cin>>x>>y;
        mpx[x].insert(y);
        mpy[y].insert(x);
    }
    int mxx=-1,mxy=-1;
    for(auto P:mpx){
        mxx=max(mxx,int(P.second.size()));
    }
    for(auto P:mpy){
        mxy=max(mxy,int(P.second.size()));
    }
    // deb(mxx);deb(mxy);
    vector<int> a,b;
    for(auto P:mpx){
        if(P.second.size()==mxx){
            a.emplace_back(P.first);
        }
    }
    for(auto P:mpy){
        if(P.second.size()==mxy)b.emplace_back(P.first);
    }
    if(sz(a)*sz(b)>300000){
        int x=a[0],y=b[0];
        cout<<int(mpx[x].size()+mpy[y].size())<<"\n";
        return;
    }
    int ans=0;
    int cnt=0;
    for(auto x:a){
        for(auto y:b){
            // cout<<x<<":"<<y<<"\n";
            ++cnt;
            ans=max(ans,int(mpx[x].size()+mpy[y].size()-(mpx[x].count(y)||mpy[y].count(x))));
        }
        if(cnt==1000000)break;
    }
    cout<<ans<<"\n";
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 110476
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
    int n;
    Deque<Character> deque;
    char[] cs;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        cs = sc.next().toCharArray();
        deque = new LinkedList<>();
        for (int i = 0; i < n; i++) {
            deque.offer(cs[i]);
        }
        solve();
    }

    void solve() {
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (cs[i] == '(') {
                count++;
            } else {
                count--;
            }
            while (count < 0) {
                deque.offerFirst('(');
                count++;
            }
        }
        while (count > 0) {
            deque.offer(')');
            count--;
        }
        StringBuilder sb = new StringBuilder();
        while (!deque.isEmpty()) {
            sb.append(deque.poll());
        }
        System.out.println(sb);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

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

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

  ll ans=0;
  for(auto x: m){
    if(x.first <= x.second){
      ans += x.second-x.first;
    } else {
      ans += x.second;
    }
  }

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


Measured memory_bytes: 4736
from collections import Counter
n,m = map(int,input().split())
a = list(map(int,input().split()))
ssum = [0]*(n+1)
for i in range(n):
    ssum[i+1] = (ssum[i]+a[i])%m
c = Counter(ssum)
ans = 0
for v in c.values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 21164
fn get_input() -> String {
    let mut word = String::new();
    std::io::stdin().read_line(&mut word).unwrap();
    word.trim().to_owned()
}

fn main() {
    let s = get_input();
    let u:i64 = s[0..2].parse().unwrap();
    let d:i64 = s[2..].parse().unwrap();

    let yymm = u >= 0 && 1 <= d && d <= 12;
    let mmyy = 1 <= u && u <= 12 && d >= 0;

    let ans = if yymm && mmyy {
        "AMBIGUOUS"
    } else if yymm {
        "YYMM"
    } else if mmyy {
        "MMYY"
    } else {
        "NA"
    };

    println!("{}", ans);
}

Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[200005]={};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
   
  }

  int i=0;
  int ans=0;
  int num=1;
  bool flag=false;
  while (a[i]!=0) {
    if(a[i]!=num)ans++;
    else {num++;flag=true;}
    i++;
  }

  if(flag==true) cout << ans <<endl;
  else cout << -1 << endl;




  return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  std::string S;
  std::cin >> S;
  std::cout << std::string(S.size(), 'x') << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define inf 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    // int dp[2001][668];
    // int comb(int n,int x)
    // {
    //     if(n<=0)
    //         return 0;
    //     if(x<=0)
    //         return 0;
    //     int ans=0;
    //     for (int i = 0; i <=n; ++i)
    //     {
    //         if(dp[n-i][x-1]==0 && (n-i)!=0 && (x-1)!=0)
    //             dp[n-i][x-1]=comb(n-i,x-1)%M;
    //         ans+=dp[n-i][x-1]%M;
    //         // ans%=M;
    //     }
    //     return ans%M;
    // }
    int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
  
        return (y%2 == 0)? p : (x * p) % m; 
    } 
    int modInverse(int a, int m) 
    {   
        return power(a, m-2, m);
    }
    int nCrModPFermat(int n, int r, int p) 
    { 
        // if(n==0)
        //     return 0;
           if (r==0) 
              return 1; 
  
        int fac[n+1]; 
        fac[0] = 1; 
        for (int i=1 ; i<=n; i++) 
            fac[i] = fac[i-1]*i%p; 
  
        return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
    } 
    signed main()
    {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll t=1;
        // cin >> t;
        /*SAARE INPUTS LENA*/
        /*VARIABLES KI RANGE DEKHLENA*/
        /*EXPONENT RANGE OF OUTPUT KA DHYAN RAKHNA*/
        while(t-->0)
        {
            ll n=0;
            cin>>n;
            ll a=0,b=0;
            // vecctor <pii> v(n);
            vector <int> v1(n),v2(n);
            for (int i = 0; i < n; ++i)
            {
                cin>>a>>b;
                v1[i]=a+b;
                v2[i]=a-b;
            }
            sort(all(v1));
            sort(all(v2));
            ll ans=max(v1[n-1]-v1[0],v2[n-1]-v2[0]);
            cout<<ans;
        }
        return 0;
    }

Measured memory_bytes: 6372
//		HYSO SERIOUS? WHY SO SERIOUS                            RIOUS? WHY SO SERIOUS? WHYSO SERIO
//		 ERIOUS? WHY SO SERIOUS ? WHY                          WHY SO SERIOUS? WHY SOSERIOUSWHYS
//		       OSERIOUS? WHY SO SERIOU         SERIOUS        ERIOUS? WHY SO SERIOUS? WHYS
//		          WHY SO SERIOUS? WHY SOSERIOUS? WHYSOSERIOUS? WHY SO SERIOUS?WHY SO SE
//		           ERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SOSERIO
//		           WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WH
//		            SERIOUS?WHYSO SERIOUS? WHY SO SERIOUS? WHY SO SERIOUS? WHYSO SE
//		              ?WHYSOSERIOUS?WHY SO SERIOUS? WHY SO SERIOUS?WHYSO SERIOUS?
//		                           OSERIOUS? WHY SO SERIOUS?WHYSOSER
//		                                 HYSOSERIOUS?WHYSOSERI
//		                                     SOSERIOUS?W
//		                                         SER
//		                                          W


#include 	<ext/pb_ds/assoc_container.hpp> 
#include 	<ext/pb_ds/tree_policy.hpp> 
#include 	<iostream>
#include 	<queue>
#include 	<tuple>
#include 	<vector>
#include	<bits/stdc++.h>
#include	<algorithm>
#include 	<cmath>
#include 	<map>
#include 	<string>
#include 	<iomanip> 
using 		namespace __gnu_pbds; 
using 		namespace std;
#define 	ll  long long int
#define		read(a) long long int a; cin>>a;
#define 	readstr(s) string s; cin>>s;
#define 	readc(c) char c; cin>>c;
#define 	readarr(a,l) long long int a[l]={0}; for(ll i=0;i<l;i++) cin>>a[i];
#define 	loop(i,a,b) for(ll i=a;i<b;i++)
#define 	rloop(i,a,b) for(ll i=a;i>b;i--)
#define 	loopitr(vec) for(auto it=vec.begin();it!=vec.end();it++)
#define 	ff first
#define 	ss second
#define 	readmtrx(i,j,a,b) ll arr[a][b]={0};for(ll i=0;i<a;i++)for(ll j=0;j<b;j++) cin>>arr[i][j];
#define 	v(pi) vector<ll>pi
#define 	all(a) a.begin(), a.end()
#define 	yes cout <<"YES"<<endl;
#define 	no cout <<"NO"<<endl;
#define 	sc(x) cout << (#x) << " is " << (x) << endl;
#define 	vp(pi) vector<pair<ll,ll>>pi
#define 	fast ios_base::sync_with_stdio(false);cin.tie(0);
#define 	pb(p) push_back(p)
#define 	mp make_pair
#define 	mi(lol) map<ll,ll>lol
#define 	fsort(vec) sort(vec.begin(),vec.end())
#define 	rsort(vec) sort(vec.begin(),vec.end(),compare)
#define 	Endl endl
#define 	ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define 	roundoff std::cout << std::setprecision(15)
#define 	inf 9223372036854775807
#define 	infn -9223372036854775807
#define 	pi 3.14159265358979323846
const 		int mod = 1e9+7; 
#define 	REVERSE(vec) reverse(vec.begin(),vec.end())


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

//code start from here 

int main() {
	fast;
	read(n)
	read(k)
	ll a=0;
	loop(i,k,n+2){
		a=(a+i*(n-i+1)+1)%mod;
	}
	cout<<a<<"\n";
	return 0;
}

//ends here 

Measured memory_bytes: 3652
unittest
{
	assert( [ "100", "1" ].parse.expand.solve == 19 );
	assert( [ "25", "2" ].parse.expand.solve == 14 );
	assert( [ "9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999", "3" ].parse.expand.solve == 117879300 );
	
	assert( [ "99", "3" ].parse.expand.solve == 0 );		// 追加ケース
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.map!( ( a ) => ( a - '0' ).to!( long ) ).array;
	input.popFront;
	auto k = input.front.to!( long );
	return tuple( n, k );
}

auto solve( long[] n, long k )
{
	// dp[ i桁目 ][ 0でない数字の数 ][ n未満フラグ ] = 条件を満たす整数の個数
	auto dp = new long[][][]( 1 + n.length, 1 + k + 1, 2 );
	dp[ 0 ][ 0 ][ 0 ] = 1;
	foreach( i; 0L .. dp.length.signed - 1 )
	{
		foreach( j; 0L .. dp[ i ].length.signed - 1 )
		{
			// n未満じゃないとき
			if( n[ i ] == 0 )
			{
				dp[ i + 1 ][ j     ][ 0 ] += dp[ i ][ j ][ 0 ];						// i桁目を 0 にしたとき
			}
			else
			{
				dp[ i + 1 ][ j + 1 ][ 0 ] += dp[ i ][ j ][ 0 ];						// i桁目を n[i] にしたとき
				dp[ i + 1 ][ j + 1 ][ 1 ] += dp[ i ][ j ][ 0 ] * ( n[ i ] - 1 );	// i桁目を 1 ~ n[i]-1 にしたとき
				dp[ i + 1 ][ j     ][ 1 ] += dp[ i ][ j ][ 0 ];						// i桁目を 0 にしたとき
			}
			
			// n未満のとき
			dp[ i + 1 ][ j + 1 ][ 1 ] += dp[ i ][ j ][ 1 ] * 9;		// i桁目を 1 ~ 9 にしたとき
			dp[ i + 1 ][ j     ][ 1 ] += dp[ i ][ j ][ 1 ];			// i桁目を 0 にしたとき
		}
	}
	return dp[ $ - 1 ][ k ].sum;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int a,b,c,tmp;
  scanf("%d %d %d",&a,&b,&c);
  tmp=a;
  a=b;
  b=tmp;
  tmp=c;
  c=a;
  a=tmp;
  printf("%d %d %d\n",a,b,c);
  return 0;
}

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

using namespace std;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; string T;
   cin >> N >> T;
   vector<int> perm(round(pow(3, N)));
   auto simplify = [&](string T) {
      string newT;
      for (char c : T) {
         if (c == 'R') {
            newT += c;
         } else if (newT.size() && newT.back() == 'S') {
            newT.pop_back();
         } else {
            newT += c;
         }
      }
      return newT;
   };
   function<void(int, string, int, int, int)> solve = [&](int bit, string T, int pw, int from, int to) {
      if (bit == N) {
         perm[from] = to;
         return;
      }
      for (int d : {0, 1, 2}) {
         int nd = d;
         string newT;
         for (char c : T) {
            if (c == 'S') {
               newT += c;
               if (nd) nd = 3 - nd;
            } else {
               if (nd == 2) {
                  newT += c;
               }
               nd = (nd + 1) % 3;
            }
         }
         solve(bit + 1, simplify(newT), pw * 3, from + d * pw, to + nd * pw);
      }
   };
   solve(0, T, 1, 0, 0);
   for (int v : perm) cout << v << " "; cout << "\n";
}


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

using namespace std;

int main() 
{
    int w, a, b, ans1 = 0, ans2 = 0;
    cin >> w >> a >> b;
    
    ans1 = b-(a+w);
    ans2 = a-(b+w);
    
    printf("%d\n", ans1 > ans2 ? ans1 > 0 ? ans1 : 0 : ans2 > 0 ? ans2 : 0);
    
    return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
typedef long long ll;
typedef pair<ll, int> pli;
const int maxn = 1e5 + 10;
const int S = 8;
int ans;
ll a[maxn];
vector<ll> fact;
vector<pli> d[maxn];
ll read() {
	register ll a, b, c;
	while(c = getchar(), c < '-');
	b = (c == '-');
	for(a = b ? 0 : c - '0'; c = getchar(), c > '-'; a = a * 10 + c - '0');
	return b ? -a : a;
}
ll pow_mod(ll a, ll n, ll mod)
{
	ll ret = 1;
	a %= mod;
	while(n)
	{
		if(n & 1) ret = (__int128)ret * a % mod;
		a = (__int128)a * a % mod; n >>= 1;
	}
	return ret;
}
bool check(ll a, ll n, ll x, ll t)
{
	ll ret = pow_mod(a, x, n);
	ll last = ret;
	for(int i = 1; i <= t; ++i)
	{
		ret = (__int128)ret * ret % n;
		if(ret == 1 && last != 1 && last != n - 1) return true;
		last = ret;
	}
	if(ret != 1) return true;
	else return false;
}
bool miller_rabin(ll n) 
{
	if(n < 2) return false;
	if(n == 2 || n == 3 || n == 7 || n == 61 || n == 24251) return true;
	if((n & 1) == 0) return false;
	ll x = n - 1;
	ll t = 0;
	while((x & 1) == 0) { x >>= 1; ++t;}
	srand(time(0));
	for(int i = 0; i < S; ++i)
	{
		ll a = rand() % (n - 1) + 1;
		if(check(a, n, x, t)) return false;
	}
	return true;
}
ll pollard_rho(ll x, ll c)
{
	ll i = 1, k = 2;
	srand(time(0));
	ll x0 = rand() % (x - 1) + 1;
	ll y = x0;
	while(true)
	{
		++i;
		x0 = ((__int128)x0 * x0 % x + c) % x;
		ll d = abs(__gcd(y - x0, x));
		if(d != 1 && d != x) return d;
		if(y == x0) return x;
		if(i == k) { y = x0; k <<= 1;}
	}
}
void findfac(ll n, int k)
{
	if(n == 1) return;
	if(miller_rabin(n))
	{
		fact.push_back(n);
		return;
	}
	ll p = n;
	int c = k;
	while(p >= n) p = pollard_rho(p, c--);
	findfac(p, k);
	findfac(n / p, k);
}
void getnum(ll & num, const int & id)
{
	num = 1;
	for(auto v : d[id]) num *= pow(v.first, v.second);
}
bool getcnum(ll & cnum, const int & id)
{
	cnum = 1;
	for(auto v : d[id]) 
	{
		ll tmp = pow(v.first, 3 - v.second);
		if(log10(cnum) + log10(tmp) > 11) return false;
		cnum *= tmp;
	}
	return true;
}
unordered_map<ll, int> numcnt;
unordered_set<ll> numvis;
unordered_map<ll, ll> numcomp;
int main()
{
	int n;
	n = read();
	for(int i = 1; i <= n; ++i) a[i] = read();
	sort(a + 1, a + n + 1);
	for(int i = 1; i <= n; ++i) 
	{
		if(i > 2 && a[i] == a[i - 1])
		{
			d[i] = d[i - 1];
			continue;
		}
		findfac(a[i], 107);
		sort(fact.begin(), fact.end());
		for(int j = 0; j < fact.size();)
		{
			int r = j + 1;
			while(r < fact.size() && fact[r] == fact[j]) ++r;
			int t = (r - j) % 3;
			if(t) d[i].push_back(mp(fact[j], t));
			j = r;
		}
		fact.clear();
	}
	ll num, cnum;
	for(int i = 1; i <= n; ++i) 
	{
		getnum(num, i); 
		if(num != 1) numcnt[num]++;
		else numcnt[num] = 1;
		if(getcnum(cnum, i)) 
			numcomp[num] = cnum;
	}
	for(auto v : numcnt)
	{
		if(!numvis.count(v.first))
		{
			numvis.insert(v.first);
			if(numcomp.count(v.first) && numcnt.count(numcomp[v.first]) && !numvis.count(numcomp[v.first])) 
			{
				numvis.insert(numcomp[v.first]);
				ans += max(v.second, numcnt[numcomp[v.first]]);
			}
			else ans += v.second;
		}
	}
	printf("%d\n", ans);
	return 0;
}
/*
6
123456789
545545121
545121215
111111111
1000000007
1000000007
*/

Measured memory_bytes: 20296
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    string S; cin >> S;
    if (S.at(2) == S.at(3) and S.at(4) == S.at(5)) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    string ans;

    rep(i, S.size()) {
        int base = S.at(i) - 'A';
        ans.push_back('A' + (base + N) % 26);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		int sum = 0;
		for(int i = 0; i < n / 4; ++i)
		{
			int temp;
			cin >> temp;
			sum += temp;
		}
		cout << sum << endl;
	}
}

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

Measured memory_bytes: 0
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cinttypes>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<string>
#include<stack>


#define FSCNd64 "%" SCNd64
#define FPRId64 "%" PRId64

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

#define PI 3.1415926535897932384626433832795

template<typename X>
bool max_u(X&m, X v)
{
	if(m<v)
	{
		m=v;
		return true;
	}
	return false;
}


template<typename X>
bool min_u(X&m, X v)
{
	if(m>v)
	{
		m=v;
		return true;
	}
	return false;
}


struct unig_t
{
	int id;
	int g, n;
};


struct solve
{
	vector<unig_t> v;
	int n;
	solve(int n):n(n){
		v.resize(n+1);
		for(int i=1;i<=n;i++)
		{
			v[i].id=i;
			v[i].g=i;
			v[i].n=1;
		}
	}
	int get_g(int a)
	{
		if(a==v[a].g) return a;
		return (v[a].g=get_g(v[a].g));
	}
	void match(int a, int b)
	{
		int ga=get_g(a);
		int gb=get_g(b);
		if(ga==gb) return;

		if(v[ga].n<v[gb].n)
		{
			swap(a, b);
			swap(ga, gb);
		}
		v[ga].n+=v[gb].n;
		v[gb].g=ga;
		v[gb].n=0;
	}
	int operator()() {
		int ans=0;
		for(int i=1;i<=n;i++)
		{
			max_u(ans, v[i].n);
		}
		return ans;
	}
};

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

	for(;;)
	{
		int n, m;
		cin >> n >> m;
		if(cin.fail()) break;

		vi a(m), b(m);
		for(int i=0;i<m;i++) cin >> a[i] >> b[i];

		solve solver(n);
		for(int i=0;i<m;i++)
		{
			solver.match(a[i], b[i]);
		}
		cout << solver() << "\n";
	}
	return 0;
}


Measured memory_bytes: 7152
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};

ll ans = (ll)(1e11);
void calc(ll w, ll h) {
    rrep(a, 1, w) {
        ll w1 = (w - a) * h;
        ll w2 = a * (h / 2);
        ll w3 = (h % 2 == 0 ? w2 : a * (h / 2 + 1));
        ans = min(ans, max({w1, w2, w3}) - min({w1, w2, w3}));
    }
    rrep(a, 1, w) {
        ll w1 = a * h;
        ll w2 = (w - a) / 2 * h;
        ll w3 = ((w - a) % 2 == 0 ? w2 : ((w - a) / 2 + 1) * h);
        ans = min(ans, max({w1, w2, w3}) - min({w1, w2, w3}));
    }
}
int main() {
    ll h, w; cin >> h >> w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    calc(w, h); calc(h, w);
    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace code_festival_2016_c {
    class Program {
        static void Main(string[] args) {
            var str = scan;
            int k = str[0];
            int t = str[1];
            var a = scan;
            if (t == 1) {
                Console.WriteLine(k - 1);
                return;
            }
            while(a[t-1] !=0 ) {
                Array.Sort(a);
                var i= t - 1;
                var c = 0;
                while (c != 2) {
                    if (a[i] > 0) {
                        a[i]--;
                        c++;
                    }
                    i--;
                    if (c == 1 && i == -1) {
                        Console.WriteLine(a[t - 1]);
                        return;
                    }
                }
            }
            Console.WriteLine("0");


            
        }
        static int[] scan {
            get {
                return Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            }
        }
    }
}


Measured memory_bytes: 2776
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using i64=long long int;

bool used[401][401];

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (auto &e: S) cin >> e;

    i64 ans = 0;
    vector<pair<int, int>> dirs = {{-1, 0}, {0, -1}, {0, 1}, {1, 0}};

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (used[i][j]) continue;
            used[i][j] = true;

            i64 cnt_b = 0, cnt_w = 0;
            stack<pair<int, int>> st;
            st.emplace(i, j);
            while (!st.empty()) {
                auto p = st.top(); st.pop();
                char pc = S[p.first][p.second];
                if (pc == '.') cnt_b++;
                else cnt_w++;
                for (auto &&d: dirs) {
                    pair<int, int> c = {p.first + d.first, p.second + d.second}; 
                    if (c.first < 0 || c.first >= H || c.second < 0 || c.second >= W) continue;
                    if (used[c.first][c.second]) continue;
                    if (S[c.first][c.second] != pc) {
                        used[c.first][c.second] = true;
                        st.push(c);
                    }
                }
            }
            ans += cnt_w * cnt_b;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1280
import sys

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

for i in range(N - M + 1):
    for j in range(N - M + 1):
        matched = True

        for k in range(M):
            if A[i+k][j:j+M] == B[k]:
                continue
            else:
                matched = False
                break
    
        if matched:
            print('Yes')
            sys.exit()

print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using std::make_pair;
using std::pair;
using std::queue;
using std::vector;

constexpr int N_MAX = 1e5;
constexpr int INF   = 2e5;

// std::vectorの出力
template <typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << "\n";
    }
    return os;
}

vector<int> solve(int n, vector<vector<int>> g) {
    // (道しるべ，部屋1までの回数)
    // second は到達したかどうかのフラグでも可
    vector<pair<int, int>> dist(n + 1, make_pair(0, INF));
    dist.at(1) = make_pair(1, 0);

    queue<int> que;
    que.push(1);  // start room

    // bfs
    while (!que.empty()) {
        int prev = que.front();
        que.pop();

        for (int ge : g.at(prev)) {
            if (dist.at(ge).second != INF) continue;

            dist.at(ge) = make_pair(prev, dist.at(prev).second + 1);
            que.push(ge);
        }
    }

    // outputs
    vector<int> res;
    for (int i = 2; i <= n; ++i) {
        res.push_back(dist.at(i).first);
    }
    return res;
}

int main() {
    using std::cin;
    using std::cout;

    int n, m;
    cin >> n >> m;

    vector<vector<int>> graph(n + 1);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }

    cout << "Yes\n" << solve(n, graph);

    return 0;
}

Measured memory_bytes: 16812
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int N, p[1001];
	fill_n(p, 1001, 0);
	scanf("%d", &N);
	int L[N];
	long long ans = 0;
	for (int i = 0; i < N; ++i) {
		scanf("%d", &L[i]);
		p[L[i]] += 1;
	}
	for (int i = 1; i <= 1000; ++i) p[i] += p[i - 1];
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i == j) continue;
			int a = min(L[i], L[j]), b = max(L[i], L[j]);
			ans += p[min(a + b - 1, 1000)] - p[b - a];
			if (a <= min(a + b - 1, 1000) && a > b - a) ans -= 1;
			if (b <= min(a + b - 1, 1000) && b > b - a) ans -= 1;
		}
	}
	printf("%lld", ans / 6);
	return 0;
}

Measured memory_bytes: 128
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

l, r, d = MAP()

ans = 0
for i in range(l, r+1):
    if i % d == 0:
        ans += 1

print(ans)

Measured memory_bytes: 10040
import math

N ,M, K = map(int,input().split())
MOD = 998244353

def getInvs(n, MOD):
    invs = [1] * (n+1)
    for x in range(2, n+1):
        invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
    return invs
invs = getInvs(N+3, MOD)

num = M
nums = []
for i in reversed(range(1,N)):
    nums.append(num)
    num *= i*(M-1)
    num *= invs[N-i]
    num %= MOD
nums.append(num)
nums.reverse()

ans = sum(nums[:K+1])
ans %= MOD
print(ans)

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] X = new long[N];
        long[] s = new long[N];
        for(int i=0;i<N;i++) {
            long cur = sc.nextLong();
            X[i]=cur;
            s[i]=cur;
        }
        Arrays.sort(s);
        long smaller = s[N/2-1];
        long bigger = s[N/2];
        for(int i=0;i<N;i++){
            long ans;
            if(X[i]<=smaller) ans=bigger;
            else ans = smaller;
            System.out.println(ans);
        }

    }
}

Measured memory_bytes: 93564
# include <iostream>
# include <vector>
# include <algorithm>
# include <cmath>

using namespace std;
void The_longest_distance()
{
	int N = 0;
	cin >> N;
	vector<pair<double, double>> points;
	for (int i = 0; i < N; ++i)
	{
		int x, y;
		cin >> x >> y;
		points.emplace_back(make_pair(x, y));
	}
	double maxLen = std::numeric_limits<double>::lowest();
	for (int i = 0; i < N; ++i)
	{
		for (int j = i + 1; j < N; ++j)
		{
			auto len = (points[i].first - points[j].first) * (points[i].first - points[j].first) +
				(points[i].second - points[j].second) * (points[i].second - points[j].second);
			maxLen = std::max(maxLen, len);
		}
	}
	cout << sqrt(maxLen);
}

int main()
{
	int K = 0;
	int S = 0;
	cin >> K >> S;
	int cnt = 0;
	for (int x = 0; x <= K; ++x)
	{
		for (int y = 0; y <= K; ++y)
		{
			/*for (int z = 0; z <= K; ++z)
			{
				int val = x + y + z;
				if (val == S)
				{
					++cnt;
				}
				else if (val > S)
				{
					break;
				}
			}
			if (x + y > S)
			{
				break;
			}*/
			int z = S - x - y;
			if (0 <= z && z <= K)
			{
				++cnt;
			}
		}
		if (x > S)
		{
			break;
		}
	}
	cout << cnt;
	return 0;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
a=[]
for i in range(h):
  a.append(list(map(int,input().split())))


xylis=[]

for i in range(h-1):
  for j in range(w-1):
    if a[i][j]%2==1:
      a[i][j]-=1
      a[i][j+1]+=1
      xylis.append([i,j,i,j+1])
  if a[i][w-1]%2==1:
    a[i][w-1]-=1
    a[i+1][w-1]+=1
    xylis.append([i,w-1,i+1,w-1])
for j in range(w-1):
  if a[h-1][j]%2==1:
    a[h-1][j]-=1
    a[h-1][j+1]+=1
    xylis.append([h-1,j,h-1,j+1])

print(len(xylis))
for xylisi in xylis:
  print(*list(map(lambda x:x+1,xylisi)))


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

int main(){
  string str;
  cin >> str;
  if(str.length() < 6) cout << "No" << endl;
  else{
  	if(str[2] == str[3] && str[4] == str[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  return 0;
}


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

int main() {
	int n;
	string s;
	cin >> n >> s;
	
	int ans = 0;
	for (int i = 0; i < n - 2; ++i)
		if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
			ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

ll dp[55][55][2505];

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

int n,s;
cin>>n>>s;
int a[55];

rep(i,1,n)
cin>>a[i];

dp[1][0][0]=1;
dp[1][1][a[1]]=1;

rep(i,2,n)
{
	rep(j,0,n)
	rep(k,0,2504)
	dp[i][j][k]=dp[i-1][j][k];
	
	rep(j,0,n)
	{
		rep(k,0,2504)
		{
			if(dp[i-1][j][k])
			{
				if(k+a[i]<=2504)
				dp[i][j+1][k+a[i]]+=dp[i-1][j][k];
			}
		}
	}
}
ll ans=0;
rep(i,1,n)
{
	ans+=dp[n][i][s*i];
}
ol(ans);

return 0;
}


Measured memory_bytes: 49408
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int N, b, a[MAX];
ll ans;

int main(int argc, char ** argv) {
	scanf("%d", &N);
	REP(i, 0, N) scanf("%d", &a[i]);
	rep(i, 0, N) {
		scanf("%d", &b);
		if(b >= a[i]) {
			ans += a[i];
			b -= a[i];
		}
		else {
			ans += b;
			b = 0;
		}
		if(b >= a[i+1]) {
			ans += a[i+1];
			a[i+1] = 0;
		}
		else {
			ans += b;
			a[i+1] -= b;
		}
	}
	cout << ans << "\n";
	return 0;
}


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

a_sm =[]
asm = 0
for i in range(n):
    asm += a[i]
    a_sm.append(asm)

s = {}

for i in range(n):
    if a_sm[i] in s:
        s[a_sm[i]] += 1
    else:
        s[a_sm[i]] = 1

ans = 0
for k in s:
    ans += s[k]*(s[k]-1)//2
if 0 in s:
    ans += s[0]
print(ans)


Measured memory_bytes: 111620
//IN THE NAME OF GOD;
//Test By Dev-C++5.11
#include<bits/stdc++.h>
#define ll  long long
#define isc ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ld long double
#define ss string
#define ww while
#define vl vector<ll>
#define pb push_back
#define in insert
#define itr iterator
#define gt goto
#define rep(i,n,j) for(ll i=n;i<j;i++)
#define tep(i,n,j) for(ll i=n;i>=j;i--)
#define co(n) cout << n ;
#define pll pair<ll,ll>
#define bft bool f=true
#define bff bool f=false
using namespace std;

ll bmm(ll a, ll b) {
	if (b == 0) return a;
	else return bmm(b, a%b);
}
ll kmm(ll a, ll b) {
	return(a*b) / bmm(a, b);
}

const ll mod = 1e9 + 7;
const ll MAXN = 1e5+5;

ll a,b;

int main() {
	isc;
	cin >> a >> b;
	if(b*2>=a)
		cout << 0;
	else
		cout << a-(b*2);
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>


int main(){
   int N, M;
   std::cin >> N >> M;
   std::vector<int> X(M);
   for(int i=0; i<M; ++i)
      std::cin >> X[i];

   if(N>=M){
      std::cout << 0 << std::endl;
      return 0;
   }

   std::sort(X.begin(), X.end());
   std::vector<int> Y(N-1);
   for(int i=0; i<M-1; ++i){
      if(i<N-1) Y[i] = i;
      else{
	 int min = X[i+1]-X[i];
	 int index = -1;
	 for(int j=0; j<N-1; ++j){
	    if(min>X[Y[j]+1]-X[Y[j]]){
	       min = X[Y[j]+1] - X[Y[j]];
	       index = j;
	    }
	 }
	 if(index>-1){
	    Y[index] = i;
	 }
      }
   }

   int sum = X[M-1] - X[0];
   for(int i=0; i<N-1; ++i){
      sum -= X[Y[i]+1] - X[Y[i]];
   }
   std::cout << sum << std::endl;

   return 0;
}


Measured memory_bytes: 896
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int maxn = 5005;

int f[maxn][maxn];
int dfs(int x,int y){
  if(f[x][y]!=-1)return f[x][y];
  if(x<=1&&y<=1)return f[x][y]=0;
  for(int i=1;i+i<=x;i++)if(!dfs(x-i-i,y+i)){
    return f[x][y]=1;
  }
  for(int i=1;i+i<=y;i++)if(!dfs(x+i,y-i-i)){
    return f[x][y]=1;
  }
  return f[x][y]=0;
}

int main() {
  //freopen("in.cpp","r",stdin);
  ll x,y;
  cin>>x>>y;
  if(abs(x-y)<=1)cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int F[45];

int fib(int n)
{
  if(n==1||n==0){return F[n]=1;}
  if(F[n]!=-1){return F[n];}
  return F[n]=fib(n-1)+fib(n-2);
}

int main()
{
  int n,r,i;
  for(i=1;i<=44;i++){F[i]=-1;}
  scanf("%d",&n);
  r=fib(n);
  printf("%d\n",r);
  return 0;
}
    



Measured memory_bytes: 2112
from bisect import *
import sys
input = sys.stdin.readline
n, q = map(int, input().split())
c = list(map(int, input().split()))
class BIT():
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.bit[i] += x
            i += i & -i
query = [list(map(int, input().split()))+[i] for i in range(q)]
query.sort(key = lambda x: x[1])
appear = [-1]*(n+2)
bit = BIT(n)

right = 0
ans = [None]*(q)
for l, r, z in query:
    for i in range(right, r):
        num = appear[c[i]]
        if num != -1:
            bit.add(num+1, -1)
        appear[c[i]] = i
        bit.add(i+1, 1)
    right = r
    ans[z] = bit.sum(r) - bit.sum(l-1)

print(*ans, sep="\n")


Measured memory_bytes: 194304