akhauriyash/Code-Regression huggingface dataset:
from sys import exit, setrecursionlimit, stdin, stderr
from functools import reduce
from itertools import *
from collections import *
from bisect import *
from heapq import *
import operator
import math
from fractions import gcd
from random import randint

setrecursionlimit(10**8)

def input():
  return stdin.readline().strip()

def read():
  return int(input())
 
def reads():
  return [int(x) for x in input().split()]

N, K = reads()
A = reads()

skip = [-1] * (N + 1)
first_occ = {}
for i in range(N-1, -1, -1):
  a = A[i]
  if a in first_occ:
    if first_occ[a] < N-1:
      skip[i] = skip[first_occ[a] + 1]
    else:
      skip[i] = first_occ[a] + 1
  else:
    skip[i] = i
  first_occ[a] = i
skip[N] = N

back = [first_occ[A[i]] + 1 for i in range(N)] + [0]
next_state = [skip[back[q]] for q in range(N+1)]


q = skip[0]

rev = {}
memo = {}
i = 0
while True:
  if q in rev:
    j = rev[q]
    break
  rev[q] = i
  memo[i] = q
  q = next_state[q]
  i += 1

m = i - j
q = memo[j + (K - 1 - j) % m]

s = []
while q < N:
  if skip[q] == q:
    s.append(A[q])
    q += 1
  else:
    q = skip[q]

print(*s)

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

int main(){
    string s;
    cin >> s;
    stack<char> st;
    int ans = 0;
    for(char c : s){
        if(!st.empty() && c != st.top()){
            st.pop();
            ans += 2;
        }else{
            st.push(c);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env ruby


result = []
while true
    cards = gets.chomp
    if cards == "-" then
        break
    end
    loopnumber = gets.to_i
    loopnumber.times do
        shufflenumber = gets.to_i
        temp = cards * 2
        cards = temp.slice(shufflenumber,cards.length)
    end
    result << cards
end
puts result



Measured memory_bytes: 6916
// Shift and Flip
// * frank_c1
// * 2017 / 12 / 26

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

const int maxn = 2005;
const int INF = (int)(1e9);
char s[maxn];
int a[maxn], b[maxn];
int l[maxn], r[maxn];

struct node {
	int l, r, id;
} h[maxn];

bool operator < (node a, node b) {
	return a.l != b.l ? a.l < b.l : (a.r != b.r ? a.r < b.r : a.id < b.id);
}

int main() {
	scanf("%s", s);
	int n = strlen(s);
	for (int i = 0; i < n; ++i) a[i] = s[i] - '0';
	scanf("%s", s);
	for (int i = 0; i < n; ++i) b[i] = s[i] - '0';
	int ac = 0, bc = 0;
	for (int i = 0; i < n; ++i) if (a[i]) ac = 1;
	for (int i = 0; i < n; ++i) if (b[i]) bc = 1;
	if (ac && !bc) return printf("-1\n"), 0;
	if (!ac && !bc) return printf("0\n"), 0;
	for (int i = 0; i < n; ++i) {
		int p = i, l = 0, r = 0;
		while (!b[p]) {
			if ((--p)  < 0) p += n; ++l;
		} p = i;
		while (!b[p]) {
			if ((++p) >= n) p -= n; ++r;
		} h[i] = (node){l, r, i};
	}
	sort(h, h + n);
	int ret = INF;
	// left
	for (int c = 0; c < n; ++c) {
		int mx = 0, cnt = 0, tmp = INF;
		for (int i = n - 1; i >= 0; --i) 
			if (a[h[i].id] ^ b[(h[i].id + n - c) % n]) {
				int x = h[i].l, y = h[i].r; ++cnt;
				tmp = min(tmp, 2 * max(0, x - c) + c + 2 * mx);
				mx = max(mx, y);
			} 
		tmp = min(tmp, c + 2 * mx); ret = min(ret, tmp + cnt);
	}
	// right
	for (int c = 0; c < n; ++c) {
		int mx = 0, cnt = 0, tmp = INF;
		for (int i = n - 1; i >= 0; --i) 
			if (a[h[i].id] ^ b[(h[i].id + c) % n]) {
				int x = h[i].l, y = h[i].r; ++cnt;
				tmp = min(tmp, 2 * max(0, mx - c) + c + 2 * x);
				mx = max(mx, y);
			} 
		tmp = min(tmp, 2 * max(0, mx - c) + c); ret = min(ret, tmp + cnt);
	}
	return printf("%d\n", ret), 0;
}

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

int main () {

    int N;
    cin >> N;

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

    int ans = INT_MIN;

    for (int i = 0; i < (1 << N); i++) {

        int value = 0, cost = 0;

        for (int j = 0; j < N; j++) {
            if (i >> j & 1) {
                value += V[j];
                cost += C[j];
            }
        }

        ans = max(ans, value - cost);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef pair<int,int> P;
int dh[4] = {1, 0, -1 ,0};
int dw[4] = {0, 1, 0, -1};
const int INF=1e9+7;

int main() {
	int H,W;
	cin >> H >> W;
	vector<string> f(H);
	vector<vector<int>> d(H, vector<int>(W,INF));
	queue<P> q;
	P p;

	rep(i,H) {
		cin >> f.at(i);
		rep(j,W)
			if(f.at(i).at(j) == '#') {
				d.at(i).at(j) = 0;
				q.push(P(i,j));
			}
	}

	while(!q.empty()) {
		p = q.front();
		q.pop();

		rep(k,4) {
			int nh=p.first+dh[k], nw=p.second+dw[k];
			if(nh<0 || nw<0 || nh>=H || nw>=W || f.at(nh).at(nw)=='#' || d.at(nh).at(nw)!=INF)
				continue;
			d.at(nh).at(nw) = d.at(p.first).at(p.second)+1;
			q.push(P(nh,nw));
		}
	}

	cout << d.at(p.first).at(p.second) << endl;
}

Measured memory_bytes: 13456
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int count = Math.min(b, d) - Math.max(a, c);
		if (count < 0) {
			System.out.println(0);
		} else {
			System.out.println(count);
		}
	}
}

Measured memory_bytes: 21972
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;i++)

int N,C,X;
int D[30][39];
int t[3][30];

int main()
{
    scanf("%d%d",&N,&C);
    rep(i,C)rep(j,C) scanf("%d",&D[i][j]);
    rep(i,N)rep(j,N) scanf("%d",&X),t[(i+j)%3][X-1]++;
    int res = 1<<30;
    rep(i,C)rep(j,C) if(i!=j) rep(k,C) if(i!=k && j!=k)
    {
        int tt = 0;
        rep(l,C) tt += D[l][i]*t[0][l];
        rep(l,C) tt += D[l][j]*t[1][l];
        rep(l,C) tt += D[l][k]*t[2][l];
        if(tt < res) res = tt;
    }
    printf("%d\n",res);
}

Measured memory_bytes: 128
object Main extends App {
  val n = readInt
  val a = readLine.split(" ").map{_.toInt}
  
  if (n <= 2) println(1)
  else {
    //dp[i]; a0～a(i-1)までの最適な分け方
    val dp = Array.fill[(Int,Char)](n+1)((0,'='))
    //初期条件
    dp(1) = (1,'-')
    dp(2) = (if (a(0) < a(1)) (1,'+')
             else if (a(0) > a(1)) (1,'-')
             else (1,'='))
    var head = 0//区切りの先頭id
        
    for (i <- 2 to n-1) {
      if (head == i-1) 
        dp(i+1) = (if (a(head) < a(i)) (dp(i)._1,'+')
                   else if (a(head) > a(i)) (dp(i)._1,'-')
                   else (dp(i)._1,'='))
      else {
        dp(i)._2 match {
          case '+' if a(i-1) <= a(i) => dp(i+1) = dp(i)
          case '-' if a(i-1) >= a(i) => dp(i+1) = dp(i)
          case '=' if a(i-1) == a(i) => dp(i+1) = dp(i)
          case '=' if a(i-1) < a(i) => dp(i+1) = (dp(i)._1,'+')
          case '=' if a(i-1) > a(i) => dp(i+1) = (dp(i)._1,'-')
          case _ => {
            dp(i+1) = (dp(i)._1 + 1,'=')
            head = i
          }
        }
      }
    }
    println(dp(n)._1)
  }
}

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

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

	int l = 0, r = 0;
	REP(i, 0, N) {
		if (S[i] == '(') l++;
		else {
			if (l > 0) l--;
			else r++;
		}
	}
	REP(i, 0, l) S = S + ')';
	REP(i, 0, r) S = '(' + S;

	cout << S << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

ll gcd(ll a, ll b) {
    if (a<b) swap(a, b);
    while(b!=0) {
        ll t = a;
        a = b;
        b = t%b;
    }
    return a;
}

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

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int k; cin >> k;
    int n; cin >> n;
    vector<int> a(2*n+1, 0);
    for(int i=1; i<=n; ++i) cin >> a[i];
    for(int i=1; i<=n; ++i) a[i+n] = a[i] + k;

    int ans = k;
    for(int i=1; i<=n; ++i) chmin(ans, a[i+n-1]-a[i]);
    cout << ans << endl;
    
    return 0;
}


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

int main()
{
    int s, cnt = 0;

    cin >> s;
    
    if(s / 100) cnt++;
    if((s % 100) / 10) cnt++;
    if(s % 10) cnt++;

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define sor(v) sort(v.begin(),v.end())
#define sorrev(v) sort(v.begin(),v.end(),greater<ll>())
#define uni(v) unique(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 
auto random_address = [] { char *p = new char; delete p; return sll(p); };
const sll SEED = chrono::steady_clock::now().time_since_epoch().count() * (random_address() | 1);
mt19937_64 rng(SEED);

int main()
{
    string s;
    cin>>s;
    ll n=s.length();
    if(s[n-1]=='s')
        s=s+"es";
    else
        s=s+"s";
    cout<<s;
    return 0;
}


Measured memory_bytes: 3628
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  xs <- getc $ split toInt
  mapM_ putStrLn $ solve xs

solve :: [[Int]] -> [String]
solve = map card

card :: [Int] -> String
card [c1,c2,c3] = if l >= 4 then "YES" else "NO"
  where
    cs = [1..10] \\ [c1, c2, c3]
    l = length $ filter (\x -> c1 + c2 + x <= 20) cs

toInt :: String -> Int
toInt s = read s
split :: (String -> a) -> String -> [a]
split f = map f . words

getc :: (String -> a) -> IO [a]
getc f = map f . lines <$> getContents

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

int main() {
	set<string> hash;
	string str;
	int case_num = 0;
	cin >> case_num;
	for (int i = 0; i < case_num; ++i) {
		cin >> str;
		hash.insert(str);
	}
	cout << hash.size();
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAXN = 100010;
int n;
int A[MAXN];

void solve() {
  sort(A, A+n);
  ll ans = 0;
  vector<P> v;
  ll cur;
  if (A[n-1] < 0) {
    cur = A[n-1];
    for (int i=0;i<n-1;i++) {
      v.push_back(P(cur, A[i]));
      cur -= A[i];
    }
  } else if (A[0] > 0) {
    cur = A[0];
    for (int i=1;i<n-1;i++) {
      v.push_back(P(cur, A[i]));
      cur -= A[i];
    }
    v.push_back(P(A[n-1], cur));
    cur = A[n-1] - cur;
  } else {
    cur = A[n - 1];
    int i = 1;
    while (A[i] < 0) {
      v.push_back(P(cur, A[i]));
      cur -= A[i++];
    }
    ll cur2 = A[0];
    while (i < n - 1) {
      v.push_back(P(cur2, A[i]));
      cur2 -= A[i++];
    }
    v.push_back(P(cur, cur2));
    cur -= cur2;
  }
  cout << cur << endl;
  for (int i=0;i<v.size();i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}

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


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

int vmaxn(vector<int> v, int n) {
  sort(v.begin(), v.end());
  return v[v.size()-n];
}

int main() {
  int N; cin >> N;
  vector<int> A(N);
  rep(i, N) cin >> A[i];
  
  int a=vmaxn(A, 1), aa=vmaxn(A, 2);
  rep(i, N) {
    if(A[i] == a) cout << aa << endl;
    else cout << a << endl;
  }
  
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define int long long   // aaaaaaaaaaaaaaaaaa
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define allr(x) (x).rbegin(),(x).rend()
#define in(s,x) s.find(x) != s.end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define SIZE(buff) (sizeof(buff)/sizeof(buff[0]))
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<pair<int,int>> VPII;
const ll mod=1000000007;
const ll INF= 1LL<<60-1;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
template<typename T, typename U>ostream& operator << (ostream& os, pair<T, U>& pair_var)
{os << pair_var.first << " " << pair_var.second ;return os;}
template<class tContainer>
long long sum(tContainer const& iContainer) {return  std::accumulate(std::begin(iContainer), std::end(iContainer), 0LL);}
 
// head
 
 
int m,n,k,res,tmp,tmp2,tmp3,h,w,x,y;
VI a;
deque<PII> que;
string s;
VI b;
vector<PII> g[2100600];
//int b[2100000];
int c[210] = {};
int rui[210000];
set<int> ch;
const int CMAX = 10000000;
long long fact[CMAX] = {};
long long revFact[CMAX] = {};

void setFact(int N)
{
  fact[0] = 1;
  for (int i = 1; i<N; i++)
  {
    fact[i] = fact[i-1]*i;
    fact[i] %= mod;
  }
  revFact[N-1] = powmod(fact[N-1],mod-2);
  for (int i=N-2;i>=0;i--)
  {
    revFact[i] = revFact[i+1]*(i+1);
    revFact[i] %= mod;
  }
}

long long getC(int a, int b)
{
  if(a<b) return 0;
  return  (((fact[a] * revFact[b]) % mod) * revFact[a-b]) % mod;
}


signed main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  setFact(10000);
  rep(i,0,k){
  cout<<getC(n-k+1,i+1)*getC((i+1)+(k-i-1)-1,k-i-1)%mod<<endl;
  
  }
  
    
}

Measured memory_bytes: 53888
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie();
    string s;
    cin>>s;
    bool a = false, b = false;
    for(int i = 0; i < 3; i++){
        if(s[i] == 'A')
        a=true;
        else
        {
            b = true;
        }
        
    }
    if(a && b) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3620
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) 
{
	cout << *it << " = " << a;
	nl;
	err(++it, args...);
}
typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}
const int mod=1e9+7;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
ll binpow(ll a, ll b, ll m) 
{a %= m;b%=(m-1);ll res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1; }return res;}
void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,c,temp,x,y;
string str;
void solveforthiscase(const int & test)
{//deb(test);
cin>>n;
ll k;
cin>>k;
int count=0;
while(n)
{
    n/=k;
    count++;
}
cout<<count;







return ;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long int;
using namespace std;

int main() {
    fastio;
    int n;
    cin >> n;
    if (n < 1000)
        cout << "ABC";
    else
        cout << "ABD";
}


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



int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool valid = true;
    for(int i = 0; i < s.length(); i++){
        valid &= (i == a ? (s[i] == '-') : (isdigit(s[i])));
    }

    if(valid) cout << "Yes\n";
    else cout << "No\n";

    return 0;

}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define range(i, l, r) for(long long int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (long long int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    if (v.size() == 0) return os << "]";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    if (s.begin() == s.end()) return os << "}";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    if (m.begin() == m.end()) return os << "}";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

lint pow(lint num, lint e, lint MOD) {
    lint res = 1;
    lint cur_num = num;
    while (e) {
        if (e & 1) {
            res *= cur_num;
            res %= MOD;
        }
        cur_num *= cur_num;
        cur_num %= MOD;
        e >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    lint N; cin >> N;
    vec<lint> d(N);
    range(i, 0, N) cin >> d.at(i);
    lint ans = 0;
    range(i, 0, N - 1) range(j, i + 1, N) {
        ans += d.at(i) * d.at(j);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	static List<String> values = new ArrayList<>();

	public static void main(String[] args) throws IOException {
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String l1 = r.readLine();
		int p = Integer.parseInt(l1);

		System.out.println(p / 2 + p % 2);

		r.close();
	}
}

Measured memory_bytes: 22996
//@sakshjha
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define pi 3.14159265358979
const ll mod = 1000000007 ;
const ll N=500005;
int main()
{
    FAST
    ll t,i,j,k;
    //cin>>t;
    t=1;
    while(t--)
    {
        ll n,q;
        cin>>n;
        ll a[n];
        map<ll,ll>mp;
        ll sum=0;
        for(i=0; i<n; i++)
        {
            cin>>a[i];
            mp[a[i]]++;
            sum+=a[i];
        }
        cin>>q;
        while(q--)
        {
            ll u,v;
            cin>>u>>v;
            if(mp.find(u)==mp.end())
            {
                cout<<sum<<"\n";
            }
            else
            {
                ll cnt=mp[u];
                ll val=v-u;
                sum+=(cnt*val);
                mp.erase(u);
                mp[v]+=cnt;
                //cout<<cnt<<"\n";
                cout<<sum<<"\n";
            }
        }

    }
    return 0;
}
/*ll pow (ll x, ll y, ll m)
{
    ll res=1;
    x=x%m;
    if(x==0)
        return 0;
    while(y>0)
    {
        if(y&1)
        {
            res*=x;
            res%=m;
        }
        y=y/2;
        x=(x*x)%m;
    }
    return res;
}*/


Measured memory_bytes: 8400
#include <iostream>

using namespace std::literals;

namespace abc086
{
	namespace task_A
	{
		struct PairIntegers
		{
			public: unsigned int a;
			public: unsigned int b;

			private: unsigned int Product (/* no argument */)
			{
				return (this->a) * (this->b);
			}

			private: bool IsProductEven (/* No argument */)
			{
				return (this->Product() % 2U) == 0U;
			}

			public: void cin (/* No argument */)
			{
				std::cin >> this->a >> this->b;
			}

			public: void Answerer (/* No argument */)
			{
				if   ( this->IsProductEven() ) std::cout << "Even"s;
				else                           std::cout << "Odd"s;

				std::cout << "\n"s;
			}
		};
	} // namespace task_A
	
} // namespace abc086


int main (void)
{
	// variables for main process
	abc086::task_A::PairIntegers given_data;

	// STEP.01
	// read out the given data
	given_data.cin();

	// STEP.02
	// output the answer of this task
	given_data.Answerer();

	// STEP.END
	return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map>
#include <map>
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
using namespace std;

int main(){
	int a, b, h;

	cin >> a;
	cin >> b;
	cin >> h;

	int s;

	s = (a + b)*h / 2;

	cout << s;

	return 0;
}

Measured memory_bytes: 256
while true
  a = []
  a[0], l = gets.split.map(&:to_i)
  break if l == 0
  a[0] = "%0#{l}d" % a[0]
  (1..25).each do |i|
    a[i] = "%0#{l}d"  % (a[i-1].split(//).sort.reverse.join.to_i - a[i-1].split(//).sort.join.to_i)
    if a.index(a[i]) < i
      puts "#{a.index(a[i])} #{a[i].to_i} #{i - a.index(a[i])}"
      break
    end
  end
end

Measured memory_bytes: 6128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  int S= 0;
  for(int i = N ; i <= K ; i++){
    int r = i;
    int a, b, c, d, e;
    a = r / 10000;
    r = r % 10000;
    b = r / 1000;
    r = r % 1000;
    c = r / 100;
    r = r % 100;
    d = r / 10;
    e = r % 10;
    if( (a == e) && (b == d)){
      S++;
    //cout << a << " " << b << " " << c << " " << d << " " << e << endl;
    }
  }
  cout << S << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    int A, B; cin >> A >> B;
    if (A*B % 2 == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 256
/*input
9
BEWPVCRWH
ZZNQYIJX
BAVREA
PA
HJMYITEOX
BCJHMRMNK
BP
QVFABZ
PRGKSPUNA
*/

#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <math.h>
#include <iomanip>
#include <utility>
#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

ll MOD = 1000000007;
const int SINF = 1000000009;
const ll INF =  1000000000000000018;

#define sp          cout << " "
#define nl          cout << "\n"
#define inv(a)      powr((a), (MOD - 2))
#define all(c)      (c).begin(),(c).end()
#define rep(i,a,b)  for(ll i = (a); i < (b); i ++)
#define prec(n)     cout << fixed << setprecision(n)
#define PI          3.14159265358979323846264338327951
#define ifalse      ios_base::sync_with_stdio(false), cin.tie(NULL)

template<typename T> void toInt(string s, T &a) { istringstream(s) >> a; }
ll gcd(ll a, ll b) { ll t; while(a) { t = a; a = b%a; b = t; } return b; }
ll sub(ll a, ll b) { a -= b; a = (a + MOD) % MOD; return a; }
ll mul(ll a, ll b) { return ((a % MOD) * (b % MOD)) % MOD; }
ll add(ll a, ll b) { a += b; a %= MOD; return a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }

ll powr(ll a, ll b) {
  ll x = 1LL;
  while(b) {
    if(b & 1) x = mul(x, a);
    a = mul(a, a), b >>= 1;
  }
  return x;
}

bool check(ll n)
{
  if(n == 1) return 0;
  if(n == 2 or n == 3) return 1;
  if(n%2 == 0 or n%3 == 0) return 0;
  for(ll i = 5; i*i <= n; i += 6) if(n%i == 0 or n % (i+2) == 0) return 0;
  return 1;
}

/*********************************START**********************************/
const int N = 100005;

int main()
{
  ifalse;
  int n;
  cin >> n;
  int cnt = 0;
  vector < string > v1, v2, v3;
  int ans = 0;
  for(int i = 0; i < n; i ++) {
    string s;
    cin >> s;
    if(s[0] == 'B' and s[s.length() - 1] == 'A') {
      v3.push_back(s);
    }  
    else if(s[0] == 'B') {
      v1.push_back(s);
    }
    else if(s[s.length() - 1] == 'A'){
      v2.push_back(s);
    }
    for(int j = 1; j < s.length(); j ++) {
      if(s[j - 1] == 'A' and s[j] == 'B') {
        ans ++;
      }
    }
  }
  int a = v3.size();
  int b = v1.size();
  int c = v2.size();
  if(a > 0) {
    ans += (a - 1);
    if(c > 0) {
      ans ++;
      c --;
    }
    if(b > 0) {
      ans ++;
      b --;
    }
  }
  ans += (min(b, c));
  cout << ans;
  return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#include <climits>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const long double PI = acos(-1.0L);
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 MOD = 1000000007;
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void init_comb() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long comb(int n, int r) {
  if (n < r) return 0;
  if (n < 0 || r < 0) return 0;
  return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init_comb();
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll ans = 0;
  for (int i = 0; i+k <= n; i++)
    ans = (ans-a[i]*comb(n-i-1, k-1)%MOD+MOD)%MOD;
  for (int i = n-1; i-k+1 >= 0; i--)
    ans = (ans+a[i]*comb(i, k-1)%MOD+MOD)%MOD;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 13056
#include<iostream>
#include<vector>
#include<algorithm>
#define INF (1<<29)
#define all(c) (c).begin(),(c).end()
#define MAX_V 400
#define to first
#define cost second
using namespace std;

typedef pair<int,int> P;

vector<int>node;
vector<P>g[MAX_V];
bool used[MAX_V];
int G[MAX_V][MAX_V];

void Tsort(int v){
  used[v]=true;
  for(int i=0;i<g[v].size();i++)
    if(!used[g[v][i].to])Tsort(g[v][i].to);
  node.push_back(v);
}

int main(void){

  int n,m,a,b,c;
  cin >> n >> m;

  fill(G[0],G[MAX_V],0);

  for(int i=0;i<m;i++){
    cin >> a >> b >> c;
    g[a].push_back(P(b,c));
    G[a][b]=c;
  }

  fill(used,used+MAX_V,false);
  Tsort(0);
  reverse(all(node));

  int dp[MAX_V];
  fill(dp,dp+MAX_V,0);

  for(int i=0;i<node.size();i++){
    for(int j=i+1;j<node.size();j++){
      if(G[node[i]][node[j]]>0)
      dp[node[j]]=max(dp[node[j]],dp[node[i]]+G[node[i]][node[j]]);
    }
  }

  cout << dp[n-1] << endl;

  return 0;
}

Measured memory_bytes: 1872
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MaX 300005
using namespace std;
using namespace __gnu_pbds;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
   	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set; 
bool isprime(ll n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (ll i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
}
int main()
{
	ll a,b,ans;
	cin>>a>>b;
	ans=a*b;
	cout<<ans;
}

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

int main(){
    int A, B;
    cin >> A >> B;

    int ans = 0;
    for (int i = A; i <= B; i++)
    {
        string s = to_string(i);
        if ((s[0] == s[4]) && (s[1] == s[3]))
        {
            ans++;
        }
        
    }
    
    cout << ans << endl;
      
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast")
#define int long long 
#define ld long double
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define loop(i,l,r) for(int i=l;i<r;i++)
#define rloop(i,r,l) for(int i=r;i>=l;i--)
#define watch(x) cerr<<(#x)<<"= "<<(x)<<endl;
#define watcharr(a) cerr<<(#a)<<"("<<sz(a)<<")= ";rep(i,sz(a))cerr<<a[i]<<",";cerr<<'\n';
#define inf 2000000000000000000LL
#define mod 1000000007
#define mod1 998244353
#define FASTIO std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;

int n,k;
int a[405],pr[405];
int dp[405][405];

signed main() {
    FASTIO;
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    //     freopen("stderr.txt", "w", stderr);
    // #endif

    // int tt=1;
    // cin>>tt;
    // while(tt--){
        cin>>n;
        loop(i,1,n+1){
            cin>>a[i];
            pr[i]=pr[i-1]+a[i];
        }
        rep(i,n+1) rep(j,n+1) dp[i][j] = (i==j)? 0:inf;
        loop(len,1,n+1){
            loop(l,1,n+1){
                int r=min(n,l+len-1);
                loop(i,l,r){
                    dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+pr[r]-pr[l-1]);
                }
            }
        }
        // loop(i,1,n+1){ loop(j,1,n+1) cerr<<dp[i][j]<<' '; cerr<<endl;}
        cout<<dp[1][n]<<endl;
        
    // }
    cerr<<"Time Elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<" sec";
    return 0;   
}

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

using namespace std;

int main()
{
    int n, p;
    while (cin >> n >> p, n | p) {
        vector<int> candidates(n, 0);
        int wan = p;
        while (true) {
            for (size_t i = 0; i < candidates.size(); ++i) {
                auto & candidate = candidates[i];
                if (wan != 0) {
                    --wan;
                    ++candidate;
                } else {
                    if (candidate == p) {
                        cout << i;
                        goto game_end;
                    }
                    wan += candidate;
                    candidate = 0;
                }
            }
        }
game_end:
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N, A;
  cin>>N>>A;
  int rem = N %	500;
  if(rem <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define all(a) a.begin(),a.end()
#define mp make_pair
#define F first
#define S second

typedef long long ll;
typedef std::vector<int>vi;
typedef std::vector<string>vs;
typedef std::vector<double>vd;
typedef std::vector<ll>vll;
typedef vector<vi>vvi;
typedef vector<vvi>vvvi;
typedef vector<vll>vvll;
typedef std::pair<int,int>pi;
typedef vector<pi>vpi;
typedef vector<vpi>vvpi;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int x,y;
	cin>>x>>y;
	cout<<x+y/2;
	return 0;
}


Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
if c%b!=0:
    ex1=1
else :
    ex1=0
time1=int(c/b)+ex1
if a%d!=0:
    ex2=1
else:
    ex2=0
time2=int(a/d)+ex2
if time1>time2:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9188
n, a, b, c, d = map(int, input().split())
s = list(input())
a, b, c, d = a-1, b-1, c-1, d-1

# check no '##' s on the way
goal = max([c,d])
for x in range(a+1, goal):
  if s[x] == '#' and s[x+1] == '#':
    print('No')
    exit(0)

if c < d:
  print('Yes')
  exit(0)

for x in range(b, d+1):
  if s[x] == '.' and s[x+1] == '.' and s[x-1] == '.':
    print('Yes')
    exit(0)

print('No')


Measured memory_bytes: 4916
A, B, C = map(int, input().split())
K = int(input())


# C > B > A
for i in range(K):
    if C >= B and B > A:
        # C > B > A
        C = C * 2
    elif C >= A and A >= B:
        # C > A >= B
        B = B * 2
    elif (
        (A >= B and B >= C)
        or (B >= A and A >= C)
        or (A >= C and C >= B)
        or (B >= C and C >= A)
    ):
        # A > B > C, B > A > C, A > C > B, B > C > A
        C = C * 2

if C > B and B > A:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9196
from collections import Counter
N=int(input())
A=list(map(int,input().split()))
L=[i+A[i] for i in range(N)]
R=[i-A[i] for i in range(N)]
ans=0
Lc=Counter(L)
Rc=Counter(R)
for key,value in Lc.items():
    ans+=value*Rc.get(key,0)
print(ans)

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

using namespace std;

typedef long long int lli;

int main() {
    string s;

    cin >> s;
    int x = 0; 
    for (auto e: s) {
        if (e == 'x') x++;
    }

    cout << ((x<=7) ? "YES" : "NO") << endl;

    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;

		// discard first line.
		br.readLine();

		while ((line = br.readLine()) != null && !line.isEmpty()) {

			char[] msgrs = line.toCharArray();
			char[] msg = br.readLine().toCharArray();

			//infer
			for (int i = msgrs.length - 1; i >= 0; i--) {
				switch (msgrs[i]) {
					case 'J':
						msg = J(msg);
						break;
					case 'C':
						msg = C(msg);
						break;
					case 'E':
						msg = E(msg);
						break;
					case 'A':
						msg = A(msg);
						break;
					case 'M':
						msg = M(msg);
						break;
					case 'P':
						msg = P(msg);
						break;
				}
			}
			//ans.
			System.out.println(new String(msg));
		}
	} //end while

	//operation
	public static char[] J(char[] msg) {
		char[] _msg = new char[msg.length];
		for (int i = 0, j = 1; i < msg.length - 1; i++, j++) {
			_msg[j] = msg[i];
		}
		_msg[0] = msg[_msg.length - 1];
		return _msg;
	}

	public static char[] C(char[] msg) {
		char[] _msg = new char[msg.length];
		for (int i = 1, j = 0; i < msg.length; i++, j++) {
			_msg[j] = msg[i];
		}
		_msg[_msg.length - 1] = msg[0];
		return _msg;
	}

	public static char[] E(char[] msg) {
		int d;
		if (msg.length % 2 == 0) d = 0;
		else d = 1;
		for (int i = 0; i < msg.length / 2; i++) {
			int j = i + (msg.length / 2) + d;
			char c1 = msg[i];
			char c2 = msg[j];
			msg[i] = c2;
			msg[j] = c1;
		}
		return msg;
	}

	public static char[] A(char[] msg) {
		char[] _msg = new char[msg.length];
		for (int i = msg.length - 1, j = 0; i >= 0; i--, j++) {
			_msg[j] = msg[i];
		}
		return _msg;
	}

	public static char[] P(char[] msg) {
		for (int i = 0; i < msg.length; i++) {
			char c = msg[i];
			if ('0' <= c && c <= '9') {
				if (c == '0') msg[i] = '9';
				else msg[i]--;
			}
		}
		return msg;
	}

	public static char[] M(char[] msg) {
		for (int i = 0; i < msg.length; i++) {
			char c = msg[i];
			if ('0' <= c && c <= '9') {
				if (c == '9') msg[i] = '0';
				else msg[i]++;
			}
		}
		return msg;
	}

} //end main

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

int main() {
    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;

    vector<int> s(n + 1, 0);
    for (int i = 0; i < n; i++) {
        if (i + 1 < n && str[i] == 'A' && str[i + 1] == 'C') s[i + 1] = s[i] + 1;
        else s[i + 1] = s[i];
    }

    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << s[r - 1] - s[l - 1] << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
N = int(input())
a = list(map(int, input().split()))

if len(a)%2 != 0 :
  a.append(0)
a.sort(reverse=True)

sum = 0
for i in range(0, len(a), 2) :
  sum += (a[i]-a[i+1])
print (sum)


Measured memory_bytes: 38384
h,w=map(int,input().split())
sij=[["." for i in range(w+2)]]
sij+=[list("."+input()+".") for i in range(h)]
sij.append(["." for i in range(w+2)])
#print(*sij,sep='\n')
for i in range(1,h+1):
    for j in range(1,w+1):
        cnt=0
        if sij[i][j]=="#":
            continue
        for ii in range(-1,2):
            for jj in range(-1,2):
                if ii==jj==0:
                    continue
                if sij[i+ii][j+jj]=="#":
                    cnt+=1
        sij[i][j]=str(cnt)
for i in range(1,h+1):
    for j in range(1,w+1):
        print(sij[i][j],end="")
    print()

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,N;cin>>N;vector<int>A(N);
  for(i=0;i<N;i++)cin>>A.at(i);
  sort(A.begin(),A.end());
  for(i=1;i<N;i++){
    if(A.at(i-1)==A.at(i))break;
  }
  if(i==N)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int n, k, cost[100020], a[10020];
int do_job(int val, int kk, int p_val) {
	if(kk == 0) {
		return 0;
	}
	int javab = cost[p_val - kk] + abs(a[p_val - kk] - val);
	for(int i = p_val - kk + 1; i < p_val; i++) {
		javab = min(javab, cost[i] + abs(a[i] - val));
	}
	return javab;
}
int main() {
	cin >> n >> k;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		cost[i] = do_job(a[i], min(k, i), i);
	}
	cout << cost[n - 1];
}

Measured memory_bytes: 4068
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,m,d;
    double ans=0;
    cin>>n>>m>>d;
    if(d==0){
        rep(i,m-1){
            double a=1/(double)n;
            ans+=a;
        }
    }
    else {
        rep(i,m-1){
            double a=2*(double)(n-d)/(double)(n*n);
            ans+=a;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <stdio.h>
typedef long long ll;
typedef struct Seg
{
	ll s, e;
};
Seg mo[11];
ll dp[200100];
ll IDT[800100];
ll n, k;
ll MOD = 998244353;
ll base;
ll max(ll a, ll b) { return a > b ? a : b; }
void update(ll n, ll k)
{
	k = base + k;
	IDT[k] = n;
	k /= 2;
	while (k >= 1)
	{
		IDT[k] = (IDT[2 * k] + IDT[2 * k + 1]) % MOD;
		k /= 2;
	}
}
ll query(ll s, ll e, ll nodel, ll noder, ll node)
{
	if (noder<s || nodel>e) return 0;
	if (s <= nodel && noder <= e) return IDT[node];
	ll m = (nodel + noder) / 2;
	return (query(s, e, nodel, m, node * 2) + query(s, e, m + 1, noder, node * 2 + 1))%MOD;
}
int main()
{
	scanf("%lld %lld", &n, &k);
	for (base = 1; base < n; base *= 2);
	for (ll i = 1; i <= k; i++)
	{
		scanf("%lld %lld", &mo[i].s, &mo[i].e);
	}
	IDT[base] = 1;
	for (ll i = 1; i < n; i++)
	{
		for (ll j = 1; j <= k; j++)
		{
			ll s = mo[j].s;
			ll e = mo[j].e;
			IDT[base + i] += query(max(0, i - e), i - s, 0, base - 1, 1);
			IDT[base + i] %= MOD;
		}
		update(IDT[base + i], i);
	}
	printf("%lld", IDT[base + n - 1]);
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    ll ans=0;
    REP(i,N+1){
        if(i%3!=0&&i%5!=0) ans+=i;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
N, M, X = map(int, input().split())
money = [0] * N
A = [[0] * M for _ in range(N)]
for i in range(N):
    tmp = list(map(int, input().split()))
    money[i] = tmp[0]
    A[i] = tmp[1:]
# bit search
ans = 10**10
for i in range(2**(N)):
    books = []
    cost = 0
    for j in range(N):
        if i & (1 << j):
            books.append(j)
            cost += money[j]
    NowPower = [0] * M
    for b in books:
        for j in range(M):
            NowPower[j] += A[b][j]
    # check power
    flag = True
    for p in NowPower:
        if X > p:
            flag = False
    if flag:
        ans = min(ans, cost)

if ans == 10**10:
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define mem(s,t) memset(s,t,sizeof(s))
#define pb(s) push_back(s)
#define inf 0x3f3f3f3f
#define mn 100010
typedef long long ll;
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",(n-1)/2);
    return 0;
}



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

#define mod 1'000'000'007
typedef long long ll;

template <typename T>
void deb(initializer_list<T> l)
{
    for (auto &e : l)
        cout << e << ' ';
    cout << '\n';
}

void solve()
{
    char b;
    cin >> b;
    if (b == 'A')
        cout << 'T';
    if (b == 'T')
        cout << 'A';
    if (b == 'C')
        cout << 'G';
    if (b == 'G')
        cout << 'C';
}

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

    int t { 1 };
    //cin >> t;
    while (t--)
        solve();

    return 0;
}


Measured memory_bytes: 256