akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner str = new Scanner(System.in);
        int N = str.nextInt();
        int K = str.nextInt();

        long result = 0;

        long NList[] = new long[N];

        for(int i = 0; i < N; i++){
            NList[i] = str.nextLong();
        }

        Arrays.sort(NList);

        for(int i = N - 1 - K; i >= 0; i--){
            result += NList[i];
        }

        System.out.println(result);

        str.close();
    }
}

Measured memory_bytes: 84640
a,b,c,x,y = map(int,input().split())

ans = float("inf")
ab_max = max(x*2, y*2) 
for ab in range(ab_max+1):
    a_buy = max(x - (ab // 2),0)
    b_buy = max(y - (ab // 2),0)
    tmp = a * a_buy + b * b_buy + ab * c
    if ans > tmp:
        ans = tmp

print(ans)


Measured memory_bytes: 39664
#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 all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;

#define NUM 100000

int main()
{
    bool number[NUM];
    vint Prime;
    rep2(i, 2, NUM)
    {
        number[i] = true;
    }
    rep2(i, 2, NUM)
    {
        if(number[i])
        {
            for (int j = 2; j * i < NUM;j++)
            {
                number[i * j] = false;
            }
        }
    }
    rep2(i,3,NUM)
    {
        if(number[i] and number[(i+1)/2])
            Prime.push_back(i);
    }
    int Q;
    cin >> Q;
    vint l(Q), r(Q);
    rep(i, Q)
    {
        cin >> l[i] >> r[i];
    }
    rep(i,Q)
    {
        cout << upper_bound(all(Prime), r[i]) - lower_bound(all(Prime), l[i]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1536
# include <bits/stdc++.h>
typedef long long lint;
using namespace std;

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  int n; cin >> n;
  while(n>0) { n-= 1000; }
  printf("%d\n",abs(n));

  return 0;
}


Measured memory_bytes: 3760
#include<bits/stdc++.h>
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define pii pair<int,int>
#define REP(i,a) for(int (i)=0; (i)<(a); (i)++)
#define RREP(i,a) for(int (i)=a-1; (i)>=(0); (i)--)
#define REP2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
typedef long long ll;

using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N;
  cin >> N;
  bool ans = false;
  REP2(i,1,10)REP2(j,1,10){
    if(i * j == N) ans = true;
  }
  if(ans) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
 int hunNum,tenNum,oneNum;
 int s;
 int count = 0;
 
 scanf("%d",&s);
 
 if(s>=100){
   s = s - 100;
   count += 1;
 }
 if(s>=10){
   s = s-10;
   count += 1;
 }
 if(s>=1){
   s = s-1;
   count += 1;
 }
 
 printf("%d",count);
 
  
  
  
 return 0; 
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		UL N; cin >> N;
		vector<UL> A(N); rep(i, N) cin >> A[i];
		sort(A.begin(), A.end());
		vector<UL> DA(N); rep(i, N) DA[A[i]]++;
		UL m = A[0], M = A[N - 1];
		if (DA[m] == 1) {
			if (m * 2 != M) { cout << "Impossible" << endl; return; }
			for (UL p = m + 1; p <= M; p++) {
				if (DA[p] < 2) { cout << "Impossible" << endl; return; }
			}
			cout << "Possible" << endl;
			return;
		}
		else if (DA[m] == 2) {
			if (m * 2 - 1 != M) { cout << "Impossible" << endl; return; }
			for (UL p = m + 1; p <= M; p++) {
				if (DA[p] < 2) { cout << "Impossible" << endl; return; }
			}
			cout << "Possible" << endl;
			return;
		}
		cout << "Impossible" << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


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

int main()
{
    int N, Y;
    cin >> N >> Y;

    for(int x = 0; x <= N; x++){
        for(int y = 0; y <= N - x; y++){
            int z = N - x - y;
            if((10000*x + 5000*y + 1000*z) == Y){
                cout << x << ' ' << y << ' ' << z << endl;
                return 0;
            }
        }
    }
    cout << -1 << ' ' << -1 << ' ' << -1 << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int n = sc.nextInt();
		int m = sc.nextInt();

		int g = 0;
		for ( int i=0; i<m; i++ ) {
			int a = sc.nextInt();
			g = g + a;
		}

		if ( g > n ) {
			System.out.println(-1);
		} else {
			System.out.println(n-g);
		}
	}
}

Measured memory_bytes: 37928
#include<stdio.h>
int main(void){
        int r,g,b,d;
        scanf("%d %d %d",&r,&g,&b);
        d=r*100+g*10+b;
        if(d%4==0){
          printf("YES\n");
        }
        else{
          printf("NO\n");
        }
	return 0;
}

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

int compute(int *a,int *b){
    int i=0;
    while(!((*a)*pow(2,i)>(*b))){
        i++;
    }
    *a=(*a)*pow(2,i);
    return i;
}
int main(){
    int a,b,c,k;
    cin>>a>>b>>c;
    cin>>k;
    
    if(a<b && b<c)
        cout<<"Yes";
    else if(a<b){
        int z= compute(&c,&b);
        if(z<=k)
            cout<<"Yes";
        else
        {
            cout<<"No";
        }
        
    }
    else{
        int z1=compute(&b,&a);
        int z2=compute(&c,&b);
        if(z1+z2 <=k)
            cout<<"Yes";
        else{
            cout<<"No";
        }
    }
    
    return 0;
}

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

using namespace std;

const int DIV = 1000000007;

void solve(int test, istream &in) {
    int x;
    in >> x;
    printf("%s", x >= 30 ? "Yes" : "No");
}

int main(int argc, char* argv[])
{
#ifdef VLAD_LOCAL
	//FILE *f = fopen("in.txt", "r");
    ifstream f("in.txt");
#else
	//FILE *f = stdin;
    istream &f = cin;
#endif
    int tests = 1;
    //f >> tests;
    for (int test = 0; test < tests; test++) {
        solve(test, f);
    }
	return 0;
}



Measured memory_bytes: 3756
#include <iostream>
#include <deque>
using namespace std;
int main()
{
	int q, quer, d, x, p;
	deque<int> dec;
	cin >> q;
	while (q--) {
		cin >> quer;
		if (quer == 0) {
			cin >> d >> x;
			if (d == 0)
				dec.push_front(x);
			if (d == 1)
				dec.push_back(x);
		}
		if (quer == 1) {
			cin >> p;
			cout << dec[p] << endl;
		}
		if (quer == 2) {
			cin >> d;
			if (d == 0)
				dec.pop_front();
			if (d == 1)
				dec.pop_back();
		}
	}
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector <int> vec(N+1);
  for (int i = 0; i < N+1; i++){
  vec.at(i) = pow(2,i) + (N - i) * K;
  }
  sort(vec.begin(),vec.end());
  cout << vec.at(0);
}


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

int main()
{
  string S;
  cin >> S;
  
  int count = 0;
  for(int i = 0; i < 3; i++)
  {
    if(S.at(i) == 'o')
      count++;
  }
  cout << 700 + (100 * count) << endl;
}

Measured memory_bytes: 256
#N = int(input())
S = input()
#S = list(input())

#N,K=map(int,input().split())
#S=list(map(int,input().split()))


ans='Yes'

if S == 'Sunny':
    ans = 'Cloudy'
elif S == 'Cloudy':
    ans = 'Rainy'
else:
    ans = 'Sunny'




print(str(ans))


Measured memory_bytes: 38384
n,k,*a=map(int,open(i:=0).read().split())
a.sort()
p=a.pop
s=b=~k%2or p()
while k>1:
 if(x:=a[i]*a[i+1])*b>a[-1]*a[-2]*b:i+=2
 else:x=p()*p()
 s=s*x%(10**9+7);k-=2
print(s)

Measured memory_bytes: 31560
def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    H = list(map(int, input().split()))

    inf = float("inf")
    dp = [inf]*N

    dp[0] = 0

    for i in range(N-1):
        dp[i+1] = min(dp[i+1], dp[i] + abs(H[i+1]-H[i]))
        if i != N-2:
            dp[i+2] = min(dp[i+2], dp[i] + abs(H[i+2]-H[i]))
    print(dp[-1])


if __name__ == "__main__":
    main()


Measured memory_bytes: 13868
import sys
# gcd
from fractions import gcd
# 切り上げ，切り捨て
# from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
# from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
# from collections import Counter
# import math
# from functools import reduce
#
# input関係の定義
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


N = ii()
A = lmi()
Leftgcd = list(accumulate(A, gcd))
Rightgcd = list(accumulate(reversed(A), gcd))
Leftgcd.insert(0, 0)
Rightgcd.insert(0, 0)
maxgcd = [1]
for i in range(N):
    maxgcd.append(gcd(Leftgcd[i], Rightgcd[N - 1 - i]))
print(max(maxgcd))

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


int main(){
    int x;
    cin>>x;
    if(x>=30)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3596
integer n, lowest, now
character(100):: s, top,tail
read*,n
read*,s
s = trim(s)
lowest=0; now=0
do i = 1,n
  if(s(i:i) == "(")then
    now = now + 1
  else
    now = now - 1
  end if
  lowest = min(lowest,now)
end do
top = ''
tail= ''
if(lowest<0)top =repeat("(",-lowest)
if(now>lowest)tail=repeat(")",now-lowest)

print'(a)', trim(top) // trim(s) // trim(tail) 

end

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

int main(){
    int_fast64_t N, K;
    scanf("%ld%ld", &N, &K);
    vector<int_fast64_t> a(N), v;
    for(int_fast64_t i = 0; i < N; ++i){
        scanf("%ld", &a[i]);
        for(int_fast64_t j = i, k(0); j >= 0; --j)v.push_back(k += a[j]);
    }
    int_fast64_t k(0), m(0);
    for(int_fast64_t i = 1125899906842624, cnt; i > 0; i >>= 1){
        cnt = 0;
        for(auto j : v){
            if(((j & m) == m) && (j & i)){
                ++cnt;
            }
        }
        if(cnt >= K){
            m |= i;
            ++k;
        }
    }
    printf("%ld\n", m);
    return 0;
}


Measured memory_bytes: 6388
#include<stdio.h>
#include<stdlib.h>

int h;

int p(int i);
int l(int i);
int r(int i);
void swap(int *a, int *b);
void maxHeapify(int *A, int i);
void buildMaxHeap(int *A);

int main(){
  int i,*A;
  scanf("%d",&h);
  A=malloc(sizeof(int)*(h+1));
  for(i=1;i<=h;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A);
  for(i=1;i<=h;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

int p(int i){
  return i/2;
}

int l(int i){
  return i*2;
}

int r(int i){
  return i*2+1;
}

void swap(int *x,int *y){
  int temp;
  temp=*x;
  *x=*y;
  *y=temp;
}

void maxHeapify(int *A, int i){
  int left,right,largest;
  left=l(i);
  right=r(i);
  if(left<=h&&A[left]>A[i]){
    largest=left;
  }
  else{
    largest=i;
  }
  if(right<=h&&A[right]>A[largest]){
    largest=right;
  }
  if(largest!=i){
    swap(&A[i],&A[largest]);
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=h/2;i>0;i--){
    maxHeapify(A,i);
  }
}



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

int main()
{
    int x,y;
    cin>>x>>y;
    int a,b,c;
    a=x+y;
    b=x*y;
    c=x-y;
    int maxx;
    maxx=max(a,b);
    maxx=max(maxx,c);
    cout<<maxx<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
using namespace std;

std::array<int, 200001> aaaa;

int main() {

	for (int i = 0;i < 200000; i++) {
		aaaa[i] = 0;
	}
	int N, K;
	int n = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		if (aaaa[a - 1] == 0)n++;
		aaaa[a - 1]++;
	}

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

	int r = 0;
	for (int i = 200000 - n + 1; i < 200000 - K + 1; i++) {
		r += aaaa[i];
	}
	cout << r;

	return 0;
}

Measured memory_bytes: 1024
S = [int(x) if x != '?' else '?' for x in input()]
length = len(S)

A = [0] * 13
B = [0] * 13
mod = 5
first = 0
r = 1

for i in range(length):
    a = S[length - i- 1]
    if a != '?':
        a = (a * r) % 13
        mod -= a
        mod %= 13

    elif first == 0:
        for j in range(10):
            a = (j * r) % 13
            A[a] += 1
        first = 1

    else:
        for j in range(10):
            a = (j * r) % 13
            for k in range(13):
                B[(k + a) % 13] += A[k]
                B[(k + a) % 13] %= 10 ** 9 + 7
        A = B
        B = [0] * 13
    r = (r * 10) % 13

if first == 0 and mod == 0:
    print(1)
elif first == 0 and mod != 0:
    print(0)
else:
    print(A[mod])


Measured memory_bytes: 47468
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int H,W,i,j=0,m,n,k;
	char s[120][120],a[120];
    for (i=0;i<=105;i++)
	for (k=0;k<=105;k++)
	s[i][k]='#';
	scanf ("%d%d",&H,&W);
	getchar();
    for (m=1;m<=H;m++)
    {
        gets(a);
        j++;
        for (k=1;k<=W;k++)
        s[j][k]=a[k-1];
    }
    for (j=0;j<H+2;j++)
    {
        for (i=0;i<=W+1;i++)
        printf("%c",s[j][i]);
        printf("\n");
    }
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::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==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}


int main(void) {
	int64 N;
	cin >> N;
	vector<vector<int64>> v(N, vector<int64>(N, -1));
	REP(i, N) {
		int64 A;
		cin >> A;
		REP(j, A) {
			int64 x, y;
			cin >> x >> y;
			v[i][x-1] = y;
		}
	}
	int64 res = 0;
	REP(i, 1 << N) {
		bool ok = 1;
		REP(j, N) {
			if (i >> j & 1) {
				REP(k, N) {
					if (v[j][k] != -1 && (i >> k & 1) != v[j][k]) ok = 0;
				}
			}
		}
		if (ok) chmax(res, __builtin_popcountll(i));
	}
	cout << res << endl;
}


Measured memory_bytes: 256
h, n = map(int, input().split())
ab = []
for i in range(n):
    ab.append(list(map(int, input().split())))
###一次元DP
dp = [100000000] * (h+1)
dp[0] = 0
for i in range(1, h+1):
    for j in range(n):
        a = ab[j][0]
        b = ab[j][1]
        # print(i, j)
        temp = i - a
        if temp < 0:
            temp = 0
        need_magic = dp[temp] + b
        if need_magic < dp[i]:
            dp[i] = need_magic
        # dp[i] = min(dp[i], dp[max(i-a, 0)] + b)
        # print(i, j, a, b, dp)
print(dp[-1])

Measured memory_bytes: 42220
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  n = int(input())
  if n%2==0:
    print(n)
  else:
    print(n*2)
  
  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 5244
#include <iostream>
#include <cmath>

int main()
{
	long long int n, a, buff;
	double n_sqrt;

	std::cin >> n;
	a = n + 1;
	n_sqrt = std::sqrt(n);

	for (long long int i = 1; i <= n_sqrt; i++)
	{
		if (n % i == 0)
		{
			buff = n / i + i - 2;
			if (buff < a)
			{
				a = buff;
			}
		}
	}
	std::cout << a << std::endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String[] s = new String[3];
			s[0] = sc.next();
			if(s[0].compareTo("0")==0)break;
			s[1] = sc.next();
			s[2] = sc.next();
			int[][] map = new int[3][3];
			
			for(int i=0;i<3;i++){
				for(int j=0;j<3;j++){
					String t = s[i].substring(j,j+1);
					if(t.compareTo("b")==0){
						map[i][j] = 1;
					}else if(t.compareTo("w")==0){
						map[i][j] = 2;
					}
				}
			}
			
			int count;
			int ans = 0;
			for(int k=1;k<3;k++){
				for(int i=0;i<3;i++){
					count = 0;
					for(int j=0;j<3;j++){
						if(map[i][j]==k)count++;
					}
					if(count==3){
						ans=k;
						break;
					}
				}
				for(int i=0;i<3;i++){
					count = 0;
					for(int j=0;j<3;j++){
						if(map[j][i]==k)count++;
					}
					if(count==3){
						ans=k;
						break;
					}
				}
				
				if(map[1][1]==k){
					if((map[0][2]==k && map[2][0]==k) || (map[0][0]==k && map[2][2]==k))ans=k;
				}
	
			}
			
			if(ans==1){
				System.out.println("b");
			}else if(ans==2){
				System.out.println("w");
			}else{
				System.out.println("NA");
			}
			
		}
	}	
}

Measured memory_bytes: 17184
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N,C=get_i
ch=Array.new(C){[]}
N.times do|i|
    s,t,c=get_i.map{|x| x-=1}
  ch[c]<<[s,t]
end
imos=array(10**5+2,0,C)
ch.each_with_index do|arr,i|
  table=array(10**5+1,0)
  arr.each do|s,t|
      if table[s].zero?
        table[s]+=1
      else
        table[s]=0
      end
      if table[t+1].zero?
        table[t+1]-=1
      else
        table[t+1]=0
      end
  end  
  imosi=imos[i]
  (10**5+1).times do|j|
      imosi[j+1]=imosi[j]+table[j]
  end
end
#C.times do|i|
    #p imos[i][0..20]
#end
ans=0
(10**5+1).times do|i|
    val=0
    C.times do|j|
      val+=max(min(imos[j][i],1),0)
    end
    ans=max(ans,val)
end
puts ans

Measured memory_bytes: 69160
from collections import Counter
N = int(input())
tmp = list(input())
da = Counter(tmp)
for _ in range(N-1):
    tmp = list(input())
    tmpd = Counter(tmp)
    for k, v in da.items():
        if not tmpd[k]:
            da[k] = 0
        else:
            da[k] = min(v, tmpd[k])
ans = ""
for k, v in da.items():
    ans += str(k)*v
a = "".join(sorted(ans))
print(a)


Measured memory_bytes: 9340
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

int partition(int A[], int p, int r) {
	int x = A[r];
	int i = p - 1;
	for (int j = p; j < r ; j++) {
		if (A[j] <= x) {
			i++;
			int tmp = A[i];
			A[i] = A[j];
			A[j] = tmp;
		}
	}
	int tmp = A[i + 1];
	A[i + 1] = A[r];
	A[r] = tmp;
	return i + 1;
}

int main() {
	int n;
	static int A[100000];
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> A[i];
	int q = partition(A, 0, n - 1);
	for (int i = 0; i < n; i++) {
		if (i) cout << ' ';
		if (i == q) cout << '[';
		cout << A[i];
		if (i == q) cout << ']';
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3420
#include<bits/stdc++.h>
#define pi 3.1415  
#define ll long long
#define pii pair<int,int>
#define debug(a) cout<<a<<'\n'
#define maxn 2009
#define MOD 1000000007
#define INF (int)3000009
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll vet[maxn];
    for(int i=0;i<n;i++){
        cin>>vet[i];
    }
    ll anst=0;
    sort(vet,vet+n);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ll ans1=-1;
            ll ini=j+1,mid,fim=n-1;
            while(ini<=fim){
                mid=(ini+fim)>>1;
                if(vet[mid]<vet[i]+vet[j]){
                    ans1=mid;
                    ini=mid+1;
                }
                else fim=mid-1;
            }
            if(ans1!=-1){
                anst+=ans1-j;
            }
        }
    }
    cout<<anst<<endl;
    return 0;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;

	vector<int> v(N, K);
	for (int i = 0; i < Q; i++) {
		int n;
		cin >> n;
		v[n - 1]++;
	}

	for (int i = 0; i < N; i++) v[i] -= Q;

	for (int i = 0; i < N; i++) {
		int n = v[i];
		if (n > 0) cout << "Yes" << endl;
		else cout << "No" << endl;
		//cout << n << endl;
	}
}

Measured memory_bytes: 3768
import math
#余弦定理を用いる
a , b , C = map(float , input() . split())
C_rad = math.pi*C/180 #角度(入力C)を度からラジアンに変換
print("{0:.8f}".format(math.sin(C_rad) * a * b/2))
print("{0:.8f}".format(a + b + math.sqrt(a**2 + b**2 - 2 * a * b * math.cos(C_rad))))
print("{0:.8f}".format(b * math.sin(C_rad)))


Measured memory_bytes: 5692
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    X,K,D =map(int,input().split())
    X= abs(X)
    if X >= K*D:
        print(X-K*D)

    else:
        c =X//D
        if (K-c)%2  ==0:
            print(X-c*D)
        else:
            print(D*(c+1)-X)








if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,m;cin>>n>>m;
  vector<vector<ll>>v(m);
  rep(i,0,m){
    ll a;cin>>a;
    rep(j,0,a){
      ll b;cin>>b;
      v[i].push_back(--b);
    }
  }
  bool p[m];rep(i,0,m)cin>>p[i];


  ll ans=0;
  rep(bit,0,(1<<n)){
    bool e=true;
    rep(i,0,m){
      ll count=0;
      // out(i<<":"<<v[i].size());
      rep(j,0,v[i].size()){
        // if((bit>>v[i][j])&1)count++;
        if(bit&(1<<v[i][j]))count++;
      }
      if(count%2!=p[i])e=false;
    }
    if(e)ans++;
  }

  out(ans);

  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))
using ll = long long;
using namespace std;

const int MAXV = 301;

ll d[MAXV][MAXV];  // d[u][v]は辺e=(u,v)のコスト, （存在しない場合はINF, ただしd[i][i]=0とする）
ll d2[MAXV][MAXV];
int V;

void warshall_floyd() {
    for (int k=0; k<V; ++k) {
        for (int i=0; i<V; ++i) {
            for (int j=0; j<V; ++j) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
    }
}

void warshall_floyd2() {
    for (int k=0; k<V; ++k) {
        for (int i=0; i<V; ++i) {
            for (int j=0; j<V; ++j) d2[i][j] = min(d2[i][j], d2[i][k] + d2[k][j]);
        }
    }
}

ll a[50001], b[50001], c[50001];

int main() {
    ll M, L;
    cin >> V >> M >> L;

    fill(d[0], d[V], 1e14);
    fill(d2[0], d2[V], 1e14);
    rep(i, V) d[i][i] = 0;
    rep(i, V) d2[i][i] = 0;

    rep(i, M) {
        cin >> a[i] >> b[i] >> c[i];
        if (c[i] > L) continue;
        a[i]--; b[i]--;
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }

    warshall_floyd();

    rep(i, V) {
        rep(j, V) {
            if (i == j) continue;
            if (d[i][j] <= L) {
                d2[i][j] = d2[j][i] = 1;
            }
        }
    }

    warshall_floyd2();


    int q;
    cin >> q;
    rep(i, q) {
        int s, t;
        cin >> s >> t;
        s--; t--;
        if (d[s][t] == 1e14) cout << -1 << endl;
        else cout << d2[s][t]-1 << endl;
    }

    // rep(i, V) {
    //     rep(j, V) cout << d[i][j] << " ";
    //     cout << endl;
    // }
}


Measured memory_bytes: 2944
use proconio::input;

fn main() {
    input! {
        n: usize,
    };
    let ans = match n % 10 {
        2 | 4 | 5 | 7 | 9 => "hon",
        0 | 1 | 6 | 8 => "pon",
        3 => "bon",
        _ => unreachable!(),
    };
    println!("{}", ans);
}


Measured memory_bytes: 2108
#include<iostream>
#include<vector>
#define MOD 1000000007
using namespace std;
int fast_pow(int base, int n, int M){
	if (n == 0) return 0;
	if (n == 1)return base;
	int halfn = fast_pow(base, n / 2, M);
	if (n % 2 == 0)  return ((long long)halfn*halfn) % M;
	else return ((((long long)(halfn) * halfn) % M)*base) % M;
}
int findMMI(int n, int M){
	return fast_pow(n, M - 2, M);
}
int modDiv(int numerator, int denominator, int M){
	int denMMI = findMMI(denominator, M);
	return ((long long)(numerator)*denMMI) % M;
}

class PerandCom{
public:
	PerandCom(int lmt, int mod){
		M = mod;
		modFact.push_back(1);
		for (int i = 1; i <= lmt; ++i){
			modFact.push_back(int(((long long)(modFact.back())*i) % M));
		}
	}
	int nCr(int n, int r){
		return modDiv(modFact[n], ((long long)(modFact[r]) * modFact[n - r]) % M, M);
	}
	int nPr(int n, int r){
		return modDiv(modFact[n], modFact[n - r], M);
	}
private:
	vector<int>modFact;
	int M;
};
int main()
{
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	PerandCom pAc(h + w, MOD);
	long long ans = 0;
	for (int t = 1; t <= h - a; ++t){
		ans +=((long long)pAc.nCr(b + t - 2, b - 1)*pAc.nCr(w - b + h - t - 1, w - b - 1));
		ans %= MOD;
	}
	cout << ans << endl;
	cin >> a;
	return 0;
}

Measured memory_bytes: 1400
import numpy as np
 
N = int(input())
A_i = np.array(list(map(int, input().split())))
stu = [[nums+1,student] for nums, student in enumerate(A_i)]
 
emp = np.full(N, np.nan)
for i, j in stu:
    emp[j-1] = i

print(*emp.astype('int'), sep=" ")

Measured memory_bytes: 36176
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp io.Reader) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 500001), 500000)
	return sc
}

func getHugeScanner(fp io.Reader, size int) *bufio.Scanner {
	sc := bufio.NewScanner(fp)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, size), size)
	return sc
}

func getNextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func getNextInt(sc *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(sc))
	return i
}

func getNextInt64(sc *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(sc), 10, 64)
	return i
}

func getNextFloat64(sc *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(sc), 64)
	return i
}

func Solve(stdin io.Reader, stdout io.Writer) {
	sc := getScanner(stdin)

	n := getNextInt(sc)
	k := getNextInt(sc)

	v := make([]int, n)
	for i := 0; i < n; i++ {
		v[i] = getNextInt(sc)
	}

	max := 0
	for l := 0; l <= k; l++ {
		for r := 0; r <= k - l; r++ {
			if l + r > n {
				continue
			}

			list := []int{}
			for i := 0; i < l; i++ {
				list = append(list, v[i])
			}
			for i := n - 1; i >= n - r; i-- {
				list = append(list, v[i])
			}

			sort.Ints(list)

			for i := 0; i < k - l - r; i++ {
				if len(list) == 0 {
					break
				}
				if list[0] < 0 {
					list = list[1:]
				} else {
					break
				}
			}

			tmp := 0
			for i := 0; i < len(list); i++ {
				tmp += list[i]
			}
			if tmp > max {
				max = tmp
			}
		}
	}

	_, _ = fmt.Fprintf(stdout, "%v\n", max)
}

func main() {
	Solve(os.Stdin, os.Stdout)
	return
}

Measured memory_bytes: 1664
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

using state=string::const_iterator;
ll expr(state &);
ll term(state &);
ll fuct(state &);
ll expr(state &s)
{
    ll ret = term(s);
    while (true) {
        char opr = *(s++);
        ll arg = term(s);
        if (opr == '+') {
            if (ret == 2 || arg == 2)ret = 2;
            else if (ret == 1 || arg == 1)ret = 1;
            else ret = 0;
        } else if (opr == '*') {
            if (ret == 0 || arg == 0)ret = 0;
            else if (ret == 1 || arg == 1)ret = 1;
            else ret = 2;
        } else {
            break;
        }
    }
    return ret;
}
ll term(state & s)
{
    if (*s == '-') {
        ++s;
        return 2 - term(s);
    } else {
        return fuct(s);
    }
}
ll fuct(state & s)
{
    if (*s == '(') {
        ++s;
        ll ret = expr(s);
        return ret;
    } else if (isdigit(*s)) {
        ll ret = *s - '0';
        ++s;
        return ret;
    }
}
int main()
{
    while (true) {
        string inp = in<string>();
        if (inp[0] != '.') {
            ll ans = 0;
            for (char p = '0'; p <= '2'; ++p) {
                for (char q = '0'; q <= '2'; ++q) {
                    for (char r = '0'; r <= '2'; ++r) {
                        string exstr = inp;
                        replace(ALL(exstr), 'P', p);
                        replace(ALL(exstr), 'Q', q);
                        replace(ALL(exstr), 'R', r);
                        auto s = exstr.cbegin();
                        ans += expr(s) == 2;
                    }
                }
            }
            cout << ans << endl;
        } else {
            break;
        }
    }
}


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

using namespace std;

#define mod 1000000007

int main()
{
	int n;
	cin >> n;
	int cnt[100001] = {};
	int ans = 0;
	for(int i = 0; i < n; i++){
		int tmp;
		cin >> tmp;
		if(tmp > n) ans++;
		else cnt[tmp]++;
	}
	for(int i = 1; i <= n; i++){
		if(cnt[i] < i) ans += cnt[i];
		else if(cnt[i] > i) ans += cnt[i] - i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
# AGC 027 A - Candy Distribution Again
N, x = map(int,input().split())
an = list(map(int,input().split()))

ak =[] 
while len(an) > 0:
    ak.append(min(an))
    del an[an.index(min(an))]

count = 0
for i in range(N):
    if x > 0:
        x -= ak[i]
        if i != N-1:
            count += 1
        if i == N-1:
            if x == 0:
                count += 1
            else:
                break
    if x < 0:
        count -= 1
        break

    if x == 0:
        break
print(count)

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

struct pt{
	int x,y,k;
};

vector<vector<bool>> v(1001,vector<bool> (1001));
int h,w,ret=0;
deque<pt> q;
vector<pair<int,int>> dir={{0,1},{1,0},{-1,0},{0,-1}};

int bfs(){
	while (!q.empty()){
		auto f=q.front();
		ret=max(ret,f.k);
		q.pop_front();
		for (auto& i:dir){
			int nx=i.first+f.x,ny=f.y+i.second;
			if (nx < h and ny < w and nx >= 0 and ny >= 0 and !v[nx][ny]){
				v[nx][ny]=true;
				q.emplace_back(pt{nx,ny,f.k+1});
			}
		}
	}
	return ret;
}

int main(){
	char c;
	cin >> h >> w;
	for (int i=0; i<h; ++i){
		for (int j=0; j<w; ++j){
			cin >> c;
			if (c == '#'){
				q.emplace_back(pt{i,j,0});
				v[i][j]=true;
			}
		}
	}
	cout << bfs();
	return 0;
}

Measured memory_bytes: 12560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
vector<vector<int>> dp(5010,vector<int>(5010)),dp2(5010,vector<int>(5010));
int main(){
    ll n,maxk;cin >> n >>maxk;
    vector<int> v(n);rep(i,n)cin >> v[i];
    ll ans=0;
    //vector<vector<int>> dp(n+1,vector<int>(maxk));
    dp[0][0]=1;
    rep(j,n){
        rep(k,maxk){
            dp[j+1][k]+=dp[j][k];
            if(k+v[j]<maxk)dp[j+1][k+v[j]]+=dp[j][k];
        }
    }
    //vector<vector<int>> dp2(n+1,vector<int>(maxk));
    dp2[n][0]=1;
    per(j,n){
        rep(k,maxk){
            dp2[j][k]+=dp2[j+1][k];
            if(k+v[j]<maxk)dp2[j][k+v[j]]+=dp2[j+1][k];
        }
    }
    rep(i,n){
        bool need=false;
        vector<int> st;
        rep(j,maxk)if(dp2[i+1][j])st.pb(j);
        rep(j,maxk){
            if(dp[i][j]){
                ll z=lower_bound(all(st),maxk-j)-lower_bound(all(st),maxk-j-v[i]);
                if(z)need=true;
            }
        }
        if(!need)ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 199932
/*                                  /   \                                                                   (Hello)//JSM//*/      
/*                                 /*****\                                                                              */
/*     Jai Shree Mataji           /       \ |\| |_| $ |-| K                                                            */
#include<vector>
#include<iostream>
#include<algorithm>                
#include<string.h>                 
#include<bits/stdc++.h>            
#include<cstring>                  
#include<map>                     
#include<cmath>                  
#include<set>
using namespace std;            
#define ll long long int        
#define ld long double
#define MOD 1000000007 
#define PI 3.1415926535897932384626433832795                                               
#define YY cout<<"YES"
#define NN cout<<"NO"
#define EE cout<<"\n"
#define ee cout<<"\n"
#define ne cout<<"-1"
#define pb push_back 
#define ff first
#define ss second
#define mkp make_pair    
#define mkt make_tuple
#define sall(v ) sort(v.begin(), v.end())      
#define all(v )  v.begin(), v.end()      
#define fo(i , n) for(ll i = 0 ; i < n ; i++)
#define vl vector<ll>
#define vc vector<char> 
#define vll vector< pair<ll,ll> > 
#define pr pair<ll,ll>
#define mps map<string ,ll>
#define mpc map<char ,char>
#define mpl map<ll,ll>
#define tpl tuple<ll,ll,ll>
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);	
	  ll t=1;
//	   cin>>t;
	      while(t--)
{


/*
3
1 1 3*/
ll n,i,j,k,l;
cin>>n;
ll a[n];
fo(i,n)
cin>>a[i];
sort(a,a+n);
ll mi=1001001;
for(i=a[0];i<=a[n-1];i++)
{
	ll c=0;
	for(j=0;j<n;j++)
	{
		c+=(a[j]-i)*(a[j]-i);
	}
	mi=min(mi,c);
}
cout<<mi;
ee;


}
return 0;
}



Measured memory_bytes: 3660
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    int ans = 0;
    rep(i, N) {
        cin >> A[i];
        rep(j, 32) {
            int a = pow(2, j);
            if (A[i] % a != 0) {
                ans += j - 1;
                break;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4064
#include <iostream>
 
using namespace std;
const int N = 1e5 + 4;
int arr[N];
int main()
{
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
 
    /// try to decrease the hight from right to left when element[i-1] > element[i].
    for(int i = n - 1; i > 0; i--)
    {
        if(arr[i - 1] > arr[i])
        {
            arr[i-1] -= 1;
        }
    }
    /// test the work by going from left to right if at any point of time the element[i-1] > element[i] cout NO.
    bool acheive = true;
    for(int i = 1; i < n; i++)
    {
        if(arr[i-1] > arr[i])
        {
            cout << "No" << endl;
            acheive = false;
            break;
        }
    }
    if(acheive)
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/agc007_a.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int H, W;
vector<vector<char>> r;

bool dfs(vector<vector<char>> &c, int h, int w, vector<vector<char>> d) {
  d[h][w] = '#';
  if (h == H - 1 && w == W - 1) {
    r = d;
    return true;
  }
  bool ok = false;
  if (h + 1 < H && c[h + 1][w] == '#') {
    ok |= dfs(c, h + 1, w, d);
  }
  if (w + 1 < W && c[h][w + 1] == '#') {
    ok |= dfs(c, h, w + 1, d);
  }
  return ok;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  cin >> H >> W;

  vector<vector<char>> c(H, vector<char>(W));
  vector<vector<char>> d(H, vector<char>(W, '-'));
  rep(i, H) rep(j, W) { cin >> c[i][j]; }
  bool ok = dfs(c, 0, 0, d);

  int cntr = 0, cntc = 0;
  if (ok) {
    rep(i, H) rep(j, W) {
      if (c[i][j] == '#') cntc++;
      if (r[i][j] == '#') cntr++;
    }
    ok = cntc == cntr;
  }
  cout << (ok ? "Possible" : "Impossible") << endl;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,arr[100],ma=0,i;
    vector <int> vec;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&arr[i]);
        vec.push_back(arr[i]);
    }
    sort(vec.begin(),vec.end());
    int cnt=0;
    for(i=0;i<n;i++){
        if(arr[i]!=vec[i]){
            cnt++;
        }
    }
    if(cnt<=2){
        printf("YES\n");
    }
    else{
        printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  long int n,a,b;
  cin>>n>>a>>b;
  if(a>b)
    cout<<0<<endl;
  else if(n==1){
    if(a!=b)
      cout<<0<<endl;
    else
      cout<<1<<endl;
  }
  else if(n==2 or a==b){
      cout<<1<<endl;
  }
  else{
    cout<<(b-a)*(n-2)+1<<endl;
  }
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    q = collections.deque()
    r = 0
    for c in s:
        if q and q[-1] != c:
            r += 2
            q.pop()
        else:
            q.append(c)

    return r



print(main())




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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N;
	cin >> N;
	vector<string> s(N);
	rep(i,N) cin >> s[i];
	int M;
	cin >> M;
	vector<string> t(M);
	rep(i,M) cin >> t[i];
	map<string, int> m;
	rep(i,N) m[s[i]]++;
	rep(i,M) m[t[i]]--;
	int ans=0;
	for(auto itr:m) ans=max(ans,itr.second);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
void log(A...)(A arg) { stderr.writeln(arg); }
int size(T)(in T s) { return cast(int)s.length; }

void main() {
    int N, X; readf("%d %d\n", &N, &X);
    auto A = readln.chomp.split(" ").map!(to!int).array;
    long ans = 0;
    if (A[0] > X) {
        ans += A[0] - X;
        A[0] = X;
    }
    for (int i = 1; i < N; i++) {
        ans += max(0, A[i] + A[i - 1] - X);
        A[i] = min(A[i], X - A[i - 1]);
    }
    //log(A);
    writeln(ans);
}


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

typedef long long ll;
using namespace std;

int main(){
    ll m=1e9+7,ans=0,l,t=1;
    string s;
    cin>>s;
    l=s.size();
    vector<ll> v(l);v[l-1]=1;
    for(int i=l-2;i>=0;i--) v[i]=(v[i+1]*3)%m;
    
    for(int i=0;i<l;i++){
        if(s[i]-'0') {
            ans+=v[i]*t;
            ans%=m;
            t<<=1;t%=m;
        }
    }
    ans+=t;
    cout<<ans%m;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const ll INF = 1LL << 60; //MAX 9223372036854775807
ll ans = INF;

int main()
{
ll n , k , q ;
cin >> n >> k >> q ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
rep(i,n){
  ll mi=a[i];
  vector<ll> v;
  vector<ll> te;
  rep(j,n+1){
    if(j==n||a[j]<mi){
      if(te.size()>=k){
        sort(te.begin(),te.end());
        rep(l,te.size()-k+1)v.push_back(te[l]);
      }
      te.clear();
    }
    else{
      te.push_back(a[j]);
    }
  }
  sort(v.begin(),v.end());
  if(v.size()>=q)ans=min(ans,v[q-1]-v[0]);
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
const int MAX1=11000;
int S[MAX1];
int n,q,T;

int linearsearch(int A[],int num,int key){
	int i=0;
	A[num]=key;
	while(A[i]!=key)i++;
	return i!=num;
}
int main() {
	int k,cnt;
	cnt=0;
	cin>>n;
	for(k=0;k<n;++k){
		cin>>S[k];
	}
	cin>>q;
	for(k=0;k<q;++k){
		cin>>T;
		if(linearsearch(S,n,T))cnt++;
		}

	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3132