akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize "trapv"
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define ld long double
#define mp make_pair
#define pii pair<int,int>
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_order(ind)
int main()
{
    fio;
    ll n;
    string s;
    cin>>n>>s;
    ll flag=0,cnt=0,cnt1=0;
    map<char,ll> m;
    rep(i,n)
    m[s[i]]++;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='R')
        {
            cnt=i;
            break;
        }
    }
    rep(i,m['R'])
    {
        if(s[i]=='W')
        cnt1++;
    }
    cout<<min(cnt1,min(m['W'],m['R']))<<endl;
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct P{
  int v,time,cur;
  P(int a, int b, int c){v=a;time=b;cur=c;}
  bool operator<(const P& a)const{ return v < a.v; }
  bool operator>(const P& a)const{ return v > a.v; }
};

struct Edge{
  int to,cost;
  Edge(int t, int c){to=t;cost=c;}
};

int N,M,L,K,A,H;
vector<Edge>G[128];
int dist[128][128];
int frez[128];

void dijkstra(){
  rep(i,M+1) fill(dist[i], dist[i] + N, INF);
  priority_queue<P, vector<P>, greater<P> >q;
  dist[M][A]=0;
  q.push(P(0,M,A));
  
  while(!q.empty()){
    P p = q.top(); q.pop();
    if(p.v > dist[p.time][p.cur]) continue;
    rep(i,G[p.cur].size()){
      Edge e = G[p.cur][i];
      if(p.time-e.cost >= 0 && dist[p.time-e.cost][e.to] > dist[p.time][p.cur] + e.cost){
	int tmp = dist[p.time][p.cur] + e.cost;
	dist[p.time-e.cost][e.to] = tmp ;
	q.push(P(dist[p.time-e.cost][e.to], p.time-e.cost, e.to));
      }

      if(frez[p.cur]){
	for(int r=1;r<=M-p.time;r++){
	  if(p.time-e.cost+r >= 0 && dist[p.time-e.cost+r][e.to] > dist[p.time][p.cur] + e.cost + r){
	    dist[p.time-e.cost+r][e.to] = dist[p.time][p.cur] + e.cost + r;
	    q.push(P(dist[p.time-e.cost+r][e.to], p.time-e.cost+r, e.to));
	  }
	}
      }
    }
  }
}

int main(){
  while(cin >> N >> M >> L >> K >> A >> H, N+M+L+K+A+H){
    memset(frez,0,sizeof(frez));
    rep(i,128) G[i].clear();
    frez[A] = frez[H] = 1;
    rep(i,L){
      int x; cin >> x;
      frez[x] = 1;
    }
    rep(i,K){
      int x,y,t; cin >> x >> y >> t;
      G[x].push_back(Edge(y,t));
      G[y].push_back(Edge(x,t));
    }

    dijkstra();
    int res = INF;
    rep(i, M+1)  res = min(res, dist[i][H]);
    if(res==INF) cout << "Help!\n";
    else cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 1588
#define N 100000
#include <stdio.h>
#include <math.h>
int isprime(int);

int main(){
  int a[N],n,c = 0,i,b;
  scanf("%d",&n);
  
  for(i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
  


  for(i = 0; i < n; i++){
    b = isprime(a[i]);
    if( b == 1 ){
      c++;
    }
  }
  printf("%d\n",c);

  return 0;
}

int isprime(x){
  int i;
  if(x == 2) return 1;

  if(x < 2 || x % 2 == 0) return 0;

  i = 3;
  while(i <= sqrt(x)){
    if(x % i == 0){
      return 0;
    }
    i = i + 2;
  }

  return 1;
}

Measured memory_bytes: 636
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(){
        int a,b,c,d;
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if(abs(a-c)<=d || (abs(a-b)<=d && abs(b-c)<=d)) printf("Yes\n");
        else printf("No\n");
        return 0;
}


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

long long m, k;
vector<long long> ans;

void solve();

int main() {
  cin >> m >> k;
  solve();
  if(ans.size() != 2 * (1 << m))
    cout << -1 << endl;
  else {
    for(long long i = 0; i < ans.size(); ++i) {
      if(i != 0) cout << " ";
      cout << ans[i];
    }
    cout << endl;
  }
  return 0;
}

void solve() {
  if(k == m && k == 1) return;
  if(k >= (1LL << m)) return;
  if(m == 1) {
    ans.push_back(0);
    ans.push_back(0);
    ans.push_back(1);
    ans.push_back(1);
    return;
  }
  for(long long i = 0; i < (1LL << m); ++i)
    if(i != k) ans.push_back(i);
  ans.push_back(k);
  for(long long i = (1LL << m) - 1; i >= 0; --i)
    if(i != k) ans.push_back(i);
  ans.push_back(k);
}


Measured memory_bytes: 3952
using System;

namespace ABC_121_B
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			string[] input = Console.ReadLine().Split();
			int n = int.Parse(input[0]);
			int m = int.Parse(input[1]);
			int c = int.Parse(input[2]);

			input = Console.ReadLine().Split();
			int[] bArr = new int[m];
			for (int i = 0; i < m; i++)
				bArr[i] = int.Parse(input[i]);

			int ans = 0;
			for (int i = 0; i < n; i++)
			{
				long sum = 0;
				input = Console.ReadLine().Split();
				for (int j = 0; j < m; j++)
					sum += int.Parse(input[j]) * bArr[j];

				if (sum > -c) ans++;
			}
			
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 11092
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int Y = sc.nextInt();
		loop:for( int i=0; i<=N; i++ ){
			for( int j=0; j<=N; j++ ){
				if( i+j<=N ){
					if( i*10000 + j*5000 + (N-i-j)*1000 == Y ){
						System.out.println(i+" "+j+" "+(N-i-j));
						break loop;
					}
				}
			}
			if( i==N ){
				System.out.println(-1+" "+(-1)+" "+(-1));
			}
		}
	}
}


Measured memory_bytes: 23636
#include <stdio.h>

int main() {
  int a, b;
  scanf("%d %d" , &a,&b);
  if(a < b) {
    printf("a < b\n");
  } else if (a > b) {
    printf("a > b\n");
  }  else  {
    printf("a == b\n");
  }

return 0;
}

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

int main(){
  int n,q,l,r;cin>>n>>q;
  string s; cin>>s;
  
  int fac[n],bac[n];
  

  fac[0]=0;
  for(int i=1;i<n;i++){
    if(s[i-1]=='A'&&s[i]=='C')fac[i]=fac[i-1]+1;
    else fac[i]=fac[i-1];
  }
  bac[n-1]=0;
    for(int i=n-2;i>=0;i--){
    if(s[i]=='A'&&s[i+1]=='C')bac[i]=bac[i+1]+1;
    else bac[i]=bac[i+1];
  }

  rep(i,q){
    cin>>l>>r;
    cout<<fac[n-1]-(l>1?fac[l-1]:0)-(r<n?bac[r-1]:0)<<endl;
  
  }
}

Measured memory_bytes: 4552
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Integer[] A = new Integer[N];
        
        for(int i = 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        
        Arrays.sort(A, Collections.reverseOrder());
        
        int alice = 0;
        int bob = 0;
        for(int i = 0; i < N; i++){
            if(i % 2 == 0){
                alice += A[i];
            }else{
                bob += A[i];
            }
        }
        
        System.out.println(alice - bob);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n - 1; i++){
		if(a[i] >= a[i + 1]) continue;
		if(abs(a[i] - a[i + 1]) > 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	
	if(a[0]) {
		cout << -1 << endl;
		return 0;
	}
	
	long ans = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] + 1 == a[i + 1]) {
			ans++;
		}else if(a[i] >= a[i + 1]) {
			ans += a[i + 1];
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int N;
    cin>>N;
    long long V[N];

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

    long long a=0;
    long long t=0;
    for(int i=0;i<N;i++){
        if(a<=V[i])
            a=V[i];
        else{
            int b=a-V[i];
            t=t+b;
            V[i]=V[i]+a;
            //a=V[i];
        }
    }
    cout<<t<<endl;
}


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

const int infinity = 1234567890;

using namespace std;
#define ll long long
int main() {
	ll n;
	cin>>n;
	ll a[n+1],i;
	for(i=0;i<n;i++)
        cin>>a[i];
    ll dp[n+1];
    dp[0]=0;
    dp[0]=0;
    dp[1]=abs(a[1]-a[0]);
    for(i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1]<<endl;

}


Measured memory_bytes: 1792
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    vector<ll> v(10000,1e9);
    v[0] = 0;
    FOR(i,0,m){
      ll a,b;
      cin>>a>>b;
      ll x=0;
      FOR(j,0,b){
        ll in;
        cin>>in;
        x = x|(1<<(in-1));
      }
      FOR(j,0,(1<<n)){
        v[j|x] = min(v[j|x], v[j] + a);
      }
    }

    if(v[(1<<n)-1] == 1e9)cout<<-1<<endl;
    else cout<<v[(1<<n)-1]<<endl;

}


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

int main()
{
    ll n, k;
    cin >> n >> k;
    ll a[n];
    rep(i, 0, n)
    {
        cin >> a[i];
        //cout << a[i] << endl;
    }
    sort(a, a + n);
    vector<ll> minus, zeros, plus;
    rep(i, 0, n)
    {
        if (a[i] < 0)
            minus.push_back(a[i]);
        else if (a[i] > 0)
            plus.push_back(a[i]);
        else
            zeros.push_back(a[i]);
    }
    ll minus_num = plus.size() * minus.size();
    ll zeros_num = (zeros.size() * (zeros.size() - 1)) / 2 + zeros.size() * plus.size() + zeros.size() * minus.size();

    if (k <= minus_num)
    {
        ll lo = -1e18, hi = -1;
        while (lo <= hi)
        {
            ll mid = lo + (hi - lo) / 2;
            ll sum = 0;
            rep(i, 0, plus.size())
            {
                ll d = (mid - plus[i] + 1) / plus[i];
                sum += upper_bound(minus.begin(), minus.end(), d) - minus.begin();
            }

            if (sum >= k)
                hi = mid - 1;
            else
                lo = mid + 1;

            //printf("%d %d %d %d\n", mid, sum, lo, hi);
        }
        cout << lo << endl;
    }
    else if (k > minus_num && k <= minus_num + zeros_num)
    {
        cout << 0 << endl;
    }
    else
    {
        ll lo = 1, hi = 1e18;
        while (lo <= hi)
        {
            ll mid = lo + (hi - lo) / 2;
            ll sum = 0;
            rep(i, 0, minus.size())
            {
                ll d = mid / minus[i] - 1;
                sum += minus.end() - upper_bound(minus.begin(), minus.end(), d);
                if (d <= minus[i])
                    sum--;
            }
            rep(i, 0, plus.size())
            {
                ll d = mid / plus[i];
                sum += upper_bound(plus.begin(), plus.end(), d) - plus.begin();
                if (d >= plus[i])
                    sum--;
            }
            sum /= 2;
            if (sum + minus_num + zeros_num >= k)
                hi = mid - 1;
            else
                lo = mid + 1;

            //printf("%d %d %d %d\n", mid, sum, lo, hi);
        }
        cout << lo << endl;
    }

    return 0;
}

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

int main(void){
    string s, t;
    int ans = 0;
    cin >> s >> t;
    for (int i = 0; s[i] !='\0'; i++){
        if(s[i]!=t[i])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3844
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    S=list(input())
    S=list(map(int,S))[::-1]
    ans=[]
    now=0
    while(now<n):
        next=now
        for i in range(1,m+1):
            if(now+i==n):
                next=n
                break
            if(S[now+i]==0): next=now+i
        if(now==next):
            print(-1)
            return
        ans.append(next-now)
        now=next
    ans=ans[::-1]
    print(*ans)
resolve()

Measured memory_bytes: 57976
def count_inversion(sequence):
    count = 0
    for i in range(1,len(sequence)):
        for j in range(i,len(sequence)):
            if sequence[i-1] > sequence[j]:
                count += 1
    else:
        count = count%MAX
    return count%MAX

def count_bigger(sequence):
    count = 0
    for num1 in sequence:
        for num2 in sequence:
            if num1 < num2:
                count += 1
    else:
        count = count%MAX
    return count%MAX

MAX = 10**9 +7
N, K = map(int,input().split())
A = list(map(int,input().split()))
ans = (count_bigger(A))%MAX

ans *= (K*(K-1)//2)%MAX
ans += ((K%MAX)*count_inversion(A))%MAX
print(int(ans%MAX))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,ans=0,a;cin>>n;
  rep(i,n) {
    cin>>a;
    if(i%2==0&&a%2==1) ans++;
  }
  print(ans);
  return 0;
}

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

using namespace std;
using ll = long long;


ll rec(ll x){
  if(x==1) return 1;
  
  return rec(x/2)*2 +1;
}

int main(){
  ll h;
  cin >> h;

  cout << rec(h)<< endl;  
  
  return 0;
}

Measured memory_bytes: 3532
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here
        Scanner sc = new Scanner(System.in);

        String splitted = new String();
        splitted = sc.next();
        splitted = sc.next();
        Character initial = splitted.toUpperCase().charAt(0);
        System.out.print("A"+initial+"C");
    }
}


Measured memory_bytes: 9676
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<iterator>
#include<queue>

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

class Graph{
    public:
    typedef struct Edge{
        ll from, to, cost;
        Edge(ll f, ll t, ll c): from(f),to(t),cost(c){}
    } Edge;

    bool isDirected;
    ll INF = 1LL << 62;
    ll v; // 頂点数
    std::vector<Edge> edges;  // 辺のリスト
    std::vector<std::vector<std::pair<ll,ll>>> list;  // 隣接リスト
    //std::vector<std::vector<ll>> matrix; // 隣接行列

    Graph(ll n, bool isDirected=false) : isDirected(isDirected) { init(n); }
    void init(ll n){
        v=n;
        edges.clear();
        list.assign(n, std::vector<std::pair<ll,ll>>());
        //matrix.assign(n, std::vector<ll>(n, INF));
    }
    void connect(ll from, ll to){
        con(from, to, 1);
        if(!isDirected) con(to, from, 1);
    }
    void connect(ll from, ll to, ll cost){
        con(from, to, cost);
        if(!isDirected) con(to, from, cost);
    }
    void con(ll from, ll to, ll cost){
        edges.push_back(Edge(from,to,cost));
        list[from].push_back(std::make_pair(to, cost));
        //matrix[from][to] = cost;
    }
};

class lowlink{
    public:
    Graph G; // 無向グラフ
    std::vector<ll> used, ord, low;
    std::vector<ll> articulation; // 連結点
    std::vector<Graph::Edge> bridge; // 橋

    lowlink(Graph G) : G(G){
        used.assign(G.v, 0);
        ord.assign(G.v, 0);
        low.assign(G.v, 0);
    }

    ll dfs(ll idx, ll k, ll parent){
        used[idx] = true;
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool isArticulation = false;
        int child_num = 0;
        for(auto to : G.list[idx]){
            if(!used[to.first]){
                child_num++;
                k = dfs(to.first, k, idx);
                low[idx] = min(low[idx], low[to.first]);
                isArticulation |= (parent != -1 && low[to.first] >= ord[idx]);
                if(ord[idx] < low[to.first]){
                    if(idx < to.first)bridge.push_back(Graph::Edge(idx, to.first, to.second));
                    else bridge.push_back(Graph::Edge(to.first, idx, to.second));
                }
            }
            else if(to.first != parent){
                low[idx] = std::min(low[idx], ord[to.first]);
            }
        }
        isArticulation |= (parent==-1 && child_num>1);
        if(isArticulation) articulation.push_back(idx);
        return k;
    }
    void build(){
        ll k=0;
        for(ll i=0; i<G.v; i++){
            if(!used[i]) k = dfs(i, k, -1);
        }
        std::sort(articulation.begin(), articulation.end());
        std::sort(bridge.begin(), bridge.end(), [](Graph::Edge a, Graph::Edge b){return (a.from==b.from) ? a.to<b.to : a.from<b.from;});
    }
};

int main(){
    ll v,e,s,t;
    cin >> v >> e;
    Graph G(v);
    REP(i,e){
        cin >> s >> t;
        G.connect(s,t);
    }
    lowlink low(G);
    low.build();
    for(auto i : low.bridge){
        cout << i.from << " " << i.to << endl;
    }
}


Measured memory_bytes: 16180
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string s;
    cin >> s;
    
    int l;
    l = s.length();
    multiset<char> alphabet;
    for(int i=0;i<l;i++)
        alphabet.insert(s[i]);

    char tmp;
    for(int i=0;i<26;i++){
        tmp = 'a' + i;
        // cout << tmp << " : " << alphabet.count(tmp) << endl;
        if(alphabet.count(tmp)%2 != 0){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    int ans = n;

    for(int i=0; i<n-1; i++){
        if(s[i]!=s[i+1]){
            ans = min(ans, max(i+1, n-i-1));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
using namespace std;
using ll = long long;
ll b[2000][2000];
int main(){
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> a(n);
    rep(i,0,n)cin >> a[i];
    //b[i][k]=k回魔法を唱えてスライムiを手に入れるための最小の時間-k*x
    //       =min(a_i, ..., a_{i-k})
    //       =min(b[i][k-1],a_{i-k})
    rep(i,0,n){
        b[i][0]=a[i];
        rep(k,1,n)b[i][k]=min(b[i][k-1],a[(i-k+n)%n]);
    }
    ll ans=1e15;
    rep(k,0,n){
        ll tmp=k*x;
        rep(i,0,n)tmp+=b[i][k];
        ans=min(ans,tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31488
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int n, k;
	cin >> n >> k;
	if(k > ((n - 1) * (n - 2)) / 2){
		cout << -1 << endl;
		return 0;
	}
	int m = n * (n - 1) / 2 - k;
	cout << m << endl;
	for(int i = 1; i <= n; i++){
		for(int j = i + 1; j <= n; j++){
			cout << i << " " << j << endl;
			m--;
			if(m == 0){
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define Q int q; cin >> q; while (q--)
#define endl '\n'
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;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    multimap<string, int> m;
    Q {
        int c;
        string k;
        cin >> c >> k;
        if (c == 0) {
            int y;
            cin >> y;
            m.emplace(k, y);
        } else if (c == 1) {
            auto range = m.equal_range(k);
            for (auto itr = range.first; itr != range.second; itr++) cout << (*itr).second << endl;
        } else if (c == 2) {
            m.erase(k);
        } else if (c == 3) {
            string y;
            cin >> y;
            auto st = m.lower_bound(k);
            auto ed = m.upper_bound(y);
            for (;st != ed; st++) cout << (*st).first << " " << (*st).second << endl;
        }
    }
}



Measured memory_bytes: 24844
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,C;
  cin >> A >> B >> C;
  if (B >= C){
  cout << "delicious";
  }else if (A >= C- B){
  cout << "safe";
  }else{
  cout << "dangerous";
  }
}


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

const int maxn = 1750000, P = 998244353;
int n, m, fact[maxn], inv[maxn];

int qp(int x, int y) {
    int z = 1;
    for (; y; y >>= 1, x = 1LL * x * x % P) {
        if (y & 1) z = 1LL * z * x % P;
    }
    return z;
}

int C(int x, int y) {
    return 1LL * fact[x] * inv[x - y] % P * inv[y] % P;
}

int S(int s) {
    int ans = 0;
    for (int i = s & 1; i <= min({n, m, s}); i += 2) {
        ans = (ans + 1LL * C(n, i) * C((s - i) / 2 + n - 1, n - 1)) % P;
    }
    return ans;
}

int main() {
    for (int i = fact[0] = inv[0] = 1; i < maxn; i++) {
        inv[i] = qp(fact[i] = 1LL * i * fact[i - 1] % P, P - 2);
    }
    scanf("%d %d", &n, &m);
    printf("%d\n", (S(3 * m) - 1LL * n * S(m - 1) % P + P) % P);
    return 0;
}

Measured memory_bytes: 13952
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,k,b;
    cin>>a>>k;
    int bar[a],haight[a];
    bar[0]=0;
    for(int i=0;i<a;i++)
    cin>>haight[i];
     bar[1]=abs(haight[0]-haight[1]);
    for(int i=0;i<a;i++){
        if(i==0)
        continue;
        if(i==1)
        continue;   
        else if(i<k){
        b=abs(haight[i]-haight[i-1])+bar[i-1];
        for(int j=0;j<i;j++){
            int c=abs(haight[i]-haight[i-1-j])+bar[i-1-j];
            if(b>c)
            b=c;
        }
        }
        else{
            b=abs(haight[i]-haight[i-1])+bar[i-1];
            for(int j=0;j<k;j++){
            int c=abs(haight[i]-haight[i-1-j])+bar[i-1-j];
            if(b>c)
            b=c;
            }
        }
        bar[i]=b;
        
    }
    cout<<bar[a-1]<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath> 
using namespace std;
string s[110],ans[110];
bool hang[110],lie[110];
int main()
{
	memset(hang,1,sizeof(hang));
    memset(lie,1,sizeof(lie));
    int h,w,i,j;
    cin >> h >> w;
    for (i = 0;i < h;i++) 
		cin >> s[i];

    for (i = 0;i < h;i++)
    {
        bool all = 1;
        for (j = 0;j < w;j++)
        {
            if (s[i][j] == '#') 
			{
				all = 0;
				break;
			}
		}
        if (all) 
			hang[i] = 0;
    }
    for (i = 0;i < w;i++)
    {
        bool all = 1;
        for (j = 0;j < h;j++)
    	{
            if (s[j][i] == '#') 
			{
				all = 0;
				break;
			}
    	}
		if (all) 
			lie[i]=0;
    }
    for (i = 0;i < h;i++)
    {
        bool out = 0;
        for (j = 0;j < w;j++)
    	{
            if ((hang[i]) && (lie[j])) 
			{
				cout << s[i][j];
				out = 1;
			}
    	}
		if (out) 
			puts("");
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 200005
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
        if(c == '-') f = -1;
        c = getchar();
    }
    while(c >= '0' && c <= '9') {
        res = res * 10 +c - '0';
        c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
        out(x / 10);
    }
    putchar('0' + x % 10);
}
int H,W,N;
int sr,sc;
char s[MAXN],t[MAXN];
int suf[MAXN];
bool Process(char a,char b,int dis,int lim) {
    suf[N + 1] = 0;int sum = 0;
    for(int i = N ; i >= 1 ; --i) {
        suf[i] = suf[i + 1];
        if(s[i] == b) {
            suf[i] = min(suf[i],sum - 1);
            --sum;
        }
        if(t[i] == a) {
            if(sum < 0) ++sum;
        }
    }
    int pos = dis;
    for(int i = 1 ; i <= N ; ++i) {
        if(s[i] == a) ++pos;
        if(pos > lim) return false;
        if(t[i] == b) {
            if(pos - 1 + suf[i + 1] >= 1) --pos;
        }
    }
    return true;
}
void Solve() {
    read(H);read(W);read(N);
    read(sr);read(sc);
    scanf("%s",s + 1);scanf("%s",t + 1);
    if(!Process('D','U',sr,H) || !Process('U','D',H + 1 - sr,H) ||
    !Process('R','L',sc,W) || !Process('L','R',W + 1 - sc,W)) {
        puts("NO");
    }
    else puts("YES");
}
int main() {
    Solve();
}

Measured memory_bytes: 1408
#DP-C

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

dp=[[0]*3 for i in range(n)]
dp[0]=l[0]
#print(dp)

for i in range(1,n):
    for j in range(3):
        for k in range(3):
            #同じ活動の場合を除く
            if j!=k:
                dp[i][j]=max(dp[i-1][k]+l[i][j],dp[i][j])
print(max(dp[-1]))

Measured memory_bytes: 74968
N = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))

P.sort()
a,b,c=0,0,0
for i in range(len(P)):
    if P[i]<=A:
        a +=1
#        b+=1
#        c+=1
    elif P[i]<=B:
        b+=1
#        c+=1
    else:
        c+=1
print(min(a,b,c))

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

int main()
{
  long long n;
  cin >> n;
  vector<long long> a(n + 1), b(n + 1);
  long long ans = 0;
  for (int i = 0; i < n + 1; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++)
  {
    cin >> b[i];
  }
  
  for (int i = 0; i < n; i++)
  {
    if (a[i] >= b[i])
    {
      ans += b[i];
    }
    else if (a[i + 1] > b[i] - a[i])
    {
      ans += b[i];
      a[i + 1] -= b[i] - a[i];
    }
    else if (a[i + 1] <= b[i] - a[i])
    {
      ans += a[i] + a[i + 1];
      a[i + 1] = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rrep(i,1,10){
        rrep(j,1,10){
            if(i*j==n){
                Cout("Yes");
                return 0;
            }
        }
    }
    Cout("No");
    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();
		if (s.charAt(0) == s.charAt(1) && s.charAt(1) == s.charAt(2)) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 21712
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

def lcm(a,b):
    return a*b // gcd(a,b)

a,b,c,d = map(int,input().split())
a -= 1
A = a-((a//c) + (a//d) - a//lcm(c,d))
B = b-((b//c) + (b//d) - b//lcm(c,d))
print(B-A)

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

long long int K, L, M;

int main(){
    scanf("%lld", &K);
    L = K / 50;
    M = K % 50;
    cout << 50 << endl;
    for(int i = 0; i < 50; ++i){
        cout << (50 - M + ((i < M) ? 50 : -1) + L) << " ";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
using namespace std;
typedef long long ll;
#define PI 3.14159265358979323846  


int main() {
	double a ;
	cin >> a;
	a = a / 3;
	a = a * a*a;
	printf("%.12lf", a);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int n;
	while(scanf("%d",&n),n)
	{
		int m = 0;
		n = 1000 - n;
		
		m += n / 500;
		n %= 500;
		m += n / 100;
		n %= 100;
		m += n / 50;
		n %= 50;
		m += n / 10;
		n %= 10;
		m += n / 5;
		n %= 5;
		m += n;
		printf("%d\n",m);
	}
	return 0;
}

Measured memory_bytes: 0
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 600 + 10 ;
int n , m ;
string s[N] ;

vector <int> v1[N] , v2[N] ;
int p1[N][N] , p2[N][N] ;

ll ans ;

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

	cin >> n >> m ;

	for (int i = 0 ; i < n ; i ++) {
		cin >> s[i] ;

		for (int j = 0 ; j < m ; j ++) {
			if (s[i][j] == '#') {
				v1[i + j].push_back(i - j + m) ;
				p1[i + j][i - j + m + 1] ++ ;

				v2[i - j + m].push_back(i + j) ;
				p2[i - j + m][i + j + 1] ++ ;
			}
		}
	}

	for (int i = 0 ; i < N ; i ++) {
		sort(v1[i].begin() , v1[i].end()) ;
		sort(v2[i].begin() , v2[i].end()) ;

		for (int j = 1 ; j < N ; j ++) {
			p1[i][j] += p1[i][j - 1] ;
			p2[i][j] += p2[i][j - 1] ;
		}
	}

	for (int i = 0 ; i < N ; i ++) {

		for (int a = 0 ; a < _sz(v1[i]) ; a ++) {
			for (int b = a + 1 ; b < _sz(v1[i]) ; b ++) {
				int A = v1[i][a] , B = v1[i][b] ;
				int d = B - A ;

				if (i + d < N) ans += p1[i + d][B] - p1[i + d][A + 1] ;
				if (i - d >= 0) ans += p1[i - d][B] - p1[i - d][A + 1] ;
			}
		}

		for (int a = 0 ; a < _sz(v2[i]) ; a ++) {
			for (int b = a + 1 ; b < _sz(v2[i]) ; b ++) {
				int A = v2[i][a] , B = v2[i][b] ;
				int d = B - A ;

				if (i + d < N) ans += p2[i + d][B + 1] - p2[i + d][A] ;
				if (i - d >= 0) ans += p2[i - d][B + 1] - p2[i - d][A] ;
			}
		}
	}

	cout << ans << '\n' ;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
int main()
{
    int n ,i ,ans=999999999 ,cnt ,j;
    scanf("%d",&n);
    char a[n];
    int b[n],c[n];
    scanf("%s",a);
    b[0] = 0;
    for(i = 1; i < n; i++)
    {
        if(a[i-1] == 'W')
            b[i] = b[i-1]+1;
        else b[i] = b[i-1];
    }
    c[n-1] = 0;
    for(i = n-2; i >= 0; i--)
    {
        if(a[i+1] == 'E')
            c[i] = c[i+1]+1;
        else c[i] = c[i+1];
    }
    for(i = 0; i < n; i++)
        if(b[i]+c[i] < ans)
            ans = b[i]+c[i];
    printf("%d",ans);
    return 0;
}


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

ll arr[3001];
ll dp[3001][3001];

ll solve(int start,int end){
    if(start>end){
        return 0;
    }
    if(dp[start][end]!=-1){
        return dp[start][end];
    }
    ll part1=arr[start]+ min(solve(start+2,end),solve(start+1,end-1));
    ll part2= arr[end]+min(solve(start,end-2),solve(start+1,end-1));
    ll ans=max(part1,part2);
    dp[start][end]=ans;
    return ans;
}


int main(){
    int N;
    ll sum=0;
    cin>>N;
    memset(dp,-1,sizeof(dp));
    for(int i=0;i<N;i++){
        cin>>arr[i];
        sum+=arr[i];
    }
    ll final_ans=solve(0,N-1);
    ll final_diff=2*final_ans-sum;
    cout<<final_diff;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  char graph[128];
  while(scanf("%d",&N),N){
    for(int i = 0;i < 128;i++)graph[i] = i;
    char a,b;
    for(int i = 0;i < N;i++){
      scanf(" %c %c",&a,&b);
      graph[a] = b;
    }
    cin >> M;
    for(int i = 0;i < M;i++){
      scanf(" %c",&a);
      cout << graph[a];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
/**************************************
*Coded By: BadduCoder (Sumit Badsara) *
***************************************/
#include<bits/stdc++.h>
using namespace std;

//All the Loops and defines required
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define ff first
#define ss second
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0); cout.tie(0);
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007

//All the declarations using typedef

typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef map<int,int> MII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int l;

void BFS(int s, vector <ll> adj[], vector <ll> &dist, map <ll,ll> &deg, vector <bool> &vis)
{
    queue <ll> que;
    que.push(s);
    while(!que.empty())
    {
        ll top = que.front(), cur_dist;
        cur_dist = dist[top];
        que.pop();
        vis[top] = true;
        // cout<<"BFS FOR "<<top<<":\n";

        REP(i,adj[top].size())
        {
            deg[adj[top].at(i)]--;
            if(deg[adj[top].at(i)]==0)
                    que.push(adj[top].at(i));
            dist[adj[top].at(i)] = max(dist[adj[top].at(i)],cur_dist + 1);
        }
    }
}

int main()
{
    _cin;
    ll n,e,x,y;
    cin>>n>>e;
    vector <ll> dist(n,0),adj[n];
    vector <bool> vis(n,false);
    map <ll,ll> in_deg;

    REP(i,e)
    {
        cin>>x>>y;
        x--;y--;
        in_deg[y]++; //first in in_degree
        adj[x].PB(y);
    }

    REP(i,n)
    {
        if(!vis[i] && in_deg[i]==0)
            BFS(i,adj,dist,in_deg,vis);
    }

    ll ans = 0;
    REP(i,n)
        if(dist[i]!=INF)
            ans = max(ans,dist[i]);

    cout<<ans;
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>

using namespace std;

int main(){
    int K,sum=0,count=1;
    cin>>K;

        if(K%2==0||K%5==0){
            cout<<"-1";
        }else{
            while(1){
                sum=(7+sum*10)%K;
                    if(sum%K==0){
                        cout<<count;
                        break;
                    }
                count++;
            }
        }

}


Measured memory_bytes: 3192
a,b,m = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = min(A) + min(B)

for _ in range(m):
    x, y, c = map(int, input().split())
    ans = min(ans, A[x-1] + B[y-1] - c)
print(ans)

Measured memory_bytes: 18736
n,m=map(int,input().split())
lmax=0
rmin=float('inf')
for i in range(m):
    l,r=map(int,input().split())
    lmax=max(lmax,l)
    rmin=min(rmin,r)

print(0 if rmin-lmax+1<=0 else rmin-lmax+1)

Measured memory_bytes: 3060
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

public class Main {
	
	private static int count = 0;
	private static Map<Integer, Set<Integer>> pass;
	private static Set<Integer> visited = new HashSet<Integer>();
	private static int n;
	
	public static void main(String[] args) {
		java.util.Scanner scanner = new java.util.Scanner(System.in);
		n = scanner.nextInt();
		int m = scanner.nextInt();
		int[][] ab = new int[m + 1][2];
		for (int i = 1; i <= m; i++) {
			ab[i] = new int[]{scanner.nextInt(), scanner.nextInt()};
		}
		pass = new HashMap<Integer, Set<Integer>>();
		for (int i = 1; i <= m; i++) {
			for (int j = 1; j <= n; j++) {
				if (ab[i][0] == j) {
					Set<Integer> set = pass.get(j);
					if (set == null) {
						set = new TreeSet<Integer>();
						pass.put(j, set);
					}
					set.add(ab[i][1]);
				} else if (ab[i][1] == j) {
					Set<Integer> set = pass.get(j);
					if (set == null) {
						set = new TreeSet<Integer>();
						pass.put(j, set);
					}
					set.add(ab[i][0]);
				}
			}
		}
		visited.add(1);
		next(1);
		System.out.println(count);
	}

	private static void next(int current) {
		if (allVisited()) {
			count++;
			return;
		}
		
		for (Integer end : pass.get(current)) {
			if (!visited.contains(end)) {
				visited.add(end);
				next(end);
				visited.remove(end);	// 1つ戻る
			}
		}
	}
	
	private static boolean allVisited() {
		return visited.size() == n;
	}
}


Measured memory_bytes: 21844
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
//typedef pair<ll, ll> P;
//typedef pair<ll, pair<ll, ll>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
ll INFL = 1LL << 60;//10^18 = 2^60
int INF = 1 << 30;//10^9
ll MOD = 1e9 + 7;
//ll MOD  = 998244353;
vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD; x += MOD; x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}
ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll x, ll y){return x / gcd(x, y) * y % MOD;};


int main(){
  ll N, K; cin >> N >> K;
  vector<ll> A(N); rep(i, N) cin >> A[i];

  vector<ll> sum(N+1), sumplus(N+1);
  sum[0] = 0;
  rep(i, N) sum[i+1] = sum[i] + A[i];
  sumplus[0] = 0;
  rep(i, N) sumplus[i+1] = sumplus[i] + max(0, A[i]);
  ll ans = 0;
  rep(i, N-K+1){
    ll res = 0;
    res += sumplus[i];
    res += sumplus[N] - sumplus[i+K];
    ans = max(ans, res);
    res += sum[i+K] - sum[i];
    ans = max(ans, res);
  }
  cout << ans << endl;





}


Measured memory_bytes: 2560
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;

int a[1000010];
int b[1000010];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {cin>>a[i];
    b[a[i]]++;}
    int sum=0;
    int x=0;
    if(n==1)
    cout<<1;
    else
    {
        for(int i=1;i<1000010;i++)
        {x=b[i]+b[i-1]+b[i+1];
        if(x>sum)
        sum=x;} 
        cout<<sum;
    }
   
    return 0;
}    

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

int main() {
    int n;
    cin >> n;
    long a[110000];
    bool u;
    bool d;
    int c = 1;
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n - 1; i++)
    {   
        if(a[i] < a[i+1]) u = true;
        if(a[i] > a[i+1]) d = true;
        if(u && d){
            u = d = false;
            c++;
        }       
    }
    cout << c << endl; 
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;

const string yey = "Yay!";
const string sad = ":(";

void solve() {
	int n, k; cin >> n >> k;
	if (k == 1)cout << 0 << endl;
	else cout << n - k << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(9);
	//init();
	//while (cin >> n>>m>>l,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int W, H, N;
    cin >> W >> H >> N;
    int point[N][3];
    for (int i = 0; i < N; i++){
        for (int j = 0; j < 3; j++) {
            cin >> point[i][j];
        }
    }

    int dl[2] = {0, 0};
    int ur[2] = {W, H};

    for (int i = 0; i < N; i++) {
        switch (point[i][2]) {
            case 1:
                dl[0] = max(dl[0],point[i][0]);
                break;
            case 2:
                ur[0] = min(ur[0],point[i][0]);
                break;
            case 3:
                dl[1] = max(dl[1], point[i][1]);
                break;
            case 4:
                ur[1] = min(ur[1], point[i][1]);
                break;
        }
    }

    if (ur[1] < dl[1] || ur[0] < dl[0]) {
        cout << 0 << endl;
    } else {
        cout << (ur[1] - dl[1]) * (ur[0] - dl[0]);
    }
    return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
int dp[3010][3010];

int main(){
  string s,t;
  cin >> s >> t;
  int s_l=s.length()+1, t_l=t.length()+1;
  rep(i,s_l){
    rep(j,t_l){
      dp[i][j]=0;
    }
  }
  for(int i=1;i<s_l;i++){
    for(int j=1;j<t_l;j++){
      dp[i][j]=max(dp[i][j],dp[i-1][j]);
      dp[i][j]=max(dp[i][j],dp[i][j-1]);
      if(s[i-1]==t[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
    }
  }
  /*rep(i,s_l){
    rep(j,t_l){
      cout << dp[i][j];
    }
    cout << endl;
  }*/
  string ans="";
  int x=s_l-1,y=t_l-1;
  while(dp[x][y]!=0){
    if(dp[x][y]==dp[x][y-1]) y--;
    else if(dp[x][y]==dp[x-1][y]) x--;
    else{
      ans = s[x-1]+ans;
      x--;y--;
    }
  }
  cout << ans;
}

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

const long long INF = 1e18;
const long long MAX = 200000;
long long val[MAX];
vector<pair<long long, long long>> edges[MAX];
long long rmin, cmin;
long long R, C, N;

bool dfs(long long i, long long prev){
    for(auto p : edges[i]){
        long long j = p.first, a = p.second;
        if(j == prev) continue;
        if(val[j] == INF){
            val[j] = a - val[i];
            if(j<R){
                rmin = min(rmin, val[j]);
            }else{
                cmin = min(cmin, val[j]);
            }
            bool result = dfs(j, i);
            if(!result) return false;
        }else{
            if(val[i] + val[j] != a){
                return false;
            }
        }
    }
    return true;
}

int main(){
    long long i, j, k;
    cin >> R >> C >> N;
    for(i=0; i<N; i++){
        long long r, c, a;
        cin >> r >> c >> a;
        r--; c--;
        edges[r].push_back({c+R, a});
        edges[c+R].push_back({r, a});
    }
    for(i=0; i<R+C; i++) val[i] = INF;
    for(i=0; i<R; i++){
        if(val[i] == INF){
            val[i] = 0;
            rmin = 0;
            cmin = INF;
            bool result = dfs(i, -1);
            if(!result || rmin + cmin < 0){
                cout << "No" << endl;
                return 0;
            }
       }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 16384
#include<stdio.h>

int main()
{
	int s;
	int h,m,sec;
	scanf("%d",&s);
	h=s/3600;
	m=(s-h*3600)/60;
	sec=s-h*3600-m*60;
	printf("%d:%d:%d\n",h,m,sec);
	return 0;
} 


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

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  int count = 0;
  for(int i = 0;i <= 100;i++){
    if(i > A && i <= B && i > C && i <= D){
      count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256