akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public 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 count = 0;
		
		for(int x = a; x <= b; x++){
			if(c % x == 0){
				count ++;
			}
		}
		System.out.println(count);
		sc.close();
	}
}


Measured memory_bytes: 26392
// In the name of God

#include <bits/stdc++.h>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	int c = 0;
	int ans = 0;
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == 'T' && c) {
			c--;
			ans++;
		}
		if(s[i] == 'S') c++;
	}
	cout << (int)s.length() - 2 * ans;
	return 0;
}


Measured memory_bytes: 720
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

char buf[20];
int main(void) {
  map<string,int> m;
  int n;
  scanf("%d", &n);
  int maxi = 0;
  REP(i, n) {
    scanf("%s", buf);
    maxi = max(maxi, ++m[buf]);
  }
  for(auto p : m) {
    if(p.second == maxi) {
      puts(p.first.c_str());
    }
  }
  return 0;
}


Measured memory_bytes: 23808
//2020-04-11 17:15:45
//#pragma GCC optimize("-Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//order_of_key(x) : number of items less than x
//find_by_order(x) : iterator to x

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()

const ld pi=3.14159265359;
ll INF=1e18+10;
ll MOD=998244353;
ll mod=1e9+7;

inline ll add(ll a,ll b,ll m){
    if((a+b)>=m)return (a+b)%m;
    return a+b;
}

inline ll mul(ll a,ll b,ll m){
    if((a*b)<m)return a*b;
    return (a*b)%m;
}
const int N=2e5+10;
ll a[N];
ll ans[N];
stack<ll> s;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    ll n;cin>>n;
    rep(i,0,n)cin>>a[i];
    a[n]=-1;
    s.push(n-1);
    ans[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        if(a[i]>a[i+1])
            ans[i]+=(a[i]+ans[i+1]);
        else{
            while(!s.empty() && a[s.top()]>a[i])s.pop();
            int in = (!s.empty()) ? s.top() : n;
            ans[i]+=((a[i]*(in-i))+ans[in]);
        }
        s.push(i);
    }
    ll sum=0;
    rep(i,0,n)sum+=ans[i];
    cout<<sum;
}

Measured memory_bytes: 4992
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author KharYusuf
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADodecagon solver = new ADodecagon();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADodecagon {
        public void solve(int testNumber, FastReader s, PrintWriter w) {
            int n = s.nextInt();
            w.println(3 * n * n);
        }

    }

    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private FastReader.SpaceCharFilter filter;

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {

            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }

            return buf[curChar++];
        }

        public int nextInt() {

            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();

                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public boolean isSpaceChar(int c) {

            if (filter != null)
                return filter.isSpaceChar(c);

            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n,m;
    cin>>n;
    m=n/10;
    n%=10;
    if(n==9||m==9)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,c,d,prod1,prod2,prod3,prod4;
  cin>>a>>b>>c>>d;
  prod1=a*c;
  prod2=a*d;
  prod3=b*c;
  prod4=b*d;
  vector<long long int> A;
  A.push_back(prod1);
  A.push_back(prod2);
  A.push_back(prod3);
  A.push_back(prod4);
  long long max=prod1;
  for(int i=0;i<4;i++)
  {
    if(max<A[i])
      max=A[i];
  }
  cout<<max;
}

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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }

int main(){
  string s;
  cin >> s;
  int chk = 0;
  rep(i,s.size()){
    if(s[i] == s[i+1] and (i == 2 or i == 4))chk++;
  }
  if(chk == 2)cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

const long long mod =998244353 ;
const int N = 1e5+5;


#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define fr(i,l,m) for(int i=l;i<m;i++)
# define vii vector<int>
#define vpr vector<pair<ll,ll> >
ll pwr(ll x,ll y);
bool isprime(int n) ;

int wt[N],val[N];
ll dp[N];
int main()
{
ios_base::sync_with_stdio(false);cin.tie(NULL);

int n,w;
cin>>n>>w;

fr(i,1,n+1)
{
    cin>>wt[i]>>val[i];

}

fr(i,1,n+1)
{
    for(int j=w;j>=wt[i];j--)
    {
        dp[j]=max(dp[j],val[i]+dp[j-wt[i]]);
    }

}

cout<<dp[w]<<endl;


return 0;
}
ll pwr(ll x,ll y)
{
    ll ans=1;
    x=x%mod;
    while(y>0){
    if(y&1)ans=(x*(ans%mod))%mod;
    x=(x*x)%mod;
    y=y/2;

    }
    return ans%mod;
}

bool isprime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(a) (a).begin(),(a).end()
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,n) for(ll (i)=(n)-1;(i)>=0;i--)
#define SHOW(x) cout << #x << ": " << x << endl;
const ll INF=1e18;
int main(){
    ll n,y;
    cin>>n>>y;
    rep(i,n+1){
        rep(j,n-i+1){
            int k = n-(i+j);
            if(i*10000+j*5000+k*1000 == y){
                cout<<i<<" "<<j<<" "<<k<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007

int main() {
	int N, R;
	cin >> N >> R;
	if (N < 10) {
		cout << R + 100 * (10 - N) << endl;
	}
	else {
		cout << R << endl;
	}
}

Measured memory_bytes: 256
import math

n = int(input())
a = list(map(int, input().split()))
a.append("#")
start = 0
end = 0

ans = 0

while a[start] != "#" :
  if a[start] != a[end]:
    x = end - start
    if x % 2 == 0:
      ans += x // 2
    else:
      ans += math.floor(x / 2)
  
    start = end

  else:
    end += 1


print(ans)

Measured memory_bytes: 38256
#include <iostream>

int main(void) {
    int N;
    int *A;
    int m=1e9, M=0;
    std::cin >> N;
    A = (int *) malloc(sizeof(int) * N);
    for(int i=0;i < N;i++) {
        std::cin >> A[i];
        if (m > A[i]) {
            m = A[i];
        }
        if (M < A[i]) {
            M = A[i];
        }
    }
    std::cout << M-m << std::endl;


    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <climits>
#include <cstdio>
#include <iomanip>
#include <utility>

using namespace std;
typedef long long int ll;

int main(int argc, char const *argv[])
{
    ll n;
    cin >> n;
    vector<ll> a(100000, 0);
    for (ll i = 0; i < n; i++)
    {
        ll temp;
        cin >> temp;
        a[temp]++;
    }

    ll max = 0;
    for (ll i = 0; i < 100000; i++)
    {
        ll temp;
        if (i == 0)
            temp = a[i] + a[i + 1];
        else if (i == 100000 - 1)
            temp = a[i - 1] + a[i];
        else
            temp = a[i - 1] + a[i] + a[i + 1];

        if (max < temp)
            max = temp;
    }
    cout << max << endl;
}

Measured memory_bytes: 1024
#define DEBUG 0

/**
 * File    : C2.cpp
 * Author  : Kazune Takahashi
 * Created : 2019-5-26 00:05:51
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(10101010));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef long long ll;

// const int dx[4] = {1, 0, -1, 0};
// const int dy[4] = {0, 1, 0, -1};

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, M;
int L[100010];
int R[100010];

int main()
{
  cin >> N >> M;
  for (auto i = 0; i < M; i++)
  {
    cin >> L[i] >> R[i];
  }
  int mini = 0;
  int maxi = N + 1;
  for (auto i = 0; i < M; i++)
  {
    mini = max(mini, L[i]);
    maxi = min(maxi, R[i]);
  }
  cout << max(0, maxi - mini + 1) << endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()
	n := bs.IntScan()
	var sum int64
	for i := 1; i <= n; i++ {
		if !(i%3 == 0 || i%5 == 0) {
			sum += int64(i)
		}
	}
	bw.Printf("%v", sum)
}


// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 1764
def get_nums
  gets.split.map(&:to_i)
end

def init_matrix(row_num, row_length, default = nil)
  Array.new(row_num).map { Array.new(row_length, default) }
end

n = gets.to_i
nums = get_nums

lcm = nums[0]
1.upto(n - 1) do |i|
  lcm = lcm.lcm(nums[i])
end
res = 0
nums.each do |i|
  res += lcm / i
end

puts res % (10**9 + 7)

Measured memory_bytes: 56764
#include <stdio.h>

int main(void) {
  int n, a, b;
  int fee;
  scanf("%d %d %d", &n, &a, &b);
  if(n * a > b) {
    fee = b;
  }
  else {
    fee = a * n;
  }

  printf("%d\n", fee);
  return(0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N,S;
    string s;
    cin >> N >> S >>s;
    if (s[S-1] == 'A'){
     s[S-1] = 'a';
    } else if ( s[S-1] == 'B'){
       s[S-1] = 'b';
    } else {
       s[S-1] = 'c';
    }
   cout << s << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    
    while(true){
        cin>>H;
        cin>>W;
        if(H==0 && W==0){
            break;
        }
    for(int j=1; j<=H; j++){
        for(int i=1; i<=W; i++){
        cout<<"#";
        }
        cout<<endl;
    }
    cout<<endl;
    }
    
}       


Measured memory_bytes: 3076
#include <iostream>
#include <cstring>

long long dp[11][1010];
int main(){
    int n, s;
    while(std::cin >> n >> s, n != 0 || s != 0){
        memset(dp, 0, sizeof(dp));
        
        dp[0][0] = 1;
        
        for(int j = 0; j <= 100; ++j){
            for(int k = 1010; k >= 0; --k){
                for(int i = n; i >= 1; --i){
                    if(k - j < 0) continue;
                    
                    dp[i][k] += dp[i - 1][k - j];
                }
            }
        }
        
        /*for(int i = 0; i <= n; ++i){
            for(int k = 0; k <= s; ++k){
                std::cout << dp[i][k] << " ";
            }
            std::cout << std::endl;
        }*/
        
        std::cout << dp[n][s] << std::endl;
    }
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) for(auto x : v){cout << x << " ";} cout << endl
#define printVS(vs) for(auto x : vs){cout << x << endl;}
#define printVV(vv) for(auto v : vv){for(auto&& x : v){cout << x << " ";}cout << endl;}
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp) for(auto p : vp) printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
typedef vector<vector<int>> Graph;
const int inf = 1e9;
const int mod = 1e9 + 7;

const int a[5] = {5, 7, 5, 7, 7};

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

    int n;
    while (cin >> n, n) {
        vi v(n);
        rep(i, n) {
            string s;
            cin >> s;
            v[i] = s.size();
        }

        auto check = [&](int first){
            int t = 0;
            int j = 0;
            rep2(i, first, n) {
                if (t < a[j]) {
                    t += v[i];
                }
                if (t > a[j]) {
                    return false;
                }
                if (t == a[j]) {
                    j++;
                    t = 0;
                }
                if (j == 5) {
                    return true;
                }
            }
        };

        rep(i, n) {
            if (check(i)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3184
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (abs(a-b) % 2 == 0) {
        cout << abs(a-b) / 2LL << endl;
        return 0;
    } 
    ll near = min(abs(1LL-a), abs(n-b));
    cout << abs(a-b) / 2LL + near + 1LL << endl; 
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define all(v) v.begin(),v.end()
#define vi vector<int> 
#define mod 1000000007
#define inf 1e17
#define fs first
#define ss second

template <typename T> 
void amax(T& x, T y) 
{ 
    if( x < y) x = y;
} 

template <typename T> 
void amin(T& x, T y) 
{ 
    if( x > y) x = y;
} 

ll f(ll n) 
{ 
    // Initialize result 
    ll count = 0; 
  
    // Keep dividing n by powers of  
    // 5 and update count 
    for (ll i = 5; n / i >= 1; i *= 5){ 
        count += n / i; 
       // cout << count << endl;
    }
    return count; 
} 




int main(){
    
    ll n;
    cin >> n;
     
    if( n%2 == 1) cout << 0 <<endl;
    else {
	     
	  cout << f(n/2) <<endl;
		
	}  
   
    
    
    

}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let c=read::<i32>();
    let d=read::<i32>();
    println!("{}",if (a-b).abs()<=d&&(b-c).abs()<=d||(a-c).abs()<=d{"Yes"}else{"No"})
}


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

int main() {
    string a,b,c;
  cin>>a>>b>>c;
  cout<<char(a.at(0)+('A'-'a'))<<char(b.at(0)+('A'-'a'))<<char(c.at(0)+('A'-'a'))<<endl;
}


Measured memory_bytes: 256
N = int(input())
n = list(map(int, input().split()))

fourEven = 0
odd = 0
for num in n:
    if num % 4 == 0:
        fourEven += 1
    elif num % 2 == 1:
        odd += 1

if len(n) // 2 <= fourEven or odd <= fourEven:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 15020
#include <iostream>
#include <cstdio>

int Partition(int *A, int p, int r)
{
    int x = A[r];
    int i = p - 1;

    for (int j = p; j < r; j++) {
        if (A[j] <= x) {
            i += 1;
            // swap
            int val_i = A[i];
            A[i] = A[j];
            A[j] = val_i;
        }
    }
    i += 1;
    // swap
    int val_i = A[i];
    A[i] = A[r];
    A[r] = val_i;
    return i;
}

int main(int argc, char *argv[])
{
    int n;
    int A[100000];
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }

    int base_idx = Partition(A, 0, n-1);

    for (int i = 0; i < n; i++) {
        if (i == base_idx) {
            std::cout << "[" << A[i] << "]";
        } else {
            std::cout << A[i];
        }
        if (i != (n-1)) {
            std::cout << " ";
        }
    }
    std::cout << std::endl;

    return 0;
}


Measured memory_bytes: 3500
#include <stdio.h>

int main(void){
   int n,i,t=0;
   scanf("%d",&n);
   int l[n],r[n];

   for(i=0;i<n;i++)
      scanf("%d%d",&l[i],&r[i]);

   for(i=0;i<n;i++){
      t+=r[i]-l[i]+1;
   }

   printf("%d\n",t);
   return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, M, A[112345], B[112345];
std::vector<LL>G[112345];
bool visited[112345];
std::deque<LL>ans;

void dfs1(LL pos)
{
	visited[pos] = true;
	for (auto v : G[pos])
	{
		if (!visited[v])
		{
			ans.push_front(v);
			dfs1(v);
			break;
		}
	}
}

void dfs2(LL pos)
{
	visited[pos] = true;
	for (auto v : G[pos])
	{
		if (!visited[v])
		{
			ans.push_back(v);
			dfs2(v);
			break;
		}
	}
}

int main()
{
	in >> N >> M;
	rep(i, M)
	{
		in >> A[i] >> B[i];
		G[A[i]].push_back(B[i]);
		G[B[i]].push_back(A[i]);
	}
	memset(visited, false, sizeof(visited));
	ans.push_back(1);
	dfs1(1);
	dfs2(1);

	out << ans.size() << std::endl;
	rep(i, ans.size() - 1) { out << ans[i] << " "; }
	out << ans[ans.size() - 1] << std::endl;
	return 0;
}

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

using namespace std;

int main(int argc, const char * argv[]) {
    long N;
    cin >> N;
    vector<long> a(N);
    for (int i=0; i<N; i++) {
        cin >> a[i];
    }
    long ans = 0;
    for (int i=0; i < N; i++) {
        long temp = 0;
        while (1) {
            if (a[i]%2==0) {
                temp++;
                a[i] /= 2;
            } else {
                break;
            }
        }
        ans += temp;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main() {
  long long x, k, d;
  cin >> x >> k >> d;
  x = abs(x);

  if (k <= x / d) {
    cout << x - k * d << endl;
    return 0;
  }

  k = (k - x / d) % 2;
  x %= d;

  for (int i = 0; i < k; ++i) x = abs(x - d);

  cout << x << endl;
}


Measured memory_bytes: 3612
#include<stdio.h>
#define MAX 2000000000
#define INFTY (1<<30)




void maxHeap(int);
void insert(int);
void increaseK(int, int);
int heapExtractMax(void);

int H, A[MAX];




void maxHeap(int i){
  int l, r, large,k;
  l = 2*i;
  r = 2*i+1;
  if( l <= H && A[l] > A[i] ) large = l;
  else large = i;
  if( r <= H && A[r] > A[large] ) large = r;
  if( large != i){
    k = A[i];
    A[i] = A[large];
    A[large] = k;
    maxHeap(large);
  }
}

void insert(int key){
  H++;
  A[H] = -INFTY;
  increaseK(H, key);
}

void increaseK(int i, int key){
  int c;
  if(key < A[i]) return;
  A[i] = key;
  while (i > 1 && A[i/2] < A[i]) {
    c = A[i/2];
    A[i/2] = A[i];
    A[i] = c;
    i = i/2;
  }
}




int heapExtractMax(){
  int max;
  if( H < 1 ) return -INFTY;
  max = A[1];
  A[1] = A[H];
  H--;
  maxHeap(1);
  return max;
}

int main(){
  int key;
  A[H] = -INFTY;
  char com[10];

  while(1){
    scanf("%s", com);
    if(com[0] == 'e' && com[1] == 'n' ) break;
    if(com[0] == 'i'){
      scanf("%d", &key);
      insert(key);
    }
    else{
      printf("%d\n", heapExtractMax());
    }
  }

  return 0;
}



Measured memory_bytes: 5620
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    ll a, b, n, x;
    cin >> a >> b >> n;
    if(b-1 >= n){
        x = n;
    } else {
        x = b - 1;
    }

    ll first = floor(1.0 * a / b * x);
    ll second = a * floor(x * 1.0 / b);
    cout << first - second << endl;
}

Measured memory_bytes: 3756
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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 (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    rep(i,n) if (s[i] == '?') s[i] = 'D';
    PRINT(s);
}


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

typedef int64_t ll;
const double pi = 2 * acos(0.0);

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)
#define eb(i, j) emplace_back(i, j)
#define sz(x) (int)(x).size()
#define endl "\n"
#define INF 1000000007
#define EPS 1e-9

//#define sets

inline void solve(){
    int a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
}

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

    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w" ,stdout);
    #endif

    #ifdef sets
        int t;
        cin >> t;
        while(t--) solve();
    #else
        solve();
    #endif
}

Measured memory_bytes: 3644
n = int(input())
a = list(map(int, input().split()))
b = a[n:2*n]

import heapq

q = a[:n]
heapq.heapify(q)

res = [0]*(n+1)
res[0] = sum(q)
for i, x in enumerate(b):
    heapq.heappush(q, x)
    y = heapq.heappop(q)
    res[i+1] = res[i]+x-y

b.reverse()
q = [-x for x in a[2*n:]]
heapq.heapify(q)
s = -sum(q)
res[-1] -= s

for i, x in enumerate(b):
    heapq.heappush(q, -x)
    y = heapq.heappop(q)
    s += x+y
    res[-2-i] -= s

print(max(res))


Measured memory_bytes: 41172
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0;i < s.size();i++){
  	if(s[i] == '?'){
    	s[i] = 'D';
    }
    else{
      
    }
  }
  cout << s;
  return 0;
}


Measured memory_bytes: 3732
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a;
	cin>>a;
	for(int z=0;z<a;z++){
		long long n;
		cin>>n;
		cout<<"Case "<<z+1<<":"<<endl;
		for(int j=0;j<10;j++){
			n=n*n;
			string a=to_string(n);
			int b=a.length();
			b=8-b;
			string t;
			for(int i=0;i<b;i++)
				t+="0";
			t+=a;
			string c=t.substr(2,4);
			n=stoi(c);
			cout<<n<<endl;
		}
	}
}

Measured memory_bytes: 3228
/****************************
*  Developer : joshi08
*  Date  :  16-06-2020
*  Year  :  2020
****************************/

#include <bits/stdc++.h>

#define lli long long int
#define mod 1000000007
#define fi first
#define se second
#define ii pair<lli, lli>
#define mp make_pair
#define endl '\n'
#define maxN 1000000000000000000
const double PI = 3.141592653589793238460;
lli gcd(lli a, lli b) { if (a == 0) return b; return gcd(b % a, a);}
lli max(lli a, lli b) {if (a > b) return a; else return b;}
lli min(lli a, lli b) {if (a < b) return a; else return b;}
lli power(lli a,lli b) {lli i,p=1; for(i=0;i<b;i++){p*=a;} return p;}

using namespace std;




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

	lli n,i,check=0,flag=0,k,m=1;
	cin>>n;
	vector<lli> a;
	//string s1,s2="1";
	for(i=0;i<n;i++)
	{
		cin>>k;
		
		if(k==0)
			flag=1;
		
		a.push_back(k);
	}
	
	if(flag)
	{
		cout<<0;
		return 0;
	}
	
	for(i=0;i<n;i++)
	{
		if(m>maxN/a[i])
		{
			check=1;
			break;
		}
		m = m*a[i];
	}
	
	if(check)
	{
		cout<<-1;
		return 0;
	}
	cout<<m;
	
    return 0;
}



Measured memory_bytes: 4288
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <algorithm>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MAX3(a, b, c) ((a) > (MAX(b, c)) ? (a) : (MAX(b, c)))
#define MIN3(a, b, c) ((a) < (MIN(b, c)) ? (a) : (MIN(b, c)))

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

int main()
{
    int n, m;
    cin >> n >> m;
    int a[1000], b[1000], c[1000], dist[100][100];

    rep(i, m) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }

    rep(i, n) {
        rep(j, n) {
            dist[i][j] = (i == j)? 0 : 10000000;
        }
    }

    rep(i, m) {
        dist[a[i]][b[i]] = c[i];
        dist[b[i]][a[i]] = c[i];
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

//    rep(i, n) {
//        rep(j, n) {
//            cout << dist[i][j] << " ";
//        }
//        cout << endl;
//    }
    int cnt = 0;
    rep(i, m) {
        int shortest = 0;
        rep(j, n) {
            if (c[i] + dist[j][a[i]] == dist[j][b[i]]) shortest = 1;
        }
        if (!shortest)
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main(){
	int no, cnta = 0, cntb = 0, cnto = 0, cntab = 0;
	char blo[256];
	while(scanf("%d,%s", &no, blo) != EOF){
		if(strcmp(blo, "A") == 0) cnta++;
		else if(strcmp(blo, "B") == 0) cntb++;
		else if(strcmp(blo, "O") == 0) cnto++;
		else if(strcmp(blo, "AB") == 0) cntab++;
	}
	cout <<cnta <<endl <<cntb <<endl <<cntab <<endl <<cnto <<endl;
	return 0;
}

Measured memory_bytes: 0
def main():
  import sys
  input=sys.stdin.readline
  n=int(input())
  
  edges=[]
  for i in range(n-1):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edges.append([a,b,i])

  edges.sort(key=lambda i:i[0])
  color=[0]*(n-1)
  head=[0]*n #上から来る色
  before=[0]*n #直前に使った色
  
  for i in range(n-1):
    a=edges[i][0]
    b=edges[i][1]
    index=edges[i][2]
    if before[a]+1==head[a]:
      c=before[a]+2
    else:
      c=before[a]+1
    before[a]=c
    head[b]=c
    color[index]=c
    
  print(max(color))
  print(*color,sep='\n')
  
if __name__=='__main__':
  main()

Measured memory_bytes: 27464
N = gets.to_i
X = gets.chomp

pop_cnt = X.count('1')

p0 = pop_cnt + 1
p1 = pop_cnt - 1

if p1 == 0
  N.times do |i|
    if X[i] == '0'
      if i == N - 1
        puts 2
      else
        puts 1
      end
    else
      puts 0
    end
  end

  exit
end

bases = [X.to_i(2) % p0, X.to_i(2) % p1]

$cache = Hash.new
$cache[0] = 0
 
class Integer
  def popcount
    to_s(2).count('1')
  end
end
 
def f(x)
  return $cache[x] if $cache[x]

  $cache[x] = f(x % x.popcount) + 1
end

v0 = 1 % p0
v1 = 1 % p1

ans = []

N.times do |i|
  if X[N - i - 1] == '0'
    r = (bases[0] + v0) % p0
  else
    r = (bases[1] - v1) % p1
  end

  if r == 0
    ans << 1
  else
    ans << f(r) + 1
  end

  v0 = (2 * v0) % p0
  v1 = (2 * v1) % p1
end

puts ans.reverse


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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};

//-----------------------------------------------------------------------------

ll a,b,c;

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

	cin>>a>>b>>c;
	if(a%2==0&&a==b&&b==c) cout<<-1<<endl;
	else {
		int t=0;
		while(true) {
			if(a%2||b%2||c%2) {
				cout<<t<<endl;
				break;
			}
			ll x=(a+b)/2,y=(b+c)/2,z=(a+c)/2;
			z=x,b=y,c=z;
			t++;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200020,mod=998244353;
#define lson o<<1,l,mid
#define rson o<<1|1,mid+1,r
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(int i=(a);i>=(b);i--)
#define MEM(x,v) memset(x,v,sizeof(x))
inline int read(){
	int x=0,f=0;char ch=getchar();
	while(ch<'0' || ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
	return f?-x:x;
}
struct item{
	int val,id;
	bool operator<(const item &i)const{return val<i.val;}
};
int n,a[maxn],b[maxn];
ll ans;
priority_queue<item> pq;
int main(){
	n=read();
	FOR(i,1,n) a[i]=read();
	FOR(i,1,n){
		b[i]=read();
		if(a[i]!=b[i]) pq.push((item){b[i],i});
	}
	while(!pq.empty()){
		int id=pq.top().id;pq.pop();
		int pre=id==1?n:id-1,nxt=id==n?1:id+1;
		if(b[id]-a[id]<b[pre]+b[nxt]) return puts("-1"),0;
		ans+=(b[id]-a[id])/(b[pre]+b[nxt]);
		b[id]-=(b[id]-a[id])/(b[pre]+b[nxt])*(b[pre]+b[nxt]);
		if(b[id]==a[id]) continue;
		pq.push((item){b[id],id});
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

bool IsPrime[2000000];
int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 2; i <= 1000000; i++) IsPrime[i] = true;
    for(int i = 2; i <= 1000000; i++) {
        if(!IsPrime[i]) continue;
        for(int j = i * 2; j <= 1e6; j += i) IsPrime[j] = false;
    }
    while(true) {
        int a, d, n;
        cin >> a >> d >> n;
        if(a == 0 && d == 0 && n == 0) break;
        int now = 0;
        int val = a;
        while(true) {
            //cerr << val << endl;
            if(IsPrime[val]) now++;
            if(now == n) break;
            val += d;
        }
        cout << val << endl;
    }
    return 0;
}


Measured memory_bytes: 4156
#include <stdio.h>

int main(){
  int n,u,k,i,j,v,V[101][101]={};

  scanf("%d",&n);   /*頂点数*/
  
  for(i=1; i<=n; i++){
    scanf("%d",&u);      /*頂点番号*/
    scanf("%d",&k);      /*出次数*/
    for(j=0; j<k; j++){
      scanf("%d",&v);     /*隣接番号*/
      V[u][v-1] = 1;    
    }
  }
  for(i=1; i<=n; i++){
    for(j=0; j<n-1; j++){
      printf("%d ",V[i][j]);
    }
    printf("%d\n",V[i][n-1]);
  }

  return 0;
}

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

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N = lread();
    auto memo = new long[](N + 1);
    memo[] = -1;
    memo[0] = 0;
    long solve(long n)
    {
        if (memo[n] != -1)
            return memo[n];
        long i = 1;
        long ans = long.max;
        while (i <= n)
        {
            ans = ans.min(solve(n - i) + 1);
            i *= 6;
        }
        i = 1;
        while (i <= n)
        {
            ans = ans.min(solve(n - i) + 1);
            i *= 9;
        }
        memo[n] = ans;
        return ans;
    }

    solve(N).writeln();
}


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


class Main {

    static int n,w;
    static long dp[][];
    static int wi[];
    static long vi[];

    public static long knapsack(int i , int cost)
    {
        if(cost < 0 || i >= n)
            return 0;

        if(dp[i][cost] != 0)
            return dp[i][cost];

        if(cost >= wi[i])
        {
            dp[i][cost] = Math.max(vi[i] + knapsack(i+1 , cost - wi[i]) , knapsack(i+1 , cost));
        }
        else
        {
            dp[i][cost] = knapsack(i+1 , cost);
        }

        return dp[i][cost];
    }

    public static void main(String[] args) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);

        StringTokenizer st1 = new StringTokenizer(br.readLine());

        n = Integer.parseInt(st1.nextToken());
        w = Integer.parseInt(st1.nextToken());

        wi = new int [n];
        vi = new long [n];

        for(int i = 0 ; i < n ; i++)
        {
            st1 = new StringTokenizer(br.readLine());

            wi[i] = Integer.parseInt(st1.nextToken());
            vi[i] = Long.parseLong(st1.nextToken());
        }

        dp = new long [n+1][w+1];


        out.println(knapsack(0 , w));


        out.flush();
        out.close();
    }

}

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

int main(){
	int N,M;
  cin>>N>>M;
  vector<int> vec(2*M);
  for(int i=0;i<2*M;i++)
    cin>>vec.at(i);
  int count=0;
  for(int i=0;i<N;i++){
    for(int j=0;j<2*M;j++){
  		if(vec.at(j)==i+1)
          count++;
    }
    cout<<count<<endl;
    count=0;
  }
}

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

int main() {
  string s;
  cin >> s;
  
  int n = s.size(), a_place, z_place, length;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'A') {
      a_place = i;
      break;
    }
  }
  for (int i = n-1; 0 <= i; i--) {
    if (s[i] == 'Z') {
      z_place = i;
      break;
    }
  }
      
  cout << z_place - a_place + 1 << endl;
}



Measured memory_bytes: 640
N,M = map(int, input().split())
X = sorted(map(int, input().split()))

R = []
if N >= M:
    print(0)
else:
    for i in range(M-1):
        R.append(X[i+1] - X[i])
        
    R.sort()

    print(sum(R[:M-N]))


Measured memory_bytes: 13968
#include <stdio.h>
#define max(a, b) ((a) > (b) ? (a) : (b))


int main(void){
    int f, i,ii,x , n,a[105], q[105], tmp;
    scanf("%d%d", &x, &n);
    if (n == 0)
    {
        printf("%d", x);
        return (0);
    }
    for (i = 0; i < n; i++)
    {
        scanf("%d", q + i);
        a[i] =  max(q[i] - x, x - q[i]);
    }
    f = 0;
    while (f == 0)
    {
        f = 1;
        for (i = 0; i < n - 1; i++)
        {
            if (a[i] > a[i + 1])
            {
                f = 0;
                a[i] ^= a[i + 1];
                a[i + 1] ^= a[i];
                a[i] ^= a[i + 1];
            }
        }
    }
       if (a[0] > 0)
    {
        printf("%d", x);
        return (0);
    }
    if (a[1] > 1)
    {
        printf("%d", x - 1);
        return (0);
    }
       
       f = 2;
       
     for (i = 1; i < n - 1; i++)
    {
        if (a[i + 1] != a[i])
        {
            tmp = a[i];
            f = 3;
            break;
        }
        i++;
        if (a[i + 1] > a[i] + 1)
        {
            printf("%d", x - a[i] - 1);
            return (0);
        }
    } 

    
    if (f == 3)
    {
        for (i = 0; i < n; i++)
        {
            if (max(q[i] - x, x - q[i]) == tmp)
            {
                printf("%d", x + x - q[i]);
                return (0);
            }
        }
    }
    
    if (n % 2 == 1)
    {
        printf("%d", x - (n / 2) - 1);
        return (0);
    }
    
    for (i = 0; i < n; i++)
    {
        if (q[i] == x + (n / 2))
        {
            printf("%d", x - n / 2);
            return (0);
        }
    }
    printf("%d", x + n / 2);
    return(0);
}


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

int main() {
  int n;
  cin >> n;
  vector<int> s(n, 0);
  for (int i = 1;i < n;i++) {
    int a;
    cin >> a;
    s[a - 1] += 1;
  }
  for (int x : s) {
    cout << x << endl;
  }
}

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    int ans = 0;
    rep(i, n) {
      int l, r;  cin >> l >> r;
      ans += r - l + 1;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    vector<int> N;
    bool result = false;

    rep(i, 4) {
        int Ni;
        cin >> Ni;
        N.pb(Ni);
    }

    sort(all(N));

    do {
        if (N[0] == 1 && N[1] == 9 && N[2] == 7 && N[3] == 4 ) {
            result = true;
        }
    } while (next_permutation(all(N)));

    cout << (result ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
using namespace std;
struct Node{
  int key;
  Node *right,*left,*parent;
};
Node *root,*NIL;
Node * treeMinimum(Node *x){
  while(x->left != NIL)x=x->left;
  return x;
}
Node * find(Node *u,int k){
  while(u!= NIL && k !=u->key){
    if(k<u->key)u=u->left;
    else u=u->right;
  }
  return u;
}
Node * treeSuccessor(Node *x){
  if(x->right != NIL)return treeMinimum(x->right);
  Node *y=x->parent;
  while(y != NIL && x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
void treeDelete(Node *z){
  Node *y;
  Node *x;
  if(z->left==NIL||z->right==NIL) y=z;
  else y = treeSuccessor(z);
  if(y->left != NIL){
    x=y->left;
  }else{
    x=y->right;
  }
  if(x != NIL){
    x->parent=y->parent;
  }
  if(y->parent==NIL){
      root=x;
    }else{
    if(y==y->parent->left){
      y->parent->left=x;
    }else{
      y->parent->right=x;
    }
  }
  if(y != z){
    z->key =y->key;
  }
  free(y);
}
void insert(int k){
  Node *y=NIL;
  Node *x=root;
  Node *z;
  z = (Node *)malloc(sizeof(Node));
  z->key=k;
z->left=NIL;
  z->right=NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }
  z->parent=y;
  if(y==NIL){
    root=z;
  }
  else{
    if(z->key<y->key){
      y->left=z;
    }else{
      y->right=z;
    }
  }
}

void inorder(Node *u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
preorder(u->left);
preorder(u->right);
}
int main(){
  int n,i,x;
  string com;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    cin>>com;
    if(com[0]=='f'){
      scanf("%d",&x);
      Node *t=find(root,x);
      if(t != NIL) printf("yes\n");


 else printf("no\n");
    }else if(com=="insert"){
      scanf("%d",&x);
      insert(x);
    }
    else if(com=="print"){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(com=="delete"){
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }
  return 0;
}



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

using namespace std;
#define PI              3.1415926536

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod 1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define REP(i,n) for(i=0;i<n;i++)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

bool f(int x, int y)
{
	return x > y;
}
void c_p_c()
{
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
int ans(int x)
{
	cout << x << endl;
	cout.flush();
	string s;
	cin >> s;

	if (s == "yes")
		return 1;
	return 0;
}
int32_t main()
{
	//c_p_c();
	FIO;

	int x;
	cin >> x;
	x ^= 1;
	cout << x;

}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <map>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
const int iINF = 1001001001;
const long long llINF = 1LL << 60;
int main()
{
	// ABC153-E, 1009, 
	int h, n;
	cin >> h >> n;
	vector<ll> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];
	vector<ll> dp(2 * 10000 + 1, iINF);
	dp[0] = 0;
	rep(i, 2 * 10000 + 1) {
		rep(j, n) {
			if (0 <= i - a[j]) dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
		}
	}
	ll ans = llINF;
	for (int i = h; i < 2 * 10000 + 1; ++i) {
		ans = min(ans, dp[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3640