akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string ans;
    cin >>ans;
    int cnt=0;
    if(ans[0]=='1')++cnt;
    if(ans[1]=='1')++cnt;
    if(ans[2]=='1')++cnt;
    cout <<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define pb(x) push_back(x)
#define MP(x,y) make_pair(x,y)
using namespace std;
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return(1);
    ll sol=power(a,b/2,m);
    sol=(sol*sol)%m;
    if(b%2==1)
        sol=(sol*a)%m;
    return(sol);
}
int a[107];
void solve()
{
    int n,sol=0;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        for(int j=0;j<n;j++)
        {
            sol=max(sol,a[i]-a[j]);
        }
    cout<<sol;
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define P1 31
#define EPS 0.00000000001
#define MOD int(10e9 + 9)
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    LL n,m;
    cin>>n>>m;
    LL ans = 0;
    if(n) ans += (n * (n-1))/2;
    if(m) ans += (m * (m-1))/2;
    cout<<ans<<'\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main() {

	while (true) {
		std::string n;
		std::cin >> n;
		if (n != "0") {
			int digits_sum = 0;
			for (const char &c : n) digits_sum += (c - '0');
			std::cout << digits_sum << '\n';
		} else {
			break;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3176
MOD=10**9+7
cnt=0; sum=0; prev=nil; can=true; h=Hash.new(0)
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end

def C(a,b) b==0||a==b ? 1 : (b=a-b if a/2<b;(a-b+1..a).inject(:*)/(1..b).inject(:*)) end

def puts_yesno(can) puts(can ? 'Yes' : 'No') end
def putsend(s) puts s; exit end
def debug(k,v) puts "#{k}:#{v}" end
########### ( ˘ω˘ )ｽﾔｧ… ###########
n=gi
kuku=[]
1.upto(9) do |i|
  1.upto(9) do |j|
    kuku << i*j
  end
end

kuku.uniq!
puts_yesno(kuku.include?(n))

Measured memory_bytes: 1788
//#include "stdc++.h"
#include<bits/stdc++.h>
#include<iostream>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;
typedef vector<int> vi;
#define m1 make_pair
#define pb push_back
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0) return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p; }
#define flush fflush(stdout)
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
int main()
{
    int n;IOS;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
        cin>>h[i];
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int const MAXN = 10;
int const MAXQ = 50;

int A[MAXN];
int a[MAXQ], b[MAXQ], c[MAXQ], d[MAXQ];

int N, M, Q;

int calc() {
  int res = 0;
  for(int i = 0; i < Q; ++i) if(A[b[i]] - A[a[i]] == c[i]) res += d[i];
  return res;
}

bool next() {
  for(int i = N-1; i >= 0; --i) {
    if(A[i] < M) {
      ++A[i];
      for(int j = i+1; j < N; ++j) A[j] = A[i];
      return true;
    }
  }
  return false;
}

int main() {
  std::cin >> N >> M >> Q;
  for(int i = 0; i < Q; ++i) {
    std::cin >> a[i] >> b[i] >> c[i] >> d[i]; --a[i]; --b[i];
  }
  for(int i = 0; i < N; ++i) A[i] = 1;
  int ans = calc();
  while(next()) ans = std::max(ans, calc());
  fin(ans);
  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <cstdio>
#include <iomanip>

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;(i)>=0;(i)--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())

typedef long long ll;


int main(){

    while(true){
        int n;
        cin>>n;
        if(n==0)break;
        
        int sum=0;
        REP(i,9){
            int t;
            cin>>t;
            sum+=t;
        }
        
        cout<<n-sum<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
using ll = long long;
using vi = vector<int>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int x,y,z,k; cin >> x >> y >> z >> k;
  vector<ll> a(x), b(y), c(z);
  rep(i,x) {
    cin >> a[i];
  }
  rep(i,y) {
    cin >> b[i];
  }
  rep(i,z) {
    cin >> c[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  sort(c.rbegin(), c.rend());
  vector<ll> ab, abc;
  rep(i,x) {
    rep(j,y) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.rbegin(), ab.rend());
  int n = min(k, (int) ab.size());
  rep(i, n) {
    rep(j, z) {
      abc.push_back(ab[i]+c[j]);
    }
  }
  sort(abc.rbegin(), abc.rend());
  int nn = min(k, (int) abc.size());
  rep(i,nn ) {
    printf("%lld\n", abc[i]);
  }
  return 0;
}

Measured memory_bytes: 44088
#!/usr/bin/env python3
import sys
import math
INF = float("inf")


def cmb(n, r):
    r = min(r, n-r)
    if r == 0:
        return 1
    if r == 1:
        return n

    numer = [n - r + k + 1 for k in range(r)]
    denom = [k + 1 for k in range(r)]

    for p in range(2, r+1):
        pivot = denom[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1, r, p):
                numer[k - offset] /= pivot
                denom[k] /= pivot

    result = 1
    for k in range(r):
        if numer[k] > 1:
            result *= int(numer[k])

    return result


def fact(n):
    if n == 0:
        return 1
    else:
        return n*fact(n-1)


def solve(N: int, x: "List[int]", y: "List[int]"):
    tot = 0
    for i in range(N):
        for j in range(i+1, N):
            tot += math.sqrt((x[i]-x[j])**2 + (y[i]-y[j])**2)
    tot *= 2/N
    print(tot)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var d, t, s int
	fmt.Scan(&d, &t, &s)

	if t >= (d+s-1)/s {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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


Measured memory_bytes: 1768
#include<iostream>
int a, b, c, x, y;
int main() {
  std::string s;
  std::cin >> a >> b >> c >> x >> y;
  int na = 0;
  int nb = 0;
  int nc = 0;

  if (c*2 <= a) {
    nc += x * 2;
    y -= x;
    x -= x;
  }
  if (y > 0 && c*2 <= b) {
    nc += y * 2;
    x -= y;
    y -= y;
  }
  int min_xy = std::min(x, y);
  if (min_xy > 0 && c * 2 <= a + b) {
    nc += min_xy * 2;
    y -= min_xy;
    x -= min_xy;
  }
  if (x > 0) na += x;
  if (y > 0) nb += y;
  std::cout << na*a + nb*b + nc*c << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int n;
    scanf("%d",&n);
    char s[n+1],t[n+1];
    char ans[2*n+1];
    int i;
    scanf("%s",s);
    scanf("%s",t);
    for(i=0;i<n;i++){
        ans[2*i]=s[i];
        ans[2*i+1]=t[i];
    }
    ans[2*n]='\0';
    printf("%s\n",ans);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  bool check = false;
  for (int i = 1; i < 10; i++) {
    for (int j = 1; j < 10; j++) {
      if (i * j == N) {
        check = true;
      }
    }
  }
  if (check) {
    cout << "Yes";
  }
  else {
    cout << "No";
  }
}

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for _ in range(N)]
L = set([0])
i = 0
cnt = 0
while True:
    if a[i]-1 == 1:
        cnt += 1
        break
    elif a[i]-1 in L:
        cnt = -1
        break
    else:
        L.add(a[i]-1)
        cnt += 1
        i = a[i]-1
print(cnt)

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

int main() {
    int n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d >> s;
    a--; b--; c--; d--;

    if (d < c) {
        for (int i = a + 1; i < c; i++) {
            if (s.at(i) == '#' && s.at(i + 1) == '#') {
                cout << "No" << endl;
                return 0;
            }
        }
        bool ok = false;
        for (int i = b - 1; i <= d - 1; i++) {
            if (s.at(i) == '.' && s.at(i + 1) == '.' && s.at(i + 2) == '.') ok = true;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else {
        bool ok = true;
        for (int i = a + 1; i < c; i++) {
            if (s.at(i) == '#' && s.at(i + 1) == '#') ok = false;
        }
        for (int i = b + 1; i < d; i++) {
            if (s.at(i) == '#' && s.at(i + 1) == '#') ok = false;
        }
        if (ok) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 640
import scala.collection.mutable.ArrayBuffer

object Main {

  def main(args: Array[String]): Unit = {

    class UnionSet(par: Array[Int]) {
      def root(x: Int): Int =
        if (par(x) == x) x
        else {
          par(x) = root(par(x))
          par(x)
        }
      def unite(x: Int, y: Int): Unit = {
        val rx = root(x)
        val ry = root(y)
        if (rx != ry)
          par(rx) = ry
      }
      def same(x: Int, y: Int): Boolean =
        root(x) == root(y)
    }
    object UnionSet {
      def apply(n: Int): UnionSet =
        new UnionSet(Array.range(0, n))
    }

    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val W = Array.fill(N, N)(sc.nextInt())

    val _E = new ArrayBuffer[(Int, Int)]() // (辺(u,v), 重みw)
    
    for {
      i <- 0 until N
      j <- 0 until N
      if W(i)(j) >= 0
    } _E.append((i, j))
    
    val E: List[(Int, Int)] = _E.sortBy(e => W(e._1)(e._2)).toList // 辺(軽い順)
    
    // 最初, 全ての頂点は別の木として初期化する
    val unionset = UnionSet(N)
    var count = 0
    // 軽い辺から見ていき
    E foreach { e =>
      val (u, v) = e
      // u, v が別の木ならば, これは軽い辺なので安全に追加できる.
      if (!unionset.same(u, v)) {
        unionset.unite(u, v)
        count += W(u)(v)
      }
    }

    // 入力が連結グラフであることから,最終的に出来上がった木は1本となり, これが最小全域木である
    // 加えた辺の重さの合計が最小全域木の重さの合計
    println(count)
  }

}



Measured memory_bytes: 62256
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
 
typedef long long LL;
  
#define N 200005
 
struct Node
{
    LL val;
    int id;
}md[N];
 
struct data
{
    int l,r,id;
}ask[N];
 
char s[N];
 
LL c[N],d[N],h[N];
LL a[N];
 
LL p;
int m,n,f;
int l,r;
 
int len,K;
 
int cmp(Node aa,Node bb)
{
    return aa.val<bb.val;
}
 
int cmp2(data aa,data bb)
{
    return aa.l/K==bb.l/K ? aa.r<bb.r : aa.l<bb.l;
}
 
void work()
{
    for (int i=1;i<=len;i++)
    {
        d[i]=d[i-1]+((s[i-1]-'0')%p ? 0 : i);
        c[i]=c[i-1]+((s[i-1]-'0')%p==0);
    }
    m = 1;
    while (m--)
    {
        l = 1,r = len;
        printf("%lld\n",d[r]-d[l-1]-(c[r]-c[l-1])*(l-1));
    }
}
 
int main()
{
    scanf("%d",&f);
    scanf("%lld",&p);
    scanf("%s",s);
    len=strlen(s);
    K=sqrt(len)+1;
    if (p==2 || p==5)
    {
        work();
        return 0;
    }
    LL res=1;
    for (int i=len-1;i>=0;i--)
    {
        md[i].val=(md[i+1].val+(s[i]-'0')*res)%p;
        md[i].id=i;
        res=res*10%p;
    }
    md[len].id=len;
    sort(md,md+len+1,cmp);
    res=0;
    for (int i=0;i<=len;i++)
    {
        if (i && md[i].val!=md[i-1].val)
            res++;
        h[md[i].id]=res;
    }
    m = 1;
    for (int i=0;i<=m;i++)
    {
        ask[i].l = 1,ask[i].r = len;
        ask[i].l--;
        ask[i].id=i;
    }
    sort(ask,ask+m,cmp2);
    int L(0),R(-1);
    res=0;
    for (int i=0;i<m;i++)
    {
        while (R<ask[i].r)
            res+=c[h[++R]]++;
        while (R>ask[i].r)
            res-=--c[h[R--]];
        while (L>ask[i].l)
            res+=c[h[--L]]++;
        while (L<ask[i].l)
            res-=--c[h[L++]];
        a[ask[i].id]=res;
    }
    for (int i=0;i<m;i++)
        printf("%lld\n",a[i]);
    return 0;
}

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

int main(){

	int r, g, b, ans;

	cin >> r >> g >> b;

	ans = 100*r + 10*g + b;

	if(ans%4 == 0){
		cout << "YES\n";
	}
	else{
		cout << "NO\n";
	}
	return 0;

}

Measured memory_bytes: 888
//Author: ZindagiMeBasAishHiChahiye
//WA/TLE
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repp(i,a,b)    for(ll int i=b-1;i>=a;i--)
#define tr(container,it) for(__typeof__(container.begin()) it = container.begin(); it != container.end(); it++)
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define mpi         map<pair<ll int,ll int>,ll int>
#define vii         vector<pair<ll,pair<ll,ll> > >
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        7340033
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define what_is(x)  cerr << #x << " is " << x << endl;
using namespace std;
#define N  5005
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define ll          long long
// ll po(ll a,ll b,ll m){
// 	a%=m;
// 	if(b==0) return 1;
// 	if(b%2) return (a*(po((a*a)%m,b/2,m)%m)%m)%m;
// 	return po((a*a)%m,b/2,m)%m;
// }

bool vis[N];
ll z[N];
void init(ll n){
	rep(i,0,n+1){
		vis[i]=false;
		z[i]=0;
	}
}
void dfs(ll n,vi &a,vi &b,ll &an,ll len,ll k,ll c){
	vis[n]=true;
	len++;
	c+=b[n];
	z[len]=c;
	an=max(an,c);
	if(len==k){
		return;
	}
	if(vis[a[n]]){
		// if(c>0){
			ll zz=(k/len-1)*c;
			
			an=max(an,zz);
			rep(i,1,len+1){
				zz+=z[i];
				an=max(an,zz);
				zz-=z[i];
			}
			zz+=z[len];
			// cout<<zz<<endl;
			rep(i,1,k%len+1){
				zz+=z[i];
				an=max(an,zz);	
				zz-=z[i];
			}
	}
	else{
		dfs(a[n],a,b,an,len,k,c);
	}
}

void solve(){
	ll n,k;
	cin>>n>>k;
	vi a(n),b(n);
	rep(i,0,n){
		cin>>a[i];
		a[i]--;
	}
	rep(i,0,n) cin>>b[i];
	ll an=-1e18;
	rep(i,0,n){
		init(n+1);
		dfs(i,a,b,an,0,k,0);
	}
	cout<<an;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	ll TESTS=1;
	// cin>>TESTS;
	while(TESTS--){
		solve();

	}
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

typedef pair<int, int> pp;
typedef pair<pp, int> ppp;
const int MAX = 150;

int main()
{
	int n, a, b;
	int m;
	while(cin >> n && n)
	{
		vector<ppp> br;

		REP(n)
		{
			cin >> m >> a >> b;
			br.push_back(ppp(pp(a,1), m));
			br.push_back(ppp(pp(b,-1), m));
		}
		sort(all(br));
		m = 0;
		bool ok = true;
		REP(n * 2)
		{
			m += (br[i].first.second) * (br[i].second);
			if(m > MAX) ok = false;
		}
		if(ok) cout << "OK" << endl;
		else cout << "NG" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
using namespace std;

int main()
{
    char a, b;
    
    cin >> a >> b;
    
    if(a == b) {
        cout << "H\n";
    } else {
        cout << "D\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"

)

func main() {
	solve(os.Stdin, os.Stdout)
}

type stringSorter []byte

func (a stringSorter) Len() int           { return len(a) }
func (a stringSorter) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a stringSorter) Less(i, j int) bool { return a[i] < a[j] }

func solve(stdin io.Reader, stdout io.Writer) {
	var n int

	var sc = make(map[string]int)

	reader := bufio.NewScanner(stdin)

	reader.Scan()
	n, _ = strconv.Atoi(reader.Text())

	for i := 0; i < n; i++ {
		reader.Scan()
		sort.Sort(stringSorter(reader.Bytes()))
		sc[reader.Text()]++
	}

	w := 0
	for _, v := range sc {
		w += v * (v - 1) / 2
	}
	fmt.Fprintln(stdout, w)
}



Measured memory_bytes: 9856
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N = int(readline())

    f = [0] * (N+1)
    for x in range(1,100):
        for y in range(1,100):
            for z in range(1,100):
                tmp = x**2 + y**2 + z**2 + x*y + y*z + z*x
                if tmp <= N:
                    f[tmp] += 1
    
    print("\n".join(map(str, f[1:])))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9292
import sys

def del_add_dot_list(a):
    del_index = []
    for i in range(len(a)):
        if all(map(lambda x: x=='.', a[i])):
            del_index.append(i)
    for i in del_index[::-1]:
        del a[i]
    return a

def spin(a):
    if len(a[0]) == 1:
        return [''.join(list(map(lambda x: x[0], a)))]
    else:
        return [''.join(list(map(lambda x: x[0], a)))] + spin(list(map(lambda x: x[1:], a)))

def main():
    sys.setrecursionlimit(10000)
    h, w = map(int, input().split())
    a = [input() for i in range(h)]
    deleted = spin(del_add_dot_list(spin(del_add_dot_list(a))))
    [print(l) for l in deleted]

if __name__ == '__main__':
    main()

Measured memory_bytes: 4340
n = int(input())
res = []
for i in range(n):
    s, p = input().split()
    p = int(p)
    res.append([i+1, s, p])

res = sorted(res, key=lambda x:x[2], reverse=True)
res = sorted(res, key=lambda x:x[1], reverse=False)
for r in res:
    print(r[0])

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

long long dp[100010];
long long dp2[100010];
long long x[100010], v[100010];
long long n, C;

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

    for (long long i(1); i <= n; i++) {
        cin >> x[i] >> v[i];
        dp[i] = dp[i - 1] - x[i] + x[i - 1] + v[i];
        dp2[i] = dp2[i - 1] - 2 * x[i] + 2 * x[i - 1] + v[i];
    }
    x[n + 1] = C;

    for (long long i(1); i <= n; i++) {
        dp[i] = max(dp[i], dp[i - 1]);
        dp2[i] = max(dp2[i], dp2[i - 1]);
    }

    long long best(dp[n]), act(0), act2(0);

    for (long long i(n); i >= 1; i--) {
        act += v[i];
        act += -x[i + 1] + x[i];
        act2 += v[i];
        act2 += -2 * x[i + 1] + 2 * x[i];
        best = max(best, max(act + dp2[i - 1], act2 + dp[i - 1]));
    }

    cout << best << '\n';
    return 0;
}


Measured memory_bytes: 3328
n = int(input())
a = list(map(int, input().split()))
m = [0]*n
for i in range(n):
  if i%2==0:
    m[0] += a[i]
  else:
    m[0] -= a[i]
for i in range(1, n):
  m[i] = 2*(a[i-1]-(m[i-1]//2))
  
print(*m)

Measured memory_bytes: 14032
#include<stdio.h>
int main(void){
	int a[4][13],b[4][13],i,j,n,y,z;
	char x,d;
	scanf("%d",&n);
	for(i=0;i<4;++i){
		for(j=0;j<13;++j)a[i][j]=0;
	}
	for(i=0;i<n;++i){
		scanf("%*c%c %d",&x,&y);
		if(x=='S')z=0;
		else if(x=='H')z=1;
		else if(x=='C')z=2;
		else if(x=='D')z=3;
		a[z][y-1]=1;
	}
	for(i=0;i<4;++i){
		for(j=0;j<13;++j){
		if(a[i][j]==0 && i==0)printf("S %d\n",j+1);
		else if(a[i][j]==0 && i==1)printf("H %d\n",j+1);
		else if(a[i][j]==0 && i==2)printf("C %d\n",j+1);
		else if(a[i][j]==0 && i==3)printf("D %d\n",j+1);
		}
	}

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>

using namespace std;

bool vis[10];
int n,k;

bool jdg(int x)
{
    while(x){
        int t=x%10;
        if(vis[t])
            return 0;
        x/=10;
    }
    return 1;
}
int main()
{
    scanf("%d%d",&n,&k); 
    for(int i=1; i<=k; i++){
        int t;
        scanf("%d",&t);
        vis[t]=1;
    }
 
    for(int i=n;;i++){
        if(jdg(i)){
            printf("%d\n",i);
            break;
        }
    }
    return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = 0;
    
    while(n--){
        int t;
        cin >> t;
        while(t %2 ==0){
            t /=2;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += b[a[i]-1]
    if i > 0 and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]
print(ans)

Measured memory_bytes: 3064
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	q := getNextInt(scanner)
	aa := make([][]int, n)
	for i := 0; i < q; i++ {
		s := getNextInt(scanner)
		switch s {
		case 0:
			t := getNextInt(scanner)
			x := getNextInt(scanner)
			aa[t] = append(aa[t], x)
		case 1:
			t := getNextInt(scanner)
			if len(aa[t]) == 0 {
				continue
			}
			fmt.Fprintln(writer, aa[t][len(aa[t])-1])
		case 2:
			t := getNextInt(scanner)
			if len(aa[t]) == 0 {
				continue
			}
			aa[t] = aa[t][:len(aa[t])-1]
		}
	}
}



Measured memory_bytes: 8868
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define se second
#define pi 3.14159265358979
//ll string_inp() {cin.get(); for(int i =0;i<n;i++){ getline(cin,s[i]);}}
ll gcd(ll a, ll b){ if (a == 0) return b;  return gcd(b % a, a);  }
ll power(ll x, ll y, ll mod = 2e18) {ll ans = 1;x %= mod;while(y){if(y&1) ans = (x * ans) % mod;x = (x * x) % mod;y >>= 1;}return ans;}
ll modInverse(ll a, ll m) { ll m0 = m; ll y = 0, x = 1; if (m == 1) return 0; while (a > 1) { ll q = a / m; ll t = m; m = a % m,a = t; t = y; y = x - q * y; x = t; } if(x < 0) x += m0;return x;}
int takemod(int a, int mod = MOD){a%=mod;if(a<0)a+=mod;return a;}
ll binsearch(std::vector<ll>& nums, ll target) {ll n = nums.size();ll l = 0;ll r = n-1;while(l<=r){ll mid = l+ (r-l)/2;if(nums[mid]==target)return mid;else if(nums[mid]>target)r = mid-1;else l = mid+1;}return -1;}
bool isPowerOfTwo (int x) {return x && (!(x&(x-1))); }

using namespace std;

int main()
{
   fastio
   ll t;
   string s;
   cin>>s;

   int ans =0;
   for(int i=0;i<s.size();i++)
   {
       ans+=s[i]-'0';
   }
   if(ans%9)
    cout<<"No"<<endl;
   else cout<<"Yes"<<endl;

}




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

using namespace std;

int main(){
    vector<int> n,x;
    int tempn,tempx;
    do{
        cin>>tempn>>tempx;
        n.push_back(tempn);
        x.push_back(tempx);
    }while (tempn!=0 || tempx!=0);
    for (int i=0;i<n.size()-1;i++){
        int cnt=0;
        for (int a=1;a<=n[i];a++){
            for (int b=a+1;b<=n[i];b++){
                int c=x[i]-a-b;
                if (c>b && c<=n[i]){
                    cnt++;
                }
            }
        }
        cout<<cnt<<endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
using namespace  std;

struct StCst
{
  int m_nNo;
  int m_nSeq;
  bool m_bDone;

  static bool AsdNo(const StCst &cnroLeft, const StCst &cnroRight) 
  { return cnroLeft.m_nNo < cnroRight.m_nNo; }
};

void fnInput(vector<StCst> &rvoSort)
{
  int nMaxSiz, nCnt = 0;
  cin >> nMaxSiz;

  rvoSort.resize(nMaxSiz);
  for (int i = 0; i < nMaxSiz; i++)
  {
    cin >> rvoSort[i].m_nNo;
    rvoSort[i].m_nSeq = nCnt++;
  }
}

void fnMinCostSort(vector<StCst> &rvoSort, int &rnSwpCnt)
{
  sort(begin(rvoSort), end(rvoSort), StCst::AsdNo);
  int nMinNo = rvoSort[0].m_nNo;

  int nCost;
  for (int i = 0; i < rvoSort.size(); i++)
  {
    if (rvoSort[i].m_bDone)  continue;

    int nTotal = rvoSort[i].m_nNo;
    int nCurSize = 1;
    int nCurMin = rvoSort[i].m_nNo; 
    rvoSort[i].m_bDone = true;

    int j = rvoSort[i].m_nSeq;
    while  (rvoSort[j].m_nNo != rvoSort[i].m_nNo)
    {
      nTotal += rvoSort[j].m_nNo;
      nCurSize++;
      nCurMin = min(nCurMin, rvoSort[j].m_nNo);
      rvoSort[j].m_bDone = true;
      j = rvoSort[j].m_nSeq;
    }

    if (nCurSize == 1)
        nCost = 0;
    else
        nCost = min(nTotal + (nCurSize - 2) * nCurMin, 
                    nTotal + nCurMin + (nCurSize + 1) * nMinNo);
    rnSwpCnt += nCost;
  }
}

void fnResult(int nSwpCnt)
{
  cout << nSwpCnt << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<StCst> voSort;

  fnInput(voSort);

  int nSwpCnt = 0;
  fnMinCostSort(voSort, nSwpCnt);

  fnResult(nSwpCnt);
  return 0;
}

Measured memory_bytes: 1228
#include<stdio.h>

int search(int A[], int n, int key) {
  int i = 0;
  A[n] = key;
  while ( A[i] != key ) i++;
  return i != n;
}

int main() {
  int i, n, A[10000+1], q, key, sum = 0;

  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);

  scanf("%d", &q);
  for ( i = 0; i < q; i++ ) {
    scanf("%d", &key);
    if ( search(A, n, key) ) sum++;
  }
  printf("%d\n", sum);

  return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, i;cin>>N;
  vector<int>B(N-1), A(N);
  for(i=0; i<N-1; i++)cin>>B[i];

  A[0] = A[1] = B[0];
  for(i=1; i<N-1; i++){
    if(B[i-1] <= B[i]){
      A[i] = B[i-1];
      A[i+1] = B[i];
    }else{//if(B[i-1] > B[i])
      A[i] = A[i+1] = B[i];
    }
  }

  int ans = 0;
  for(i=0; i<N; i++){
    ans += A[i];
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define long long long
#define read cin >>
#define echo cout <<
#define fin << endl
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

vector<string> string_split(string s, char delimit) {
  vector<string> v;
  stringstream ss{s};
  string buf;
  while (getline(ss, buf, delimit)) {
    v.push_back(buf);
  }
  return v;
}

int main() {
  // bit全探索で+の位置を総当たりして和を求める
  string s;
  read s;
  long ans = 0;
  int n = s.size() - 1;
  if (n == 0) {
    ans = stol(s);
  } else {
    for (int bit = 0; bit < (1 << n); ++bit) {
      string target = s;
      int hosei = 0;
      // 文字列生成
      for (int i = 0; i < n; ++i) {
        if (bit & (1 << i)) {
          // 列挙にi番目の要素が含まれる場合の処理
          // cout << "bit = " << bit << " / "
          //     << "target = " << target << endl;
          target.insert(i + 1 + hosei, "+");
          // cout << "target_after = " << target << endl;
          hosei++;
        } else {
          // 含まれない場合の処理
        }
      }
      vector<string> v = string_split(target, '+');
      for (string tmp : v) {
        // cout << "tmp = " << tmp << endl;
        ans += stol(tmp);
      }
    }
  }
  echo ans fin;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define ll  long long
#define PI  acos(-1)
#define pb  push_back
#define ins insert
#define INF 1000000000000000007 //1e18+7
#define mk  make_pair
#define lb(v,x) lower_bound(all(v),x)
#define ub(v,x)  upper_bound(all(v),x)
#define ff  first
#define ss  second
#define rev reverse
#define endl "\n"
#define max3(x,y,z)  max(x,max(y,z))
#define min3(x,y,z)  min(x,min(y,z))
#define sz(a) (ll)a.size()
#define double long double
#define minpq  priority_queue <ll,vector<ll>,greater<ll> > 
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define mset(x,y)  memset(x,y,sizeof(x))
#define all(x)   (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bp(n)  __builtin_popcountll(n)
#define mxt(a)  *(max_element(a.begin(),a.end()))
#define mnt(a)  *(min_element(a.begin(),a.end())
#define unique_sort(c) (sort(all(c)), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define trav(a, x) 	  for(auto &a : x)
#define re(i,n)       for(ll i=0;i<n;++i) 
#define int2Bin(x,y)  bitset <y> z=x; cout<<z.to_string()<<endl;
const double eps=1e-7;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
// int dx[8]={+1, +1, +1, 0, 0, -1, -1, -1};
// int dy[8]={+1, 0, -1, +1, -1, +1, 0, -1};
int dx[]={0,0,1,-1};
int dy[]={1,-1,0,0};
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=(res*x);y=y>>1;x=(x*x);}return res;}
ll sqr(ll x) { return x * x;}
template <typename T> T gcd(T a,T b){ if(a==0) return b; return gcd(b%a,a); }
template <class T> inline void chmax(T &x,T y){ x = max((x), (y));}
template <class T> inline void chmin(T &x,T y){ x = min((x), (y));}
template <class T> T abs(T x) { return x>0 ? x : -x;}
template <typename T> T powm(T a,T b, ll m){T cnt=1; while(b>0){ if(b%2==1) cnt=(cnt*a)%m; b/=2; a=(a*a)%m; }return cnt%m;}
typedef pair<int,int>  pii;
typedef pair<ll,ll>  pll;
typedef vector<pll>  vpii;
typedef vector<ll>   vll;
typedef vector<int>  vii;
///template <typename T> using orderset = tree <T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
///*X.find_by_order(k) //returns the kth largest element.(0-based)
///X.order_of_key(val) //returns the no. of values less than val.
ll ncr(ll n,ll r){ll res=1;if(r>n)return 0;if(r>n-r)r=n-r;for(ll i=0;i<r;i++){res*=(n-i);res/=(i+1);}return res;}
const int MOD=1000000007;	
const int N=5005;
void prec(){
	
}
void run(){
	int n;cin>>n;
	if(n%1000==0) cout<<0;
	else cout<<1000-n%1000;
}					
int32_t main()
{
    cin.sync_with_stdio(0);cin.tie(0);
	cin.exceptions(cin.failbit);
    int tc=1;
    //cin>>tc;
    prec();
    re(i,tc)
    	run();
    return 0; 
}

Measured memory_bytes: 3648
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let s: usize = iter.next().unwrap().parse().unwrap();

    let mut a: Vec<usize> = vec![s];

    let mut prev = s;

    if s == 1 || s == 2 || s == 4 {
        println!("{}", 4);
    } else {
        loop {
            let next = if prev % 2 == 0 {
                prev / 2
            } else {
                3 * prev + 1
            };
            a.push(next);

            if next == 4 {
                break;
            }
            prev = next;
        }

        // for item in &a{
        //     print!("{} ", item);
        // }

        println!("{}", a.len() + 3);
    }

    // println!("{}", ab * bc / 2);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long int
const ll mod=1e9+7;
using namespace std;

ll power(ll a,ll n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a)%mod,n/2))%mod;
    }
    return power((a*a)%mod,n/2)%mod;
}

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ll s;
  cin>>s;
  ll dp [2001]={};
  dp[0] = 1;
  for(ll i = 1;i<=s ;i++)
  {
  	for(ll j = 3 ;j<=i ;j++)
  	{
  		dp[i] += dp[i-j];
  		dp[i] %= mod;
  	}
  }
  cout<<dp[s];
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back
#define pb push_back

int main(void){
  int n,a,b;
  cin >> n >> a >> b;
  cout << min(a*n, b) << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
l = sorted(l,key=lambda x:x[0])
ans = 0
i = 0
while m>=0:
    if l[i][1]>=m:
        ans += m*l[i][0]
        break
    else:
        ans += l[i][1]*l[i][0]
        m -= l[i][1]
    i+=1
print(ans)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

vi64 make_list(i64 x) {
  vi64 ret;
  for (i64 i = 2; i * i <= x; i += 1) {
    if (x % i == 0) {
      ret.push_back(i);
      if (i != x / i) ret.push_back(x / i);
    }
  }
  sort(all(ret));
  ret.push_back(x);
  return ret;
}

void solve() {
  i64 n;
  cin >> n;
  if (n == 2) {
    cout << 1 << endl;
    return;
  }
  i64 ans = 0;
  {
    auto v = make_list(n - 1);
    ans += sz(v);
  }
  {
    auto judge = [&](i64 x) {
      i64 nn = n;
      while (nn % x == 0) nn /= x;
      return nn % x == 1;
    };
    auto v = make_list(n);
    rep(i, sz(v)) {
      if (judge(v[i])) {
        ans += 1;
      }
    }
  }
  cout << ans << endl;
}

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

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() {
  string S;
  ll K;
  cin >> S >> K;
  if (S[0] != '1') {
    cout << S[0] << endl;
  } else {
    int one = 0;
    REP(i, S.size()) {
      if (S[i] == '1')
        one = i + 1;
      else
        break;
    }
    if (K <= 1ll * one)
      cout << '1' << endl;
    else
      cout << S[one] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input_str[] = new String[2];
        Deque<String> list = new ArrayDeque<String>();
        StringBuilder ans = new StringBuilder();
        try {
            int N = Integer.parseInt(br.readLine());

            for (int loop = 0; loop < N; loop++) {
                input_str = br.readLine().split("\\s+");

                if (input_str[0].equals("insert")) {
                    list.addFirst(input_str[1]);
                } else if (input_str[0].equals("delete")) {
                    list.remove(input_str[1]);
                } else if (input_str[0].equals("deleteFirst")) {
                    list.removeFirst();
                } else if (input_str[0].equals("deleteLast")) {
                    list.removeLast();
                }
            }
            if (!list.isEmpty()) {
                ans.append(list.getFirst());
                list.removeFirst();
            }
            while (!list.isEmpty()) {
                ans.append(" ").append(list.getFirst());
                list.removeFirst();
            }
            System.out.println(ans.toString());
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 600572
import java.io.*;
import java.util.*;
 
public class Main{
	boolean[][] memo;
	int A, B, C, D, E, F;
	public void solve(){
		A = nextInt();
		B = nextInt();
		C = nextInt();
		D = nextInt();
		E = nextInt();
		F = nextInt();

		memo = new boolean[F / 100 + 1][F + 1];
			
		dfs(0, 0);
		double max = 0;
		int maxi = A;
		int maxj = 0;
		for(int i = 0; i < memo.length; i++){
			for(int j = 0; j < memo[i].length; j++){
				if(i + j == 0) continue;
				if(memo[i][j]){
					if(E * i >= j && max < (double)j /(i * 100 + j)){
						max = (double)j /(i * 100 + j);
						maxi = i;
						maxj = j;
					}
				}
			}
		}
		out.printf("%d %d\n", maxi * 100 + maxj, maxj);
	}
	public void dfs(int water, int suger){
		if(water * 100 + suger > F) return;
		if(memo[water][suger]) return;
		memo[water][suger] = true;
		dfs(water +  A, suger);
		dfs(water +  B, suger);
		dfs(water, suger + C);
		dfs(water, suger + D);
	}
	
	private static PrintWriter out;
	public static void main(String[] args){
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}
	
	
	
	public static int nextInt(){
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}
	
	public static long nextLong(){
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(;i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}
	public static String next(){
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}
	
	
	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;
	private static int read(){
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return (bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}
	
	private static boolean isAlNum(int c){
		return '!' <= c && c <= '~';
	}
}

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  long long ans = (long long) -1e23;
  if (a <= 0 && c <= 0) {
    ans = max(a*c, ans);
  }
  if (b >= 0 && d >= 0) {
    ans = max(b*d, ans);
  }
  if (b <= 0 && c >= 0) {
    ans = max(b*c, ans);
  }
  if (d <= 0 && a >= 0) {
    ans = max(a*d, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
    int n;
    cin >> n;
    vector<int> a(n+2);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int sum = 0;
    for(int i = 0; i <= n; i++){
        sum += abs(a[i] - a[i+1]);
    }
    for(int i = 1; i <= n; i++){
        int ans = sum;
        ans -= abs(a[i]-a[i-1]);
        ans -= abs(a[i+1]-a[i]);
        ans += abs(a[i+1]-a[i-1]);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

int dp_solve(const int n, const string& s){
    //x : s.size()
    //y : use cnt
    //z ; lucky number
    bool dp[n+1][4][1000] = { };
    // vector<vector<vector<bool>>> dp(n + 1, vector<vector<bool>>(4, vector<bool>(1000, false)));
    dp[0][0][0] = true;
    for (auto i = 0; i < n; i++) {
        int tmp = (s[i] - '0');
        for (auto j = 0; j <= 3; j++) {
            for (auto k = 0; k <= 999; k++) {
                int index = k * 10 + tmp;
//                cout << i << " " << j << " " << k << " " << index << endl;
//                cout << dp[i][j][k] << " -> " << dp[i + 1][j][k] << endl;
                dp[i + 1][j][k] = dp[i][j][k] or dp[i + 1][j][k];
                if(index <= 999 and j < 3) {
//                    cout << dp[i][j][k] << " -> " << dp[i + 1][j + 1][index] << endl;
                    dp[i + 1][j + 1][index] = dp[i][j][k] or dp[i + 1][j + 1][index];
                }
            }
        }
    }

//    for (auto i = 0; i <= n; i++) {
//        for (auto j = 0; j <= 3; j++) {
//            for (auto k = 0; k <= 30; k++) {
//                cout << dp[i][j][k] << " ";
//            }
//            cout << endl;
//        }
//        cout << endl;
//    }

    int cnt = 0;
    for (auto i = 0; i <= 999; i++) if(dp[n][3][i]) cnt++;

    return cnt;
}

int main(){
    int n; string s;
    cin >> n >> s;

//    int ans = 0;
//    for (auto i = 0; i <= 999; i++) {
//        vector<int> number(3);
//        int tmp = i;
//        for (auto j = 0; j < 3; j++) {
//            number[j] = tmp % 10;
//            tmp /= 10;
//        }
//        int cnt = 0;
//        for (auto k = 0; k < (int)s.size(); k++) {
//            if(s[k] - '0' == number[cnt]) cnt++;
//            if(cnt == 3) {
//                ans++;
//                break;
//            }
//        }
//    }
//
//    cout << ans << endl;

    cout << dp_solve(n, s) << endl;
    return 0;
}

Measured memory_bytes: 117504
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define lc (x<<1)
#define rc (x<<1|1)
#define gc getchar()//(p1==p2&&(p2=(p1=buf)+fread(buf,1,size,stdin),p1==p2)?EOF:*p1++)
#define mk make_pair
#define pi pair<int,int>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=55,M=N*N,ED=N*M*2-5,size=1<<20;

//char buf[size],*p1=buf,*p2=buf;
template<class o> void qr(o &x) {
	char c=gc; x=0; int f=1;
	while(!isdigit(c)){if(c=='-')f=-1; c=gc;}
	while(isdigit(c)) x=x*10+c-'0',c=gc;
	x*=f;
}
template<class o> void qw(o x) {
	if(x/10) qw(x/10);
	putchar(x%10+'0');
}
template<class o> void pr1(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); putchar(' ');
}
template<class o> void pr2(o x) {
	if(x<0)x=-x,putchar('-');
	qw(x); puts("");
}

int n,m,s,sil[N],tim[N];
ll f[N][M*2],ans[N];
struct edge{int y,next,d,t;}a[M]; int len,last[N];
void ins(int x,int y,int d,int t) {a[++len]=(edge){y,last[x],d,t}; last[x]=len;}

pair<int,int> q[ED+5];
int l,r;

void spfa() {
	q[l=r=1]=mk(1,s);r++;
	while(l!=r) {
		int x=q[l].first; 
		s=q[l].second; l++; if(l==ED)l=1;
		ans[x]=min(ans[x],f[x][s]);
		if(s+sil[x]<M*2&&f[x][s]+tim[x]<f[x][s+sil[x]]) {
			f[x][s+sil[x]]=f[x][s]+tim[x];
			q[r++]=mk(x,s+sil[x]);
			if(r==ED) r=1;
		} 
		for(int k=last[x],y,d,t;k;k=a[k].next) {
			y=a[k].y; d=a[k].d; t=a[k].t;
			if(s>=d&&f[x][s]+t<f[y][s-d]) {
				f[y][s-d]=f[x][s]+t;
				q[r++]=mk(y,s-d);
				if(r==ED) r=1;
			}
		}
	}
}

int main() {
	qr(n); qr(m); qr(s); s=min(s,M-1);
	for(int i=1,X,Y,D,T;i<=m;i++)
		qr(X),qr(Y),qr(D),qr(T),ins(X,Y,D,T),ins(Y,X,D,T);
	memset(f,63,sizeof(f));
	memset(ans,63,sizeof(ans));
	for(int i=1;i<=n;i++) qr(sil[i]),qr(tim[i]),sil[i]=min(sil[i],M-1);
	f[1][s]=0;
	spfa();
	for(int i=2;i<=n;i++) pr2(ans[i]);
	return 0;
}



Measured memory_bytes: 8772