akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (ll i = a; i < b; i++)
ll cnt[100005];
ll b[1000005], c[100005];

int main()
{
    int n, q;
    ll a;
    cin >> n;

    ll sum = 0;
    rep(i, 0, n)
    {
        cin >> a;
        cnt[a]++;
        sum += a;
    }
    cin >> q;
    rep(i, 0, q)
    {
        cin >> b[i] >> c[i];
    }
    rep(i, 0, q)
    {
        ll num = cnt[b[i]];
        rep(j, 0, num)
        {
            sum += (c[i] - b[i]);
            cnt[b[i]]--;
            cnt[c[i]]++;
        }
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 5980
import math

#n = int(input())
n, d= [int(i) for i in input().split()]
table = [[int(i) for i in input().split()] for j in range(n)]
#table = [list(input()) for n in range(h)]
#list = [int(i) for i in input().split()]
#num = [int(i) for i in range(n)]
#s = [input() for i in range(n)]
#s = input()
#list = list(s)
#temp = [[0 for _ in range(13)] for _ in range(13)]

ans = 0

for i in range(n-1) :
    for j in range(i+1,n):
        dis = 0
        for k in range(d):
            dis += (table[i][k] - table[j][k]) ** 2
        for k in range(127):
            if (k**2 == dis) :
                ans += 1

print(ans)

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

int main() {
    int N, L;
    cin >> N >> L;
    int sum;
    if (L <= 0 && L+N-1 >= 0) sum = N*(2*L + N - 1) / 2;
    else if(L > 0) sum = N*(2*L + N - 1) / 2 - L;
    else sum = (N-1)*(2*L + N - 2) / 2;
  
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] k = new int[m];
		int[] s = new int[m];
		for(i = 0; i <m; i++) {
			k[i] = Integer.parseInt(sc.next());
			s[i] = 0;
			for(j = 0; j <k[i]; j++) {
				int aa = 1 << (Integer.parseInt(sc.next()) -1);
				s[i] |= (aa);
			}
		}
		int[] p = new int[m];
		for(i = 0; i <m; i++) {
			p[i] = Integer.parseInt(sc.next());
		}
		sc.close();
		sc = null;
		int max = (int) Math.pow(2, n);
		int cnt = 0;
		for(i = 0; i <max; i++) {
			for(j = 0; j <m; j++) {
				if(Integer.bitCount(s[j] & i) % 2 != p[j] ) {
					break;
				}
			}
			if(j == m) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
i,j,k,s;
main(x)
{
  char a[99],b[99];
  for(scanf("%s%d",a,&x);x--;)
    {
      scanf("%s",b);
      for(i=0;i<10;i++)
	{
	  k=0;
	  if(a[k]==b[i])
	    {
	      for(j=i;1;)
		{
		  j++;
		  k++;
		  j=j>9?0:j;
		  if(a[k]=='\0')
		    {s++;i=11;break;}
		  if(a[k]!=b[j])
		    break;
		}
	    }
	}
    }
  printf("%d\n",s);
  exit(0);
}

Measured memory_bytes: 0
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define AMAX 10000

int main( void ){
  unsigned short *A, *B;
  int C[AMAX+ 1];
  int n, i,j;
  scanf("%d",&n);

  A = malloc( sizeof( short ) * n + 1);
  B = malloc( sizeof( short ) * n + 1);

  for( i = 0 ; i <= AMAX ; i++){
    C[i] = 0;
  }
  for( i = 0 ; i < n ; i++ ){
    scanf("%hu",&A[i + 1]);
    C[A[i + 1]]++;
  }
  for( i = 1 ; i <= AMAX ; i++ ){
    C[i] += C[i - 1];
  }
  for( j = 1 ; j <= n ; j++ ){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }
  for( i = 1 ; i <= n ; i++ ){
    if( i > 1 ){
      printf(" ");
    }
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 8464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0; i<n; i++){
      cin >> x.at(i);
  }
auto tml = minmax_element(x.begin(), x.end());
int min=1000000000;
for(int i=*tml.first; i<=*tml.second; i++){
    int total=0;
    for(int j=0; j<n; j++){
        total+=(i-x.at(j))*(i-x.at(j));
    }
    if (total<min) min=total;
}
cout << min << endl;
  return 0;
}


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

#define ll long long int
#define str string
#define ALL(a)  (a).begin(),(a).end()

ll MOD = 1000000007, INFL = 1ll << 60, INF = 1 << 30, mod = 1e9 + 7, Max = INF, Min = -1;
ll a = 0, b = 0, c = 0, n = 0, m = 0, high = 0, sum = 0, MASK = 0;
ll A[500000] = {}, B[500000] = {}, C[500000] = {}, dp[200000][3], rui[500000] = {}, bitdp[1 << 12] = {};
int dy[] = { 0, 0, 1, -1 }, dx[] = { 1, -1, 0, 0 };
vector<ll> va, vb, vc;
str S, T;
bool check = true, check2 = false;


int main() {
	//Code Line
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		va.push_back(a);
	}
	for (int i = 0; i < n; i++) {
		cin >> a;
		vb.push_back(a);
	}
	for (int i = 0; i < n; i++) {
		cin >> a;
		vc.push_back(a);
	}

	sort(ALL(va));
	sort(ALL(vb));
	sort(ALL(vc));

	for (int i = 0; i < n; i++) {
		auto a = lower_bound(ALL(va), vb[i]);
			auto c = upper_bound(ALL(vc), vb[i]);
			sum += (a-va.begin()) * (n-(c-vc.begin()));
		
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 3316
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

const int N=100005;

int n,cnt,a1,a2,a3,mx,c1,c2,c3,mn;
int a[N];

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n); cnt=1;
	for (i=1;i<n;i++) if (a[i]!=a[i+1]) cnt++;
	if (cnt==1){
		if (a[1]==0) printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	if (cnt==2){
		for (i=1;i<n;i++)
			if (a[i]!=a[i+1]){
				c1=i,c2=n-i;
				break;
			}
		if (a[1]!=0){
			printf("No\n");
			return 0;
		}
		if (c2==c1*2) printf("Yes\n");
		else printf("No\n");
		return 0;
	}
	if (cnt!=3){
		printf("No\n");
		return 0;
	}
	a1=a[1]; a3=a[n];
	for (i=1;i<n;i++) if (a[i]!=a[i+1]){
		a2=a[i+1];
		break;
	}
	if ((a1^a3)!=a2){
		printf("No\n");
		return 0;
	}
	for (i=1;i<=n;i++){
		if (a[i]==a1) c1++;
		if (a[i]==a2) c2++;
		if (a[i]==a3) c3++;
	}
	if (c1==c2&&c3==c2) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
// Right Triangle

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;


int main() {
    int a, b ,c;
    cin >> a >> b >> c;
    cout << a * b / 2 << endl;
}


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
// #define int long long
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000               // 2e9
#define LLINF 2000000000000000000ll  // 2e18 (llmax:9e18)
#define fi first
#define sec second
#define all(x) (x).begin(), (x).end()
#define sq(x) ((x) * (x))
#define dmp(x) cerr << #x << ": " << x << endl;

template <class T>
void chmin(T &a, const T &b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, const T &b) {
  if (a < b) a = b;
}

template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template <class T>
vector<T> vect(int len, T elem) {
  return vector<T>(len, elem);
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << p.fi << ',' << p.sec;
  return os;
}
template <class T, class U>
istream &operator>>(istream &is, pair<T, U> &p) {
  is >> p.fi >> p.sec;
  return is;
}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 < vec.size()) os << ' ';
  }
  return os;
}
template <class T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) is >> vec[i];
  return is;
}
void fastio() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
}

void solve() {
  ll N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(A, N % (A + B)) << endl;
  return;
}

signed main() {
  fastio();
  solve();
  // int t; cin >> t; while(t--)solve();
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<char> vec(n);
  rep(i, n) vec.at(i) = s.at(i);
  int count = 0;
  rep(i,vec.size()-1) {
    if(vec.at(i) == vec.at(i+1)) count++;;
  }
  cout << n - count << endl;
  return 0;
}

Measured memory_bytes: 512
// --------------------<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<bits/stdc++.h>
using namespace std;
#define int long long
#define d long double
#define pii pair<int,int>
#define pb push_back
#define pf push_front
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 1003
#define inf LLONG_MAX
#define hahaha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
//int mod=998244353;
char a[M][M];
int n,m,ans=0,dp[M][M];

int recur(int i,int j,int &cnt)
{
    if(dp[i][j])
        return dp[i][j];
    
    if(i==n and j==m)
    {
        cnt=(cnt+1)%mod;
        return dp[i][j]=cnt;
    }
    if(a[i][j+1]=='.')
        dp[i][j]=(dp[i][j]+recur(i,j+1,cnt))%mod;
    if(a[i+1][j]=='.')
        dp[i][j]=(dp[i][j]+recur(i+1,j,cnt))%mod;
    
    return dp[i][j];
}   

signed main()
{
    hahaha
    
    memset(dp,0,sizeof dp);
    cin>>n>>m;
    int i,j,k;
    for(i=1;i<=n;++i)
        for(j=1;j<=m;++j)
            cin>>a[i][j];
    
    dp[1][1]=1;
    for(i=1;i<=n;++i)
        for(j=1;j<=m;++j)
            if(a[i][j]=='.')
                dp[i][j]=(dp[i][j]+dp[i-1][j])%mod,dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
                
    cout<<dp[n][m];    
    //int cnt=0;
    //cout<<recur(1,1,cnt);
    
        
    return 0;
}


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

int main() { 
	int n, y, i, j, k;
	cin >> n >>y;
	for(i=0;i<=y/10000;i++){
		for(j=0;j<=y/5000;j++){
			k=n-i-j;
			if(k>=0 && 10000*i+5000*j+1000*k==y){
				cout << i << ' ' << j << ' ' << k << endl;
				return 0;
			}
		}
	}
 	cout << "-1" << ' ' << "-1"<< ' ' << "-1" << endl;
	return 0; 
} 

Measured memory_bytes: 256
import math

a, b, x = list(map(float, input().split()))
s = x / a
if(s * 2 > a * b):
    print(math.degrees(math.atan(2*(a*b-s)/(a*a)))) 
elif(s * 2 == a * b):
    print(45.0)
else:
    print(math.degrees(math.atan(b*b/(2*s))))


Measured memory_bytes: 3060
import bisect
import sys
sys.setrecursionlimit(10**7)

def dfs(v):
  pos=bisect.bisect_left(dp,arr[v])
  changes.append((pos,dp[pos]))
  dp[pos]=arr[v]
  ans[v]=bisect.bisect_left(dp,10**18)
  for u in g[v]:
    if checked[u]==0:
      checked[u]=1
      dfs(u)
  pos,val=changes.pop()
  dp[pos]=val

n=int(input())
arr=[0]+list(map(int,input().split()))
g=[[] for _ in range(n+1)]
for _ in range(n-1):
  a,b=map(int,input().split())
  g[a].append(b)
  g[b].append(a)
ans=[0]*(n+1)
checked=[0]*(n+1)
checked[1]=1
dp=[10**18 for _ in range(n+1)]
changes=[]
dfs(1)
for i in range(1,n+1):
  print(ans[i])

Measured memory_bytes: 239676
#include <iostream>
using namespace std;
int main()
{
	int digit = 0;
	int number;
	int a;
	cin >> number;
	a = number;
	while (number != 0) {
		number = number / 10;
		++digit;
	}
	int sum = 0;
	if (digit == 1)
	{
		cout << a;
	}
	else
	{
		for (int i = 1; i < digit; i++)
		{
			if (i % 2 == 1)
			{
				int t = 1;
				{
					
					for (int j = 0; j < i-1; j++)t = t * 10;
				}
				sum += t*10 - 1 - t + 1;
			}

		}
		if (digit % 2 == 1)
		{
			int t = 1;
			{

				for (int j = 0; j < digit - 1; j++)t = t * 10;
			}
			sum += a - t + 1;
		}
		cout << sum;
	}
	
	return 0;
}

Measured memory_bytes: 256
x, n = gets.split.map(&:to_i)
if n == 0
    puts x
    return
end
arr = gets.split.map(&:to_i)

ans = nil
diff = 0

loop do
  unless arr.include?(x - diff)
      ans = x - diff
      break
  end
  unless arr.include?(x + diff)
      ans = x + diff
      break  
  end
  diff += 1
end

puts ans

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

int main() {
    int n, neg = 0;
    long long sum[2], a[10000];
    vector<int> ans;
    cin >> n;
    sum[0] = sum[1] = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i] > 0){
            neg = -1;
            sum[i%2] += a[i];
        }else if(neg != -1){
            if(a[i] > a[neg]){
                neg = i;
            }
        }
    }
    
    if(neg != -1){
        cout << a[neg] << endl;
        cout << n-1 << endl;
        
        for(int i=0;i<neg;i++){
            cout << 1 << endl;
        }
        for(int i=n-neg;i>1;i--){
            cout << i << endl;
        }
        return 0;
    }
    
    if(sum[0] < sum[1]){
        for(int i=0;i<n;i+=2)a[i] = -1;
    }else{
        for(int i=1;i<n;i+=2)a[i] = -1;
    }
    for(int i=n-1;i>0;i--){
        if(a[i] < 0){
            ans.push_back(i+1);
            continue;
        }
        if(i >= 3){
            if(a[i-2] < 0){
                ans.push_back(i-1);
                a[i-2] = a[i];
                i--;
            }else{
                ans.push_back(i);
                a[i-2] += a[i];
                i--;
            }
        }else if(i == 1){
            ans.push_back(1);
            a[i-1] = a[i];
        }else if(a[i-2] < 0){
            ans.push_back(1);
            ans.push_back(1);
            a[i-2] = a[i];
            break;
        }else{
            ans.push_back(i);
            a[i-2] += a[i];
            break;
        }
    }
    cout << a[0] << endl;
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << endl;
    }
	return 0;
}

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

ans = 0
#Num1:
A = [0 for i in range(9)] # r_0 g_1 b_2 rg_3 rb_4 gr_5 gb_6 br_7 bg_8
for i in S:
  if i == 'R':
    A[0] += 1 # r
    A[5] += A[1] # gr = g + [r]
    A[7] += A[2] # br = b + [r]
    ans += A[6] + A[8] # gb[r], bg[r]
  elif i == 'G':
    A[1] += 1 # g
    A[3] += A[0] # rg = r + [g]
    A[8] += A[2] # bg = b + [g]
    ans += A[4] + A[7] # rb[g], br[g]
  else: # i == 'B'
    A[2] += 1 # b
    A[4] += A[0] # rb = r + [b]
    A[6] += A[1] # gb = g + [b]
    ans += A[3] + A[5] # rg[b], gr[b]
#  print(A, ans)
    
#Num2:
for i in range(1, (N+1)//2):
  for j in range(0, N - 2 * i):
    if S[j] != S[j+i] and S[j] != S[j+2*i] and S[j+i] != S[j+2*i]:
      ans -= 1
      
print(ans)

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

using namespace std;
using LL = long long;

int main() {
	
	ios_base :: sync_with_stdio(0); cin.tie(NULL);

	string a;
	cin >> a;

	if (a == "ABC")
		cout << "ARC" << '\n';
	else cout << "ABC" << '\n';	


	return 0;	
}

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

#define mp       make_pair
#define mt	  make_tuple
#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF=1<<29;
const double EPS=1e-9;
const ll MOD = 1000000007;

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

const int MAX_NM = 100100;
int N,M;
vector<int> X;
int mod_count[MAX_NM];
int ans;
bool is_pair[MAX_NM];
int pair_count[MAX_NM];
int main(){
  cin >> N >> M;
  X.resize(N);
  set<int> number;
  for (int i = 0; i < N; i++){
    cin >> X[i];
    mod_count[X[i] % M]++;
    if (is_pair[X[i]]){
      pair_count[X[i] % M]++;
      is_pair[X[i]] = false;
    }else{
      is_pair[X[i]] = true;
    }
  }
  sort(X.begin(), X.end());
  ans = 0;
  int res= mod_count[0] / 2;
  mod_count[0] -= 2 * res;
  ans += res;
  //mod_count[0] = 0;
  if (M % 2 == 0){
    int res = mod_count[M / 2] / 2;
    ans += res;
    mod_count[M / 2] -= 2 * res;
  }
  for (int i = 1; i < (M + 1) / 2; i++){
    int a = mod_count[i];
    int b = mod_count[M - i];
    int c = min(a, b);
    ans += c;
    mod_count[i] -= c;
    mod_count[M - i] -= c;
    if (mod_count[i] > 0){
      ans += min(mod_count[i] / 2, pair_count[i]);
    }else if (mod_count[M - i] > 0){
      ans += min(mod_count[M - i] / 2, pair_count[M - i]);
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;

const int N=300005;

struct ST{
	int l,r,mx;
}t[2][N<<2];
struct node{
	int l,r;
}q[N];
int n,cnt,ans,inf,m,x,y;
int b[N],dp[N],s[N];

void update(int tp,int k){
	t[tp][k].mx=max(t[tp][k<<1].mx,t[tp][k<<1|1].mx);
}

void build(int tp,int k,int l,int r){
	t[tp][k].l=l; t[tp][k].r=r;
	t[tp][k].mx=inf;
	if (l==r) return;
	int mid=(l+r)>>1;
	build(tp,k<<1,l,mid);
	build(tp,k<<1|1,mid+1,r);
	update(tp,k);
}

int query(int tp,int k,int L,int R){
	if (L<=t[tp][k].l&&t[tp][k].r<=R) return t[tp][k].mx;
	int mid=(t[tp][k].l+t[tp][k].r)>>1;
	if (R<=mid) return query(tp,k<<1,L,R);
	else if (L>mid) return query(tp,k<<1|1,L,R);
	else return max(query(tp,k<<1,L,R),query(tp,k<<1|1,L,R));
}

void modify(int tp,int k,int p,int w){
	if (t[tp][k].l==t[tp][k].r){
		t[tp][k].mx=max(t[tp][k].mx,w);
		return;
	}
	int mid=(t[tp][k].l+t[tp][k].r)>>1;
	if (p<=mid) modify(tp,k<<1,p,w);
	else modify(tp,k<<1|1,p,w);
	update(tp,k);
}

bool cmp(node a,node b){
	return a.l<b.l||(a.l==b.l&&a.r<b.r);
}

int main(){
	int i;
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		scanf("%d",&b[i]);
		if (b[i]==0) cnt++,b[i]=-1;
		s[i]=s[i-1]+b[i];
	}
	scanf("%d",&m);
	for (i=1;i<=m;i++) scanf("%d%d",&q[i].l,&q[i].r);
	sort(q+1,q+1+m,cmp);
	memset(dp,-0x3f,sizeof(dp)); inf=dp[0];
	build(0,1,1,n);
	build(1,1,1,n);
	ans=0;
	for (i=1;i<=m;i++){
		x=q[i].l; y=q[i].r;
		dp[i]=s[y]-s[x-1];
		if (x>1) dp[i]=max(dp[i],query(0,1,1,x-1)+s[y]-s[x-1]);
		if (y>x) dp[i]=max(dp[i],query(1,1,x,y-1)+s[y]);
		modify(0,1,y,dp[i]);
		modify(1,1,y,dp[i]-s[y]);
		ans=max(ans,dp[i]);
	}
	printf("%d\n",n-cnt-ans);
	return 0;
}

Measured memory_bytes: 20352
s=input()
if s=='SAT':
    print('1')
elif s=='FRI':
    print('2')
elif s=='THU':
    print('3')
elif s=='WED':
    print('4')
elif s=='TUE':
    print('5')
elif s=='MON':
    print('6')
else:
    print('7')


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

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

	vector<int> h(N);
	for(int i=0; i<N; ++i) cin >> h[i];

	sort(h.begin(), h.end());

	int ans = (int)1e9 + 1;
	for(int i=0; i+K-1<N; ++i){
		ans = min(ans, h[i+K-1] - h[i]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <numeric> //lcm
#include <iomanip> //double精度 setprecision


#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = n-1; i >= 0; --i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define all(vec) (vec).begin(),(vec).end()

#define debug(vec) for(auto v : vec) cout << v << " "; cout << endl;
#define debug2D(vec2D) for(auto vec : vec2D) { for (auto v : vec) cout << v << " "; cout << endl; } 

using namespace std;

typedef long long ll;

const ll INF = 1000000000; //10^10
//const ll MOD = 998244353;
const ll MOD = 1000000007;

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

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

	//int t; cin >> t;

	//rep(test, t) {
	//int;
	string _s;
	cin >> _s;

	int s[4];
	rep(i,4) s[i] = _s[i] - '0';

	int a = 10*s[0] + s[1], b = s[2]*10 + s[3]; 

	if (1 <= a && a <= 12 && 1 <= b && b <= 12) cout << "AMBIGUOUS" << endl;
	else if (1 <= a && a <= 12) cout << "MMYY" << endl;
	else if (1 <= b && b <= 12) cout << "YYMM" << endl;
	else cout << "NA" << endl;
}

Measured memory_bytes: 256
def base_change(numbers,base,keta):
    s=""
    while numbers>0:
        a,b=divmod(numbers,base)
        if b==0:
            s+="0"
            numbers=a
        elif b!=0:
            s+=str(b)
            numbers=a
    if len(s)<keta:
        s+="0"*(keta-len(s))
    elif len(s)>keta:
        print("桁がどうやら足りないようです。桁をもう少し数が収まるように大きく取ってください　。")
    s=s[::-1]
    return s
#C - Synthetic Kadomatsu
n,A,B,C=map(int,input().split())
lists=[int(input()) for i in range(n)]   
mini=10**9
for i in range(4**(n)):
    alist=[0,0,0,0]
    counterlist=[0,0,0,0]
    S=base_change(i,4,n)
    for i in range(n):
        for j in range(3):
            if S[i]==str(j):
                alist[j]+=lists[i]
                counterlist[j]+=1
    if all(counterlist[j]>0 for j in range(3)):
        mini=min(mini,10*(sum(counterlist[:3])-3)+abs(alist[0]-A)+abs(alist[1]-B)+abs(alist[2]-C))
print(mini)  

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> S(N);
    rep(i, 0, N) cin >> S[i];
    ll ans = 0;
    rep(C, 1, N) {
        ll now_ans = 0;
        if ((N - 1) % C) {
            for (int x = 0; N - 1 - C * x > C; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
        else {
            for (int x = 0; N - 1 - C * x > C * x; ++x) {
                now_ans += S[C * x] + S[N - 1 - C * x];
                ans = max(ans, now_ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  char s[3];
  cin>>s[0]>>s[1]>>s[2];
  int max=0, locmax=0;
  for(int i=0;i<3;i++){
    if(s[i] == 'R'){
      locmax++;
    }
    else{
      locmax=0;
    }
    if(locmax>max){
      max=locmax;
    }
  }
  cout<<max;
}
      


Measured memory_bytes: 3544
#include <stdio.h>

int main() {
	int A, B, C;
	scanf("%d%d%d",&A,&B,&C);
	if ((A==B&&B!=C)|| (C == B && B != A)||(A == C && B != C)) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	return 0;
}

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

#define MP make_pair
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0;i<(n);i++)
#define REP1(i,n) for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n) for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;
    if(K <= N){
        cout << K*X + (N-K)*Y << endl;
    }else{
        cout << N*X << endl;
    }
}


Measured memory_bytes: 256
import numpy as np

D = int(input())
Cs = list(map(int, input().split()))
Ss = []
for d in range(D):
    s = list(map(int, input().split()))
    Ss.append(s)

Ss = np.array(Ss)

solution = np.argmax(Ss, axis=1)

days_till_next = np.ones_like(Ss) * (D - 1) - np.arange(D).reshape((D, 1))


def update_days_till_next(d, erase=False):
    contest = solution[d]
    delta = days_till_next[d + 1, contest] + 1 if d < D - 1 else 0
    days_till_next[d, contest] = delta
    for _d in range(d - 1, -1, -1):
        if solution[_d] == contest or _d == 0:
            days_till_next[_d:d, contest] = (d - _d) - np.arange(d - _d) + (delta if erase else 0)
            break


def update_days_till_next_old(d):
    contest = solution[d]
    if d < D - 1:
        days_till_next[d, contest] = days_till_next[d + 1, contest] + 1
    for _d in range(d - 1, -1, -1):
        if solution[_d] == contest or _d == 0:
            days_till_next[_d:d, contest] = (d - _d + 1) - np.arange(d - _d)
            break

for d in range(D - 1, -1, -1):
    update_days_till_next(d)

for _ in range(400):
    n_contests = len(Ss[0])
    days_since_last = np.zeros(n_contests)
    for d, i in enumerate(solution):
        days_since_last += 1
        new_scores = days_till_next[d] * days_since_last * Cs + Ss[d]
        new_i = new_scores.argmax()
        days_since_last[new_i] = 0
        if new_i != i:
            update_days_till_next(d, erase=True)
            solution[d] = new_i
            update_days_till_next(d)


for s in solution:
    print(s + 1)

# with open("test.out", "w") as f:
#     f.writelines("\n".join(list(map(str, solution + 1))))


Measured memory_bytes: 27828
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
vector<int> E[maxn];
#define mp(a, b) make_pair(a, b)
typedef pair<int, int> pii;
int ans;
void check(pii & x, int y)
{
	if(y > x.first) 
	{
		x.second = x.first;
		x.first = y;
	}
	else if (y > x.second) x.second = y;
}
int dfs(int x, int fa)
{
	pii Max = mp(-1, -1);
	for(auto v : E[x])
		if(v != fa)
			check(Max, dfs(v, x));
	++Max.first;
	++Max.second;
	ans = max(ans, Max.first + Max.second);
	return Max.first;
}
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i < n; ++i)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs(1, 0);
	++ans;
	if((ans - 2) % 3)
		puts("First");
	else
		puts("Second");
	return 0;
}

Measured memory_bytes: 23168
import java.util.Scanner;
class Main{

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

int a;
int b;
int c;
int hantei = 0;

a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();

if(a<b){
	hantei++;
}else{
	hantei = 0;
}

if(a<c){
	hantei++;
}else{
	hantei = 0;
}

if(b<c){
	hantei++;
}else{
	hantei = 0;
}
if(hantei==3){
	System.out.println("Yes");
}else{
	System.out.println("No");
}

    }
}

Measured memory_bytes: 26236
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    ll n;
    cin >> n;
    vector<ll> p(n),q(n);
    ll cnt1=0,cnt2=0;
    rep(i,n){
        cin >> p[i];
        p[i]--;
    }
    q=p;
    rep(i,n){
        if(i==n-1 && p[i]==i){
            swap(p[i-1],p[i]);
            cnt1++;
            continue;
        }
        if(p[i]==i){
            swap(p[i],p[i+1]);
            cnt1++;
        }
    }
    rep(i,n){
        if(i==n-1 && q[n-i-1]==n-i-1){
            swap(q[n-i-1],q[n-i]);
            cnt2++;
            continue;
        }
        if(q[n-i-1]==n-i-1){
            swap(q[n-i-1],q[n-i-2]);
            cnt2++;
        }
    }
    ll cnt=min(cnt1,cnt2);
    cout << cnt << endl;
}


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

int main(void)
{
    int r, c, a[100][100];
    
    cin >> r >> c;
    
    for (int i = 0; i < r; ++i) {
        
        for (int j = 0; j < c; ++j) {
            cin >> a[i][j];
            cout << a[i][j] << " ";
        }
        cout << accumulate(a[i], a[i]+c, 0.0) << endl;
    }
    
    int sum1 = 0;
    for (int j = 0; j < c; ++j) {
        int sum2 = 0;
        for (int i = 0; i < r; ++i) {
            sum2 += a[i][j];
        }
        sum1 += sum2;
        cout << sum2 << " ";
    }
    cout << sum1 << endl;
    
    return 0;
}


Measured memory_bytes: 3284
#include<iostream>
#include<stdlib.h>
  
using namespace std;
  
struct Node {
  int key;
  Node* next;
  Node* prev;
};
  
struct List {
  Node* nil;

  void init(){
    nil = (Node*) malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
    nil->key = 0;
  }

  Node* find(int key) {
    for(Node* i = nil->next; i != nil; i = i->next) {
      if(i->key == key) {
        return i;
      }
    }
    return nil;
  }

  void insert(Node* x) {
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
  }

  void add(int x) {
    Node* p = (Node*) malloc(sizeof(Node));
    p->key = x;
    insert(p);
  }

  void deleteNode(Node* x) {
    if (x == nil) {
      return;
    }
    x->prev->next = x->next;
    x->next->prev = x->prev;
    free(x);
  }

  void delete_x(int key) {
    Node* x = find(key);
    deleteNode(x);
  }

  void deleteFirst() {
    Node* x = nil->next;
    deleteNode(x);
  }

  void deleteLast() {
    Node* x = nil->prev;
    deleteNode(x);
  }

  void output(){
    int flg = 0;
    for(Node* i = nil->next; i!=nil; i=i->next) {
      if(flg) {
        cout << ' ';
      }
      cout << i->key;
      flg = 1;
    }
    cout << endl;
  }
};
  
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  List list;
  list.init();

  int N, x;
  string str;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> str;
    if (str == "insert") {
      cin >> x;
      list.add(x);
    } else if (str == "delete") {
      cin >> x;
      list.delete_x(x);
    } else if (str == "deleteFirst") {
      list.deleteFirst();
    } else {
      list.deleteLast();
    }
  }
  list.output();
}


Measured memory_bytes: 34456
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
//#include <chrono>
using namespace std;

int main()
{
  int N; cin >> N;
  string stmp;
  double dtmp;
  double jpy, bit;
  jpy = bit = 0;
  for(int i = 0; i < N; i++){
    cin >> dtmp >> stmp;
    if(stmp.compare("BTC") == 0){
		bit+=dtmp;
    }else if(stmp.compare("JPY") == 0){
      jpy+=dtmp;
    }
  }
  cout << (jpy+bit*380000) << endl;
  return 0;
}


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

int main()
{
    int n;
    cin>>n;
    double A[n];
    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    double dp[n+1][n+1];
    for(int i=0;i<=n;i++){
        dp[0][i] = 0.0;
    }
        dp[0][0] = 1.0;
    dp[1][0] = (1-A[0]);
    for(int j = 2;j<=n;j++){
        dp[j][0] = dp[j-1][0]*(1-A[j-1]);
    }
    for(int i=1;i<=n;i++){
        for(int j = 1;j<=i;j++){
            dp[i][j] = dp[i-1][j]*(1-A[i-1]) + dp[i-1][j-1]*(A[i-1]);
        }
    }
    double ans  = dp[n][n];
    int i = ((n+1)/2);
    for(int j = i;j<n;j++){
        ans+=dp[n][j];
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
	return 0;
}

Measured memory_bytes: 70144
#include <bits/stdc++.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
    int h,w;
    cin >> h >> w;
    char grid[h+1][w+1];
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
            cin >> grid[i][j];
    vector<vector<ll>> dp (h+1,vector<ll>(w+1));
    dp[0][1] = 1;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(grid[i][j] == '#') dp[i][j] = 0;
            else dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    }
    cout << dp[h][w] << endl;
    return 0;
}/////////////////////////////

Measured memory_bytes: 12212
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
       
        ll a,b,c,k;cin>>a>>b>>c>>k;ll sum;
        sum=min(a,k);
        k=k-min(a,k);
        k=k-min(b,k);
        sum-=min(c,k);
        cout<<sum;

}


Measured memory_bytes: 3656
A, B, K = map(int, input().split())

if B - A + 1 <= 2 * K:
    for i in range(A, B + 1):
        print(i)
else:
    for i in range(A, A + K):
        print(i)
    for i in range(B - K + 1, B + 1):
        print(i)


Measured memory_bytes: 3060
#include <stdio.h>
#include <bits/stdtr1c++.h>

#define clr(ar) memset(ar, 0, sizeof(ar))
#define read() freopen("lol.txt", "r", stdin)
#define dbg(x) cout << #x << " = " << x << endl
#define ran(a, b) ((((rand() << 15) ^ rand()) % ((b) - (a) + 1)) + (a))

using namespace std;

struct Point{
    long long x, y;
    Point(){}
    Point(long long x, long long y) : x(x), y(y){}
} ar[10];

void print(int n){
    printf("%d\n", n);
    for (int i = 0; i < n; i++) printf("%lld %lld\n", ar[i].x, ar[i].y);
}

long long area(Point poly[], int n){
    long long res = 0;
    for (int i = 0, j = n - 1; i < n; j = i++){
        res += ((poly[j].x + poly[i].x) * (poly[j].y - poly[i].y));
    }
    return abs(res);
}

long long extended_gcd(long long a, long long b, long long& x, long long& y){
    if (!b){
        y = 0, x = 1;
        return a;
    }

    long long g = extended_gcd(b, a % b, y, x);
    y -= ((a / b) * x);
    return g;
}

int main(){
    int t, i, j;
    long long a, x, y, z, g, xmax, ymax;

    scanf("%d", &t);
    while (t--){
        scanf("%lld %lld", &xmax, &ymax);
        g = extended_gcd(xmax, ymax, x, y);
        ar[0] = Point(0, 0), ar[1] = Point(abs(x), abs(y)), ar[2] = Point(xmax, ymax);

        a = area(ar, 3);
        if (a > 0 && a <= 50000 && ar[1].x <= xmax && ar[1].y <= ymax) print(3);
        else{
            ar[0] = Point(0, 0), ar[1] = Point(abs(y), abs(x)), ar[2] = Point(xmax, ymax);
            a = area(ar, 3);
            if (a > 0 && a <= 50000 && ar[1].x <= xmax && ar[1].y <= ymax) print(3);
            else{
                ar[0] = Point(0, 0), ar[1] = Point(xmax - 1, ymax), ar[2] = Point(xmax / g, ymax / g), ar[3] = Point(xmax, ymax - 1);
                a = area(ar, 4);
                assert(a > 0 && a <= 50000);
                print(4);
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3228
N,M,Q=map(int,input().split())
L=[]
for i in range(Q):
  L.append(list(map(int,input().split())))
  L[i][0]-=1
  L[i][1]-=1
#print(L)
import itertools
R=list(range(1,M+1))#ここで変数Lを使っていた
A=list(itertools.combinations_with_replacement(R,N))
ans=0
#print(L)変数を上書きしていた！！！！！
for i in A:
  tmp=0  
  for a,b,c,d in L:
    if (i[b]-i[a])==c:
      tmp+=d
  ans=max(ans,tmp)
print(ans)

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

int main() {
  int64_t N, A,B;
  cin >> N>>A>>B;
  
  int64_t count = N/(A+B)*A;
  int64_t ans = N%(A+B);
  count += min(ans, A);
  
  cout << count <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll n;
	cin>>n;
	vector<ll> vec(n,0);
	for(ll i=0;i<n;i++) cin>>vec[i];
	ll count=0;
	for(ll i=1;i<n-1;i++){
		vector<ll> v;
		v.push_back(vec[i-1]);
		v.push_back(vec[i]);
		v.push_back(vec[i+1]);
		sort(v.begin(),v.end());
		if(v[1]==vec[i]){
			count++;
		}
	}
	cout<<count<<endl;
}

Measured memory_bytes: 384
from itertools import accumulate

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

dp = [[0]*(K+1) for _ in range(N+1)]
dp[0][0] = 1
MOD = 10**9+7

for i,a in enumerate(A):
    ac = [0] + list(accumulate(dp[i]))
    for j in range(K+1):
        dp[i+1][j] = (ac[j+1] - ac[max(0,j-a)]) % MOD
print(dp[-1][-1])

Measured memory_bytes: 174728
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) (v).begin(), (v).end()



int main() {
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}

	ll num_C = 0;
	fori(i, 2, s.size() - 1) {
		if (s[i] == 'C') ++num_C;
	}
	if (num_C != 1) {
		cout << "WA" << endl;
		return 0;
	}

	num_C = 0;
	rep(i, s.size()) {
		ll tmp = s[i] - 'A';
		if (0 <= tmp && tmp < 26) ++num_C;
	}
	if (num_C != 2) {
		cout << "WA" << endl;
		return 0;
	}

	cout << "AC" << endl;
	return 0;



}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll N;
ll i, j, k;
ll dp[1010101][10];
ll ans;
int main(){
    scanf("%lld", &N);
    ans = 0;
    ll a = 0;
    dp[0][0] = 2;
    rep(i,0,N){
        rep(j,0,3){
            if(j<2){
                (dp[i+1][j + 1] += dp[i][j]) %= MOD;
            }
            (dp[i + 1][j] += dp[i][j] * (8 + j)) %= MOD;
        }
    }
    printf("%lld\n", dp[N][2]);

    return 0;
}

Measured memory_bytes: 81728
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, H: "List[int]"):
    H = sorted(H, reverse=True)[K:]

    print(sum(H))


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    H = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, H)

if __name__ == '__main__':
    main()


Measured memory_bytes: 30588
#include <stdio.h>
int main(){
	int n, m, x, y, i;
	if(scanf("%d", &n)== 1);
	m = 1;
	i = (unsigned int)(n/2);
  
  	for(x=1; x<=i; ++x){
  		y = n - x;
          if(n - y != y){
			++m;
          }
	 	}
    m = m - 1;
	printf("%d\n", m);
    
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
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; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int X;
	cin >> X;
	if (X >= 400 && X <= 599)cout << "8";
	else if (X >= 600 && X <= 799)cout << "7";
	else if (X >= 800 && X <= 999)cout << "6";
	else if (X >= 1000 && X <= 1199)cout << "5";
	else if (X >= 1200 && X <= 1399)cout << "4";
	else if (X >= 1400 && X <= 1599)cout << "3";
	else if (X >= 1600 && X <= 1799)cout << "2";
	else if (X >= 1800 && X <= 1999)cout << "1";
}

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

int main(){
	int n;
	cin >> n;
	vector<int> v(8,0);
	int count=0;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;	
		if(a<400) v[0]++;
		else if (a<800) v[1]++;
		else if (a<1200) v[2]++;
		else if (a<1600) v[3]++;
		else if (a<2000) v[4]++;
		else if (a<2400) v[5]++;
		else if (a<2800) v[6]++;
		else if (a<3200) v[7]++;
		else count++;
	}
	int current1 = 0;
	for(int x: v) if (x>0) current1 ++;
	if(current1==0)cout << 1;
	else cout << current1;
	cout << " " << current1+count;
     
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <deque>
#include <bitset>
#include <climits>
#include <cstdio>
#include <list>
#include <iomanip>
using namespace std;

#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define AS 200001
#define mod 1000000007
ll dp[3001][3001][2];
ll solve(vector<int>&v, int i, int j, bool turn) {
	if (i > j)
		return 0;
	if (dp[i][j][turn] != -1)
		return dp[i][j][turn];
	if (turn == 1)
		return dp[i][j][turn] = max(v[i] + solve(v, i + 1, j, 0), v[j] + solve(v, i, j - 1, 0));
	else
		return dp[i][j][turn] = min(solve(v, i + 1, j, 1), solve(v, i, j - 1, 1));
}
int main() {
	fastIO
	int n;
	cin >> n;
	vector<int>ar;
	ar.resize(n + 1);
	ll sum = 0;
	F1(ar, n);
	for (int i = 1; i <= n; i++) {
		sum += ar[i];
	}
	memset(dp, -1, sizeof dp);
	ll scoreX = solve(ar, 1, n, 1);
	ll scoreY = (sum - scoreX);
	cout << scoreX - scoreY;
	//P1(ar, n);
}

Measured memory_bytes: 141184
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int k = arr[0];
    int s = arr[1];
    int cnt = 0;
    for (int x = 0; x <= k; x++) {
      for (int y = 0; y <= k; y++) {
        int z = s - x - y;
        if (0 <= z && z <= k) cnt++;
      }
    }
    Console.WriteLine(cnt);
  }
}

Measured memory_bytes: 13268
package main

import (
	"bufio"
	"fmt"
	"io"
	"log"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	h, w := io.NextInt(), io.NextInt()
	stage := make([]string, h)
	for i := 0; i < h; i++ {
		stage[i] = io.Next()
	}
	ans := solve(h, w, stage)
	io.Println(ans)
}

var logger = log.New(os.Stderr, "", 0)

func solve(h, w int, stage []string) (ans int) {
	visited := make([][]bool, h)
	for i := range visited {
		visited[i] = make([]bool, w)
	}
	for x := 0; x < h; x++ {
		for y := 0; y < w; y++ {
			if visited[x][y] {
				continue
			}
			ans += bfs(x, y, visited, stage)
		}
	}
	return ans
}

func bfs(x, y int, visited [][]bool, stage []string) int {
	h, w := len(stage), len(stage[0])
	count := make(map[byte]int, 2)
	q := newQueue()
	visited[x][y] = true
	count[stage[x][y]]++
	q.push(pair{x, y})
	for len(*q) > 0 {
		p := q.pop()
		for i := range dx {
			nx, ny := p.x+dx[i], p.y+dy[i]
			if nx < 0 || h <= nx || ny < 0 || w <= ny {
				logger.Println("continue: out of range", nx, ny)
				continue
			}
			if visited[nx][ny] {
				logger.Println("continue: already visited", nx, ny)
				continue
			}
			if stage[nx][ny] == stage[p.x][p.y] {
				logger.Println("continue: same color", nx, ny)
				continue
			}
			logger.Printf("visit: (%d,%d)->(%d,%d)\n", p.x, p.y, nx, ny)
			visited[nx][ny] = true
			count[stage[nx][ny]]++
			q.push(pair{nx, ny})
		}
	}
	return count['#'] * count['.']
}

type pair struct{ x, y int }

type queue []pair

func newQueue() *queue {
	return &queue{}
}

func (q *queue) push(p pair) {
	*q = append(*q, p)
	logger.Println("push:", p)
}

func (q *queue) pop() pair {
	p := (*q)[0]
	*q = (*q)[1:]
	logger.Println("pop:", p)
	return p
}

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

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 31152
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main(){
    vector<int> sosu;
    bool check[10000]{false};
    for(int i=2;i<10000;++i){
        if(!check[i]){
            sosu.push_back(i);
            for(int j=i*2;j<10000;j+=i){
                check[j]=true;
            }
        }
    }
    sosu.push_back(1000000000);
    int time;
    cin>>time;
    int dummy;
    int answer=time;
    int ch;
    vector<int>::iterator place;
    for(int i=0;i<time;++i){
        cin>>dummy;
        if(dummy==2)continue;
        ch=sqrt((double)dummy)+1;
        for(place=sosu.begin();*place<=ch;++place){
            if(dummy%*place==0){
                --answer;
                break;
            }
        }
    }
    cout<<answer<<endl;
    return 0;
}

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

int main() {
	int n,temp=0,gokei=0;cin>>n;
  	for(int i=0;i<n;i++){
    	cin>>temp;
      	gokei+=temp;
    }
  	if(gokei%2==0) cout<<"YES"<<endl;
  	else  cout<<"NO"<<endl;
}


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

ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }

ll count(ll a, ll b, ll d) { return b / d - (a - 1) / d; }

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

  ll ans = count(a, b, c) + count(a, b, d) - count(a, b, lcm(c, d));
  cout << ((b - a + 1) - ans) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <algorithm>
#include <functional>
#include <vector>
#include <iomanip>

#include<math.h>
using namespace std;

int x[8], y[8];

int factorial(int n){
  if (n <= 1) return 1;
  else return n*factorial(n-1);
}

int main(void)
{
  int N;
  cin >> N;
  for (int i = 0; i < N; i++){
    cin >> x[i] >> y[i];
  }
  long double d = 0.0;
  vector<int> v(N);
  for (int i = 0; i < N; i++){
    v[i] = i+1;
  }
  do {
    for (int i = 0; i < N-1; i++){
      d += sqrt( (long double)( (x[v[i]-1] - x[v[i+1]-1]) * (x[v[i]-1] - x[v[i+1]-1]) +
                (y[v[i]-1] - y[v[i+1]-1]) * (y[v[i]-1] - y[v[i+1]-1]) ) );
      //cout << d << endl;
    }
  } while (next_permutation(v.begin(), v.end()));
  
  d /= factorial(N);
  cout << setprecision(20) << d << endl;
  return 0;
}

Measured memory_bytes: 384