akhauriyash/Code-Regression huggingface dataset:
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		buf := strings.Split(scanner.Text(), " ")
		cards := make([]int, len(buf))
		for i := range buf {
			cards[i], _ = strconv.Atoi(buf[i])
		}
		if cards[0] == 0 {
			break
		}
		sum, ace := 0, 0
		for _, v := range cards {
			if v == 1 {
				v = 0
				ace++
			} else if v >= 10 {
				v = 10
			}
			sum += v
			if sum+ace > 21 {
				break
			}
		}
		if sum+ace > 21 {
			fmt.Println(0)
		} else if ace > 0 && sum+ace<= 11 {
			fmt.Println(sum+ace+10) // 1->11なるAceは高々1枚
		} else {
			fmt.Println(sum+ace)
		}
	}
}



Measured memory_bytes: 1112
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <ctime>

#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
#define TT int test_cases; cin >> test_cases; while(test_cases--)
#define TT1 int test_cases=1; while(test_cases--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
 
using namespace std;
typedef long long int ll;

 
int main() {
    
    FAST;
    TT1{
        
        int n;cin>>n;
        vector<ll> a(n);
        map<ll,ll> m;
        ll sum=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            m[a[i]]++;
            sum+=a[i];
            
        }
        int q;cin>>q;
        for(int i=0;i<q;i++)
        {
            ll b,c;cin>>b>>c;
            ll t=m[b];
            sum=sum+t*(c-b);
            m.erase(b);
            m[c]=m[c]+t;
            cout<<sum<<"\n";
        }
        
        
    }
}

Measured memory_bytes: 7852
#ifndef _WIN32
#include<iostream>
#endif

#include<string>
#include<cmath>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<utility>
#include<tuple>
using namespace std;

#define FOR(i,bg,ed) for(int i=(bg);i<(ed);i++)
#define REP(i,n) FOR(i,0,n)
#define ITR(x,v) for(auto &x:v)
typedef pair<int, int> P;
typedef vector<int> V;
typedef vector<V > VV;


const int INF = 1e8;
int main() {
	int N;
	while (cin >> N, N) {
		VV t(N, V(N + 1));
		REP(i, N) {
			cin >> t[i].back();
			REP(j, N)cin >> t[i][j];

		}
		vector<int> dp(1 << N, INF);
		dp[0] = 0;
		REP(bit, 1 << N) {
			REP(i, N)if ((bit >> i) & 1);
			else {
				int nxtbit = bit | (1 << i);
				int cost = t[i].back();
				REP(j, N)if ((bit >> j) & 1) {
					cost = min(cost, t[i][j]);
				}
				dp[nxtbit] = min(dp[nxtbit], dp[bit] + cost);
			}



		}

		cout << dp.back() << endl;
	}

	return 0;
}

Measured memory_bytes: 3396
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const char s[2]={'A','B'};
int a,b,c,d,q,k,nb;ll lim;
int calc(int x)
{
	return (a-(b-x+k-1)/k)/k;
}
inline int find(){
    R int l=0,r=b,mid,ans=0;
    while(l<=r){
        mid=(l+r)>>1;
        mid<=calc(mid)?(ans=mid,l=mid+1):r=mid-1;
    }
    return ans;
}
int main(){
//  freopen("testdata.in","r",stdin);
    for(scanf("%d",&q);q;--q){
        scanf("%d%d%d%d",&a,&b,&c,&d),--c;
        k=(a+b)/(a<b?a+1:b+1);
        if(k==1)fp(i,c,d-1)putchar(s[(i+(b>a))&1]);
        else{
            nb=find();
//          printf("qwq %d %d %d %d\n",a,b,k,nb);
            lim=nb+a-(b-nb+k-1)/k+1;
            fp(i,c,d-1)putchar(i<lim?s[i%(k+1)==k]:s[(a+b-i)%(k+1)>0]);
        }
        putchar('\n');
    }
    return 0;
}

Measured memory_bytes: 384
n = int(input())
dp = [[0 for i in range(3)] for j in range(n)]
a, b, c = ([0] * n for i in range(3))
for i in range(n):
  a[i], b[i], c[i] = map(int, input().split())
dp[0] = [a[0], b[0], c[0]]
for i in range(n - 1):
  dp[i + 1][0] = max(dp[i][1], dp[i][2]) + a[i + 1]
  dp[i + 1][1] = max(dp[i][0], dp[i][2]) + b[i + 1]
  dp[i + 1][2] = max(dp[i][0], dp[i][1]) + c[i + 1]
print(max(dp[n - 1]))

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

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

    if(abs(c - a) <= d){
        cout << "Yes" << endl;
        return 0;
    }
    else if((abs(b - a) <= d) && (abs(c - b) <= d)){
        cout << "Yes" << endl;
        return 0;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys,math,copy,queue,itertools,bisect
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
MOD = 10**9 + 7

N,K = LI()
ans = 0
for i in range(1,K+1):
    yaku = []
    for j in range(1,int(math.sqrt(i))+1):
        if i % j == 0:
            yaku.append(j)
            k = i // j
            if k != j:
                yaku.append(k)
    yaku.sort(reverse=True)
    num = []
    for y in yaku:
        ny = pow(K // y,N-1,MOD)
        for z in range(len(num)):
            if yaku[z] % y == 0:
                ny -= num[z]
        num.append(ny)
    for x,y in zip(num,yaku):
        ans = (ans + x * y) % MOD

print (ans)




Measured memory_bytes: 71096
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	string s; int k; std::cin >> s >> k;
	int n = s.length();
	for (int i = 0; i < n; i++) {
		if (s[i]!='a'&&'z' - s[i] + 1 <= k) {
			k -= 'z' - s[i] + 1;
			s[i] = 'a';
		}
	}
	k %= 26;
	s[n - 1] = (s[n - 1] - 'a' + k + 26) % 26 + 'a';
	std::cout << s << endl;
	char nyaa;
	std::cin >> nyaa;
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define fo(i,N) for(i=0;i<N;++i)
#define fos(i,b,N) for(i=b;i<N;++i)
#define forr(i,N) for(i=N-1;i>=0;--i)
#define disp(n) cout<<n<<endl;
#define N 100005
#define M 10000007
#define ll long long
#define vll vector <long long int>
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
using namespace std;
int main()
{
string s;
cin>>s;
bool f=true;
int i,n=s.size();
for(i=0;i<n/2;++i)
   if(s[i]!=s[n-1-i])
    {
      f = false;
      break;
    }
int n1 = (n-1)/2;
for(i=0;i<n1/2;++i)
   if(s[i]!=s[n1-1-i])
    {
      f = false;
      break;
    }
int n2 = (n+3)/2;
for(i=n2-1;i<(n+n2)/2;++i)
   if(s[i]!=s[n-1-i])
    {
      f  = false;
      break;
    }
if(f)
cout<<"Yes";
else
  cout<<"No";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#define rep(i, a, n) for(int i = a;i < n;i++)
using namespace std;


double dp[100010][100];
double ans[100010];


double pow2(int i){
	return pow(2, -i);
}


void makeDP(){
	dp[1][1] = 1;
	ans[1] = 1;

	rep(i, 1, 100005){
		rep(j, 0, 99){
			double e = dp[i][j]*pow2(j);
			dp[i+1][j+1] += e;
			ans[i+1] += e;
			dp[i+1][0] += dp[i][j]-e;
		}
		ans[i+1] += ans[i];
	}
}


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

	int n;

	makeDP();
	
	while(cin >> n, n) cout << fixed << ans[n] << endl;

	return 0;
}


Measured memory_bytes: 82308
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define pb push_back
#define mp make_pair
#define ull unsigned long long int
#define ll long long int
#define vi vector<int>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define eps 1e-10
#define dbs long double

ll i,j,k,sum=0,ans=0,n;

void fastio(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void solve()
{
	cin>>n>>k;
	int a[n+1];
	int dp[n+1];
	for(i=1;i<=n;i++)
		cin>>a[i];
	dp[0]=0;
	dp[1]=0;
	for(i=2;i<=n;i++)
	{
		int mini = INT_MAX;
		j = i-1;
		while(j>0 && (i-j)<=k)
		{
			mini = min(mini,dp[j]+abs(a[i]-a[j]));
			j--;
		}
		dp[i] = mini;
	}
	cout<<dp[n];
}

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

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        s: chars,
    }
    let mut d = 0;
    for i in 0..n {
        if s[i] == 'R' {
            d += 1;
        } else {
            d -= 1;
        }
    }
    puts!("{}\n", if d > 0 { "Yes" } else { "No" });
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include <bits/stdc++.h>
template<class T> inline bool chmin(T&a, T b){if(a > b){a = b; return true;}else{return false;}}
template<class T> inline bool chmax(T&a, T b){if(a < b){a = b; return true;}else{return false;}}
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1.0)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string l;
    cin >> l;
    vector<vector<ll>> dp(l.size()+1, vector<ll>(2, 0));
    dp[0][1] = 1;
    rep(i, l.size()){
        dp[i+1][0] += dp[i][0] * 3;
        if(l[i] == '0'){
            dp[i+1][1] += dp[i][1];
        }else{
            dp[i+1][0] += dp[i][1];
            dp[i+1][1] += (dp[i][1] * 2);
        }
        dp[i+1][0] %= mod;
        dp[i+1][1] %= mod;
    }
    cout << (dp[l.size()][0] + dp[l.size()][1]) % mod << endl;
}

Measured memory_bytes: 8780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 25;
int n,a[N];
ll ans;

ll dfs(int l,int r,int xl,int xr){
	if(l+1==r)return 0ll;
	ll ans=1e18;
	for(int mid=l+1;mid<r;mid++){
		ans=min(ans, dfs(l,mid,xl,xr+xl)+dfs(mid,r,xl+xr,xr)+1ll*(a[mid])*(xl+xr));
	}
	return ans;
}

int main()
{
	cin >> n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	cout << 1ll*a[1]+1ll*a[n]+dfs(1,n,1,1) << endl;
	return 0;
}

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

int main()
{
    string t;
    cin >> t;

    int ans=0;
    rep(i,t.size()){
        if(t[i]=='?') t[i] = 'D';
        cout << t[i];
    }
    cout << endl;
    return 0;
}

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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

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

int N, M, P[1001];

int main(){
  while(scanf("%d%d", &N, &M) && N+M){
    rep(i, N)  scanf("%d", P+i);
    P[N] = 0;
    vi p;
    rep(i, N+1) rep(j, N+1) if(P[i] + P[j] <= M) p.PB(P[i]+P[j]);
    sort(p.begin(), p.end());

    int res = 0;
    rep(i, p.size()){
      int d = M - p[i];
      int l = 0, h = p.size();
      int m;
      while(h - l > 1){
	m = (l+h)/2;
	if(p[m] < d) l = m;
	else if(p[m] > d) h = m;
	else break;
      }
      if(p[m] > d) m--;
      //      printf("%d %d\n", p[m], p[i]);
      res = max(res, p[m] + p[i]);
    }
    printf("%d\n", res);
  }
  return 0;
}

Measured memory_bytes: 9164
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const ll INF = 1000000007;
int dp[1005][1005];

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>a(h);
	rep(i, h)cin >> a[i];
	dp[1][0] = 1;
	rep(i, h)rep(j, w) {
		if (a[i][j] == '#')dp[i+1][j+1] = 0;
		else {
			dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
			dp[i + 1][j + 1] %= INF;
		}
		//cout << dp[i + 1][j + 1] << endl;
	}
	cout << dp[h][w];
	return 0;
}

Measured memory_bytes: 9388
n = int(input())
A = [[False for _ in range(n)] for _ in range(n)]
for _ in range(n):
    tmp = list(map(int, input().split()))
    for i in range(tmp[1]):
        A[tmp[0]-1][tmp[i+2]-1] = True

WHITE = 0
GRAY = 1
BLACK = 2
color = [WHITE for _ in range(n)]
d = [0 for _ in range(n)]
f = [0 for _ in range(n)]
time = 1

def dfs(u):
    global dfs_color, d, f, time
    color[u] = GRAY
    d[u] += time
    time += 1
    for v in range(n):
        if A[u][v]:
            if color[v] == WHITE:
                dfs(v)
        else:
            continue
    color[u] = BLACK
    f[u] = time
    time += 1 

for u in range(n):
    if color[u] == WHITE:
        dfs(u)

for i in range(n):
    print(str(i+1) + ' ' + str(d[i]) + ' ' + str(f[i]) )

Measured memory_bytes: 7852
#include<bits/stdc++.h>
using namespace std;
long long int l,zx[1000000],b=1,e=0,m,n,sum=0;
int main()
{   
    cin>>m;
    for(long long int i=0;i<m;i++) 
	{
	scanf("%lld",&zx[i]);
	if(zx[i]==b) 
	{
		b++;sum++;e=1;
	} 
}
	if(e)cout<<m-sum;
	else cout<<-1;
    return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

///-------------------------------------------------------------------

int const mx = 100000;
int dp[mx];
int a[mx];

int f(int n){
    if(dp[n]!=-1) return dp[n]; ///base cases are ok with dp[0] and dp[1]
    
    return dp[n] = min( f(n-1) + abs(a[n]-a[n-1]),
                        f(n-2) + abs(a[n]-a[n-2]) );
}

int main()
{
    int n; cin>>n;
    for0(i,n) cin>>a[i];

    mem(dp, -1);

    ///for base cases
    dp[0] = 0;
    dp[1] = abs(a[0]-a[1]);

    cout<<f(n-1);
}


Measured memory_bytes: 6636
#include<bits/stdc++.h>
using namespace std;
#define int long long 
const int INF=1e18+7;
//dp[mask] - best score possible with mask
int n;
vector<int>dp((1ll<<16), -INF);
vector<vector<int>>a(16, vector<int>(16, 0));

void rec(int i, int msk, int score, vector<int> &not_taken, vector<int> &selected)
{
    if(i==(int)not_taken.size())
    {
        // if(msk==5)
        // {
        //     cout<<score<<endl;
        // }
        for(int j=0; j<(int)selected.size(); ++j)
        {
            for(int k=j+1; k<(int)selected.size(); ++k)
            {
                score+=a[selected[j]][selected[k]];
            }
        }
        dp[msk]=max(dp[msk], score);
        return;
    }
    // cout<<not_taken[i]<<endl;
    rec(i+1, msk, score, not_taken, selected);
    selected.push_back(not_taken[i]);
    rec(i+1, msk|(1ll<<not_taken[i]), score, not_taken, selected);
    selected.pop_back();
}

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

    dp[0]=0;
    for(int mask=0; mask<(1ll<<n); ++mask)
    {
        // cout<<mask<<":"<<dp[mask]<<"\n";
        vector<int>not_taken, selected;
        for(int i=0; i<n; ++i)
        {
            if(!(mask & (1ll<<i)))
            {
                not_taken.push_back(i);
            }
        }
        rec(0, mask, dp[mask], not_taken, selected);
    }
    cout<<dp[(1ll<<n)-1];
}

Measured memory_bytes: 768
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

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

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(k);
    if (k > n) k = n;
    int h[n]; rep(i, n) in(h[i]);
    int dp[n];

    rep(i, k + 1) dp[i] = abs(h[i] - h[0]);

    repr(i, k + 1, n) {
        int c = INT_MAX;
        rep(j, k) {
            c = std::min(c, dp[i - 1 - j] + abs(h[i] - h[i - 1 - j]));
        }
        dp[i] = c;
    }

    out(dp[n - 1]);
}

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

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 1024
// 5:20
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <tuple>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)
#define STRING(str) #str
#define DEBUG 0
#if DEBUG
    #define dump(var) dump2(STRING(var), var)
#else
    #define dump(var)
#endif

template <typename T>
void dump2(const string& name, const T& value)
{
    cerr << name << ": " << value << endl;
}
void dump2(const string& name, const tuple<ll,ll,ll>& value)
{
    ll a,b,c;
    tie(a,b,c) = value;
    cerr << name << ": (" << a << ", " << b << ", " << c << ")" << endl;
}

void solve()
{
    ll N,M,K;
    cin >> N >> M >> K;
    for1(h,N+1) {
        for1(w,M+1) {
            ll cnt = h*(M-w) + w*(N-h);
            if (cnt == K) {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
}

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


Measured memory_bytes: 256
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    d = defaultdict(int)
    for _ in range(N):
        s = input()
        d[s[0]] += 1

    ans = 0
    for a in combinations("MARCH", 3):
        ans += d[a[0]] * d[a[1]] * d[a[2]]

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    string S;
    cin >> S;


    cout << (S == "ABC" ? "ARC" : "ABC") << endl;
}

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

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

A.sort()
A_max = A[-1]
table = [0] * (A_max + 1)

for x in A:
    table[x] += 1
    for y in range(x * 2, A_max + 1, x):
        table[y] += 1

result = sum([1 for x in A if table[x] == 1])
print(result)


Measured memory_bytes: 32284
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, start, end) for (int i = start; i < end; i++)
#define rloop(i, start, end) for (int i = start; i >= end; i--)

void solve(){
    //code goes here
    string s;
    cin>>s;
    int n=s.length();
    if(s[n-1]!='s'){
        cout<<s+'s';
    }
    else{
        cout<<s+"es";
    }
    
}

int32_t main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t=1;
    // cin>>t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
int a,b,c,k;
void input();

void solve(){
    int need = 0;
    while(a>=b){
        b*=2;need++;
    }
    while(b>=c){
        c*=2;need++;
    }
    //cout<<need<<"\n";
    if(need<=k){
        cout<<"Yes\n";
    }
    else{
        cout<<"No\n";
    }
}

void Clear(){

}

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

    input();
    solve();
    Clear();
}

void input(){
    cin>>a>>b>>c>>k;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

int main(){
	ll N, M;
	cin >> N >> M;
	vector<ll> count(M, 0);
	REP(i, N){
		ll K;
		cin >> K;
		REP(i, K){
			ll A;
			cin >> A;
			A--;
			count[A]++;
		}
	}
	ll res = 0;
	REP(i, M) if(count[i]==N) res++;
	cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
//const int INF = 1001001001;

int main(void){
    ll n,k;
    cin >> n >> k;
    ll r=n%k;
    ll ans=min(r,abs(r-k));
    cout << ans;
    return 0;
}

Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var (
	n     int
	total int
	sumx  int
	tmp   = math.MaxInt64
)

func main() {
	fmt.Scan(&n)
	a := make([]int, 0, n)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for sc.Scan() {
		tmp, _ := strconv.Atoi(sc.Text())
		total += tmp
		a = append(a, tmp)
	}

	for i := 0; i < (n - 1); i++ {
		sumx += a[i]
		tmp = min(tmp, abs(2*sumx-total))
	}
	fmt.Println(tmp)
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

Measured memory_bytes: 3584
#include<iostream>
using namespace std;
int main(void)
{
	char in, ans;
	cin >> in;
	switch (in) {
	case 'A': ans = 'T'; break;
	case 'C': ans = 'G'; break;
	case 'G': ans = 'C'; break;
	case 'T': ans = 'A';
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;


int main() {
  int a,b,c;
  cin >> a >>b>>c;
  if (a < b && b < c) {
  cout << "Yes" << endl;
  } else {
  cout << "No" << endl;
  }
  return 0;
}



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

int main(){
  ll taka = 100;
  ll goal;
  cin >> goal;

  for (ll i = 0; i < 1000000; i++) {
    taka *= 1.01;
    if (taka >= goal) {
      cout << i+1 << endl;
      return 0;
    }
  }

}


Measured memory_bytes: 3620
N = int(input())
A = input()
ans = 0
for i in range(N):
  now = 0
  a = A[0:i+1]
  b = A[i+1:N]
  k = list(set(list(a)))
  l = list(set(list(b)))
  if min(len(k),len(l)) == len(k):
    for j in range(len(k)):
      if k[j] in l:
        now += 1
    if now > ans:
      ans = now
  else:
    for j in range(len(l)):
      if l[j] in k:
        now += 1
    if now > ans:
      ans = now
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;

int main(){
	string s;
	cin >> s;
	int l = s.size();

	//最上位を1減らして和を取る
	int d = s[0] - '0' - 1;
	int ans = d + 9 * (l-1);

	//そのまま
	int a = 0;
	for(int i = 0;i < s.size();i++) a += s[i]-'0';
	ans = max(a, ans);

	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(long long H, long long A){
    int res = H / A;
    int mod = H % A;
    if(mod == 0) {
        cout << res << endl;
    }else {
        cout << res + 1 << endl;
    }
}

// Generated by 1.1.7.1 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(){
    long long H;
    scanf("%lld",&H);
    long long A;
    scanf("%lld",&A);
    solve(H, A);
    return 0;
}


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

int main() {
  int n;
  cin>>n;
  if(n<105){
    cout<<0<<endl;
  }
  else if(n<135){
    cout<<1<<endl;
  }
  else if(n<165){
    cout<<2<<endl;
  }
  else if(n<189){
    cout<<3<<endl;
  }
  else if(n<195){
    cout<<4<<endl;
  }
  else{
    cout<<5<<endl;
  }
}

Measured memory_bytes: 256
o = list(input())
e = list(input())
psw = ['0']*(len(o)+len(e))

for i in range(len(o)):
    j = i * 2
    psw[j] = o[i]
for i in range(len(e)):
    j = i * 2 + 1
    psw[j] = e[i]

print(*psw, sep='')

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

N = int(input().split()[0])
p_list = list(map(int, input().split()))
# p_list = p_list[::-1]
min_p = p_list[0]
c = 0
for p in p_list:
    if p <= min_p:
        c += 1
        min_p = p

ans = c

print(ans)


Measured memory_bytes: 24744
s=input()
p=input()

ls=len(s)
lp=len(p)

for i in range(ls):
    if i+lp<=ls:
        #s[:]が正しい。s[,]になってた。
        j=i+lp
        check=s[i:j]
    else:
        check1=s[i:ls]#s[a:b]はbの文字を含まない
        check2=s[0:i+lp-ls]
        check=check1+check2
        #print(check1+"1"+p)
        #print(check2+"2"+p)
        #print(check+"3")
    if check==p:
        print("Yes")
        break
    elif i==ls-1:
        print("No")



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

using namespace std;
long long n,m,w[110],v[110],s=0,f[110][100010];
int main()
{
    //freopen("bai.inp","r",stdin);
    //freopen("bai.out","w",stdout);
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >>n >>m;
    for (int i=1; i<=n; i++){
        cin >>w[i] >>v[i];
        s += v[i];
    }
    //for (int i=0; i<110; i++)
        for (int j=0; j<100010; j++){
            f[0][j] = 1e9+10;
        }
    f[0][0] = 0;
    for (int i=1; i<=n; i++)
        for (int j=1; j<=s; j++)
            if (v[i] > j) f[i][j] = f[i-1][j];
            else f[i][j] = min(f[i-1][j-v[i]] + w[i], f[i-1][j]);
    //for (int i=1; i<=n; i++)
    //    for (int j=1; j<=s; j++)
    //        if (f[i][j] <1e9) cout <<i <<' '<<j <<' ' <<f[i][j] <<endl;
    for (int j=s; j>=1; j--){
        //cout <<j <<' '<<f[n][j]<<endl;
        if (f[n][j] <= m) {cout <<j;break;}
    }
    return 0;
}


Measured memory_bytes: 80128
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<tuple>
#define llint long long int
#define lldo long double
#define fir first
#define sec second
#define pub push_back
#define mp make_pair
#define mt make_tuple
void maxeq(int &a,int b){if(a<b){a=b;}}
using namespace std;
int main(void){
	int n,i,ansA=0,ansB=0;cin>>n;
	vector<pair<int,int>> hito(n);
	vector<int>nin(100001);//?????°
	vector<int>sta(100001);//??????????´???????
	for(i=0;i<n;i++){
		cin>>hito[i].fir>>hito[i].sec;
		nin[hito[i].fir]++;
		sta[hito[i].fir]++;
		nin[hito[i].sec]--;
	}
	for(i=1;i<=100000;i++){nin[i]+=nin[i-1];sta[i]+=sta[i-1];}
	for(i=0;i<n;i++){
		maxeq(ansB,nin[hito[i].fir]);
		maxeq(ansA,nin[hito[i].fir]+sta[hito[i].sec-1]-sta[hito[i].fir]);
	}
	cout<<ansA<<" "<<ansB<<endl;
	return 0;
}

Measured memory_bytes: 5212
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

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

bool isPrime[200010];
set<int> divisor[200010];
void solve(int N, std::vector<int> A){
  sort(A.begin(),A.end());
  if(A[0]==1){
    if(A[1]==1)cout<<0<<endl;
    else cout<<1<<endl;
    return;
  }
  REP(i,N){
    for(int p=1;p<=1000;p++){
      if(p*p>A[i])break;
      if(A[i]%p==0){
	divisor[i].insert(p);
	divisor[i].insert(A[i]/p);
      }
    }
  }
  int result=0;
  REP(i,N){
    if(i<N-1&&A[i]==A[i+1]){
      while(A[i]==A[i+1])i++;
      continue;
    }
    bool prime=true;
    for(auto d:divisor[i]){
      if(d==A[i])continue;
      auto it=lower_bound(A.begin(),A.end(),d);
      if(*it==d){
	prime=false;
	break;
      }
    }
    if(prime)result++;
  }
  cout<<result<<endl;
}

int main(){
  int N;
  scanf("%d",&N);
  std::vector<int> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%d",&A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 472668
#include <stdio.h>

#define MAX_N 1000000

int isPrime[ MAX_N + 1 ];

int main( void ) {
	int i, j, a, d, n, fig;

	isPrime[ 1 ] = 0;
	for ( i = 2; i <= MAX_N; i++ )
		isPrime[ i ] = 1;

	for ( i = 4; i <= MAX_N; i += 2 )
		isPrime[ i ] = 0;

	for ( i = 3; i * i <= MAX_N; i += 2 )
		if ( isPrime[ i ] )
			for ( j = i * 2; j <= MAX_N; j += i )
				isPrime[ j ] = 0;

	for ( ; scanf( "%d %d %d", &a, &d, &n ), a; printf( "%d\n", fig - d ) )
		for ( fig = a; n; fig += d )
			n -= isPrime[ fig ];

	return 0;
}

Measured memory_bytes: 4504
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
using namespace std;
int main() {
	int a,w, b, c, d, e, f, i, j, n;
	for (i = 0; i < 7; i++) {
		scanf("%d %d", &a, &b);
		w = a - b;
		printf("%d\n", w);
	}
}

Measured memory_bytes: 3192
#include "bits/stdc++.h"
#define ALL(a) a.begin(),a.end()
using namespace std;

set<string> operation(const string train) {
    set<string> result;
    int div = 1;
    while (div < train.length()) {
        string sub1 = train.substr(0, div);
        string sub2 = train.substr(div);
        string sub1r = sub1;
        string sub2r = sub2;
        reverse(ALL(sub1r));
        reverse(ALL(sub2r));
        string sub1c[] = {sub1, sub1r};
        string sub2c[] = {sub2, sub2r};
        
        for (string s1 : sub1c) {
            for (string s2 : sub2c) {
                result.insert(s1+s2);
                result.insert(s2+s1);
            }
        }
        ++div;
    }
    return result;
}
int main(void){
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string train;
        cin >> train;
        set<string> res = operation(train);
        cout << res.size() << endl;
    }
    
    return EXIT_SUCCESS;
}

Measured memory_bytes: 3232
n = gets.to_i
prime = Array.new(55556,0)
for i in 2..55555
  x = i
  while x <= 55555
    prime[x] = i if prime[x] == 0
    x += i
  end
end
arr = []
cnt = 0
y = 11
while cnt < n
  if prime[y] == y
    arr << y
    cnt += 1
  end
  y += 10
end
arr.each do |s|
  print "#{s} "
end
puts ""

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

int main() {
        int N, N2;  // 入力, 計算用
        int sum = 0;  //桁和

        cin >> N;
        N2 = N; // escape

        while (N2 > 0) {
            sum += (N2%10);
            // cout << "sum: " << sum << endl;
            N2 /= 10;
        }

        if (N % sum == 0){
                cout << "Yes" << endl;
        } else {
                cout << "No" << endl;
        }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;

int read()
{
	int s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(int x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(int x,char c='\n')
{
	write(x);
	putchar(c);
}
int dp[N*N],a[5][5];

signed main()
{
	int n=read();
	for (int i=0;i<=1;i++)
	for (int j=1;j<=3;j++) a[i][j]=read();
	for (int p=0;p<=1;p++)
	{
		int m=0;
		for (int i=0;i<=n;i++) dp[i]=0;
		for (int i=1;i<=3;i++)
		for (int j=a[p][i];j<=n;j++)
		dp[j]=max(dp[j],dp[j-a[p][i]]+a[p^1][i]-a[p][i]);
		for (int i=0;i<=n;i++) m=max(m,n+dp[i]);
		n=m;
	}
	print(n);

	return 0;
}

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

int main(){
	

	ll n,k; cin>>k>>n;
	ll ans=0,diff=-1,sum=0;
	ll a[n];
	for(int i=0;i<n;i++) { cin>>a[i]; }
	for(int i=0;i<n;i++){
		if(i==n-1){
			ll d = (k-a[i])+a[0];
			diff = max ( d,diff );
			sum+=d;
		}
		else{
			ll d = abs(a[i]-a[i+1]);
			diff = max(d,diff);
			sum+=d;
		}
	}
	

	cout<<sum-diff;
  cout<<"\n";
	return 0;
}

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

public class Main{
    public static void main(String[] args) throws IOException{
        FastReader in = new FastReader();
        FastWriter out = new FastWriter();
        int[] pqr = new int[3];
        pqr[0] = in.nextInt();
        pqr[1] = in.nextInt();
        pqr[2] = in.nextInt();
        Arrays.sort(pqr);
        out.pl(pqr[0] + pqr[1]);
        out.close();
    } 
}
class FastReader{ 
    BufferedReader br; 
    StringTokenizer st; 
    public FastReader() { 
        br = new BufferedReader(new InputStreamReader(System.in)); 
    } 
    String next(){ 
        while (st == null || !st.hasMoreElements()) { 
            try{ 
                st = new StringTokenizer(br.readLine()); 
            }catch (IOException  e){ 
                e.printStackTrace(); 
            } 
        } 
        return st.nextToken(); 
    } 
    int nextInt(){ 
        return Integer.parseInt(next()); 
    } 
    long nextLong(){ 
        return Long.parseLong(next()); 
    } 
    double nextDouble(){ 
      return Double.parseDouble(next()); 
    } 
    String nextLine(){ 
        String str = ""; 
        try{ 
            str = br.readLine(); 
        } 
        catch (IOException e){ 
            e.printStackTrace(); 
        } 
        return str; 
    } 
}
class FastWriter{
    PrintWriter out;
    FastWriter(){
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	out.flush();
    }
    void pl(Object o){
        out.write(o.toString());
	    out.write("\n");
        out.flush();
    }
    void pl(){
        out.write("\n");
    }
    void p(Object o){
        out.write(o.toString());
    }
    void close(){
        out.flush();
        out.close();
    }  
}


Measured memory_bytes: 33000
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
 
#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
 
bool comp(const pii &a,const pii &b){
    if(a.second > b.second)return true;
    return false;
}
 
int main(){
    int n;
    cin >> n;
    vector<pii> a(n);
    int m = 0;
    int tmp;
    rep(i,n){ 
        cin >> tmp;
        a[i] = make_pair(i,tmp);
    }
 
    sort(a.begin(),a.end(),comp);
 
    // rep(i,n){
    //     cout << a[i].first << " " << a[i].second << endl;
    // }
 
    rep(i,n){
        if(a[0].first == i){
            cout << a[1].second << endl;
        }else{
            cout << a[0].second << endl;
        }
    }
 
    return 0;
}

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

using namespace std;

int main() {
  int N, W;
  cin >> N >> W;
  vector<int> w(N+1), v(N+1);
  for(int i = 0; i < N; i++) cin >> v[i+1] >> w[i+1];
  vector<int> tmp(W+1);
  vector<vector<int> > table(N+1);
  for(int i = 0; i < N+1; i++) table[i] = tmp;
  for(int i = 0; i < N+1; i++) table[i][0] = 0;
  for(int i = 0; i < W+1; i++) table[0][i] = 0;
  for(int i = 1; i < N+1; i++) {
    for(int j = 1; j < W+1; j++) {
      if(w[i] > j) table[i][j] = table[i-1][j];
      else table[i][j] = max(table[i-1][j], table[i-1][j-w[i]] + v[i]);
    }
  }
  cout << table[N][W] << endl;
}

Measured memory_bytes: 6732
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,x;
    cin >> n >> x;
    int mas[n];
    for(int i=0;i<n;i++)cin >> mas[i];
    int t=1;
    int c=0;
    for(int i=0;i<n;i++){
        c+=mas[i];
        if(x<c)break;
        else t++;
    }
    cout << t;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int dx = tx - sx, dy = ty - sy;
  cout << string(dx, 'R') << string(dy, 'U');
  cout << string(dx, 'L') << string(dy, 'D');
  cout << 'D' << string(dx + 1, 'R') << string(dy + 1, 'U') << 'L';
  cout << 'U' << string(dx + 1, 'L') << string(dy + 1, 'D') << 'R';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int dpjump(int n,int a[])
{
    long long int dp[n+1];
    dp[1]=0;
    dp[2]=abs(a[1]-a[0]);
    for(int i=3;i<=n;i++)
    {
        dp[i]=min(abs(a[i-1]-a[i-2])+dp[i-1],abs(a[i-1]-a[i-3])+dp[i-2]);


    }
    return dp[n];



}
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<dpjump(n,a);
    return 0;
}


Measured memory_bytes: 1408
#include<iostream>
 #include<algorithm>
 using namespace std;
 #define N 100010
 int main(){
 int n,m,h[N],ma[N];
 cin>>n>>m;
 for(int i=1;i<=n;i++){
 cin>>h[i];
 ma[i]=0;
 }
 for(int i=0;i<m;i++){
 int a,b;
 cin>>a>>b;
 ma[a]=max(ma[a],h[b]);
 ma[b]=max(ma[b],h[a]);
 }
 int ans=0;
 for(int i=1;i<=n;i++){
 ans+=h[i]>ma[i];
 }
 cout<<ans<<endl;
 }

Measured memory_bytes: 4356
def tairu(a):
    hoge=None
    ii=0
    if len(a)==1:
        return 0
    for i in range(len(a)-1):
        hoge=a[i:i+2]
        if hoge[0]==hoge[1]:
            ii+=1
            if a[i+1]=="0":
                a[i+1]="1"
            else:
                a[i+1]="0"
    else:
        if a[-1]==a[-2]:
            ii+=1
    return ii
  
a=list(input())
print(tairu(a))

Measured memory_bytes: 49584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>N>>S;
    vector<char>ans(N+1);

    ans[0]='S';
    ans[1]='S';
    rep2(i,N-1){
        if((S[i]=='o')^(ans[i-1]=='S')^(ans[i]=='S')){
            ans[i+1]='S';
        }else{
            ans[i+1]='W';
        }
    }
    if(ans[N]==ans[0] && ((ans[N-1]=='S')^(S[0]=='x'))){
        rep(i,N){
            cout<<ans[i];
        }
        cout<<endl;
        return 0;

    }

    ans[0]='W';
    ans[1]='S';
    rep2(i,N-1){
        if((S[i]=='o')^(ans[i-1]=='S')^(ans[i]=='S')){
            ans[i+1]='S';
        }else{
            ans[i+1]='W';
        }
    }
    if(ans[N]==ans[0] && ((ans[N-1]=='W')^(S[0]=='x'))){
        rep(i,N){
            cout<<ans[i];
        }
        cout<<endl;
        return 0;

    }
    ans[0]='S';
    ans[1]='W';
    rep2(i,N-1){
        if((S[i]=='o')^(ans[i-1]=='S')^(ans[i]=='S')){
            ans[i+1]='S';
        }else{
            ans[i+1]='W';
        }
    }
    if(ans[N]==ans[0] && ((ans[N-1]=='W')^(S[0]=='x'))){
        rep(i,N){
            cout<<ans[i];
        }
        cout<<endl;
        return 0;

    }

    ans[0]='W';
    ans[1]='W';
    rep2(i,N-1){
        if((S[i]=='o')^(ans[i-1]=='S')^(ans[i]=='S')){
            ans[i+1]='S';
        }else{
            ans[i+1]='W';
        }
    }
    if(ans[N]==ans[0] && ((ans[N-1]=='S')^(S[0]=='x'))){
        rep(i,N){
            cout<<ans[i];
        }
        cout<<endl;
        return 0;

    }
    
    cout << -1 << endl;


    return 0;
    

}

Measured memory_bytes: 3840
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll n, k;
ll a[100005];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> k;
  REP(i, n) cin >> a[i];

  ll dp[42][2];
  REP(i, 42) REP(j, 2) dp[i][j] = -LLINF;
  dp[40][0] = 0;

  RREP(i, 40) {
    ll D = 1LL << i;

    int num1 = 0;
    REP(j, n) if((a[j] >> i) & 1) num1++;
    int num0 = n - num1;

    if((k >> i) & 1) {
      dp[i][0] = max(dp[i][0], dp[i + 1][0] + D * num0);
      dp[i][1] = max(dp[i][1], dp[i + 1][0] + D * num1);
    } else {
      dp[i][0] = max(dp[i][0], dp[i + 1][0] + D * num1);
    }
    dp[i][1] = max(dp[i][1], dp[i + 1][1] + D * max(num0, num1));
  }

  cout << max(dp[0][0], dp[0][1]) << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(void)
{
    int n, a[10000], kazu;
    int soe = 0;
    int max, min;
	long sum = 0;
	
    scanf("%d", &n);

    kazu = n;
    while (n != 0){
        scanf(" %d", &a[soe]);
        --n;
        ++soe;
    }

    max = a[0];
    min = a[0];

    soe = 0;

    while (soe != kazu){
        if (min > a[soe]){
            min = a[soe];
        }

        if (max < a[soe]){
            max = a[soe];
        }

        sum += (long)a[soe];

        ++soe;
    }

    printf("%d %d %ld\n", min, max, sum);

    return 0;
}

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

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

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

int main()
{
    ll N,M;
    cin >> N >> M;
    priority_queue<ll, vector<ll>, greater<ll> > A;
    rep(i,N)
    {
        ll tmp;
        cin >> tmp;
        A.push(tmp);
    }
    
    vector<pair<ll, ll> >bc(M);
    rep(i,M) cin >> bc[i].second >> bc[i].first;
    sort(all(bc),greater<pair<ll, ll> >());
    //rep(i,M) cout << bc[i].second << " " << bc[i].first << endl;

    rep(i,M)
    {
        bool flag = true;
        rep(j,bc[i].second)
        {
            if( A.top() >= bc[i].first )
            {
                flag = false;
                break;
            }
            else
            {
                A.pop();
                A.push(bc[i].first);
            }
        }
        if( !flag )break;
    }

    ll ans = 0;
    rep(i,N)
    {
        ans += A.top();
        A.pop();
    }
    cout << ans << endl;

}


Measured memory_bytes: 2676