akhauriyash/Code-Regression huggingface dataset:
var str = readLine()!
for num in 0...3 {
  let a = str.index(str.startIndex, offsetBy: num)
  let b = str.index(str.startIndex, offsetBy: num+1)
  
   if str [a]==str [b] {
    print("Bad")
     break
   }
  else if num==3 {
    print("Good")
  }
}
  

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

int main() {
    //変数宣言
    int N;
    int A[210]; //最大200個なので余裕を持って210に

    //入力受付
    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    int res = 0;

    //操作が行える限り操作を繰り返す
    while(true) {
        bool exist_odd = false; //A[i]が全て偶数か判定するフラグ
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true; //奇数があったらフラグを立てる
        }

        if (exist_odd) break;

        //操作を行えるなら操作を実際に行う
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res;
    }

    cout << res << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX=11;

int w,d,ans;
int x[MAX],y[MAX],check[MAX];

void solve(){
    ans=0;
    for (int i=0;i<d;++i) check[i]=0;
    for (int i=0;i<w;++i){
        ans+=x[i];
        for (int j=0;j<d;++j) if (!check[j]&&x[i]==y[j]){
            check[j]=1; break;
        }
    }
    for (int i=0;i<d;++i) if (!check[i])
        ans+=y[i];
    cout << ans << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> w >> d,w){
        for (int i=0;i<w;++i) cin >> x[i];
        for (int i=0;i<d;++i) cin >> y[i];
        solve();
    }
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

// SegmentTree
template<class T> struct Min {
  using Type = T;
  T nil;
  Min(){}
  Min(T nil):nil(nil){}
  T operator()(T a, T b) { return a < b ? a : b; }
};
template<class T> struct Max {
  using Type = T;
  T nil;
  Max(){}
  Max(T nil):nil(nil){}
  T operator()(T a, T b) { return a > b ? a : b; }
};
template<class T> struct Sum {
  using Type = T;
  T nil;
  Sum(){}
  Sum(T nil):nil(nil){}
  T operator()(T a, T b) { return a + b; }
};

template<class Monoid> struct SegmentTree {
  using T = typename Monoid::Type;
  vector<T> data;
  Monoid func;
  int sz;
  SegmentTree(int n, Monoid f):func(f) {
    sz = 1; while(sz < n) sz <<= 1;
    data.resize(2*sz+1, func.nil);
  }
  void update(int k, T x) {
    k += sz-1;
    data[k] += x;
    while(k > 0) {
      k = (k-1)/2;
      data[k] = func(data[2*k+1], data[2*k+2]);
    }
  }
  T query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return func.nil;
    if(a <= l && r <= b) return data[k];
    return func(query(a, b, 2*k+1, l, (l+r)/2), query(a, b, 2*k+2, (l+r)/2, r));
  }
  T query(int a, int b) {
    return query(a, b, 0, 0, sz);
  }
};


signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n, q;
  cin >> n >> q;
  SegmentTree<Sum<int>> seg(n, Sum<int>(0));
  rep(i, q) {
    int com, x, y;
    cin >> com >> x >> y;
    if(com == 0) seg.update(x-1, y);
    else cout << seg.query(x-1, y) << endl;
  }

  return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using lint = long long;
using namespace std;

const int MOD = 1000000007;

const double PI = acos(-1);
const double Rad2Deg = 180.0 / PI;
const double Deg2Rad = PI / 180.0;

int main() {
    int N;
    cin >> N;
    int h[100020];
    for (int i = 0; i < N; i++) cin >> h[i];

    int c[100020];
    c[1] = abs(h[1] - h[0]);

    for (int i = 2; i < N; i++) {
        c[i] = min(c[i-2] + abs(h[i] - h[i-2]), c[i-1] + abs(h[i] - h[i-1]));
    }

    cout << c[N-1] << endl;
    return 0;
}


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

int main() {
    int x, y;
    cin >> x >> y;
    for (int crane = 0; crane <= x; crane++) {
        int t = crane*2+(x-crane)*4;
        if (t==y) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";


    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <map>
#include <vector>
using namespace std;
int main()
{
  for(;;){
    int n;
    cin >> n;
    if(n == 0) break;
    map<string,int> price;
    for(int i=0; i<n; i++){
      string s;
      int p;
      cin >> s >> p;
      price.insert(make_pair(s,p));
    }
    int m;
    cin >> m;
    map<string,vector<string> > recipe;
    for(int i=0; i<m; i++){
      string goal;
      cin >> goal;
      int j;
      cin >> j;
      int sum = 0;
      for(int k=0; k<j; k++){
        string src;
        cin >> src;
        sum += price[src];
        recipe[src].push_back(goal);
      }
      if(sum < price[goal]){
        int diff = price[goal] - sum;
        price[goal] = sum;
        vector<string>::iterator it;
        for(it = recipe[goal].begin(); it != recipe[goal].end(); it++){
          price[*it] -= diff;
        }
      }
    }
    string target;
    cin >> target;
    cout << price[target] << endl;    
  }
  return 0;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int N = Convert.ToInt32(imp[0]);
            int A = Convert.ToInt32(imp[1]);
            int B = Convert.ToInt32(imp[2]);

            int maxmem = Math.Min(A, B);
            int minmem = (A + B) - N;

            if (minmem < 0)
            {
               minmem = 0;
            }
           
            Console.Write("{0} {1}", maxmem, minmem);
        }
    }
}

Measured memory_bytes: 13268
a,b=map(int,input().split())
ans=1

def factorization(n):
    arr = []
    temp = n
    for i in range(2,int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a_list=factorization(a)
b_list=factorization(b)

a_new=[a[0] for a in a_list]
b_new=[b[0] for b in b_list]

if a_new[0]==b_new[0]==1:
    ans=0

for i in a_new:
    if i in b_new:
        ans += 1

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
#define rep(i,n) for(ll i=0; i<(n); i++)
template<class T> inline void chmax(T &a, T b){if(a<b)a=b;}
template<class T> inline void chmin(T &a, T b){if(a>b)a=b;}
const ll inf=1LL<<60;
int main(){
    ll H,W,N,ans=0,f=0;
    cin>>H>>W>>N;
    vector<ll> x(N),y(N),z(N);
    vector<vector<ll>> v(H,vector<ll>(W,-inf));
    rep(k,N){
        cin>>x[k]>>y[k]>>z[k];
        x[k]--;y[k]--;
        rep(i,H)rep(j,W){
            chmax(v[i][j],z[k]-(labs(x[k]-i)+labs(y[k]-j)));
        }
    }
    rep(i,N){
        if(v[x[i]][y[i]]!=z[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    rep(i,H)rep(j,W){
        ans+=v[i][j];
        if(i)if(labs(v[i-1][j]-v[i][j])>1)f=1;
        if(j)if(labs(v[i][j-1]-v[i][j])>1)f=1;
        if(f){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;
}


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

bool ninit(int a, vector<int> p){
  for(int i=0;i<p.size();i++){
    if(p.at(i) == a){
      return false;
    }
  }
  return true;
}

int main(){
  int X, N;
  cin >> X >> N;
  vector<int> p(N);
  if(N==0) cout << X << endl;
  else{
    for(int i=0;i<N;i++){
      cin >> p.at(i);
    }

    for(int i=0;i<100;i++){
      if(ninit(X-i,p)){
	cout << X-i << endl;
	break;
      }
      if(ninit(X+i,p)){
	cout << X+i << endl;
	break;
      }
    }
  }
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

int main(){
	int n, m;
	std::priority_queue<long long> aList;

	std::cin>>n>>m;

	for(int i=0; i<n; i++){
		long long tmp;
		std::cin>>tmp;

		aList.push(tmp);
	}

	for(int i=0; i<m; i++){
		long long tmp= aList.top();
		aList.pop();

		aList.push(tmp/2);
	}

	long long ans=0;

	while(!aList.empty()){
		ans+= aList.top();
		aList.pop();
	}

	std::cout<<ans<<std::endl;

	return 0;
}


Measured memory_bytes: 1400
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            String S = reader.readLine();

            int MOD = 1000000007;

            long[][] count = new long[100001][13];

            count[0][0] = 1;

            for (int i = 1; i <= S.length(); i++) {
                char c = S.charAt(i - 1);

                if (c != '?') {
                    int j = c - '0';
                    for (int k = 0; k < 13; k++) {
                        count[i][(k * 10 + j) % 13] = count[i - 1][k];
                    }
                } else {
                    for (int j = 0; j < 10; j++) {
                        for (int k = 0; k < 13; k++) {
                            count[i][(k * 10 + j) % 13] += count[i - 1][k];
                        }
                    }

                    for (int k = 0; k < 13; k++) {
                        count[i][k] %= MOD;
                    }
                }
            }

            System.out.println(count[S.length()][5]);
        }
    }

}


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

int main(){
    ll n, m;
    cin >> n >> m;
    if(n == 1  &&  m == 1){
        cout << 1 << endl;
    }else if(n == 1  &&  m != 1){ 
        cout << m-2 << endl;
    }else if(n != 1  &&  m == 1){ 
        cout << n-2 << endl;
    }else{
        cout << (n-2)*(m-2) << endl;
    }
    return 0;
}

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

typedef long long int ll;

typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;

#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define Precision(i) cout << fixed << setprecision(i)

const double PI=3.14159265358979323846;
const int MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;

int main() {

  ll a,b,c,x,y;
  cin >> a >> b >> c >> x >> y;

  ll ans = INF;

  ans = min(ans,x*a+y*b);
  ans = min(ans,max(x,y)*2*c);

  if(x>y){
    ans = min(ans,y*2*c+(x-y)*a);
  }else{
    ans = min(ans,x*2*c+(y-x)*b);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift()-0;
   if(n==0)break;
   var str=n.toString(8)+"";
   str=str.replace(/7/g,"9");
   str=str.replace(/6/g,"8");
   str=str.replace(/5/g,"7");
   str=str.replace(/4/g,"5");
   console.log(str);
}

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

int main() {
  int N, A, B;
  scanf("%d%d%d", &N, &A, &B);

  int dist = abs(A - B) + 1;
  if (dist == 0 || dist % 2 != 0)
    printf("Alice");
  else
    printf("Borys");

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 1000000000

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

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

int abs(int a){
    if (a < 0)
        return -1*a;
    return a;
}

long long int dp[100009];

int main() {
    int n, W;
    int wt, val;
    scanf("%d %d", &n, &W);

    for (int i=0; i < n; i++) {
        scanf("%d %d", &wt, &val);

        for (int cur_wt=W-wt; cur_wt >=0; cur_wt--) {
            dp[cur_wt+wt] = max(dp[cur_wt+wt], dp[cur_wt]+val);
        }
    }

    long long ans = 0;
    for (int i=0; i <= W; i++)
        ans = max(ans, dp[i]);

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 2480
#include <iostream>

using namespace std;

int main() {
	int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	cout << h2 * 60 + m2 - (h1 * 60 + m1) - k << endl;

	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define st first
#define nd second

using ll = long long ;
using namespace std;
using pii = pair<int,int>;
ll x;
void ch(int dif){
	ll want = x;
	ll val = 1LL;
	for(int i = 1;i <= 5; i++){
		val *= 1LL * dif;
	}
	//printf("val = %lld", val);
	want -= val;
	//printf("at %d want = %d\n", dif, want);
	if(want == 0){
		printf("0 %d", -dif);
		exit(0);	
	}
	if(want % (5 * dif) != 0){
		return;
	}
	want /= (5LL * dif);

	for(int i = 1; 1LL * i * i <= abs(want); i++){
		int need = (int) want;
		if(i == dif) continue;
		if(i * i - i * dif + dif * dif == 0) continue;
		//printf("at %d %d %d", i, need, need % i);
		if(abs(need) % i == 0){
			need /= i;
			if(need % abs(i - dif) != 0) continue;
			need /= (i - dif);
			//printf("here need = %d", need);
			if(need == i * i - i * dif + dif * dif){
				printf("%d %d", i, i - dif);
				exit(0);
			}
		}
	}

}
int main(){
	scanf("%lld", &x);
	for(int i = 1; 1LL * i * i <= x; i++){
		if(x % i == 0) ch(i);
	}


}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
long long int a[100005];
long long int n;
long long int dp[10000][10000][2];
long long int func(long long int i,long long int j,long long int turn)
{
	if(i>j)
	return 0;

	if(dp[i][j][turn])
	return dp[i][j][turn];
	if(turn==0)
	{
		if(i!=j)
		{
			dp[i][j][turn]=max(a[i]+func(i+1,j,1),a[j]+func(i,j-1,1));
		}
		else
		{
			dp[i][j][turn]=a[i]+func(i+1,j,1);
		}
	}
	if(turn==1)
	{
		if(i!=j)
		dp[i][j][turn]=min(-1*a[i]+func(i+1,j,0),-1*a[j]+func(i,j-1,0));
		else
		{
			dp[i][j][turn]=-1*a[i]+func(i+1,j,0);
		}
		
	}
	return dp[i][j][turn];

}


 int main()
{
long long int t=1;
	;
	while(t--)
	{
	cin>>n;
for(long long int i=01;i<=n;i++)
cin>>a[i];
		cout<<func(1,n,0);
	}
}

Measured memory_bytes: 470016
#include <iostream>
#include <cstdio>
#define N 55
using namespace std;

typedef long long ll;
ll n, c, mx, mi, a[N];
int main()
{
	ll i, t;
	cin >> n;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	while (1) {
		mx = mi = n;
		for (i = 0; i < n; i++) if (a[i] >= mx) mi = i, mx = a[i];
		if (mi == n) break;
		t = (a[mi] - n - 1) / n + 1;
		c += t;
		a[mi] -= t * n;
		for (i = 0; i < n; i++) if (i != mi) a[i] += t;
	}
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.PriorityQueue;
import java.util.Scanner;

class Stuff implements Comparable<Stuff> {
    int v;
    int w;
    double performance;

    Stuff(int v, int w) {
        this.v = v;
        this.w = w;
        performance = 1.0 * v / w;
    }

    public int compareTo(Stuff s) {
        if(performance < s.performance) return 1;
        if(performance > s.performance) return -1;
        return 0;
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
 
        int n = sc.nextInt();
        int w = sc.nextInt();
        PriorityQueue<Stuff> que = new PriorityQueue<>();
        for(int i = 0; i < n; i++) {
            int vi = sc.nextInt();
            int wi = sc.nextInt();
            que.add(new Stuff(vi, wi));
        }

        double res = 0;
        while(w > 0 && !que.isEmpty()) {
            Stuff s = que.poll();
            if(w >= s.w) {
                res += s.v;
                w -= s.w;
            }else {
                res += s.performance * w;
                w = 0;
            }
        }

        System.out.println(BigDecimal.valueOf(res).toPlainString());
 
        sc.close();
    }
}


Measured memory_bytes: 104744
#include<iostream>
using namespace std;
int main()
{
	long int p,n,sum=0;
   long 	int a[n], b[n];
   cin>>p>>n;
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
}
	//cout<<endl;
	for(int i=0;i<n;i++)
	{
		if(i==n-1)
		b[i]=p+a[0]-a[i];
		else
		b[i]=a[i+1]-a[i];
		
		sum=sum+b[i];
	//	cout<<b[i]<<" ";
		
	}
	long int min=sum-b[0];
	for(int i=1;i<n;i++)
	{
		if(sum-b[i]<min)
		min=sum-b[i];
	}
	cout<<min;
	return 0;
}

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


int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    
    vector<ll> A(X), B(Y), C(Z);
    
    for (int i=0; i<X; i++) {
        cin >> A[i];
    }
    for (int i=0; i<Y; i++) {
        cin >> B[i];
    }
    for (int i=0; i<Z; i++) {
        cin >> C[i];
    }
    
    vector<ll> AplB, sum_ABC;
    
    for (int i=0; i<X; i++) {
        for (int j=0; j<Y; j++) {
            AplB.push_back(A[i] + B[j]);
        }
    }
    
    sort(AplB.begin(), AplB.end(), greater<ll>());
    
    for (int i=0; i<min(K, X*Y); i++) {
        for (int j=0; j<Z; j++) {
            sum_ABC.push_back(AplB[i] + C[j]);
        }
    }
    
    sort(sum_ABC.begin(), sum_ABC.end(), greater<ll>());
    
    for (int i=0; i<K; i++) cout << sum_ABC[i] << endl;
    
}

Measured memory_bytes: 43240
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DSumOfDivisors {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        lint ans = 0;
        RREP(i, N){
            lint k = N / i;
            ans += k * (k+1) / 2 * i;
        }
        out<<ans<<'\n';
    }
};


int main() {
	DSumOfDivisors solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3620
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

// ALDS1_5_B
public class Main {
	int SENTINEL = 1234567890;
	int sum = 0;
	void merge(int[]A, int left, int mid, int right) {
		int n1 = mid - left + 1;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for (int i = 0; i <= n1; i++) {
			L[i] = A[left + i];
		}
		for (int i = 0; i < n2; i++) {
			R[i] = A[mid + 1 + i];
		}
		L[n1] = SENTINEL;
		R[n2] = SENTINEL;
		int i = 0;
		int j = 0;
		for (int k = left; k <= right; k++) {
			sum += 1;
			if (L[i] <= R[j]) {
				A[k] = L[i];
				i = i + 1;
			} else {
				A[k] = R[j];
				j = j + 1;
			}
	    }
	}

	void mergeSort(int[] A, int left, int right) {
	    	if (left < right) {
	    		int mid = (left + right)/2;
	    		mergeSort(A, left, mid);
	    		mergeSort(A, mid + 1, right);
	    		merge(A, left, mid, right);
	  	}
	}
	    
	    
	void run() throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] S = new int[n];
		String[] str = br.readLine().split(" ");
		for (int i = 0; i < str.length; i++) {
			S[i] = Integer.parseInt(str[i]);
		}
		mergeSort(S, 0, n - 1);
		for (int i = 0; i < S.length; i++) {
    			if (i == S.length - 1) System.out.println(S[i]);
    			else System.out.print(S[i] + " ");
		}
		System.out.println(sum);
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
}



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

int N = 10, A[11];


signed main()
{
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A, A + N);
    for(int i = N - 1; i >= N - 3; i--){
        cout << A[i] << endl;
    }

    return 0;
}



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

int main()
{
char S;
int sum=700;
for(int i=0;i<3;i++)
{ cin>>S;
    if(S=='o')
    {
        sum=sum+100;
    }
}
cout<<sum<<endl;
    
    return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a;
  string s;
  vector<string> vec;
  cin>>a;
  for(int i=0; i<a; i++){
    cin>>s;
    vec.push_back(s);
  }

  sort(vec.begin(),vec.end());
  vec.erase(unique(vec.begin(),vec.end()),vec.end());

  cout<<vec.size()<<'\n';
  return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod (ll)(1e9 +7);

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}

int main()
{
    ll l,r;
    cin >> l >> r;

    if(r - l >= 2019){
        cout << 0 << endl;
        //cout << " 000 " << endl;
        return 0;
    }

    ll ans = 2018;
    REP(i,l,r){
        REP(j,i+1,r+1){
            ll ti = i % 2019;
            ll tj = j % 2019;
            ans = min(ans,(ti*tj) % 2019);
            if(ans == 0){
                cout << 0 << endl;
                //cout << " 111 " << endl; 
                //cout << i << " " << j << " " << i*j << endl;
                return 0;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
main()
{
	int n, i, f, j, s, k, x;
	char a[110][12];
	scanf("%d\n", &n);
	for (i=0, f=0; i<n; i++)
	{
		scanf("%s", &a[i]);
		if (i>0 && f==0)
		{
			if (a[i][0]!=a[i-1][s-1])
			{
				f=1;
			}
			else
			{
			for (j=0; j<i; j++)
			{
				if (strlen(a[i])==strlen(a[j]))
				{
					for (k=0, x=0; k<strlen(a[i]); k++)
					{
						if (a[i][k]!=a[j][k])
						{
							x=1;
							break;
						}
					}
					if (x==0)
					{
						f=1;
					}
				}
			}
			}
		}
		s=strlen(a[i]);
	}
	if (f==0)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
void Yes(bool c) { if (c)print("Yes"); else print("No"); };
void YES(bool c) { if (c)print("YES"); else print("NO"); };

void solve() {
    char b;
    cin >> b;
    char x;
    if(b=='A') x = 'T';
    else if(b=='T') x = 'A';
    else if(b=='G') x = 'C';
    else x = 'G';
    print(x);
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main() {

int a,b,c,d; cin>>a>>b>>c>>d; 
  rep(i,999999){
    c-=b; if(c<=0){cout<<"Yes"<<endl;break;}
    a-=d; if(a<=0){cout<<"No"<<endl;break;}
  
  }
  
  
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String [] line=in.readLine().split(" ");
		int n = Integer.parseInt(line[0]);
		int l = Integer.parseInt(line[1]);
		ArrayList<String> listOfString = new ArrayList<>();

		for (int i = 0; i <n; i++) {
			listOfString.add(in.readLine());
		}
		
		Collections.sort(listOfString);
		StringBuilder result=new StringBuilder();
		listOfString.forEach(value->result.append(value));
		
		System.out.println(result);

	}
}


Measured memory_bytes: 27476
// Problem: A - Repeat ACL
// Contest: AtCoder - ACL Beginner Contest
// URL: https://atcoder.jp/contests/abl/tasks/abl_a
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define ll long long int
#define ii int
#define du double
#define jmp "\n"
#define vl vector<ll>
#define vvl vector<vl>
#define pb push_back
#define printv(v)     \
  for (auto x : v)    \
    cout << x << " "; \
  cout << jmp;
#define vi vector<int>
#define vb vector<bool>
#define ump unordered_map
#define SORT(v) sort(v.begin(), v.end())
#define REV(x) reverse(x.begin(), x.end())
#define all(x) x.begin(), x.end()
#define SET(x, a) memset(x, a, sizeof(x))
#define si(x) x.size()
#define ff first
#define ss second
#define iin insert
#define deb(x) cout << "test " << #x << "=" << x << jmp
#define deb2(x, y) cout << "test " << #x << "=" << x << "," << #y << "=" << y << jmp
using namespace std;
const ll nax = 1e5 + 5;
void solve()
{
	ll n;
	string s1="",s="ACL";
	cin>>n;
	while(n--)
	s1+=s;
	cout<<s1;
}
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll t = 1;
  // cin >> t;
  while (t--)
    solve();
  return 0;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int mod = 1000000007;
const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int cul(int n){
    vector<int> ar(10,0);
    int re = 0;
    rep(i,10){
        ar[i] = n % 10;
        n /= 10;
        re += ar[i];
    }
    return re;
}

int main() {
    int n; cin >> n;
    int ans = 0;
    if (n % cul(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

map<int, int> have;
int n, m;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        int x;
        scanf("%d", &x);
        have[x]++;
    }
    scanf("%d", &m);
    for (int i = 0; i < m; i++)
    {
        int x;
        scanf("%d", &x);
        have[x]--;
        if (have[x] < 0) 
        {
            printf("NO\n");
            return 0;
        }
    }
    printf("YES\n");
    return 0;
}

Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define inf 1145141919364364
#define double long double
using namespace std;
typedef pair<ll, ll>P;
ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
signed main() {
	ll n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	ggr
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  int ans = 0;
  REP(i, n) {
    int a; cin >> a;
    while (a % 2 == 0) {
      ++ans;
      a /= 2;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
#include <vector>
#include <set>
#include <queue>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <map>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

using namespace std;
// using namespace __gnu_pbds;
 
#define F first
#define S second
#define ll long long
#define pb push_back
#define ppb pop_back
#define pii pair<int, int>
#define piii pair<int, pii>
#define __ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define watch(x) cout << (#x) << " is " << (x) << endl
//#define int long long
// #define ld long double
 

const int N = 1e5 + 20, mod = 1e9 + 7, inf = 2e9 + 9;
const ll INF = 1e18 + 20;

int n, k, dp[N], h[N];

signed main() { __
    // freopen("a.in", "r", stdin);
    // freopen("a.out", "w", stdout);
    cin>>n>>k;
    for(int i = 1; i <= n; i++) {
        cin>>h[i];
    }
    for(int i = 2; i <= n; i++) {
        dp[i] = inf;
        for(int j = 1; j <= k; j++) {
            if(i - j < 1) break;
            dp[i] = min(dp[i], dp[i - j] + abs(h[i - j] - h[i]));
        }
//        cout<<dp[i];
//        break;
    }
    cout<<dp[n];
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
int main(void)
{
    int h, w;
    char a[110][110] = {'#'};

    cin >> h >> w;

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i <= w+1; i++) {
        a[0][i] = '#';
        a[h+1][i] = '#';
    }

    for (int i = 0; i <= h+1; i++) {
        a[i][0] = '#';
        a[i][w+1] = '#';
    }

    for (int i = 0; i <= h+1; i++) {
        for (int j = 0; j <= w+1; j++) {
            cout << a[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Windows;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    public class Program
    {
        static void Main(string[] args)
        {
            var n = Read();
            var ans = string.Empty;
            var str = n.Last().ToString().Int();
            if (str == 2
                || str == 4
                || str == 5
                || str == 7
                || str == 9)
            {
                ans = "hon";
            }
            if (str == 0
                || str == 1
                || str == 6
                || str == 8)
            {
                ans = "pon";
            }

            if (str == 3)
            {
                ans = "bon";
            }

            WriteRead(ans);
        }
        
        public static string Read()
        {
            return Console.ReadLine();
        }

        public static string[] ReadSplit()
        {
            return Console.ReadLine().Split(' ');
        }

        public static void WriteRead(object str)
        {
            Console.WriteLine(str);
            Read();
        }

        public static void Write(object str)
        {
            Console.WriteLine(str);
        }

        private static bool ChangeMin<T>(ref T a, T b) where T : IComparable
        {
            if (a.CompareTo(b) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }

        private static bool ChangekMax<T>(ref T a, T b) where T : IComparable
        {
            if (b.CompareTo(a) > 0)
            {
                a = b;
                return true;
            }
            return false;
        }
    }
}


public static class Extentions
{
    public static int Int(this object obj)
    {
        return int.Parse(obj.ToString());
    }

    public static long Long(this object obj)
    {
        return long.Parse(obj.ToString());
    }

    public static decimal Decimal(this object obj)
    {
        return decimal.Parse(obj.ToString());
    }

    public static double Double(this object obj)
    {
        return double.Parse(obj.ToString());
    }

    public static T2 GetValueZero<T1, T2>(this Dictionary<T1, T2> d, T1 key) where T2 : struct
    {
        T2 value;
        if (d.TryGetValue(key, out value))
        {
            return value;
        }
        return new T2();
    }
}



Measured memory_bytes: 18652
#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;
ll MOD = 1e9+7;


int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    vector<int> n(4);
    REP(i, 4){
        cin >> n[i];
    }
    sort(n.begin(), n.end());
    if(n[0] == 1 && n[1] == 4 && n[2] == 7 && n[3] == 9){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

string s[8];

int check( int i , int j ){

  if( i + 1 < 8 && j + 1 < 8 ){
    if( s[i][j+1] == '1' && s[i+1][j+1] == '1' && s[i+1][j] == '1' ){
      return 1;
    }
  }
  if( i + 3 < 8 ){
    if( s[i+1][j] == '1' && s[i+2][j] == '1' && s[i+3][j] == '1' ){
      return 2;
    }
  }
  if( j + 3 < 8 ){
    if( s[i][j+1] == '1' && s[i][j+2] == '1' && s[i][j+3] == '1' ){
      return 3;
    }
  }
 if( j - 1 >= 0 && i + 2 < 8 ){
    if( s[i+1][j] == '1' && s[i+1][j-1] == '1' && s[i+2][j-1] == '1' ){
      return 4;
    }
  }
 if( j + 2 < 8 && i + 1 < 8 ){
    if( s[i][j+1] == '1' && s[i+1][j+1] == '1' && s[i+1][j+2] == '1' ){
      return 5;
    }
  }
  if( j + 1 < 8 && i + 2 < 8 ){
    if( s[i+1][j] == '1' && s[i+1][j+1] == '1' && s[i+2][j+1] == '1' ){
      return 6;
    }
  }
  return 7;
}

int main(void){
  
  while( cin >> s[0] ){

    for( int i = 1 ; i < 8 ; i++ ){
	cin >> s[i];
    }

    for( int i = 0 ; i < 8 ; i++ ){
      for( int j = 0 ; j < 8 ; j++ ){
	if( s[i][j] == '1' ){
	  //  cout << i << j << "---" <<  endl;
	  switch( check( i , j ) ){
	  case 1:
	    cout << "A" << endl;
	    break;
	  case 2:
	    cout << "B" << endl;
	    break;
	  case 3:
	    cout << "C" << endl;
	    break;
	  case 4:
	    cout << "D" << endl;
	    break;
	  case 5:
	    cout << "E" << endl;
	    break;
	  case 6:
	    cout << "F" << endl;
	    break;
	  case 7:
	    cout << "G" << endl;
	    break;
	  }
	  goto end;
	}
      }
    }
   end:;
  }
  return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
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; }

int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >>m;
    vector<vector<int>> vec(m);
    for (int i = 0; i < m; ++i) {
        int k; cin >> k;
        vec[i].resize(k);
        for (int j = 0; j < k; ++j) {
            cin >> vec[i][j];
            --vec[i][j];
        }
    }
    vector<int> p(m);
    for (int i = 0; i < m; ++i) {
        cin >> p[i];
    }
    int ans = 0;
    for (int bit = 0; bit < (1 << n); bit++) {
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            int count = 0;
            for (int id = 0; id < vec[j].size(); ++id) {
                int temp = vec[j][id];
                if ((bit >> temp) & 1) count++;
            }
            if (count % 2 != p[j]) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << 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 out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()

using pii=pair<int,int>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvc=vector<vector<char>>;
using ti3=tuple<int,int,int>;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }

struct pos {
  int lx,ly,rx,ry;
  pos(int lx,int ly,int rx,int ry):lx(lx),rx(rx),ly(ly),ry(ry){};
};


bool used[51][51][51][51];
bool bfs(int w, int h){
  vvc roomL(h,vector<char>(w)),roomR(h,vector<char>(w));
  rep(i,51)rep(j,51)rep(k,51)rep(l,51) used[i][j][k][l]=false;
  auto s=pos(0,0,0,0);
  rep(i,h){
    rep(j,w) {cin>>roomL[i][j];if(roomL[i][j]=='L'){s.lx=j;s.ly=i;}}
    rep(j,w) {cin>>roomR[i][j];if(roomR[i][j]=='R'){s.rx=j;s.ry=i;}}
  }

  queue<pos> Q;
  Q.push(s);

  pii dx[4]{pii(1,-1),pii(-1,1),pii(0,0),pii(0,0)};
  pii dy[4]{pii(0,0), pii(0,0) ,pii(1,1),pii(-1,-1)};

  while(!Q.empty()){
    int lx,ly,rx,ry;
    auto src=Q.front();Q.pop();
    lx=src.lx;rx=src.rx;ly=src.ly;ry=src.ry;

    for (int i = 0; i < 4; ++i) {
      int LX,LY,RX,RY;
      LX=lx+dx[i].first;
      RX=rx+dx[i].second;
      LY=ly+dy[i].first;
      RY=ry+dy[i].second;

      if(LX<0||LX>=w) LX=lx;
      if(RX<0||RX>=w) RX=rx;
      if(LY<0||LY>=h) LY=ly;
      if(RY<0||RY>=h) RY=ry;
      if(roomR[RY][RX]=='#') RY=ry,RX=rx;
      if(roomL[LY][LX]=='#') LY=ly,LX=lx;

      
      if(roomR[RY][RX]=='%'&&roomL[LY][LX]=='%') return true;
      if(roomR[RY][RX]=='%') continue;
      if(roomL[LY][LX]=='%') continue;
      
      if(!used[LX][LY][RX][RY])Q.push(pos(LX,LY,RX,RY)),used[LX][LY][RX][RY]=true;
    }
  }
  return false;

}

int main(){
  int W,H;
  while(cin>>W>>H,(W|H)){
    cout << (bfs(W,H)?"Yes":"No") << endl;
  }
}



Measured memory_bytes: 10496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++)
        cin>>p[i];
    sort(p,p+n);
    int sum=0,j=0;
    for(int i=0;i<k;i++)
    {
        sum=sum+p[j];
        j++;
    }
    cout<<sum;

   }


Measured memory_bytes: 3620
#include <cstdio>
#include <algorithm>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define int long long

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int int
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
        while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
        return x * f ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

#define N 200010

int n;
int a[N] ; ll ans = 0;

signed main() {
	n = read() ; ll now = 0 ;
	for(int i = 1; i <= n; i ++) a[i] = read() ;
	for(int l = 1 , r = 1 ; l <= n; ) {
		while((now ^ a[r]) == (now + a[r]) && r <= n) {
			now ^= (ll)a[r ++] ;
		}
		ans += (ll)(r - l) ;
		now ^= (ll)a[l ++] ;
	}
	outn(ans) ;
	return 0 ;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

#ifdef _DEBUG
#define dump(x) cout << #x << " = " << (x) << "\n"
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n"
#else
#define dump(x)
#define debug(x)
#endif


int main() {
#ifdef _DEBUG
	printf( "Debug Mode\n" );
#endif
	for ( int i = 1; i < 10; i++ ) {
		for ( int j = 1; j < 10; j++ ) {
			dump( i );
			dump( j );
			printf( "%dx%d=%d\n", i, j, i * j );
		}
	}
	return 0;
}

Measured memory_bytes: 1096
# 2019/09/17

s=list(input())
n=len(s)
k=int(input())

cnta=0
min_l=10000

for i in range(n):
    cnt=123-ord(s[i])
    if cnt>k:continue
    if s[i]=='a':
        cnta+=1
        continue
    s[i]='a'
    k-=cnt
    if k==0:break
else:
    last=s[-1]
    while cnta>=0:
        tmp=ord(last)-97
        kk=(k-cnta*26)%26
        
        min_l=min(min_l,(tmp+kk)%26)
        cnta-=1
    else:
        s[-1]=chr(min_l+97)
        
print(''.join(s))

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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)


int main() {
	cin.sync_with_stdio(false);
	ll N, M;
	cin >> N >> M;
	if (abs(N - M) >= 2) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 1;
	ll x = 1000000000 + 7;
	if (N == M) {
		reps(i, 1, N + 1) {
			ans *= i;
			ans %= x;
		}
		reps(i, 1, M + 1) {
			ans *= i;
			ans %= x;
		}
		ans *= 2;
		ans %= x;
	}
	else {
		reps(i, 1, N + 1) {
			ans *= i;
			ans %= x;
		}
		reps(i, 1, M + 1) {
			ans *= i;
			ans %= x;
		}
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;

bool arr[1010];

int main(){
  int N,M,c,d;
  cin >> N >> M;
  for(int i = 0 ; i < M ; i++){
    cin >> c >> d;
    for(int j = c ; j < d ; j++){
      arr[j] = true;
    }
  }
  cout << N+2*count(arr,arr+N,1)+1 << endl;
  return 0;
}

Measured memory_bytes: 1164
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
  long int N, K;
  long int sum = 0;
  long int sub = 0;
  long int i;
  
  cin >> N >> K;

  long int* H = new long int[N];

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

  if(K == 0){
    cout << sum << endl;
  }
  else if(K >= N){
    cout << 0 << endl;
  }
  else{
    sort(H, H + N, greater<long int>());
    
    for(i = 0; i < K; i++){
      sub += H[i];
    }
    
    cout << sum - sub << endl;
  }

  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int top,S[1000];
void push(int x){
  top++;
  S[top]=x;
}
int pop(){
  top--;
  return S[top+1];
}
int main(){
  int catch[2],i=0;
  char c[100];
  top=0;
  while(1){
    if(scanf("%s",c)==EOF)break;
    else{
    if(c[0]=='+'){
      catch[0]=pop();
      catch[1]=pop();
      push(catch[0]+catch[1]);
    }
    else if(c[0]=='-'){
       catch[0]=pop();
      catch[1]=pop();
      push(catch[1]-catch[0]);
    }
    else if(c[0]=='*'){
       catch[0]=pop();
      catch[1]=pop();
      push(catch[0]*catch[1]);
    }
    else{
      push(atoi(c));
    }
  }
  }
  printf("%d\n",pop());   



}



Measured memory_bytes: 2128