akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

from collections import deque


class PriorityQueue:
    def __init__(self, size):
        self.tree = [None] * size
        self.bottom = 0

    def add(self, data):
        n = self.bottom
        self.bottom += 1
        self.tree[n] = data
        while n != 0:
            parent = (n - 1) // 2
            if self.tree[parent][1] < self.tree[n][1]:
                self.tree[parent], self.tree[n] = (
                    self.tree[n],
                    self.tree[parent],
                )
                n = parent
            else:
                return

    def top(self):
        return self.tree[0]

    def size(self):
        return self.bottom

    def pop_top(self):
        rv = self.tree[0]
        self.tree[0] = self.tree[self.bottom - 1]
        self.bottom -= 1
        n = 0
        while True:
            child1 = 2 * n + 1
            if child1 >= self.bottom:
                return rv
            child2 = 2 * n + 2
            if child2 >= self.bottom:
                child2 = child1

            if (
                self.tree[n][1] > self.tree[child1][1]
                and self.tree[n][1] > self.tree[child2][1]
            ):
                return rv
            elif self.tree[child1][1] > self.tree[child2][1]:
                self.tree[n], self.tree[child1] = (
                    self.tree[child1],
                    self.tree[n],
                )
                n = child1
            else:
                self.tree[n], self.tree[child2] = (
                    self.tree[child2],
                    self.tree[n],
                )
                n = child2
        return rv


def solve(N, M, A, B):
    ans = 0
    # 日付順にソートする
    all_works = deque(sorted(zip(A, B), key=lambda x: x[0]))
    pq = PriorityQueue(N)

    for d in range(1, M+1):
        # print('d=', d)
        # 今日が期限の仕事があれば追加
        while all_works and all_works[0][0] == d:
            work = all_works.popleft()
            pq.add(work)
        # print('all_works', all_works)
        # print('pq=', pq.tree)
        # 優先キューから最優先の仕事をする
        if pq.size():
            work = pq.pop_top()
            ans += work[1]

    return ans


if __name__ == '__main__':
    N, M = map(int, input().split())
    A = [0] * N
    B = [0] * N
    for idx in range(N):
        A[idx], B[idx] = map(int, input().split())

    ans = solve(N, M, A, B)

    print(ans)


Measured memory_bytes: 21204
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// main.cpp

int main() {
  i64 r, D, answer;
  std::cin >> r >> D >> answer;

  for (i64 i = 0; i < 10; ++i) {
    answer = r * answer - D;
    std::cout << answer << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) (v).begin(),(v).end()
#define out(a) cout << (a) << endl
using namespace std;
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >>  d;
    int ans = min(b, d) - max(a, c);
    if (ans < 0) out(0);
    else out(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  unsigned long long X,Uresisa;
  cin >> X;
  Uresisa = 0ULL;
   
  if(X < 500){
    Uresisa = X - (X % 5);
    cout << Uresisa << endl;
    return(0);
  }else{
    unsigned long long amari = X % 500;
    Uresisa = (X - amari) * 2;

    unsigned long long Xtmp = amari - (amari % 5);

    Uresisa += Xtmp;
        cout << Uresisa << endl;
    return(0);
  } 
}

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

using namespace std;

int k=0,n=0;
int a[1000001];
int mx=0;

int main()
{
	cin >> k >> n;
	for (int i=0; i<n; i++)
	{
		cin >> a[i];
	}	
	mx = a[n-1];
	int res=INT_MAX;
	for (int i=0; i<n; i++)
	{
		res = min(res, mx-a[i]);
		a[i]+=k;
		mx = max(mx, a[i]);
	}
	cout << res;
	return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String buffer;
		int i = 0;
		try {
			while ((buffer = reader.readLine())  != null) {
				int x = Integer.valueOf(buffer);
				if (x == 0) {
					return;
				}
				System.out.println("Case " + ++i + ": " + x);
			}
		} catch (Exception ex) {
			ex.printStackTrace();
		}
	}
}

Measured memory_bytes: 32264
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;



int main(){
    ll N;
    cin >> N;
    vector<ll> A(N,0);
    for(ll i=0;i<N;i++){
        cin>>A[i]
    ;}
    vector<P> C(0);
    vector<P> D(0);
    for(ll i=0;i<N;i++){
        C.emplace_back(P(i+A[i],i));
        if(i>0)
        D.emplace_back(P(i-A[i],i));
    ;}


    //自分より番号大きいものだけ見ろ

    ll ans=0;

    sort(C.begin(), C.end());
    sort(D.begin(), D.end());

    for(ll i=0;i<N-1;i++){
        ll x=C[i].first;
        ll y=C[i].second;//yより大きい番号しか残すな
        ll s=lower_bound(D.begin(), D.end(), P(x,0))-D.begin();
        ll t=upper_bound(D.begin(), D.end(), P(x,INF))-D.begin();//ｓからｔ-1番目までをみる
        ans+=t-s;
        //D.erase(lower_bound(D.begin(), D.end(), P(i+1-A[i+1],i+1)))
    ;}
    cout<<ans<<endl;



    
    return 0;
}


Measured memory_bytes: 11372
#include <bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define pll pair<long long int, long long int>
#define pii pair<int, int>
#define vii vector<int>
#define vll vector<long long int>
#define sii set<int>
#define sll set<long long int>
#define usi unordered_set<int, custom_hash>
#define usl unordered_set<long long int, custom_hash>
#define mii map<int, int>
#define mll map<long long int, long long int>
#define umi unordered_map<int, int, custom_hash>
#define uml unordered_map<long long int, long long int, custom_hash>
#define ski stack<int>
#define skl stack<long long int>
#define all(v) v.begin(),v.end()
using namespace std;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c`
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


const int N=2e5+1;
const int mod=998244353;
ll a[N], b[N], c[N];


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
#endif
    
    int n, x, y, z;
    cin>>n>>x>>y;
    ll prev=0, cur=abs(x-y);
    for(int i=2;i<n;++i){
        if(i!=2){
            x=y; y=z;
        }
        cin>>z;
        ll tmp1=cur+abs(z-y);
        ll tmp2=prev+abs(z-x);
        prev=cur;
        cur=min(tmp1, tmp2);

    }

    cout<<cur<<endl;

}

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

const int D_x[4] = { 0,1,0,-1 };
const int D_y[4] = { 1,0,-1,0 };
const int ANS = 123456780;

void setNum(int puzzle[3][3],int n) {
	for (int i = 2; i >= 0; i--) {
		for (int j = 2; j >= 0; j--) {
			puzzle[i][j] = n % 10;
			n /= 10;
		}
	}
}

int getNum(int puzzle[3][3]) {
	int res = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			res *= 10;
			res += puzzle[i][j];
		}
	}
	return res;
}

void find_0(int puzzle[3][3], int& x, int& y) {
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (puzzle[i][j] == 0) {
				x = j;
				y = i;
				return;
			}
		}
	}
}

int solve(int puzzle[3][3]) {
	queue<int> q;
	unordered_set<int> table;
	int cnt = 1;

	q.push(getNum(puzzle));
	if (q.front() == ANS)return 0;
	while (true) {
		int s = q.size();

		for (int i = 0; i < s; i++) {
			int x, y;
			setNum(puzzle, q.front());
			find_0(puzzle, x, y);

			for (int j = 0; j < 4; j++) {
				int X = x + D_x[j];
				int Y = y + D_y[j];
				if (X < 0 || Y < 0 || X >= 3 || Y >= 3)continue;
				setNum(puzzle, q.front());
				swap(puzzle[y][x], puzzle[Y][X]);

				int n = getNum(puzzle);
				if (n == ANS) {
					return cnt;
				}
				if (table.count(n) == 0) {
					table.insert(n);
					q.push(n);
				}
			}
			q.pop();
		}
		cnt++;
	}
}

int main() {
	int puzzle[3][3];

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> puzzle[i][j];
		}
	}

	cout << solve(puzzle) << endl;

	return 0;
}

Measured memory_bytes: 10612
#include <vector> 
#include <list> 
#include <map>
#include <set>
#include <deque>
#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>
#include <queue>
#include <complex>
using namespace std;

//conversion
//------------------------------------------
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(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x * x; }

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

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

const LL mod = 1000000007;


#define Yes_ cout<<"Yes"<<endl; return 0;
#define No_ cout<<"No"<<endl; return 0;


#define YES_ cout<<"YES"<<endl; return 0;
#define NO_ cout<<"NO"<<endl; return 0;

int main() {


	int N;
	cin >> N;
	vector<LL> A(N),B;
	REP(i, N) { cin >> A[i]; }
	B = A;
	LL sum = (A[0]!=0) ? A[0]:1;
	LL num = (A[0] != 0) ? 0 : 1;
	for (int i = 1; i < N; i++) {

		if (sum > 0) {
			if (sum + A[i] >= 0) {
				num += abs(A[i]+sum) + 1;
				sum = -1;
			}
			else {
				sum += A[i];
			}
		}
		else if (sum < 0) {
			if (sum + A[i] <= 0) {
				num += abs(A[i] + sum) + 1;
				sum = 1;
			}
			else {
				sum += A[i];
			}
		}

	}
	 sum = (A[0] >= 0) ? -1 : 1;
	LL num2 = abs(A[0]) + 1;
	for (int i = 1; i < N; i++) {

		if (sum > 0) {
			if (sum + A[i] >= 0) {
				num2 += abs(A[i] + sum) + 1;
				sum = -1;
			}
			else {
				sum += A[i];
			}
		}
		else if (sum < 0) {
			if (sum + A[i] <= 0) {
				num2 += abs(A[i] + sum) + 1;
				sum = 1;
			}
			else {
				sum += A[i];
			}
		}

	}
	cout << min(num,num2) << endl;
}

Measured memory_bytes: 1792
#include"bits/stdc++.h"
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

const ll INF = (ll)1e18 + 5;

void Main()
{
	ll N, M;
  	cin >> N >> M;
  	vll a(N);
  	rep(i,N) cin >> a[i];
  	sort(all(a));
  
	auto f = [&](ll x){
    	// 幸福度 x 以上の握手が何通りあるか
      	ll res = 0;
  		rep(i,N){
          	ll L = -1, R = N;
			while(L+1!=R){
              	ll M = (L+R)/2;
          		if(a[i]+a[M] >= x) R = M;
          		else L = M;
            }
          	res += (N-R);
        }
      	return res;
    };
  
	ll l = -1, r = INF;
  	while(l+1!=r){
    	ll m = (l+r)/2;
      	if(f(m) < M) r = m;
      	else l = m;
    }
  	
  	// cout << l << endl;
  	// l = 67; 67 以上の組を上から M 個分足す
    
  	// 右からの累積和を Rsum[] に保持
  	vll Rsum(N+1);
  	Rsum[N] = 0;
  	Rsum[N-1] = a[N-1];
  	rep3rev(i,N-2,0) Rsum[i] = Rsum[i+1] + a[i];
  	//rep(i,N) cout << i << ": " << Rsum[i] << endl;
  
  	auto g = [&](ll x){
    	// 幸福度 x 以上の握手を全て足す
      	ll res = 0;
  		rep(i,N){
          	ll L = -1, R = N;
			while(L+1!=R){
              	ll M = (L+R)/2;
          		if(a[i]+a[M] >= x) R = M;
          		else L = M;
            }
          	res += a[i]*(N-R) + Rsum[R];
          	//cout << i << ": " << N-R << ", " << R << ", " << res << endl;
        }
      	return res;
    };
  
  	ll ans = g(l);
  	if(f(l) > M) ans -= l*(f(l)-M);	
 
  	cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int main(){
    int n; cin >> n;
    set <int> s;
    int tmp;

    rep(i, n){
        cin >> tmp;
        s.insert(tmp);
    }

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int x,y,z,a;
  scanf("%d %d",&x,&y);

  while(1)
    {
      if (x<y)
        {
          z = x;
          x = y;
          y = z;
        }
      if ((x/y) == 0){a = 1;break;};
      if ((x%y) == 0){a = y;break;};
      x = x % y;
    }
  printf("%d\n",a);
  return 0;
}

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

using namespace std;

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

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

int N, M;
int ans = 0;

void solve() {
    cin >> N >> M;
    int c[N] = {};
    int r[N] = {};
    rep(i,N) c[i] = 1;
    int cur = 0;
    r[cur] = 1;
    rep(i,M) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        if (r[x]) {
            r[y] = 1;
        }
        c[x]--;
        c[y]++;
        if (c[x] == 0) r[x] = 0;
    }
    rep(i,N) {
        //cout << c[i] << " " << r[i] << endl;
        if (c[i] && r[i]) ans++;
    }
    cout << ans << endl;
}

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


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

int main() {
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if (x - r >= 0 && w - x - r >= 0 && y - r >= 0 && h - y - r >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    for (int i = 10*b; i <= 10*b+9; ++i)
    {
        if (i*2/25 == a) { cout << i; return 0; }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main (void)
{
    int H, W;
    char a[101][101];
    int i, j, delh[100] = {0}, delw[100] = {0};

    scanf("%d %d", &H, &W);

    for (i = 0; i < H; i++) {
        scanf("%s", &a[i][0]);
    }

    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            if (a[i][j] == '#') delh[i] = 1;
        }
    }
    for (i = 0; i < W; i++) {
        for (j = 0; j < H; j++) {
            if (a[j][i] == '#') delw[i] = 1;
        }
    }
    for (i = 0; i < H; i++) {
        for (j = 0; j < W; j++) {
            if (delh[i] == 1 && delw[j] == 1)
                putchar(a[i][j]);
        }
        if (delh[i] == 1) puts("");
    }

    return 0;
}

Measured memory_bytes: 128
#![allow(non_snake_case)]

fn read_line() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_tuple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    (v[0], v[1])
}

fn main() {
    let (D, G) = read_tuple::<usize>();
    let G = G / 100;
    let mut pc = vec![(0, 0); D+1];
    let mut sum_p = 0;
    for i in 1..D+1 {
        pc[i] = read_tuple::<usize>();
        sum_p += pc[i].0;
        pc[i].1 /= 100;
    }
    let mut dp = vec![vec![0; sum_p+1]; D+1];
    for i in 1..D+1 {
        let (p, c) = pc[i];
        for j in 1..sum_p+1 {
            for k in 0..std::cmp::min(p, j)+1 {
                if k == p {
                    dp[i][j] = std::cmp::max(dp[i][j], dp[i-1][j-k]+i*p+c);
                } else {
                    dp[i][j] = std::cmp::max(dp[i][j], dp[i-1][j-k]+i*k);
                }
            }
        }
    }
    for i in 1..sum_p+1 {
        if dp[D][i] >= G {
            println!("{}", i);
            return;
        }
    }
}


Measured memory_bytes: 4352
Scanf.scanf "%d" (fun n ->
    let s = Array.init n (fun _ -> Scanf.scanf " %s" (fun s -> s)) in
    Array.sort compare s;
    let rec loop i prev acc =
        if i = n then acc else
            if s.(i) = prev then loop (i + 1) prev acc
                            else loop (i + 1) s.(i) (acc + 1)
    in
    loop 1 s.(0) 1 |> Printf.printf "%d\n"
)

Measured memory_bytes: 12688
loop do
  n, k = [gets, gets].map(&:to_i)

  break if n == 0 and k == 0

  cards = []

  ans = []

  n.times{ cards.push(gets.to_i) }

  cards.permutation(k) {|*a| ans.push(a.join) } 

  puts ans.uniq.length
end

Measured memory_bytes: 9532
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = 2147483647;

struct min_stack {
    stack<int> S, M;
    void push(int x) {
        S.push(x);
        M.push(M.empty() ? x : min(M.top(), x)); }
    int top() { return S.top(); }
    int mn() { return M.top(); }
    void pop() { S.pop(); M.pop(); }
    bool empty() { return S.empty(); }
};
struct min_queue {
    min_stack inp, outp;
    void push(int x) { inp.push(x); }
    void fix() {
        if (outp.empty()) while (!inp.empty())
            outp.push(inp.top()), inp.pop();
    }
    int top() { fix(); return outp.top(); }
    int mn() {
        if (inp.empty()) return outp.mn();
        if (outp.empty()) return inp.mn();
        return min(inp.mn(), outp.mn()); }
    void pop() { fix(); outp.pop(); }
    bool empty() { return inp.empty() && outp.empty(); }
};

int main() {
    int n;
    ll x;
    cin >> n >> x;
    vector<ll> cost(n);
    rep(i,0,n) {
        cin >> cost[i];
    }
    ll mn = 2000000000000000000LL;
    vector<ll> best(n);
    rep(sh,0,n) {
        rep(i,0,n) best[i] = -1;
        min_queue Q;
        int cnt = 0;
        rep(i,0,2*n) {
            Q.push(cost[i%n]);
            cnt++;
            if (cnt > sh+1) {
                Q.pop();
                cnt--;
            }
            assert(cnt <= sh+1);
            if (cnt == sh+1) {
                best[i%n] = Q.mn();
            }
        }
        ll res = sh * x;
        rep(i,0,n) {
            assert(best[i] != -1);
            res += best[i];
        }
        mn = min(mn, res);
    }
    cout << mn << endl;
    return 0;
}



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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

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

    REP(i,n)
        cin >> a[i] >> b[i];

    sort(ALL(a)); sort(ALL(b));

    if (n % 2 != 0)
        cout << b[n/2] - a[n/2] + 1 << endl;
    
    else
        cout << (b[n / 2] + b[n / 2 - 1]) - (a[n / 2] + a[n / 2 - 1]) + 1 << endl;
    return 0;
}


Measured memory_bytes: 4832
from collections import deque
def main():
    k = int(input())
    d = deque(list(range(1, 10)))
    ans = 0
    for _ in range(k):
        ans = d.popleft()
        if ans % 10 != 0:
            d.append(10 * ans + (ans % 10) - 1)
        d.append(10 * ans + (ans % 10))
        if ans % 10 != 9:
            d.append(10 * ans + (ans % 10) + 1)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18680
import java.util.Scanner;

public class Main {

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

		int N = scanner.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
		}
		
		int c[] = new int[N];
		int minc = 0;
		for (int i = 0; i < N; i++) {
			int t = A[i];
			int ct = 0;
			while ((t & 0x01) != 1) {
				ct++;
				t = t >> 1;
				if (i != 0 && ct >= minc) break;
			}
			if (i == 0) {
				minc = ct;
			} else if (ct < minc) {
				minc = ct;
			}
			c[i] = ct;
		}
		
		System.out.println(minc);

	}

}


Measured memory_bytes: 23380
A,B,C=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
if A==max(A,B,C):
    print(A*10+B+C)
elif B==max(A,B,C):
    print(B*10+A+C)
elif C==max(A,B,C):
    print(C*10+B+A)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> Pll;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/10;
const ll MOD = 1e9+7;

ll N;
ll s[100010];
vll sum[2][100010];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>N;
  for(ll i=0;i<N;i++){
    cin>>s[i];
  }
  for(ll i=1;i<N;i++){
    sum[0][i].push_back(s[0]);
    for(ll j=i;j<N;j+=i){
      sum[0][i].push_back(sum[0][i].back()+s[j]);
    }
  }
  for(ll i=1;i<N;i++){
    sum[1][i].push_back(s[N-1]);
    for(ll j=N-1-i;j>=0;j-=i){
      sum[1][i].push_back(sum[1][i].back()+s[j]);
    }
  }
  ll ans = 0;
  for(ll A=2;A<=N-1;A++){
    ll M = N-1-A;
    for(ll C=1;C*C<=M;C++)if(M%C==0){
      ll m=M/C;
      if(C<A&&(A%C!=0||A/C>m)){
        ans = max(ans,sum[0][C][m]+sum[1][C][m]);
      }
      swap(C,m);
      if(C<A&&(A%C!=0||A/C>m)){
        ans = max(ans,sum[0][C][m]+sum[1][C][m]);
      }
      swap(C,m);
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 36596
_n=int(input())
_s=input()
t=len([1 for s in _s if s=="."])
c=[]
c.append((t,0))
for n in range(_n):
    if _s[n]=="#":
        t+=1
    else:
        t-=1
    c.append((t,n+1))
c.sort()
print(c[0][0])


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

int main(){
  int N, K; cin >> N >> K;
  vector<int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  cout << accumulate(a.begin(), a.begin()+K, 0);
}

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

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    /*重なりを求める。c-dを固定しa-bを動かして範囲による
    場合分けをするのが数学的な解き方だが、
    今回は配列を使って解くことにする。*/
    int time[101]={0};
    for (int i=a; i<b; i++) time[i] += 1;
    for (int i=c; i<d; i++) time[i] += 1;
    
    int count = 0;
    for (int i=0; i<101; i++) {
        if (time[i] == 2) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#define q(x,y)(f[x]*h[y]%m*h[(x)-(y)]%m)
const z=2e5,m=1e9+7;long long H,W,A,B,i=1,f[1<<18],g[1<<18],h[1<<18],r;
main(){
for(f[0]=1;i<z;i++)f[i]=f[i-1]*i%m;
for(g[1]=1,i=2;i<z;i++)g[i]=g[m%i]*(m-m/i)%m;
for(h[0]=i=1;i<z;i++)h[i]=h[i-1]*g[i]%m;
for(scanf("%d%d%d%d",&H,&W,&A,&B),i=0;i<W-B;i++)r=(r+q(A+i-1,i)*q(W-i+H-A-2,H-A-1))%m;
i=!printf("%d\n",r);
}

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

typedef long long ll;

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

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define ALL(s) (s).begin(),(s).end()
#define ALLn(s,n) s,s+n
#define F first
#define S second
#define pb push_back
#define tc(t) int t; cin >> t; while(t--)
#define _ ios_base::sync_with_stdio(false); cin.tie(NULL);
#define D1(x) { cerr << " [" << #x << ": " << x << "]\n"; }
#define D2(x) { cerr << " [" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }

const ll MOD = 1e9 + 7;
const ll MAXN = 1e6 + 7;
const ll INF = INT_MAX;

void solve() {
	int n,a,b,c;
	cin >> n >> a >> b >> c;

	int abc[3];
	abc[0] = a;
	abc[1] = b;
	abc[2] = c;
	
	vector<char> ans;
	vector<string> v;
	
	map<char,int> mp;
	mp['A'] = 0, mp['B'] = 0, mp['C'] = 0;
	
	F0R(i, n) {
		string s;
		cin >> s;
		v.pb(s);
		mp[s[0]]++;
		mp[s[1]]++;
	}
	
	if(a + b + c == 0) cout << "No\n";
	else {
		
		F0R(i, n) {
			//cout << abc[0] << " " << abc[1] << " " << abc[2] << "\n";
			char f = v[i][0];
			char s = v[i][1];
			char rem = (f == 'A' ? (s == 'B' ? 'C' : 'B') : (f == 'B' ? (s == 'A' ? 'C' : 'A') : (s == 'B' ? 'B' : 'A')));
			mp[f]--;
			mp[s]--;
			if(abc[f -'A'] == 0 && abc[s -'A'] == 0) {
				cout << "No\n";
				return;
			}
			else {
				if((abc[f - 'A'] > abc[s - 'A']) || ((abc[f - 'A'] == abc[s - 'A']) && i != n-1 && (v[i + 1][0] == s || v[i + 1][1] == s))) {
					abc[f - 'A']--; abc[s - 'A']++;
					ans.pb(s);
				}
				else  {
					//if((abc[f - 'A'] < abc[s - 'A']) || ((abc[f - 'A'] == abc[s - 'A']) && mp[f] >= mp[s]))
					abc[f - 'A']++; abc[s - 'A']--;
					ans.pb(f);
				}
			}
		}

		cout << "Yes\n";
		for(auto x: ans) cout << x << "\n";
		cout << "\n";
	}
}

int32_t main() {_
	//tc(t)
		solve();
}



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

int main(){
    int count[26];
    for(int i=0;i<26;i++){
        count[i] = 0;
    }

    string s;
    cin >> s;

    for(int j=0;j<s.size();j++){
        count[s[j] - 'a']++;
    }

    int n = 0;
    for(int i=0;i<26;i++){
        if(count[i] > 1){
            cout << "no" << endl;
            n = 1;
            break;
        }
    }

    if(n == 0){
        cout << "yes" << endl;
    }
    
    return 0;
}


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

const ll mod = 1e9 + 7;

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

/*-------------------------------------------*/

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

    int n, t[100];
    string s[100];

    cin >> n;
    rep(i, n) cin >> s[i] >> t[i];
    string x;
    cin >> x;
    int ans = 0;
    bool b = 0;
    rep(i, n) {
        if(b == 1)
            ans += t[i];
        if(b == 0)
            if(s[i] == x)
                b = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

vector<int> G[15];
int P[15];

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

  rep(i,M){
    int k;
    cin >> k;
    rep(j,k){
      int s;
      cin >> s;
      G[i].push_back(s-1);
    }
  }
  rep(i,M){
    cin >> P[i];
  }
  
  int ret = 0;
  for(ll S=0; S<(1<<N); S++){
    vector<int> x;
    rep(i,N){
      if((S>>i)&1) x.push_back(1);
      else x.push_back(0);
    }
    bool ok = true;
    rep(i,M){
      int tmp = 0;
      rep(j,G[i].size()){
        tmp += x[G[i][j]];
      }
      if(P[i] != tmp%2) ok = false;
    }
    if(ok) ret++;
  }

  cout << ret << endl;
  
  return 0;
}


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

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

  int tmp = 3*a + b;

  int ans = tmp/2;

  cout << ans << endl; 
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){

  char mk[4]={'S','H','C','D'};
  int n,c[4][14],i,j,s,m;
  char g;

  for(i=0;i<4;i++)
    for(j=0;j<14;j++)c[i][j]=0;

      scanf("%d",&n);

      for(i=0;i<n;i++){
	scanf(" %c %d",&g,&s);
	if(g=='S')m=0;
       	if(g=='H')m=1;
      	if(g=='C')m=2;
       	if(g=='D')m=3;
	c[m][s]=1;
  }
      for(i=0;i<4;i++){
	for(j=1;j<14;j++){
	  if(c[i][j]==0)printf("%c %d\n",mk[i],j);
	}
      }

  return 0;
  
    
}

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

vector<int> G[SIZE];
vector<int> ans(SIZE), a(SIZE);
vector<int> L;
void dfs(int k = 0, int p = -1){
    int flag = -1;
    int itr = lower_bound(L.begin(), L.end(), a[k]) - L.begin();
    if (itr == L.size()){
        L.push_back(a[k]);
    }
    else {
        flag = L[itr];
        L[itr] = a[k];
    }
    ans[k] = L.size();
    for (auto &&i : G[k]){
        if (i == p)continue;
        dfs(i, k);
    }
    if (!L.empty() && flag == -1)L.pop_back();
    else L[itr] = flag;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;
    rep(i,n)cin >> a[i];
    rep(i,n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs();
    rep(i,n)
        cout << ans[i] << endl;
}

Measured memory_bytes: 30004
#include<bits/stdc++.h>
using namespace std;
#define M 200005
int n,A[M],mx1[M],mx2[M];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>A[i],mx1[i]=max(mx1[i-1],A[i]);
	for(int i=n;i>=1;i--)mx2[i]=max(mx2[i+1],A[i]);
	for(int i=1;i<=n;i++)printf("%d\n",max(mx1[i-1],mx2[i+1]));
	return 0;
}

Measured memory_bytes: 3968
class Main
{
	public static void main( String[] args )
	{
		java.util.Scanner sc = new java.util.Scanner( System.in );
		
		int n = sc.nextInt();
		while( n != 0 )
		{
			n--;
			
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			
			if( check( a, b, c ) ){
				System.out.println( "YES" );
			}else{
				System.out.println( "NO" );
			}
		}
	}
	static boolean check( int a, int b, int c )
	{
		if( a*a == b*b + c*c )return true;
		if( b*b == c*c + a*a )return true;
		if( c*c == a*a + b*b )return true;
		
		return false;
	}
}

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

int main()
{
	uint32_t N, K, H;
	uint32_t ans = 1000000000;
	vector <uint32_t> h;

	cin >> N >> K;

	for (uint32_t i = 0; i < N; i++)
	{
		cin >> H;
		h.push_back(H);
	}
	sort(h.begin(), h.end());
	for (uint32_t i = 0; i <= N - K; i++)
	{
		if (ans > h[i + K - 1] - h[i]) ans = h[i + K - 1] - h[i];
	}

	cout << ans << endl;
}


Measured memory_bytes: 892
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

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

#define MAX_V 1000

long long int cost[MAX_V][MAX_V]; // cost[u][v] は頂点uからvへのコスト
long long int mincost[MAX_V];
bool used[MAX_V];

long long int prim(int V){
	
	for(int i = 0; i < V; i++){
		mincost[i] = INF;
		used[i] = false;
	}
	
	mincost[0] = 0;
	
	long long int total = 0;
	
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || mincost[u] < mincost[add_v])){
				add_v = u;
			}
		} // 追加する頂点を決定
		
		if(add_v == -1){
			break;
		} // 更新する頂点がない場合、終了
		used[add_v] = true;
		total += mincost[add_v];
		
		for(int u = 0; u < V; u++){
			mincost[u] = min(mincost[u], cost[add_v][u]);
		} // 集合の外の頂点への最小コストを更新
	}
	return total;
}

int main(){
	
	while(true){
		int P, V;
		cin >> P >> V;
		if(P == 0){
			break;
		}
		long long int num[1000];
		for(int i = 0; i < V; i++){
			num[i] = INF;
		}
		for(int i = 0; i < P; i++){
			for(int j = 0; j < V; j++){
				long long int C;
				cin >> C;
				if(C){
					num[j] = min(num[j], C);
				}
			}
		}
		for(int i = 0; i < V; i++){
			cost[i][i] = 0;
		}
		for(int i = 0; i < V; i++){
			cost[0][i + 1] = cost[i + 1][0] = num[i];
		}
		
		for(int i = 1; i <= V; i++){
			for(int j = i + 1; j <= V; j++){
				long long int C;
				cin >> C;
				if(C == 0){
					C = INF;
				}
				cost[j][i] = cost[i][j] = C;
			}
		}
		V++;
		cout << prim(V) << endl;
	}
	return 0;
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define lli long long int
#define inf 2147483647
#define infll LLONG_MAX
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    int k, n, ans = inf;
    cin >> k >> n;
    vector<int> a(n*2);
    rep(i, n){
        cin >> a[i];
        a[i+n] = a[i] + k;
    }

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

Measured memory_bytes: 1792
function main(input) {
  var a = input.split(" ")[0]-0, b = input.split(" ")[1]-0;
  if(a<=5){
    console.log(0);
  }else if(a<=12){
    console.log(b/2);
  }else{
    console.log(b);
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

signed main() {
    int n,m,Q;
    cin >> n >> m >> Q;

    vector<vector<int>> G(n+1);
    for(int i = 0; i < m; i++){
        int l,r;
        cin >> l >> r;
        G[l].push_back(r);
    }
    for(int i = 0; i < n + 1; i++){
        sort(G[i].begin(),G[i].end());
    }

    for(int i = 0; i < Q; i++){
        int p,q;
        cin >> p >> q;
        int ans = 0;
        for(int j = p; j <= q; j++){
            ans += upper_bound(G[j].begin(),G[j].end(), q) - G[j].begin();
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
const int mod = 1e9+7;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  vi c(26);
  for (char x : s) c[x-'a']++;
  ll res = 1;
  for (int x : c) res = res * (x + 1) % mod;
  cout << (res + mod - 1) % mod << endl;
  return 0;
}


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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

int n, m, k;
int a[7][7];

int main() {
	cin >>n>>m>>k;
	for (int i=0 ; i<n ; i++) {
		for (int j=0 ; j<m ; j++) {
			char c;
			cin >>c;
			if (c == '#') a[i][j]++;
		}
	}
	int sol = 0;
	for (int r=0 ; r<(1<<n) ; r++) {
		for (int c=0 ; c<(1<<m) ; c++) {
			int cnt = 0;
			for (int i=0 ; i<n ; i++) {
				for (int j=0 ; j<m ; j++) {
					if (((1<<i)&r) || ((1<<j)&c)) continue;
					cnt += a[i][j];
				}
			}
			if (cnt == k) sol++;
		}
	}
	cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int k;
    cin >> k;
    int cnt = 0;
    int num = 7;
    while(cnt < k){
        cnt++;
        if (num % k == 0){
            cout << cnt << endl;
            return 0;
        }
        num *= 10;
        num += 7;
        num %= k;
    }
    cout << -1 << endl;
    return 0;
}

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

int H, W;
string s[100];

int main(){
    cin >> H >> W;

    for(int i = 0; i < H; i++) cin >> s[i];

    for(int i = 0; i < W+2; i++) cout << "#";
    cout << endl;
    for(int i = 0; i < H; i++) cout << "#" << s[i] << "#" << endl;
    for(int i = 0; i < W+2; i++) cout << "#";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define n 500000
#define mem(arr) memset(arr, 0, sizeof(arr))
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
void solve();
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int times = 1;
//	cin >> times;
	for(int i=0; i<times; i++)
	{
		solve();
		cout << '\n';
	}
	return 0;
}

int a, b, c, d, e, f, g, h;
int arr[n + 50], arr1[n + 50], arr2[n + 50];

//type here

void solve()
{
	string str; cin >> str;
	int ans = 0;
	for(int i=0; i<str.size(); i++)
	{
		if(str[i] == 'g')
		{
			if(i % 2) ans ++; 
		}
		else
		{
			if(i % 2 == 0) ans --;
		}
	}
	cout << ans << '\n';
}

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

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

    int now = 0;
    ll cost = 0, ans = 0;
    rep(i,n) {
        cost += abs(now - a[i]);
        now = a[i];
    }
    cost += abs(a[n-1]);

    ans = cost;
    rep(i,n) {
        if (i == 0) {
            ans -= (abs(a[i]) + abs (a[i] - a[i + 1]));
            ans += abs(a[i+1]);
            cout << ans << endl;
        }
        else if (i == n - 1) {
            ans -= (abs(a[i] - a[i - 1]) + abs(a[i]));
            ans += abs(a[i - 1]);
            cout << ans << endl;
        }
        else {
            ans -= (abs(a[i] - a[i - 1]) + abs(a[i] - a[i + 1]));
            ans += abs(a[i - 1] - a[i + 1]);
            cout << ans << endl;
        }
        ans = cost;
    }
    return 0;
}

Measured memory_bytes: 3952
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

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

  int N;
  std::vector<int> a;
  std::map<int, int> mp;
  std::set<int> st;

  cin >> N;
  a.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
    st.insert(a[i]);
    mp[a[i]]++;
  }

  int ans = 0;

  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    if (*itr > mp[*itr]) {
      ans += mp[*itr];
    }
  else if (*itr < mp[*itr]) {
      ans += mp[*itr] - *itr;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 9728
import java.util.Scanner;

/**
 * Hello world!
 *
 */
public class Main
{
    public static void main( String[] args )
    {
		Scanner scanner = new Scanner (System.in);
		String input = scanner.nextLine();

		IrohaAndEasy solver = new IrohaAndEasy();

		System.out.println(solver.solve(input));

    }

    static class IrohaAndEasy {

    	public String solve(String input) {

    		String answer;
    		String abc[] = input.split(" ");
    		int five = 0;
    		int seven = 0;
    		int other = 0;

    		for(String n :abc) {
    			Integer i = new Integer(n);
    			if( i== 5) {
    				five++;
    			} else if(i == 7) {
    				seven++;
    			} else {
    				other++;
    			}
    		}

    		if(five == 2 && seven == 1) {
    			answer = "YES";
    		} else {
    			answer = "NO";
    		}
    		return answer;
    	}

    }

}


Measured memory_bytes: 21844
using System;

class Program
{
    public static void Main(string[] args)
    {
        string[] inputs = Console.ReadLine().Split(' ');
        int allPeople = int.Parse(inputs[0]);
        int densha = int.Parse(inputs[1]);
        int takushi = int.Parse(inputs[2]);

        int denshaSum = densha * allPeople;

        var result = denshaSum < takushi ? denshaSum : takushi;

        Console.WriteLine(result);
        
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
void output(int*,int);
void insertionsort(int*,int);

int main(){
  int N,i,j;
  int A[1000];

  scanf("%d",&N);
  for(i=0;i<N;i++)
    scanf("%d",&A[i]);

  output(A,N);
  insertionsort(A,N);

  return 0;
}

void output(int A[],int N){
  int i;

  for(i=0;i<N;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

void insertionsort(int A[],int N){
  int i,j,v;

  for(i=1;i<N;i++){
    v=A[i];
    j=i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
    }
    A[j+1]=v;
    output(A,N);
  }
}

Measured memory_bytes: 608
#include <stdio.h>

int main(void)
{
	int n;
	int money;
	
	scanf("%d", &n);
	
	money = 100000;
	while (n != 0){
		money += money * 0.05;
		
		if (money % 1000 != 0){
			money = (money + 999) / 1000 * 1000;
		}
		n--;
	}
	printf("%d\n", money);
	
	return (0);
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <cstring>
#include <cmath>
using namespace std;
#define MAXH 101
#define MAXW 101
#define INF 1000
#define MAXN 100001
#define MOD 1000000007
typedef long long ll;



int main(){
    string S;
    cin >> S;
    ll sum = 0;
    ll pivot = 0;
    for(ll i = 0;i < (1 << (S.length() - 1));i++){
        ll n = i;
        for(int j = 0;j < S.length() - 1;j++){
            if(n % 2 == 1){
                sum += (ll)stol(S.substr(pivot,j  - pivot + 1));
                pivot = j + 1;
            }
            n /= 2;
        }
        if(pivot != S.length()){
            sum += stol(S.substr(pivot));
        }
        pivot = 0;
    }

    printf("%lld\n", sum);

    return 0;
}


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

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

  int m, n, a, b, ans[1010][1010] = {0};
  cin >> m >> n >> a >> b;
  for (int x = 0; x <= m; x++)
  {
    int ones = x * a + (m - x) * (n - a);
    int nume = ones - n * (m - b), deno = b * 2 - m;
    int y = nume / deno;
    if (y * deno != nume || y < 0 || y > n)
      continue;

    vector<pair<int, int>> cols;
    for (int i = 0; i < n; i++)
      cols.push_back({i < y ? b : m - b, i});
    for (int i = 0; i < m; i++)
    {
      int num1 = i < x ? a : n - a;
      sort(cols.begin(), cols.end(), greater<pair<int, int>>());
      for (int j = 0; j < num1; j++)
      {
        assert(cols[j].first > 0);
        cols[j].first--;
        ans[i][cols[j].second] = 1;
      }
    }

    for (int i = 0; i < m; i++)
    {
      for (int j = 0; j < n; j++)
        cout << ans[i][j];
      cout << endl;
    }
    return 0;
  }

  cout << -1 << endl;
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}

int main() {
    int n;
    cin >> n;
    ll ans = 0;
    vector<ll>dp(n+1);
    for(int i = 1;i<=n;i++) {
        for(int j = i;j<=n;j += i) {
            dp[j]++; 
        }
    }
    for(int i = 1;i<=n;i++) {
        ans += i*dp[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 81388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};

const int mxH = 1010;
ll dp[mxH][mxH] = {0LL};

int main(){
    int h, w;
    cin >> h >> w;
    char maze[h][w];
    for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) cin >> maze[i][j];
    dp[0][0] = 1;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(maze[i][j] == '#') dp[i][j] = 0;
            else{
                if(j != 0) dp[i][j] += dp[i][j-1], dp[i][j] %= MOD;
                if(i != 0) dp[i][j] += dp[i-1][j], dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
}

Measured memory_bytes: 9088
#include <iostream>

using namespace std;
int main()
{
	int n, a[110], sum, ans;

ans = 0;
sum = 0;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	if ((sum % n) > n / 2) sum += n;
	sum /= n;

	for (int i = 0; i < n; i++){
		ans += (sum - a[i]) * (sum - a[i]);
	}
	cout << ans << endl;

	return (0);
}


Measured memory_bytes: 256