akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.trim_right();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, r) = parse_line!(usize, usize);

    let r = if n >= 10 { r } else { r + 100 * (10 - n) };

    println!("{}", r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
int main(){

	int N,K,R=0;
	string S;
	cin >> N >> K >> S;
	for (int i = 1; i < N; i++){
		if (S.at(i) == S.at(i-1) ){
			R++;
		}
	}
	R += K*2;
	if (R >= N) {
		R = N-1;
	}

	cout << R << endl;
	
}



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

int main() {
  int N; cin >> N;
  int A[N], B[N];
  for (int i=0; i<N-1; i++) cin >> A[i];
  for (int i=0; i<N; i++) {
    B[i] = 0;
  }

  for (int i=0; i<N-1; i++) {
    B[A[i]-1]++;
  }

  for (int i=0; i<N; i++) cout << B[i] << endl;

  return 0;
}


Measured memory_bytes: 5200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    vector<VL> num = { {0,1,2,3},{1,0,3,2},{2,3,0,1},{3,2,1,0} };
    vector<VL> m = { {1,1,1,1},{1,-1,1,-1},{1,-1,-1,1},{1,1,-1,-1} };

    while (1) {
        int n;
        cin >> n;
        if (n == 0)break;
        FOR(k, 0, n) {
            VL a(4), b(4);
            cin >> a; cin >> b;

            VL ans(4, 0);
            FOR(i, 0, 4)FOR(j, 0, 4) {
                ans[num[i][j]] += a[i] * b[j] * m[i][j];
            }

            FOR(i, 0, 4)cout << ans[i] << (i == 3 ? "\n" : " ");
        }
    }
    
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
  	cin>>n>>k;
  	int h[n];
  	for(int i=0;i<n;i++){
    	cin>>h[i];
    } 
  	int dp[n];
  	for(int i=0;i<n;i++){
      dp[i] = INT_MAX;
    }
  	for(int i=0;i<n;i++){
  	    if(dp[i]==INT_MAX)
  	        dp[i]=0;
      for(int j=1;j<=k;j++){
      	if(i+j<n)
          dp[i+j] = min(dp[i+j],dp[i]+abs(h[i]-h[i+j]));
      }
    }
  	cout<<dp[n-1]<<endl;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
//Write From this Line

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

	int M = -1e9;
	int m = 1e9;
	int mi = -1, Mi = -1;
	rep(i,n){
		if(chmin(m,a[i])) mi = i;
		if(chmax(M,a[i])) Mi = i;
	}
	if(M - abs(m) >= 0){
		// 全部正にする
		vector<P> ans(0);
		rep(i,n){
			ans.push_back({Mi+1,i+1});
		}
		// 全部正になった
		// 後は累積和
		for(int i = 1; i <= n-1; i++){
			ans.push_back({i,i+1});
		}
		cout << ans.size() << endl;
		for(P x: ans){
			cout << x.first <<" " << x.second << endl;
		}
	} else {
		vector<P> ans(0);
		rep(i,n){
			ans.push_back({mi+1,i+1});
		}
		// 全部負になった。
		for(int i = n; i >= 2; i--){
			ans.push_back({i,i-1});
		}
		cout << ans.size() << endl;
		for(P x: ans){
			cout << x.first <<" " << x.second << endl;
		}
		
	}
}


Measured memory_bytes: 3640
n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(0, n, 2):
    b.append(a[i])
b = list(reversed(b))
for i in range(1, n, 2):
    b.append(a[i])
if n % 2 == 0:
    b = list(reversed(b))
print(' '.join(list(map(str, b))))

Measured memory_bytes: 123220
import java.math.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int p[] = new int[n];
        int cnt = 1;
        ;
        for(int i=0;i<n;i++)
            p[i] = sc.nextInt();
        int tmp = p[0];
        for (int i = 1; i < n; i++) {
            if (tmp > p[i])
                cnt++;
            if (p[i] < tmp)
                tmp = p[i];
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 87260
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    string ans = "ai1333";
    ll x; cin >> x;
    ans += string(x/100,'3');
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3224
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

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

int main(){
  int mny = 100000;
  int i,j,n;
  int kiri[3],tmp,chk;

  scanf("%d",&n);
  rep(i,n){
    mny *= 1.05;
    chk = 0;
    tmp = mny;

    rep(j,3){ kiri[j] = tmp % 10; tmp /= 10;}
    rep(j,3) chk = chk * 10 + kiri[3-1-j];
    if(chk){ mny -= chk; mny += 1000;}
  }

  printf("%d\n", mny);

  return 0;
}

Measured memory_bytes: 0
n=int(input())
a=list(map(int,input().split()))
b=a[::-2]
if(n%2==1):c=a[1::2]
else:c=a[::2]
#print(b)
#print(c)
outp=str(b[0])
for i in range(1,len(b)):outp+=" "+str(b[i])
for i in range(len(c)):outp+=" "+str(c[i])
print(outp)

Measured memory_bytes: 26180
#include <stdio.h>
#include <stdlib.h>

int main(){
    int X,Y;
    scanf("%x%x",&X,&Y);
    
    
    if (X > Y) {
        printf(">");
    }else if(X < Y){
        printf("<");
    }else{
        printf("=");
    }
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >>m;
    int count_ac=0;
    int count_pn=0;
    vector<bool> l(n,false);
    vector<int> k(n,0);

    for(int i=0;i<m;i++){
        int p;
        string s;
        cin >> p >> s;
        p=p-1; 
        if(l.at(p)){
            continue;
        }
        if(s=="AC"){
            l.at(p) = true;
            count_pn += k.at(p);
            count_ac++;
        }        
        else if(s=="WA"){
            k.at(p)++;
        }
    }

    cout << count_ac << " " << count_pn << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    string str;
    int n,k;
    int a[100000];
    int sum = 0;
    cin >> n >> k;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if(n == k) 
    {
        cout << 1 << endl;
    }
    else
    {
        int i = n - k;
        int j = i % (k-1);
        i = i / (k-1);
        if(j == 0) {
            cout << i+1 << endl;
        }
        else {
            cout << i+2 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 640
(defun walk ()
  (let* ((n (read))
        (min-w (1- n))
        (root (isqrt n)))
    (do* ((i 2 (1+ i))
         (j (floor n i) (setf j (floor n i))))
        ((> i root) (format t "~d" min-w))
        (if (= n (* i j)) 
            (if (< (+ i j -2) min-w) (setf min-w (+ i j -2)))))))

(walk)

Measured memory_bytes: 6504
#include <iostream>
#include <queue>
using namespace std;
int main(){
    queue <char> sq;
    string s;
    cin >> s;
    int count = 0 , size = s.length();
    bool firstupper = false , upper = true;
    for (int i = 0 ; i < size ; i++)
        sq.push(s[i]);
    if (isupper(sq.front())) firstupper = true;
    sq.pop(); sq.pop();
    for (int i = 0 ; i < size ; i++){
        if (sq.front() == 'C') count++;
        sq.pop();
    }
    for (int i = 0 ; i < size ; i++){
        if (isupper(s[i]) and s[i] != 'A' and s[i] != 'C') upper = false;
    }
    if (upper and firstupper and count == 1 and s[1] != 'C' and s[size-1] != 'C') cout << "AC";
    else cout << "WA";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
W = [input() for i in range(n)]

D = set()
ls = W[0][-1]
D.add(W[0])
for i in range(1, n):
    if ls == W[i][0] and not W[i] in D:
        D.add(W[i])
        ls = W[i][-1]
    else:
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 3064
def main():
    
    n,m = map(int,input().split())
    l = list(input())[::-1]
    ans = []
    i = 0
    l[0] = 0

    while i < n+1:
        if l[i] == 0:
            a = -1
            for j in range(m,0,-1):
                if i+j < n+1 and l[i+j] != "1":
                    a = i+j
                    ans.append(j)
                    l[a] = 0
                    break
            if a == -1:
                print(-1)
                exit()
            else:
                i = a
            
            if l[-1] == 0:
                break
    
    print(*ans[::-1])

if __name__ == "__main__":
    main()


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

using namespace std;

template<typename T> std::ostream& operator<<(std::ostream&o, const std::vector<T>&t) {
	// this way helps deal with empty vector
	for (size_t i = 0; i < t.size(); ++i) {
		o << t[i] << " \n"[i == t.size() - 1];
	}
	return o;
}

int N;
vector<int> a;
void solve(){
	cin>>N;
	a.reserve(N);
	for (int i=0;i<N;i++){
		int x;
		cin>>x;
		a.push_back(x);
	}
	int rMax = *max_element(a.begin(), a.end());
	int rMin = rMax;
	int rX = -1;
	for (int i=0;i<N;i++){
		if (a[i]!=rMax){
			int t;
			if (a[i]<=(rMax+1)/2){
				t = a[i];
			}
			else{
				t = rMax - a[i];
			}
			if (rMin>rMax/2 -t){
				rMin = rMax/2-t;
				rX = a[i];
			}
		}
	}
	cout<<rMax<<' '<<rX<<endl;
}

int main(){
// 	freopen("in.txt","r",stdin);
// 	freopen("out.txt","w",stdout);
	std::ios::sync_with_stdio(false);

		solve();

	return 0;
}



Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

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

//組み合わせ　初期化は0で　初期値1
ll dp[100010][4];

//解説AC
//https://atcoder.jp/contests/abc104/submissions/2955456

//1. 状態["","A","AB","ABC"]
//2. 順序 後ろから

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

  string s;
  cin >> s;
  int n = s.size();

  
  dp[n][3] = 1;
  ROF(i, n-1, 0){
    ROF(j, 3, 0){      
      if(s[i] == '?'){
	dp[i][j] = dp[i+1][j]*3LL;
      }
      else{
	dp[i][j] = dp[i+1][j]*1LL;
      }      
      if(j < 3){
	if(s[i] == '?' || s[i] == "ABC"[j]){
	  dp[i][j] += dp[i+1][j+1];
	}
      }
      dp[i][j] %= MOD;      
    }
  }

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


Measured memory_bytes: 3664
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;

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

	int len = n.length();
	int sum = 0;
	rep(i, len) {
		sum += n[i] - '0';
	}
	int ans = stoi(n);
	if (ans % sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
// B - Frog 2
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define chmin(x,y) x=min(x,y)

int main(){
	int INF = 1e+9, N,K; cin>>N>>K;
	vector<int> H(N), dp(N, INF);
	rp(i, 0, N) cin>>H[i]; // i:[0,N-1]
	dp[0] = 0;
	rp(i, 1, N){ // i:[1,N-1]
		for(int j=i-1; j>=max(0,i-K); --j) // j:i-k:[i-1,max(0,i-K)]
				chmin(
					dp[i],
					dp[j] + abs(H[j] - H[i])
				);
	}
	cout<< dp[N-1] <<endl;
}


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

int cnt[505][505];

int main() {
  int n,m,q;
  cin>>n>>m>>q;
  rep(i,m) {
    int l,r;
    cin>>l>>r;
    l--; r--;
    for (int j=0; j<=l; j++) {
      cnt[j][r]++;
    }
  }
  rep(i,n) {
    rep(j,n-1) {
      cnt[i][j+1]+=cnt[i][j];
    }
  } 
  rep(i,q) {
    int p,q;
    cin>>p>>q;
    p--; q--;
    cout<<cnt[p][q]<<endl;
  }
  return 0;
}




Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
long long n,m,u,v,s1,s2,mn=INT_MAX,b[701];
bool a[701][701],s[701],t[701];
inline long long read()
{
    long long sum=0,x=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
	{
        if (ch=='-')
          x=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9')
	{
        sum=sum*10+ch-'0';
        ch=getchar();
    }
    return sum*x;
}
inline void write(long long x)    
{
    if (x<0)
    {
    	putchar('-');
    	x=-x;
	}
	if (x>9)
      write(x/10);
    putchar(x%10+'0');
}
inline void dfs(int x,int y)
{
	b[x]=y;
	if (y==1)
	  ++s2;else
	  ++s1;
    for (register int i=1;i<=n;++i)
    {
    	if (x==i||a[x][i])
    	  continue;
    	if (!b[i])
    	  dfs(i,-y);else
    	if (b[i]==y)
    	{
    		write(-1);
    		exit(0);
		}
	}
}
int main()
{
	n=read();m=read();
	for (register int i=1;i<=m;++i)
	{
		u=read();v=read();
		a[u][v]=true;
		a[v][u]=true;
	}
	s[0]=true;
	for (register int i=1;i<=n;++i)
	{
		if (b[i])
		  continue;
		s1=0;s2=0;
		dfs(i,1);
		memset(t,0,sizeof(t));
		for (register int j=0;j<=n;++j)
		{
			t[j+s1]=t[j+s1]|s[j];
			t[j+s2]=t[j+s2]|s[j];
		}
		memcpy(s,t,sizeof(t));
	}
	for (register int i=0;i<=n;++i)
	  if (s[i])
	    mn=min(mn,(i*(i-1)/2)+((n-i)*(n-i-1)/2));
	write(mn);
	return 0;
}

Measured memory_bytes: 4116
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long int sum=0;
    for(int i=1;i<=n;i++)
    {
	if(i%3==0&&i%5==0){
	    continue;
	}
	else if(i%3==0)
	{
	    continue;
	}
	else if(i%5==0)
	{
	    continue;
	}
	else if(i%3!=0&&i%5!=0)
	    sum+=i;
    }
    cout<<sum;
}


Measured memory_bytes: 3620
N, M, K = list(map(int, input().split()))
mod = 998244353

c = 1
answer = 0

for i in range(K+1):
    answer += (M * c  * pow(M-1, N - i - 1, mod)) % mod
    answer %= mod
    c = (c * (N-i-1) * pow(i+1, mod-2, mod)) % mod
    
print(answer)

Measured memory_bytes: 9100
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val sx = sc.nextInt()
    val sy = sc.nextInt()
    val tx = sc.nextInt()
    val ty = sc.nextInt()

    val dy = Math.abs(ty - sy)
    val dx = Math.abs(tx - sx)
    val answer = (1..dy).toList().map { "U" } + (1..dx).map { "R" } + // route1
            (1..dy).toList().map { "D" } + (1..dx).map { "L" } + // route2
            listOf("L") + (1..dy + 1).toList().map { "U" } + (1..dx + 1).map { "R" } + listOf("D") + // route3
            listOf("R") + (1..dy + 1).toList().map { "D" } + (1..dx + 1).map { "L" } + listOf("U") // route4
    println(answer.joinToString(""))
}

Measured memory_bytes: 31516
n = int(input())

e = [0] * 101

for x in range(2, n + 1):
    d = 2
    while x > 1:
        c = 0
        while x % d == 0:
            x //= d
            c += 1
        e[d] += c
        d += 1


# 75
# 25 3
# 15 5
# 5 5 3

def f(n, e=e):
    return len(tuple(filter(lambda x: x >= n - 1, e)))


ans = f(75) + f(25) * (f(3) - 1) + f(15) * (f(5) - 1) + f(5) * (f(5) - 1) // 2 * (f(3) - 2)
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

int main()
{
  int X;
  cin >> X;
  int ans = 0;
  for(int b = 1; b < 1000; ++b){
    for(int p = 2; p <= 10; ++p){
      if(pow(b,p) <= X){
        ans = max(ans, (int)pow(b,p));
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-

n = input()
a = map(int, raw_input().split())
b = a
asum = [0]*len(a)
bsum = [0]*len(a)

asum[0] = a[0]
bsum[0] = b[0]
cnt_a = 0
cnt_b = 0
if(a[0]==0):
    asum[0] = 1
    cnt_a = 1
    bsum[0] = -1
    cnt_b = 1

if(a[0]<0):
    cnt_a += (-1)*a[0]+1
    asum[0] = 1
for i in range(len(a)-1):
    asum[i+1] = a[i+1] + asum[i]
    if(i%2==0 and asum[i+1]>=0):
        cnt_a += asum[i+1]+1
        asum[i+1] = -1
    elif(i%2==1 and asum[i+1]<=0):
        cnt_a += (-1)*asum[i+1]+1
        asum[i+1] = 1
if(b[0]>0):
    cnt_b += b[0]+1
    bsum[0] = -1
for i in range(len(b)-1):
    bsum[i+1] = b[i+1] + bsum[i]
    if(i%2==0 and bsum[i+1]<=0):
        cnt_b += (-1)*bsum[i+1]+1
        bsum[i+1] = 1
    elif(i%2==1 and bsum[i+1]>=0):
        cnt_b += bsum[i+1]+1
        bsum[i+1] = -1
print(min(cnt_a,cnt_b))

Measured memory_bytes: 12552
#[allow(unused_imports)]
use {
   proconio::{fastout, input, marker::*},
   std::cmp::*,
   std::collections::*,
};

#[fastout]
fn main() {
   input! {
      n: usize,
      mut l: [usize;n]
   }
   l.sort();
   let mut ans = 0;
   for i in 0..n {
      for j in i+1..n {
         if l[i] == l[j] {
            continue;
         }
         for k in j+1..n {
            if l[j] == l[k] {
               continue;
            }
            if l[i] + l[j] > l[k] {
               ans += 1;
            }
         }
      }
   }
   println!("{}", ans);
}


Measured memory_bytes: 2180
#include "bits/stdc++.h"
using namespace std;
#define max(a, b) (a < b ? b : a)
#define min(a, b) ((a > b) ? b : a)
#define mod 1e9 + 7
#define FOR(a, c) for (int(a) = 0; (a) < (c); (a)++)
#define FORL(a, b, c) for (int(a) = (b); (a) <= (c); (a)++)
#define FORR(a, b, c) for (int(a) = (b); (a) >= (c); (a)--)
#define INF 1000000000000000003
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define F first
#define S second
#define PB push_back
#define POB pop_back
#define MP make_pair
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
int i,k;
cin>>k;
string s;
cin>>s;
int x=s.length();
if(k>x)
k=x;
for(i=0;i<k;i++)
{
	cout<<s[i];
}
if(k<x)
cout<<"...";

    return 0;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

void OutputError(std::string s) {
  cerr << "\033[93m" << s << "\033[m" << endl;
  return;
}

int main(void) {
  cout << std::fixed << std::setprecision(10);
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int64_t k, a, b;
  int64_t result = 0;
  cin >> k >> a >> b;
  if (b - a >= 3) {
    if (k - (a - 1) >= 0) {
      result += a;
      k -= (a - 1);
      if (k >= 2) {
        if (k % 2 == 0) {
          result += k / 2 * (b - a);
        } else {
          result += k / 2 * (b - a) + 1;
        }
      } else {
        result++;
      }
    } else {
      result = k + 1;
    }
  } else {
    result = k + 1;
  }
  cout << std::max(result, k + 1) << endl;

  return 0;
}


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

typedef unsigned long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

int main(){
    ll n;
    cin >> n;
    ll rt = sqrt(2*n);
    ll k = 0;

    if(rt*(rt+1) == 2*n) k = rt+1;
    else if(rt*(rt-1) == 2*n) k = rt;

    if(k == 0){
        cout << "No" << endl;
    } else {
        vector<int> ans[k];
        for(int i = 1; i <= n; i++){
            ll first = (i-1)%k;
            ll second = ((i+k-1)/k+((i-1)%k))%k;
            ans[first].push_back(i);
            ans[second].push_back(i);
        }
        cout << "Yes" << endl;
        cout << k << endl;
        for(int i = 0; i < k; i++){
            cout << k-1;
            for(int j = 0; j < k-1; j++){
                cout << " " << ans[i][j];
            }
            cout << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
#include<algorithm>
#include<list>
#include <string>
using namespace std;

int main(){
    string a;
    string b;
    cin >> a;
    cin >> b;
    
    for(int i = 0; i < a.length()+b.length();i++){
        if(i==0)cout << a.substr(0,1);
        else if(i==1)cout << b.substr(0,1);
        else if(i%2!=1)cout << a.substr(i/2,1);
        else cout << b.substr(i/2,1);
    }
    cout << endl;
    
    return 0;

    
}

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

typedef long long int ll;

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin >> n;
    
    ll a[n];
    for (ll i=0 ; i<n ; i++) {
		cin >> a[i];
	}
	
	ll maxEle = a[0];
	ll ans = 0;
	
	for (ll i=1 ; i<n ; i++) {
		if (a[i]<maxEle) {
			ans += (maxEle -a[i]);
		}
		else {
			maxEle = a[i];
		}
	}
	
	cout << ans << "\n";
}


Measured memory_bytes: 5216
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Scanner;
public class Main {
	Scanner sc = new Scanner(System.in);
	 
	public static void main(String[] args) {
		new Main().AOJ0053();
	}
	
	
	void AOJ0053(){
		ArrayList<Integer> primes = primeTable(1000000);
		while(true){
			int ans = 0;
			
			int input = sc.nextInt();
			if(input == 0)break;
			
			for(int i = 0; i < input;i++){
				ans += primes.get(i);
			}
			
			System.out.println(ans);
		}
	}
	
	
	
	ArrayList<Integer> primeTable(int n){
		boolean[] table = new boolean[n];
		for(int i = 0; i < table.length; i++){
			table[i] = true;
		}
		
		table[0] = false;
		table[1] = false;
		
		for(int i = 2; i*i < n; i++){
			if(table[i] == false)continue;
			for(int j = i*2; j < n; j += i){
				table[j]=false;
			}
		}
		
		
		ArrayList<Integer> primelist = new ArrayList<Integer>();
		for(int i = 0; i < n; i++){
			if(table[i] == true)primelist.add(i);
		}
		return primelist;
	}
}

Measured memory_bytes: 24864
import java.util.Scanner;
 
class Node{
    int id;
    int parent, left, right;
    public Node(int id){
        this.id = id;
        this.parent = -1;
        this.left = -1;
        this.right = -1;
    }
}
class Nodes{
    Node[] nodes;
    public int getDepth(int id){
        int d = 0;
        int u = nodes[id].parent;
        while(u != -1){
            u = nodes[u].parent;
            d++;
        }
        return d;
    }
    public void printChildren(int id){
        int c = nodes[id].left;
        while(c!=-1){
            System.out.print(c);
            c = nodes[c].right;
            if(c!=-1) System.out.print(", ");
        }
    }
    public void printNode(int id){
        System.out.print("node " + id + ": ");
        System.out.print("parent = " + nodes[id].parent + ", ");
        System.out.print("depth = " + getDepth(id) + ", ");
        if(nodes[id].parent == -1)
            System.out.print("root, ");
        else if(nodes[id].left == -1)
            System.out.print("leaf, ");
        else
            System.out.print("internal node, ");
        System.out.print("[");
        printChildren(id);
        System.out.println("]");
    }
}
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
         
        Nodes mynodes = new Nodes();
        Node[] nodes = new Node[n];
        mynodes.nodes = nodes;
        for(int i = 0;i<n;i++){
            nodes[i] = new Node(i);
        }
        int l = 0;
        for(int i=0;i<n;i++){
            int id = in.nextInt();
            int k = in.nextInt();
            for(int j=0;j<k;j++){
                int c = in.nextInt();
                if(j==0){
                    nodes[id].left = c;
					l = c;
                }
                else{
					nodes[l].right = c;
                	l = c;
				}
                nodes[c].parent = id;
            }
        }
        for(int j=0;j<n;j++){
            mynodes.printNode(j);
        }
    }
}

Measured memory_bytes: 131024
fun main(args: Array<String>) {
    val s = readInputLine().toCharArray()
    var K = readInputLine().toInt()
    
    for ((i, c) in s.withIndex()) {
        if (s[i] != 'a' && K >= ('z' - c) + 1) {
            s[i] = 'a'
            K -= ('z' - c) + 1
        }
    }
    
    s[s.size - 1] = (((s[s.size - 1] - 'a').toInt() + K) % ('z' - 'a' + 1).toInt() + 'a'.toInt()).toChar()

    println(s.joinToString(""))
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main(){
  string a,b,u;
  int a1,b1;
  cin>>a>>b>>a1>>b1>>u;
  if(a==u){
    cout<<a1-1<<" "<<b1<<endl;
  }else{
    cout<<a1<<" "<<b1-1<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
#define EPS 1e-10
using namespace std;
int n;

double add(double a ,double b){
  if(abs(a+b)<EPS*(abs(a)+abs(b)))return 0;
  return a+b;
}

class P{
public:
  double x,y;

  P(){}
  P(double x,double y):x(x),y(y){}

  P operator + (P p){
    return P(add(x,p.x),add(y,p.y));
  }
  P operator - (P p){
    return P(add(x,-p.x),add(y,-p.y));
  }
  P operator * (double d){
    return P(x*d,y*d);
  }
  double dot(P p){
    return add(x*p.x,y*p.y);
  }
  double det(P p){
    return add(x*p.y,-y*p.x);
  }
};
  bool cmp_x(const P& p,const P& q){
    if(p.x != q.x)return p.x < q.x;
    return p.y < q.y;
  }

vector<P> convex_hull(vector<P> ps,int n){

  sort(ps.begin(),ps.end(),cmp_x);
  int k = 0;
  vector<P> qs(2*n);
  for(int i = 0 ; i < n ; i++ ){
    while( k > 1 && (qs[k-2]-qs[k-1]).det(qs[k-1]-ps[i])<= 0)k--;
    qs[k++] = ps[i];
  }
  for(int i = n-2 ,t = k ; i >= 0 ; i--  ){
    while(k > t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0)k--;
    qs[k++] = ps[i];
  }
  qs.resize(k-1);
  return qs;
}

int main(){
  while( cin >> n , n){
    vector<P>p;
    p.clear();
    for(int i = 0 ; i < n ; i++ )
      {
	double a,b;
	char c; 
	cin >> a >> c >> b;
	p.push_back(P(a,b));
      }

    vector<P> q = convex_hull(p,n);
    cout <<  p.size() - q.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>
 
int main(void)
{
	char str[11] = { 0 };
	char str2[11] = { 0 };
	int i;
	int j=0;
 
	scanf("%s", str);
 
	for (i = 0;i < 10;i++)
	{
		if (str[i] == '0')
        {
			str2[j] = '0';
			j = j + 1;
		}
		else if (str[i] == '1')
		{
			str2[j] = '1';
			j = j + 1;
		}
		else if (str[i] == 'B')
		{
			if (j != 0)
			{
				j = j - 1;
				str2[j] = '\0';
 
			}
			
		}
	}
	printf("%s", str2);
 
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll x,y;

int main(void){
	scanf("%lld%lld",&x,&y);
	if(x%y==0LL){
		puts("-1");
		return 0;
	}else{
		printf("%lld\n",x);
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

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

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int n = sc.nextInt();
		int l = sc.nextInt();
		
		String[] s = new String[n];
		
		for(int i = 0; i < n; i++) s[i] = sc.next();
		
		Arrays.sort(s);
		StringBuilder sb = new StringBuilder();
		
		for(int i = 0; i < n; i++) sb.append(s[i]);
		
		out.println(sb.toString());
		
	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}

	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21204
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n,m;
vector<vector<int> > to;

int main(){
  cin >> n >> m;
  vector<int> ans(n,-1);
  ans[0]=0;
  to.resize(n);
  rep(i,m){
    int a,b;
    cin >> a >> b;
    a--; b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  queue<int> q;
  q.push(0);
  while(q.size()){
    int v=q.front(); q.pop();
    for(auto nv:to[v]){
      if(ans[nv]!=-1) continue; 
      ans[nv]=v;
      q.push(nv);
    }
  }
  bool f=1;
  rep(i,n){
    if(i==0) continue;
    if(ans[i]==-1) f=0;
  }
  if(f==0){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  rep(i,n){
    if(i==0) continue;
    cout << ans[i]+1 << endl;
  }
}


Measured memory_bytes: 10344
#include<bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mll map<ll,ll>
#define sll set<ll>
#define fo(i,n) for(i=0;i<n;i++)
#define MOD 1000000007
using namespace std;

int main()
{
    ios::sync_with_stdio(false);

    #ifdef UJJWAL_HOME
        freopen("000.txt","r",stdin);
    #endif

    ll n,i,j,k,t,q,h,s,d;

    cin>>q>>h>>s>>d>>n;

    ll mi=n*4*q;

    mi=min(mi,n*2*h);
    mi=min(mi,n*s);
    if(n%2==0)
        mi=min(mi,d*n/2);
    else
        mi=min(mi,(n-1)/2*d+min(s,min(2*h,4*q)));

    cout<<mi;

    return 0;
}


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

int main()
{
    int N = 0;
    cin >> N;
    int64_t sum = 0;
    vector<int64_t> arr(N);
    for (int i = 0; i < N; i++)
    {
        cin >> arr.at(i);
        sum += arr.at(i);
    }
    sort(arr.begin(), arr.end());
    cout << arr.at(0) << " ";
    cout << arr.at(N - 1) << " ";
    cout << sum << endl; 
}


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

int main(){
    string s;
    cin >> s;
    auto a = s[0];
    if(s[1] == a && s[2] == a)
        cout << "No" << endl;
    else
    {
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(void)
{
	vector<int> twoThrow;
	int n;
	int m;
	int point[1000];
	int ans;
	
	while (1){
		twoThrow.clear();
		
		scanf("%d%d", &n, &m);
		
		if (n == 0){
			break;
		}
		
		for (int i = 0; i < n; i++){
			scanf("%d", &point[i]);
		}
		
		
		twoThrow.push_back(0);
		for (int i = 0; i < n; i++){
			twoThrow.push_back(point[i]);
			for (int j = i; j < n; j++){
				twoThrow.push_back(point[i] + point[j]);
			}
		}
		sort(twoThrow.begin(), twoThrow.end());
		
		int t;
		ans = 0;
		for (int i = 0; i < twoThrow.size(); i++){
			vector<int>::iterator it = upper_bound(twoThrow.begin(), twoThrow.end(), m - twoThrow[i]);
			if (it == twoThrow.begin()){
				continue;
			}
			it--;
			t = *it;
			if (ans < t + twoThrow[i]){
				ans = t + twoThrow[i];
			}
		}
		
		printf("%d\n", ans);
	}
	
	return (0);
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int a, b, c;
  cin>>a>>b>>c;
  repn(i, 1, 100)
  {
    int z = a*i - c;
    if(z %b == 0) {
      puts("YES");
      return 0;
    }
  }
  puts("NO");
  return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define dump(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<int> x(N);
  REP(i, N) cin >> x[i];
  int ans = 1e9;
  int l = 0;
  int r = K - 1;
  for(; l < N - K + 1; l++) {
    r = l + K - 1;
    int temp = 0;
    if(x[l] < 0 && x[r] > 0) {
      temp = x[r] - x[l] + min(x[r], -x[l]);
    } else {
      temp = max(abs(x[l]), abs(x[r]));
    }
    ans = min(ans, temp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
// C++ code to find number of distinct numbers 
// in a subarray 
#include<bits/stdc++.h> 
using namespace std; 

const int MAX = 1000001; 

// structure to store queries 
struct Query 
{ 
	int l, r, idx; 
}; 

// cmp function to sort queries according to r 
bool cmp(Query x, Query y) 
{ 
	return x.r < y.r; 
} 

// updating the bit array 
void update(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

// querying the bit array 
int query(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void answeringQueries(int arr[], int n, Query queries[], int q) 
{ 
	// initialising bit array 
	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	// holds the rightmost index of any number 
	// as numbers of a[i] are less than or equal to 10^6 
	int last_visit[MAX]; 
	memset(last_visit, -1, sizeof(last_visit)); 

	// answer for each query 
	int ans[q]; 
	int query_counter = 0; 
	for (int i=0; i<n; i++) 
	{ 
		// If last visit is not -1 update -1 at the 
		// idx equal to last_visit[arr[i]] 
		if (last_visit[arr[i]] !=-1) 
			update (last_visit[arr[i]] + 1, -1, bit, n); 

		// Setting last_visit[arr[i]] as i and updating 
		// the bit array accordingly 
		last_visit[arr[i]] = i; 
		update(i + 1, 1, bit, n); 

		// If i is equal to r of any query store answer 
		// for that query in ans[] 
		while (query_counter < q && queries[query_counter].r == i) 
		{ 
			ans[queries[query_counter].idx] = 
					query(queries[query_counter].r + 1, bit, n)- 
					query(queries[query_counter].l, bit, n); 
			query_counter++; 
		} 
	} 

	// print answer for each query 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

// driver code 
int main() 
{ int n, q;
	cin >> n >> q;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i]--;
	}
	Query queries[q]; 
	int l, r;
	for (int i = 0; i < q; i++) {
		cin >> l >> r;
		l--;
		r--;
		queries[i].l = l;
		queries[i].r = r;
		queries[i].idx = i;
	}
	sort(queries, queries+q, cmp); 
	answeringQueries(a, n, queries, q); 
	return 0; 
} 


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

int main(){
    string as,bs;
    cin>>as>>bs;
    
    ll a=stoll(as);
    
    bs.erase(bs.end()-3);
    ll b=stoll(bs);
    
    ll ans=a*b/100l;
    cout<<ans<<endl;
}

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

int n, m, ans = 0;
int memo[55][2] = {0};
vector<int> edge[55];

bool solve(int x, int y);

int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    memo[i][0] = a;
    memo[i][1] = b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  for(int i = 0; i < m; ++i)
    if(solve(memo[i][0], memo[i][1])) ++ans;
  cout << ans << endl;
  return 0;
}

bool solve(int x, int y) {
  queue<int> qu;
  bool ch[55] = {0};
  ch[x] = 1;
  qu.push(x);
  while(qu.size() > 0) {
    int now = qu.front();
    qu.pop();
    for(int i = 0; i < edge[now].size(); ++i) {
      int nextn = edge[now][i];
      if(!ch[nextn] && (now != x || nextn != y)) {
        ch[nextn] = 1;
        qu.push(nextn);
      }
    }
  }
  return !ch[y];
}

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

int main(){
    string word, sen_word, com_word;
    int count, i, j;

    cin >> word;

    count = 0;
    while(1){
        cin >> sen_word;
        com_word = sen_word;
        if (sen_word == "END_OF_TEXT") break;
        i = 0;
        j = 0;
        while(i < sen_word.size()){
            sen_word[i] = tolower(sen_word[i]);
            if (isalpha(sen_word[i])){
            	com_word[j] = sen_word[i];
            	j++;
            }
            i++;
        }
        com_word.erase(j, i);
        if (word == com_word) count++;
    }
    cout << count << endl;
    return 0;
}


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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

string s;
int k;

void read() {
  cin >> s >> k;
}

void solve() {
  for(int i = 0; s[i] && i < k; ++i)
    if (s[i] != '1') {
      cout << s[i];
      return;
    }
  cout << s[k - 1];
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

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;
}

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

	map<int, int> mp;

	for (int i = 0; i < n; i++) {
		int num;
		cin >> num;
		mp[num]++;
	}

	int ans = 0;

	for (auto m : mp) {
		int f = m.first;
		int s = m.second;
		if (f > s) {
			ans += s;
		} else if (f < s) {
			ans += s - f;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 4736
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N,M,K;
    cin >> N >> M >> K;
    for (int yi = 0; yi <= N; ++yi) {
        for (int xi = 0; xi <= M; ++xi) {
            if(yi * xi + (N-yi)*(M-xi) == K){
                cout <<"Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#define ll long long
using namespace std;
int main(){
     int N,X;
     int L[101];
     int D[101];
     D[0] = 0;
     cin >> N >> X;
     for(int i = 0; i < N; i++){
          cin >> L[i];
          D[i+1] = D[i] + L[i];
          if(D[i+1] > X){
               cout << i+1 << endl;
               return 0;
          }
     }
     cout << N+1 << endl;
     return 0;
}

Measured memory_bytes: 256