akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#define ll long long
using namespace std;

ll a[300000], mx[300000][2], ans[300000];

int main() {
	int N;
	cin >> N;
	int m=(1<<N);
	vector<vector<int>> v(N+1);
	for(int i=0; i<m; ++i){
		cin >> a[i];
		int cnt=0;
		for(int j=0; j<N; ++j){
			if(i&(1<<j)) ++cnt;
		}
		v[cnt].push_back(i);
	}
	for(int i=0; i<v[1].size(); ++i){
		if(a[v[1][i]]<a[0]) mx[v[1][i]][1]=v[1][i];
		else mx[v[1][i]][0]=v[1][i];
	}
	for(int i=2; i<=N; ++i){
		for(int j=0; j<v[i].size(); ++j){
			if(a[v[i][j]]<a[0]) mx[v[i][j]][1]=v[i][j];
			else mx[v[i][j]][0]=v[i][j];
			for(int k=0; k<N; ++k){
				if((v[i][j])&(1<<k)){
					int g=v[i][j]-(1<<k);
					for(int p=0; p<2; ++p){
						if(a[mx[g][p]]>a[mx[v[i][j]][0]]){
							mx[v[i][j]][1]=mx[v[i][j]][0];
							mx[v[i][j]][0]=mx[g][p];
						}
						else if(mx[g][p]!=mx[v[i][j]][0] && a[mx[g][p]]>a[mx[v[i][j]][1]]){
							mx[v[i][j]][1]=mx[g][p];
						}
					}
				}
			}
		}
	}
	for(int i=1; i<m; ++i){
		ans[i]=max(ans[i-1], a[mx[i][0]]+a[mx[i][1]]);
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 13428
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()
#define INF ((int)1e9)
using namespace std;

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

bool AllPass(vector<int> x, int cand){
	int n = (int)x.size();
	rep (i, n){
		if (x[i] % cand != 0){
			return false;
		} // end if
	} // end rep
	return true;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, X; cin >> N >> X;
	vector<int> x(N, 0);
	rep (i, N){
		cin >> x[i];
	} // end rep

	rep (i, N){
		x[i] = abs(x[i] - X);
	} // end rep

	sort(ALL(x));
	x.erase(unique(ALL(x)), x.end());

	int res = x[0];
	for (int i = 1; i < (int)x.size(); ++i){
		res = __gcd(res, x[i]);
	} // end for

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 640
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include "bits/stdc++.h"
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 5010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int a, b;

int gcd(int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> a >> b;
    cout << (ll) a * b / gcd(a, b);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;


int main(){
    
    int t, h, m, s;

    cin >> t;

    h = t / 3600;

    t -= h*3600;

    m = t/60;

    t -= m*60;

    s = t;

    cout << h << ":" << m << ":" << s << endl;

    return 0;
}




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

using namespace std;

int N;

int main(){
    cin >> N;

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

    //各部分増加列の最大値を格納

    vector<int> l;
    l.push_back(A[N-1]);
    for(int i=N-2 ; i>=0; i--){

        //一番でかいやつ以上なら、新たに部分草加列を作成
        if(A[i] >= l[l.size()-1]){
            l.push_back(A[i]);
            continue;
        }else if(A[i] < l[0]){
            l[0] = A[i];
            continue;
        }

        //追加可能な中で一番最小値の小さい部分増加列に追加
        auto it = upper_bound(l.begin(), l.end(), A[i]);
        *it = A[i];
    }

    cout << l.size();

    return 0;
}

Measured memory_bytes: 1276
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = MAP()
p = LIST()

tree = UnionFind(N)

for _ in range(M):
	x, y = MAP()
	tree.union(x-1, y-1)

ans = 0
for i, x in enumerate(p):
	if tree.same(i, x-1):
		ans += 1

print(ans)


Measured memory_bytes: 21732
//omajinai c++
#include <iostream>
#include<cmath>
#include<vector>
#include <algorithm>
#include <limits>
#include <numeric>
#include <type_traits>
#include <map>
#include <string>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define itn int
using ll = long long;
constexpr auto mod = 1000000007;
using namespace std;
int main() {
int aa,bb,m;
  cin>>aa>>bb>>m;
  vector<int> a(aa);
  vector<int> b(bb);
  rep(i,aa){
    cin>>a[i];
  }
  rep(i,bb){
    cin>>b[i];
  }
  int x,y,c;
  int mini=200000;
  rep(i,m){
    cin>>x>>y>>c;
    mini=min(mini,a[x-1]+b[y-1]-c);
  }
  int amin=*min_element(all(a));
  int bmin=*min_element(all(b));
  mini=min(mini,amin+bmin);
  cout<<mini;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=(1<<17)+5;
typedef long long ll;
typedef vector<pair<ll,ll> >VPI;
VPI vec[N],tmpl,tmpr,tmp,tmq,res;
vector<int>g[N];
int val[N],fa[N],n,flag;
ll mid;

void upd(VPI&a){
	VPI b;
	for(auto i:a){
		if(!b.empty()){
			if(b.back().first==i.first){
				if(b.back().second>i.second)b.pop_back();
				else continue;
			}
		}
		b.push_back(i);
	}
	a.swap(b);
}

void merge(VPI&a,VPI&b,VPI&c){
	reverse(b.begin(),b.end());
	upd(a);upd(b);
	int n=a.size(),m=b.size();
	c.resize(n+m);
	merge(a.begin(),a.end(),b.begin(),b.end(),c.begin());
	upd(c);a.clear();b.clear();
}

void dfs(int x){
	vec[x].clear();
	if(g[x].empty()){vec[x].emplace_back(0,0);return;}
	int l=g[x][0],r=g[x][1];
	dfs(l);dfs(r);
	for(auto i:vec[l])
		tmp.emplace_back(i.first+val[l],i.second+val[l]),
		tmq.emplace_back(i.second+val[l],i.first+val[l]);
	merge(tmp,tmq,tmpl);
	for(auto i:vec[r])
		tmp.emplace_back(i.first+val[r],i.second+val[r]),
		tmq.emplace_back(i.second+val[r],i.first+val[r]);
	merge(tmp,tmq,tmpr);
	int j=tmpr.size();--j;
	for(auto i:tmpl){
		for(;j>=0&&i.first+tmpr[j].first>mid;--j);
		if(j>=0){
			if(i.second<tmpr[j].second)tmq.emplace_back(i.second,tmpr[j].second);
			else tmp.emplace_back(tmpr[j].second,i.second);
		}
	}
	merge(tmp,tmq,res);
	for(auto i:res){
		assert(i.first<=i.second);
		if(!vec[x].empty()&&vec[x].back().second<=i.second)continue;
		vec[x].push_back(i);
	}
	if(vec[x].empty())flag=0;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=2;i<=n;++i){
		cin>>fa[i]>>val[i];
		g[fa[i]].push_back(i);
	}
	ll L=0,R=1e12;
	while(L<R){
		mid=(L+R)/2;flag=1;
		dfs(1);
		if(flag)R=mid;
		else L=mid+1;
	}
	cout<<L<<'\n';
	return 0;
}


Measured memory_bytes: 26656
#include <stdio.h>

main(){
  int dtime[100][100];
  int dcost[100][100];
  int m, n, i, j, k, a, b, cost, time, t, p, q, r;

  while(1){
    scanf("%d %d", &n, &m);
    if(n==0 && m==0) break;

    for(i=0;i<m;i++){
      for(j=0;j<m;j++){
        if(i==j){
          dtime[i][j]=0;
          dcost[i][j]=0;
          continue;
        }
        dtime[i][j]=1000000;
        dcost[i][j]=1000000;
      }
    }

    for(i=0;i<n;i++){
      scanf("%d %d %d %d", &a, &b, &cost, &time);
      a--;
      b--;
      dtime[a][b]=dtime[b][a]=time;
      dcost[a][b]=dcost[b][a]=cost;
    }
    for(k=0;k<m;k++){
      for(i=0;i<m;i++){
        for(j=0;j<m;j++){
          if(dtime[i][j]>dtime[i][k]+dtime[k][j]){
            dtime[i][j]=dtime[i][k]+dtime[k][j];
          }
          if(dcost[i][j]>dcost[i][k]+dcost[k][j]){
            dcost[i][j]=dcost[i][k]+dcost[k][j];
          }
        }
      }
    }

    scanf("%d", &t);
    for(i=0;i<t;i++){
      scanf("%d %d %d", &p, &q, &r);
      p--;
      q--;
      if(r==0) printf("%d\n", dcost[p][q]);
      else if(r==1) printf("%d\n", dtime[p][q]);
    }
  }
  return 0;
}

Measured memory_bytes: 492
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S[] = sc.next().split("");
    String a = "1";
    String b = "0";
    int countA = 0;
    int countB = 0;
    for (String s : S) {
      if (s.equals(a)) {
        countA++;	
      }
      if (s.equals(b)) {
        countB++;
      }
      String t = a;
      a = b;
      b = t;
    }
    System.out.println(Math.min(countA,countB));
  }
}

Measured memory_bytes: 33112
#include<stdio.h>
int main(){
  int i,j,n,q;
  int cnt=0;

  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++) 
    scanf("%d",&T[i]);


  for(i=0;i<q;i++){ 
    for(j=0;j<n;j++){
      if(T[i]==S[j]){
	cnt++;
	break;
      }
    }
  }
  printf("%d\n",cnt);

  return 0;
} 



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

using namespace std;

const long long INF = (1ll << 61);

long long rec(long long x, long long A, long long B, long long C, long long D, map<long long, long long>& dp){
  if(dp.count(x)) return dp[x];
  if(x == 0) return 0;
  if(x == 1) return D;
  
  long long ret = INF;
  
  if(x <= ret / D) ret = x * D;
  
  ret = min(rec(x / 2, A, B, C, D, dp) + A + D * (x % 2), ret);
  ret = min(rec((x + 1) / 2, A, B, C, D, dp) + A + D * (2 - x % 2), ret);
  
  ret = min(rec(x / 3, A, B, C, D, dp) + B + D * (x % 3), ret);
  ret = min(rec((x + 2) / 3, A, B, C, D, dp) + B + D * (3 - x % 3), ret);
  
  ret = min(rec(x / 5, A, B, C, D, dp) + C + D * (x % 5), ret);
  ret = min(rec((x + 4) / 5, A, B, C, D, dp) + C + D * (5 - x % 5), ret);
  
  return dp[x] = ret;
}

int main(){
  int T;
  cin >> T;
  
  while(T--){
    long long N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    
    map<long long, long long> dp;
    
    cout << rec(N, A, B, C, D, dp) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 4328
class Data:
    def __init__(self):
        self.name = ""
        self.time = -1
    def printdata(self,sum):
        print(self.name,sum)
    def datain(self,name,time):
        self.name = name
        self.time = int(time)

def enqueue(Q,x):
    global tail
    Q[tail] = x
    if(tail+1 == n+1):
        tail = 0
    else:
        tail += 1

def dequeue():
    global head
    if(head+1 == n+1):
        head = 0
    else:
        head += 1

n,q = map(int,input().split())
A = [Data()]
head = 0
tail = n
sum = 0

for i in range(n):
    d = list(map(str,input().split()))
    A.append(Data())
    A[i].datain(d[0],d[1])
A.append(Data()) #要素数1追加

while(head != tail):
    if(A[head].time - q > 0):
        A[head].time -= q
        enqueue(A,A[head])
        dequeue()
        sum += q
    else:
        sum += A[head].time
        A[head].printdata(sum)
        dequeue()


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

#define pll pair<ll,ll>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define F first
#define S second
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define sz(a) int((a).size())
#define endl '\n' // remove for interactive

const int INF = 1e9;
const ll mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int diff(string a, string b)
{
    int ret = 0;
    int n = a.size();
    for(int i = 0; i < n; i++)
    {
        if(a[i] != b[i]) ret++;
    }
    return ret;
}

void solve()
{
    string s, t; cin>>s>>t;
    int n = s.size();
    int m = t.size();
    int ans = 1e9;
    REP(i, 0, n-1-(m-1))
    {
        ans = min(ans, diff(s.substr(i, m), t));
    }
    cout<<ans<<endl;
}

int main()
{
    // clock_t start, end;
    // start = clock();
    ios_base::sync_with_stdio(0); //cant use scanf, printf
    cin.tie(0);cout.tie(0); // no longer auto flush cout before each cin, remove for interactive
    int t = 1;
    // cin>>t;
    REP(i, 1, t)
    {
        solve();
        
    }
    // end = clock();
    // double time_taken = double(end - start) / double(CLOCKS_PER_SEC); 
    // watch(time_taken);
    ll x = INF; x++;
    return 0;
    
}



/*before sub
TEST: 0(1 by 1 too), 1, equal, -ve, bounds(random and ez)
ERR/WA: loop vars, out of bounds, endl, finish taking inputs, large doubles, larger INF, corr mod, t, early/late mod
RE: double dec, integer overflow(ll or 1LL mult)
*/





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

ll inf=9223372036854775806;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n;
	cin>>n;
	n/=3;
	cout<<n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vi l(q), r(q);
  rep(i, q) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  vi ac(n + 1, 0);
  rep(i, n - 1) {
    ac[i + 1] = ac[i];
    if(s[i] == 'A' && s[i + 1] == 'C') ac[i + 1]++;
  }
  rep(i, q) cout << ac[r[i]] - ac[l[i]] << endl;
}

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

int n,m;
int a=0x7fffffff,b;

int main(){
    cin>>n>>m;
    for(int x,y,i=0; i<m; ++i){
        cin>>x>>y;
        if(y<a) a=y;
        if(x>b) b=x;
    }
    cout<<max(0,a-b+1);
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
using namespace std;
int x[10][10];
int gen(int g[],int s,int n,int c[]){

}
main(){
    int n,m;
    scanf("%d %d",&n,&m);
    int arr[n];
    for(int i=0;i<n;i++){
        arr[i]=i+1;
    }
    for(int i=0;i<m;i++){
        int a,b;
        scanf("%d %d",&a,&b);
        x[a][b]=1;
        x[b][a]=1;
    }
    int co=0;
    do{
        int b=1;
        for(int i=0;i<n-1;i++){
            if(x[arr[i]][arr[i+1]]==0){
                b=0;
            }
        }
        co+=b;
    }while(next_permutation(arr+1,arr+n));
    printf("%d",co);
}


Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
  string s, t;
  cin >> s >> t;
  int size_s = s.size(), size_t = t.size();
  char itibu = t[size_t - 1];
  if (t == s + itibu) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main(){
    int N, L; cin >> N >> L;
    int sum=(2*L+N-1)*N/2;

    //絶対値minのやつ
    if(L<=0 && 0 <= L+N-1){
        cout << sum << endl;
    }
    else if( L>0 ){
        cout << sum-L << endl;
    }
    else{
        cout << sum-(L+N-1) << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        final int N = scan.nextInt();
        int[] A = new int[N];
        int[] B = new int[N];
        int[] C = new int[N];
        for(int i = 0; i < N; i++){
            A[i] = scan.nextInt();
        }
        for(int i = 0; i < N; i++){
            B[i] = scan.nextInt();
        }
        for(int i = 0; i < N - 1; i++){
            C[i] = scan.nextInt();
        }
        scan.close();
        int result = 0;
        for(int i = 0; i < N; i++){
            result += B[A[i] - 1];
            if(i != 0 && A[i - 1] + 1 == A[i] ){
                result += C[A[i - 1] - 1];
            }
        }

        System.out.println(result);
        
    }
    
}


Measured memory_bytes: 23124
#include <stdio.h>
#include <algorithm>
#define N 100001
using namespace std;

int read()
{
	char c;
	while((c = getchar()) < 48 || c > 57);
	int x = c - 48;
	while((c = getchar()) > 47 && c < 58) x = x * 10 + c - 48;
	return x;
}

int a[N];

int main()
{		
	int n, i, l[2] = {0}, j = 0, t = 0;
	
	n = read();
	for(i = 0; i < n; i++) a[i] = read();
	make_heap(a, a + n);
	for(i = n - 1; i >= 0; i--){
		pop_heap(a, a + i + 1);
		if(a[i] == t){
			l[j++] = t;
			t = 0;
			if(j == 2) break;
		}
		else t = a[i];
	}
	printf("%lld\n", (long long)l[0] * (long long)l[1]);	
			
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<queue>

using namespace std;

const int MAX = 10;
const int INF = (1<<25);
const int D_MAX = 7;

class Dice{

public:
  int top,bottom,north,south,west,east;

  Dice(){}
  Dice(int t, int b, int n, int s, int w, int e)
    :top(t),bottom(b),north(n),south(s),west(w),east(e){}

  void setDice(int t, int b, int n, int s, int w, int e){
    top = t; bottom = b, north = n; south = s, west = w; east = e;
  }

  void rotateNorth(){setDice(south,north,top,bottom,west,east);}
  void rotateSouth(){setDice(north,south,bottom,top,west,east);}
  void rotateEast(){setDice(west,east,north,south,bottom,top);}
  void rotateWest(){setDice(east,west,north,south,top,bottom);}
  void rotateCW(){setDice(top,bottom,west,east,south,north);}
  void rotateCCW(){setDice(top,bottom,east,west,north,south);}
};


struct State{
  int x,y,t;
  Dice d;
  State(){}
  State(int a, int b, int c, Dice dd):x(a),y(b),t(c),d(dd){}
  bool operator < (const State& s) const {return t>s.t;}
};

int M[MAX][MAX];
int T[MAX][MAX][D_MAX][D_MAX][D_MAX];
// T[i][j][k][l][m] := mininum cost to M[i][k] with Dice's top is k, south is l, east = m;
int w,h,sx,sy,gx,gy;
int dx[] = {0,1,0,-1};
int dy[] = {-1,0,1,0};
string dir = "NESW";

bool isInside(int x, int y){return 0<=x&&x<w&&0<=y&&y<h;}

void input(){
  for(int i = 0; i < h; i++)
    for(int j = 0; j < w; j++) cin >> M[i][j];
  cin >> sy >> sx >> gy >> gx;
}

void init(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      for(int k = 0; k < D_MAX; k++)
	for(int l = 0; l < D_MAX; l++)
	  for(int m = 0; m < D_MAX; m++) T[i][j][k][l][m] = INF;
}


void solve(){

  T[sy][sx][1][2][3];
  priority_queue<State> Q;
  Q.push(State(sx,sy,0,Dice(1,6,5,2,4,3)));

  while(!Q.empty()){
    State now = Q.top();
    Q.pop();

    if(now.t > T[now.y][now.x][now.d.top][now.d.south][now.d.east]) continue;

    for(int i = 0; i < 4; i++){
      State nex = now;
      nex.x += dx[i];
      nex.y += dy[i];
      if(dir[i] == 'N') nex.d.rotateNorth();
      if(dir[i] == 'S') nex.d.rotateSouth();
      if(dir[i] == 'E') nex.d.rotateEast();
      if(dir[i] == 'W') nex.d.rotateWest();

      if(isInside(nex.x,nex.y) && T[nex.y][nex.x][nex.d.top][nex.d.south][nex.d.east] > now.t+M[nex.y][nex.x]*nex.d.bottom){	
	T[nex.y][nex.x][nex.d.top][nex.d.south][nex.d.east] = now.t+M[nex.y][nex.x]*nex.d.bottom;
	nex.t += M[nex.y][nex.x]*nex.d.bottom;
	Q.push(nex);
      }
    }
  }

  int ans = INF;

  for(int i = 0; i < D_MAX; i++)
    for(int j = 0; j < D_MAX; j++)
      for(int k = 0; k < D_MAX; k++) ans = min(ans,T[gy][gx][i][j][k]);

  cout << ans << endl;
  
}

int main(){
  
  while(cin >> h >> w && h+w){
    init();
    input();
    solve();
  }
  return 0;
}

Measured memory_bytes: 1380
//このこーどはしゃくよーしています

using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split();
        int N = int.Parse(str[0]);
        long K = long.Parse(str[1]);
        long[] A = new long[N];
        long[] B = new long[N];
        string[] str2 = Console.ReadLine().Split();
        string[] str3 = Console.ReadLine().Split();
        for (var i = 0; i < N; i++)
        {
            A[i] = long.Parse(str2[i]);
            B[i] = long.Parse(str3[i]);
        }
        Array.Sort(A);
        Array.Sort(B);
        Array.Reverse(B);
        long min = 0;
        long max = long.MaxValue;
        while (min < max)
        {
            long m = (min + max) / 2;
            long s = 0;
            for (var i = 0; i < N; i++)
            {
                long t = m / B[i];
                if (A[i] > t)
                {
                    s += A[i] - t;
                }
            }
            if (s > K)
            {
                min = m + 1;
            }
            else
            {
                max = m;
            }
        }
        Console.WriteLine(min);
    }
}


Measured memory_bytes: 47216
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id,id1,id2,id3,id4,lim,from,to;
L A[Mx],B[Mx];
int main()
{
    scanf("%lld%lld",&n,&m);

    printf("%lld\n", (n*m));
    return 0;
}

/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3784
// Remeber Choose Compiler: GCC9
#include <bits/stdc++.h>

using namespace std;

// Debug Output Utility
#ifdef LOCAL
#define dbg(args...)             \
    do {                         \
        cout << #args << " -> "; \
        err(args);               \
    } while (0)
void err() { std::cout << std::endl; }
template <typename T, typename... Args>
void err(T a, Args... args) {
    std::cout << a << ' ';
    err(args...);
}
template <template <typename...> class T, typename t, typename... A>
void err(const T<t> &arg, const A &... args) {
    for (auto &v : arg)
        std::cout << v << ' ';
    err(args...);
}
#else
#define dbg(...)
#endif

// Macro Definitions:
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

// Type Alias:
using int64 = long long;
using PII   = pair<int, int>;

// Global Const Variable
const int64 INF = 0x3f3f3f3f3f3f3f3f;
const int MOD   = 1000000007;
const int MAXN  = 200005;

int a[MAXN];

void run() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i=0;i<n;i++) cin >> a[i], ans ^= a[i];
    for(int i=0;i<n;i++) {
        cout << (ans ^ a[i]) << " ";
    }
    cout << endl;
}

// Debug Input Redirection
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
#endif
    run();
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
typedef long long LL;

LL i, j, k;

void solve(LL n) {
    for (i = 1; i <= 3500; i++) {
        if (n/4 >= i) continue;
        for (j = i; j <= 3500; j++) {
            LL tmp1 = i+j;
            LL tmp2 = i*j;
            k = 4*tmp2 - n*tmp1;
            if (k > 0 && n*tmp2%k==0) {
                k = n*tmp2/k;
                return;
            }
        }
    }
}

int main() {
//    freopen("test.txt", "r", stdin);
    int n;
    cin >> n;
    solve(n);
    cout << i << ' ' << j << ' ' << k << endl;

    return 0;
}

Measured memory_bytes: 256
N=int(input())

words=[input() for _ in range(N)]

tmp=set(words)
#print(tmp)
c=1
if len(words)!=len(tmp):
    c=0
else:
    for i in range(N):
#        print(words)
        if i==0:
            continue
        elif words[i][0]!=words[i-1][-1]:
            c=0
            break


#print(c)
if c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include <cstddef>
#include<set>
#include<stack>
#include <deque>
#include<queue>
#include<utility>
#include<vector>
#include<map>
#include<cmath>
#include<cstring>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#define  ll  long long
#define ull unsigned long long
#define  sl(a)  scanf("%lld",&a)
#define  si(a)  scanf("%d",&a)
#define mem(n,m) memset(n,m,sizeof(n))
#define PI acos(-1)
#define pb    push_back
#define pf    push_front
#define vll   vector<ll>
#define pll   pair<ll,ll>
#define mp  make_pair
#define vpll vector< pair <ll,ll> >
#define vplpll vector<pair<ll,pair<ll,ll> > >
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S(X) ( (X) * (X) )
#define forab(i, a, b) for(i = a; i <= b; i++)
#define forn(i, n) for(i = 0; i < n; i++)
#define print(a,b) printf("Case %lld: %lld\n",a,b)
using namespace std;
ll powd(ll a,ll b){if(b==1){return a;}if(b%2==1){return powd(a,b-1)*a;}else{ll x=powd(a,b/2); return x*x;}}
ll powm(ll a,ll b,ll m){if(b==0){return 1;}if(b==1){return a%m;}if(b%2==1){return ((powm(a,b-1,m)%m)*(a%m))%m;}else{ll x=powm(a,b/2,m); return ((x%m)*(x%m))%m;}}
ll gcd(ll a,ll b){if(a==0){return b;}return gcd(b,a%b);}
ll a[200005];
int main()
{
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    ll p=1;
    for(ll i=k+1;i<=n;i++)
    {
        if(a[i]>a[i-k])
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

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

int main(void){
  string S;
  cin >> S;
  int ans=700;
  for(int i=0;i<3;i++){
      if(S.at(i) == 'o'){
          ans+=100;
      }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
#define N 60
int n,m,a,b,c,t;
int ans[N],s[N];
void mult(int C[N][N], int A[N][N], int B[N][N]){
  int tmp[N][N];
  for(int i=0;i<n;++i)
    for(int j=0;j<n;++j){
      tmp[i][j]=0;
      for(int k=0;k<n;++k)
	tmp[i][j]=(tmp[i][j]+A[i][k]*B[k][j])%m;
    }
  for(int i=0;i<n;++i)
    for(int j=0;j<n;++j) C[i][j]=tmp[i][j];
}

void solve(){
  int A[N][N],M[N][N];
  for(int i=0;i<n;++i)
    for(int j=0;j<n;++j) A[i][j] = 0, M[i][j]=(i==j);
  for(int i=0;i<n;++i) A[i][i] = b;
  for(int i=1;i<n;++i){
    A[i][i-1]=a;
    A[i-1][i]=c;
  }

  while(t){
    if(t&1)
      mult(M,M,A);
    mult(A,A,A);
    t/=2;
  }

  for(int i=0;i<n;++i){
    ans[i]=0;
    for(int j=0;j<n;++j)
      ans[i]=(ans[i]+M[i][j]*s[j])%m;
  }
}

int main(){
  while(cin>>n>>m>>a>>b>>c>>t,n||m||a||b||c||t){
    for(int i=0;i<n;++i) cin >> s[i];
    solve();
    for(int i=0;i<n-1;++i) cout << ans[i] << " ";
    cout << ans[n-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
import math
n = int(raw_input())
p = map(int,raw_input().split())
q = map(int,raw_input().split())
p_n = 0
q_n = 0
n_list = [i for i in range(1,n+1)]
f_list = [math.factorial(i) for i in range(n)]
f_list = f_list[::-1]
for a in range(n):
  p_n += n_list.index(p[a])*f_list[0]
  n_list.remove(p[a])
  f_list.pop(0)
  
n_list = [i for i in range(1,n+1)]
f_list = [math.factorial(i) for i in range(n)]
f_list = f_list[::-1]
for a in range(n):
  q_n += n_list.index(q[a])*f_list[0]
  n_list.remove(q[a])
  f_list.pop(0)
#print p_n,q_n
print abs(p_n - q_n)


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

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

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

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

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

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

signed main() {
  init();
  string a, b, c;
  cin >> a >> b >> c;
  string ans = {(char)toupper(a[0]), (char)toupper(b[0]), (char)toupper(c[0])};
  ANS;
  return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<algorithm> 
#include<cstdio>
#include<cctype>
#include<string>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<unordered_map>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int N = 105;
const double pi = acos(-1.0);
const ll mod = 998244353;
void init(){
	ios::sync_with_stdio(false);cin.tie(0);
} 
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
ll a[N];
ll quickpow(ll a,ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ans;
}

int main()
{
	int a1,b1,a2,b2;
	cin>>a1>>b1>>a2>>b2;
	int t1,t2;
	t1=(a2+b1-1)/b1;
	t2=(a1+b2-1)/b2;
	if(t1<=t2)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3592
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int i = (s.size() % 2 == 0 ? s.size() - 2 : s.size() - 1);
    for(; i != 0; i -= 2){
        if(s.substr(0, i/2) == s.substr(i/2, i/2)){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int N;
    cin >> N;
    ll A[N];
    REP(i, N) cin >> A[i];

    ll dpt[N], dpf[N];
    dpt[0] = (A[0] + A[1]) * -1;
    dpf[0] = (A[0] + A[1]);
    FOR(i, 1, N - 1) {
        dpt[i] = max(dpt[i - 1] - (-1 * A[i]) + A[i] + -1 * A[i + 1],
                     dpf[i - 1] - A[i] + -1 * A[i] + -1 * A[i + 1]);
        dpf[i] = max(dpt[i - 1] - (-1 * A[i]) + -1 * A[i] + A[i + 1],
                     dpf[i - 1] - A[i] + A[i] + A[i + 1]);
    }
    cout << max(dpt[N - 2], dpf[N - 2]) << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#include<bits/stdc++.h>
using namespace std;
typedef     long long    ll;
typedef     vector<int> vi;
typedef     vector<long long> vl;
typedef     pair<int, int>pi;
typedef     pair<long long, long long>pl;
#define F   first
#define S   second
#define pb  push_back
#define     all(x)      x.begin() , x.end()
#define mp  make_pair
#define       FOR(i,a,b) for(i=a;i<=b;i++)
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)
int main()
{

  int t;
  t = 1;
  //cin >> t;
  while (t--)
  {
    int n,i,c=0;
    cin>>n;
    string s;
    cin>>s;
    s+=(s[n-1]+1);
    for(i=0;i<s.size()-1;i++)
    {
       if(s[i]!=s[i+1])
       {
        c++;
       }
    }

   cout<<c<<endl;
  }
}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    int N, x;
    cin >> N >> x;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll n = 0;
    FOR(i, N, 1)
    {
        if (A[i] + A[i - 1] <= x)
            continue;
        ll t = (A[i] + A[i - 1]) - x;

        n += t;
        A[i] -= std::min(t, A[i]);
    }
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int n;
	cin >> n;

	vector<int> a(n);
	rep(i, n){
		cin >> a[i];
		a[i]--;
	}

	int ans = 0;
	vector<bool> used(n, false);
	rep(i, n){
		if(!used[a[i]] && a[a[i]] == i){
			used[i] = true;
			used[a[i]] = true;
			ans++;
		} 
	}

	cout << ans << endl;
}


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repd(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()

// output
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
  cout << a;
  ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
  cout << a << ' ';
}

int ans = 0;
bool check = 0;
string s, t;
int N = 3;
vector<int> v(N);
int a, b;
int x, y;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

int main()
{
  int y, m, d;
  char c1, c2;
  cin >> y >> c1 >> m >> c2 >> d;
  cout << (m <= 4 ? "Heisei" : "TBD") << endl;
}

Measured memory_bytes: 3560
//AtCoder ABC099 A - ABD
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;

int main() {
    ll N; cin>>N;
    if(N>=1000){
        cout<<"ABD"<<endl;
        N-=999;
    }else{
        cout<<"ABC"<<endl;
    }
    //std::cout << std::setfill('0') << std::right << std::setw(3) << N <<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[] arr = new int[n];

                for (int i = 0; i < n; i++)
                {
                    arr[i] = int.Parse(Console.ReadLine());
                }
                sb.AppendLine(Count(arr).ToString());
            }
            Console.Write(sb);
        }

        static int Count(int[] arr)
        {
            int ret = 0;
            bool flg = true;

            for (int i = 0; flg; i++)
            {
                flg = false;

                for (int j = arr.Length - 1; j > i; j--)
                {
                    if (arr[j] < arr[j - 1])
                    {
                        int temp = arr[j];
                        arr[j] = arr[j - 1];
                        arr[j - 1] = temp;

                        flg = true;
                        ret++;
                    }
                }
            }
            return ret;
        }
    }
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#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 rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


int main() {
  int n;
  cin >> n;
  cout << n * n * n << endl;

}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    k=int(input())
    score=0
    B=0

    from heapq import heappush,heappop
    q=[] # 小さいほうの最大をとる→マイナスにして入れる
    Q=[] # 大きいほうの最小をとる

    for _ in range(k):
        s=input()
        if(s[0]=='1'):
            s,a,b=map(int,s.split())
            heappush(q,-a)
            heappush(Q,a)
            B+=b
            # 大小関係が逆転しているかを判断する
            t=-q[0]; T=Q[0]
            if(t>T):
                score+=t-T
                heappop(q); heappop(Q)
                heappush(q,-T); heappush(Q,t)
        else:
            print(-q[0],score+B)
resolve()

Measured memory_bytes: 91992
// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
    std.range, std.container, std.bigint, std.ascii, std.typecons;

// }}}
// nep.scanner {{{
class Scanner
{
    import std.stdio : File, stdin;
    import std.conv : to;
    import std.array : split;
    import std.string : chomp;

    private File file;
    private char[][] str;
    private size_t idx;

    this(File file = stdin)
    {
        this.file = file;
        this.idx = 0;
    }

    private char[] next()
    {
        if (idx < str.length)
        {
            return str[idx++];
        }

        char[] s;
        while (s.length == 0)
        {
            s = file.readln.chomp.to!(char[]);
        }

        str = s.split;
        idx = 0;

        return str[idx++];
    }

    T next(T)()
    {
        return next.to!(T);
    }

    T[] nextArray(T)(size_t len)
    {
        T[] ret = new T[len];

        foreach (ref c; ret)
        {
            c = next!(T);
        }

        return ret;
    }

    void scan()()
    {
    }

    void scan(T, S...)(ref T x, ref S args)
    {
        x = next!(T);
        scan(args);
    }
}
// }}}

void main()
{
    auto cin = new Scanner;
    int a, b, x;
    cin.scan(a, b, x);
    if (a <= x && a + b >= x)
    {
        writeln("YES");
    }
    else
    {
        writeln("NO");
    }
}


Measured memory_bytes: 256
s = input()

ans = 0
cnt = 0

for i in range(len(s)):
    if s[i] == 'A' or s[i] == 'C' or s[i] == 'G' or s[i] == 'T':
        cnt += 1
    else:
        ans = max(ans, cnt)
        cnt = 0
        

        
ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define lepb(i,s,t) for(int i=(s);i>=(t);--i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll inff = 4557430888798830399ll;
const db eps = 1e-10;
const db pi = acos(-1.0);
const ll mod = 1e9+7;

int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int n,q,k,d,M,C;string s;ll S,Z;
	cin>>n>>s>>q;
	rep(i,0,q)
	{
		cin>>k;
		d=s.find_first_of('D');S=Z=M=C=0;
		if(d==-1){cout<<0<<endl;continue;}
		for(int i=d,j=d;i<sz(s);i++)
		{
			if(s[i]=='D')
			{
				for(;j-i<k&&j<sz(s);j++)
				{
					if(s[j]=='M')M+=1;
					if(s[j]=='C')Z+=M,C+=1;
				}
				S+=Z;
			}
			if(s[i]=='M')Z-=C,M-=1;
			if(s[i]=='C')C-=1;
		}
		cout<<S<<endl;
	}
}

Measured memory_bytes: 1948
#include<bits/stdc++.h>
using namespace std;
    static const double pi = 3.141592653589793;
 typedef pair<int64_t,int64_t> P;
#define rep(i, n) for (int i = 0; i < (n); i++)


int main(){
int64_t H,N;
  cin>>H>>N;
  int64_t damage[N];
int64_t cost[N];
  rep(i,N)  cin>>damage[i]>>cost[i];
int64_t dp[H+1];
  rep(i,H+1) dp[i]=5000000000;
  dp[0]=0;
  rep(j,H+1)
rep(i,N)
  {
  {
    if(damage[i]>=j) dp[j]=min(dp[j],cost[i]);
  else dp[j]=min(dp[j],dp[j-damage[i]]+cost[i]);
  }
  }
  cout<<dp[H];
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  ll n;
  cin >> n;
  ll l[2000];
  FOR(i,0,n-1) {
    scanf("%lld", &l[i]);
  }

  ll ans = 0;

  sort(l,l+n);

  FOR(i,0,n-3){
    FOR(j,i+1,n-2){
      FOR(k,j+1,n-1){
        if(l[i]+l[j]>l[k]) ++ans;
      }
    }
  }

  cout << ans << endl;

}



Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>

int main(){

char inputan[1000];
char inputanBaru[1000];
int count=0;
scanf("%s", inputan);
int len=strlen(inputan);
int l=0;
for(int j=0;j<len;j++){
    inputanBaru[l+1]='\0';
    inputanBaru[l]=inputan[j];
    if(inputanBaru[l]=='B'){
        if(!(inputanBaru[l-1]>=48 && inputanBaru[l-1]<=57)){
            continue;
        }
        inputanBaru[l-1]='\0';
        l--;
        continue;
    }
    l++;
}

printf("%s\n", inputanBaru);


    return 0;
}

Measured memory_bytes: 1600
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;


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

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int d1, d2;
		cin >> d1 >> d2;

		if (d1 == d2) {
			cnt++;
		}
		else {
			cnt = 0;
		}

		if (cnt == 3) {
			cout << "Yes" << endl;
			return 0;
		}
		
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3628