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

int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};

int main(void){
  using State = tuple<int, int, int>; // (i, j, cnt)

  int H, W; cin >> H >> W;
  vector<vector<char>> A(H, vector<char>(W));
  queue<State> que;
  for(int i = 0; i < H; i++){
    string str; cin >> str;
    for(int j = 0; j < W; j++){
      A[i][j] = str[j];
      if(str[j] == '#'){
        que.push(make_tuple(i, j, 0));
      }
    }
  }


  int ans = 0;
  while(!que.empty()){
    State s = que.front(); que.pop();
    int h, w, cnt;
    tie(h, w, cnt) = s;
    ans = max(ans, cnt);
    for(int loop = 0; loop < 4; loop++){
      int nh = h + dh[loop];
      int nw = w + dw[loop];

      if(0 <= nh && nh < H && 0 <= nw && nw < W && A[nh][nw] == '.'){
        A[nh][nw] = '#';
        que.push(make_tuple(nh, nw, cnt+1));
        ans = max(ans, cnt+1);
      }
    }

    // for(int i = 0; i < H; i++){
    //   for(int j = 0; j < W; j++){
    //     cout << A[i][j];
    //   }
    //   cout << endl;
    // }
    // cout << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 13456
#include<stdio.h>

int main(void){
  int a;
  int b[1000]={0};
  int c[123456*2]={0};
  int i=0;
  int j=0;
  int n=0;

  c[2]=1;
  
  for(i=3;i<123456*2;i=i+2){
    c[i]=1;
    for(j=3;j<i;j=j=j+2){
      if(i%j==0){
	c[i]=0;
	break;
      }
    }
  }
  
  j=0;
  while(1){
    scanf("%d", &a);
    n++;
    if(a==0)
      break;
    for(i=a+1;i<=2*a;i++)
      b[j]+=c[i];
    j++;
  }

  
  for(i=0;i<n-1;i++)
    printf("%d\n",b[i]);

  return 0;
}



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

int main() {
	int a[105];
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ans = 0;
	int flag = -1;
	for (int i = 1; i <= n; i++) {
		if (flag == -1) {
			flag = a[i];
		}
		else if (flag == a[i]) {
			ans++;
			flag = -1;
		}
		else {
			flag = a[i];
		}
	}
	cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace  std;
#define LL long long
const int MAXN = 2e5+55;

const LL mod = 1e9+7;
LL fac[MAXN];
LL inv[MAXN];

LL qkm(LL base,int mi)
{
	LL ans=1;
	while(mi){
		if(mi&1) ans=ans*base%mod;
		base=base*base%mod;
		mi>>=1;
	}
	return ans;
}

void init()
{
	fac[0]=fac[1]=1;

	for(int i=2;i<=MAXN;i++)fac[i]=fac[i-1]*i%mod;

	inv[MAXN]=qkm(fac[MAXN],mod-2);

	for(int i=MAXN-1;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;


}

LL C(LL n,LL m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
	init();
	LL n , m;
	cin>>n>>m;
	LL ans=1;
	for(int i=2;i<=sqrt(m);i++){
		if(m%i==0){
			int num=0;
			while(m%i==0) {
				num++;
				m/=i;
			}
			ans=ans*C(num+n-1,n-1)%mod;
		}
	}
	if(m>1)
		ans=ans*C(n,n-1)%mod;
	cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define vi vector<int>
#define Vi vector<vector<int>>
#define ll long long
#define P pair<int,int>
#define vp  vector<P>
#define mod 1000000009
using namespace std;
int main(){
	char a;
	cin>>a;
	cout<<(char)(a+1)<<endl;
	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int32_t main() {

    map<int, int> f;
    for(int i = 0; i < 6; ++i) {
        int a; cin >> a;
        f[a]++;
        if(f[a] == 3) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    deque<ll> A(N), B(N);
    rep(i,N){
        cin >> A[i];
        B[i] = A[i];
    }
    deque<ll> v;

    sort(A.rbegin(), A.rend());
    //v.push_back(A[0]);
    //v.push_back(A[1]);
    
    //v.push(A[0]);
    ll ans = A[0];
    v.push_back(A[1]);
    v.push_back(A[1]);
    REP(i,2,N){
        if(i%2 == 0){
            v.pop_front();            
        }
        ans += v.front();
        v.push_back(A[i]);
    }
    cout << ans << endl;
    /*sort(B.begin(), B.end());
    
    deque<ll> C;
    rep(i,N){
        ll tmp;
        if(i%4 == 0 || i%4 == 1){
            tmp = B.back();
            B.pop_back();
        }else{
            tmp = B.front();
            B.pop_front();
        }
        C.push_back(tmp);
    }
    C.push_front(C.back());
    C.push_back(C.front());
    ll ans = 0;
    REP(i,1,N+1){
        ans += max(C[i-1], C[i+1]);
    }
    cout << ans << endl;*/
}


Measured memory_bytes: 7492
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
   
    int count=0;
    
    int n=sc.nextInt();  
    int array1[]=new int[n];
    for(int i=0;i<n;i++)array1[i]=sc.nextInt();
    
    int q=sc.nextInt();
    int array2[]=new int[q];
    for(int i=0;i<q;i++) array2[i]=sc.nextInt();
   
    for(int i=0;i<q;i++){
      int start=0;
      int goal=n-1;
      while(true){
        int middle=(int)(start+goal)/2;
        if(array2[i]==array1[middle]){
          count+=1;
          break;
        }
        if(start-goal>-1) break;
        else if(array1[middle]<array2[i]) start=middle+1;
        else if(array2[i]<array1[middle]) goal=middle-1;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 67604
package main

import "fmt"

func main() {
	var x, y int
	for {
		fmt.Scan(&x, &y)
		if x == 0 && y == 0 {
			break
		}
		if x > y {
			x, y = y, x
		}
		fmt.Printf("%d %d\n", x, y)
	}
	return
}



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

using namespace std;

#define X first
#define Y second

using R=long double;
using P=pair<R, R>;

const double EPS = 1e-10;

R dist2(P a, P b) {
	R dx = a.X - b.X;
	R dy = a.Y - b.Y;
	return dx*dx+dy*dy;
}

int main() {
	int n;
	while(cin >> n, n) {
		vector<P> p(n), pl;
		for(int i = 0; i < n; i++) cin >> p[i].X >> p[i].Y;
		for(int i = 0; i < p.size(); i++) {
			P p1 = p[i];
			for(int j = i+1; j < p.size(); j++) {
				P p2 = p[j];
				if(dist2(p1, p2)-EPS > 4.0) continue;

				R dxy2 = sqrt(dist2(p1, p2)/4.0);
				R l = sqrt(1-(dxy2*dxy2));
				R cx = (p1.X+p2.X)/2.0;
				R cy = (p1.Y+p2.Y)/2.0;
				R dx = (p2.X-p1.X);
				R dy = (p2.Y-p1.Y);

				R dlx = l/sqrt(dist2(p1, p2)) * dy;
				R dly = l/sqrt(dist2(p1, p2)) * -dx;

				pl.push_back(P(cx+dlx, cy+dly));
				pl.push_back(P(cx-dlx, cy-dly));
			}
		}

		int res = 1;
		for(P p1:pl) {
			int tmp = 2;
			for(P p2:p) {
				if(sqrt(dist2(p1, p2)) < 1.0-EPS) tmp++;
			}
			res = max(res, tmp);
		}

		cout << res << endl;
	}

	return 0;
}

Measured memory_bytes: 4796
#include<iostream>

using namespace std;

string str[100];

int main() {
	int H, W;
	

	//入力
	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		cin >> str[i];
	}

	//出力
	for (int i = 0; i < H; i++) {
		cout << str[i] << endl;
		cout << str[i] << endl;
	}

}

Measured memory_bytes: 256
// 目標:セグメント木でACしたい
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

const int VAL = 'z' - 'a' + 1;
const int MAX_N = 500100;
set<int> st[VAL];
char S[MAX_N];
int N, Q;
vector<int> res;

int main()
{
    scanf("%d", &N);
    scanf("%s", S);
    for(int i = 0; i < VAL; ++i) {
        st[i].clear();
        st[i].insert(N);
    }
    for(int i = 0; i < N; ++i) {
        st[S[i]-'a'].insert(i);
    }
    scanf("%d", &Q);
    for(int i = 0; i < Q; ++i) {
        int a, l, r;
        scanf("%d %d", &a, &l);
        --l;
        if(a == 1) {
            char tmp[2];
            scanf("%s", tmp);
            st[S[l]-'a'].erase(l);
            st[tmp[0]-'a'].insert(l);
            S[l] = tmp[0];
        }
        else {
            scanf("%d", &r);
            --r;
            int ans = 0;
            for(int j = 0; j < VAL; ++j) {
                auto itr = st[j].lower_bound(l);
                if(*itr <= r) ++ans;
            }
            res.push_back(ans);
        }
    }
    for(auto &p : res) printf("%d\n", p);
    return 0;
}

Measured memory_bytes: 24448
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int h = in.nextInt();
        int w = in.nextInt();
        char[][] cs = new char[h][w];
        for (int i = 0; i < h; i++) {
            cs[i] = in.next().toCharArray();
        }

        int vertical[] = {0, 1, 0, -1};
        int holizontal[] = {-1, 0, 1, 0};
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (cs[i][j] == '#') {
                    boolean ok = false;
                    for (int j2 = 0; j2 < 4; j2++) {
                        int y = i + vertical[j2];
                        int x = j + holizontal[j2];
                        if (y >= 0 && y < h && x >= 0 && x < w && cs[y][x] == '#') {
                            ok = true;
                            break;
                        }
                    }

                    if (!ok) {
                        System.out.println("No");
                        return;
                    }
                }
            }
        }

        System.out.println("Yes");
    }
}

Measured memory_bytes: 35720
N, x = map(int, input().split())
A = [int(i) for i in input().split()]
ct = 0
for i in range(N-1):
    l = (A[i] + A[i+1]) - x
    if l > A[i+1]:
        ct += l
        A[i+1] = 0
        A[i] -= l - A[i+1]
    elif l > 0:
        ct += l
        A[i+1] -= l
print(ct)


Measured memory_bytes: 14052
#include<iostream>
#include<string>
#include<vector>

using namespace std;

typedef long long ll;

const ll k_mod = 1000000007;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int h, w;
  cin >> h >> w;
  
  vector<vector<ll>> p(h + 1, vector<ll>(w + 1, 0));
  p[1][1] = 1;
  for(int i = 1; i <= h; ++i){
    for(int j = 1; j <= w; ++j){
      char c;
      cin >> c;
      if(c == '#') p[i][j] = -1;
      else{
        p[i][j] += (p[i - 1][j] != -1) ? p[i - 1][j] : 0;
        p[i][j] += (p[i][j - 1] != -1) ? p[i][j - 1] : 0;
        p[i][j] %= k_mod;
      }
    }
  }
  
  cout << p[h][w] << endl;
  
  return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

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

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int A,B;
    cin >> A >> B;
    A += B;
    cout << (A > 9 ? "error" : to_string(A)) << "\n";
}

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

int main() {
	char b;
	cin >> b;
	if (b=='A'){
		cout << 'T';
	}
	else if (b=='T'){
		cout << 'A';
	}
	else if (b=='C'){
		cout << 'G';
	}
	else if (b=='G'){
		cout << 'C';
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
vl to[220000];
vl cnt(220000);
bool visited[220000];
int main(){
    ll n;cin>>n;
    for(int i=2;i<=n;i++){
        ll a;cin>>a;
        to[a].push_back(i);
        to[i].push_back(a);
    }
    queue<ll> q;
    q.push(1);
    visited[1]=true;
    for(int i=0;i<220000;i++)cnt[i]=0;
    while(q.size()){
        ll now=q.front();
        q.pop();
        for(auto nxt:to[now]){
            if(visited[nxt])continue;
            visited[nxt]=true;
            cnt[now]++;
            q.push(nxt);
        }
    }
    for(int i=1;i<=n;i++)cout<<cnt[i]<<endl;
    return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  int A, P;
  cin >> A >> P;
  cout << (3 * A + P) / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
#define TOP 3
int main(void) {
    int n, tmp, i, ranking[TOP] = {0};
    while (scanf("%d", &n) != EOF) {
        for (i=0; i<TOP; i++) {
            if (ranking[i] < n) {
                tmp = ranking[i];
                ranking[i] = n;
                n = tmp;
            }
        }
    }
    for (i=0; i<TOP; i++) {
        printf("%d\n", ranking[i]);
    }
    return 0;
}


Measured memory_bytes: 2048
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
int main(){
	//mahakal(),fast;
	ll n ;
	cin>> n ;
	ll a=n%10;
	n=n/10;
	ll b=n%10;
	n=n/10;
	ll c=n ;
	if(a==7 || b==7 || c==7){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 3568
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
def main():
	nums = input().split(" ") 
	width, height, x, y, r =[int(i) for i in nums]
	if 0 <= x - r and x + r <= width and 0 <= y - r and y + r <= height:
		return "Yes"
	else:
		return "No"
if __name__ == '__main__':
  print(main())

Measured memory_bytes: 7716
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
const int INF = 2e9 + 1;
int x[4] = {-1, 0, 1, 0};
int y[4] = {0, 1, 0, -1};
int dp[1010][1010];
struct node{
    int nx;
    int ny;
};
void Main(){
    int h, w;
    cin >> h >> w;
    h += 2;
    w += 2;
    int sh, sw, gh, gw;
    cin >> sh >> sw >> gh >> gw;
    vector<string> s(h);
    string str = "";
    For(i,0,w) str += '#';
    s[0] = str;
    s[h-1] = str;
    For(i,1,h-1){
        cin >> s[i];
        s[i] = '#' + s[i] + '#';
    }
    For(i,0,h) For(j,0,w) dp[i][j] = INF;
    dp[sh][sw] = 0;
    deque<node> que;
    node init;
    init.nx = sh;
    init.ny = sw;
    que.push_back(init);
    while(!que.empty()){
        auto now = que.front();
        node to;
        que.pop_front();
        if(now.nx == gh && now.ny == gw) break;
        For(i,0,4){
            if(s[now.nx + x[i]][now.ny + y[i]] == '#'){
                continue;
            }
            if(dp[now.nx + x[i]][now.ny + y[i]] > dp[now.nx][now.ny]){
                dp[now.nx + x[i]][now.ny + y[i]] =  dp[now.nx][now.ny];
                to.nx =  now.nx + x[i];
                to.ny = now.ny + y[i];
                que.push_front(to);
            }
        }
        For(i, -2, 3){
            if(clamp(now.nx + i, 0, h-1) != now.nx + i) continue;
            For(j, -2, 3){
                if(clamp(now.ny + j, 0, w-1) != now.ny + j) continue;
                if(s[now.nx + i][now.ny + j] == '#') continue;
                if(dp[now.nx + i][now.ny + j] >  dp[now.nx][now.ny] + 1){
                    dp[now.nx + i][now.ny + j] =  dp[now.nx][now.ny] + 1;
                    to.nx =  now.nx + i;
                    to.ny = now.ny + j;
                    que.push_back(to);
                }               
            }
        }
    }
    /*For(i,0,h){
        For(j,0,w){
            cout << dp[i][j] << " \n"[j==w-1];
        }
    }*/
    if(dp[gh][gw] == INF) cout << -1 << endl;
    else cout << dp[gh][gw] << endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

Measured memory_bytes: 9640
#include <cstdio>

bool LinearSearch(int n, int s[], int ti) {
  if (s[n - 1] == ti) {
    return true;
  }
  int i = 0;
  s[n - 1] = ti;
  while (s[i] != ti) {
    ++i;
  }
  if (i == n - 1) {
    return false;
  }
  return true;
}

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

  int counter = 0;
  for (int i = 0; i < q; ++i) {
    if (LinearSearch(n, s, t[i])) {
      ++counter;
    }
  }

  printf("%d\n", counter);
}

Measured memory_bytes: 2632
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 

const int MOD = 1000000007;

int dp[100005][3];

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

    vector< vector<int> > s(N); //! satisfaction
    rep(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        s[i].push_back(a);
        s[i].push_back(b);
        s[i].push_back(c);
    }

    rep(k,3) {
        dp[0][k] = s[0][k];
    }
    for (int i = 1; i < N; ++i) {
        rep(k,3) {
            dp[i][k] = max(dp[i-1][(k+1)%3], dp[i-1][(k+2)%3]) + s[i][k];
        }
    }

    int ans = 0;
    rep(k,3) {
        ans = max(ans, dp[N-1][k]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
ll cost[200005]={0};
signed main(){
  ll n,x,ans=0;
  cin>>n>>x;
  for(int i=0;i<n;i++) {
    cin>>cost[i];
    ans+=cost[i];
  }
  for(int i=0;i<n;i++) {
    cost[i+n]=cost[i];
  }
  for(ll i=1;i<n;i++){
    multiset<ll> st;
    ll kans=i*x;
    for(int j=0;j<i;j++) st.insert(cost[j]);
    for(int j=i;j<n+i;j++){
      st.insert(cost[j]);
      ll mincost=*(st.lower_bound(0));
      st.erase(cost[j-i]);
      kans+=mincost;
    }
    ans=min(ans,kans);
  }
  cout<<ans<<endl;
}


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

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

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,K;
  cin>>N>>K;
  vector<ll>x(N);
  for(int i=0;i<N;i++)cin>>x[i];
  sort(rng(x));
  ll ans=LONG_MAX;
  for(int i=0;i<N;i++){
    if(i+K-1<N)ans=min(ans,x[i+K-1]-x[i]+min(abs(x[i+K-1]),abs(x[i])));
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
}

vector <vector <int> > g;
vector <int> val;
int n;
vector <bool> visited;
vector <int> ans;
map <int,int,greater<int> > m2;
void dfs(int s);
int INF=2e9;
vector <int> d;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    n=nxt();
    val.resize(n+1);
    for(int i=1;i<=n;i++)
        cin>>val[i];
    g.resize(n+1,vector <int>(0));
    for(int i=0;i<n-1;i++)
    {
        int u=nxt(),v=nxt();
        g[u].push_back(v);
        g[v].push_back(u);
    }
    visited.resize(n+1,0);
    ans.resize(n+1,0);
    d.resize(n+1,INF);
    d[0]=-INF;
    dfs(1);
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<endl;
    
    
    return 0;   
}

set <int,greater<int>> s2;

void dfs(int s)
{
    visited[s]=1;
    //ans[s]=mx;
    int j = upper_bound(d.begin(), d.end(), val[s]) - d.begin();
    int temp=-1;
        if (d[j-1] < val[s] && val[s] < d[j]){
            temp=d[j];
            d[j] = val[s];
            s2.insert(j);
        }
    for(auto i:g[s])
    {
        if(!visited[i])
        {
            //m2[val[s]]=mx;
            dfs(i);
        }
    }
     ans[s]=*(s2.begin());
    if(temp!=-1){
        d[j]=temp;
        if(temp==INF)
            s2.erase(j);
    }
    //if(m2.find(val[s])!=m2.end())
       // m2.erase(val[s]);
   

}




 
 


Measured memory_bytes: 30804
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
int n,k,a[N];
int main()
{
    scanf("%d%d",&k,&n);
    if(k&1)
    {
        int tot=n;
        for(int i=1;i<=n;i++) a[i]=k/2+k%2;
        for(int i=1;i<=n/2;i++)
        {
            if(tot==n)
            {
                a[tot]--;
                if(a[tot]==0) tot--;
            }
            else
            {
                if(a[tot]==1) a[tot]--,tot--;
                else
                {
                    a[tot]--;
                    for(int j=tot+1;j<=n;j++) a[j]=k;
                    tot=n;
                }
            }
        }
        for(int i=1;i<=tot;i++)
            printf(i==tot?"%d\n":"%d ",a[i]);
    }
    else
    {
        printf("%d",k/2);
        for(int i=2;i<=n;i++)
            printf(" %d",k);
        putchar('\n');
    }
}
/*
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> >v;
vector<int>s;
void dfs(int u,int up,int mx)
{
    if(u==up+1){v.push_back(s);return;}
    for(int i=1;i<=mx;i++)
    {
        s.push_back(i);
        dfs(u+1,up,mx);
        s.pop_back();
    }
}
int main()
{
    for(int i=1;i<=8;i++)
    {
        dfs(1,i,5);
        sort(v.begin(),v.end());
        int x=v.size()/2+v.size()%2-1;
        for(int i=0;i<v[x].size();i++)
            printf(i==v[x].size()-1?"%d\n":"%d ",v[x][i]);
    }
}
k=3
2
2 1 +1
2 2 1 +1
2 2 2 +2
2 2 2 2 +2
2 2 2 2 1 3 +3
2 2 2 2 2 1 3 +3
2 2 2 2 2 2 1 2 +4

k=2
1
1 2
1 2 2
1 2 2 2
1 2 2 2 2
1 2 2 2 2 2
1 2 2 2 2 2 2
1 2 2 2 2 2 2 2

k=4
2
2 4
2 4 4
2 4 4 4
2 4 4 4 4
2 4 4 4 4 4
2 4 4 4 4 4 4
2 4 4 4 4 4 4 4

k=5
3
3 2 +1
3 3 2 +1
3 3 3 1 +2
3 3 3 3 1 +2
3 3 3 3 3 +3
3 3 3 3 3 3 +3
*/


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

#define int long long
template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

signed main(){
  int n,m,k;cin>>n>>m>>k;
  vector<int> a(n),b(m);
  for(int i=0;i<n;i++)cin>>a[i];
  for(int i=0;i<m;i++)cin>>b[i];
  int now=0,nowtime=0;
  while(now<m&&nowtime+b[now]<=k)nowtime+=b[now++];
  int ans=now;
  for(int i=0;i<n;i++){
    nowtime+=a[i];
    while(now&&nowtime>k)nowtime-=b[--now];
    if(nowtime<=k)chmax(ans,i+1+now);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 6424
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))

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

    set<char> st;
    for(char c : S) st.insert(c);
    for(char c : T) if(!st.count(c)){cout << -1 << endl; return 0;}

    string ss = S + S;
    i64 SLen = S.size();
    i64 ssLen = SLen*2;
    vector<i64> nextIndex(26,1e9);
    vector<vector<i64>> nextIndexies(SLen);

    for(int i=ssLen-1;i>=0;i--){
        if(i < SLen) nextIndexies[i] = nextIndex;
        nextIndex[ss[i] - 'a'] = i;
    }

    i64 nowIdx = -1;
    for(char c : T){
        if(nowIdx < 0) nowIdx = nextIndex[c - 'a'];
        else {
            i64 dist = nextIndexies[nowIdx % SLen][c - 'a'] - (nowIdx % SLen);  
            nowIdx += dist;
        }
    }

    i64 ans = nowIdx + 1;

    cout << ans << endl;
}

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

int main() {
  int A1, A2, A3;
  
  cin >> A1 >> A2 >> A3;
  
  if(A1+A2+A3 >= 22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}



Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n,ans,temp;
    scanf("%d",&n);
    ans=n;
    while(n--){
        scanf("%d",&temp);
        for(int i=1;i*i<temp;i++)if((temp-i)%(i*2+1)==0){
            ans--;
            break;
        }
    }
    printf("%d\n",ans);
}


Measured memory_bytes: 2664
#include <stdio.h>

int main(){
 int D;
  scanf("%d", &D);
  if(D==25){
    printf("Christmas");
  }else if(D==24){
    printf("Christmas Eve");
    
  }else if(D==23){
    printf("Christmas Eve Eve");
  }else{
    printf("Christmas Eve Eve Eve");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <cassert>

using namespace std;
using ll = long long;

int main()
{
    int n;
    cin >> n;
    vector<int> l(n);
    for(int i = 0; i < n; i++){
        cin >> l[i];
    }
    int ans = 0;
    for(int i = 0; i < n-2; i++){
        for(int j = i+1; j < n-1; j++){
            for(int k = j+1; k < n; k++){
                if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k]){
                    if(l[i] < l[j] + l[k] && l[j] < l[i] + l[k] && l[k] < l[j] + l[i]) ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#ifndef LOCAL
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#else
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair


int main() {
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int a = 0;
    for (int i = 0; i < 3; i++)
    {
        if (s[i] == 'A') a++;
    }
    if (a == 0 or a == 3){
        cout << "No";
    } else {
        cout << "Yes";
    }
    

}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<cassert>
#include<sstream>
#include<complex>
#include<cstdio>
#include<climits>
#include<cstdlib>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<ctime>
#include<cctype>
#include<unordered_map>
#include<unordered_set>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define all(n) (n).begin(),(n).end()
#define MAX 1010
#define pow2(a) ((a)*(a))

using namespace std;

struct Point{
  int x,y;
  Point(int x=IINF,int y=IINF):x(x),y(y){}
};

struct Data{
  int cur,cost;
  Data(int cur=IINF,int cost=IINF):cur(cur),cost(cost){}
};

inline double dist(Point a,Point b){
  return sqrt(pow2(abs(a.x-b.x))+pow2(abs(a.y-b.y)));
}

int N,X,Y;
vector<int> G[MAX];

int main()
{
  int T;
  cin >> T;
  while(T--){
    cin >> N >> X >> Y;

    rep(i,N)G[i].clear();

    deque<Data> deq;
    bool used[N+1];
    Point ps[N+1];
    rep(i,N+1){
      used[i] = false;
      cin >> ps[i].x >> ps[i].y;
    }

    REP(i,1,N+1){
      if(dist(ps[0],ps[i]) <= 10.0){
	deq.push_back(Data(i-1,1));
	used[i-1] = true;
      }
      REP(j,i+1,N+1){
	if(dist(ps[i],ps[j]) <= 50.0){
	  G[i-1].push_back(j-1);
	  G[j-1].push_back(i-1);
	}
      }
    }

    if(deq.empty()){
      cout << 0 << endl;
      continue;
    }
    /*
    rep(sp,N){
      cout << "from " << sp << " : ";
      for(int next : G[sp]){
	cout << next << " ";
      }
      cout << endl;
    }
    cout << endl;
    */
    int maxcost = 1;
    while(!deq.empty()){
      Data data = deq.front(); deq.pop_front();

      for(int next : G[data.cur]){
	if(used[next])continue;
	used[next] = true;
	maxcost = max(maxcost,data.cost+1);
	deq.push_back(Data(next,data.cost+1));
      }

    }

    if( X > Y && maxcost == 1){
      cout << X << endl;
      continue;
    }

    if( X > Y ){
      cout << "You're always welcome!" << endl;
    } else {
      cout << X*maxcost << endl;
    }

  }
  return 0;
}

Measured memory_bytes: 5316
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define sz(x) ((int)(x).size())
#define sq(x) ((x)*(x))
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
double add(double a,double b){
	if(abs(a+b)<eps*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{
	double x,y;
	P() {}
	P(double x,double y) : x(x),y(y){}
	P operator + (P p){
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p){
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d){
		return P(x*d,y*d);
	}
	double dot(P p){
		return add(x*p.x,y*p.y);
	}
	double det(P p){
		return add(x*p.y,-y*p.x);
	}
	double norm(){
		return sqrt(x*x+y*y);
	}
	double dist2(P p){
		return sq(x-p.x)+sq(y-p.y);
	}
	P vert(){
		return P(y,-x);
	}
	void dump(){
		printf("%.12f %.12f\n",x,y);
		return;
	}
};
int N;
P pts[305];
int solve(){
	scanf("%d",&N);
	if(N==0)return 1;
	for(int i=0;i<N;i++){
		scanf("%lf %lf",&pts[i].x,&pts[i].y);
	}
	int ans = 1;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			P m = (pts[i]+pts[j])*0.5;
			P a = (pts[i]-pts[j]);
			double na = a.norm();
			if(na>2.0)continue;
			a = (a.vert())*(sqrt(1-sq(na/2.0))/na);
			P b = m+a;
			P c = m-a;
			/*cout << i << ' ' << j << endl;
			m.dump();
			a.dump();
			b.dump();
			c.dump();
			cout << endl;*/
			int cnt = 0;
			for(int k=0;k<N;k++){
				//if(1.0<pts[k].dist2(b)&&pts[k].dist2(b)<=1.0+eps)printf("%d:%.12f\n",k,pts[k].dist2(b));
				if(pts[k].dist2(b)<=1.0+eps)cnt++;
			}
			ans = max(ans,cnt);
			cnt = 0;
			for(int k=0;k<N;k++){
				//if(1.0<pts[k].dist2(c)&&pts[k].dist2(c)<=1.0+eps)printf("%d:%.12f\n",k,pts[k].dist2(c));
				if(pts[k].dist2(c)<=1.0+eps)cnt++;
			}
			ans = max(ans,cnt);
		}
	}
	printf("%d\n",ans);
	return 0;
}
int main(){
	while(!solve()){}
	return 0;
}

Measured memory_bytes: 3128
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<climits>
#include<algorithm>
#include<vector>
#include<valarray>
#include<string>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iostream>
#include<iomanip>
using namespace std;
   
   
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define drep(i,n) for(int i=n-1;i>=0;i--)
#define DREP(i,n) for(int i=n;i>0;i--)
#define Rep(i,m,n) for(int i=m;i<n;i++)
#define ReP(i,m,n) for(int i=m;i<=n;i++)
#define scani(a) scanf("%d",&a)
#define scand(a) scanf("%lf",&a)
#define scans(s) scanf("%s",s)
#define readi(a) int a;scanf("%d",&a)
#define printi(a) printf("%d",a)
#define prints(s) printf("%s",s)
#define even(n) (((n)+1)%2)
#define odd(n) ((n)%2)
#define sg(x) ((x)?1:0)
#define LF printf("\n")
#define SPACE printf(" ")
#define pb push_back
#define mp make_pair
#define bs binary_search
#define all(a) (a).begin(),(a).end()
#define forall(itr,a) for(auto itr=(a).begin();itr!=(a).end();++itr)
   
typedef long long LL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<double,double> pdd;
typedef pair<int,int> pii;

const double pi = acos(-1.0);
double rad(double t){return t*pi/180.0;}
double deg(double d){return d*180.0/pi;}
template<typename T>T GCD(T x,T y){return y?GCD(y,x%y):x;}
template<typename T>T LCM(T x,T y){return x/GCD(x,y)*y;}
template<class T>ostream& operator<<(ostream& os,const set<T>& s){os<<"{";for(auto itr=s.begin();s.end() != itr;++itr){if(itr!=s.begin())os<<',';os<<*itr;}os<<"}";return os;}
template<class S,class T>ostream& operator<<(ostream& os,const pair<S,T>& p){os<<'('<<p.first<<','<<p.second<<')';return os;}
const int MOD = (int)pow(10,9) +7;
 
 
//begin global variable
//

//
//end   global variable
 
int main(){
  ios::sync_with_stdio(false);
  //begin main()
  //
  string s;
  LL k;
  cin >> s;
  cin >> k;

  LL n = s.length();
  rep(i,n-1){
    if(s[i] != 'a' && k > 'z' - s[i]){
      k -= (('z'+1) - s[i]);
      //cout << "k=" << k << endl;
      s[i] = 'a';
    }
  }
  s[n-1] = (k%26 + (s[n-1]-'a'))%26 + 'a';

  cout << s << endl;
  //
  //end   main()
  return 0;
}


Measured memory_bytes: 592
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>
    
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
const int INF = 1000*1000*1000;
const ll LINF = (ll)1e18;
int xv[4] = {-1, 1, 0, 0};
int yv[4] = {0, 0, -1, 1};


int main() { 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H, W, D;
    cin >> H >> W >> D;
    vector<P> mp(H*W+1);
    vector<int> dp(H*W+2, 0);
    
    REP(i, H){
        REP(j, W){
            int a;
            cin >> a;
            mp[a] = make_pair(j+1,i+1);
        }
    }
    
    for(int i = D; i < H*W+1; i++){
        if(dp[i] == 0){
            dp[i] = abs(mp[i].first - mp[i-D].first) + abs(mp[i].second - mp[i-D].second) + dp[i-D];
        }
    }
//    for(int i = 0; i < H*W+1; i++){
//        cout << i << "," << dp[i] << endl;;
//    }
//    cout << endl;

    int Q;
    cin >> Q;
    REP(i, Q){
        int L, R;
        cin >> L >> R;
//        ll ans = 0;
//        cout << L << "," << R << endl;
//        for(int j = L; j < R; j+=D){
//            cout << j << ":" << mp[j+D].first << "-" << mp[j].first << endl;
//            ans += abs(mp[j+D].first - mp[j].first) + abs(mp[j+D].second - mp[j].second);
//        }
//        cout << dp[R] - dp[L] << ":" << ans << endl;
        cout << dp[R] - dp[L] << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
n = gets.chomp.to_i
aAry = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
mAry = gets.chomp.split.map(&:to_i)

# p n, aAry, q, mAry

def recSolve(ary, i, m)
    if m == 0 then
        return true
    elsif i >= ary.size then
        return false
    else
        res = recSolve(ary, i + 1, m) || recSolve(ary, i + 1, m - ary[i])
        return res
    end
end

mAry.each do |m|
    # puts "m = " + m.to_s
    if recSolve(aAry, 0, m) then
        puts "yes"
    else
        puts "no"
    end
end



Measured memory_bytes: 6872
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] != ".":
            continue
        num = 0
        if h != 0 and S[h - 1][w] == "#":
            num += 1
        if h != H - 1 and S[h + 1][w] == "#":
            num += 1
        if w != 0 and S[h][w - 1] == "#":
            num += 1
        if w != W - 1 and S[h][w + 1] == "#":
            num += 1
        if h != 0 and w != 0 and S[h - 1][w - 1] == "#":
            num += 1
        if h != H - 1 and w != 0 and S[h + 1][w - 1] == "#":
            num += 1
        if h != 0 and w != W - 1 and S[h - 1][w + 1] == "#":
            num += 1
        if h != H - 1 and w != W - 1 and S[h + 1][w + 1] == "#":
            num += 1
        S[h][w] = str(num)
    print("".join(S[h]))


Measured memory_bytes: 3188
N = int(input())
if N==0:
    print(0)
else:
    A = []
    while N!=0:
        if N%2==1:
            A.append("1")
            N -= 1
        else:
            A.append("0")
        N = N//(-2)
    A = A[::-1]
    print("".join(A))

Measured memory_bytes: 61744
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const ll LINF = 1LL << 50;
const int VMAX = 1e+5;
/* global variables */
/* function */
/* main */
int main(){
    string s, t;
    cin >> s >> t;
    vector<vector<int>> dp(s.size()+1, vector<int>(t.size()+1));

    for (int i = 0; i < s.size(); i++) {
        for (int j = 0; j < t.size(); j++) {
            dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            if (s[i] == t[j]) {
                dp[i+1][j+1] = dp[i][j] + 1;
            }
        }
    }
    string ret = "";
    int slen = s.size()-1;
    int tlen = t.size()-1;
    int len = dp[s.size()][t.size()];
    while (len > 0) {
        if (s[slen] == t[tlen]) {
            ret += s[slen];
            slen--;
            tlen--;
            len--;
        }
        else if (dp[slen+1][tlen+1] == dp[slen+1][tlen]) tlen--;
        else slen--;
    }
    reverse(ret.begin(), ret.end());
    cout << ret << '\n';
}


Measured memory_bytes: 38620
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int gcd = 0;
		int[] xDifference = new int[n];
		// 整数nの数だけ標準入力
		for(int i = 0; i < n; i++) {
			xDifference[i] = Math.abs(x - sc.nextInt());
			if(i == 0) {
				gcd = xDifference[i];
			} else {
				gcd = gcd(gcd, xDifference[i]);				
			}
		}
		System.out.println(gcd);
		sc.close();
	}
	// 最大公約数を求めるgcdメソッド
	private static int gcd(int m, int n) {
		if(m < n) {
			return gcd(n, m);
		}
		if(n == 0) {
			return m;
		}
		return gcd(n, m % n);
	}
}

Measured memory_bytes: 50904
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int i,j,k;
    string s;
    cin>>s>>k;
    if(k==1){cout<<s[0]<<endl;}
    else{
 for(i=0;i<s.size();i++){
         if(s[i]!='1'){
           if(i+1>k){cout<<s[i-1]<<endl;break;}
          else{cout<<s[i]<<endl;break;}
        }
   }
        if(i==s.size()){cout<<s[0]<<endl;}
  
     }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> vec(3);
  for (int i = 0; i < 3; i++) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  if (vec[0] + vec[1] == vec[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
int a,b;cin>>a>>b;
  int sum=a+b;
  int sub=a-b;
  int mul=a*b;
  int res=max(sum,sub);
  res=max(res,mul);
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
$n,m=gets.split.map(&:to_i)
ab = []
m.times do
  ab.push gets.split.map(&:to_i)
end

def combine(ary, i, j)
  ary[i] += ary[j]
  ary[j] = []
  ary
end

def create(ary, val)
  i = ary.find_index { |e| e.empty? }
  ary[i] = val
  ary
end

def disconnected?(br)
  is = []
  1.upto($n) do |i|
    is.push [i]
  end
  br.each do |b|
    src = b.first
    dst = b.last
    src_i = is.find_index { |e| e.include?(src) }
    dst_i = is.find_index { |e| e.include?(dst) }
    if src_i && dst_i
      is = combine(is, src_i, dst_i) if src_i != dst_i
    elsif src_i
      is[src_i].push dst
    elsif dst_i
      is[dst_i].push src
    else
      is = create(is, [src, dst])
    end
  end
  is.select { |e| !e.empty? }.size == 1 ? false : true
end
count = 0
0.upto(m-1) do |i|
  b = ab.dup
  b.delete_at(i)
  count += 1 if disconnected?(b)
end
puts count


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

int main(){
  vector<int> count(100001);
  vector<int> a(100001),b(100001),c(100001);
  int n;
  long long int sum=0LL;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> a.at(i);
    sum+=a.at(i);
    count.at(a.at(i))++;
  }

  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    cin >> b.at(i) >> c.at(i);
    sum += (count.at(b.at(i)) * (c.at(i)-b.at(i)));
    count.at(c.at(i))+=count.at(b.at(i));
    count.at(b.at(i))=0;
    cout << sum << endl;
  }
}

Measured memory_bytes: 4656
import math
class Point:
	def __init__(self,x,y):
		self.x = x
		self.y = y
	def __add__(self,p):
		return Point(self.x+p.x,self.y+p.y)
	def __sub__(self,p):
		return Point(self.x-p.x,self.y-p.y)
	def __mul__(self,p):
		return Point(self.x*p,self.y*p)

def Dot(a,b):
	return a.x*b.x + a.y*b.y
def Cross(a,b):
	return a.x*b.y - a.y*b.x
def Dis(a,b):
	return math.sqrt( (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) )
def Dis2(a,b):
	return (a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)

x1,y1,x2,y2 = map(int,input().split())
p1 = Point(x1,y1)
p2 = Point(x2,y2)
p1p2_dis2 = Dis2(p1,p2)

q = int(input())
for i in range(q):
	x,y = map(int,input().split())
	p = Point(x,y)
	dot_res = Dot(p-p1,p2-p1)
	h = (p2-p1) * (dot_res/p1p2_dis2) + p1

	p_ = h + (h-p)
	print(p_.x,p_.y)



Measured memory_bytes: 5700
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint A, B, K; cin >> A >> B >> K;
    range(i, A, B + 1) {
        if (i - K < A or i + K > B) cout << i << "\n";
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <functional>
#include <algorithm>
using namespace std;

typedef long long ll;

ll days[31];

int main()
{
    int n;
    days[0] = 1;
    days[1] = 1;
    days[2] = 2;
    for(int i = 3; i < 31; i++) {
        days[i] = days[i - 1] + days[i - 2] + days[i - 3];
    }
    
    while(cin >> n && n) {
        ll year = days[n] / 3650;
        if((days[n] % 3650) > 0) {
            year++;
        }
        cout << year << endl;
    }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define cmin(a,b) (a>(b)?a=(b),1:0)
#define cmax(a,b) (a<(b)?a=(b),1:0)
#define dmin(a,b) ((a)<(b)?(a):(b))
#define dmax(a,b) ((a)>(b)?(a):(b))
namespace io
{
	int F()
	{
		 int F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
	long long G()
	{
		 long long F=1,n=0;
		 char ch;
		 while((ch=getchar())!='-'&&(ch<'0'||ch>'9'));
		 ch=='-'?F=0:n=ch-'0';
		 while((ch=getchar())>='0'&&ch<='9')n=n*10+ch-'0';
		 return F?n:-n;
	}
}
int R(int l,int r)
{
	return (rand()<<15|rand())%(r-l+1)+l;
}
int a[1111111];
const int M=1000000007;
int f[1111111];
int sum[1111111];
int ss[1111111];
int la[1111111];
int s0[1111111];
int main()
{
	int n=io::F();
	for(int i=1;i<=n;++i)a[i]=io::F();
	for(int i=1;i<=n;++i)a[i]^=a[i-1];
	for(int i=1;i<=n;++i)s0[i]=s0[i-1]+(a[i]==0);
	int c0=a[n]==0;
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		if(a[i]==0)
		{
			if(i!=n)c0=c0*2%M;
		}
		else
		{
			f[i]=1;
			int c=s0[i]-s0[la[a[i]]];
			if(la[a[i]])ss[a[i]]=(ss[a[i]]+1ll*sum[a[i]]*c)%M,f[i]=(f[i]+ss[a[i]])%M;
			sum[a[i]]=(sum[a[i]]+f[i])%M;
			la[a[i]]=i;
			if(i==n||a[n]==0)ans=(ans+f[i])%M;
		}
	}
	printf("%d\n",(ans+c0)%M);
	return 0;
}


Measured memory_bytes: 22784