akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <cstdio>
#include <cctype>
#include <queue>
#include <complex>
#include <climits>
#include <cstring>

typedef long long ll;

using namespace std;

ll nCr[2000][2000] = {0};

int main(void){
	int p[3];
	int juice[2];
	int m = 10000;

	cin >> p[0] >> p[1] >> p[2];
	cin >> juice[0] >> juice[1];

	for(int i=0; i<3; ++i){
		for(int j=0; j<2; ++j){
			m = min(m, p[i] + juice[j] - 50);
		}
	}

	cout << m << endl;

	return 0;
}

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

class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			String str = br.readLine();
			int N = Integer.parseInt(str);
			System.out.println("ABC"+N);

		}catch (Exception e) {
			System.exit(0);
		}
	}
}


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

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

int main() {
    string s;
    cin >> s;
    int cntA = 0;
    rep(i, 3) if (s[i] == 'A') cntA++;
    if (cntA != 3 && cntA != 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 764
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		String s = stdIn.next();
		if(s.equals("ABC")) {
			System.out.println("ARC");
		}else {
			System.out.println("ABC");
		}
		
		
	}

}


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

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]) {
  int n;
  cin >> n;

  vector<vector<pair<int, ll>>> g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b, c;
    cin >> a >> b >> c;
    a--, b--;
    g[a].push_back({b, c});
    g[b].push_back({a, c});
  }

  int q, k;
  cin >> q >> k;
  k--;

  vector<ll> costs(n);
  vector<bool> seen(n, false);
  stack<pair<int, ll>> st;
  st.push({k, 0});
  while (!st.empty()) {
    auto [idx, cost] = st.top();
    st.pop();
    if (seen[idx]) {
      continue;
    }

    costs[idx] = cost;
    seen[idx] = true;

    for (auto &child : g[idx]) {
      st.push({child.first, cost + child.second});
    }
  }

  vector<ll> ans;
  for (int i = 0; i < q; ++i) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    ans.push_back(costs[x] + costs[y]);
  }

  for (auto a : ans) {
    cout << a << '\n';
  }

  return 0;
}

Measured memory_bytes: 13552
N, M = map(int, input().split())

# 裏（カウント）：接している枚数が偶数

if N == 1 and M == 1:
    print(1) # 0
elif N == 1 or M == 1:
    print(N*M-2) # 両端のぞく
else:
    print((N-2)*(M-2))


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
#define INF (ll)(1ll<<60)
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}

int main(){
	ll n;cin>>n;
	vector<ll> a(n);
	rep(i,n){cin>>a[i];if(a[i]==0){cout<<0<<endl;return 0;}}

	ll ans=1;
	bool cant=false;
	rep(i,n){
		if(ans>1000000000000000000/a[i]){
			cant=true;
			break;
		}else{
			ans*=a[i];
		}
	}

	if(!cant) cout<<ans<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 4048
//#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 07/Mar/20 05:40:30 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

#define		int                    long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
    cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
    cout << t << " ";
    pr (u, args...);
}

// clang-format on


signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr);
	int a, b;
	cin >> a >> b;
	bool flag = 0;
	fr (i, 1, 1e4) {
		if ((i * 8) / 100 == a and (i * 10) / 100 == b) {
			pr (i);
			flag = 1;
			break;
		}
	}
	if (!flag) {
		pr (-1);
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        int[][][] members = new int[4][3][10];
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            int b = scanner.nextInt();
            int f = scanner.nextInt();
            int r = scanner.nextInt();
            int v = scanner.nextInt();

            members[b-1][f-1][r-1] += v;
        }

        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 10; k++) {
                    System.out.print(" ");
                    System.out.print(members[i][j][k]);
                }
                System.out.print("\n");
            }
            System.out.println("####################");
        }

        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                System.out.print(" ");
                System.out.print(members[3][j][k]);
            }
            System.out.print("\n");
        }

        scanner.close();
    }
}



Measured memory_bytes: 29360
n, k = map(int, input().split())
aa = list(map(int, input().split()))
k_bit=[int(b) for b in list(format(k,"b"))]
k_bit.reverse()
m=len(k_bit)
cnt_bit = [0] * m
for a in aa:
    for i in range(m):
        cnt_bit[i] += a & 1
        a >>= 1
#print(cnt_bit)
x_bit=[(cnt<n/2)*1 for cnt in cnt_bit]
#print(k_bit)
#print(x_bit)
for i in range(m-1,-1,-1):
    kb=k_bit[i]
    xb=x_bit[i]
    if kb==1 and xb==0:break
    if kb==0 and xb==1:x_bit[i]=0
#print(x_bit)
x=sum(x_bit[i]*2**i for i in range(m))
#print(x)
print(sum(a^x for a in aa))


Measured memory_bytes: 14708
import  itertools

N,M=map(int,input().split())
graph = [[] for _ in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

def judge(pattern):
    if pattern[0]!=0:
        return False
    else:
        flag=True
        for i in range(len(pattern)-1):
            if pattern[i+1] in graph[pattern[i]]:
                continue
            else:
                flag=False
        if flag:
            return True
        return False

nums=[]
for i in range(N):
    nums.append(i)
ans=0
for pa in itertools.permutations(nums,N):
    pas=list(pa)
    if judge(pas):
        ans+=1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, b = 0, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (a > b) {
      b = a;
    }
    sum += a;
  }
  cout << b / 2 + sum - b << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

const ull DIV = 1e+09 + 7;

ull get_fact(ull n) {
    ull ans = 1;

    while(n != 1) {
        // cout << n <<endl;
        ans = (ans*n)%DIV;
        // if (ans == 0) {
        //     cout << n << endl;
        //     return ans;
        // }
        n--;
    }

    // cout << "fact(" << n << ")=" << ans << endl;

    return ans;
}

int main(void) {
    int N, M;
    cin >> N >> M;

    if (abs(N-M) > 1) {
        cout << 0 << endl;
        return 0;
    }

    // N == M
    ull ans = 0;
    if (N == M) {
        // cout << 1 << endl;
        ans = 2 * get_fact(N)%DIV * get_fact(M)%DIV;
        cout << ans << endl;
    } else {
    // abs(N-M) == 1
        // cout << 2 << endl;
        ans = get_fact(N)%DIV * get_fact(M)%DIV;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<math.h>
#include<string.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a[200010],b[200001];
	int n,k,t;
	cin>>n>>k;
	int i;
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	while(k--){
		t=0;
		for(i=0;i<n;i++){
			int c,d;
			c=i+a[i];
			d=max(0,i-a[i]);
			b[c+1]--;
			b[d]++;
		}
		a[0]=b[0];
		if(a[0]==n)
		t++;
		for(i=1;i<n;i++){
			b[i]=b[i]+b[i-1];
			a[i]=b[i];
			b[i-1]=0;
			if(a[i]==n)
			t++; 
		}
		if(t==n)
		break;
		b[i-1]=0;
	}
	for(i=0;i<n;i++)
	cout<<a[i]<<' ';
}

Measured memory_bytes: 4724
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;

bool compare_by_b(pair<long long, long long>a, pair<long long, long long>b){
    if(a.second != b.second) return a.second < b.second;
    else return a.first < b.first;
}

int main(){
  int N;  cin >> N;
  vector<pair<long long,long long> >task(N);
  for(int i=0;i<N;i++){
    cin >> task.at(i).first >> task.at(i).second;
  }

  long long time = 0;
  sort(task.begin(),task.end(),compare_by_b);

  for(int i=0;i<N;i++){
    time += task.at(i).first;
    if(time > task.at(i).second){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t=1;
    // cin>>t;
    while(t--)
    {
        int h,n;
        cin>>h>>n;
        vector<int>a(n);
        int sum=0;
        for(int i=0;i<n;i++) 
        {
            cin>>a[i];
            sum+=a[i];
        }
        if(sum>=h) cout<<"Yes"; else cout<<"No";
    }
	return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;

#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define uniq(x) ((x).erase(unique(all(x)),(x).end()))
#define sz(x) ((int)(x).size())

#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)

string to_string(string s){
  return '"' + s + '"';
}
string to_string(const char *s){
  return to_string((string)s);
}
string to_string(bool b){
  return (b ? "true" : "false");
}
template<class A, class B>
string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template<class A, class B, class C>
string to_string(tuple<A, B, C> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
template<class A, class B, class C, class D>
string to_string(tuple<A, B, C, D> p){
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
template<class A>
string to_string(A v){
  bool first = true;
  string res = "{";
  for(const auto &x : v){
    if(!first){
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out(){cerr << endl;}
template<class Head, class... Tail>
void debug_out(Head H, Tail... T){
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL//compile with -DLOCAL
#define debug(...) cerr << "LINE" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) void(0)
#endif

template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

using mint = modint998244353;
vector<mint> pow10;
mint inv9 = mint(9).inv();

//区間変更・区間和取得
//seg.prod(l, r).value で値をとりだす！
struct S{
  mint value;
  int l;
  int r;
};
struct F{
  int d;
  bool flag;
};
const int INF = 1e9;

S op(S a, S b){ return {a.value+b.value, min(a.l,b.l), max(a.r,b.r)}; }
S e(){ return {0, INF, -INF}; }
S mapping(F f, S x){
  if(f.flag){
    x.value = f.d * (pow10.at(x.r) - pow10.at(x.l)) * inv9;
  }
  return x;
}
F composition(F f, F g){
  if(f.flag)  return f;
  else  return g;
}
F id(){ return {0, false}; }


int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N,Q;
  cin >> N >> Q;


  pow10.resize(N+1);
  mint tmp = 1;
  rep(i,N+1){
    pow10.at(i) = tmp;
    tmp *= 10;
  }

  vector<S> v(N);
  rep(i,N){
    v.at(i) = {pow10.at(i), i, i+1};
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);

  rep(_,Q){
    int l,r,d;
    cin >> r >> l >> d;
    r = N - r + 1;
    l = N - l;
    seg.apply(l, r, F{d, true});
    cout << seg.prod(0, N).value.val() << endl;
  }

  return 0;
}

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

using namespace std;

#define LL long long
#define ULL unsigned LL
#define LD long double
#define debug(x) cerr << #x << " " << x << endl;

const int N = 1e5 + 2137;
vector<int> V[N];
//vector<int> W[N]; // graf transponowany
int d[N]; // stopien wejsciowy
int dp[N];

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin>>n>>m;
	int a, b;
	for(int i=0; i<m; i++) {
		cin>>a>>b;
		V[a].push_back(b);
		//W[b].push_back(a);
		d[b]++;
	}
	queue<int> toposort;
	for(int i=1; i<=n; i++) {
		if(d[i] == 0)
			toposort.push(i);
	}
	int w = 0;
	while(!toposort.empty()) {
		int v = toposort.front();
		w = max(w, dp[v]);
		toposort.pop();
		for(int i=0; i<V[v].size(); i++) {
			int u = V[v][i];
			dp[u] = max(dp[u], dp[v]+1);
			d[u]--;
			if(d[u] <= 0)
				toposort.push(u);
		}
	}
	cout<<w;
}


Measured memory_bytes: 6528
N,M = map(int,input().split())

A = [[] for i in range(N)]

for i in range(N):
    A[i] = list(map(int,input().split()))

B = [[0]*1 for i in range(M)]

for i in range(M):
    B[i] = int(input())


for row in range(N):
    answer = 0
    for col in range(M):
        answer += A[row][col]*B[col]
    print("{}".format(answer))



Measured memory_bytes: 6020
#include<bits/stdc++.h>
using namespace std;
int main() {
	string w;
	cin >> w;
	vector<int> word(30);
	for (int i = 0; i < w.size(); i++) {
		word[w[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (word[i]%2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;

}

Measured memory_bytes: 256
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long N = lread();
    auto A = aryread();
    long sum = A.sum();
    long ans = long.max;
    foreach (i; 1 .. N)
        A[i] = A[i] + A[i - 1];
    foreach (i; 0 .. N - 1)
        ans = ans.min(abs(A[i] * 2 - sum));
    // writeln(sum, A);
    writeln(ans);
}


Measured memory_bytes: 11008
import sys
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
def resolve():
    S = sr()
    T = sr()
    for i in range((len(S))):
        if S[i] != T[i]:
            print('No')
            return
    print('Yes')
resolve()

Measured memory_bytes: 61668
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define erep(i, n) for (int i = 0; i <= (int)(n); i++)

int main() {
    int n; cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i] >> b[i] >> c[i];

    vector< vector<int> > dp(n, vector<int>(3));
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    rep (i, n - 1) {
        rep (j, 3) {
            if (j == 0) dp[i + 1][0] = max(dp[i][1] + a[i + 1], dp[i][2] + a[i + 1]);
            if (j == 1) dp[i + 1][1] = max(dp[i][0] + b[i + 1], dp[i][2] + b[i + 1]);
            if (j == 2) dp[i + 1][2] = max(dp[i][0] + c[i + 1], dp[i][1] + c[i + 1]);
        }
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}


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

AC = 0
WA = 0
TLE = 0
RE = 0

for i in range(N) :
  status = str(input())

  if status == "AC":
    AC += 1
  elif status == "WA": 
    WA += 1
  elif status == "TLE":
    TLE += 1
  elif status == "RE":
    RE += 1
    
print("AC" + " x " + str(AC))
print("WA" + " x " + str(WA))
print("TLE" + " x " + str(TLE))
print("RE" + " x " + str(RE))

Measured memory_bytes: 9204
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

const ld pi = 3.141592653589793;

#ifdef EBUG
#define debug(x) cout << "\033[31m" << #x << ": " << x << "\033[0m\n";
#else
#define debug(x)
#endif

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll n, k, ans;
ll h[100005];
int main() {
  cin >> n >> k;
  rep(i, n) {
    cin >> h[i];
  }

  rep(i, n) {
    if (k <= h[i]) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4376
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"
#define ncr(n, r) (n>=r?((ft[n]*mod_in((ft[r]*ft[(n)-(r)])%MOD))%MOD):0LL)
#define mod_in(a) power(a, MOD - 2)
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%MOD)

const ll MOD = 1000000007;

vector<ll> ft(1, 1LL);

ll add(ll a, ll b){a += b; return a>=MOD?a-MOD:a;}
ll sub(ll a, ll b){a -= b; return (a<0?a+MOD:a);}
ll mult(ll a, ll b){return (a*b)%MOD;}

int main() //PointBlank's code ¯\_(ツ)_/¯
{
    fact(500005);
    int n, m, res = 0;
    cin >> n >> m;
    repp(i, 0, n){
        ll y = mult(mult(ncr(n, i), 
        mult(ncr(m, i),ft[i])), 
        mult(mult(ncr(m-i, (n-i)), ft[n-i]), 
        mult(ncr(m-i,( n-i)), ft[n-i])));
        res = i%2?sub(res, y):add(res, y); 
    }
    cout << res << endl;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 7300
#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

char ch[10001];

int n,m,ans,sum[10001][4];

signed main()
{
	n=read();
	scanf("%s",ch+1);
	for ( int i=1;i<=n;i++ ) 
	{
		for ( int j=0;j<=2;j++ ) sum[i][j]=sum[i-1][j];
		if(ch[i]=='B') sum[i][2]++;
		if(ch[i]=='G') sum[i][1]++;
		if(ch[i]=='R') sum[i][0]++;
	}
	for ( int i=1;i<=n;i++ ) 
		for ( int j=i+1;j<=n;j++ ) 
		{
			int pos=j-i+j;
			if(ch[i]=='R'&&ch[j]=='G') ans+=sum[n][2]-sum[j][2]-(ch[pos]=='B');
			if(ch[i]=='R'&&ch[j]=='B') ans+=sum[n][1]-sum[j][1]-(ch[pos]=='G');
			if(ch[i]=='G'&&ch[j]=='B') ans+=sum[n][0]-sum[j][0]-(ch[pos]=='R');
			if(ch[i]=='G'&&ch[j]=='R') ans+=sum[n][2]-sum[j][2]-(ch[pos]=='B');
			if(ch[i]=='B'&&ch[j]=='G') ans+=sum[n][0]-sum[j][0]-(ch[pos]=='R');
			if(ch[i]=='B'&&ch[j]=='R') ans+=sum[n][1]-sum[j][1]-(ch[pos]=='G');
		}
	printf("%lld\n",ans);
	return 0;
}
		


Measured memory_bytes: 3948
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int64_t> v(N), vec(N);
	for (int i = 0; i < N; i++) cin >> v.at(i);
	sort(v.begin(), v.end());
	
	vector<int64_t> A(N/2), B(N/2);
	int64_t mid = 0;

	if (N % 2 == 0) {
		int64_t c = 0;
		for (int i = 0; i < N / 2; i++) A.at(i) = v.at(i);
		for (int i = N / 2; i < N; i++) {
			B.at(c++) = v.at(i);
		}

		int64_t a = 0, b = 0;
		for (int i = 0; i < N; i++) {
			if (i%2) vec.at(i) = A.at(a++);
			else vec.at(i) = B.at(b++);
		}
		/*for (int i = 0; i < A.size(); i++) cout << A.at(i);
		cout << endl;
		for (int i = 0; i < B.size(); i++) cout << B.at(i);
		cout << endl;*/
		/*for (int i = 0; i < N; i++) cout << vec.at(i);
		cout << endl;*/

		int64_t d = 0;
		for (int i = 1; i < N; i++) {
			d += abs(vec.at(i) - vec.at(i - 1));
		}
		cout << d << endl;
	}
	else {
		vector<int64_t> vec(N-1);

		int64_t c = 0;
		for (int i = 0; i < N / 2; i++) A.at(i) = v.at(i);
		for (int i = N / 2 + 1; i < N; i++) {
			B.at(c++) = v.at(i);
		}
		mid = v.at(N / 2);
		//cout << mid << endl;

		int64_t a = 0, b = 0;
		for (int i = 0; i < N - 1; i++) {
			if (i % 2) vec.at(i) = A.at(a++);
			else vec.at(i) = B.at(b++);
			//cout << vec.at(i);
		}
		//cout << endl;

		//cout << vec.size() << endl;
		vector<int64_t> vec2 = { mid };
		for (int i = 0; i < N-1;i++) {
			vec2.push_back(vec.at(i));
		}
		vec.push_back(mid);

		//for (int i = 0; i < N; i++) cout << vec.at(i);
		//cout << endl;
		//for (int i = 0; i < N; i++) cout << vec2.at(i);
		//cout << endl;

		int64_t d1 = 0, d2 = 0;
		for (int i = 1; i < N; i++) {
			d1 += abs(vec.at(i) - vec.at(i - 1));
		}
		for (int i = 1; i < N; i++) {
			d2 += abs(vec2.at(i) - vec2.at(i - 1));
		}

		cout << max(d1,d2) << endl;
	}

}

Measured memory_bytes: 7960
#include <iostream>
using namespace std;
int main()
{
    int N,s[105],t,ans=0;
    cin>>N;
    for(int i=0;i<N;i++){
         cin>>s[i];
    }
    for(int i=0;i<N;i++){
        int mini=i;
        for(int j=i;j<N;j++){
            if(s[j]<s[mini]){
                mini=j;
            }
        }
            if(i!=mini){
                t=s[i];
                s[i]=s[mini];
                s[mini]=t;
                ans++;
            }
        
    }
    int cas=0;
    for(int i=0;i<N;i++){
        if(++cas>1) cout<<" ";
        cout<<s[i];
    }
    cout<<endl;
    cout<<ans<<endl;
}


Measured memory_bytes: 3080
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>

#define f first
#define s second
#define mp make_pair

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

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int sb[10][10000];

int main(){
  int R, C;
  while(scanf("%d%d",&R,&C), R+C){
    REP(i,R) REP(j,C) scanf("%d",&sb[i][j]);
    int ans = 0;
    REP(k, (1<<R)){
      REP(i,R)
        if(k & (1<<i))
          REP(j,C)
            sb[i][j] = !sb[i][j];

      int cnt = 0;
      REP(j,C){
        int tmp = 0;
        REP(i,R)
          tmp += sb[i][j];
        cnt += max(tmp, R-tmp);
      }
      ans = max(ans, cnt);

      REP(i,R)
        if(k & (1<<i))
          REP(j,C)
            sb[i][j] = !sb[i][j];
    }
    printf("%d\n",ans);
  }
  return 0;
}

Measured memory_bytes: 1268
#include<stdio.h>
#include<math.h>

typedef struct{
  double x;
  double y;
}k;


void kochCurve(int,k,k);


int main(){

  k p1,p2;
  int n;

  p1.x = 0;
  p2.x = 100;
  p1.y = 0;
  p2.y = 0;

  scanf("%d",&n);

  printf("%f %f\n",p1.x,p1.y);
  kochCurve(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);

  return 0;

}


void kochCurve(int n, k p1, k p2){

  k s,t,u;

  if(n==0) return;

  s.x = (p2.x-p1.x)/3+p1.x;
  s.y = (p2.y-p1.y)/3+p1.y;
  t.x = 2*(p2.x-p1.x)/3+p1.x;
  t.y = 2*(p2.y-p1.y)/3+p1.y;
  u.x = (t.x-s.x)/2-sqrt(3)/2*(t.y-s.y)+s.x;
  u.y = (t.y-s.y)/2+sqrt(3)/2*(t.x-s.x)+s.y;


  kochCurve(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  
  kochCurve(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  
  kochCurve(n-1,u,t);
  printf("%f %f\n",t.x,t.y);

  kochCurve(n-1,t,p2);


}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <complex>
#include <cmath>
#include <algorithm>

using namespace std;

int n, m, k;
string s;

int main()
{
    cin >> n >> k;
    cin >> s;
    for (int i = 0; i + 1 < n; i++)
    {
        if (s[i] != s[i + 1]) m++;
    }
    while (m > 0 && k > 0)
    {
        m -= 2;
        k--;
        if (m < 0) m = 0;
    }
    cout << n - 1 - m;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

const string YES = "Yes";
const string NO = "No";

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

    vector<vector<int>> A(3, vector<int>(3));
    REP(i, 3) REP(j, 3) cin >> A[i][j];

    int N;
    cin >> N;

    std::vector<int> b(N);
    REP(k, N) {
        int tmp; cin >> tmp;
        REP(i, 3) REP(j, 3)
            if (A[i][j] == tmp) A[i][j] = 0;
    }

    bool ans = false;
    REP(i, 3) {
        int sum = 0;
        REP(j, 3)
            sum += A[i][j];
        if (sum == 0) ans = true;
    }

    REP(j, 3) {
        int sum = 0;
        REP(i, 3)
            sum += A[i][j];
        if (sum == 0) ans = true;
    }

    if (A[0][0] + A[1][1] + A[2][2] == 0) ans = true;
    if (A[0][2] + A[1][1] + A[2][0] == 0) ans = true;

    if (ans) cout << YES << '\n';
    else cout << NO << '\n';

    return 0;
}


Measured memory_bytes: 256
from collections import deque
S = input()
T = input()
q = deque(list(S))
OK = False
for i in range(len(S)):
    last = q[-1]
    q.pop()
    q.appendleft(last)
    ans = list(q)
    ans = ''.join(ans)
    #print (ans)
    if ans == T:
        print ("Yes")
        OK = True
        break
if OK == False:
    print ("No")

Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {
	
	public static final long MOD = 1_000_000_007;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String l = sc.next();
		
		long ans = 1;
		long pow = 1;
		int n = l.length();
		

		
		for (int i=0;i<n;i++) {
			if (l.charAt(n-i-1)=='1') {
				ans = (ans*2+pow)%MOD;
			}
			pow = pow*3%MOD;
		}

		System.out.println(ans);
	}

	

}




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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }




int main() {
    vector<int> v(3);
    cin >> v[0] >> v[1] >> v[2];
    sort(v.begin(), v.end());
    int ans = 0;
    if(v[0]%2 == v[1]%2) {
        if(v[0]%2 != v[2]%2) {
            v[0]++;
            v[1]++;
            ans = 1;
        }
    } else {
        if(v[0]%2 == v[2]%2) {
            v[0]++;
            v[2]++;
            ans = 1;
        } else {
            v[1]++;
            v[2]++;
            ans = 1;
        }
    }

    ans += ((v[2]-v[1])/2) + ((v[2]-v[0])/2);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


int main(){

	while(true){

		int m,n,x,y;
		vector<pair<int,int> >c;
		vector<pair<int,int> >p;
		vector<pair<int,int> >s;

		cin >> m;
		if(m==0) break;
		rep(i,m){
		cin >> x >> y;
		c.push_back(make_pair(x,y));
		}
		cin >> n;
		rep(i,n){
		cin >> x >> y;
		p.push_back(make_pair(x,y));
		}
		sort(c.begin(),c.end());
		sort(p.begin(),p.end());

		int u,v;
        rep(i,n-m+1){
        u=0;	
		rep(j,m-1){
	    s.push_back(make_pair(p[i].first+c[j+1].first-c[0].first,p[i].second+c[j+1].second-c[0].second));
	   
		rep(k,n){
		if(p[k]==s[j]){ u++; break;}
		}
        }
		s.clear();
		if(u==m-1){ v=i; break;}
	}
        
		cout << p[v].first-c[0].first << " " << p[v].second-c[0].second << endl;
        c.clear(); p.clear();
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
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 long long INF = 1LL << 60;

int N;
vector<bool> visited;
vector<int> numlist;

void dfs(int c, int i, int n){
    if(c==N) {
        numlist.push_back(n);
        return;
    }
    visited[i] = true;
    REP(next_i, N){
        if(visited[next_i]) continue;
        dfs(c+1, next_i, n*10+(next_i+1));
    }
    visited[i] = false;
    return;

}
int main()
{
    cin >> N;
    int A=0;
    REP(i, N){
        int a;
        cin >> a;
        A=A*10+a;
    }
    int B=0;
    REP(i, N){
        int a;
        cin >> a;
        B=B*10+a;
    }

    //cout << A << endl;
    //cout << B << endl;

    visited.resize(N);
    REP(i, N) visited[i]=false;

    REP(next_i, N) dfs(1, next_i, next_i+1);

    int cnt_A, cnt_B;
    int cnt=0;
    for(auto x:numlist){
        if(x==A) cnt_A=cnt;
        if(x==B) cnt_B=cnt;
        cnt++;
    }
    cout << abs(cnt_B-cnt_A) << endl;


    return 0;
}

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

int cut(string S, string T){
  int kazu = 0;
  for( char C = 'a'; C <= 'z'; C++ ){
    if( count(S.begin(), S.end(), C) > 0 && count(T.begin(), T.end(), C) > 0 ){
      kazu++;
    }
  }
  return kazu;
}
 
signed main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int ans = 0;
  for( int i = 0; i < N; i++ ){
    int tmp = cut( S.substr(0, i), S.substr(i) );
    ans = max( ans, tmp );
  }
  cout << ans << endl;
     
      
}



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

int main(){
	int r,c;
	cin>>r>>c;
	int a[r+1][c+1]={};
	for(int i=0;i<r;i++){
		for(int j=0;j<c;j++){
			cin>>a[i][j];
			a[r][j]+=a[i][j];
			a[i][c]+=a[i][j];
			a[r][c]+=a[i][j];
		}
	}
	for(int i=0;i<=r;i++){
		for(int j=0;j<=c;j++){
			cout<<a[i][j];
			if(j!=c) cout<<" ";
		}
		cout<<endl;
	}
	return 0;
}



Measured memory_bytes: 3128
using System;
using System.Linq;

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			var s = "";
			while((s = Console.ReadLine()) != "0")
			{
				var n = int.Parse(s);
				var arr = new int[7];
				foreach(var i in Enumerable.Range(1, n))
				{
					var o = int.Parse(Console.ReadLine());
					arr[Math.Min(o / 10, 6)] += 1;
				}
				foreach(var i in arr)
				{
					Console.WriteLine(i);
				}
			}
		}
	}
}

Measured memory_bytes: 5992
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

bool is_even(string S) {
    int l = S.size() / 2;
    string sub_1 = S.substr(0, l);
    string sub_2 = S.substr(l, l);
    if(sub_1 == sub_2) return true;
    else return false;
}

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

    int l = 0;
    for(int i = S.size() - 2; i >= 1; i -= 2) {
        string sub = S.substr(0, i);
        dump(sub);
        if(is_even(sub)) {
            l = sub.size();
            break;
        }
    }

    cout << l << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();

        }



        System.out.println(N*N);
    }
}


Measured memory_bytes: 24276
var n, i : longint;
    a, cnt : array[1..200005] of int64;
    has : array[1..200005] of boolean;
    tot : int64;
    
begin
    readln(n);
    fillchar(cnt, sizeof(cnt), 0);
    for i := 1 to n do 
    begin
        read(a[i]);
        inc(cnt[a[i]]);
    end;
    tot := 0;
    fillchar(has, sizeof(has), false);
    for i := 1 to n do 
    begin
        if (not has[a[i]]) then 
        begin
            tot := tot + cnt[a[i]] * (cnt[a[i]] - 1) div 2;
            has[a[i]] := true;
        end;
    end;
    for i := 1 to n do 
    begin
        writeln(tot - cnt[a[i]] * (cnt[a[i]] - 1) div 2 + (cnt[a[i]] - 1) * (cnt[a[i]] - 2) div 2);
    end;
end.

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
const int N = 3000;
double arr[N];
double mem[N][N];
double sum = 0;
int n;
double calc(int heads , int i ) {
    if (heads == 0) return 1;
    if (i == -1) return 0;
    if (mem[i][heads] > -1.0)
        return mem[i][heads];
    return mem[i][heads] = ( arr[i] * calc(heads - 1 , i - 1)) + ((1.0-arr[i]) * calc(heads , i - 1));
    
} 
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    memset(mem , -1.0 , sizeof(mem));
    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }
    cout << fixed << setprecision(10) << calc(n/2 + 1 , n - 1) << endl;
}

Measured memory_bytes: 74320
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main(){
    input!{
        A: i32,
        B: i32,
        C: i32,
        D: i32,
    }

    println!("{}", std::cmp::max(A * B, C * D));
}

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

long long x, y;
unsigned long long a, c;
long double b;

int main() {
  cin >> x >> b;
  a = x;
  assert(0 <= x && x <= (long long)(1e15));
  assert(0 <= b && b < 10);
  // cin >> a >> b;
  c = b * 1000ULL;
  a *= c;
  a /= 1000;
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 3728
///By the name of Almighty ALLAH///
#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n,k,i,d1,d2,d;
    cin>> k >> n;
    int ara[n];
    for(i=0;i<n;i++){        /// 5 14 16 21 25
        cin >> ara[i];
    }
    int last = ara[n-1];
    int fst = ara[0];
    d = last - fst;

    for(i=0;i<n;i++){
        if(i==0){
            d1 = last - fst;
            d2 = ara[i] + (k-ara[i+1]);
        }
        else if(i==n-1){
            d1 = last -fst;
            d2 = (k-last) + ara[i-1];
        }
        else{
            d1 = (last - ara[i]) + (k-last) + ara[i-1];
            d2 = ara[i] + (k-ara[i+1]);
        }
        d = min(d1,d);
        d = min(d2,d);
    }
    cout << d << endl;
}


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

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> x(N);
  for(int i=0;i<N;i++)cin >> x[i];
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=min(x[i],K-x[i]);
  }
  cout << 2*sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=200005;
int n,q,a,b,i,x[N];
ll add[N*5],mn1[N*5],mn2[N*5],ans=1ll<<60;
ll Abs(ll a)
{
	return a>0?a:-a;
}
void built(int o,int l,int r)
{
	if(l<=b&&r>=b)
		mn1[o]=-b,mn2[o]=b;
	else
		mn1[o]=mn2[o]=1ll<<60;	
	if(l==r)
		return;
	int mid=l+r>>1;
	built(o<<1,l,mid);
	built(o<<1|1,mid+1,r);
}
void pushdown(int o,int l,int r)
{
	add[o<<1]+=add[o],add[o<<1|1]+=add[o];
	mn1[o<<1]+=add[o],mn1[o<<1|1]+=add[o];
	mn2[o<<1]+=add[o],mn2[o<<1|1]+=add[o];
	add[o]=0;
}
void update(int o,int l,int r,int x,ll y)
{
	if(l==r)
	{
		mn1[o]=min(mn1[o],y-l),mn2[o]=min(mn2[o],y+l);
		return;
	}
	pushdown(o,l,r);
	int mid=l+r>>1;
	if(x<=mid)
		update(o<<1,l,mid,x,y);
	else
		update(o<<1|1,mid+1,r,x,y);
	mn1[o]=min(mn1[o<<1],mn1[o<<1|1]);
	mn2[o]=min(mn2[o<<1],mn2[o<<1|1]);
}
ll query1(int o,int l,int r,int x,int y)
{
	if(l>=x&&r<=y)
		return mn1[o];
	pushdown(o,l,r);
	int mid=l+r>>1;
	ll rtn=1ll<<60;
	if(x<=mid)
		rtn=query1(o<<1,l,mid,x,y);
	if(y>mid)
		rtn=min(rtn,query1(o<<1|1,mid+1,r,x,y));
	return rtn;
}
ll query2(int o,int l,int r,int x,int y)
{
	if(l>=x&&r<=y)
		return mn2[o];
	pushdown(o,l,r);
	int mid=l+r>>1;
	ll rtn=1ll<<60;
	if(x<=mid)
		rtn=query2(o<<1,l,mid,x,y);
	if(y>mid)
		rtn=min(rtn,query2(o<<1|1,mid+1,r,x,y));
	return rtn;
}
void work(int o,int l,int r)
{
	if(l==r)
	{
		ans=min(ans,mn1[o]+l);
		return;
	}
	pushdown(o,l,r);
	int mid=l+r>>1;
	work(o<<1,l,mid);
	work(o<<1|1,mid+1,r);
}
int main()
{
	scanf("%d%d%d%d",&n,&q,&a,&b);
	for(i=1;i<=q;++i)
		scanf("%d",x+i);
	x[0]=a;
	built(1,1,n);
	for(i=1;i<=q;++i)
	{
		ll w=min(x[i]+query1(1,1,n,1,x[i]),query2(1,1,n,x[i],n)-x[i]);
		add[1]+=Abs(x[i]-x[i-1]);
		mn1[1]+=Abs(x[i]-x[i-1]);
		mn2[1]+=Abs(x[i]-x[i-1]);
		update(1,1,n,x[i-1],w);
	}
	work(1,1,n);
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 19328
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m,x = LI()
    t = LI()
    a = collections.defaultdict(int)
    for c in t:
        a[c] = 1
    r = inf
    tr = 0
    for i in range(x+1,n):
        tr += a[i]
    r = tr
    tr = 0
    for i in range(x-1,-1,-1):
        tr += a[i]
    if r > tr:
         r = tr

    return r


print(main())




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

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

	int N,R;
	int i,j;
	int tmp;
	int answer;
	int counter=0;
	double ave;
	vector<int> given;

	cin >> N >> R;

	
	if(N>=10){
		answer=R;
	}else{
		answer=R+(100*(10-N));
	}
	cout << answer << endl;

	return 0;
}



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

int main()
{
	int n, k, r, s, p;
	string t;
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;

	long long ret = 0;
	for (int i = 0; i < n; ++i) {
		int point = 0;
		if (t[i] == 'r') {
			point = p;
		}
		else if (t[i] == 's') {
			point = r;
		}
		else {	// p
			point = s;
		}

		if (0 <= i - k && t[i] == t[i - k]) {
			point = 0;
			t[i] = 'n';
		}
		ret += point;
	}

	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 512
input_N = int(input())
p_list = list(map(int, input().split()))

cnt =1
for i in range(input_N-1):
    if p_list[i] > p_list[i+1]:
        cnt += 1
    else:
#         print(i)

        p_list[i+1] = p_list[i]
        
print(cnt)

Measured memory_bytes: 24872
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()
template<class T>
using reverse_priority_queue = priority_queue<T, vector<T>, greater<T>>;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){ cin >> a.at(i); }

    vector<ll> b = a;
    b.insert(b.end(), ALL(a));

    vector<ll> next_index(b.size(), -1);
    map<ll, ll> nmap;
    RREP(i, b.size()){
        const auto bi = b.at(i);
        if(nmap.count(bi)){
            const auto j = nmap[bi];
            if(j + 1 < 2 * n && next_index[j + 1] != -1){
                next_index[i] = next_index[j + 1];
            }else{
                next_index[i] = j + 1;
            }
        }
        nmap[bi] = i;
    }

    next_index.resize(n + 1);
    // cerr << "0 ";
    REP(i, n + 1){
        if(next_index.at(i) == -1){
            next_index.at(i) = i % n;
        }else{
            next_index.at(i) -= n;
        }
        assert(next_index.at(i) >= 0 && next_index.at(i) <= n);
        // cerr << next_index.at(i) << ' ';
    }
    // cerr << endl;

    vector<vector<ll>> next2p(42, vector<ll>(n + 1));
    next2p.at(0) = next_index;
    for(ll i = 1; i < next2p.size(); ++i){
        // cerr << i << ' ';
        REP(j, n + 1){
            const ll j2 = next2p.at(i - 1).at(j);
            next2p.at(i).at(j) = next2p.at(i - 1).at(j2);
            // cerr << next2p.at(i).at(j) << ' ';
        }
        // cerr << endl;
    }

    ll cur_idx = 0;
    k--;
    REP(i, next2p.size()){
        if((k >> i) & 1){
            cur_idx = next2p.at(i).at(cur_idx);
        }
    }

    // cerr << "cur_idx=" << cur_idx << endl;

    vector<ll> ans;
    set<ll> used;
    for(; cur_idx < n; ++cur_idx){
        const auto ai = a.at(cur_idx);
        if(used.count(ai)){
            while(used.count(ai)){
                used.erase(ans.back());
                ans.pop_back();
            }
        }else{
            ans.push_back(ai);
            used.insert(ai);
        }
    }

    REP(i, ans.size()){
        cout << ans.at(i);
        if(i + 1 < ans.size()){
            cout << ' ';
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 100156
#include<iostream>
#include<vector>
#include<bits/stdc++.h>
#define lli long long int
#define mod 1000000007
#define pb push_back
#define mk make_pair
#define fastio ios_base::sync_with_stdio(false); cout.tie(NULL);
using namespace std;

int main()
{
	fastio;
	lli n,i;
	cin>>n;
	lli a[n],cur_max,ans=0;
	for(i=0;i<n;i++)
		cin>>a[i];
	cur_max=a[0];
	for(i=1;i<n;i++)
	{
		if(a[i]<cur_max)
			ans+=max((lli)0,cur_max-a[i]);
		else if(a[i]>cur_max)
			cur_max=a[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 5204
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long c;
    cin >> c;
    int odd,even;
    if(c % 2){
        odd = c / 2 + 1;
        even = c / 2;
    }else{
        odd = c / 2;
        even = c / 2;
    }
    cout << odd * even;
    return 0;
}

Measured memory_bytes: 256
w, h, n = gets.split.map(&:to_i)

left = 0
bottom = 0
top = h
right = w

n.times do
  xi, yi, ai = gets.split.map(&:to_i)

  case ai
  when 1
    left = xi if left < xi
  when 2
    right = xi if right > xi
  when 3
    bottom = yi if bottom < yi
  when 4
    top = yi if top > yi
  else
  end
end

def calc_area(width, height)
  return 0 unless width > 0 && height > 0
  width * height
end

puts calc_area(right - left, top - bottom)


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
    char x,y;
    cin >> x >> y;
    if((int)x > (int)y){
        printf(">\n");
    }else if((int)x < (int)y){
        printf("<\n");
    }else{
        printf("=\n");
    }
    return 0;
}


Measured memory_bytes: 256
from collections import Counter, defaultdict
from itertools import product

H, W, N = map(int, input().split())

c = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    for dx, dy in product([-1, 0, 1], repeat=2):
        y = a - 2 + dy
        x = b - 2 + dx
        if 0 <= y < H - 2 and 0 <= x < W - 2:
            c[(x, y)] += 1

ans = Counter(c.values())
print((H - 2) * (W - 2) - sum(ans.values()))
for i in range(1, 10):
    print(ans[i])


Measured memory_bytes: 166868
N = int(input())
dp = [0] * (10**5+10)
for i in range(1,100005):
    dp[i] = float("inf")
    power = 1
    while power <= i:
        dp[i] = min(dp[i], dp[i-power]+1)
        power *= 6
    power2 = 1
    while power2 <= i:
        dp[i] = min(dp[i], dp[i-power2]+1)
        power2 *= 9

print(dp[N])


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

int main(){
  string s,t;
  cin >> s >> t;
  int n=s.size();
  int m=t.size();
  string ans="";
  for(int i=0;i<=n;i++){
    ans+='z';
  }
  for(int i=0;i<n-m+1;i++){
    bool check=true;
    for(int j=0;j<m;j++){
      if(s[i+j]!=t[j]&&s[i+j]!='?'){
        check=false;
      }
    }
    if(check){
      string u="";
      for(int j=0;j<i;j++){
        if(s[j]=='?'){
          u+='a';
        }
        else{
          u+=s[j];
        }
      }
      for(int j=i;j<i+m;j++){
        u+=t[j-i];
      }
      for(int j=i+m;j<n;j++){
        if(s[j]=='?'){
          u+='a';
        }
        else{
          u+=s[j];
        }
      }
      ans=min(ans,u);
    }
  }
  if(ans.size()==n){
    cout << ans << endl;
  }
  else{
    cout << "UNRESTORABLE" << endl;
  }
}

Measured memory_bytes: 256