akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(a) for(int k=head[a];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=5e5+5,M=5e3+5,INF=1e9,mod=998244353;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
struct edge{int t,ne;}e[N];
int head[N],cnt,w[N],g[2][N],f[N],n;
void adde(int a,int b){e[++cnt]=(edge){b,head[a]};head[a]=cnt;}
int gao(int x){
	if(!head[x]){f[x]=0;return 1;}
	run(x)if(!gao(v))return 0;
	int now=1;re(i,0,M)g[now][i]=INF;
	g[now][0]=0;
	run(x){
		now^=1;re(i,0,M)g[now][i]=INF;
		rep(i,0,w[x]){
			if(i>=w[v])gmin(g[now][i],g[now^1][i-w[v]]+f[v]);
			if(i>=f[v])gmin(g[now][i],g[now^1][i-f[v]]+w[v]);
		}
	}int o=INF;
	rep(i,0,w[x])gmin(o,g[now][i]);
	if(o==INF)return 0;
	f[x]=o;
	return 1;
}
int main(){
	read(n);
	rep(i,2,n)adde(read(),i);
	rep(i,1,n)read(w[i]);
	if(0==gao(1))puts("IMPOSSIBLE");else puts("POSSIBLE");
}

Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

		String a = scan.next();
	    String a2 = null;
	    a2 =a.toUpperCase();
	    char a_front = a2.charAt(0);


		
		
		String b = scan.next();
	    String b2 = null;
	    b2 =b.toUpperCase();
	    char b_front = b2.charAt(0);


		String c = scan.next();
	    String c2 = null;
	    c2 =c.toUpperCase();
	    char c_front = c2.charAt(0);

		
		System.out.println("" + a_front + b_front + c_front + "");

		
	}

}


Measured memory_bytes: 23892
n = int(input())
A = list(map(int, input().split()))
q = int(input())
L = list(map(int, input().split()))
X = list()
for bit in range(1<<n):
  A2 = list()
  for i in range(n):
    if bit & (1<<i):
      A2.append(A[i])
  X.append(sum(A2))
for i in range(q):
  if L[i] in X:
    print('yes')
  else:
    print('no')


Measured memory_bytes: 43072
#include "stdio.h"
int main(){
  int a,b;
  scanf("%d",&a);
  scanf("%d",&b);
  int ans=a+b;
  if(ans<a-b)ans=a-b;
  if(ans<a*b)ans=a*b;
  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int i=0,j=n-1;
    int cnt=0;
    while(i<j)
    {
        while(s[i]=='R'&&i<n)i++;
        while(s[j]=='W'&&j>=0)j--;
        if(i>=j)continue;
        cnt++;
        //cout<<i<<" "<<j<<"\n";
        swap(s[i],s[j]);

    }
    cout<<cnt<<"\n";

}
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=1;__<=_;__++)
    {
        Digvijay();
    }
}



Measured memory_bytes: 3708
# -*- coding: utf-8 -*-


def main():
    n, m = map(int, input().split())
    joken_list = [tuple(map(int, input().split())) for i in range(m)]

    init_num = 0
    if n > 1:
        init_num = 10 ** (n - 1)
    limit_num = 10 ** n

    result = -1
    for i in range(init_num, limit_num):
        match = True
        for keta, value in joken_list:
            if str(i)[keta - 1] != str(value):
                match = False
                break

        if match:
            result = i
            break

    print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define maxn 100010
using namespace std;
int n;
long long ans,x;
long long a[maxn];
int main()
{
    scanf("%d%lld",&n,&x);
    for(int i=1;i<=n;i++){scanf("%lld",&a[i]);ans+=a[i];}
    if(x==0){
    	printf("%lld",ans);
    	return 0;
	}
	ans=0;
    if(a[1]>x){
        ans += a[1]-x;
        a[1]=x;
    }
    for(int i=2;i<=n;i++)
     if(a[i-1] + a[i] >x)ans += a[i-1] +a[i] -x,a[i]=x-a[i-1];
    printf("%lld",ans);
   return 0;
}

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

#define ll long long int
#define vi vector<int>
#define ii pair< int , int >
#define vii vector<ii>
#define FOR(i, n) for(ll i = 0; i < (ll)n; i++)
int MAX(int a, int b){return (a > b) ? a:b;}
int MIN(int a, int b){return (a < b) ? a:b;}
int ABS(int x){return (x > 0) ? x:-x;}
int left(int x){return (x<<1);}
int right(int x){return (x<<1)+1;}
int lsone(int x){return (x&(-x));}

const int maxn = 3e3 + 5;

int n, a[maxn];
ll ans[maxn][maxn][2];
bool found[maxn][maxn][2];

ll dp(int l, int r, bool turn){
	if(r < l) return 0;
	if(found[l][r][turn]) return ans[l][r][turn];
	found[l][r][turn] = true;
	if(turn){//Minimize diff
		ll tmp1 = dp(l+1, r, 1-turn)-a[l];
		ll tmp2 = dp(l, r-1, 1-turn)-a[r];
		ans[l][r][turn] = min(tmp1, tmp2);
	}else{
		ll tmp1 = dp(l+1, r, 1-turn)+a[l];
		ll tmp2 = dp(l, r-1, 1-turn)+a[r];
		ans[l][r][turn] = max(tmp1, tmp2);
	}
	return ans[l][r][turn];
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	printf("%lld\n", dp(0, n-1, 0));
}

Measured memory_bytes: 158208
#include <iostream>
using namespace std;
static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;

int n, M[MAX][MAX];
int prim()
{
    int u, minv;
    int d[MAX], p[MAX], color[MAX];
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = WHITE;
    }
    d[0] = 0;
    while (1)
    {
        minv = INFTY;
        u = -1;
        for (int i = 0; i < n; i++)
        {
            if (minv > d[i] && color[i] != BLACK)
            {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1)
            break;
        color[u] = BLACK;
        for (int v = 0; v < n; v++)
        {
            if (color[v] != BLACK && M[u][v] != INFTY)
            {
                if (d[v] > M[u][v])
                {
                    d[v] = M[u][v];
                    p[v] = u;
                    color[v] = GRAY;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        if (p[i] != -1)
            sum += M[i][p[i]];
    }
    return sum;
}
int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int e;
            cin >> e;
            M[i][j] = (e == -1) ? INFTY : e;
        }
    }
    cout << prim() << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <iostream>
#include <limits>
#include <numeric>
#include <type_traits>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define MOD 1000000007
#define SORT(s) sort(s.begin(), s.end());
#define REVERSE(s) reverse(s.begin(), s.end());
#define SUM(s) accumulate(s.begin(), s.end(), 0LL);
#define P pair<int,int>
#define mp make_pair
#define valid(x,y,h,w) (0<=x&&x<h&&0<=y&&y<w)
//#define int ll
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int ndx[8] = { 0,1,0,-1, 1,1,-1,-1 };
int ndy[8] = { 1,0,-1,0, 1,-1,-1,1 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

template <class T>
void VecRowShow(vector<T> vec) {
	rep(i, vec.size()) {
		if (i != vec.size() - 1) cout << vec[i] << " ";
		else cout << vec[i] << endl;
	}
}

unsigned gcd(unsigned a, unsigned b) {
	if (a < b) return gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

int main() {

	int n;
	cin >> n;

	ll ans = 0;
	FOR(i, 1, n + 1) {
		FOR(j, 1, n + 1) {
			FOR(k, 1, n + 1) {
				ans += gcd(i, gcd(j, k));
			}
		}
	}
	cout << ans << endl;
}




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

# define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
# define FORD(i, a, b) for(int i = (a); i >= (b); --i)
# define VAR(v, i) __typeof(i) v=(i)
# define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define ff first
# define ss second
# define mp make_pair
# define pb push_back
# define next ____next
# define prev ____prev
# define left ____left
# define hash ____hash

using namespace std;

typedef long long lld;
typedef pair<int, int> pii;
typedef pair<lld, lld> pll;

template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}

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

# define MOD 1000000007LL
# define MAXN 100009

int N;
lld arr[MAXN];
lld yerler[MAXN];

lld ans = 1;

int main(){
	cin >> N;
	
	
	FOR(i, 1, N){
		cin >> arr[i];
		
		//~ arr[i] = arr[i] / 2 - (i - 1);
		yerler[i] = (i-1) * 2 + 1;
	}
	
	lld giden = 0;
	lld sana = 0;
	int pnt = 0;
	
	while(pnt != N){
		while(pnt != N  &&  yerler[pnt+1] - 2LL * giden <= arr[pnt+1]){
			sana++;
			pnt++;
		}
		
		if(pnt != N){
			pnt++;
			sana++;
		}
		
		ans = (ans * sana) % MOD;
		
		sana--;
		giden++;
		
		//~ cout << ans << " " << sana << " " << pnt << "\n";
		//~ getchar();
	}
	
	while(sana){
		ans = (ans * sana) % MOD;
		sana--;
	}
	
	cout << ans << "\n";
}


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

int main(void) {
  ll n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];

  int ans = 0;
  for(int i = 0; i<n;i++) {
    if(h[i]>=k){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

template <typename T>
T gcd(T a, T b) {
  while (a) {
    b %= a;
    swap(a, b);
  }
  return b;
}

template <typename T>
T lcm(T a, T b) {
  return a / gcd(a, b) * b;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    A[i] /= 2;
  }
  auto f = [](int x) {
    int res = 0;
    while (x % 2 == 0) {
      x /= 2;
      res++;
    }
    return res;
  };
  int cnt = f(A[0]);
  for (int i = 0; i < N; i++) {
    if (cnt != f(A[i])) {
      cout << 0 << '\n';
      return 0;
    }
  }
  int64_t l = 1;
  for (int i = 0; i < N; i++) {
    l = lcm(l, A[i]);
  }
  cout << (M / l + 1) / 2 << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define mp make_pair
#define pb(x) push_back(x)
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pil pair<int, long long>
#define pli pair<long long, int>
#define pcc pair<char, char>
#define pdd pair<double, double>
#define mll map<long long, long long>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define flsh fflush(stdout)
#define gcd __gcd
#define clr(x) memset(x, 0, sizeof(x))
#define mod 1000000007LL
#define mod2 998244353LL
#define INF 1000000000007
 

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> o_tree;


void solve()
{  
    ll n;
    cin>>n;
    ll i,j;
    map<string ,ll> m;
    for(i=0;i<n;i++)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    ll maxi=1;
    for(auto it:m)
    {
        maxi=max(maxi,it.second);
    }
    vector<string> res;
    for(auto it:m)
    {
        if(it.second==maxi)
        {
            res.pb(it.first);
        }
    }
    sort(all(res));
    for(auto it:res)
    {
        cout<<it<<"\n";
    }
}


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


if (fopen("input.txt","r" ))
  {
     freopen("input.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
  }
cout<<setprecision(20);


ll t=1;


// cin>>t;


while(t--)
{
solve();
} 


return 0;
}

Measured memory_bytes: 27192
//! 尺卂乃卂.卂ﾌ乇乇ㄒ
#include<bits/stdc++.h>
//#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
//Using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> Ordered_set;

#define ll              long long
#define int             long long
#define ld             long double
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define vii             vector<vi>
#define vip            vector<pii>
#define mii             map<int,int>
#define mip             map<pair<int,int>,int>
#define mic             map<char,int> 
#define all(v)          v.begin(),v.end()  
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define lb(x)           (x&(-x))
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
#define itr(it,v)          for(auto it:v)
#define show(arr,n)     for(int i=0;i<n;i++) cout<<arr[i]<<" "; cout<<"\n";
#define fi(i,n)         for(int i=0;i<n;i++)
#define fir(i,k,n)       for(int i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ff               first 
#define ss               second
#define deb(x) cout << #x << "=" << x << endl
#define FIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define check(x) (x && cout<<"Yes\n")||(cout<<"No\n");
#define fin(s)          freopen(s,"r",stdin);  
#define fout(s)         freopen(s,"w",stdout);

const ld pi = 3.141592653589793238462643383279502884;
const int xd[]={-1,0,1,0};
const int yd[]={0,-1,0,1};
int XX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int YY[] = { -1, 0,  1, -1, 1, -1, 0, 1 };

int expo(int a,int b,int m);
int mmi(int a,int m);
void ipgraph(int m);

const int N=5*(1e5)+10;
vii adj(N);
int a[N],b[N];
bool cmp(pii a,pii b){
    if(a.ff==b.ff) return a.ss<b.ss;
    return a.ff<b.ff;
}
void  solve(){

}
int32_t main()
{
    FIO
    int n; cin>>n;
    vip v;
    fi(i,n) {
        cin>>a[i]>>b[i];
        v.pb({a[i],b[i]});
    }
    sort(all(v),cmp);
    int maxz=INT_FAST64_MIN,minz=INT_FAST64_MAX;
    int maxz1=INT_FAST64_MIN,minz1=INT_FAST64_MAX;
    fi(i,n){
        maxz=max(maxz,a[i]+b[i]);
        minz=min(minz,a[i]+b[i]);
        maxz1=max(maxz1,a[i]-b[i]);
        minz1=min(minz1,a[i]-b[i]);
    }
    cout<<max(maxz1-minz1,maxz-minz)<<"\n";
    return 0;

}

void ipgraph(int m){
    int i, u, v;
    while(m--){
          cin>>u>>v;
         u--, v--;
    adj[u].pb(v);
    adj[v].pb(u);
    }
}
int expo(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return a;
    int val=(expo(a,b/2,m)*expo(a,b/2,m))%m;
    if(b & 1) return (val*a)%m;
    else return val;
}
int mmi(int a,int m){
    return expo(a,m-2,m);
}

Measured memory_bytes: 21428
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
const ll BIG=1e15;

int main(){
  int N; cin>>N;
  string S; cin>>S;
  string ans=S;
  for(int i=0;i<ans.size();i++) {
    int X=ans.at(i)-'A';
    X=(X+N)%26;
    ans.at(i)='A'+X;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import io.StdIn._
object Main extends App {
    val n = readInt
    val Array(t, a) = readLine.split(" ").map(_.toInt)
    val hs = readLine.split(" ").map(_.toInt).zipWithIndex

    val sorted = hs.sortWith((x,y) => (a-(t-x._1*0.006)).abs < (a-(t-y._1*0.006)).abs)
    val result = sorted.head._2+1
    println(result)
}

Measured memory_bytes: 54888
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

d,t,s=map(int,input().split())
if d<=t*s:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 69116
#include<bits/stdc++.h>
using namespace std;
const long double PI=3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
inline long long read() {
	long long x=0,f=0;char ch=getchar();
	while(!isdigit(ch))f|=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+(ch^48),ch=getchar();
	return f?-x:x;
}
int main(){
	string s="CODEFESTIVAL2016";
    char c;
    int ans=0;
    for(int i=0;i<16;i++)cin>>c,ans+=(c!=s[i]);
    cout<<ans<<"\n";
    return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define long long long
#define db double
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
template <class T> inline void chmin(T &a, const T& val) { if (a > val) a = val; }
template <class T> inline void chmax(T &a, const T& val) { if (a < val) a = val; }
template <class T> long sqr(T a) { return 1ll * a * a; }
template <class T> void compress(T &a){
  sort(all(a)); a.resize(unique(all(a)) - a.begin());  
}

const db pi = acos(-1.00);
const db eps = 1e-6;
const int INF = 1e9;
const int MOD = 1e9+7;
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};

int main()
{
  fastio;
  int n; cin >> n;
  vector <int> a(n);
  for (int &x : a) cin >> x;
  sort(all(a)); reverse(all(a));
  long res = a[0]; int ptr = 1;
  for (int i = 2; i < n; i += 2){
    res += a[ptr];
    if (i + 1 < n) res += a[ptr];
    ptr++;
  }
  cout << res;
  return 0;
}

Measured memory_bytes: 3996
#pragma GCC optimize("O3")
#pragma GCC target("arch=corei7-avx")

#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <cassert>
#include <cmath>
#include <queue>
#include <ctime>

using namespace std;

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()

int f(int x) {
    int res = 0;
    for (int i = 1; i <= x; i++) {
        if (x % i == 0) ++res;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int res = 0;
    for (int i = 1; i <= n; i += 2) {
        if (f(i) == 8) ++res;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int n,k;
int a[100005];

struct status
{
	int start_now;
	int end_now;
	int len;
}t[200005];

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		scanf("%d",a+i);
		a[i]--;
	}
	ll now=0;
	ll addition=0;
	for(int i=0;i<n-1;i++)
	{
		bool debug=(i==0);
		int st=a[i];
		int ed=a[i+1];
		if(ed<st) ed+=k;
		now+=ed-st;
		if(ed-st<=1) continue;
		st+=2;
		if(st>=k && ed>=k)
		{
			st-=k;
			ed-=k;
		}
		else if(st<k && ed>=k)
		{
			t[0].start_now++;
			t[st].start_now++;
			t[ed-k].len+=ed-st+1;
			t[ed-k].end_now++;
			addition+=k-st;
			continue;
		}
		t[st].start_now++;
		t[ed].end_now++;
		t[ed].len+=ed-st+1;
	}
//	for(int i=0;i<2*k-1;i++)
//	{
//		cout<<t[i].start_now<<' ';
//	}
//	cout<<endl;
//	for(int i=0;i<2*k-1;i++)
//	{
//		cout<<t[i].end_now<<' ';
//	}
//	cout<<endl;
	ll res=now;
	int toadd=0;
	for(int i=0;i<k;i++)
	{
		if(i==0) now-=addition;
		int i1=i;
		int i2=i+k;
		toadd+=t[i1].start_now;
//		toadd+=t[i2].start_now;
		now-=toadd;
//		cout<<now<<' '<<toadd<<endl;
		res=min(res,now);
		toadd-=t[i1].end_now;
//		toadd-=t[i2].end_now;
		now+=t[i1].len;
//		now+=t[i2].len;
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B=1,C=1,D=0,F,G=0,H=0,I=0;
    string S;
    cin >> S;
    if(S[1]>96){
        A=S.size();
        for(int i=2;i<A-1;i++){
            if(S[i]=='C'&&D==1){
                H=1;
                break;
            }
            else if(S[i]=='C'){
                D++;
                F=i;
                H=2;
            }
        }

        for(int i=2;i<A;i++){
            if(i==F)continue;
            if(S[i]<96){
                B=0;
                break;
            }
        }
        if(B==1&&H==2&&S[0]=='A'){
            cout << "AC" << endl;
            C=0;
        }
    }
    if(C||H==1)cout << "WA" << endl;
}


Measured memory_bytes: 256
//gauravsinghh
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 1000000000
#define lim 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
int main(){
    IOS
    //io_set();
    ll n, g = -1;
    cin >> n;
    ll a[n];
    rep(i, n){
      cin >> a[i];
      if(a[i] == 1 && g == -1){
        g = i;
      }
    }
    if(g == -1){
      cout << -1 << endl;
      return 0;
    }
    ll need = 2;
    fo(i, g, n-1){
      if(a[i] == need){
        need++;
      }
    }
    cout << n- need + 1 << endl;
    return 0;
} 




































































































 

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

int main(int argc, char *argv[]) {

	long A; cin >> A;
	double B; cin >> B;
	B = B * 100 + 0.01;

	cout <<  A * long(B) / 100 << endl;
	

	return 0;
}


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

int main() {
  long long int n, ans;

  scanf("%lld", &n);

  ans = n - 1;
  for (long long int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, i + (n / i) - 2);
    }
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

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

    ans = 0;
    rep(i, N){
        int h;
        cin >> h;
        if(h >= K){
            ans++;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  ll N,W;
  cin >> N >> W;
  
  
  //品物iまでを使って得られる重さwの価値の総和の最大値

  ll dp[N][W+1];
  ll w[N],v[N];
  rep(i,N) cin >> w[i] >> v[i];
  rep(i,W+1) dp[0][i]=0;
  dp[0][w[0]]=v[0];
  rep1(i,N-1){
    rep(j,W+1){
      if(j-w[i]>=0){
	dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
	  //	  cout << dp[i][j] << endl;
      }
      else dp[i][j]=dp[i-1][j];
    }
  }
  ll ans=0;
  rep(i,W+1){
    ans = max(dp[N-1][i],ans);
  }
  cout <<ans << endl;

  
  return 0;
    

}


Measured memory_bytes: 78336
A,B=map(int,input().split())
if A<0 and B<0:
    A=-1*A
    B=-1*B
    print(A//B)
elif A<0 and B>0:
    A=-1*A
    print(-1*(A//B))
elif A>=0 and B<0:
    B=-1*B
    print(-1*(A//B))
else:
    print(A//B)


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
//#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
//#include <unordered_map>

using namespace std;

template<typename T> void uin(T &a, T b) {if (b < a) a = b;}
template<typename T> void uax(T &a, T b) {if (b > a) a = b;}

#define int long long
#define double long double
#define all(v) v.begin(), v.end()


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> odd;
	for (int i = 0; i < m; ++i) {
		cin >> a[i];
		if (a[i] & 1) {
			odd.emplace_back(a[i]);
		}
	}
	if ((int)odd.size() > 2) {
		cout << "Impossible\n";
		return 0;
	}
	vector<int> v;
	if (!odd.empty()) v.emplace_back(odd[0]);
	for (int i = 0; i < m; ++i) {
		if (a[i] % 2 == 0) v.emplace_back(a[i]);
	}
	if ((int)odd.size() > 1) {
		v.emplace_back(odd[1]);
	}
	for (int i : v) cout << i << ' ';
	cout << '\n';
	vector<int> ans;
	if (v[0] != 1) ans.emplace_back(v[0] - 1);
	for (int i = 1; i < (int)v.size() - 1; ++i) ans.emplace_back(v[i]);
	if (v.size() != 1) {
		ans.emplace_back(v.back() + 1);
	}
	int sum = 0;
	for (int x : ans) sum += x;
	if (ans.size() == 1 && sum < n) ans.emplace_back(1);
	else if (ans.empty()) ans.emplace_back(1);
	cout << ans.size() << '\n';
	for (int i : ans) {
		cout << i << ' ';
	}
	cout << '\n';
    return 0;
}

/*


*/


Measured memory_bytes: 256
#include<stdio.h>
int main() {
	int a, b, c,buff;
	scanf("%d %d %d", &a, &b, &c);
	if (c < b) {
		buff = b;
		b = c;
		c = buff;
	}
	if (b < a) {
		buff = a;
		a = b;
		b = buff;
	}
	if (c < b) {
		buff = b;
		b = c;
		c = buff;
	}
	printf("%d %d %d\n", a, b, c);
}


Measured memory_bytes: 2744
#include<stdio.h>

#define INF 1000000001
int c = 0;

int L[250001];
int R[250001];

void merge(int array[], int left, int mid, int right) {
  int n1 = mid - left;
  int n2 = right - mid;

  for(int i = 0; i < n1; i++) {
    L[i] = array[left + i];
  }
  for(int i = 0; i < n2; i++) {
    R[i] = array[mid + i];
  }
  L[n1] = INF;
  R[n2] = INF;

  int i = 0;
  int j = 0;

  for(int k = left; k < right; k++) {
    c++;
    if(L[i] <= R[j]) {
      array[k] = L[i];
      i++;
    }
    else {
      array[k] = R[j];
      j++;
    }
  }
}

void mergeSort(int array[], int left, int right) {
  if(left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(array, left, mid);
    mergeSort(array, mid, right);
    merge(array, left, mid, right);
  }
}

int main(void) {
  int n;
  int array[500000];

  scanf("%d", &n);
  for(int i = 0; i < n; i++) {
    scanf("%d", &array[i]);
  }

  mergeSort(array, 0, n);
  for(int i = 0; i < n; i++) {
    if(i > 0) {
      printf(" ");
    }
    printf("%d", array[i]);
  }
  printf("\n");
  printf("%d\n", c);
  return 0;
}

Measured memory_bytes: 4936
#include <cstdio>
using namespace std;

int a,b;
char c;

int main(){

	while(1){
		scanf("%d %c %d", &a,&c,&b);
		if(c == '?'){
			break;
		}else if(c == '+'){
			printf("%d\n", a+b);
		}else if(c == '-'){
			printf("%d\n", a-b);	
		}else if(c == '*'){
			printf("%d\n", a*b);
		}else if(c == '/'){
			printf("%d\n", a/b);
		}
	}
}


Measured memory_bytes: 2716
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

const MOD:i64 = 1000000007;

fn main(){
    input! {
        n: usize,
        an: [i64;n],
    }
    let mut ans = 0;
    let mut count = 0;
    for i in 0..n {
        ans = (ans + (an[i] * count)) % MOD;
        count = (count + an[i])% MOD;
    }
    println!("{}",ans);
}

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

using namespace std;
typedef long long ll;

#define floop(i, N) for (ll i = 0; i < N; i++)
#define floop1(i, N) for (ll i = 1; i <= N; i++)
#define out(ans) cout << ans << endl
#define in(n) cin >> n

constexpr ll inf = 1e18;

void solve();

int main()
{
    solve();
}

void solve()
{
    char b;
    in(b);
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['G'] = 'C';
    m['C'] = 'G';
    out(m[b]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            res.push_back(i);
            if (i != n / i) res.push_back(n / i);
        }
    }
    return res;
}

int main() {
    ll n, sum = 0;
    cin >> n;
    vector<ll> ls = divisor(n);
    for(auto i : ls){
        i--;
        if(i > 0 && n/i == n%i){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


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

typedef long long ll;

int main() {
	int N; cin >> N;
	int A, B; cin >> A >> B;
	vector<int> P(N), c(3,0);
	for (int i = 0; i < N; i++) {
		cin >> P[i];
		if(P[i]<=A) c[0]++;
		if(A+1<=P[i] && P[i]<=B) c[1]++;
		if(B+1<=P[i]) c[2]++;
	}
	int ans = min(c[0],min(c[1],c[2]));
	cout << ans << endl;
}


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

#define ll long long
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)

const ll MOD = 1e9+7;

// Combinationの使い方
// vector<vector<ll>> v(N+1, vector<ll>(N+1, 0));
// comb(v);
void comb(vector<vector<ll>> &v){
    for(int i = 0; i < v.size(); i++){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(int k = 1; k < v.size(); k++){
        for(int j = 1; j < k; j++){
            v[k][j] = (v[k-1][j-1] + v[k-1][j]);
            //余りを求める問題は毎回計算ごとにやる
            // v[k][j] = (v[k-1][j-1] + v[k-1][j]) % MOD;
        }
    }
}

// Union Find
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;
    }
};

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

// 1 << 3 : int "3" change to bit "100"
// rep(pattern, 1 << N) if (pattern & (1 << x)) cnt++

int check(int N, vector<int> &d){
    while(N!=0){
        rep(i,d.size()){
            if(d[i] == N % 10) return 1;
        }
        N /= 10;
    }
    return 0;
}

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

    vector<int> D(K,0);
    rep(i,K) cin >> D[i];

    while(check(N,D)) N++;

    cout << N << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T1, class T2>bool chmax(T1& a, const T2& b) { return a < b ? a = b, 1 : 0; }
template<class T1, class T2>bool chmin(T1& a, const T2& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int main() {
    int A, B;
    cin >> A >> B;

    if (abs(A - B) % 2 == 0) {
        write((A + B) / 2);
    }
    else {
        write("IMPOSSIBLE");
    }
}

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

using namespace std;


int main(){
    int N; cin >> N;
    int W[N];

    for (int i = 0; i < N; i++) cin >> W[i];
    
    int s = accumulate(W, W+N, 0);
    int s1,s2;
    int res = 100000000;
    for (int i = 2; i < N; i++){
        s1 = 0;
        for (int j = 0; j < i; j++){
            s1 += W[j];
        }
        s2 = s - s1;
        res =  min(res, abs(s1-s2));
    }

    cout << res << endl;
}
        






Measured memory_bytes: 256
import java.util.*;
public class Main {
  
 public static void main(String args[]){
   int N=0,k=0;

   Scanner obj=new Scanner(System.in);
   N=obj.nextInt();
k=obj.nextInt();
   int h[]=new int[N];
   for(int i=0;i<N;i++){
    h[i]=obj.nextInt();
   }
   int dp[]=new int[N];
	if(N==0)
      {
System.out.println(0);
return;
}
   if(N==1)
{     	
System.out.println(0);
return;
}
   if(N<=k+1)
     {
System.out.println(Math.abs(h[0]-h[N-1]));
return;
}
   dp[0]=0;
 //  dp[1]=Math.abs(h[0]-h[1]);
   for(int i=1;i<N;i++){
dp[i]=Integer.MAX_VALUE;
   for(int j =1;j<=i && j <=k;j++){
    dp[i]= Math.min(Math.abs(h[i]-h[i-j])+dp[i-j],dp[i]);
}
   }
   System.out.println(dp[N-1]);
 }
}


Measured memory_bytes: 59724
#include <iostream>
using namespace std;
int a, b, c;
int main(void){
    // Your code here!
    cin >> a >> b;
    if (a > b) {
        c = b;
        b = a;
        a = c;
    }
    while (b % a != 0) {
        c = b % a;
        b = a;
        a = c;
    }
    cout << a << endl;
}



Measured memory_bytes: 3076
#include <iostream>
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <climits>
#include <math.h>
#include <cassert>
#include <unordered_map>
#include <chrono>
#include <random>
#include <ctime>
using namespace std;
#pragma warning(disable : 4996)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const ld PI = 3.14159265358979323846;
const ll MOD = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


int main() {
#ifdef _DEBUG
	freopen("input1.txt", "r", stdin);
	freopen("output2.txt", "w", stdout);
#endif
	srand(time(0));
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int wa = 0, tle = 0, ac = 0, re = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (s == "AC")ac++;
		else if (s == "TLE")tle++;
		else if (s == "RE")re++;
		else wa++;
	}
	cout << "AC x " << ac << "\n";
	cout << "WA x " << wa << "\n";
	cout << "TLE x " << tle << "\n";
	cout << "RE x " << re << "\n";
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int mod=1e9+7;
ll dp[1<<21];
int main(){
    int n;
    cin>>n;
    int a[n][n];
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    dp[0]=1;
    for(int mask=0;mask<(1<<n)-1;mask++){
        int c=__builtin_popcount(mask);
        for(int b=0;b<n;b++){
            if(a[c][b]&&!(mask&(1<<b))){
                int m2=mask^(1<<b);
                dp[m2]=(dp[m2]+dp[mask])%mod;
            }
        }
    }

    cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 16640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
5 4
0 1
1 2
2 3
3 4

output:
1
2
3
"""

import sys

sys.setrecursionlimit(int(1e6))


def generate_adj_table(_v_info):
    for v_detail in _v_info:
        source, target = map(int, v_detail)
        init_adj_table[source].append(target)
        init_adj_table[target].append(source)
    return init_adj_table


def Tarjan(current, parents, visited, disc, low):
    global timer
    current_children_count = 0
    visited[current] = True
    disc[current] = low[current] = timer
    timer += 1

    for adj in adj_table[current]:
        if not visited[adj]:
            parents[adj] = current
            current_children_count += 1

            Tarjan(adj, parents, visited, disc, low)

            low[current] = min(low[current], low[adj])
            # current is root of DFS tree
            if parents[current] == -1 and current_children_count > 1:
                art_set.add(current)

            elif parents[current] != -1 and low[adj] >= disc[current]:
                art_set.add(current)

        elif adj != parents[current]:
            low[current] = min(low[current], disc[adj])

    # print(timer, parents, visited, disc, low)
    return None


def art_points():
    parents = [-1] * vertices
    visited = [False] * vertices
    disc = [float('inf')] * vertices
    low = [float('inf')] * vertices

    for v in range(vertices):
        if not visited[v]:
            Tarjan(v, parents, visited, disc, low)

    return art_set


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices, edges = map(int, _input[0].split())
    v_info = map(lambda x: x.split(), _input[1:])
    init_adj_table = tuple([] for _ in range(vertices))
    adj_table = generate_adj_table(v_info)

    timer = 0
    art_set = set()
    ans = art_points()
    if ans:
        print(*sorted(ans), sep='\n')

Measured memory_bytes: 23784
// ARC083
// D - Restoring Road Network

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 300;

int N;
int g[MAX_N][MAX_N];

ll solve() {
    ll ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            bool is_adj = true;
            for (int k = 0; k < N; k++) {
                if (k == i || k == j) {
                    continue;
                }
                if (g[i][j] > g[i][k] + g[k][j]) {
                    return -1;
                }
                if (g[i][j] == g[i][k] + g[k][j]) {
                    is_adj = false;
                }
            }
            if (is_adj) {
                ans += g[i][j];
            }
        }
    }
    return ans / 2;
}

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> g[i][j];
        }
    }

    cout << solve() << endl;

    return 0;
}


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

int n;
char s;
int flag=0;
int main()
{
    cin>>n;
    for (int i=0; i<n; ++i)
    {
        cin>>s;
        if (s=='Y')
            flag=1;
    }
    if (flag) cout<<"Four"<<endl;
    else cout<<"Three"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define INF 100000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define MAX 101

int main(){
    int i,j,n;
    int mincost,u,v,sum=0;
    
    scanf("%d",&n);
    
    int color[n];
    int d[n];
    int M[n][n];
    int p[n];
    
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            M[i][j]=-1;
        }
    }
    
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            scanf("%d",&M[i][j]);
        }
    }
    
    for(i=0;i<n;i++){
        color[i]=WHITE;
        d[i]=INF;
    }
    d[0]=0;
    p[0]=-1;
    
    while(1){
        mincost=INF;
        for(i=0;i<n;i++){
            if(color[i]!=BLACK && d[i]<mincost){
                mincost=d[i];
                u=i;
            }
        }
        if(mincost==INF)break;
        
        sum+=mincost;
        color[u]=BLACK;
        
        for(v=0;v<n;v++){
            if(color[v]!=BLACK && M[u][v]!=-1){
                if(M[u][v]<d[v]){
                    d[v]=M[u][v];
                    p[v]=u;
                    color[v]=GRAY;
                }
            }
        }
    }
    printf("%d\n",sum);
    
    return 0;
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <limits>
#include <math.h>
#include <cmath>
#include <cctype>
#include <cstdio>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int> ;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vvll = vector<vector<long long >>;
#define PI 3.141592653
#define rep(i, k, n) for(ll i = k; i < n; i++)

int main(){
  ll n; cin >> n;

  ll k = n % 1000;
  
  if(k == 0){cout << 0 << endl;}
  else{cout << 1000 - k << endl;}
  
}


Measured memory_bytes: 3620
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  string n; cin >>n;
  ll key=0;
  rep(i, n.size()){
    char u=n.at(i);
    int a=u-'0';
    key+=a;
}
  if(key%9==0){
    cout <<"Yes"<<endl;
  }else{
    cout <<"No"<<endl;
  }
}

Measured memory_bytes: 3708
#include<bits/stdc++.h>
using namespace std;
long long N,ans;

map<long long,int>prime_factor(long long n){
	map<long long,int>factor;
    for(long long i=2LL;i*i<=n;i++)while(n%i==0LL){factor[i]++;n/=i;}
    if(n!=1LL)factor[n]=1;
    return factor;
}

int main(){
    cin>>N;
    map<long long,int>prime=prime_factor(N);
    for(auto x:prime){
        long long num=1LL;
        while(num*(num+1LL)/2LL<=x.second){ans++;num++;}
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include <stdio.h>

int main() {
  int arr[26]={0};
  char c;
  while (scanf("%c", &c)!=EOF) {
    arr[c-'a']++;
  }

  for (int i=0; i<26; i++) {
    if (arr[i]%2==1) {
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");
  return 0;
}

Measured memory_bytes: 128