akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

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

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
typedef pair<int,int> P;
#define F first
#define S second
int n,q;
P d[4*1000005];
void init(int n_){
  n=1;
  while(n<n_) n*=2;
  for(int i=0;i<n-1;i++) {
    d[i].F=0;
    d[i].S=0;
  }
  for(int i=n-1;i<2*n-1;i++) {
    d[i].F=0;
    d[i].S=i-n+1;
  }
}
void update(int k,int a){
  k+=n-1;
  d[k].F+=a;
  while(k>0){
    k=(k-1)/2;
    if(d[k*2+1].F>=d[k*2+2].F) {
      d[k].F=d[k*2+1].F;
      d[k].S=d[k*2+1].S;
    }else{
      d[k].F=d[k*2+2].F;
      d[k].S=d[k*2+2].S;
    }
  }
}
int query(int a,int b,int k,int l,int r){
  if(r<=a || b <= l ) return 0;
  if(a<=l&&r<=b) return d[k].S;
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    if(d[vl].F>=d[vr].F) return vl;
    else return vr;
  }
}
int main(){
  int a,b;
  cin >> n >> q;
  init(n);
  for(int i=0;i<q;i++){
    cin >> a >> b;
    a--;
    update(a,b);
    int x=query(0,n,0,0,n);
    cout << x+1 << " " << d[n-1+x].F << endl;
  }
  return 0;
}

Measured memory_bytes: 32408
#include<bits/stdc++.h>
using namespace std;
const int Maxn=3e5+1;
int qzhl[Maxn],qzhr[Maxn];
char s[Maxn];
int n; 

int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>s[i];
	}
	
	qzhl[1]=0;
	for(int i=1;i<n;i++){
		qzhl[i+1]=qzhl[i];
		if(s[i]=='W')qzhl[i+1]++;
	}
	qzhr[n]=0;
	for(int i=n;i>1;i--){
		qzhr[i-1]=qzhr[i];
		if(s[i]=='E')qzhr[i-1]++;
	}
	int ans=Maxn;
	for(int i=1;i<=n;i++){
		ans=min(ans,qzhl[i]+qzhr[i]);
	}
	cout<<ans;
}

Measured memory_bytes: 2944
/*
━━━━━┒ギリギリ♂ eye！
┓┏┓┏┓┃キリキリ♂ mind！
┛┗┛┗┛┃＼○／
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb;

const int maxn = 55;
const int maxm = 2550;
LL dp[maxn][maxn][maxm];
int n, a;
int x[maxn];

int main() {
	// FRead();
	while(~Rint(n) && ~Rint(a)) {
		Cls(dp); dp[0][0][0] = 1;
		Rep(i, n) cin >> x[i];
		For(i, 1, n+1) {
			Rep(j, n+1) {
				Rep(k, 2501) {
					dp[i][j][k] += dp[i-1][j][k];
					if(j >= 1 && k >= x[i-1]) {
						dp[i][j][k] += dp[i-1][j-1][k-x[i-1]];
					}
				}
			}
		}
		LL ret = 0;
		For(i, 1, n+1) ret += dp[n][i][a*i];
		cout << ret << endl;
	}
	RT 0;
}

Measured memory_bytes: 60544
/* ex 5-4
   TakayukiY*/

#include<stdio.h>

int main(void){
    //10文字以下の入力なので11文字分確保、ポインターの定義
    char seqence[11],*ptr;
    //インデックスと最大の長さの定義
    int i=0,max=0;
    //文字列を格納
    scanf("%s",seqence);
    //ポインターを格納
    ptr=seqence;

    while(*ptr){
        //ACGTの文字が現れたとき、現在の連続数iに1を加える
        if(*ptr=='A'||*ptr=='C'||*ptr=='G'||*ptr=='T'){
            i++;
        }
        //ACGT以外の文字が現れたとき、連続数iが今までの最大を超えれば更新
        //連続数iを初期化
        else{
            if(max<i) max=i;
            i=0;
        }
        ptr++;
    }
    //最後の文字までACGTだった場合の更新
    if(max<i) max=i;

    printf("%d",max);

    return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <sstream>
using namespace std;

typedef long long LL;
#define lowbit(x) ((x)&(-x))
#define INF 0x3f3f3f3f
#define memset(a,b) memset(a,b,sizeof(a))
#define	GE() printf(">----------\n")
#define	IN() freopen("in.txt","r",stdin)
#define	OUT() freopen("out.txt","w",stdout)
const LL mod=1000000007;
const int inf=0x3f3f3f3f;
const double pi=acos(-1.0);
const double eps=1e-8;
const int maxn=100005;

LL n, m;

LL A(LL x, LL y){
    LL val=1;
    while(y--){
        val=(val*x--)%mod;
    }
    return val;
}

int main()
{
    while(~scanf("%lld%lld", &n, &m)){
        LL ans=0;
        if(abs(n-m)<2){
            ans=((A(n, n)%mod)*(A(m, m)%mod))%mod;
            if(n==m)ans=(ans*2)%mod;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 256
import std.stdio;

void main() {
  int width, height;
  while(readf("%d %d\n", &width, &height), (width + height) != 0) {
    int[][] route = new int[][](width + 1, height + 1);
    int number;
    readf("%d\n", &number);
    for(int i, j, n = 0; n < number; n++) {
      readf("%d %d\n", &i, &j);
      route[i][j] = -1;
    }
    
    route[1][1] = 1;
  
    for(int i = 1; i <= width; i++) {
      for(int j = 1; j <= height; j++) {
        if (route[i][j] == -1) continue;
        if (route[i - 1][j] >= 0) route[i][j] += route[i - 1][j];
        if (route[i][j - 1] >= 0) route[i][j] += route[i][j - 1];
      }
    }
    writeln(route[width][height]);
  }
}

Measured memory_bytes: 1068
# include "iostream"
# include "cstdio"
# include "queue"

using namespace std;

const int maxm=1e5+10;
const long long Inf=1ll<<50;

int head[maxm],tot=1,N,Cnt,S,T;
int Deep[maxm];
long long A[maxm];

struct edge{
	int To;
	int Next;
	long long Value;
	# define To(x) Edge[x].To
	# define Next(x) Edge[x].Next
	# define Value(x) Edge[x].Value
}Edge[maxm<<1];

inline void Add_Edge(int From,int To,long long Value){Edge[++tot]=(edge){To,head[From],Value},head[From]=tot;return;}
inline void Insert_Edge(int From,int To,long long Value){Add_Edge(From,To,Value);Add_Edge(To,From,0);return;}

inline bool Bfs(int S,int T){
    register int i,x;
    for(i=1;i<=N+2;i++) Deep[i]=0;
    queue<int> q;
    q.push(S);
    Deep[S]=1;
    while(q.size()){
        x=q.front(),q.pop();
        for(i=head[x];i;i=Next(i)){
            if(Value(i) && !Deep[To(i)]){
                q.push(To(i));
                Deep[To(i)]=Deep[x]+1;
                if(To(i)==T) return true;
            }
        }
    }
    return false;
}

long long Dfs(int now,long long Now){
    if(now==T) return Now;
    long long Rest=Now,Reduce;
    for(int i=head[now];i && Rest;i=Next(i)){
        if(Value(i) && Deep[To(i)]==Deep[now]+1){
            Reduce=Dfs(To(i),min(Rest,Value(i)));
            if(!Reduce) Deep[To(i)]=0;
            Value(i)-=Reduce;
            Value(i^1)+=Reduce;
            Rest-=Reduce;
        }
    }
    return Now-Rest;
}

int main(){
	register int i,j;
	register long long Ans=0,Now,Max=0;
	scanf("%d",&N);
	for(i=1;i<=N;i++)	scanf("%lld",A+i);
	S=N+1;
	T=N+2;
	for(i=1;i<=N;i++){
		if(A[i]>0){
			Insert_Edge(S,i,A[i]);
			Ans+=A[i];
		}else{
			Insert_Edge(i,T,-A[i]);
		}
	}
	for(i=1;i<=N;i++){
		for(j=i<<1;j<=N;j+=i){
			Insert_Edge(j,i,Inf);
		}
	}
	while(Bfs(S,T)){
		while(Now=Dfs(S,Inf)){
			Max+=Now;
		}
	}
	cout<<Ans-Max<<endl;
	return 0;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define debug(...) \
    { cerr << "# " << __VA_ARGS__ << "\n"; }
#else
#define debug(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
   public:
    void solve() {
        string s;
        int k;
        cin >> s >> k;
        i64 ans = 0;
        int cur = 0;
        for (int i = 0; i < s.size(); ++i) {
            int num = s[i] - '0';
            for (int j = 0; j < num; ++j) {
                if (j == 0)
                    ans += cal(s.size() - i - 1, k);
                else
                    ans += cal(s.size() - i - 1, k - 1);
            }
            if (num != 0)
                --k;
        }
        if (k == 0)
            ans++;
        cout << ans << '\n';
    }
    i64 d[4] = {1, 9, 9 * 9, 9 * 9 * 9};
    i64 cal(int len, int k) {
        if (k < 0)
            return 0;
        if (k > len)
            return 0;
        if (len == k)
            return d[k];
        i64 res = 1;
        for (int i = 0; i < k; ++i) res = res * (len - i);
        for (int i = 1; i <= k; ++i) res /= i;
        return res * d[k];
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
#define all(v) v.begin(), v.end()
const ll MX = 1e18; //1(1倍)e(指数)18(10^18)
int main() {
    int n;
    scanf("%d", &n);
    vector<ll> a(n);
    // Nの合計 - xの合計 = yは合計、最小の|y - x|=|(N - x) - x|=N - 2 * x
    ll sum = 0;
    ll x = 0;
    ll ans = MX;
    rep(i, n) {
        scanf("%lld", &a[i]);
        sum += a[i];
    };
    rep(i, n) {
        x += a[i];
        // 必ず1枚以上選ぶ必要があるので
        if (i + 1 < n) ans = min(ans, abs(sum - 2 * x));
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4780
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int n,ap[1<<20][26];ll ans;
char buf[1<<20];
string s[1<<18];
struct trie{
	struct{
		int ch[26],fin,vis=-1;
	}a[1<<21];
	int tot,rt;
	void ins(char*s,int l,int&p){
		if(!p)p=++tot;
		if(l<0){a[p].fin=1;return;}
		ins(s-1,l-1,a[p].ch[*s-'a']);
	}
}tr;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf(" %s",buf),s[i]=buf;
		int n=s[i].size();
		tr.ins(&s[i].back(),n-1,tr.rt);
	}
	for(int i=0;i<n;i++){
		int n=s[i].size();
		int p=tr.rt;
		for(int j=0;j<26;j++)ap[0][j]=j+'a'==s[i][0];
		for(int j=1;j<n;j++){
			memcpy(ap[j],ap[j-1],sizeof ap[0]);
			ap[j][s[i][j]-'a']=1;
		}
		for(int j=n-1;~j;j--){
			if(j)for(int k=0;k<26;k++)if(ap[j-1][k]){
				int np=tr.a[p].ch[k];
				if(!np || tr.a[np].vis==i)continue;
				tr.a[np].vis=i;
				if(tr.a[np].fin)ans++;
			}
			if(tr.a[p].vis!=i){
				tr.a[p].vis=i;
				if(tr.a[p].fin)ans++;
			}
			p=tr.a[p].ch[s[i][j]-'a'];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

 ll N, K;

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

	cin >> N >> K;

	if (K % 2 == 1) {
		ll x = N / K;
		cout << x*x*x << "\n";
	}
	else {
		ll x = N / K;
		ll y = N / (K / 2);
		y -= x;
		cout << y*y*y + x*x*x << "\n";
	}

}

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

#include <vector>
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
using namespace std;

int main() {
  map<long, long> mp;
  long N, tmp;
  cin >> N;
  rep(i, N - 1) {
    cin >> tmp;
    if (mp.count(tmp) == 0) {
      mp[tmp] = 1;
    } else {
      mp[tmp]++;
    }
  }
  rep(i, N) {
    if (mp.count(i + 1) == 0) {
      cout << 0 << endl;
    } else {
      cout << mp[i + 1] << endl;
    }
  }
}

Measured memory_bytes: 16052
#include <stdio.h>
#include <math.h>

int main(void) {
	double x;
	double y;
	double angle;
	int kazu;
	int i;
	while(1) {
		scanf("%d",&kazu);
		if(kazu==-1)break;
		x=1; 
		y=0;
		for(i=1;i<kazu;i++) {
			angle=atan2(y,x);
			x-=sin(angle);
			y+=cos(angle);
		}
		printf("%f\n%f\n",x,y);
	}
	return 0;
}

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

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

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

int main(){
  int N,A=0,B=0;
  cin >> N;
  vector<int> card(N);
  for(int i=0;i<N;i++){
    cin >> card.at(i);
  }
  sort(card.begin(),card.end());
  reverse(card.begin(),card.end());
  for(int i=0;i<N/2;i++){
    A += card.at(2*i);
    B += card.at(2*i+1);
  }
  if(N%2==1)
    A += card.at(N-1);
  cout << A-B;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        String s = sc.next();

        int l = s.length();
        int[] a = new int[l + 1], ax = new int[l + 1];
        int[] c = new int[l + 1], cx = new int[l + 1];
        long[] pow2 = new long[l + 1], pow3 = new long[l + 1];
        pow2[0] = 1;
        pow3[0] = 1;

        for (int i = 0; i < l; i++) {
            a[i + 1] += a[i];
            ax[i + 1] += ax[i];
            c[l - i - 1] += c[l - i];
            cx[l - i - 1] += cx[l - i];
            pow2[i + 1] = pow2[i] * 2 % MOD;
            pow3[i + 1] = pow3[i] * 3 % MOD;

            switch (s.charAt(i)) {
                case 'A':
                    a[i + 1]++;
                    break;
                case '?':
                    ax[i + 1]++;
            }
            switch (s.charAt(l - i - 1)) {
                case 'C':
                    c[l - i - 1]++;
                    break;
                case '?':
                    cx[l - i - 1]++;
            }
        }

//        debug(a, ax);
//        debug(c, cx);

        long ans = 0;
        for (int i = 1; i < l - 1; i++) {
            if (s.charAt(i) == 'B' || s.charAt(i) == '?') {
                long cnt = 0;
                long x1 = 1L * a[i] * c[i + 1] % MOD * pow3[ax[i]] % MOD * pow3[cx[i + 1]] % MOD;
                long x2 = (cx[i + 1] > 0) ? 1L * a[i] * cx[i + 1] % MOD * pow3[ax[i]] % MOD * pow3[cx[i + 1] - 1] % MOD : 0;
                long x3 = (ax[i] > 0) ? 1L * ax[i] * c[i + 1] % MOD * pow3[ax[i] - 1] % MOD * pow3[cx[i + 1]] % MOD : 0;
                long x4 = (ax[i] > 0 && cx[i + 1] > 0) ? 1L * ax[i] * cx[i + 1] % MOD * pow3[ax[i] - 1] % MOD * pow3[cx[i + 1] - 1] % MOD : 0;
//                debug(x1, x2, x3, x4);
                ans = (ans + x1 + x2 + x3 + x4) % MOD;
            }
        }

        out.println(ans);

        out.flush();
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 29664
#include <bits/stdc++.h>
#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(auto it=(X).begin();it!=(X).end();it++)
#define numa(x,a) for(auto x: a)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define pf push_front
#define sec second
#define sz(x) ((int)(x).size())
#define ALL( c ) (c).begin(), (c).end()
#define gcd(a,b) __gcd(a,b)
#define mem(x,n) memset(x,n,sizeof(x))
#define endl "\n"
using namespace std;
template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple){}
template <int POS, class TUPLE, class H, class ...Ts> void deploy(std::ostream &os, const TUPLE &t){ os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); }
template <class T,class U> std::ostream& operator<<(std::ostream &os, std::pair<T,U> &p){ os << "(" << p.first <<", " << p.second <<")";return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::vector<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T> std::ostream& operator<<(std::ostream &os, std::set<T> &v){ int remain = v.size(); os << "{"; for(auto e: v) os << e << (--remain == 0 ? "}" : ", "); return os; }
template <class T, class K> std::ostream& operator<<(std::ostream &os, std::map<T, K> &mp){ int remain = mp.size(); os << "{"; for(auto e: mp) os << "(" << e.first << " -> " << e.second << ")" << (--remain == 0 ? "}" : ", "); return os; }
#define DEBUG1(var0) { std::cerr << (#var0) << "=" << (var0) << endl; }
#define DEBUG2(var0, var1) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG2(var1,var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << (#var0) << "=" << (var0) << ", ";DEBUG3(var1,var2,var3); }
using ll = long long;

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int H,W;
  cin >> W >> H;
  vector <ll> p(W);
  vector <ll> q(H);
  rep(i,W){
    cin >> p[i];
  }
  rep(i,H){
    cin >> q[i];
  }
  sort(ALL(p)); sort(ALL(q));
  p.push_back(INF); q.push_back(INF);
  reverse(ALL(p)); reverse(ALL(q));
  int w = W, h = H;
  ll ans = 0;
  while (true) {
    if (w == 0 && h == 0) {
      break;
    }
    //DEBUG1(ans);
    if (p.back() > q.back()) {
      ans += q.back() * (w + 1);
      q.pop_back();
      h -= 1;
    }else{
      ans += p.back() * (h + 1);
      p.pop_back();
      w -= 1;
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(ll i=0;i<N;i++)
int const INF=1000000000;
int DP[100001][3];
typedef long long ll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i=0;i<100001;i++){
        DP[i][0]=-1;
        DP[i][1]=-1;
        DP[i][2]=-1;
    }
    int N;
    cin>>N;
    vector<int>a(N+1);
    vector<int>b(N+1);
    vector<int>c(N+1);
    for(int i=1;i<=N;i++){
        cin>>a[i]>>b[i]>>c[i];
    }
    DP[0][0]=0;
    DP[0][1]=0;
    DP[0][2]=0;
    for(int i=1;i<=N;i++){
        DP[i][0]=max(DP[i-1][1]+a[i],DP[i-1][2]+a[i]);
        DP[i][1]=max(DP[i-1][0]+b[i],DP[i-1][2]+b[i]);
        DP[i][2]=max(DP[i-1][0]+c[i],DP[i-1][1]+c[i]);
    }
    cout<<max({DP[N][0],DP[N][1],DP[N][2]})<<endl;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
  
int main() {
  int A, B, C, D, sum;
  cin >> A >> B >> C >> D;
  sum = A + B - (C + D);
  if (sum > 0) {
    cout << "Left" << endl;
  } 
  if (sum == 0) {
    cout << "Balanced" << endl;
  }
  if (sum < 0) {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
import heapq
from collections import defaultdict
v_num = int(input())
edges = defaultdict(list)
for i in range(v_num):
    data = [int(n) for n in input().split(" ")[1:]]
    for j in range(i + 1, v_num):
        if data[j] != -1:
            edges[i].append([data[j], j])
            edges[j].append([data[j], i])
queue = []
heapq.heapify(queue)
for c in edges[0]:
    heapq.heappush(queue, c)
visited = {0}
answer = 0
while len(visited) < v_num:
    q = heapq.heappop(queue)
    weight, one = q[0], q[1]
    if one in visited:
        continue
    answer += weight
    for e in edges[one]:
        heapq.heappush(queue, e)
    visited |= {one}
print(answer)

Measured memory_bytes: 9064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5; 

#define endl "\n"

priority_queue<int> Maxheap;
priority_queue<int,vector<int>,greater<int> > Minheap;

ll l,r,B;

void insert(int x){
	if(Maxheap.empty()) {
		Maxheap.push(x);
		l+=x;
	}
	else {
		if(x<=Maxheap.top()){
			Maxheap.push(x);
			l+=x;
			if((int)Maxheap.size()-(int)Minheap.size()>=2){
				int t=Maxheap.top();
				Maxheap.pop();
				Minheap.push(t);
				l-=t;
				r+=t; 
			}
		}
		else {
			Minheap.push(x);
			r+=x;
			if(Minheap.size()>Maxheap.size()){
				int t=Minheap.top();
				Minheap.pop();
				Maxheap.push(t);
				l+=t;
				r-=t;
			}
		}
	}
} 

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int q,op,a,b,x;
	cin>>q;
	l=r=B=0;
	while(q--){
		cin>>op;
		if(op==1) {
			cin>>a>>b;
			insert(a);
			B+=b;
		}
		else{
			if(!Maxheap.empty()) x=Maxheap.top();
			else x=0;
			cout<<x<<' '<<((ll)Maxheap.size()*x-l)+(r-(ll)Minheap.size()*x)+B<<endl;
		}
	}
	return 0;
}

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

using namespace std;

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

#define X first
#define Y second

const int N=1e5+10;
const int MOD=1e9+7,BASE=43;
const int inf=1e9+10;



int n,a[N];
int f[N];
int re[N][2];
int sign(int x){
    if (x==0) return x;
    if (x<0) return -1;
    return 1;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",a+i);
    re[1][0]=re[1][1]=1;
    for(int i=2;i<=n;i++){
        int val=sign(a[i]-a[i-1]);
        if (val!=-1) re[i][1]=re[i-1][1];
        else re[i][1]=i;
        if (val!=1) re[i][0]=re[i-1][0];
        else re[i][0]=i;
    }
    for(int i=1;i<=n;i++)
        f[i]=min(f[re[i][0]-1],f[re[i][1]-1])+1;
    cout<<f[n]<<'\n';
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

		while (sc.hasNext()) {
			for (int i = 0; i < 3; i++) {
				enter_time[i] = sc.nextInt();
			}

			for (int i = 0; i < 3; i++) {
				leave_time[i] = sc.nextInt();
			}

			timeCalculatror(enter_time, leave_time);
		}


	}
	private static void timeCalculatror(int[] enter_time, int[] leave_time) {
		int time_ans = 3600 * (leave_time[0] - enter_time[0]) +
						60 *  (leave_time[1] - enter_time[1]) +
							  (leave_time[2] - enter_time[2]);

		int[] a_hms = new int[3];

		a_hms[0] = time_ans / 3600;
		a_hms[1] = (time_ans % 3600) / 60;
		a_hms[2] = time_ans % 60;

		System.out.printf("%d %d %d\n", a_hms[0], a_hms[1], a_hms[2]);
	}


}


Measured memory_bytes: 26416
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
using namespace std;

int n, a[110000], ans;
int b[110000];
int dp[110000][33];

int get(int x) {
	if (x == 1)
		return 0;
	int l = 0, r = 31;
	while (l < r - 1) {
		int mid = (l + r) / 2;
		if ((1 << mid) >= x)
			r = mid;
		else
			l = mid;
	}
	return r;
}

void up(int &x, int y) {
	x = min(x, y);
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		b[i] = get(a[i]);
	}
	dp[0][0] = 0;
	for (int i = 1; i <= 32; i++)
		dp[0][i] = 1e9;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= 32; j++)
			dp[i][j] = 1e9;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j <= 32; j++) {
			int p = j, cost = dp[i - 1][j];
			if ((1 << b[i]) != a[i]) {
				if (p > 0) {
					up(dp[i][max(0, b[i] - 1)], cost + max(0, b[i] - p));
				}
				up(dp[i][b[i]], cost + max(1, b[i] - p));
			}else {
				up(dp[i][b[i]], cost + max(0, b[i] - p));
			}
		}
	ans = 1e9;
	for (int i = 0; i <= 32; i++)
		ans = min(ans, dp[n][i]);
	printf("%d\n", ans);
}


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

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

int main()
{
	string s, t ;
	cin >> s >> t ;
	
	int ans = INF ;
	for (int i=0; i + t.size() <= s.size(); i++)
	{
		int tmp = 0 ;
		for (int j=0; j<t.size(); j++)
			if (s[i+j] != t[j])
				tmp++ ;
				
		ans = min (ans, tmp) ;
	}
	
	cout << ans << endl ;

	return 0 ;
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#pragma GCC target ("avx2")
#pragma GCC optimization ("O2")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);


int32_t main()
{
    map<string,int>mp;
    int n;
    cin >> n;
    FOR(i,1,n){
        string s;cin >> s;
        mp[s]++;
    }
    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";
}



Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <ctime>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cassert>
#include <bitset>
#include <list>
#include <cstdio>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <cmath>
#include <tuple>
#include <cassert>
#include <array>
#include <iomanip>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

#define REP(i,m,n) for(int i=(m); i<(n); i++)
#define RREP(i,n,m) for(int i=(n);i>=(m); i--)
#define pb push_back
#define mp make_pair
#define debug(x) cerr << #x << ": " << x << endl
// #define int long long 

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30)-1);
const ll linf = (1LL<<60);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n;
    cin >> s;
    bool ok = true;
    if(n%2==1) ok = false;
    else
    {
        REP(i,0,n/2)
        {
            if(s[i] != s[n/2+i]) ok = false;
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    
    if (k > 1)
        cout << n - k << '\n';
    else
        cout << 0 << '\n';
    
    return 0;
}

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

int main()
{
    int n,k;cin>>n>>k;
    vector<int> a(n);
    int i;
    for(i=0;i<n;i++)cin>>a.at(i);
    vector<int> count(n,0);
    for(i=0;i<n;i++)count.at(a.at(i)-1)++;
    sort(count.begin(),count.end());
    int ans=0;
    for(i=0;i<n-k;i++)ans+=count.at(i);
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

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

    vvi pos(26);
    rep(i, l) {
        pos[s[i]-'a'].pb(i);
    }

    int res = INF;
    rep(i, 26) {
        if(!pos[i].size()) continue;
        int t = 0, now = 0;
        rep(j, pos[i].size()) {
            if(!j) t = max(t, pos[i][j]);
            else t = max(t, pos[i][j]-now-1);
            now = pos[i][j];
        }
        t = max(t, l-1-pos[i].back());
        res = min(res, t);
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
S = str(input())
n = len(S)
ans = 0

for i in range(1 << n-1):
    ins = S[0]
    for j in range(n-1):
        if i & (1 << j):
            ins += "+" + S[j+1]
        else:
            ins += S[j+1]

    ans += eval(ins)

print(ans)


Measured memory_bytes: 3060
N = gets.chomp!.to_i
input = []
N.times do
	input << gets.chomp!
end

ans = ""
('a'..'z').to_a.each do |char|
	arr = input.map do |i| 
		i.count(char)
	end
		
	mi = arr.min
	ans += char * mi
	
end

puts ans


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  char a, b;
  cin >> a >> b;

  if (a == 'H') {
    COUT(b);
    return 0;
  }

  if (b == 'H') {
    COUT("D");
    return 0;
  }
  COUT("H");
  return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <string>    // useful for reading and writing
#include <fstream>   // ifstream, ofstream
#include <sstream>   // istringstream

using namespace std;

int main()
{
while(1)
{
    int x,y;
    cin >> x >>y;

    if(x==0&&y==0) break;
    if(x<=y)
    {
        cout << x <<" "<<y<<endl;
    }else
    {
        cout << y <<" "<<x<<endl;
    }
}

    return 0;
}


Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		//A
		/*
		int n = sc.nextInt();
		if(n%2 == 0)
			System.out.println(n);
		else
			System.out.println(n*2);
			*/
		//b
		int n  = sc.nextInt();
		int[] a = new int[n];
		for(int i = 0 ; i < n ; i++){
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = Math.abs(a[0]-a[a.length-1]);
		System.out.println(ans);
	}
}


Measured memory_bytes: 22608
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>
#define rep(i,N) for(int i=0; i<N; i++)
using namespace std;


int main(){
    string S,T;
    cin >> S >> T;
    int min = 2000;
    rep(i,S.size()-T.size()+1){
        int cnt = 0;
        rep(j,T.size()){
            if(S[i+j]==T[j]){
                continue;
            }else{
                cnt++;
            }
        }
        if(cnt < min){
            min = cnt;
        }

    }
    cout << min << endl;
    
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  string s, t;
  cin >> s >> t;
  vector<vector<int>> pos(26);
  for (int i = 0; i < (int) s.size(); i++) {
    pos[s[i] - 'a'].push_back(i);
  }
  int cur = -1;
  long long cycle = 0;
  for (char c : t) {
    int x = c - 'a';
    if (pos[x].empty()) {
      cout << -1 << endl;
      return 0;
    }
    auto res = upper_bound(pos[x].begin(), pos[x].end(), cur);
    if (res == pos[x].end()) {
      cur = -1;
      cycle++;
      res = lower_bound(pos[x].begin(), pos[x].end(), cur);
    }
    cur = *res;
  }
  cout << cycle * (int) s.size() + cur + 1 << endl;
  return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

//int upper(int dif,int m){
//	int ret = dif;
//	while(ret<=m)ret+=dif;
//	return ret;
//}
//
//int lower(int dif,int m){
//	int ret = dif;
//	while(ret<m)ret+=dif;
//	return ret;
//}
//
//int under(int dif,int m){
//	int ret=dif;
//	while(ret+dif<=m)ret+=dif;
//	return ret;
//}
//int n,m;
//
//bool isRef(int time,int dif,int ndif){
//	int ntime;
//	if(dif<=ndif)ntime = lower(ndif,time);
//	else		ntime = upper(ndif,time);
//	if(ntime>m)return false;
//	else return true;
//}
//
//int main(){
//	while(cin>>n>>m){
//		vector<pair<pii,int>> vec;
//		int ans=-1;
//		if(n==0&&m==0)break;
//		vector<int> v(n);
//		rep(i,n)cin>>v[i];
//		
//		int pos = -1, time = INF, dif = INF;
//		for(int i=0;i<n;i++){
//			if(i==0 || isRef( time,dif,v[i] )){
//				pos = i+1;
//				time = under(v[i],m);
//				dif = v[i];
//				vec.pb(make_pair(pii(time,dif),pos));
//			}
//			else{
//				int ntime;
//				if(dif<=v[i])ntime = lower(v[i],time);
//				else		ntime = upper(v[i],time);
//				if(ntime>m){ans = i+1;break;}
//				vec.pb(make_pair(pii(ntime,v[i]),pos));
//			}
//		}
//		rep(i,vec.size())cout<<vec[i].first.first<<" "<<vec[i].first.second<<" "<<vec[i].second<<endl;
//		if(ans!=-1)cout<<ans<<endl;
//		else{
//			sort(all(vec));
//			if(vec[0].first==vec[1].first)cout<<n<<endl;
//			else cout<<vec[0].second+1<<endl;
//		}
//	}
//}



//int main(){
//	int n, m, p, result = 0;
//	int field[10] = {0};
//	
//	cin >> n >> m;
//	
//	for(int i=0; i < m; i++){
//		cin >> p;
//		int q = max(field[p]+1,field[p+1]+1);
//		field[p]=q; field[p+1]=q;
//		result = max(result, q);
//	}
//	cout << result << endl;
//}

int result[10];

int solve(vector<int> field){
	int r[10];
	for(int i=0; i < 10; i++) r[i] = i;
	
	for(int i=0; i < field.size(); i++){
		swap(r[field[i]], r[field[i]+1]);
	}
	
	bool ok = true;
	for(int i=0; i < 10; i++) if(r[i] != result[i]){ ok = false; break;}
	if(! ok) return 100000;
	
	
	
	bool f[15][15];
	for(int i=0; i < 15; i++) for(int j=0; j < 15; j++) f[i][j] = false;
	
	for(int i=0; i < field.size(); i++){
		f[i+1][field[i]] = true;
	}
	
	
	bool change = false;
	while(1){
		change = false;
		for(int i=1; i < 10; i++){
			for(int j=1; j < 10; j++){
				if(!f[i][j] || i == 1) continue;
				bool ok = true;
				for(int k=-1; k <= 1; k++){
					if(f[i-1][j+k] == 1){ok = false;}
				}
				if(ok){change = true; f[i][j] = false; f[i-1][j] = true;}
				
			}
			
		}
		if(!change) break;
	}
	int ans = 0;
	
	for(int i=0; i < 10; i++){
		for(int j=0; j < 10; j++){
			if(f[i][j]) ans = max(ans, i);
		}
	}
	return ans;
}

int main(){
	int n, m;
	vector<int> field;
	
	cin >> n >> m;
	
	int p;

	for(int i=0; i < 10; i++) result[i] = i;
	for(int i=0; i < m; i++){
		cin >> p;
		field.push_back(p);
		swap(result[p], result[p+1]);
	}
	sort(field.begin(), field.end());
	
	int ans = 100000;
	
	do{
		ans = min(ans, solve(field));
	}while(next_permutation(field.begin(), field.end()));
	
	cout << ans << endl;
}

Measured memory_bytes: 1220
#include<iostream>
#include<string>
#define MIN -1000000
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
bool visited[100005];
const int max_N = 1e5 + 10;
string S;
int main(void) {
	cin >> S;
	S[3] = '8';
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws java.io.IOException {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            if ((n | m) == 0)
                break;
            int[] w = new int[n + m];
            for (int i = 0; i < n + m; i++)
                w[i] = sc.nextInt();
            Arrays.sort(w);
            int ans = w[0];
            for (int i = 0; i < n + m - 1; i++)
                ans = Math.max(ans, w[i + 1] - w[i]);
            System.out.println(ans);

        }

    }
}

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


int main(){
    int n;
    cin >> n;
    
    vector<int> x(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    sort(x.begin(),x.end());
    
    int ans = 1e8 + 7;
    int minIndex = x[0];
    int maxIndex = x[n-1];
    
    for (int p = minIndex; p <= maxIndex; p++){
        
        int cost = 0;
        
        for (int i = 0; i < n; i++){
            cost += (x[i]-p)* (x[i]-p);
        }
        
        ans = min(ans, cost);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <climits> 
#include <time.h>

int main()
{
 //clock_t start=clock();
    long N,K;
    std::cin >> N >> K;
    long s[100]={};
    long d[100];
    long A[100][100];
    for(long i=0; i<K; i++){
        std::cin >>d[i];
        for(long j=0; j<d[i]; j++){
            std::cin >> A[i][j];
        }
    }

    for(long i=0; i<K; i++){
        for(long j=0; j<d[i]; j++){
            s[A[i][j]-1]=1;
        }
    }
long count=0;
    for(long i=0; i<N; i++){
        if(s[i]==0){
            count++;
        }
    }
    std::cout << count << std::endl;
    //clock_t end=clock();
//std::cout << static_cast<double>(end-start)/CLOCKS_PER_SEC * 1000.0 << std::endl;
    return 0;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;

ll gcd(ll a, ll b)
{
	if (a < b) {
		a ^= b;
		b ^= a;
		a ^= b;
	}

	return b ? gcd(b, a % b) : a;
}

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

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

	cout << lcm(a, b) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;

using ll = long long;

int main()
{
    ll a;
    string s, t;
    cin >> s >> t;
    ll sum = 0;
    for(int i = 0;i < s.length();i++)
    {
        if(s[i] != t[i])
        {
            sum++;
        }
    }
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3468
A=list(map(int,input().split()))
a=A[0]
b=A[1]
if (a+b)>=(a-b):
    if (a+b)>=(a*b):
        print(a+b)
    else:
        print(a*b)
else:
    if (a-b)>=(a*b):
        print(a-b)
    else:
        print(a*b)

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}



int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int A, B, m;
	cin >>A >>B >>m;
	VI a(A), b(B);
	rep(i,A) cin>>a[i];
	rep(i,B) cin>>b[i];
	VI x(m), y(m), c(m);
	rep(i, m) cin >>x[i] >>y[i] >>c[i];
	
	int cnd = *min_element(all(a)) + *min_element(all(b));
	
	rep(i, m){
		int wk = a[x[i]-1] + b[y[i]-1] - c[i];
		cnd = min(cnd, wk);
	}
	
	cout <<cnd <<"\n";
	return 0;
}


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

int abs(int n){
  if(n<0) return -n;
  else return n;
}
int main(){
  int N,M;
  cin >> N >> M;
  int a[N],b[N],c[M],d[M];
  for(int i=0;i<N;i++){
    cin >> a[i] >> b[i];
  }
  for(int j=0;j<M;j++){
    cin >> c[j] >> d[j];
  }
  for(int i=0;i<N;i++){
    int minplace = 0;
    int dis = abs(a[i]-c[0])+abs(b[i]-d[0]);
    for(int j=0;j<M;j++){
    	if(abs(a[i]-c[j])+abs(b[i]-d[j]) < dis){
          dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
          minplace = j;
        }
    }
    cout << minplace + 1 << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int n;
  int a[20];
  int b;
  int c[19];
  int sum = 0;
  int i;
  
  scanf("%d", &n);
  for(i = 0; i < n; i++)
    scanf("%d", &a[i]);
  for(i = 0; i < n; i++) {
    scanf("%d", &b);
    sum += b;
  }
  for(i = 0; i < n-1; i++)
    scanf("%d", &c[i]);
  
  for(i = 0; i < n-1; i++) {
    if (a[i]+1 == a[i+1])
      sum += c[a[i]-1];
  }
  
  printf("%d", sum);
  
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int countwatch(int tree,int gold);

int main(){
    int n,d;
    scanf("%d%d",&n,&d);
    printf("%d\n",countwatch(n,d));
    return 0;
}

int countwatch(int tree,int gold){
    int man;
    //切り上げ計算
    //切り上げ=(被序数＋序数-1/序数)
    man = ((tree+(gold*2+1)-1)/(gold*2+1));
    return man;
}

Measured memory_bytes: 128
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let mut n = String::new();
  std::io::stdin().read_line(&mut n).ok();

  let mut ls = read_vec::<u32>();
  ls.sort();

  let ans: u32 = ls.iter()
    .enumerate()
    .filter(|&(i, _)| i % 2 == 0)
    .map(|(_, x)| x)
    .sum();

  println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iomanip>
#define ll long long

using namespace std;

int main()
{
ll n,m;
cin>>n>>m;
ll a[m];
for(ll i=0; i<m; i++){
	cin>>a[i];
}
ll sum=0;
for(ll i=0; i<m; i++){
	sum= sum+a[i];
}
ll ans = n-sum;
if(ans>=0){

cout<<ans;
}
else{
	cout<<-1;
}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

map<llong, int> PrimeFact(llong n){
	map<llong, int> ret;
	while(n % 2 == 0){
		ret[2]++;
		n /= 2;
	}
	for(llong i = 3; i*i <= n; i += 2){
		while(n%i == 0){
			ret[i]++;
			n /= i;
		}
	}
	if(n != 1)
	ret[n]++;

	return ret;
}

int main(){
	llong N;
	string s,t;
	cin >> N >> s >> t;

	llong ans = 1;
	for(int i = 0; i < N; i++){
		if(i == 0){
			if(s[i] == t[i])
				ans *= 3;
			else
				ans *= 6, i++;
		}else{
			if(s[i-1] == t[i-1])
				ans *= 2;
			else if(s[i] != t[i])
				ans *= 3;

			if(s[i] != t[i])
				i++;
		}
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

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

int main()
{

int n,x,i;
cin>>n;
int a[n+2];
for(i=1;i<=n;i++)
{
    cin>>x;
    a[x]=i;
}
for(i=1;i<=n;i++)
{
    cout<<a[i]<<" ";
}
cout<<endl;


}


Measured memory_bytes: 1152
from sys import exit, stdin
N = int(stdin.readline().rstrip())
s = ""
while N != 0:
    r = N % 2
    if r < 0:
        r += 2
    N = (N - r) // -2
    s += str(r)
if s == "":
    s = "0"
print(s[::-1])

Measured memory_bytes: 3060
import math

s = int(input())
mod = 10**9 + 7

maxN = s//3
result = 0
for i in range(1, maxN+1): 
  tmp = s - 3*i
  if tmp == 0: 
    result += 1
  else: 
  	result += math.factorial(tmp+i-1)//(math.factorial(i-1)*math.factorial(tmp))

print(result%mod)

Measured memory_bytes: 9208
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

const int N = (int)(2e5 + 500);

int n;
int a[N], b[N], cntA[N], cntB[N];
set <int> g[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifndef _LOCAL          
    #endif // _LOCAL

    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        g[x].insert(i);
        ++cntA[x];
    }

    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ++cntB[x];
    }

    for (int i = 1; i <= n; ++i)
        if (cntA[i] + cntB[i] > n)
            return void(cout << "No\n"), 0;

    priority_queue <pair <int, int> > A, B;

    for (int i = 1; i <= n; ++i) {
        if (cntA[i])
            A.push(make_pair(cntA[i] + cntB[i], i));
        if (cntB[i])
            B.push(make_pair(cntA[i] + cntB[i], i));
    }

    while (!B.empty()) {
//        cerr << (int)(A.size()) << " " << (int)(B.size()) << " ";
        auto itA = A.top();
        auto itB = B.top();
        A.pop();
        B.pop();

//        cerr << (itA.second) << " " << (itB.second) << "\n";
        if (itA.second == itB.second) {
            auto it = A.top();
            A.pop();
            A.push(itA);
            itA = it;
        }

        assert(itA.second != itB.second);

        b[*g[itA.second].begin()] = itB.second;
        g[itA.second].erase(g[itA.second].begin());

        --cntA[itA.second];
        --cntB[itB.second];
        if (cntA[itA.second])
            A.push(make_pair(cntA[itA.second] + cntB[itA.second], itA.second));
        if (cntB[itB.second])
            B.push(make_pair(cntA[itB.second] + cntB[itB.second], itB.second));
    }

    cout << "Yes\n";
    for (int i = 0; i < n; ++i)
        cout << b[i] << " ";

    return 0;
}

Measured memory_bytes: 27628
#include<stdio.h>
int main(void){
  int a = 10,i ,j ,ho;
  int m[a];
  for (i = 0; i < a; i++) {
  scanf("%d" ,&m[i]);
  }

for (i = 0; i < a; i++){
  for (j = 0; j < a - 1; j++){
    if(m[j] < m[j + 1]){
      ho = m[j + 1];
      m[j + 1] = m[j];
      m[j] = ho;
      }
    }
  }
  printf("%d\n%d\n%d\n",m[0] ,m[1] ,m[2]);
  return 0;
}



Measured memory_bytes: 2048
#include <algorithm>
#include <iostream>
#include <vector>

#define INF 1000000007

int main(){
    int limit, m;
    std::cin >> limit >> m;

    std::vector<int> c(m);
    for(int i = 0; i < m; ++i){
        std::cin >> c.at(i);
    }

    std::sort(std::begin(c), std::end(c));

    std::vector<std::vector<int>> dp(m + 1, std::vector<int>(limit + 1, INF));
    for(int i = 0; i <= m; ++i){
        dp.at(i).at(0) = 0;
    }

    for(int i = 0; i < m; ++i){
        for(int amount = 0; amount <= limit; ++amount){
            if(c.at(i) <= amount){
                dp.at(i + 1).at(amount) = std::min(dp.at(i + 1).at(amount - c.at(i)) + 1, dp.at(i).at(amount));
            }else{
                dp.at(i + 1).at(amount) = dp.at(i).at(amount);
            }
        }
    }

    std::cout << dp.at(m).at(limit) << std::endl;

    return 0;
}


Measured memory_bytes: 7136