akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)

int main() {
  string S;
  ll K;
  cin >> S >> K;

  char result = '1';
  rep(i, 100) {
    if (i >= K) break;
    if (S[i] != '1') {
      result = S[i];
      break;
    }
  }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <cstdlib>
using ll = long long;
using namespace std;

int main(void){
	ll n,k;
	cin >> n >> k;
	ll t = n%k;
	ll ans = min(t,k-(t));
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, r;
    cin >> n >> r;
    cout << (n >= 10 ? r : r + 100 * (10 - n)) << endl;
}

Measured memory_bytes: 3628
S = input()
X,Y = S[0],S[2]
L = {"A":0,"B":1,"C":2,"D":3,"E":4,"F":5}
if L[X]<L[Y]:
    print("<")
elif L[X]>L[Y]:
    print(">")
elif L[X]==L[Y]:
    print("=")


Measured memory_bytes: 61708
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[i] == l[j] || l[j] == l[k] || l[k] == l[i]) continue;
                if(l[i] + l[j] <= l[k]) continue;
                if(l[i] + l[k] <= l[j]) continue;
                if(l[j] + l[k] <= l[i]) continue;
                if(abs(l[i] - l[j]) >= l[k]) continue;
                if(abs(l[i] - l[k]) >= l[j]) continue;
                if(abs(l[j] - l[k]) >= l[i]) continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
}


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

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

    int a0=0, a1=0;

    for(int i=0; i<s.size(); i++){
        if(s[i]=='0') {
            a0++;
        } else {
            a1++;
        }
    }

    cout << min(a0, a1) * 2 << endl;

    return 0;
}

Measured memory_bytes: 3752
import java.util.*;

public class Main{
    static int[] p = new int[1130];
    static int pnum;
    static int[][][] dp;

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

	calcPrimes();

	int n = sc.nextInt();
	int k = sc.nextInt();

	while(n!=0){

	    dp = new int[1121][15][188];
	    for(int i=0; i<=n; i++)
		for(int j=0; j<=k; j++)
		    for(int l=0; l<188; l++)dp[i][j][l] = -1;
	    System.out.println(solve(n,k,0));

	    n = sc.nextInt();
	    k = sc.nextInt();
	}
    }

    public static int solve(int n, int k, int idx){
	if(n==0 && k==0){return 1;}
	else if(n==0 || k==0){return 0;}
	if(dp[n][k][idx]>=0){return dp[n][k][idx];}
	
	int res = 0;
	for(int i=idx; i<pnum; i++){
	    if(p[i]>n){
		break;
	    }else{
		res += solve(n-p[i],k-1,i+1);
	    }
	}

	return dp[n][k][idx] = res;
    }

    public static void calcPrimes(){
	p[0] = 2;
	pnum = 1;
	for(int i=3; i<=1120; i+=2){
	    boolean add = true;
	    for(int j=0; j<pnum; j++){
		if(p[j]*p[j]>i){break;}
		if(i%p[j]==0){
		    add = false;
		    break;
		}
	    }
	    if(add){p[pnum++] = i;}
	}
    }
}

Measured memory_bytes: 58000
import sys
sys.setrecursionlimit(1000000)

N, M = map(int, input().split())
s = input()
G = [[] for _ in range(2 * N)]
for _ in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    if s[a] == s[b]:
        G[a].append(b + N)
        G[b].append(a + N)
    else:
        G[a + N].append(b)
        G[b + N].append(a)

status = [0] * (2 * N) #0 = 未訪問　1 = 訪問中 2 = 訪問済
def dfs(v):
    if status[v] == 1:
        print('Yes')
        exit()
    elif status[v] == 0:
        status[v] = 1
        for u in G[v]:
            dfs(u)
        status[v] = 2

for v in range(2 * N):
    dfs(v)
print('No')


Measured memory_bytes: 162436
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <functional>
#include <queue>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
const int INF = 100000000;

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

    int count = 0;
    for(int i = 0; i < (s.size())/2; i++){
        if(s[i] != s[s.size() - 1 - i]){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>

using namespace std;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)

long long t, n, m, u, v, q, k, s;
const int N = 2e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 57;

long long arr[N];
string str, ss;

int main() {
   csl;
   long long H, W, h, w;
   cin >> H >> W >> h >> w;
   if (H % h != 0 || W % w != 0) {
      cout << "Yes\n";
      for (int i = 1; i <= H; ++i) {
         for (int j = 1; j <= W; ++j) {
            if (i % h == 0 && j % w == 0) cout << (-h * w + 1) * 4000 - 1<< " ";
            else cout << 4000 << " ";
         }
         cout << '\n';
      }
   } else cout << "No\n";
   return 0;
}




























Measured memory_bytes: 1664
use std::io::{BufRead, BufReader};

fn main(){
    let n = read::<i32>()[0];
    let ans = n / 2 + n % 2;
    println!("{}",ans);
}

fn read<T>() -> Vec<T>
where
  T: std::str::FromStr,
  T::Err: std::fmt::Debug,
{
    let lines: Vec<T> =
        BufReader::new(std::io::stdin())
        .lines()
        .map(|l| l.unwrap().parse::<T>().unwrap())
        .collect();
    lines
}


Measured memory_bytes: 4476
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,ans,cost=100000;
  int c[1000],ta[1000];
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>c[i]>>ta[i];
    if(ta[i]<=t && c[i]<cost){
      cost=c[i];
    }
  }
  if(cost!=100000) cout<<cost<<endl;
  else cout<<"TLE"<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N,Y; cin >>N>>Y;
    REP(i,N+1)
    {
        LL remY = Y - 1e4 * i;
        LL remN =  N - i;
        if((remY - 1000 * remN) % 4000 == 0 && (remY - 1000 * remN) / 4000 <= remN && (remY - 1000*remN)/4000 >= 0)
        {
            cout << i << " " << (remY-1000*remN)/4000 <<" "<< remN-(remY-1000*remN)/4000 << endl;
            return 0;
        }
    }
    cout << "-1 -1 -1" << endl;

}

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

// Template Headers {{{
using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long; using vll = vector<long long>;
template <class T> using min_queue = priority_queue<T, vector<T>, greater<T>>;
template <class T> istream &operator>>(istream &, vector<T> &);
template <class T> ostream &operator<<(ostream &, const vector<T> &);
template <class T, class U> istream &operator>>(istream &, pair<T, U> &);
template <class T, class U> ostream &operator<<(ostream &, const pair<T, U> &);
template <class T> struct Inf { static constexpr T inf() { return std::numeric_limits<T>::has_infinity ? std::numeric_limits<T>::infinity() : std::numeric_limits<T>::max(); } };
template <> struct Inf<int> { static constexpr int inf() { return 0x3f3f3f3f; } };
template <> struct Inf<long long> { static constexpr long long inf() { return 0x3f3f3f3f3f3f3f3fLL; } };
constexpr int INF = Inf<int>::inf(); constexpr ll BINF = Inf<ll>::inf();
// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// }}}

int solve() {
	string s; cin >> s;
	cout << (s == "ABC" ? "ARC" : "ABC") << endl;
	return 0;
}

// Template Main {{{
int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	// precompute();
	// int t; cin >> t; for (int i=1;i<=t;i++)
	solve();
	// cout << "Case #" << i << ": ", solve();
	return 0;
}

template <class T> istream &operator>>(istream &is, vector<T> &v) {
	for (auto it=v.begin();it!=v.end();++it) is >> *it;
	return is;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
	for (auto it=v.begin();it!=v.end();) os << *it, os << " \n"[++it==v.end()];
	return os;
}

template <class T, class U> istream &operator>>(istream &is, pair<T, U> &p) {
	return is >> p.first >> p.second;
}

template <class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) {
	return os << p.first << ' ' << p.second;
}
// }}}

// vim: fdm=marker


Measured memory_bytes: 3644
import math
a,b,c = map(int,input().split())
d = list(map(int,input().split()))
ans = 0
for i in range(a):
    sum = c
    e = list(map(int,input().split()))
    for j in range(b):
        sum += e[j]*d[j]
    if sum>0:
        ans+=1

print(ans)

Measured memory_bytes: 62376
import sys
N = int(input())
H = list(map(int, input().split()))

for i in range(N-1,0,-1):
  if H[i-1] - H[i] > 1:
    print('No')
    sys.exit()
  elif H[i-1] > H[i]:
    H[i-1] -= 1
print('Yes')

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

const int N = 10;

vector<int> adj[N];

int n, m, ans = 0;
int vst[N];

void dfs(int i, int c = 1) {
  if (c == n) ans++;
  vst[i] = 1;
  for (auto &j : adj[i]) {
    if (!vst[j]) dfs(j, c + 1);
  }
  vst[i] = 0;
}

void solve() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) solve();
}


Measured memory_bytes: 3664
private fun readStrings() = readLine()!!.split(" ")
private fun readInts() = readStrings().map { it.toInt() }

fun canPaint(grid: List<String>, h: Int, w: Int): Boolean {
    for (height in 0 until h) {
        for (column in 0 until w) {
            val char = grid[height][column]
            if (char == '#') {
                val up   = grid.getOrNull(height - 1)?.getOrNull(column) == '#'
                val down = grid.getOrNull(height + 1)?.getOrNull(column) == '#'
                val left = grid.getOrNull(height)?.getOrNull(column - 1) == '#'
                val right= grid.getOrNull(height)?.getOrNull(column + 1) == '#'
                if (!(up || down || left || right)) {
                    return false
                }
            }
        }
    }
    return true
}

fun main(args: Array<String>) {
    val (H, W) = readInts()
    val s = (1 .. H).map { readLine()!! }

    println(if (canPaint(s, H, W)) "Yes" else "No")
}

Measured memory_bytes: 37984
n=int(raw_input())
a=map(int,raw_input().split())
invalid=1
for i in a:
    if(i%2==0):
        if(i%3==0 or i%5==0):
            pass
        else:
            invalid=0
            break
if(invalid==1):
    print "APPROVED"
else:
    print "DENIED"

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

using namespace std;

int main() {

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    while(A >= 0 || C >= 0) {
        C = C - B;
        if (C <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        A = A - D;
        if (A <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    unordered_map<ll,int>mp;
    ll n;cin >>n;
    for (int i = 0; i < n; ++i) {
        ll a;cin >>a;
        mp[a]++;
    }
    ll ans=0;
    for(auto p:mp){
        ans+=((p.second-p.first)<0)?p.second:p.second-p.first;
    }
    cout <<ans <<endl;
    return 0;
}


Measured memory_bytes: 7240
import           Data.List
import Control.Applicative

cost :: Int -> [Int] -> Int
cost k ts = f (length ts) k (filter (>0) $ intervals ts)
  where
    intervals []         = []
    intervals [t]        = []
    intervals (t1:t2:ts) = t2 - (t1 + 1) : intervals (t2:ts)
    f n k itvls | k >= (length itvls + 1) = n
                | otherwise = n + sum (take (length itvls + 1 - k) (sort itvls))

main = do
  [n, k] <- fmap read . words <$> getLine
  ts <- fmap read . lines <$> getContents
  print $ cost k ts



Measured memory_bytes: 27676
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include <cmath>
#include <limits>
#include <utility>
#include <map>
#include <iomanip>


#define rep(p,q) for(int i = p;i < q;i++)
#define ll long long

using namespace std;

const int cons = 1e9 + 7;

//60C
int main(void) {
	ll n, t;
	cin >> n >> t;
	ll ans = 0;
	ll showeredTime = 0;
	ll forwardTi = 0;
	rep(0, n) {
		ll ti;
		cin >> ti;
		if (ti == 0)continue;
		if (ti <= forwardTi + t) {
			showeredTime += ti - forwardTi;
		}
		else {
			ans += showeredTime + t;
			showeredTime = 0;
		}
		forwardTi = ti;
	}
	ans += showeredTime + t;
	cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define _inline __inline__ __attribute__((always_inline))
using namespace std;
_inline void read(int &x){
	int res=0,f=1;
	char c=getchar();
	if(c=='-') f=-1;
	while(c>'9'||c<'0') c=getchar();
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	x=res*f;
}
inline void print(int x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
int n,a[100005],x,ans;
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(x);
        if(x>n) ans++;
        else a[x]++;
    }
    for(int i=1;i<=n;i++){
        if(a[i]==0) continue;
        if(a[i]<i) ans+=a[i];
        else if(a[i]>i) ans+=a[i]-i;
    }
    print(ans),puts("");
    exit(0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    //前２個、後ろ２個を取る。12を超えているかどうかで判定すればよい
    int a,b;
    a = (s.at(0)-'0')*10+(s.at(1)-'0');
    b = (s.at(2)-'0')*10+(s.at(3)-'0');
   // cout<<a<<" "<<b<<endl;
   //超えてる　超えてる　からやる。
   if((a==0&&b==0)||(a==0&&12<b)||(12<a&&b==0)||(12<a&&12<b)){
       cout<<"NA"<<endl;
   }
   else if((a==0&&0<b&&b<13)||(12<a&&0<b&&b<13)){
       cout<<"YYMM"<<endl;
   }
   else if((0<a&&a<13&&b==0)||(0<a&&a<13&&12<b)){
       cout<<"MMYY"<<endl;
   }
   else if(0<a&&a<13&&0<b&&b<13){
       cout<<"AMBIGUOUS"<<endl;
   }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 

////////////////////////////////////////////////////////


int main() {
    ll n, k; cin >> n >> k;
    string s; cin >> s;
    ll cnt = 0;
    rep(i, 0, sz(s)-1){
        if(s[i] == 'R' && s[i+1] == 'R') cnt++;
        if(s[i] == 'L' && s[i+1] == 'L') cnt++;
    }
    cnt += 2*k;
    if(cnt > n-1) cnt = n-1;
    co(cnt);

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int n,m,a,b,i;
  scanf("%d %d",&m,&n);
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a>m/2)a=m-a+1;
    if(b>m/2)b=m-b+1;
    if(a>b)a=b;
    a%=3;
    if(a%3==0)a=3;
    printf("%d\n",a);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}

template<class T, class Cond>
struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  bool operator()(T& a, const T& b) const {
    if(cond(a, b)) { a = b; return true; }
    return false;
  }
};
template<class T, class Cond>
chain<T, Cond> make_chain(Cond cond) { return chain<T, Cond>(cond); }

int main() {
  i64 S, W;
  cin >> S >> W;
  cout << ((S > W) ? "safe" : "unsafe") << endl;
}


Measured memory_bytes: 3568
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A: Measure
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  if (s.size() == 3) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}


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

const int INF = 1 << 30;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

class State
{
public:
  int tx, ty, kx, ky, c;
  State(int _tx, int _ty, int _kx, int _ky, int _c = 0)
    :tx(_tx), ty(_ty), kx(_kx), ky(_ky), c(_c) {}
};

int main()
{
  int X, Y;
  while (cin >> X >> Y) {
    if ((X|Y) == 0)
      break;

    int tx, ty, kx, ky;
    cin >> tx >> ty >> kx >> ky;

    vector<vector<int> > depart(Y, vector<int>(X));
    for (int i = 0; i < Y; ++i) {
      for (int j = 0; j < X; ++j)
	cin >> depart[i][j];
    }

    int ans = -1;
    queue<State> que;
    que.push(State(tx-1, ty-1, kx-1, ky-1, 0));
    vector<vector<vector<vector<int> > > > dp(Y, vector<vector<vector<int> > >(X, vector<vector<int> >(Y, vector<int>(X, INF))));
    while (!que.empty()) {
      const State st = que.front();
      que.pop();

      if (st.tx == st.kx && st.ty == st.ky) {
	ans = st.c;
	break;
      }

      if (dp[st.ty][st.tx][st.ky][st.kx] < st.c)
	continue;

      dp[st.ty][st.tx][st.ky][st.kx] = st.c;
      for (int d = 0; d < 4; ++d) {
	tx = st.tx + dx[d];
	ty = st.ty + dy[d];
	kx = st.kx + dx[(d+2)%4];
	ky = st.ky + dy[(d+2)%4];
	if (tx < 0 || X <= tx || ty < 0 || Y <= ty || depart[ty][tx] != 0) {
	  tx = st.tx;
	  ty = st.ty;
	}

	if (kx < 0 || X <= kx || ky < 0 || Y <= ky || depart[ky][kx] != 0) {
	  kx = st.kx;
	  ky = st.ky;
	}

	if (dp[ty][tx][ky][kx] > st.c+1) {
	  dp[ty][tx][ky][kx] = st.c+1;
	  que.push(State(tx, ty, kx, ky, st.c+1));
	}
      }
    }

    if (ans == -1)
      cout << "NA" << endl;
    else
      cout << ans << endl;
  }
  return 0;
}

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


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

    int counter = 0;
    if (s[0]=='1') ++counter;
    if (s[1]=='1') ++counter;
    if (s[2]=='1') ++counter;

    cout << counter << endl;


}

Measured memory_bytes: 256
def main():
    N = int(input())
    abc = [list(map(int, input().split())) for _ in range(N)]

    DP = [[0, 0, 0] for _ in range(N)]
    DP[0] = abc[0]

    for i in range(1, N):
        for j in range(3):
            tmp = [abc[i][j] + DP[i-1][k] for k in range(3) if k != j]
            DP[i][j] = max(tmp)

    print(max(DP[-1]))

main()


Measured memory_bytes: 47364
// 座標圧縮+2次元累積和(imos)
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
const int INF = 1e9+1;

vector<int> compress(vector<int> x, vector<int> y){
    vector<int> v;
    v.push_back(INF);
    v.push_back(-INF);
    for(auto i : x) v.push_back(i);
    for(auto i : y) v.push_back(i);
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}

// N = 2000,座圧で最大2000 * 2(両端)
int imos[4010][4010] = {};

int main(){
    int n;
    cin >> n;
    vector<int> x1(n), y1(n), x2(n), y2(n);
    for(int i = 0; i < n; i++)  cin >> x1[i] >> y1[i] >> x2[i] >> y2[i];
    vector<int> x = compress(x1, x2);
    int h = x.size();
    vector<int> y = compress(y1, y2);
    int w = y.size();
    auto fx = [&](int val) -> int{
        return lower_bound(x.begin(), x.end(), val)-x.begin();
    };
    auto fy = [&](int val) -> int{
        return lower_bound(y.begin(), y.end(), val)-y.begin();
    };
    for(int i = 0; i < n; i++){
        int a = fx(x1[i]), b = fy(y1[i]), c = fx(x2[i])-1, d = fy(y2[i])-1;
        imos[a][b]++; imos[c+1][d+1]++;
        imos[a][d+1]--; imos[c+1][b]--;
    }
    ll ans = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i)   imos[i][j] += imos[i-1][j];
            if(j)   imos[i][j] += imos[i][j-1];
            if(i != 0 && j != 0)    imos[i][j] -= imos[i-1][j-1];
            if(imos[i][j] > 0){
                ans += (ll)(x[i+1]-x[i])*(y[j+1]-y[j]);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 65896
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int x = sc.nextInt();

        boolean[] dp = new boolean[1010000];
        dp[0] = true;
        for (int i = 0; i < 1000000; i++) {
            if(dp[i]){
                for (int j = 0; j <=5; j++) {
                    dp[i + 100 + j] = true;
                }
            }
        }

        if(dp[x]){
            System.out.println(1);
        }else{
            System.out.println(0);
        }
        return;


    }

    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            }else{
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }else if(b == -1 || !isPrintableChar(b)){
                    return minus ? -n : n;
                }else{
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
    }
}


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

int main() {
  string a, b;
  cin >> a >> b;
  string ans;
  int n, m;
  n = a.size();
  m = b.size();
  if (n > m) ans = "GREATER";
  else if (n < m) ans = "LESS";
  else {
    if (a > b) ans = "GREATER";
    else if (a == b) ans = "EQUAL";
    else ans = "LESS";
  }
  cout << ans << '\n';
  return 0;
}

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

using namespace std;

typedef long long ll;

#define FOR(_i, _a, _b) for (int _i=_a; i<_b; ++_i)

const int INF = 1e9+7;

int main()
{
    int n, k;
    cin >> n >> k;
    vector <ll> a(n+1);
    vector <ll> dp(n+1, INF);
    dp[1] = 0;
    FOR(i, 1, n+1)
        cin >> a[i];
    FOR(i, 2, n+1)
    {
        int idx = 1;
        while (i - idx >= 1 && idx <= k)
            dp[i] = min(dp[i], dp[i-idx] + abs(a[i-idx] - a[i])), ++idx;
    }

    cout << dp[n];
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <unordered_set>

int main() {
  int n = 0;
  std::cin >> n;

  std::unordered_set<uint64_t> cards;

  for (uint32_t i = 0; i < n; i++) {
    uint64_t num;
    std::cin >> num;
    auto found = cards.find(num);
    if (found == cards.end()) {
      cards.insert(num);
    } else {
      cards.erase(found);
    }
  }

  std::cout << cards.size() << std::endl;
}


Measured memory_bytes: 4388
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int N; cin >> N;
  vector<string> S(N); rep(i, N) cin >> S.at(i);
  vector<long long int> MARCH(5, 0);
  rep(i, N){
    if(S.at(i).at(0) == 'M'){
      MARCH.at(0)++;
    } else if(S.at(i).at(0) == 'A'){
      MARCH.at(1)++;
    } else if(S.at(i).at(0) == 'R'){
      MARCH.at(2)++;
    } else if(S.at(i).at(0) == 'C'){
      MARCH.at(3)++;
    } else if(S.at(i).at(0) == 'H'){
      MARCH.at(4)++;
    }
  }
  long long ans = 0;
  for(int i = 0; i < 3; i++){
    for(int j = i+1; j < 4; j++){
      for(int k = j+1; k < 5; k++){
        ans += MARCH.at(i) * MARCH.at(j) * MARCH.at(k);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long LL;
typedef pair<int, int> PII;

int n;
int a[100000];
deque<int> b;

LL solve() {
    sort(a, a + n);
    b.clear();
    b.pb(a[0]);
    int l = 1;
    int r = n;
    while (l < r) {
        if (l < r) {
            b.push_front(a[--r]);
        }
        if (l < r) {
            b.pb(a[--r]);
        }
        if (l < r) {
            b.push_front(a[l++]);
        }
        if (l < r) {
            b.pb(a[l++]);
        }
    }
    LL res = 0;
    forn(i, n - 1) {
        res += abs(b[i] - b[i + 1]);
    }
    return res;
}

int main() {
    scanf("%d", &n);
    forn(i, n) scanf("%d", a + i);
    LL ans = solve();
    forn(i, n) a[i] *= -1;
    ans = max(ans, solve());
    cout << ans << endl;
    return 0;
}


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

int main() {

  unsigned int Natuyasumi;
  unsigned int Syukudai;

  cin >> Natuyasumi >> Syukudai;

  vector<int> hiniti(Syukudai);

  int sumHiniti = 0;

  for(int i=0; i<Syukudai; i++){
    cin >> hiniti.at(i);
    sumHiniti += hiniti.at(i);
  }

  if(sumHiniti > Natuyasumi){
    cout << "-1" << endl;
    return 0;
  }

  int ans = Natuyasumi - sumHiniti;

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
const ll MOD = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	ll n;
	vector<ll> a(5);
	cin >> n;
	REP(i, 5)
		cin >> a[i];
	sort(ALL(a));
	if(a[0] >= n)
		cout << 5;
	else
		cout << (n - 1) / a[0] + 5;
}

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


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

    if(a == 0)
        cout<<(b/x)+1<<"\n";
    else
    {
        cout<<((b/x)-(a-1)/x)<<"\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F(i,max,s) for(register int i=1;i<=max;i+=s)
using namespace std; 
inline bool able(int num,int lbound,int stound)
{ 
    register int sum=0; 
    while(num!=0)
	{ 
        sum+=num%10; 
        num/=10;
    }
    return (lbound<=sum&&sum<=stound);
}
inline void work()
{
	register int i,ed,lb,st,sum=0;
	cin>>ed>>lb>>st; 
    F(i,ed,1)if(able(i,lb,st))sum+=i; 
    cout<<sum<<endl; 
}
int main()
{
	work();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    S.erase(S.end()-2,S.end());
    while(S.size()){
        string sl = S.substr(0,S.size() / 2);
        string sr = S.substr(S.size() / 2);
        if(sl == sr){
            cout << S.size() << endl;
            return 0;
        }
        S.erase(S.end()-2, S.end());
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
mod=10**9+7
n,x=map(int,input().split())
a=list(map(int,input().split()))
dp=[[[0]*256 for j in range(n+1)] for k in range(2)]
dp[0][0][0]=1
for i in range(n):
  for j in range(n+1):
    for k in range(256):
      dp[(i+1)&1][j][k]=dp[i&1][j][k]
  for j in range(n):
    for k in range(256):
      dp[(i+1)&1][j+1][k^a[i]]+=dp[i&1][j][k]
      if mod<=dp[(i+1)&1][j][k^a[i]]:
        dp[(i+1)&1][j][k^a[i]]-=mod

ans=0
fac=[1]*(n+1)
for i in range(1,n+1):
  fac[i]=fac[i-1]*i
  if mod<=fac[i]:
    fac[i]-=mod
for j in range(n+1):
  ans+=dp[n&1][j][x]*fac[j]
  ans%=mod

print(ans)


Measured memory_bytes: 74312
#include <bits/stdc++.h>
#define xx first
#define yy second
#define D if(0)
#define cerr D cerr

using namespace std;
typedef long long ll;

template <typename T>
vector<T> read_n(ll n) {
  vector<T> ret(n);
  for(ll i = 0; i < n; i++) cin >> ret[i];
  return ret;
}

template <typename iter>
void dump(iter begin, iter end) {
  for(iter it = begin; it != end; it++) {
    if(it != begin) cout << " ";
    cout << *it;
  } cout << endl;
}

const ll top = 1e18;

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

  ll ret = 1;
  ll n; cin >> n;

  int fail = 0;
  for(ll i = 0; i < n; i++) {
    ll x; cin >> x;

    if(ret != 0 && top / ret < x) {
      fail = 1;
    }

    if(x == 0) {
      fail = 0;
    }

    ret *= x;
  }

  if(fail) {
    cout << "-1\n";
  } else {
    cout << ret << "\n";
  }

  return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)
#define f first

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;

const int MAXN=2e5+10,INF=1e6;

queue<pair<pair<int,int> ,int> > Q;
int N,A[MAXN];
int curid=1;
vector<pii> ans;
vi G[2*MAXN];
pii V[2*MAXN];
priority_queue<pii> QQ;

struct STN{
	int e,o;
	void merge(STN& L, STN& R){
		e = A[L.e] < A[R.e] ? L.e : R.e;
		o = A[L.o] < A[R.o] ? L.o : R.o;
	}
	void operator=(int pos){
		if(pos % 2 == 0) e = pos, o = N;
		if(pos % 2 == 1) e = N, o = pos;
	}
};
STN ST[4*MAXN];
void STB(int id = 1,int l = 0,int r = N){
	if(r - l < 2){
		ST[id] = l;
		return;
	}
	int M = (l+r)>>1, L=id<<1, R=L|1;
	STB(L, l, M); STB(R, M, r);
	ST[id].merge(ST[L],ST[R]);
}

STN STQ(int x,int y,int id = 1,int l = 0,int r = N){
	if(x == l && y == r)	return ST[id];
	int M = (l+r)>>1, L=id<<1, R=L|1;
	if(x>=M)	return STQ(x,y,R,M,r);
	if(y<=M)	return STQ(x,y,L,l,M);
	STN res,ln=STQ(x, M, L, l, M),rn=STQ(M, y, R, M, r);
	return res.merge(ln, rn), res;
}

void STU(int p,int x,int id = 1,int l = 0,int r = N){
	if(r - l < 2){
		ST[id]=x;
		return;
	}
	int M = (l+r)>>1, L=id<<1, R=L|1;
	if(p < M) STU(p, x, L, l, M);
	else STU(p, x, R, M, r);
	ST[id].merge(ST[L],ST[R]);
}

void f() {
	Q.push({{0,N},0});
	while(!Q.empty()) {
		int lo = Q.front().first.first;
		int hi = Q.front().first.second;
		int id = Q.front().second;
		Q.pop();
		if(lo + 1 >= hi) {
			V[id] = {INF,INF};
			continue;
		}
		STN n1 = STQ(lo,hi);
		int pos1 = lo % 2 == 0 ? n1.e : n1.o;
		STN n2 = STQ(pos1,hi);
		int pos2 = lo % 2 == 0 ? n2.o : n2.e;
		V[id] = {A[pos1],A[pos2]};
		Q.push({{lo,pos1},curid});
		G[id].pb(curid++);
		Q.push({{pos1+1,pos2},curid});
		G[id].pb(curid++);
		Q.push({{pos2+1,hi},curid});
		G[id].pb(curid++);
	}
}

int main() {
	ri(N);
	FOR(i,0,N) ri(A[i]);
	A[N] = INF;
	STB();
	f();
	ans.pb(V[0]);
	QQ.push({-V[0].first,0});
	while(!QQ.empty()) {
		int val = -QQ.top().first;
		int id = QQ.top().second; QQ.pop();
		if(val < INF) printf("%d %d ",V[id].first,V[id].second);
		FOR(i,0,G[id].size()) {
			int u = G[id][i];
			QQ.push({-V[u].first,u});
		}
	}
	printf("\n");
}


Measured memory_bytes: 26108
/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;

clock_t time_p=clock();
void aryanc403()
{
#ifdef ARYANC403
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/priank/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s,t;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>s>>t;
    cout<<t<<s<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 256
n = int(input())
for i in range(10**3):
    if n == i*(i+1)//2:
        x = i
        break
else:
    print("No")
    exit()
ans = [[] for i in range(x+1)]
app = 0
for i in range(1,x+1):
    for j in range(i):
        app += 1
        ans[j].append(app)
    ans[i].extend([k for k in range(i*(i-1)//2+1,i*(i+1)//2+1)])
print("Yes")
print(x+1)
for ansarr in ans:
    print(x, *ansarr, sep = " ")


Measured memory_bytes: 48348
def insertionSort(A, N, g=1):
    global count
    for i in range(g, N):
        v = A[i]
        j = i-g
        while A[j] > v and j >= 0:
            A[j+g], A[j] = A[j], A[j+g]
            count += 1
            j -= g


def bubbleSort(A, N):
    flag = 1
    while flag:
        flag = 0
        for j in range(N-1, 0, -1):
            if A[j] < A[j-1]:
                A[j], A[j-1] = A[j-1], A[j]
                flag = 1


def selectionSort(A, N):
    for i in range(N):
        minidx = i
        for j in range(i, N):
            if A[j] < A[minidx]:
                minidx = j
        A[i], A[minidx] = A[minidx], A[i]


def shellSort_d(N):
    G = [1]
    i = 0
    while True:
        tmp = G[i] * 3 + 1
        if tmp < N:
            G.append(tmp)
            i += 1
        else:
            break
    G.reverse()
    return G


def shellSort(A, N):
    global count, G
    count = 0
    G = shellSort_d(N)
    for g in G:
        insertionSort(A, N, g)


N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

shellSort(A, N)

print(len(G))
print(" ".join(map(str,G)))
print(count)
for a in A:
    print(a)


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

namespace abc68
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            Console.WriteLine("ABC" + N);
           

        }
    }
}


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

struct RMQ {
    const ll INF = 1ll<<60;
    int n;
    vector<ll> data;

    RMQ() {}
    RMQ(int n_) { init(n_); }
    RMQ(int n_, vector<ll> &vec) { init(n_); set(vec); build(); }
    void init(int n_) {
        n = 1; while (n < n_) n <<= 1;
        data.assign(n<<1,INF);
    }
    void set(vector<ll> &vec) {
        for (int i = 0; i < (int)vec.size(); i++) data[i+n] = vec[i];
    }
    void build() {
        for (int i = n-1; i > 0; i--) data[i] = min(data[i<<1],data[(i<<1)|1]);
    }

    void update(int i, ll x) {
        i += n; data[i] = x;
        while (i >>= 1) data[i] = min(data[i<<1],data[(i<<1)|1]);
    }
    ll query(int a, int b) {
        ll res = INF;
        for (int l = a + n, r = b + n; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = min(res,data[l++]);
            if (r & 1) res = min(res,data[--r]);
        }
        return res;
    }
};

int main(){
    ll n, x; cin >> n >> x;
    vector<ll> a(n<<1);
    rep(i,n) { cin >> a[i]; a[i+n] = a[i]; }

    RMQ data(n<<1,a);
    ll ans = 1ll<<60;
    rep(i,n) {
        ll ch = i * x;
        rep(j,n) ch += data.query(n+j-i,n+j+1);
        if (ch < ans) ans = ch;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3696
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define Se second
#define Fi first

char in[30];
char in2[30];
bool chk[30];
int main() {
	scanf("%s", in);
	
	int N = strlen(in), i, j;
	for (i = 0; i < N; i++) chk[in[i] - 'a'] = true;

	if (N != 26) {
		printf("%s", in);
		for (i = 0; i < 26; i++) {
			if (chk[i]) continue;
			printf("%c\n", i + 'a');
			break;
		}
		return 0;
	}

	for (i = 0; i < N; i++) in2[i] = in[i];
	if (!next_permutation(in2, in2 + N)) return !printf("-1\n");

	for (i = 0; i < N; i++) {
		printf("%c", in2[i]);
		if (in2[i] != in[i]) break;
	}
	return !printf("\n");
}

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

int main() {
    int N;
    while (cin >> N, N) {
        vector<char> v(N);
        for (auto& i : v) cin >> i;

        vector<int> sum(26);
        for (int i = 0; i < N; i++) {
            sum[v[i] - 'A']++;
            vector<pair<int,int> > ssum;
            for (int j = 0; j < 26; j++) {
                ssum.push_back(pair<int,int>(sum[j], j));
            }
            sort(ssum.begin(), ssum.end());

            if (N - i - 1 + ssum[24].first < ssum[25].first) {
                cout << (char)(ssum[25].second + 'A') << " " << i + 1 << endl;
                break;
            }
            if (i + 1 == N) {
                cout << "TIE" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
int main() {
//input
int a[200001];
int n;
int num=1;
int count=0;
cin>>n;
rep(i,n){
	cin>>a[i];
}
//compute

//output

	rep(i,n){
		if(num==a[i]){
			num++;
		}
		else{
			count++;
		}
	}
	if(count==n){
		cout<<-1;
	}
	else {
		cout<<count;
	}
	return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextLong()
    var ans = dsum(n)
    for (j in (1..16)) {
        var k = n
        for (i in (1..j)) { k /= 10 }
        for (i in (1..j)) { k *= 10 }
        val l = dsum(k - 1)
        if (l >= ans) ans = l
    }
    println(ans)
}

fun dsum(n: Long): Long {
    if (n <= 0) return 0
    if (n <= 9) return n
    return dsum(n / 10) + n % 10
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int left = a+b;
  int right = c+d;
  if(left < right){
    cout << "Right" << endl;
  }else if(left == right){
    cout << "Balanced" << endl;
  }else{
    cout << "Left" << endl;
  }
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
assets = 1000               # 資産

# 売買するかどうかのフラグ(買→1、売→0)をリストで生成
# (所持資産・所持株数を最大限に使い切って行う)
flag = []
for n in range(N-1):
    if A[n] <= A[n+1]:      # 当日の株価 <= 翌日の株価 ⇒ 買う
        flag.append(1)
    else:
        flag.append(0)      # 当日の株価 > 翌日の株価 ⇒ 売る
flag.append(0)              # 最終日は売る
# print(flag)

amount = 0                  # 所持株数
for idx, f in enumerate(flag):      # 売買処理
    if f == 1:
        purchase = assets // A[idx] # 購入数
        amount += purchase
        assets -= purchase * A[idx]
    else:
        assets += amount * A[idx]
        amount = 0
    # print(assets, amount)

print(assets)


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

#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    int x = 0;
    while(x*x <= N){
        x++;
    }
    cout << (x-1) * (x-1) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<set>
using namespace std;
int main(){
        int n;
        cin>>n;
        string s,t;
        set<string> m;
        for(int i=0;i<n;i++){
                cin>>s>>t;
                if(s=="insert") m.insert(t);
                else if(s=="find") {
                        if(m.find(t)==m.end()) cout<<"no"<<endl;
                        else cout<<"yes"<<endl;
                }
        }
        return 0;
}


Measured memory_bytes: 32560
#include <iostream>      
#include <stdio.h>       // printf,scanf
#include <stdlib.h>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>  //sort,binarySearch
#include <functional> 
#include <iomanip>    // setprecision
#include <utility>    // c+11 Array
#include <set>
#include <sstream>
#include <map>
#include <bits/stdc++.h> // include all
#define MOD 1000000007
#define PI 3.141592653589793238462643383279
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define pb(x) push_back(x)
#define debug(x) cout << #x << " = " << x << endl;
#define debret(x) debug(x) ; return 0;

using namespace std;

int main(void){

    int A, B;
    char op;

    cin >> A >> op >> B;

    int ans = 0;

    if(op == '+'){
        ans = A + B;
    }else{
        ans = A - B;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256