akhauriyash/Code-Regression huggingface dataset:
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 2019;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    string S;cin >> S;
    reverse(S.begin(),S.end());
    map<int,long long> remainder;
    remainder[0] = 1;
    long long nowRemain = 0;
    for(long long i = 0;i<S.size();i++){
        long long A = S.at(i)-'0';
        long long now = (A*mod_pow(10,i) + nowRemain) % MOD;
        remainder[now]++;
        nowRemain = now;
        //cout << now << endl;
    }
    long long ans = 0;
    for(auto V : remainder){
        ans += (V.second*(V.second-1))/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3808
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int b = 0;
    for (int i = 0; i < n; i++) {
        int t = n - i * 7;
        if (t >= 0 && t % 4 == 0) b = 1;
    }

    cout << (b ? "Yes" : "No") << endl;

    return 0;
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;cin>>S;
    S[3]='8';
    cout<<S<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		String s = sc.nextLine();
		sc.close();
		
		String replacedS = s.replace("ABC", "");
		
		System.out.println((n-replacedS.length())/3);
	}
}


Measured memory_bytes: 21972
#include <stdio.h>

int main(void){
  int r,d,x;
  	scanf("%d%d%d",&r,&d,&x);
  int i=0;
  for(i=0;i<10;++i){
    printf("%d\n",r*x-d);
    x=r*x-d;
  }
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int ans = 0;
    for (int i = 1; i < N; i++) {
        if (A[i]==A[i-1]) {
            A[i] = -1;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>b(3,0);
	rep(i, n) {
		int a;
		cin >> a;
		if (a % 2 == 1) {
			b[0]++;
		}
		else {
			a /= 2;
			if (a % 2 == 0) {
				b[2]++;
			}
			else b[1]++;
		}
	}
	if (b[1]==0) {
		if (b[0] <= b[2] + 1)print("Yes");
		else print("No");
	}
	else {
		if (b[2] >= b[0])print("Yes");
		else print("No");
	}
}

Measured memory_bytes: 3632
import itertools
n,a,b,c = map(int,input().split())

ll = []
for _ in range(n):
    l = int(input())
    ll.append(l)
    

assign = [0, 1, 2, 3]

ans = float('inf')
for assignl in itertools.product(assign, repeat=n):
    mp = -30
    abc = [0,0,0]
    for idx, i in enumerate(assignl):
        if i > 0:
            mp += 10
            abc[i-1] += ll[idx]
    if 0 in abc:
        continue
    else:
        mp += abs(abc[0] - a)
        mp += abs(abc[1] - b)
        mp += abs(abc[2] - c)
    if mp < ans:
        ans = mp
        
print(ans)
            
        
        
        



Measured memory_bytes: 45804
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {

    int X, Y, Z;

    cin >> X >> Y >> Z;


    


    cout << to_string(Z) << " " << to_string(X) << " " << to_string(Y) << endl;


    
    return 0;
}

Measured memory_bytes: 256
/*

Author: @karngyan
Team: BlundersPride

*/

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
using namespace std;

using ll = long long;
using ld = long double;
using vll = std::vector< ll >;
using pll = std::pair< ll, ll >;
using vvll = std::vector<vll>;
using vpll = std::vector< pll >;


#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define endl '\n'
#define pb push_back
#define eb emplace_back
#define rep(i, begin, end) for(__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define max3( a, b, c ) max( a , max(b , c))
#define cres(c,n) (c).clear(),(c).resize(n)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define cntll(a) __builtin_popcountll((a))
#define ff first
#define ss second
#define mk make_pair
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it){}
template<typename T , typename... Args>
void err(istream_iterator<string> it , T a , Args... args)
{
	cerr << *it << " = " << a << endl;
	err(++it , args ... );
}

ll sum(){ return 0; }
template<typename T, typename... Args>
auto sum(T a, Args... args){ return a + sum(args...);}
const ll MOD = 1e9+7;
////////////////////////////////////////////////////////////////////////////////////////////////////////



signed main()
{

	fast;
////////////////////////////////////////////////////////////////////////////////////////////

	ll a , b;
	cin >> a >> b;
	if(a>=13){
		cout<<b;
	}
	else if(a >=6 and a<=12)
		cout<<b/2;
	else
		cout<<0;




	
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define F first;
#define S second;
using namespace std;
typedef pair<int, int> P;

int h, w;
int dy[4] = {1, -1, 0, 0};
int dx[4] = {0, 0, 1, -1};
int f[50][50];
bool contain(int y, int x){
    return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    while(1){
        cin >> w >> h;
        if(h + w == 0) break;
        vector<string> s(h);
        rep(i, 0, h) cin >> s[i];
        rep(i, 0, h) rep(j, 0, w) f[i][j] = 0;
        int bc = 0, wc = 0;
        rep(i, 0, h){
            rep(j, 0, w){
                if(s[i][j] == '.') continue;
                queue<P> q;
                q.push(P(i, j));
                int bt = (s[i][j] == 'W' ? 1 : 0);
                while(!q.empty()){
                    P p = q.front(); q.pop();
                    rep(k, 0, 4){
                        int ny = p.first + dy[k];
                        int nx = p.second + dx[k];
                        // cout << ny << " " << nx << endl;
                        if(!contain(ny, nx)) continue;
                        if(s[ny][nx] == '.'){
                            // if(s[ny][nx] == 'W' || s[ny][nx] == 'B') continue;
                            if(f[ny][nx] & (1 << bt)) continue;
                            f[ny][nx] |= (1 << bt);
                        // cout << p.first << " " << p.second << endl;
                            
                            q.push(P(ny, nx));
                        }
                    }
                }
            }
        }
        rep(i, 0, h){
            rep(j, 0, w){
                // cout << f[i][j] << " ";
                if(f[i][j] == 1) bc++;
                if(f[i][j] == 2) wc++;
            }
            // cout << endl;
        }
        cout << bc << " " << wc << endl;
    }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    string s; cin >> s;
    for(int i=0; i<s.size()-8; i++) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

ll kaz[100005];

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

    vector<ll> A(N);
    ll sum=0;

    for(int i=0;i<N;i++){
        cin >> A[i];
        kaz[A[i]]++;
        sum += A[i];
    }

    
    int Q;
    cin >> Q;

    vector<ll> B(Q);
    vector<ll> C(Q);

    for(int i=0;i<Q;i++){
        cin >> B[i] >> C[i];   
    }
    
    for(int i=0;i<Q;i++){   
        sum -= kaz[B[i]]*B[i];
        sum += kaz[B[i]]*C[i];
        kaz[C[i]] += kaz[B[i]];
        kaz[B[i]] = 0;
        cout << sum<<endl;

        


    }

    

    

    






    return 0;
}

Measured memory_bytes: 6392
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

/*
cin.tie(0);
ios::sync_with_stdio(false);
*/

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

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

int main(){
  string s;
  int k;
  set<string> ans;
  cin>>s>>k;
  for(int i=0;i<26;i++){
    string x="";
    bool ok=false;
    for(int j=0;j<s.size();j++){
      if(char('a'+i)==s[j]||ok){
	x="";
	for(int l=j;l<min(j+5,(int)s.size());l++){
	  x+=s[l];
	  ans.insert(x);
	}
      }
    }
    if(ans.size()>=k)break;
  }
  int cnt=1;
  //cout<<k<<endl;
  for(auto x: ans){
    //cout<<"debug"<<cnt<<": "<<x<<endl;
    if(cnt==k)cout<<x<<endl;
    cnt++;
  }//cout<<ans[k-1]<<endl;
  
  //sort(all(ans));
  //cout<<ans[k-1]<<endl;
  return 0;
}


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

#define endl '\n'

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

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

	string s, t; cin >> s >> t;

	vector<vector<int>> lcs(s.length() + 1, vector<int>(t.length() + 1));
	vector<vector<int>> dir(s.length() + 1, vector<int>(t.length() + 1));

	for(int i = 1; i <= s.length(); ++i)
		for(int j = 1; j <= t.length(); ++j)
		{
			if(s[i - 1] == t[j - 1]) lcs[i][j] = lcs[i - 1][j - 1] + 1, dir[i][j] = 1;
			else if(lcs[i - 1][j] > lcs[i][j - 1]) lcs[i][j] = lcs[i - 1][j], dir[i][j] = 2;
			else lcs[i][j] = lcs[i][j - 1], dir[i][j] = 3;
		}

	string ans = "";
	int x = s.length(), y = t.length();
	while(x > 0 && y > 0)
	{
		switch(dir[x][y])
		{
			case 1:
				--x, --y, ans += s[x];
				break;
			case 2:
				--x;
				break;
			case 3:
				--y;
				break;
		}
	}

	reverse(ans.begin(), ans.end());
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 70912
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vin=vector<int>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;

int main() { 
 int n,m,k;
  cin>>n>>m>>k;
  ////////nを固定して全探索
  bool ok=false;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=m;j++){
      int b=i*j+(n-i)*(m-j);
      if(b==k) ok=true;
    }
    if(ok) break;
    
    
  }
  if(ok)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

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

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long long LL;

LL N,M;

int main(){
	scanf("%lld%lld" , &N , &M);
	LL ans = min(N,M/2);
	N -= ans;
	M -= ans * 2;
	printf("%lld\n" , ans + M / 4);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<long long> pref(n);
    for (int i = 0; i < n; i++) {
        if (i == 0) pref[i] = a[i];
        else pref[i] = pref[i - 1] + a[i];
    }
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] * ((pref[n - 1] - pref[i]) % mod) % mod;
        ans %= mod;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 5620
use std::collections::VecDeque;

fn main() {
    let (n, m) = read_to_pair::<usize>();
    let mut tree: Vec<Vec<usize>> = vec![vec![]; n + 1];
    for _ in 0..m {
        let (u, v) = read_to_pair::<usize>();
        tree[u].push(v);
    }
    let (s, t) = read_to_pair::<usize>();
    let mut q: VecDeque<(usize, usize)> = VecDeque::new();
    let mut reached = vec![vec![false; 3]; n + 1];
    q.push_back((s, 0));
    reached[s][0] = true;
    while !q.is_empty() {
        let (cur, count) = q.pop_front().unwrap();
        if cur == t && count % 3 == 0 {
            println!("{}", count / 3);
            return;
        }
        for v in tree[cur].iter() {
            let next_count = count + 1;
            if !reached[*v][next_count % 3] {
                reached[*v][next_count % 3] = true;
                q.push_back((*v, next_count));
            }
        }
    }
    println!("-1");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_to_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_to_pair<T: std::str::FromStr + Copy>() -> (T, T) {
    let v = read_to_vec();
    (v[0], v[1])
}


Measured memory_bytes: 16636
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#include <complex>

#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef complex<double> P;

typedef pair<double,double> DD;
typedef pair<double, DD> TD;

// 点 p1, p2  の通る直線の方程式
TD calc_line (P p1, P p2 )
{
	double a = p1.imag() - p2.imag();
	double b = p2.real() - p1.real();
	double c = p1.real()*p2.imag() - p2.real()*p1.imag();

	return TD (a, DD (b, c ) );
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.a_symmetric_point", "r", stdin );

	double x1, y1, x2, y2, xq, yq;
	while (scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) != EOF) {
//		cerr << " x1: " << x1 << " y1: " << y1 << " x2: " << x2 << " y2: " << y2 << " xq: " << xq << " yq: " << yq << endl;
		P p1 = P (x1, y1 );
		P p2 = P (x2, y2 );
		P q  = P (xq, yq );
		TD l = calc_line (p1, p2 );
		double a = l.first;
		double b = l.second.first;
		double c = l.second.second;
//		cerr << "a: " << a << " b: " << b << " c: " << c << endl;
		double C = (a*xq + b*yq + c)/(a*a+b*b);
		P ph = q - P(C*a, C*b );
		double x = 2.*ph.real() - xq;
		double y = 2.*ph.imag() - yq;

		printf ("%lf %lf\n", x, y );
	} // end loop
		
	return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define LLI long long int
#define ULTRA 2134567890
#define debug(x) if(MODE==x)
#define MODE 0
using namespace std;

char A[107];
char B[107];

int main()
{
    int i,j;

    scanf("%s",A);
    scanf("%s",B);
    int cnt = 0;
    for( i=0; A[i]; i++)
    {
        if(A[i]==B[i])
            cnt++;
    }
    printf("%d\n",cnt);

    return 0;
}


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

int main() 
{
  int x;
  cin >> x;
  int c500 = x / 500;
  x = x % 500;
  int c5 = x / 5;
  cout << c500 * 1000 + c5 * 5 << endl;
}


Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000
typedef long long i64;

#define M 998244353

int n;
int a[MAXN], c[MAXN];

int input() {
	if (scanf("%d", &n) < 0) return 0;
	for (int i=0; i<n; i++)
		scanf("%d", &a[i]);
	return 1;
}

void init() {
}

i64 solve() {
	if (a[0]!=0) return 0;
	memset(c, 0, sizeof(c));
	for (int i=0; i<n; i++)
		c[a[i]]++;
	i64 r = 1;
	if (c[0]!=1) return 0;
	//printa(c,n);
	for (int i=1; i<n; i++) {
		if (c[i]==0) {
			for (int j=i+1; j<n; j++)
				if (c[j]) return 0;
			break;
		}
		for (int j=0; j<c[i]; j++)
			r = r * c[i-1] % M;
	}
	return r;
}

void output(i64 ans) {
	printf("%lld\n", ans);
}

void cleanup() {
}

int main() {
	//precalc();
	//int ca; scanf("%d", &ca);
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}




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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    int N;
    cin >> N;
    int a = N / 100, b = N % 100;
    int c = a * 10 + a;
    if (c < b){
        ++a;
        cout << a * 100 + a * 10 + a << "\n";
    }
    else {
        cout << a * 100 + a * 10 + a << "\n";
    }

        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

class Dice
{
//              ----------
//		       | S[0]     |
//             |          |
//             |          |
//             |          |
//  --------------------------------------------
//  | S[3]     | S[1]     | S[2]     | S[4]    |
//  |          |          |          |         |
//  |          |          |          |         |
//  |          |          |          |         |
//  |-------------------------------------------
//             | S[5]     |
//             |          |
//             |          |
//             |          |
//              ----------
//
//
private:
	int S[6];		//サイコロの各面の整数を格納する配列
	int top_id;		//サイコロ上面を示す配列添字
	int left_id;	//サイコロ左側面を示す配列添字
	int right_id;	//サイコロ右側面を示す配列添字
	int front_id;	//サイコロ手前の面を示す配列添字
	int back_id;	//サイコロ奥側の面を示す配列添字
	int bottom_id;	//サイコロ底面の面を示す配列添字

public:

	//コンストラクタ
	Dice()
	{
		//サイコロの各面の整数を入力する
		input_surface();

		//初期状態の面を指す配列添字を指定
		top_id = 0;
		left_id = 3;
		right_id = 2;
		front_id = 1;
		back_id = 4;
		bottom_id = 5;

		//output_surface();
	}

	//サイコロの各面の整数を入力する関数
	void input_surface(void)
	{
		for(int i = 0; i < 6; i++)
		{
			cin >> S[i];
		}
	}

	//サイコロを転がす命令を実行
	void exec_operation(const string &opr)
	{
		for(int pos = 0; pos < opr.size(); pos++)
		{
			roll_dice( opr[pos] );
			//output_surface();
		}

		//上面のサイコロの値を出力
		cout << S[top_id] << endl;
	}

	//指定した方向にサイコロを転がす処理を実施
	void roll_dice(const char direction)
	{
		int tmp;

		switch(direction)
		{
			//東方向
			case 'E':
				tmp = top_id;
				top_id = left_id;		//left -> top
				left_id = bottom_id;	//bottom -> left
				bottom_id = right_id;	//right -> bottom
				right_id = tmp;			//top -> right
				break;
			//北方向
			case 'N':
				tmp = top_id;
				top_id = front_id;		//front -> top
				front_id = bottom_id;	//bottom -> front
				bottom_id = back_id;	//back -> bottom
				back_id = tmp;			//top -> back
				break;
			//南方向
			case 'S':
				tmp = top_id;
				top_id = back_id;		//back -> top
				back_id = bottom_id;	//bottom -> back
				bottom_id = front_id;	//front -> bottom
				front_id = tmp;			//top -> front
				break;
			//西方向
			case 'W':
				tmp = top_id;
				top_id = right_id;		//right -> top
				right_id = bottom_id;	//bottom -> right
				bottom_id = left_id;	//left -> bottom
				left_id = tmp;			//top -> left
				break;
			default:
				cout << "[fail]invalid direction" << endl;
				break;
		}
	}
	
	//確認用
	void output_surface(void)
	{
		cout << "S[top] = " << S[top_id] << endl;
		cout << "S[left] = " << S[left_id] << endl;
		cout << "S[right] = " << S[right_id] << endl;
		cout << "S[bottom] = " << S[bottom_id] << endl;
		cout << "S[front] = " << S[front_id] << endl;
		cout << "S[back] = " << S[back_id] << endl;
		cout << "-----------------------------" << endl;
	}
	
};

int main(void)
{
	Dice dice;
	string operation;	//命令を示す文字列

	cin >> operation;		//命令を入力

	dice.exec_operation( operation );
	
	return 0;
}



Measured memory_bytes: 3208
from fractions import gcd
n=int(input())
a=[int(_) for _ in input().split()]
flist=[]
elist=[]

for iii in range(len(a)):
  end=a[len(a)-iii-1]
  front=a[iii]
  if iii==0:
    elist.append(end)
    flist.append(front)
  else:
  	elist.append(gcd(end,elist[-1]))
  	flist.append(gcd(front,flist[-1]))

ans=0
for iii in range(len(elist)-2):
  ans=max(ans,gcd(flist[iii],elist[len(elist)-iii-3]))

ans=max(flist[-2],ans)
ans=max(elist[-2],ans)
print(ans)


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

int main(){
  int N;
  cin>>N;
  vector<int64_t> A(N+1);
  vector<int64_t> B(N);
  for(int i=0;i<=N;++i){
    cin>>A.at(i);
  }
  for(int i=0;i<N;++i){
    cin>>B.at(i);
  }

  int64_t sum=0;
  for(int i=0;i<N;++i){
    if(B.at(i)<A.at(i)){
      sum=sum+B.at(i);
    }
    else if(A.at(i)<=B.at(i) && B.at(i)<A.at(i)+A.at(i+1)){
      sum=sum+B.at(i);
      A.at(i+1)=A.at(i+1)+A.at(i)-B.at(i);
    }
    else{
      sum=sum+A.at(i)+A.at(i+1);
      A.at(i+1)=0;
    }
  }

  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>


using namespace std;

long long n, a[7];
long long ans, MX, j, i, k;

void chmax(long long &x, long long y) {
  x = (x > y ? x : y);
}

int main() {
  scanf("%lld", &n);
  for(i = 1;i <= 6; i++) scanf("%d", &a[i]);
  if(a[1] <= a[4] && a[2] >= a[5] && a[3] >= a[6]) {
    n = n / a[1] * a[4] + (n % a[1]);
    for(i = 0, j = n; i <= n; i++, j = n - i)
      chmax(MX, i % a[5] + j % a[6] + i / a[5] * a[2] + j / a[6] * a[3]);
  } else if(a[1] >= a[4] && a[2] <= a[5] && a[3] >= a[6]) {
    n = n / a[2] * a[5] + n % a[2];
    for(i=0, j = n; i <= n; i++, j = n - i)
      chmax(MX, i % a[4] + j % a[6] + i / a[4] * a[1] + j / a[6] * a[3]);
  } else if(a[1] >= a[4] && a[2] >= a[5] && a[3] <= a[6]) {
    n = n / a[3] * a[6] + n % a[3];
    for(i = 0, j = n; i <= n; i++, j = n - i)
      chmax(MX, i % a[4] + j % a[5] + i / a[4] * a[1] + j / a[5] * a[2]);
  } else if(a[1]<=a[4]&&a[2]<=a[5]&&a[3]<=a[6]||a[1]>=a[4]&&a[2]>=a[5]&&a[3]>=a[6]){
    for(i=0;i<=n;i++)
      for(j=0;j<=n-i;j++){
        k = n - i - j;
        ans=max(i/a[1]*a[4]+i%a[1],i/a[4]*a[1]+i%a[4])+max(j/a[2]*a[5]+j%a[2],j/a[5]*a[2]+j%a[5])+max(k/a[3]*a[6]+k%a[3],k/a[6]*a[3]+k%a[6]);
        chmax(MX, ans);
        MX=max(MX,ans);
      }
  }
  else if(a[1]>=a[4]){//a[2]<=a[5]
    for(i=0;i<=n;i++)
      j=n-i, chmax(MX, i%a[2]+j%a[3]+i/a[2]*a[5]+j/a[3]*a[6]);
    MX=MX/a[4]*a[1]+MX%a[4];
  }else if(a[2]>=a[5]){
    for(i=0;i<=n;i++){
      j=n-i; chmax(MX, i%a[1]+j%a[3]+i/a[1]*a[4]+j/a[3]*a[6]);
    } MX=MX/a[5]*a[2]+MX%a[5];
  }else{
    for(i=0;i<=n;i++){
      j=n-i; chmax(MX, i%a[1]+j%a[2]+i/a[1]*a[4]+j/a[2]*a[5]);
    } MX=MX/a[6]*a[3]+MX%a[6];
  } printf("%lld\n", MX);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
struct UFT{
  vector<int> par;//親
  vector<int> rank;//木の深さ
  vector<int> size;//木の大きさ
  int n;
  
  UFT(int _n)
  {
    n = _n;
    par.resize(n);
    rank.assign(n,0);
    size.assign(n,0);
    rep(i,n){
      par[i] = i;
    }
  }
  
  //xの根を返す
  int find(int x)
  {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
  }

  //x,yを併合
  void unite(int x,int y)
  {
    x = find(x);
    y = find(y);
    if(x == y) return;

    if(rank[x] < rank[y]){
      par[x] = y;
      size[y] += size[x];
    }
    else{
      par[y] = x;
      size[x] += size[y];
      if(rank[x] == rank[y]) rank[x]++;
    }
  }

  //x,yが同じグループにいるかどうかを返す
  bool same(int x,int y)
  {
    return find(x) == find(y);
  }

  //xの属する木のサイズを探す
  int usize(int x)
  {
    return size[find(x)];
  }
};
const int M = 100010;
int main()
{
  ll n;cin >> n;
  vector<int> x(n), y(n);
  rep(i,n) {
    cin >> x[i] >> y[i];
    x[i]--; y[i]--;
  }

  UFT uf(2*M);
  rep(i,n) uf.unite(x[i], y[i] + M);
  map<int,ll> mx, my;
  rep(i, M) mx[ uf.find(i) ]++;
  rep(i, M) my[ uf.find(i + M) ]++;
  
  ll res = 0;
  rep(i, 2*M) res += mx[i]*my[i];
  cout << res - n << "\n";
  
  return 0;
}


Measured memory_bytes: 28416
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n; cin>>n;
	cout<<n*n*n<<"\n";
	return 0;
}





























Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    let [n, d] = nextIntArray()
    let cnt = 0
    while(hasNext()){
        let tmp = nextIntArray()
        let dd = Math.sqrt(tmp[0]*tmp[0] + tmp[1]*tmp[1])
        if(dd <= d) cnt++
    }
    console.log(cnt)
}
Main()



Measured memory_bytes: 62572
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let m: usize = scan(tokens);
    let mut value = vec![0; m];
    let mut bits = vec![0; m];
    for i in 0..m {
        let a: usize = scan(tokens);
        let b: usize = scan(tokens);
        let mut d: usize = 0;
        for _ in 0..b {
            let c: usize = scan(tokens);
            d |= 1 << (c - 1);
        }
        value[i] = a;
        bits[i] = d;
    }
    let inf: usize = 1_000_000_000;
    let mut dp = vec![inf; 1 << n];
    dp[0] = 0;
    for i in 0..m {
        for b0 in 0..1 << n {
            let b1 = b0 | bits[i];
            dp[b1] = std::cmp::min(dp[b1], dp[b0] + value[i]);
        }
    }
    if dp[(1 << n) - 1] == inf {
        println!("-1");
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }
}


Measured memory_bytes: 4352
N = int(input())
h = [int(i) for i in input().split()]

ans = 0

while max(h):
    mx = max(h)
    on = False

    for i in range(N):
        if h[i] == mx:
            h[i] -= 1
            if not on:
                ans += 1
            on = True
        else:
            on = False

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string a;
  cin>>a;
  int k=a.length();
  if(a[0]==a[k-1])
  {
    if(k%2==0)
	{
      cout<<"First"<<endl;
      return 0;
    }
    else
	{
      cout<<"Second"<<endl;
      return 0;
    }
  }
  else
  {
    if(k%2==0)
	{
      cout<<"Second"<<endl;
      return 0;
    }
    else
	{
      cout<<"First"<<endl;
      return 0;
    }
  }
  return 0;
}

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

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    if (abs(c-a) <= d || (abs(a-b) <= d && abs(b-c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, mod = 998244353;
int n, k;
int l[15], r[15];
int f[N], s[N];
inline int read () {
    int tot = 0, f = 1; char c = getchar ();
    while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar (); }
    while (c >= '0' && c <= '9') { tot = tot * 10 + c - '0'; c = getchar (); }
    return tot * f;
}
signed main () {
    n = read (); k = read ();
    for (int i = 1; i <= k; i++) {
        l[i] = read (); r[i] = read ();
    }
    f[1] = 1; s[1] = 1;
    for (int i = 2; i <= n; i++) {
        // cout << i << endl;
        for (int j = 1; j <= k; j++) {
            int L = max (i - r[j], 1ll), R = i - l[j]; if (R <= 0) continue;
            // cout << L << " " << R << endl;
            f[i] += s[R] - s[L - 1];
            f[i] %= mod;
        }
        s[i] = s[i - 1] + f[i];
    }
    // for (int i = 0; i < n; i++) printf ("%lld\n", f[i]);
    printf ("%lld\n", f[n]);
    return 0;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int_fast32_t n;
    string s;

    cin >> n >> s;

    vector<int_fast32_t> pr, pg, pb;

    for(int_fast32_t i = 0; i < n; ++i) {
        switch(s.at(i)) {
            case 'R':
                pr.emplace_back(i);
                break;
            case 'G':
                pg.emplace_back(i);
                break;
            case 'B':
                pb.emplace_back(i);
                break;
        }
    }

    int_fast64_t ans = pr.size() * pg.size() * pb.size();

    for(int_fast32_t i: pr) {
        for(int_fast32_t j: pg) {
            if(i < j) {
                if(2 * i - j >= 0 && s.at(2 * i - j) == 'B') --ans;
                if(2 * j - i < n && s.at(2 * j - i) == 'B') --ans;
                if((j - i) % 2 == 0 && s.at((i + j) / 2) == 'B') --ans;
            }
            if(i > j) {
                if(2 * j - i >= 0 && s.at(2 * j - i) == 'B') --ans;
                if(2 * i - j < n && s.at(2 * i - j) == 'B') --ans;
                if((i - j) % 2 == 0 && s.at((i + j) / 2) == 'B') --ans;
            } 
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 3628
s = input()
ascii_lowercase = list('abcdefghijklmnopqrstuvwxyz')
s = list(s)
s = set(s)
s = list(s)
s = sorted(s)
n = len(s)
flag = 0

for i in range(n):
    if s[i] != ascii_lowercase[i]:
        print(ascii_lowercase[i])
        flag = 1
        break

if len(s) != len(ascii_lowercase) and flag != 1:
    print(ascii_lowercase[len(s)])
elif flag != 1:
    print('None')


Measured memory_bytes: 9756
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
#include <cstdint>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    ll div = N / (A + B);
    ll mo = N % (A + B);
    cout << A * (div) + min(mo, A) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define ll long long int

using namespace std;


main()
{
	ll n;
	cin>>n;
	ll a[n+1];
	a[0]=0;
	for(ll i=0;i<=n;i++)
	{
		a[i]=0;
	}
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			for(ll k=1;k<=n;k++)
			{
				ll mul = i*(i+j) + j*(j+k) + k*(k+i);
				if(mul>n)
					break;
				a[mul]++; 		
			}
		}
	}
	for(ll i=1;i<=n;i++)
		cout<<a[i]<<endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
  int n;
  cin >> n;
  map<int,long long int>mp;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
    mp[v[i]]++;
  }
  
  map<int,long long int>mp1;
  long long int sum=0;
  for(auto it = mp.begin();it!=mp.end();it++){
      long long int k = it->second;
      mp1[it->first]=((k-1)*(k-2))/2;
      mp[it->first]=(k*(k-1))/2;
      sum+= k*(k-1)/2;

  }
  for(int i=0;i<n;i++){
      cout << sum - mp[v[i]] +mp1[v[i]] <<"\n";
  }        
    
}

Measured memory_bytes: 18176
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]
 
sys.setrecursionlimit(1000000)
mod = 1000000007
 
def solve():
  N,M = map(int,input().split())
  A = list(map(int,input().split()))
  count = 0
  
  for i in A:
    if i*4*M >= sum(A):
      count += 1
 
  if count >= M:
    print("Yes")
  else:
    print("No")
  return
 
#Solve
if __name__ == "__main__":
    solve()

Measured memory_bytes: 38384
import java.util.ArrayDeque

fun main(args: Array<String>) {
    while (true) {
        val (W, H) = readLine()!!.split(" ").map(String::toInt)

        if (W == 0 && H == 0) {
            return
        }
        val graph = Array(H) { readLine()!!.split(" ") }

        val seen = Array(H) { BooleanArray(W) }

        var count = 0
        for (i in 0 until H) {
            for (j in 0 until W) {
                if (graph[i][j] == "0" || seen[i][j]) {
                    continue
                }
                val stack = ArrayDeque<Pair<Int, Int>>()
                stack.push(i to j)

                while (stack.isNotEmpty()) {
                    val (h, w) = stack.pop()
                    seen[h][w] = true
                    for (th in -1..1) {
                        for (tw in -1..1) {
                            val ch = h + th
                            val cw = w + tw
                            if (ch in 0 until H && cw in 0 until W && !seen[ch][cw] && graph[ch][cw] == "1") {
                                stack.push(ch to cw)
                            }
                        }
                    }
                }
                count++
            }
        }
        println(count)
    }
}


Measured memory_bytes: 36996
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)

def main():
    a, b = map(int, input().strip().split())
    if a <10 and b < 10:
        print(a*b)
    else:
        print(-1)

if __name__ == '__main__':
    main()


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

std::string rotate(std::string &input) {
	std::string result;
	return input[input.size() - 1] + input.substr(0, input.size() - 1);
}

int main(int argc, char *argv[]) {
	std::string S;
	std::string T;
	std::cin >> S >> T;

	
	bool is_ok(false);
	for (int i = 0; i <= S.size() * 2; i++) {
		S = rotate(S);
		if (S == T) {
			is_ok = true;
			break;
		}
	}

	std::cout << ((is_ok) ? "Yes" : "No") << std::endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N):
    if A[i] < 0:
        A[i] = -A[i]
        cnt += 1
if cnt % 2 == 0:
    print(sum(A))
else:
    print(sum(A) - 2*min(A))

Measured memory_bytes: 14412
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int num[500005];
int vis[500005];
int t;

int abs1(int x)
{
   if (x>=0)
      return x;
   else
      return -x;
}
int check(int x)
{
   x%=2;
   if (x==0)
      return (vis[t]^1);
   else
      return vis[t];
}

int main()
{
cin>>t;
for (int a=1;a<=2*t-1;a++)
   scanf("%d",&num[a]);
int l=1,r=2*t-1;
int mid;
int k;
while (l<=r)
{
   mid=(l+r)>>1;
   k=-1;
   for (int a=1;a<=2*t-1;a++)
      if (num[a]>=mid)
         vis[a]=1;
      else
         vis[a]=0;
   pair<int,int> flag1;
   pair<int,int> flag2;
   flag1.first=-1;
   flag2.first=-1;
   for (int a=t;a>=2;a--)
      if (vis[a]==vis[a-1])
      {
	     flag1.second=vis[a];
         flag1.first=a;
         break;
	  }
   for (int a=t;a<2*t-1;a++)
      if (vis[a]==vis[a+1])
      {
         flag2.second=vis[a];
         flag2.first=a;
         break;
	  }
   if (flag1.first!=-1||flag2.first!=-1)
   {
      if (abs1(flag1.first-t)>abs1(flag2.first-t))
         k=flag2.second;
      else
         k=flag1.second;
   }
   if (k==-1)
      k=check(t);
   if (k==0)
      r=mid-1;
   if (k==1)
      l=mid+1;
}
cout<<r;
	return 0;
}

Measured memory_bytes: 1792
/*
Author:loceaner
*/
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

const int A = 5e5 + 11;
const int B = 1e6 + 11;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;

inline int read() {
	char c = getchar(); int x = 0, f = 1;
	for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for( ; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
	return x * f;
}

char s[A];
int cnt1, cnt2, cnt3, cnt4;

int main() {
	int n = read();
	for (int i = 1; i <= n; i++) {
		scanf("%s", s + 1);
		if (s[1] == 'A') cnt1++;
		else if (s[1] == 'W') cnt2++;
		else if (s[1] == 'R') cnt3++;
		else if (s[1] == 'T') cnt4++;
	}
	printf("AC x %d\n", cnt1);
	printf("WA x %d\n", cnt2);
	printf("TLE x %d\n", cnt4);
	printf("RE x %d\n", cnt3);
	return 0;
}


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

int main() {
    string s;
    cin >> s;
    int r = 0;
    for(int i = 0; i < s.length() / 2; i++)
        r += s[i] != s[s.length() - i - 1];
    cout << r << endl;
    return 0;
}


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

int main()
{
	int64_t n, wlim;
	cin >> n >> wlim;
	vector<int64_t> ws(n), vs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> ws[i] >> vs[i];
	}
	vector<vector<int64_t>> dp(n, vector<int64_t>(wlim + 1, 0));
	dp[0][ws[0]] = vs[0];
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j <= wlim; j++)
		{
			dp[i][j] = max(dp[i][j], dp[i - 1][j]);
			if (j + ws[i] <= wlim)
			{
				dp[i][j + ws[i]] = max(dp[i][j + ws[i]], dp[i - 1][j] + vs[i]);
			}
		}
	}
	int64_t ans = -1;
	for (int j = 0; j <= wlim; j++)
	{
		ans = max(ans, dp[n - 1][j]);
	}
	cout << ans << endl;
	return 0;
}

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

#define INF (INT32_MAX)
#define MOD (1000000000+7)
#define MAX 10

int N, K;
int D[MAX];

vector<int> v;
int digit;

int dfs( int d, int add )
{
	if( d >= digit ) {
		return add;
	}
	int res[10] = { 0 };
	for( int i = 0; i < v.size(); i++ ) {
		res[i] = dfs( d + 1, add * 10 + v[i] );
	}
	int ans = INF;
	for( int i = 0; i < 10; i++ ) {
		if( res[i] < N ) {
			continue;
		}
		ans = min( ans, res[i] );
	}
	return ans;
}

int main() {
	cin >> N >> K;
	for( int i = 0; i < K; i++ ) {
		cin >> D[i];
	}

	for( int i = 0; i < 10; i++ ) {
		int flag = 0;
		for( int j = 0; j < K; j++ ) {
			if( i == D[j] ) {
				flag = 1;
				break;
			}
		}
		if( flag == 0 ) {
			v.push_back( i );
		}
	}
	int n = N;
	while( n > 0 ) {
		n /= 10;
		digit++;
	}
	int ans = dfs( 0, 0 );
	if( ans == INF ) {
		int mi = INF;
		int mii = INF;
		for( int i = 0; i < v.size(); i++ ) {
			if( v[i] < mi ) {
				mi = v[i];
			}
			if( v[i] > 0 && v[i] < mii ) {
				mii = v[i];
			}
		}
		ans = mii;
		for( int i; i < digit; i++ ) {
			ans = ans * 10 + mi;
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

#define NUM_KETA (4 + 1 + 1) /* strlen('9999\0') + carry */

bool incr(char N[NUM_KETA], const uint32_t idx)
{
    bool f = false;

    for (int32_t i = idx; i >= 0; i--) {
        if (N[i] == '9') {
            N[i] = '0';
            f = true;
        } else {
            N[i]++;
            break;
        }
    }
    for (int32_t i = idx + 1; i < NUM_KETA; i++) {
        N[i] = '0';
    }

    return f;
}

uint32_t getLen(const char N[NUM_KETA])
{
    const char *p = N;
    uint32_t ret = NUM_KETA;
    while (*p == '0') {
        ret--;
        p++;
    }
    return ret;
}

int main(void)
{
    char buf[NUM_KETA];
    char N[NUM_KETA];
    uint32_t K;
    vector<char> D;

    /* input */
    cin >> buf >> K;
    for (uint32_t i = 0; i < K; i++) {
        char d;
        cin >> d;
        D.push_back(d);
    }

    // for (uint32_t i = 0; i < K; i++) {
    //     printf("D[%u] = %c\n", i, D[i]);
    // }

    uint32_t len = strlen(buf);
    for (uint32_t i = 0; i < NUM_KETA - len; i++) {
        N[i] = '0';
    }
    for (uint32_t i = 0; i < len; i++) {
        N[NUM_KETA - len + i] = buf[i];
    }

    /* calc */
    for (uint32_t i = NUM_KETA - getLen(N); i < NUM_KETA; i++) {
        bool f = false;
        // printf("check N[%u] = '%c'\n", i, N[i]);
        while (find(D.begin(), D.end(), N[i]) != D.end()) {
            // printf("incr N[%u] = '%c'\n", i, N[i]);
            f = incr(N, i);
            if (f) {
                break;
            }
        }
        if (f) {
            // printf("true\n");
            i = NUM_KETA - getLen(N) - 1;
            // printf("set i = %u\n", i);
            continue;
        }
    }

    /* output */
    char *p = N;
    while (*p == '0') p++;
    printf("%s\n", p);

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <chrono>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define eps 1e-9
#define f first
#define s second

typedef long long ll;

using namespace std;

const int N = 1e5;
int a[N+5];
int a1[N+5];

int main()

{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int n;
    ll ans = 0, ans1 = 0;

    cin >> n;

    int arr[n];
    pair <int, int> p[n];

    for (int i = 0; i < n; i++) {

        cin >> arr[i];

        if (i == 0) p[i].first = 1;
        else if (i == n-1) {
            if (i%2) p[i].first = -1;
            else p[i].first = 1;
        } else if (i%2) p[i].first = -2;
        else p[i].first = 2;

        p[i].second = i;
    }

    sort(p, p+n);
    sort(arr, arr+n);

    for (int i = n-1; i >= 0; i--) a[p[i].second] = arr[i];
    for (int i = 0; i < n; i++) a1[p[i].second] = arr[n-1-i];

    for (int i = 0; i < n-1; i++) ans+=abs(a[i+1]-a[i]), ans1+=abs(a1[i+1]-a1[i]);

    cout << max(ans, ans1);

    return 0;
}


Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
#define int long long
int n,s[200005],a;
signed main()
{
	cin>>n;
	for(int i=1;i<=n-1;i++)
	{
		cin>>a;
		s[a]++;
	}
	for(int i=1;i<=n;i++)
		cout<<s[i]<<endl;
}

Measured memory_bytes: 5148