akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fo(a,b,c) for(int i=a;i<b;i+=c)  
typedef pair<ll , pair<ll, ll> > pi;
int pow(int x,int y){
    int res=1;
    while(y){
        if(y&1) res*=x;
        y>>=1;
        x*=x;
    }
    return res;
}   
struct Compare {
    constexpr bool operator()(pi const & a,
                              pi const & b) const noexcept
    { return a.first < b.first || (a.first == b.first && a.second.first > b.second.first); }
 
};
void prefix_function( string s,ll arr[] )
{
     long long border=0; arr[0]=0;
    for(long long i=1;i<s.size();i++)
    {
      while(border>0 && s[i]!=s[border])
        border=arr[border-1];
     
     if(s[i]==s[border])
         border++;
      else
       border=0;
      
      arr[i]=border;
    }
}
ll mod=998244353;
ll add( ll a , ll b)
{
    return (((a%mod)+(b%mod))%mod);
}
ll mul(ll a,ll b)
{
  return (((a%mod)*(b%mod))%mod);
}
//send mod-2 for a^-1 if mod is a prime number
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1) res = mul(res, a);
        a = mul(a, a);
        b >>= 1;
    }
    return res;
}
ll dsu_arr[100000];
ll dsu_sz[100000];
void dsu(ll n)
{
    for(ll i=0;i<=n;i++)
    {
        dsu_arr[i]=i;
        dsu_sz[i]=1;
    }
}
ll find(ll x)
{
     ll root=x;
    while (root!=dsu_arr[root])
    {
        root=dsu_arr[root];
    }
    while(x!=dsu_arr[x])
    {
        dsu_arr[x]=root;
        x=dsu_arr[x];
    }
    return root;
}
ll merge(ll x,ll y)
{
    ll root1=find(x);
    ll root2=find(y);
    
    if(root1==root2)
    return 0ll;
 
    if(dsu_sz[x]>dsu_sz[y]){
    dsu_arr[root2]=root1;
    dsu_sz[x]+=dsu_sz[y];
    }
    else
    {
         dsu_sz[y]+=dsu_sz[x];
        dsu_arr[root1]=root2;
    }
    return 1ll;
}


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


}



   
      
    
        



Measured memory_bytes: 3632
/*
[ ( ^ _ ^ ) ]
*/
// problem: atc/abc165_c
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1000000000

int n, m, q;
ll rs = 0;
vector<vector<int>> con(60, vector<int>(4));
vector<int> a(15);

void dfs(int last, int idx) {
    if(idx>n) {
        ll s = 0;
        for(int i=0; i<q; i++) {
            if(a[con[i][1]] - a[con[i][0]] == con[i][2]) {
                s += con[i][3];
            }
        }
        rs = max(rs, s);
        return;
    }
    for(int i=last; i<=m; i++) {
        a[idx] = i;
        dfs(i, idx+1);
    }
}

int main() {
    scanf("%d%d%d", &n, &m, &q);
    for(int i=0; i<q; i++) {
        scanf("%d %d %d %d", &con[i][0], &con[i][1], &con[i][2], &con[i][3]);
    }
    rs = 0;
    dfs(1, 1);
    printf("%lld\n", rs);
}


Measured memory_bytes: 3796
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
	
		int i;
	Outer : { for(i = 0; i < s.length()-1; i++)
				for(int j = i+1; j < s.length(); j++)
					if(s.charAt(i) == s.charAt(j))
						break Outer;
			}
		if(i == s.length()-1)
			System.out.println("yes");
		else 
			System.out.println("no");
	}
}

Measured memory_bytes: 23252
n = int(input())
l = list(input().strip())

lb, lw, rb, rw = 0, 0, l.count("#"), l.count(".")


ans = lb+rw
for i in range(len(l)):
    if l[i] == "#":
        lb += 1
        rb -= 1
    else:
        lw += 1
        rw -= 1

    ans = min(ans, lb+rw)
print(ans)


Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[405][405];
const ll INF = 1e18+5; 
int main() {
    int n;
    cin>>n;
    vector<ll> a(n),sum(n+1,0);
    for(int i =0;i<n;i++) {
        cin>>a[i];
        sum[i+1] = sum[i] + a[i];
    }
    auto get = [&](int l,int r) {
        return sum[r+1] - sum[l];
    };
    for(int l = n-1;l>=0;l--) {
        for(int r = l;r<n;r++) {
            if(l == r) {
                dp[l][r] = 0;
            } else {
                dp[l][r] = INF;
                for(int i = l;i<=r-1;i++) {
                    dp[l][r] = min(dp[l][r],dp[l][i] + dp[i+1][r] + get(l,r));
                }
            }
        }
    } 
    cout<<dp[0][n-1]<<"\n";   
}

Measured memory_bytes: 4884
/*by freesteed*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get_be(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
//get_be biger & equal
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const ll oo=1e9+10;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
//ll a[Max];
ll n,m;
//SUN, MON, TUE, WED, THU, FRI, or SAT.
void solve(){
	string s;
	cin>>s;
	if(s=="Sunny")cout<<"Cloudy";
	else if(s=="Cloudy")cout<<"Rainy";
	else cout<<"Sunny";
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}





Measured memory_bytes: 256
def gcd(x,y):
  n,m = min(x,y), max(x,y)
  while n!=0:
    n, m = m%n, n
  
  return m

def prime_factorization(N):
  f = 2
  p_f = []
  while N%f==0:
    p_f.append(f)
    N //= f
  f = 3
  while f**2 <= N:
    if N%f==0:
      p_f.append(f)
      N //= f
    else: f+=2
  if N!=1: p_f.append(N)
  return p_f

A, B = list(map(int, input().split(" ")))
print(1+len(set(prime_factorization(gcd(A, B)))))

Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline


def main():
    n, q = map(int, input().split())

    g = [[] for _ in range(n)]
    for _ in range(n - 1):
        ai, bi = map(int, input().split())
        g[ai - 1].append(bi - 1)
        g[bi - 1].append(ai - 1)

    ans = [0] * n
    for _ in range(q):
        pi, xi = map(int, input().split())
        ans[pi - 1] += xi

    def dfs(v, p=-1):
        for u in g[v]:
            if u == p:
                continue
            ans[u] += ans[v]
            dfs(u, v)

    dfs(0)
    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 268416
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int N, K, a;
    vector<long long> HP;
    long long result = 0;
    cin >> N >> K;

    for (int i = 0; i < N; i++) {
        cin >> a;
        HP.push_back(a); 
    }
    sort(HP.begin(), HP.end());
    if (HP.size() > K) {
        for (int i = 0; i < K; i++) {
            HP.pop_back();
        }
        int num = HP.size();
        for (int i = 0; i < num; i++) {
            result += HP.at(i);
        }
        cout << result << endl; 
    }
    else {
        cout << 0 << endl;
    }
}   


Measured memory_bytes: 3444
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<=b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define T ll
#define ordered_set tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b, ll m){
    ll ans=1;
    a%=m;
    while(b){
        if(b&1) ans=ans*a%m;
        b>>=1;
        a=a*a%m;
    }
    return ans;
}


int main(){
    IOS
    int n;
    cin>>n;
    int a[n+2],b[n+1];
    FOR(i,1,n+1){
    	cin>>a[i];
    }
    FOR(i,1,n){
    	cin>>b[i];
    }
    ll ans=0;
    FOR(i,1,n){
    	int d=min(a[i],b[i]);
    	a[i]-=d;
    	b[i]-=d;
    	ans+=d;
    	d=min(b[i],a[i+1]);
    	a[i+1]-=d;
    	ans+=d;
    }
    cout<<ans;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

vector<int> G[100010];
int d[2][100010];
void dfs(int p ,int v, int parent) {
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i] == parent) continue;
		d[p][G[v][i]] = d[p][v] + 1;
		dfs(p, G[v][i], v);
	}
}
int main()
{
	int N, u, v;
	cin >> N >> u >> v;
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	u--; v--;
	d[0][u] = 0;
	d[1][v] = 0;
	dfs(0, u, -1);
	dfs(1, v, -1);
	int ans = 0, num = 0;
	for (int i = 0; i < N; i++) {
		if (d[0][i] < d[1][i]) {
			ans = max(ans, d[1][i] - 1);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 12928
#include <stdio.h>

int main(){
  int a, b, c;  scanf("%d %d %d", &a, &b, &c);

  if(a==b && b==c && !(a%2 || b%2 || c%2)){
    printf("-1\n");
    return 0;
  }
  int ans = 0;
  while(!(a%2 || b%2 || c%2)){
    ans++;
    int na=b+c, nb=c+a, nc=a+c;
    a=na/2, b=nb/2, c=nc/2;
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort(reverse = True)

    import heapq
    l = []
    heapq.heapify(l)
    heapq.heappush(l, -1 * a[0])
    # ne[0,0] = a[0]
    # ne[0,1] = a[0]
    ans = 0

    for i, aa in enumerate(a):
        if i == 0:
            continue
        v = heapq.heappop(l) * -1
        ans += v
        heapq.heappush(l,aa * -1)
        heapq.heappush(l,aa * -1)
    print(ans)
if __name__=='__main__':
    main()


Measured memory_bytes: 31676
def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n):return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx as nx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop
x=n1()
ans=x.index(0)
print(ans+1)

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

int main() {
   int r; cin >> r;
   long double ans = 2 * r * M_PI;
   cout << setprecision(20) << ans << endl;

}


Measured memory_bytes: 3772
#include <iostream>

using namespace std;

int main()
{
    int h, n;
    cin >> h >> n;
    int a[n];
    for(int i=0; i<n; ++i)
    {
        cin >> a[i];
    }
    int r = 0;
    for(int i=0; i<n; ++i)
    {
        r += a[i];
    }
    if(r >= h)
    {
        cout << "Yes";
    }
    else cout << "No";
    return 0;
}



Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    double a, b;
    cin >> a >> b;
    cout << setprecision(10) << (a*b)/(a+b) << "\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) int(a.size())
const int N=2e5+10;

int gi() {
	int x=0,o=1;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*o;
}

int n,mx,p;
vi E[N];
bool win[N];

void dfs(int u,int ff,int dis) {
	if(dis>mx) mx=dis,p=u;
	for(auto v:E[u]) if(v!=ff) dfs(v,u,dis+1);
}

int main() {
	cin>>n;
	for(int i=1,u,v;i<n;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
	dfs(1,0,0);mx=0;dfs(p,0,0);
	win[0]=1;
	for(int i=2;i<=mx;i++) {
		if(!win[i-1]||!win[i-2]) win[i]=1;
	}
	puts(win[mx]?"First":"Second");
	return 0;
}


Measured memory_bytes: 20736
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define takeline cin.ignore();
#define iactive cout.flush();
#define N 900005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
string a,b; ll n,m; ll dp[3005][3005],fl[3005][3005];
ll findans(ll i,ll j){
	if(i>=n||j>=m) return 0;

	if(dp[i][j]!=-1){
		return dp[i][j];
	}
	if(a[i]==b[j]){
		fl[i][j]=0;
		return dp[i][j]=findans(i+1,j+1)+1;
	}
	else{
		ll x,y;
		x=findans(i+1,j);
		y=findans(i,j+1);
		if(x>y) fl[i][j]=1;
		else fl[i][j]=2;
		return dp[i][j]=max(x,y);
	}
}
string stt;
void trace(ll i,ll j){
	if(i>=n||j>=m) return ;

	if(fl[i][j]==0){
		stt+=a[i];
		trace(i+1,j+1);
	}
	else if(fl[i][j]==1){
		trace(i+1,j);
	}
	else{
		trace(i,j+1);
	}
}
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	cin>>a>>b;
	n=a.length();	
	m=b.length();
	memset(dp,-1,sizeof(dp));
	ll an=findans(0,0);
	trace(0,0);
	cout<<stt;
	return 0;
}

Measured memory_bytes: 141952
#include <iostream>
#include <vector>

using namespace std;

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> A(n);
  int total = 0;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    total += A[i];
  }
  int c = 0;
  const int limit = (total + 4 * m - 1) / (4 * m);
  for (auto e : A) {
    if (e >= limit) ++c;
  }
  cout << (c >= m ? "Yes" : "No") << endl;

  return 0;
}


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

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

    int ans;
    if (N < 100) {
        if (D == 0) ans = N;
        else if (D == 1) ans = 100 * N;
        else ans = 10000 * N;
    } else {
        if (D == 0) ans = N + 1;
        else if (D == 1) ans = 100 * (N + 1);
        else ans = 10000 * (N + 1);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

  long long ans=0;
  long long min=0;
  for(int j=0;j<K-1;j++)
    {
      min += j;
    }
    long long max=0;
    for(int j=N;j>N-K+1;j--)
    {
      max += j;
    }

  for(int i=K;i<=N+1;i++)
  {
    min += i-1;
    max += N-i+1;

    ans += max - min + 1;
    ans %= 1000000007;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3624
using System;

namespace ConsoleApp1
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var a = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if (a >= 3200)
            {
                Console.WriteLine(s);
            }
            else
            {
                Console.WriteLine("red");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

int main() {

	ll N, M;
	cin >> N >> M;

	ll ret = 0;

	ret += min(N, M / 2);
	M -= ret * 2;
	ret += (M / 4);

	cout << ret << endl;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool f1 = false;
    bool f2 = false;
    if (s[2] == s[3])
        f1 = true;
    if (s[4] == s[5])
        f2 = true;
    if (f1 && f2)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  int N;
  cin>>N;
  int a[N];
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=a[i];
  }
  int x=sum/N;
  int summ=0;
  if(abs(sum-x*N)<abs(sum-(x+1)*N)){
    for(int i=0;i<N;i++){
      summ+=(a[i]-x)*(a[i]-x);
    }

  }else{
    for(int i=0;i<N;i++){
      summ+=(a[i]-x-1)*(a[i]-x-1);
    }

  }
  cout<<summ<<endl;

}




Measured memory_bytes: 256
N,K = map(int,input().split())
lh = list(map(int,input().split()))
dp = [float("inf")]*N
dp[0] = 0
for i in range(N):
    for k in range(i+1,min((i+K+1),N)):
        dp[k] = min(dp[k],(dp[i]+abs(lh[i]-lh[k])))
print(dp[-1])


Measured memory_bytes: 55008
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1e5+10;
#define int ll

void print() {
    cout << endl;
}

// template <class Head, class... Tail>
// void print(Head&& head, Tail&&... tail) {
//     cout << head;
//     if (sizeof...(tail) != 0) cout << " ";
//     print(forward<Tail>(tail)...);
// }

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i,k-1)cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    cout << p.first << " " << p.second << "\n";
}

template<class T>
bool chmax(T &a, T b){if(a < b){a = b; return true;} return false;}
template<class T>
bool chmin(T &a, T b){if(a > b){a = b; return true;} return false;}
signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t;cin >> s >> t;
    ll ns, nt;
    ns = s.size();
    nt = t.size();
    debug(ns);debug(nt);
    vector<vector<ll>> dp(ns+1, vector<ll>(nt+1));

    rep(i,ns)rep(j,nt){
        if(s[i] == t[j]){
            chmax(dp[i+1][j+1], dp[i][j] + 1);
        }
        chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
    }
    // print(dp);

    string ans;
    ll x = ns, y = nt;
    ll temp = dp[ns][nt];
    while(temp){
        // debug(x);debug(y);
        if(dp[x][y] == dp[x-1][y]){
            x--;
            continue;
        }
        if(dp[x][y] == dp[x][y-1]){
            y--;
            continue;
        }
        ans += s[x-1];
        temp--;
        x--;y--;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 70784
#include <iostream>

using namespace std;

using ll = long long;

int main () {
	ll n, y;
	cin >> n >> y;
	
	int a = -1, b = -1, c = -1;
  for (int i = 0; i <= n; ++i) {
		for (int j = 0; i + j <= n; ++j) {
			if (i * 10000ll + j * 5000ll + (n - i - j) * 1000ll == y) {
				  a = i;
					b = j;
					c = n - i - j;
				}
			}
	}
	cout << a << " " << b << " " << c << endl;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void uniq(vector<int> &vec){sort(vec.begin(), vec.end());vec.erase(unique(vec.begin(), vec.end()), vec.end());}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}


signed main(){start();
    int n,x;
    cin>>n>>x;
    vector<int> l(n);
    for(int i=0; i<n; i++) cin>>l[i];
    
    int ans=1;
    for(int i=0; i<n; i++){
        int wa=0;
        for(int j=0; j<=i; j++){
            wa = wa+l[j];
        }
        if(wa<=x) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int x;
    cin >> x;
    int dp[110000]={};
    dp[100]=1,dp[101]=1,dp[102]=1,dp[103]=1,dp[104]=1,dp[105]=1;

    int i=100;
    while(i<=100000){
        if(dp[i]){
            dp[i+100]=1;
            dp[i+101]=1;
            dp[i+102]=1;
            dp[i+103]=1;
            dp[i+104]=1;
            dp[i+105]=1;
        }
      i++;
    }

    if(dp[x]){
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    

}

Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {

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

        int[] A = new int[n];
        for (int i = 0; i < n; i++) A[i] = Integer.parseInt(sc.next());

        int q = partition(A, 0, n-1);
        int[] lower = Arrays.copyOfRange(A, 0, q);
        int[] upper = Arrays.copyOfRange(A, q+1, A.length);

        String lowerStr = Arrays.stream(lower).mapToObj(String::valueOf).collect(Collectors.joining(" "));
        String upperStr = Arrays.stream(upper).mapToObj(String::valueOf).collect(Collectors.joining(" "));
        System.out.println(lowerStr + " [" + A[q] + "] " + upperStr);
    }

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



Measured memory_bytes: 72412
#include<bits/stdc++.h>
using namespace std;
#define ll  long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD = 1000000007;
ll cnt =0,ans=0;
const int MAX = 510000;


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
int main(){

   ll n , m;    cin >> n >> m;
   UnionFind tree(n+1);
   
   vector<int> a(m);
   vector<int> b(m);
   for(int i=0;i<m;i++){
       cin >> a.at(i) >> b.at(i);
       int c,d;
       c = a.at(i);
       d = b.at(i);
       tree.unite(c,d);
       }

       map<int,int> mp;
       for(int i=1;i<=n;i++){
           mp[tree.root(i)]++;//根を数える
       }

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

}
       


Measured memory_bytes: 9064
#!/usr/bin/env python3


def f(x):
    if x % 4 == 0:
        return x
    elif x % 4 == 1:
        return 1
    elif x % 4 == 2:
        return x + 1
    else:
        return 0


A, B = map(int, input().split())
print(f(A) ^ f(B) ^ A)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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 int64_t INF = 1LL << 60;

int main() {
	int N;
  cin>>N;
  vector<int>A(N);
  vector<int>k(1000000);
  int64_t sum=0;
  for(int i=0;i<N;i++){
    cin>>A[i];
    k[A[i]]++;
    sum+=A[i];
  }
  int Q;
  cin>>Q;
  vector<int>B(Q),C(Q);
  for(int i=0;i<Q;i++){
    cin>>B[i]>>C[i];
  }
  for(int i=0;i<Q;i++){
   sum=sum+k[B[i]]*(C[i]-B[i]);
   k[C[i]]+=k[B[i]];
   k[B[i]]=0;
   cout<<sum<<endl;
  }

  

  return 0;
}


Measured memory_bytes: 8264
from collections import deque

N, M = map(int, input().split())
AB = [map(int, input().split()) for _ in range(M)]
A, B = [list(i) for i in zip(*AB)]

reach = [[] for i in range(N+1)]
reach[0].append(1)

for i in range(M):
    reach[A[i]].append(B[i])
    reach[B[i]].append(A[i])

d = deque()
visited = [-1]*(N+1)
ans = [-1]*(N+1)

d.appendleft(1)
visited[1] = 0

while d:
    now = d.pop()
    nexts = reach[now]

    for next in nexts:
        if visited[next] == -1:
            visited[next] = visited[now] + 1
            ans[next] = now
            d.appendleft(next)
        elif visited[now]+1 < visited[next]:
            visited[next] = visited[now]
            ans[next] = now

print('Yes')
for v in ans[2:]:
    print(v)


Measured memory_bytes: 165736
#グラフの連結成分を調べる
def Graph(ab):
    G=[[] for i in range(n)]
    #up_G=[0]*n#up_G[i]=頂点iの親
    for a,b in ab:
        G[a-1].append(b)
        G[b-1].append(a)
        #up_G[b-1]=a
    return G #,up_G

#木上のDFSテンプレ
from collections import deque
def dfs(G,v,p,a,b):
    #(G,v,p)=(グラフ(木の情報),探索中の頂点,vの親)
    #vの子の頂点を決めて、vをpに移す
    log=[False]*n
    q=deque([])
    q.append([v,p])
    log[v-1]=True
    while q:
        V,P=q[-1]
        for new_v in G[V-1]:
            #new_vが頂点の時はアウト
            if {a,b}=={V,new_v}:continue
            if new_v==P:continue
            if log[new_v-1]:continue
            log[new_v-1]=True
            q.append([new_v,V])
            break
        else:
            q.pop()

    for i in log:
        if i==False:
            return 1
    return 0

n,m=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(m)]
G=Graph(ab)
#print(G)

ans=0
for a,b in ab:
    ans+=dfs(G,1,-1,a,b)

print(ans)

Measured memory_bytes: 3316
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const int MOD=1e9+7;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

std::string to_binString(unsigned int val)
{
    if( !val )
        return std::string("0");
    std::string str;
    while( val != 0 ) {
        if( (val & 1) == 0 )  // val は偶数か？
            str.insert(str.begin(), '0');  //  偶数の場合
        else
            str.insert(str.begin(), '1');  //  奇数の場合
        val >>= 1;
    }
    return str;
}

/*
  dp[bit] := bitの鍵を使った時の費用の最小値
 */

int n, m;
int a[1050], b[1050], c[1050][20];

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

  cin >> n >> m;
  REP(i, m) {
      cin >> a[i] >> b[i];
      REP(j,b[i]) cin >> c[i][j];  
  }

  const int INF = 1e9;
  vector<int> dp(5010, INF);

  dp[0] = 0;
  
  REP(item, m){
    //current state
    int cur = 0;
    REP(j, b[item]){
      cur |= (1 << (c[item][j]-1));
    }    
    //cerr << to_binString(cur) << endl;

    //bitDP
    REP(bit, (1<<n)){
      dp[bit|cur] = min(dp[bit|cur], dp[bit] + a[item]);
    }
  }

  if(dp[(1 << n) - 1] == INF) dp[(1 << n) - 1] = -1;
  cout << dp[(1 << n) - 1] << endl;  
  return 0;
}


Measured memory_bytes: 384
#!/usr/bin/perl

my ($N,$X,$Y) = map { $_ - 0 } split(/\s+/,<STDIN>);

my @r = ();
$#r = $N;

$X --;
$Y --;

for(my $i=0;$i<$N-1;$i++){
  for(my $j=$i+1;$j<$N;$j++){
    
    my $d1 = $j - $i;
    
    my $d2 = abs( $X - $i ) + 1 + abs( $Y - $j );
    my $d3 = abs( $Y - $i ) + 1 + abs( $X - $j );
    
    $d1 = $d2 if ( $d2 < $d1 );
    $d1 = $d3 if ( $d3 < $d1 );
    
    $r[ $d1 ]++;
    
  }
}
for(my $i=1;$i<$N;$i++){
  my $x = $r[$i] - 0;
  print "$x\n";
}



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

int main(){
    int n, x;
    cin >> n;
    x = n/1.08;
    if(x != n/1.08){
        if(x+1 < (n+1)/1.08) cout << int(x+1) << endl;
        else cout << ":(" << endl;
    }else{
        if(x < (n+1)/1.08) cout << int(x) << endl;
        else cout << ":(" << endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef string st;
typedef double db;
typedef vector<long long> vecll;
typedef vector<char> vechar;
typedef vector<string> vecst;

int main(){
    ll N;
    cin >> N;
    vecll d(N);
    for(auto& i : d) cin >> i;

    vecll count(101);
    for(auto& i : d) count.at(i)++;

    ll ans = 0;
    for(auto& i : count) if( i > 0) ans++;

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
int debt = 100000;
int week;
scanf("%d", &week);
while(week--){
debt *= 1.05;
if(debt % 1000){
debt = (debt / 1000 + 1) * 1000;
}
}
printf("%d\n", debt);
return 0;
}

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

    h,w,k = map(int,input().split())
    mod = 10**9+7

    if w == 1:
        print(1)
        return

    fib = [1,2,3,5]
    for i in range(100):
        fib.append(fib[len(fib)-1]+fib[len(fib)-2])
    fib.append(1)
    fib.append(1)
    fib.append(1)


    dp = [[0]*w for _ in [0]*h]
    dp[0][0] = fib[w-2]
    dp[0][1] = fib[w-3]

    for i in range(1,h):
        for j in range(w):
            dp[i][j] = (dp[i-1][j]*fib[j-1]*fib[w-2-j])%mod
            if j >= 1:
                dp[i][j] = (dp[i][j] + dp[i-1][j-1]*fib[j-2]*fib[w-2-j])%mod
            if j <= w-2:
                dp[i][j] = (dp[i][j] + dp[i-1][j+1]*fib[j-1]*fib[w-3-j])%mod
    
    print(dp[-1][k-1])

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
bool fact(int m){
  if(m%2==0)return false; 
  int s=sqrt(m);
  for(int j=3;j<=s;j+=2){
    if(m%j==0) return false;
  }
  return true ;
} 
int main(){
  int n,cnt=0;
  cin>>n;
  vector<int> v;
  for(int i=11;cnt<n;i+=10){
     if(fact(i)){
        v.push_back(i);
        cnt++; 
     }
  }
    rep(i,n)
      printf("%d ",v[i]);
  return 0;
}

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


signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    string s;
    cin>>s;
    int ans=0;
    if(s=="SUN") ans=7;
    if(s=="MON") ans=6;
    if(s=="TUE") ans=5;
    if(s=="WED") ans=4;
    if(s=="THU") ans=3;
    if(s=="FRI") ans=2;
    if(s=="SAT") ans=1;
    cout << ans << endl;

}

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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const string YES = "Yes";
const string NO = "No";

void solve(string S){
    if (S[2] == S[3] && S[4] == S[5]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

}

// 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)
int main(){
    string S;
    cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n;
	string a;
	cin>>a;
	cin>>k;
	k--;
	int x;
	for(x=0;x<a.size();x++)
	{
		if(a[x]!=a[k])
		{
			a[x]='*';
		}
		cout<<a[x];
	}
	cout<<endl;
	
}

Measured memory_bytes: 256
#include <stdio.h>

int min(int ,int);
int main(){
  int i,j,k,l,n,m[101][101],x[101];/*101*/
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d %d",&x[i-1],&x[i]);
  for(i=1;i<=n;i++) m[i][i]=0;
  for(j=2;j<=n;j++){
    for(i=0;i<=n-j+1;i++){
      l=i+j-1;
      m[i][l]=(1<<21);
      for(k=i;k<=l-1;k++){
	m[i][l]=min(m[i][l],m[i][k]+m[k+1][l]+x[i-1]*x[k]*x[l]);
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}

int min(int x,int y){
  return x<y ? x:y;
}



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

using namespace std;
typedef long long ll;

using namespace std;
typedef long long ll;
ll mod = 1e9+7;

int main(void)
{
  ll H,W,N;cin>>H>>W>>N;
  ll a = (N-1)/W;
  ll b = (N-1)/H;
  cout<<min(a,b)+1<<endl;

  return 0;
}

Measured memory_bytes: 256
<?php

	// 3????????°????????\???
	$num = preg_split('/ /', trim(fgets(STDIN)));

	$a = intval($num[0]);
	$b = intval($num[1]);
	$c = intval($num[2]);
	$ans = 0;

	for($a = $a; $a <= $b; $a++){

		if($c % $a == 0){

			$ans++;

		}
	}
			echo ($ans);
?>

Measured memory_bytes: 9288
#include <iostream>

using namespace std;

int main()
{
	int x;
	cin >> x;
	for (int i = -119; i < 119; i++) {
		for (int j = -118; j <= 119; j++) {
			if (j * j * j * j * j - i * i * i * i * i == x) {
				cout << j << " " << i << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
const int N_MAX = pow(10, 5);
int main (void) {
    int N;
    ll A[N_MAX];
    ll h = 0;

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

    sort(A, A + N, greater<int>());

    int cnt = 1;
    for (int i = 0; i < N; i++) {
        if (A[i] == A[i + 1]) cnt++;
        else {
            if (cnt >= 4) {
                if (h == 0) cout << A[i] * A[i] << endl;
                else cout << h * A[i] << endl;
                return 0;
            } else if (cnt >= 2) {
                if (h == 0) h = A[i];
                else {
                    cout << h * A[i] << endl;
                    return 0;
                }
            }
            cnt = 1;
        }
    }
    cout << 0 << endl;

    return 0;
}


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

int main(void){
        int n,m,x,y,cou=0;
	cin>>n>>m;
	vector<pair<int,int>> vec(m);
	for(int i=0;i<m;i++){
		cin>>x>>y;
		vec[i]=make_pair(y,x);
	}


	sort(vec.begin(),vec.end());
	n=0;
	for(int i=0;i<m;i++){
	if(n<=vec[i].second){
		n=vec[i].first;
		cou++;
	}
	}
	cout<<cou<<endl;
	
        return 0;
}



Measured memory_bytes: 1024
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

namespace n91 {

	using i8 = std::int_least8_t;
	using i32 = std::int_least32_t;
	using i64 = std::int_least64_t;
	using u8 = std::uint_least8_t;
	using u32 = std::uint_least32_t;
	using u64 = std::uint_least64_t;
	using isize = std::ptrdiff_t;
	using usize = std::size_t;

	class rep {
		const usize f, l;

	public:
		class itr {
			friend rep;
			usize i;
			constexpr itr(const usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { ++i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr rep(const usize first, const usize last) noexcept
			: f(first), l(last) {}
		constexpr itr begin() const noexcept { return itr(f); }
		constexpr itr end() const noexcept { return itr(l); }
	};
	class revrep {
		const usize f, l;

	public:
		class itr {
			friend revrep;
			usize i;
			constexpr itr(usize x) noexcept : i(x) {}

		public:
			void operator++() noexcept { --i; }
			constexpr usize operator*() const noexcept { return i; }
			constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
		};
		constexpr revrep(usize first, usize last) noexcept : f(--first), l(--last) {}
		constexpr itr begin() const noexcept { return itr(l); }
		constexpr itr end() const noexcept { return itr(f); }
	};
	template <class T> using vec_alias = std::vector<T>;
	template <class T> auto md_vec(const usize n, const T &value) {
		return std::vector<T>(n, value);
	}
	template <class... Args> auto md_vec(const usize n, Args... args) {
		return std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
	}
	template <class T> constexpr T difference(const T &a, const T &b) {
		return a < b ? b - a : a - b;
	}

} // namespace n91

#include <utility>

namespace n91 {
	template <class T> T gcd(T m, T n) {
		while (m %= n)
			::std::swap(m, n);
		return n;
	}
} // namespace n91

#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <utility>

namespace n91 {

	void main_() {
		usize n;
		std::cin >> n;
		std::vector<i64> a(n);
		for (auto &e : a) {
			std::cin >> e;
		}
		auto itr =
			std::partition(a.begin(), a.end(), [](const auto x) { return x < 0; });
		if (std::distance(a.begin(), itr) % 2 != 0) {
			std::nth_element(a.begin(), std::prev(itr), itr);
			std::nth_element(itr, itr, a.end());
			if (itr != a.end() && *std::prev(itr) < -*itr) {
				++itr;
			}
			else {
				--itr;
			}
		}
		std::for_each(a.begin(), itr, [](auto &x) { x = -x; });
		std::cout << std::accumulate(a.cbegin(), a.cend(), static_cast<i64>(0))
			<< std::endl;
	}

} // namespace n91

int main() {
	n91::main_();
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void)
{
  int h, w;
  cin >> h >> w;

  string board[50];

  for (int i = 0; i < h; ++i)
    cin >> board[i];
  const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
  const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

  for (int i = 0; i < h; ++i)
  {
    for (int j = 0; j < w; ++j)
    {
      if (board[i][j] == '#')
        continue;

      int num = 0;
      for (int d = 0; d < 8; ++d)
      {
        const int ni = i + dy[d];
        const int nj = j + dx[d];

        if (ni < 0 || h <= ni)
          continue;
        if (nj < 0 || w <= nj)
          continue;
        if (board[ni][nj] == '#')
          num++;
      }

      board[i][j] = char(num + '0');
    }
  }

  for (int i = 0; i < h; ++i)
    cout << board[i] << endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;


int main(){
  int N,K;
  cin>>N>>K;
  int A[200050]={};
  for(int i=0;i<N;i++){
    int val;
    cin>>val;
    A[val]++;
  }
  vector<int> v;
  for(int i=1;i<=200000;i++){
    if(A[i]!=0){
      v.push_back(A[i]);
    }
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int ans=0;
  for(int i=K;i<v.size();i++){
    ans+=v[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2168
package main

import (
	"bufio"
	"os"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	flag := true
	for {
		for i := 0; i < 3; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), "")
			if buf[0] == "0" {
				flag = false
				break
			}
			a, b := 0, 0
			buf = buf[1:]
			for _, v := range buf {
				if string(v) == "A" {
					a++
				} else {
					b++
				}
			}
			if a > b {
				a++
			} else {
				b++
			}
			fmt.Println(a, b)
		}
		if !flag {
			break
		}
	}
}


Measured memory_bytes: 1096
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//*
constexpr ll MOD = 1e9 + 7;
/*/
constexpr ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
constexpr bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
constexpr bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

void Pr(bool f){
  cout << (f ? "Yes" : "No") << "\n";
  exit(0);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a >= k){
    print(k);
    return 0;
  }
  if(a+b >= k){
    print(a);
    return 0;
  }
  print(a-(k-a-b));
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i=a;i<=b;++i)
ll a[1000000+9];
ll kq[1990009];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n;
cin>>n;

cin>>a[1]>>a[2];
kq[2]=abs(a[1]-a[2]);
F(i,3,n)
{
    cin>>a[i];
    kq[i]=min(kq[i-1]+abs(a[i]-a[i-1]),kq[i-2]+abs(a[i]-a[i-2]));
}
cout<<kq[n];
}


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define pq priority_queue
#define mp make_pair
#define pii pair<int,int>
#define mod 998244353

int lowbit(int x) {return x&(-x);}

int n;
ll f[444][444];
int a[444];
ll sum[444];

ll getf(int l,int r) {
	if (f[l][r]!=-1) return f[l][r];
	if (l==r) return f[l][r]=0ll;
	ll tmp=1e18;
	for (int i=l+1;i<=r;i++) {
		ll cur=getf(l,i-1)+getf(i,r);
		tmp=min(cur,tmp);
	}
	return f[l][r]=tmp+sum[r]-sum[l-1];
}

int main(){
	memset(f,-1,sizeof(f));
	scanf("%d",&n);
	for (int i=1;i<=n;i++) {
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+(ll)a[i];
	}
	cout<<getf(1,n);
	return 0;
}


Measured memory_bytes: 1792
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int a;
    cin >> a;

    cout << (a + a * a + a * a * a) << '\n';

    return 0;
}

Measured memory_bytes: 3652