akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    long long int n;
    scanf("%lld", &n);
    long long int ar[n+10], i, j, sum = 0, a, b, c, sumi;
    ar [0] = 0;
    ar[n+1] = 0;
    for (i=1; i<=n; i++)
    {
        scanf("%lld", &ar[i]);
        sum = sum + abs(ar[i] - ar[i - 1]);
    }
    sum = sum + abs(ar[n]);
//    printf("%lld   sum\n", sum);
    sumi = sum;
    for (i=1; i<=n; i++)
    {
        sum = sumi;
        if (ar[i-1] < ar[i] )
        {
            if(ar[i] < ar[i+1] || ar[i] == ar[i+1])
                printf("%lld\n", sum);
            if (ar[i] > ar[i+1])
            {
                if (ar[i+1] < ar[i-1])
                    printf("%lld\n", sum - (2 * abs(ar[i] - ar[i-1])));
                else if(ar[i+1] >= ar[i-1])
                    printf("%lld\n", sum - (2 * abs(ar[i] - ar[i+1])));
            }
        }
        else if (ar[i-1] > ar[i] )
        {
            if(ar[i] > ar[i+1] || ar[i] == ar[i+1])
                printf("%lld\n", sum);
            else if(ar[i] < ar[i+1])
            {
                if(ar[i+1] > ar[i-1])
                    printf("%lld\n", sum - (2 * abs(ar[i] - ar[i-1])));
                else if(ar[i+1] <= ar[i-1])
                    printf("%lld\n", sum - (2 * abs(ar[i] - ar[i+1])));

            }
        }
        else if (ar[i-1] == ar[i])
        {
            printf("%lld\n", sum);
        }

    }
    return 0;
}


Measured memory_bytes: 1920
program Hello;
var    
   x,y,k,N,hasil:longint;
begin
    readln(N);
	x:=800*N;
	if (N>=15) then
	begin
	    k:= N div 15;
	    y:= 200*k;
	end
	else
	begin
	    y:= 0;
	end;
	hasil:=x-y;
	writeln(hasil)
end.


Measured memory_bytes: 128
#include<iostream>
#include <iomanip> // setprecisionを使用するのに必要
int main(){
    long long int a,b;
    std::cin>>a>>b;
    long double c;
    c=a;
  	c=c/b;
    std::cout<<a/b<<" "<<a%b<<" "<<std::fixed<<std::setprecision(11)<<c<<std::endl;
    return 0;
}


Measured memory_bytes: 3256
#include<iostream>
using namespace std;
int main(){
    int a,b,k[10001];
    cin>>a>>b;
    for(int i=0;i<b;i++){
        cin>>k[i];
    }
    if(b==1){
        cout<<k[0]-1<<endl;
        return 0;
    }else{
        int ans=0;
        for(int i=0;i<b;i++){
            for(int j=0;j<b;j++){
                ans+=k[j];
            }
            ans-=k[i];
            if(ans<k[i]){
                cout<<k[i]-ans-1<<endl;
                return 0;
            }else{
            	ans=0;
			}
        }
    }
    cout<<0<<endl;
    //YEHHHHHH!
    return 0;
}

Measured memory_bytes: 256
use std::io::stdin;
use std::str::FromStr;
use std::f32::consts::PI;

fn main() {
    let r: f32 = read_elem();
    println!("{}", 2.0 * PI * r);
}

#[allow(dead_code)]
fn read_elem<T: FromStr>() -> T {
    let mut l = String::new();
    stdin().read_line(&mut l).unwrap();
    l.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_n_elems<T: FromStr>() -> Vec<T> {
    let n = read_elem::<u32>();
    let mut vec: Vec<T> = vec![];
    for _i in 0..n {
        vec.push(read_elem::<T>());
    }
    vec
}

#[allow(dead_code)]
fn read_split_line<T: FromStr>() -> Vec<T> {
    let mut l = String::new();
    stdin().read_line(&mut l).unwrap();
    l.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 2200
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		Map<Long,Long> map = new HashMap<>();
		for(int i=0;i<n;i++) {
			long tmp = in.nextInt();
			if(map.containsKey(tmp)) map.put(tmp, map.get(tmp)+1);
			else map.put(tmp, 1L);
		}
		for(int i=0;i<m;i++) {
			long b = in.nextLong();
			long c = in.nextLong();
			if(map.containsKey(c)) map.put(c, map.get(c)+b);
			else map.put(c, b);
		}
		List<Long> list = new ArrayList<>();
		for(long key : map.keySet()) list.add(key);
		list.sort((e1,e2)->e1>e2?-1:1);
		long ans = 0;
		int idx = 0;
		while(true) {
			if(n-map.get(list.get(idx))>0) {
				ans += map.get(list.get(idx)) * list.get(idx);
				n -= map.get(list.get(idx));
				idx++;
			}else {
				ans += n * list.get(idx);
				break;
			}
		}
		System.out.println(ans);
		in.close();

	}

}


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

using namespace std;

int a[100], b[100], c[100], d[100];
int n, m;

int main(){

	scanf("%d %d", &n, &m);

	for(int i = 0; i < n; i++)
		scanf("%d %d", a+i, b+i);

	for(int i = 0; i < m; i++)
		scanf("%d %d", c+i, d+i);

	for(int i = 0; i < n; i++){
		int ans = 0, mn = 1000000000;
		for(int j = 0; j < m; j++){
			int dt = abs(a[i] - c[j]) + abs(b[i] - d[j]);
			if(dt < mn){
				mn = dt;
				ans = j;
			}
		}

		printf("%d\n", ans+1);
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
using namespace std;
typedef long long int ll;
const int INF = 1001001001;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
/*bit全探索
for (int bit = 0; bit < (1<<N); ++bit) {
}
if (bit & (1 << i)) {
}
*/

bool isPrime(int x){
    if(x==1)return 0;
    if(x==2)return 1;
    if(x%2==0)return 0;
    for(int i=3;i*i<=x;i++)if(x%i==0)return 0;
    return 1;
}

ll f(string &s){
    string a = "";
    ll sum = 0;
    int n = s.size();
    rep(i,n){
        if(s[i]=='+'){
            sum += stoll(a);
            a = "";
        }else{
            a += s[i];
        }
    }
    sum += stoll(a);
    return sum;
} 

int main(){
    string s;
    cin >> s;
    ll sum = 0;
    int n = s.length()-1; 
    rep(bit,1<<n){
        string tmp = "";
        tmp += s[0];
        rep(i,n){
            if(bit&(1<<i)){
                tmp+="+";
            }
            tmp+=s[i+1];
        }
        sum+=f(tmp);
    }
    cout << sum << endl;
    return 0;
}


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

int main (){
    int n;
    cin >> n;
    map<string,int> mp;
    rep(i,n){
        string s;
        cin >> s;
        sort(s.begin(),s.end());
        mp[s]++;
    }
    int64_t sum=0;
    for(auto &p:mp){
        int a=p.second;
        sum+=(int64_t)a*(a-1)/2;
    }
    cout << sum <<endl;
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	cout<<0<<endl;
	string s;
	cin>>s;
	if (s=="Vacant")
	{
		return 0;
	}
	int ok=0,ng=n+1;
	while (ng-ok>1)
	{
		int mid=(ok+ng)/2;
		cout<<mid<<endl;
		string t;
		cin>>t;
		if (t=="Vacant")
		{
			return 0;
		}
		if (mid%2==0)
		{
			if (s==t)
			{
				ok=mid;
			}
			else
			{
				ng=mid;
			}
		}
		else
		{
			if (s==t)
			{
				ng=mid;
			}
			else
			{
				ok=mid;
			}
		}
	}
	cout<<ok<<endl;
	cin>>s;
	if (s=="Vacant")
	{
		return 0;
	}
	return 0;
}


Measured memory_bytes: 852
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;

internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.B
{
    public class Program
    {
        public static long N { get; private set; }
        public static long A { get; private set; }
        public static long B { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            var inputs = CR.GetLongs();
            N = inputs[0];
            A = inputs[1];
            B = inputs[2];

            var k = N / (A + B);
            var amari = N % (A + B);

            return k * A + Math.Min(amari, A);
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"

using namespace std;

typedef pair<int, int> P;
#define int long long
#define ll long long
#define mod 1000000007
#define INF (1LL<<60)


signed main(){

	int N, p[10];
	cin >> N;
	int m = -INF, idx;
	for (int i = 0; i < N; i++){
		cin >> p[i];
		if (p[i] > m) {
			m = p[i];
			idx = i;
		}
	}
	int ans = 0;
	for (int i = 0; i < N; i++){
		if (idx == i) ans += p[i] / 2;
		else ans += p[i];
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int ctoi(char c){return c - '0';}

template<typename T>  
bool isOk(T key,T value){
  return key >= value;
}

template<typename T>
T binary_search(vector<T> a,T key){
  T ok = a.size()-1;
  T ng = 0;

  while(abs(ok - ng) > 1){
    T mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}

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

int main() { // TODO: 二分探索のコードを書き直す

  //cin.tie(0); ios::sync_with_stdio(0);
  int h,w;cin>>h>>w;
  vector<string> s(h);rep(i,h)cin>>s[i];
  int ans = 0;
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#')continue;

      vector<vector<int> > dist(h,vector<int>(w,-1));
      queue<pair<int,int> > que; 
      dist[i][j] = 0;
      que.push(mp(i,j));

      while(!que.empty()){
        pair<int,int> cur = que.front();que.pop();

        rep(i,4){
          pair<int,int> next = cur;
          next.fi += dy[i];
          next.se += dx[i];
          if(next.fi < 0 || next.fi >= h || next.se < 0 || next.se >= w)continue;
          if(s[next.fi][next.se] == '#')continue;

          if(dist[next.fi][next.se] == -1){
            que.push(next);
            dist[next.fi][next.se] = dist[cur.fi][cur.se]+1;
            ans = max(ans,dist[next.fi][next.se]);
          }
          
        }

      }
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void B();

int main()
{
	B();
	fflush(stdout);
	return 0;
}

static void B()
{
	int N;
	get(N);

	std::vector<LLONG> li(N);
	for (int i = 0; i < N; i++) {
		get(li[i]);
	}

	std::sort(li.begin(), li.end());

	LLONG ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				if (li[i] - li[j] < li[k] && li[k] < li[i] + li[j] && li[i] != li[j] && li[j] != li[k] && li[i] != li[k]) {
					ans++;
				}
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 3724
import sys
import bisect
 
N, Q = map(int, input().split(' '))
G = [list(map(int, sys.stdin.readline().split(' '))) for _ in range(N)]
T = [int(sys.stdin.readline()) for _ in range(Q)]

class SegTree :
    def __init__(self, n) :
        self.n = n
        self.A = [10**15] * (2 << (n + 1).bit_length())
 
    def update(self, l, r, val) :
      l += len(self.A) // 2
      r += len(self.A) // 2
      while l < r:
          if l & 1 :
              self.A[l] = min(self.A[l], val)
              l += 1
          if r & 1:
              self.A[r-1] = min(self.A[r-1], val)
              r -= 1
          l //= 2
          r //= 2

    def get(self, i) :
      i += len(self.A) // 2
      ret = self.A[i]
      while i > 0 :
          i //= 2
          ret = min(ret, self.A[i])
      return ret if ret < 10**15 else -1

ST = SegTree(Q)
for g in G :
    s = g[0] - g[2]
    e = g[1] - g[2]
 
    ll = bisect.bisect_left(T, s)
    rr = bisect.bisect_left(T, e)
 
    if ll == rr :
        continue
 
    ST.update(ll, rr, g[2])
 
for i in range(Q) :
    ans = ST.get(i)
    print(ans)


Measured memory_bytes: 109024
/*
h s, d't skp th si tll i's sved
 * ABC141 E
 * ABC145 D
 * ABC147 F
 * ABC174 F
*/
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
ll n;
cin>>n;
ll a[n];
map<ll,ll> mp;
ll ans=0;
for(ll i=0;i<n;i++)
{
cin>>a[i];
mp[a[i]]++;
}
for(ll i=1;i<=n;i++)
{
if(mp[i]>0)
{
ans+=mp[i]*(mp[i]-1)/2;
}
}
for(ll i=0;i<n;i++)
{
ll h=ans;
h-=mp[a[i]]*(mp[a[i]]-1)/2;
h+=(mp[a[i]]-1)*(mp[a[i]]-2)/2;
cout<<h<<endl;
}
}



/*
 * ||||


 */

Measured memory_bytes: 17676
#include <bits/stdc++.h>
using namespace std;
int INF = 2000000000;
int longest_increasing_subsequence_length(vector<int> &A){
	int N = A.size();
	vector<int> dp(N + 1, INF);
	for (int i = 0; i < N; i++){
		*lower_bound(dp.begin(), dp.end(), A[i]) = A[i];
	}
	return lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
}
int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++){
    cin >> A[i];
  }
  cout << longest_increasing_subsequence_length(A) << endl;
}


Measured memory_bytes: 3620
n,m=map(int,input().split())
w=[]
for i in range(m):
    a,b=map(int,input().split())
    w.append((a,b))
w.sort(reverse=True)
d=[]
for i in range(m):
    a,b=w.pop()
    if i==0:
        d.append([a,b])
    else:
        if d[-1][1]<=a:
            d.append([a,b])
        elif d[-1][1]>b:
            d[-1][1]=b
print(len(d))

Measured memory_bytes: 54472
// ToDo
// Link: https://atcoder.jp/contests/dp/tasks/dp_d
#include <iostream>
#include <climits>
#include <set>
#include <vector>
#include <stdio.h>
#include <map>
#include <stack>
#include <algorithm>
#include <unordered_map>
#define ll long long int
#define fastio ios_base::sync_with_stdio(false)
#define fastcin cin.tie(NULL)
using namespace std;
ll knapSack(ll W,ll* wt,ll* val,ll n){

	ll dp[n+1][W+1];

	for(int i=0;i<=n;i++){
		for(int j=0;j<=W;j++){
			if(i == 0 || j == 0){
				dp[i][j] = 0;
			}else if(wt[i-1] <= j){
				dp[i][j] = max(dp[i-1][j],val[i-1]+dp[i-1][j-wt[i-1]]);
			}else{
				dp[i][j] = dp[i-1][j];
			}
		}
	}


	return dp[n][W];
}
int main(){

	fastio;
	fastcin;	
	
    
    // freopen("small_input.txt", "r", stdin);
    
    // freopen("small_output.txt", "w", stdout);
    
	ll n,W;
	cin>>n>>W;
	ll* val = new ll[n];
	ll* wt = new ll[n];
	for(int i=0;i<n;i++){
		cin>>wt[i]>>val[i];
	}

	cout<<knapSack(W,wt,val,n);



}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    int x = n * 800;
    int y = n / 15 * 200;
    cout << x - y << endl;
}


Measured memory_bytes: 3636
package main

import (
	"fmt"
)

func main() {
	var a string
	fmt.Scan(&a)

	x := string(getRune(a, 0))
	y := string(getRune(a, 1))
	z := string(getRune(a, 2))

	res := 0
	for _, i := range []string{x, y, z} {

		if i == "1" {
			res++
		}
	}

	fmt.Println(res)
}

func getRune(s string, i int) rune {
	r := []rune(s)
	return r[i]
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N,L;
    cin >> N >> L;
    int sum = 0;
    repX(i,N+1,1){
        sum += L + i - 1;
    }
    int ans = 0;
    repX(i, N + 1, 1)
    {
        int x = sum -(L+i-1);
        if(abs(sum - ans) > abs(sum - x)){
            ans = x;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
using System;

namespace _2101
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int n = int.Parse(Console.ReadLine());
                if (n == 0)
                {
                    break;
                }
                int x = 1;
                bool b = true;
                if (n == 1)
                {
                    Console.WriteLine("deficient number");
                }
                else
                {
                    for (int i = 2; i <= Math.Sqrt(n) && b; i++)
                    {
                        if (n % i == 0)
                        {
                            x += i;
                            if (i != n / i)
                            {
                                x += n / i;
                            }
                            if (n < x)
                            {
                                b = false;
                            }
                        }
                    }
                    if (n < x)
                    {
                        Console.WriteLine("abundant number");
                    }
                    else if (n == x)
                    {
                        Console.WriteLine("perfect number");
                    }
                    else
                    {
                        Console.WriteLine("deficient number");
                    }
                }
            }
        }
    }
}

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

// using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))

constexpr int MAX = 100000 + 5;
int n, m;
// trueが飛ばすやつ
bool g[MAX];
int dp[MAX];
/***** MAIN *****/
signed main() {
  cin >> n >> m;
  REP(i,m) {
    int tmp;
    cin >> tmp;
    g[tmp] = true;
  }
  dp[0] = 1;
  REP(i,n) {
    if(g[i]) continue;
    REPS(j,1,3) {
      if(g[i+j]) continue;
      dp[i+j] = (dp[i+j] + dp[i]) % MOD;
    }
  }
  cout << dp[n];
  cout << "\n";
  return 0;
}
/***** MAIN *****/


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

int main() {
  int a, b;
  char op;
  while (true) {
    cin >> a >> op >> b;
    if (op == '+')
      cout << a + b << endl;
    else if (op == '-')
      cout << a - b << endl;
    else if (op == '*')
      cout << a * b << endl;
    else if (op == '/')
      cout << a / b << endl;
    else if (op == '?')
      break;
  }
}


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

int main(){
  string S;
  cin >> S;
  int i, count;
  i=0;
  count=1;
  bool flag=true;
  while(i<S.size()-1){
    if(S[i]==S[i+1] && flag){
      if(i==S.size()-2){
        i=i+2;
      }else{
      	i=i+2;
      	count=count+1;
      }
      flag=false;
    }else{
      i=i+1;
      count=count+1;
      flag=true;
    }
    //cout << "i count " << i << " " << count << endl;
  }
  
  cout << count << endl;
  
  return 0;
}

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

using namespace std;

#define int long long

#ifndef bhupixb
    #define var(...)
    #define stl(...)
#endif

#define rep(i,a,b) for (int i = a; i <= (int)b; ++i)
#define f first
#define s second

#define single_test

const int maxn = 404;
int dp[maxn][maxn];
int psum[maxn][maxn];
const int inf = 1e18;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1), pre(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        pre[i] = pre[i - 1] + a[i];
    }
    rep(i,1,n) {
        rep(j,i,n) psum[i][j] = pre[j] - pre[i - 1];
    }
    rep(len, 2, n) {
        for (int i = 1; i + len - 1 <= n; ++i) {
            int j = i + len - 1;
            int ans = inf;
            for (int k = i; k < j; ++k) {
                ans = min(ans, dp[i][k] + dp[k+1][j] + psum[i][j]);
            }
            dp[i][j] = ans;
        }
    }
    cout << dp[1][n] << '\n';
}

signed main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    #ifndef single_test
        cin >> t;
    #endif
    for (int i = 1; i <= t; ++i) {
        // cout << "Case #" << i << ": ";
        solve();
    }

    return 0;
}

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

int main() {
string S;
cin >> S;
 
string ans = "Yes";

for (int i = 0; i < S.size(); i++) {
  if (i % 2 == 0 && S.at(i) == 'L') {
    ans = "No";
    }
  else if (i % 2 == 1 && S.at(i) == 'R') {
    ans = "No";
  }
}

cout << ans << endl;

}

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

int main() {
  int N;
  cin >> N;
  vector<int> h(N),height(N,0);
  for(int i=0;i<N;i++) cin >> h.at(i);
  int ans = 0;
  while(1){
    int ans_tmp = ans;
    for(int i=0;i<N;i++){
      if(height.at(i) != h.at(i) ){
        for(int j=i;j<N;j++){
          if(height.at(j) != h.at(j) ) height.at(j) ++;
          else break;
        }
        ans ++;
        i = -1;
      }
    }
//    cout << ans << endl;
//    for(int k=0;k<N;k++) cout << height.at(k) << endl;
    if(ans == ans_tmp) break;
  }
  
//  for(int i=0;i<N;i++) cout << height.at(i) << endl;
  cout << ans << endl;
}

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

int main(){
    int n, k; cin >> n >> k;
    int l[55]; rep(i,n) cin >> l[i];
    sort(l,l+n,greater<int>());
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += l[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int k, s; readV(k, s);

  auto ans = 0;
  foreach (x; 0..k+1)
    foreach (y; 0..k+1) {
      auto z = s-x-y;
      if (z >= 0 && z <= k) ++ans;
    }

  writeln(ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int P[N*N];
    rep(i, N*N) {cin >> P[i]; P[i]--;}
    int d[N][N], rem[N][N];
    rep(i, N) rep(j, N) d[i][j] = min({i, N-1-i, j, N-1-j});
    fill(rem[0], rem[N], 1);
    int ans = 0;
    rep(n, N*N){
        int p = P[n]/N, q = P[n]%N;
        ans += d[p][q];
        rem[p][q] = 0;
        queue<pii> que;
        que.push(pii(p, q));
        while(!que.empty()){
            int x = que.front().first, y = que.front().second;
            que.pop();
            rep2(i, -1, 1) rep2(j, -1, 1){
                if(abs(i+j) != 1) continue;
                int nx = x+i, ny = y+j;
                if(nx < 0 || nx >= N || ny < 0 || ny >= N) continue;
                if(chmin(d[nx][ny], d[x][y]+rem[x][y])) que.push(pii(nx, ny));
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <iomanip>
#include <algorithm>
#include <cmath>

using namespace std;
using ll = long long;
using pint = pair<int, int>;

bool cmp(const pair<int, pair<string, int>>& a, const pair<int, pair<string, int>>& b) {

	bool ret = false;
	if (a.second.first < b.second.first) {
		ret = true;
	}
	else if (a.second.first == b.second.first){
		if (a.second.second > b.second.second) {
			ret = true;
		}
	}
	return ret;
}

int main() {
	int N;
	cin >> N;
	vector<pair<int, pair<string, int>>> a;

	for (int i = 0; i < N; ++i) {
		string S;
		int P;
		cin >> S >> P;
		pair<int, pair<string, int>> tmp(i, make_pair(S, P));
		a.push_back(tmp);
	}

	sort(a.begin(), a.end(), cmp);

	for (auto aa : a) {
		cout << aa.first + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 3552
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <complex>
#include <iomanip>
#include <cmath>
using namespace std;
typedef long long ll;

int main()
{
  int n, cnt = 0, tmp = 0;
  cin >> n;
  ll a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  while (1) {
    for (int i = 0; i < n; i++) {
      if (a[i] % 2 != 0) {
        tmp++;
        break;
      }
      a[i] /= 2;
    }
    if (tmp > 0) break;
    cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
function main (s) {
    s=s.split(" ");
	s[0]=parseInt(s[0]);
	s[2]=parseInt(s[2]);
	console.log((s[1]=="+")?(s[0]+s[2]):(s[0]-s[2]))
}
 
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define intt long long 
using namespace std;
const int maxx =2e6+1314;
int read(){int k;scanf("%d",&k);return k;}
int n,Q;	
struct AA{		
	int L,R;	
}A[maxx];	
bool my(AA a,AA b){	
	return a.R<b.R;
}	
int dp[maxx];
int Min[maxx];	
int lz[maxx];
#define rtz (rt*2)	
#define rty (rtz+1)	
#define mid (l+r>>1)
void pushdown(int rt){
	Min[rtz]=min(Min[rtz],lz[rt]);
	Min[rty]=min(Min[rty],lz[rt]);
	lz[rtz]=min(lz[rt],lz[rtz]);
	lz[rty]=min(lz[rty],lz[rt]);
	lz[rt]=lz[0];
}	
void insert(int l,int r,int rt,int L,int R,int v){	
	if(l>R||r<L)return ;
//	cout<<l<<"__"<<r<<"||||"<<L<<"_____"<<R<<"____"<<v<<endl;	
	if(l>=L&&r<=R){
		Min[rt]=min(Min[rt],v),lz[rt]=min(lz[rt],v);
		return ;
	}	
	pushdown(rt);
	insert(l,mid,rtz,L,R,v);	
	insert(mid+1,r,rty,L,R,v);	
	Min[rt] = min(Min[rtz],Min[rty]);
}	
int find(int l,int r,int rt,int pos){	
	if(l==r)return Min[rt];
	pushdown(rt);
	if(mid>=pos)return find(l,mid,rtz,pos);
	else return find(mid+1,r,rty,pos);
}	
int s[maxx];
int b[maxx];
//²»Í¬µÄÎ»ÖÃ:
//Èç¹û¸³Öµ³É1µÄ»°£¬¹±Ï×=bÖÐ0µÄ¸öÊýs2[R]-s2[L-1];
int main(){	
//	freopen("a.in","r",stdin);
	memset(Min,127,sizeof(Min));
	memset(lz,127,sizeof(lz));
	n=read();
	for(int i=1;i<=n;i++)b[i]=read(),s[i]=s[i-1]+(!b[i]);
	//T2£º¸³Öµ³É1 
	Q=read();
	for(int i=1;i<=Q;i++){A[i].L=read(),A[i].R=read();}	
	sort(A+1,A+1+Q,my);
	int top=0;
	for(int i=1;i<=n;i++){	
		dp[i]=dp[i-1]+b[i];
		while(top<Q&&A[top+1].R==i){top++;
			int L=A[top].L,R=A[top].R;
			intt c=min(dp[L-1]+s[R]-s[L-1],find(1,n,1,L)+s[R]);
			dp[i]=min(dp[i],dp[L-1]+s[R]-s[L-1]);
			dp[i]=min(dp[i],find(1,n,1,L)+s[R]);
			insert(1,n,1,L,R,c-s[R]);
		}	
//		insert(1,n,1,i,i,dp[i]-s[i]); 
	}	
	cout<<dp[n]<<endl;
	return 0;
}
 

Measured memory_bytes: 25728
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

int main() {
  string s;
  cin >> s;
  int ans{};
  for (auto e : s) {
    if (e == '+')
      ans++;
    else
      ans--;
  }
  cout << ans << endl;
}


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

int main(){
  string s; cin>>s;
  long long ans=0,c1=0,c2=0,log=0;
  for(int i=0;i<s.size();i++){
    if(s.at(i)=='<'){
      while(i<s.size() && s.at(i)=='<'){
        c1++;
        i++;
      }if(i!=s.size()) i--;
      if(c2>0){
        if(log==0){
          log=c2; c2=0;
          while(log>0){
            ans+=log;
            log--;
          }
          while(log<c1){
            ans+=log;
            log++;
          }c1=0;
        }else{
          if(log>c2){
            ans+=log; log=c2-1;
          }else{
            ans+=c2; log = c2-1;
          }
          for(int j=0;j<c2-1;j++){
            ans+=log;
            log--;
          }c2=0;
          for(int j=0;j<c1;j++){
            ans+=log;
            log++;
          }c1=0;
        }
      }else continue;
    }else{
      while(i<s.size() && s.at(i)=='>'){
        c2++;
        i++;
      }if(i!=s.size()) i--;
      if(c1>0){
        if(log==0){
          while(c1>log){
            ans+=log;
            log++;
          }c1=0;
          if(log>c2){
            ans+=log; log=c2-1;
          }else{
            ans+=c2; log = c2-1;
          }
          for(int j=0;j<c2-1;j++){
            ans+=log;
            log--;
          }c2=0;
        }else{
          for(int j=0;j<c1;j++){
            ans+=log;
            log++;
          }c1=0;
          if(log>c2){
            ans+=log; log=c2-1;
          }else{
            ans+=c2; log = c2-1;
          }
          for(int j=0;j<c2-1;j++){
            ans+=log;
            log--;
          }c2=0;
        }
      }else continue;
    }
  }
  if(c1>0){
    for(int i=0;i<c1;i++){
      ans+=log;
      log++;
    }
  }if(c2>0){
    if(log>c2){
            ans+=log; log=c2-1;
          }else{
            ans+=c2; log = c2-1;
          }
    for(int i=0;i<c2-1;i++){
      ans+=log;
      log--;
    }
  }
  cout<<ans+log<<endl;
}


Measured memory_bytes: 900
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 9/17/2020
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const double PI = acos(-1);

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

	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> arr(n);
	for(int64_t& el : arr) cin >> el;
	vector<int64_t> dp(n, int(1e18));
	dp[n-1] = 0;
	for(int i = n-2; i >= 0; i--) {
		for(int kk = 0; kk <= k; kk++) {
			if((i+kk) < n) dp[i] = min(dp[i], dp[i+kk] + abs(arr[i] - arr[i+kk]));
		}
	}
	cout << dp[0] << "\n";

	return 0;
}



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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A % B == 0 and C > 0) {
    cout << "NO" << endl;
    return 0;
  }
  
  if (C % A == 0) {
    cout << "YES" << endl;
    return 0;
  }
  
  unsigned long long sum = 0;
  for (int i = 1; i < 10000000; ++i) {
    sum += A * i;
    if (sum % B == C or (A * i) % B == C) {
      cout << "YES" << endl;
      return 0;
    }
  }
  
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
long long ans;
int i,j,m,n,p,k,A[N],B[N],Max,f[N],C[N];
set<int>st;
int main()
{
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;++i) scanf("%d",&A[i]),B[++B[0]]=A[i];
	sort(B+1,B+B[0]+1); B[0]=unique(B+1,B+B[0]+1)-(B+1);
	int Min=1e9+7;
	for (i=1;i<=n;++i)
	{
			Min=min(Min,A[i]);
			Max=max(Max,A[i]-Min);
	}
	for (i=1;i<=n;++i)
	{
			st.insert(A[i]);
			if (st.find(A[i]-Max)==st.end()) continue;
			f[i]=f[C[lower_bound(B+1,B+B[0]+1,A[i]-Max)-B]]+1;
			C[lower_bound(B+1,B+B[0]+1,A[i])-B]=i;
			ans+=f[i];
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 6528
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)
#pragma GCC optimize("unroll-loops")
// -------------------</optimizations>--------------------
#include <iostream>
#include <bitset>
#include <algorithm>        // sort()
#include <vector>           // for vectors
#include <map>              // for ordered map
#include <unordered_map>
#include <list>             // for list
#include <iomanip>          // for setprecision()
#include <cmath>            // for pow(), sqrt(), log(), log10(), ....
#include <cstring>          // for memset()
#include <unordered_set>    // for unordered_set
#include <climits>          // for INT_MAX & INT_MIN
#include <set>              // for ordered set

#define C ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define NINF INT_MIN
const double pi=acos(-1); // value of pi


bool isVowel(char ch) {
    if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u') {
        return 1;
    }
    return 0;
}

bool compare(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second<b.second;
}

map<ll, list<ll>> m;
// map<ll, ll> m;

bool isPrime(ll n) {
    for(ll i=3; i*i<=n; i+=2) {
        if(n%i==0) {
            return false;
        }
    }
    return true;
}

int main() {
    C
//     freopen("input.txt","r",stdin);
// 	freopen("output.txt","w",stdout);
    int t=1;
    // cin >> t;
    while(t--) {
        ll n, ans, x=0;
        cin >> n;
        ll arr[n];
        for(ll i=0; i<n; i++) {
            cin >> arr[i];
            x=x^arr[i];
        }
        for(ll i=0; i<n; i++) {
            ans=x^arr[i];
            cout << ans << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 4748
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main {
    public static void main(String[] args) throws java.lang.Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader((System.in)));
        StringTokenizer s = new StringTokenizer(br.readLine());
        long n = Long.parseLong(s.nextToken());
        long blue = Long.parseLong(s.nextToken());
        long red = Long.parseLong(s.nextToken());
        long periods = n / (blue + red);
        long totalBlue = blue * periods;
        System.out.println(totalBlue + Math.min(n % (blue + red), blue));
    }
}

Measured memory_bytes: 22864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    int h,w; cin >> h >> w;
    string s;
    rep(i, h){
        rep(j, w){
            cin >> s;
            if(s == "snuke"){
                cout << (char)(j + 'A') << i+1 << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
N,K = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)
dp=Array.new(N,0)
for i in 1...N
    cnt=Float::INFINITY
    if 1<=i && i<K
        for j in 0..i-1
            com=dp[j]+(as[j]-as[i]).abs
            cnt=cnt > com ? com : cnt
        end
        dp[i]=cnt
    else
        for j in i-K..i-1
            com=dp[j]+(as[j]-as[i]).abs
            cnt=cnt > com ? com : cnt
        end
        dp[i]=cnt
    end
end
puts dp.last


Measured memory_bytes: 11404
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

r,c,k = ip()
x = []
ct = 0
for i in range(r):
    s = list(input())
    x.append(s)
    ct += s.count('#')
ans = 0
for ii in range(2**r):
    for jj in range(2**c):
        a = bin(ii)[2:].zfill(r)
        b = bin(jj)[2:].zfill(c)
        #print(a,b)
        new = 0
        for i in range(r):
            for j in range(c):
                if a[i] =='1' or b[j] == '1':
                    if x[i][j] == '#':
                        new += 1
        if ct-new == k:
            ans += 1
print(ans)




Measured memory_bytes: 69368
def isOne_sort(array):
    n = len(array)
    sort_count = 0
    for i in range(0, n-1):
        if(sort_count>1):
            return 'NO'
        # 最小値のインデックスを保持
        min = i
        for j in range(i+1, n):
            if array[min] > array[j]:
                min = j
        # 見つけた最小値を未整列末尾要素と交換
        if(i!=min):
            tmp = array[min]
            array[min] = array[i]
            array[i] = tmp
            sort_count+=1
    return 'YES'

N = int(input())
P = [int(i) for i in input().split()]
print(isOne_sort(P))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int Max=1e9+100;
const ll Maxx=1e18+500;
const int sz=1e3+100;
vector<pii> test;
int main()
{
    Khela
    int  a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,n,mx;
    char ch;
    double d;
    string str1,str2,str;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>n>>k)
    {
         test.clear();
         test.pb({0,0});
         int id,last=0;
         cin>>str;
         for(i=0;i<n;i++){
             if(str[i]=='0') {
                 if(last==0) id=i+1;
                 ++last;
             }
             else{
                 if(last>0){
                     test.pb({id,i});
                 }
                 last=0;
             }
         }
         if(last>0) test.pb({id,n});
 
         test.pb({n+1,n+1});
         
         int siz=test.size();
         int mx=0;
         for(i=0;i<siz;i++)
         {
             if(i+k<siz){
                 p=test[i+k].f-test[i-1].s-1;
                 mx=max(p,mx);
             }
             else {
                 p=test[siz-1].first-test[i-1].s-1;
                 mx=max(mx,p);
             }
         }
 
         if(siz==2) mx=n;
 
         cout<<mx<<endl;
    }
 
 
 
 
 
}

Measured memory_bytes: 1020
#include <iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#define ll long long
using namespace std;
#define rep(n) for(int i=0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<=n;i++)
int main(void){
    // Your code here!
int n,k,count=0;
cin>>n;
vector<int> inp(n,-1),out(n,-1);
for(int i=0;i<n;i++){
    cin>>inp[i];
    inp[i]--;
}

for(int i=1;i<=n;i++){
    out[inp[i-1]]=i;
}

rep(n){
    cout<<out[i]<<" ";
}

}


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

int main() {

  while( true ) {

    long long int n;
    cin >> n;
    if ( n == 0 ) break;

    long long int w, h;
    cin >> w >> h;

    long long int cnt[101][101] = {};

    for ( long long int i = 0; i < n; i++ ) {

      long long int x, y;
      cin >> x >> y;
      cnt[x][y]++;

    }

    for ( long long int y = 1; y <= h; y++ ) {

      long long int k = 0;

      for ( long long int x = 1; x <= w; x++ ) {

	k += cnt[x][y];
	cnt[x][y] = cnt[x][y-1] + k;

      }

    }

    long long int s, t;
    cin >> s >> t;

    long long int ans = 0;

    for ( long long int y = t; y <= h; y++ ) {
      for ( long long int x = s; x <= w; x++ ) {

	ans = max( ans, cnt[x][y] - cnt[x][y-t] - cnt[x-s][y] + cnt[x-s][y-t] );

      }
    }

    cout << ans << endl;

  }

  return 0;

}

Measured memory_bytes: 1244
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power((((a%mod)*(a%mod))%mod),b/2)%mod;
    else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
}

 
int32_t main()
{
    IOS
    
        
        int n;
        cin>>n;
        int count=0;
        int a[n];
        for(int i=0;i<n;++i)
            cin>>a[i];

        for(int i=0;i<n;++i)
        {
            if(a[i]!=i+1)
            {
                if(count==1)
                {
                    cout<<"NO";
                    return 0;
                }
                if(a[a[i]-1]==i+1)
                {
                    a[a[i]-1]=a[i];

                    count++;
                    continue;
                }
                cout<<"NO";
                return 0;
            }
        }
        cout<<"YES";


 
 
 
}

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

int main() {
	int h,w,d,i,j;
	cin>>h>>w>>d;
	 int ma[h][w];
	 pair <int ,int > a[h*w+1],b[h*w+1];
	 for(i=1;i<=h*w;i++)
	   {a[i].first=0;
	   a[i].second=0;}
	for(i=0;i<h;i++)
	  {
	  	  for(j=0;j<w;j++)
	  	    {cin>>ma[i][j];
	  	       //cout<<ma[i][j];
	  	        a[ma[i][j]].first=i+1;
	  	        a[ma[i][j]].second=j+1;
	  	    }
	  }
	
	 long int q;
	 int x,y;
	 long int dis[h*w+1];
	 for(i=1;i<=h*w;i++)
	   {
	       if(i-d<=0)
	         dis[i]=0;
	       else
	         {
	         	dis[i]=dis[i-d]+abs(a[i].first-a[i-d].first)+abs(a[i].second-a[i-d].second);
	         }
	   }
	 cin>>q;  
	 while(q--)
	   {
	   	   cin>>x>>y;
	   	   cout<<dis[y]-dis[x]<<"\n";
	   }
	// your code goes here
	return 0;
}

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

using namespace std;

int main(){
	int i,j,m,n,t,sum = 0,k = 13;
	bool f,tf;
	scanf("%d",&n);
	while(sum!=n){
		j = 3;
		tf = true;
		while(j<=ceil(sqrt(k))&&tf==true){
			if(k % j==0)tf = false;
			else j++;
		}
		if(tf==true){
			if(sum==0) cout << k;
			else cout << ' ' << k;
			sum ++;
		}
		k += 10;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59

int main(){
    ll i,j;
    ll n,x;
    cin>>n>>x;
    vector<pair<ll,vector<ll> > > v;

    for(i=0;i<n;i++){
        vector<ll> w(3);
        ll b,l,u;
        cin>>b>>l>>u;
        w[0]=b;
        w[1]=l;
        w[2]=u;
        v.pb(make_pair(u*(x-b)+l*b,w));
    }
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());

    ll sm[n];
    sm[0]=v[0].fi;
    for(i=1;i<n;i++){
        sm[i]=sm[i-1]+v[i].fi;
    }
    ll d=0;
    for(i=0;i<n;i++){
        d-=v[i].se[0]*v[i].se[1];
    }

    ll le=-1;
    ll ri=n*x;

    while(ri-le>1){
        ll mi=(ri+le)/2;
        if(mi!=n*x){
        ll s=mi/x;
        ll t=mi-s*x;
        bool f=0;
        for(i=0;i<n;i++){
            ll te=d;
            if(i<=s-1){
                te+=sm[s]-v[i].fi;
                if(t>=v[i].se[0]){
                    te+=v[i].se[0]*v[i].se[1]+(t-v[i].se[0])*v[i].se[2];
                }
                else te+=t*v[i].se[1];
            }
            else {
                if(s-1>=0) te+=sm[s-1];
                if(t>=v[i].se[0]){
                    te+=v[i].se[0]*v[i].se[1]+(t-v[i].se[0])*v[i].se[2];
                }
                else te+=t*v[i].se[1];
            }
            if(te>=0) f=1;
        }
        if(f==1) ri=mi;
        else le=mi;
        }
        else {
            ri=mi;
        }

    }
    cout<<ri<<endl;
}

Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s, t;
	cin >> s >> t;
	bool flag = true;
	map<char, char> a, b;
	for(int k = 0; k < s.size(); k++)
	{
		char i = s[k];
		char j = t[k];
		if(a.count(i))
		{
			if(a[i] != j)
				flag = false;
		}
		if(b.count(j))
		{
			if(b[j] != i)
				flag = false;
		}
		a[i] = j;
		b[j] = i;
	}
	if(flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    int x;
    cin >> x;
    bool find = false;
    while(find == false){
        if(x < 2){
            x++;
            continue;
        }else if(x == 2){
            break;
        }else if(x % 2 == 0){
            x++;
            continue;
        }
        double sqrtx = sqrt(x);
        bool g = true;
        for(int i=3; i <= sqrtx; i+=2){
            if(x % i == 0){
                g = false;
                break;
            }
        }
        if(g == false){
            x++;
        }else{
            find = true;
        }
    }
    
    cout << x << endl;
}


Measured memory_bytes: 256