akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll int64_t
#define rep(i,n) for(int64_t i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr int64_t INF=(1ll<<60);
constexpr int64_t mod=1000000007;
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};


int main(){
    ll n,m;cin>>n>>m;
    
    UnionFind uf(n);
    vector<bool> ans(n);

    rep(i,m){
        ll x,y,z;
        cin>>x>>y>>z;
        x--;y--;z%=2;

        uf.unite(x,y);
    }

    rep(i,n){
        ans[uf.root(i)]=true;
    }

    ll sum=0;
    rep(i,n){
        if(ans[i]==true) sum++;
    }

    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 4432
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s[] = sc.nextLine().split("");
		int ans_flag = 0;
		String l = "L";
		String r = "R";

		for(int i=0; i<s.length;i++) {
			if((i+1)%2==1) {
				if(s[i].equals(l)) {
					ans_flag = 1;
				}
			}else {
				if(s[i].equals(r)) {
					ans_flag = 1;
				}
			}

		}


		if(ans_flag==0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}

}



Measured memory_bytes: 21844
// B.

#include <iostream>

using namespace std;

int main(int argc, char *argv[]) {
	int n, k, x, ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		ans += min(x, abs(x - k)) * 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
//21:46~
//??????????????????????????£???
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

string data;
char goal[9] = "01234567";
queue<string> qu;
map<string,int> mp;
int d[4] = {-4,-1,1,4};
int pos;
int ans[1000];
char tmp;


void solve(){
  mp[goal] = 0;
  qu.push(goal);
  string pre_data;
  while(qu.size()){
    data = qu.front();
    pre_data = data;
    qu.pop();
    pos = data.find('0');
    for(int i = 0; i < 4; i++){
      if(pos + d[i] >= 0 && pos + d[i] < 8 && !(pos == 3 && d[i] == 1) && !(pos == 4 && d[i] == -1)){
        data = pre_data;
        swap(data[pos],data[pos+d[i]]);
        if(mp.find(data) == mp.end()){
          mp[data] = mp[pre_data] + 1;
          qu.push(data);
        }
      }
    }
  }
}

int main(){
  int n = 0;
  size_t c;
  solve();
  while(getline(cin, data)){
    while((c = data.find_first_of(" ")) != string::npos){
      data.erase(c,1);
    }
    ans[n++] = mp[data];
  }
  for(int i = 0; i < n; i++)
    printf("%d\n", ans[i]);
}

Measured memory_bytes: 5440
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char **argv){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n;
	cin>>n;
	vector<ll> a(n);
	for(ll &i:a) cin>>i;
	sort(a.begin(),a.end());
	ll ans=a[n-1];
	int t=n-2,i=t;
	while(t){
		int k=min(2,t);
		t-=k;
		ans+=k*a[i--];
	}
	cout<<ans;
}

Measured memory_bytes: 4760
n, q = map(int, input().split())
s = input()

acc = [0]
sum = 0
for i in range(n-1):
    # if s[i:i+2] == "AC":
    if s[i] == "A" and s[i+1] == "C":
        sum += 1
        acc.append(sum)
    else:
        acc.append(sum)


for _ in range(q):
    l, r = map(int, input().split())
    print(acc[r-1] - acc[l-1])


Measured memory_bytes: 51504
N = int(input())
T = 1
A = 1
for i in range(N):
    Tk = [0,0]
    Ak = [0,0]
    Tn,An = map(int,input().rstrip().split(" "))
    if T % Tn == 0:
        Tk[0] = T
    else:
        Tk[0] = (T // Tn + 1) * Tn
    Ak[0] = (Tk[0] // Tn) * An
    if Ak[0] < A:
        Ak[0] = 10 ** 18 + 1

    if A % An == 0:
        Ak[1] = A
    else:
        Ak[1] = (A // An + 1) * An
    Tk[1] = (Ak[1] // An) * Tn
    if Tk[1] < T:
        Tk[1] = 10 ** 18 + 1
    
    if Tk[0] + Ak[0] <= Tk[1] + Ak[1]:
        T = Tk[0]
        A = Ak[0]
    else:
        T = Tk[1]
        A = Ak[1]
print(A + T)

Measured memory_bytes: 9200
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#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...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}


//extended euclidean algorithm( x is inverse of a wrt b onlt if gcd!=1)
ll gcd(ll a,ll b,ll &x,ll &y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1,y1;
	ll d=gcd(b,a%b,x1,y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;

}


int main()
{
speed
ll n;
cin>>n;
ll a[n];
rep(i,0,n) cin>>a[i];
ll c=0;
ll mx=a[0];
rep(i,1,n)
{
	if(a[i]<mx)
	{
		c+=(mx-a[i]);
	}
	mx=max(mx,a[i]);
}
cout<<c<<endl;

}



Measured memory_bytes: 9772
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = "abcdefghijklmnopqrxtuvwxyz";
		String[] param = b.split("");
		for(int i = 0; i < param.length;i++){
			if(a.contains(param[i]) == true){
			
			}else if(a.contains(param[i]) == false){
				System.out.println(param[i]);
				return;
			}
		}
		System.out.println("None");

	}
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    int  minus_cnt            = 0;
    bool exist_zero           = false;
    int  min_val_without_zero = INF;
    vector<int> A(N);
    REP(i, N) {
        std::cin >> A[i];
        if(A[i] < 0) minus_cnt++;
        if(A[i] == 0) exist_zero = true;
        A[i] = abs(A[i]);
        if(A[i] != 0) min_val_without_zero = min(min_val_without_zero, A[i]);
    }

    if(exist_zero || minus_cnt % 2 == 0) {
        std::cout << accumulate(ALL(A), 0LL) << std::endl;
    }
    else {
        std::cout << accumulate(ALL(A), 0LL) - min_val_without_zero * 2 << std::endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    int A[N],W[N];
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    int x=0;
    for(int i=0;i<N;i++){
        if(i%2==0)
           x+=A[i];
        else
        {
           x+=-1*A[i];
        }
        
    }
    
    W[0]=x;
    for(int i=1;i<N;i++){
        W[i]=2*A[i-1]-W[i-1];
    }
    for(int i=0;i<N;i++){
        cout<<W[i]<<' ';
    }
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  int sum = 0;
  REP(i, n) {
    cin >> a[i];
    sum += a[i];
  }
  int pop = 0;
  REP(i, n) {
    if (a[i] >= sum / float(4 * m)) pop++;
  }
  if (pop >= m) cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){
  int D, G;
  cin >> D >> G;
  G /= 100;
  vector<int> p(D), c(D), full(D), pp(D);
  for(int i = 0; i < D; i++){
    cin >> p.at(i) >> c.at(i);
    c.at(i) /= 100;
    full.at(i) = (i+1) * p.at(i) + c.at(i);
  }
  pp = p;
  int result = 1000;
  for(int tmp = 0; tmp < (1<<D); tmp++){
    bitset<10> bit(tmp);
    p = pp;
    int point = 0;
    int counter = 0;
    for(int i = 0; i < D; i++){
      if(bit.test(i)){
        point += full.at(i);
        counter += p.at(i);
        p.at(i) = 0;
      }
    }
    if(point < G){
      for(int i = D-1; i >= 0; i--){
        while(point < G && p.at(i) > 0){
          point += (i+1);
          counter++;
          p.at(i)--;
        }
        if(point >= G) break;
      }
    }
    result = min(result, counter);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n;
    scanf("%d",&n);
    int x[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d",&x[i]);
    }
    int max=x[0];
    for(i=0;i<n;i++){
        if(x[i] >= max){
            max = x[i];
        }
    }
    int min = 2147483647;
    int j;
    for(j=0;j<=max;j++){
        //jは集会を開く点
        int sum = 0;
        for(i=0;i<n;i++){
            sum += (x[i]-j)*(x[i]-j);
        }if(sum <= min){
            min = sum;
        }
    }
    printf("%d\n",min);
    return 0;
}


Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

#include <map>

double x[111],y[111],r[111];
int g[300][300];


int main(){
    int cnt = 1;
    int n;
    while(cin>>n && n){
        map<double,int> m1,m2;
        vector<double> xs,ys;
        rep(i,n){
            cin>>x[i]>>y[i]>>r[i];
            xs.eb(x[i]+r[i]);
            xs.eb(x[i]-r[i]);
            ys.eb(y[i]+r[i]);
            ys.eb(y[i]-r[i]);
        }
        sort(all(xs));
        sort(all(ys));
        xs.erase(unique(all(xs)), xs.end());
        ys.erase(unique(all(ys)), ys.end());
        memset(g,0,sizeof(g));
        rep(i,n){
            int x1 = lower_bound(all(xs), x[i]-r[i])- xs.begin();
            int x2 = lower_bound(all(xs), x[i]+r[i])- xs.begin();
            int y1 = lower_bound(all(ys), y[i]-r[i])- ys.begin();
            int y2 = lower_bound(all(ys), y[i]+r[i])- ys.begin();
            g[y1][x1]++;
            g[y1][x2]--;
            g[y2][x1]--;
            g[y2][x2]++;
        }
        rep(i,300) loop(j,1,300) g[i][j] += g[i][j-1];
        loop(i,1,300) rep(j,300) g[i][j] += g[i-1][j];
        // rep(i,8){
        //     rep(j,8){
        //         cout << g[i][j] << " ";
        //     }
        //     cout << endl;
        // }
        double ans = 0;
        rep(i,ys.size()-1)rep(j,xs.size()-1){
            if(g[i][j]){
                double h = ys[i+1]-ys[i], w=xs[j+1]-xs[j];
                dump(h,w);
                ans += h*w;
            }
        }
        printf("%d %.2lf\n", cnt++, ans);
    }
}

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

using namespace std;
typedef priority_queue<int, vector<int>, greater<int> > pque;

int np[160000] = {-1, -1, 0};
int primes[14684];

int main()
{
    for(int p=2; p<400; p++)
    {
        if(!np[p])
        {
            for(int i=2*p; i<160000; i+=p)
            {
                np[i] = -1;
            }
        }
    }

    int idx=0;
    for(int i=0; i<160000; i++)
    {
        if(!np[i])
        {
            np[i] = idx;
            primes[idx++] = i;
        }
    }

    int n, p;
    while(cin >> n >> p, ~(n&p))
    {
        pque q;
        n++;
        while(np[n]==-1) n++;
        int pidx = np[n];
        for(int i=0; i<200; i++)
        {
            for(int j=i; j<200; j++)
            {
                q.push(primes[pidx+i] + primes[pidx+j]);
            }
        }
        for(int i=1; i<p; i++) q.pop();
        cout << q.top() << endl;
    }

}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb push_back
#define ff first 
#define ss second  
typedef pair<int,int> pp;
bool com(pp x,pp y){
    return x.ff<y.ff;
} 
const int N=1e5+9; 
int weight[N];
ll price[N];
int n,w;
vector<vector<ll>> dp(N,vector<ll> (102,-1));
ll f(int w,int n){
    if(w==0||n==0){
        return 0;
    }
    if(dp[w][n]!=-1){
        return dp[w][n];
    }
    if(weight[n-1]>w){
        return dp[w][n]=f(w,n-1);
    }
    return dp[w][n]=max(price[n-1]+f(w-weight[n-1],n-1),f(w,n-1));
}
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	cin>>n>>w;
	for(int i=0;i<n;i++){
	    cin>>weight[i]>>price[i];
	} 
	cout<<f(w,n);
	
}


Measured memory_bytes: 86720
//#include "IntMod.h"
//typedef IntMod<1000000007> MInt;
 
//#include "Union_Find.h"
 
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
//#include <unordered_set>
//#include <unordered_map>
#include <iomanip>
#include <sstream>
 
using namespace std;
#define REP(i,a,n) for(int i = a; i < n; ++i)
#define REPM(i,n,a) for(int i = n - 1; i >= a; --i)
#define EPS 0.0001
#define INF 0x3FFFFFFF
#define INFLL 0x3FFFFFFF3FFFFFFF
#define INFD 1.0e+308
typedef long long LL;
typedef unsigned long long ULL;
 
class SplitStream {
	typedef basic_ostream<char, char_traits<char> > BaseOst;
	std::ostream& ost_m;
	bool line_is_empty_m;
public:
	SplitStream(std::ostream& ost);
	template <typename T>
	SplitStream& operator<<(T right);
	SplitStream& operator<<(BaseOst& (*right)(BaseOst&));
};
SplitStream::SplitStream(std::ostream& ost) : ost_m(ost), line_is_empty_m(true) {}
template <typename T>
SplitStream& SplitStream::operator<<(T right) {
	if (!line_is_empty_m) ost_m << ' ';
	line_is_empty_m = false;
	ost_m << right;
	return *this;
}
/* std::endl のみ */
SplitStream& SplitStream::operator<<(BaseOst& (*right)(BaseOst&)) {
	ost_m << '\n';
	ost_m.flush();
	line_is_empty_m = true;
	return *this;
}
SplitStream Scout(cout);
 
template <typename T, int Begin, int End>
class OffsetArray {
	T arr_m[End - Begin];
public:
	OffsetArray();
 
	T& operator[](int index);
	T operator[](int index) const;
};
template<typename T, int Begin, int End>
OffsetArray<T, Begin, End>::OffsetArray() : arr_m() {}
 
template<typename T, int Begin, int End>
T & OffsetArray<T, Begin, End>::operator[](int index) {
	return arr_m[index - Begin];
}
 
template<typename T, int Begin, int End>
T OffsetArray<T, Begin, End>::operator[](int index) const {
	return arr_m[index - Begin];
}
 
int A, B, C;
int main() {
	cin >> A >> B >> C;
	cout << (A == B&&B == C ? 1 : A != B &&B != C&&C != A ? 3 : 2) << endl;
	return 0;
}

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

using namespace std;
using ll = long long;


vector<int> cost, c;
vector<vector<int>> hen;
void dfs(int v, int prev) {
	cost[v] = c.back();
	c.pop_back();

	for(auto i : hen[v]) {
		if(i == prev)continue;
		dfs(i, v);
	} 
}

int main()
{
	int n; cin >> n;
	cost.resize(n), hen.resize(n), c.resize(n);
	for(int i = 0; i < n - 1; i++) {int a, b; cin >> a >> b; a--, b--; hen[a].push_back(b), hen[b].push_back(a);}
	for(int i = 0; i < n ; i++)cin >> c[i];
	sort(c.begin(), c.end());
	cout << accumulate(c.begin(), c.end(), 0) - c.back() << endl;
	dfs(0, -1);
	for(int i = 0; i < n; i++)cout << cost[i] << " ";



}

Measured memory_bytes: 1408
/*input
1
1

*/
 
/*
                                                    ______________
                                                          |       )
                                                          |   )   /
                                                          |______/
                                                    |     |      \
                                                    |     |   )   \
                                                    |_____|_______)
 
*/
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <iomanip>
#include <fstream>
#include <stack>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;
 
#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
int mod = 1000000007;
const int inf = 2147483647;
const ll LL_INF = 1234567890123456789ll;
#define PI 3.14159265
#define endl '\n'
#define F first
#define S second
#define debug(x) cout << #x << " = " << x << endl;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define out(container) for (auto it : container) cout << it << " "; cout << endl;
 
 
template < typename T > T GCD(T a, T b)            { ll t; while(a) { t = a; a = b % a; b = t; } return b; }
template < typename T > string toString(T a)       { return to_string(a); }
template < typename T > void toInt(string s, T &x) { stringstream str(s); str >> x;}
inline int add(int x, int y){ x += y; if(x >= mod) x -= mod; return x;}
inline int sub(int x, int y){ x -= y; if(x < 0) x += mod; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % mod;}
inline int powr(int a, ll b){
  int x = 1 % mod;
  while(b){
    if(b & 1) x = mul(x, a);
    a = mul(a, a);
    b >>= 1;
  }
  return x;
}
inline int inv(int a){ return powr(a, mod - 2);}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  int n, m;
  cin >> n >> m;
  vector<int> vec;
  int v;
  vec.pb(0);
  for (int i = 0; i < n; i++) {
    cin >> v;
    vec.pb(v);
  }  
  vector<bool> good(n + 1, true);
  int a, b;
  while (m--) {
    cin >> a >> b;
    good[a] = (good[a] && (vec[a] > vec[b]));
    good[b] = (good[b] && (vec[a] < vec[b]));
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans += good[i];
  }
  cout << ans << endl;

  return 0;
}

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

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        String[] list = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
        String s = sc.next();

        for (int i = 0; i < list.length; i++) {
            if (s.equals(list[i])) {
                System.out.println(7 - i);
                return;
            }
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

        String next() {
            try {
                while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                    tokenizer = new StringTokenizer(reader.readLine());
                }
            } catch (IOException ignored) {
            }
            return tokenizer.nextToken();
        }

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

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

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

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

	sort(a, a + n);
	cout << abs(a[n - 1] - a[0]) << endl;

	return 0;
}

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

Measured memory_bytes: 4028
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=2e5+5;
int a[N],st[N],b[N],top,len,n,l,r,mid,ans,las;
bool ck(){
//	printf("%d\n",mid);
	top=0,len=0;
	fp(i,1,n)if(!cmax(len,a[i])){
//		printf("%d %d %d\n",i,len,a[i]);
		while(top&&st[top]>a[i])--top;
//		printf("%d %d %d\n",i,len,a[i]);
		len=a[i],las=len;
//		printf("%d %d %d\n",i,len,a[i]);
		while(top&&b[top]==mid-1&&st[top]==las)--las,--top;
//		printf("%d %d %d\n",i,len,a[i]);
		if(!las)return false;
//		printf("%d %d %d %d\n",i,len,a[i],top);
		st[top]!=las?(st[++top]=las,b[top]=1):++b[top];
	}
	return true;
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d",&n);
	fp(i,1,n)scanf("%d",&a[i]);
	R bool fl=1;
	fp(i,2,n)if(a[i]<=a[i-1])fl=0;
	if(fl)return puts("1"),0;
	l=2,r=n;
	while(l<=r){
		mid=(l+r)>>1;
		ck()?(ans=mid,r=mid-1):l=mid+1;
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    long long n;cin>>n;
    long long  arr[n];
    map<long long,long long>s;
    for(long long  i=0;i<n;i++){
        cin>>arr[i];
        if(s.count(arr[i])){
            s[arr[i]]++;
        }else{
            s[arr[i]]=1;
        }
    }
    long long sum=0;
    for(auto x:s){
        if(x.second>=2){
            long long d=x.second;
            d--;
            while(d>0){
                sum+=d;
                d--;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<sum-s[arr[i]]+1<<"\t";
    }
}


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

bool kaibun(int n);

int main()
{
  int A, B;
  cin >> A >> B;
  int count = 0;
  for (int i = A; i <= B; i++) {
    if (kaibun(i)) count++;
  }
  cout << count;
  return 0;
}

bool kaibun(int n)
{
  int m[5], p = 10000;

  for (int i = 0; i < 5; i++) {
      m[i] = n/p;
      n -= m[i]*p;
      p /= 10;
  }

  if ((m[0]==m[4])&&(m[1]==m[3])) return true;
  else return false;
}


Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))
    a = sum([B[i - 1] for i in A])
    c = sum([C[i - 1] for i, j in zip(A[:-1], A[1:]) if i == j - 1])
    print(a + c)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>

using namespace std;

struct Point{
	double x,y;
};

int main(){

	int a,b,c;

	scanf("%d %d %d",&a,&b,&c);

	if(c == 1){
		printf("Open\n");
	}else{
		if(a == 1 && b == 1)printf("Open\n");
		else{
			printf("Close\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2612
#include <iostream>
#include <string>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;

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

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

  rep(i, s.length()) {
    if(s==t) {
      cout << "Yes" << '\n';
      return 0;
    }
    char c = s[0];
    for(int j = 0; j < s.length()-1; ++j) s[j] = s[j+1];
    s[s.length()-1] = c;
  }
  cout << "No" << '\n';
  return 0;
}


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

int main() {
  string s;
  cin>>s;
  vector<int> n;
  for (char c: s) {
    n.push_back(c - '0');
  }
  int len = n.size();
  reverse(n.begin(), n.end());
  long long dp[len][2];
  for (int i=0; i<len; i++) {
    dp[i][0] = -1;
    dp[i][1] = -1;
  }
  dp[0][0] = n[0];
  if (n[0] > 0) {
    dp[0][1] = 10 - n[0];
  }
  for (int i=1; i<len; i++) {
    dp[i][0] = dp[i-1][0] + n[i];
    if (n[i] > 0) {
      dp[i][1] = dp[i-1][0] + 10 - n[i];
    } else {
      dp[i][1] = -1;
    }
    if (dp[i-1][1] > -1) {
      if (n[i] < 9) {
        dp[i][0] = min(dp[i-1][1] + n[i] + 1, dp[i][0]);
      }
      if (n[i] > 0) {
        dp[i][1] = min(dp[i-1][1] + 9 - n[i], dp[i][1]);
      } else {
        dp[i][1] = dp[i-1][1] + 9 - n[i];
      }
    }
  }
  long long ans = dp[len-1][0];
  if (dp[len-1][1] > -1) {
    ans = min(dp[len-1][1] + 1, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 21496
#include<iostream>
#include<cmath>
#define ll long long
using namespace std;
int main()
{
	const int N=5e5;
	static char c[N+2];
	static ll a[N+2]={};
	ll i,j,t,left,right,sum=0;
	
	for(i=1;;i++)
	{
		c[i]=getchar();
		if(c[i]=='\n')
		break;
	}
	t=i;//t为数组长度，此时有t-1个符号。 
	
	
	for(i=1;i<=t-1;i++)
	{
		if(c[i]=='<')
		break;
	}
	a[1]=i-1;
	
	for(i=t-1;i>=1;i--)
	{
		if(c[i]=='>')
		break;
	}
	a[t]=t-1-i;
	
	for(i=1;i<=t-2;i++)
	{
		if(c[i]=='>'&&c[i+1]=='<')
		a[i+1]=0;
		if(c[i]=='<'&&c[i+1]=='<')
		a[i+1]=a[i]+1;
		if(c[i]=='<'&&c[i+1]=='>')
		{
			left=0;right=0;
			for(j=i+1;j<=t-1;j++)
			{
				if(c[j]=='<')
				break;
				right++;
			}
			for(j=i;j>=1;j--)
			{
				if(c[j]=='>')
				break;
				left++;
			}
			a[i+1]=max(right,left);
		}
	}
	for(i=t-2;i>=1;i--)
	{
		if(c[i]=='>'&&c[i+1]=='>')
		a[i+1]=a[i+2]+1;
	}
	
	for(i=1;i<=t;i++)
	{
		sum+=a[i];
	}
	cout<<sum;
	
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> a(N);
  
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  int now = 1, c = 0;
  for (;;) {
    if (now == 2) {
      cout << c << endl;
      break;
    }
    if (c >= N) {
      cout << -1 << endl;
      break;
    }
    c++;
    now = a.at(now - 1);
  }
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll          long long
#define pb          push_back
#define INF         9223372036854775807
#define    endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define lower(u)    transform(u.begin(), u.end(), u.begin(), ::tolower);//convert string u to lowercase;
#define upper(u)    transform(u.begin(), u.end(), u.begin(), ::toupper);
using namespace std;

using namespace __gnu_pbds; 
  
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define N  100005

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
ll fun(ll x)
{
    ll ans=0;
    while(x!=0)
    {
        x=x%(__builtin_popcount(x));
        ans++;
    }
    return ans;
}
void solve()
{
    ll n;
    // cout<<1808079%14<<endl;
    cin>>n;
    string s;
    cin>>s;
    ll one=0;
    for(auto u:s)
        if(u=='1')
            one++;
    reverse(all(s));
    ll sum[2];
    memset(sum,0,sizeof(sum));
    // cout<<one<<endl;
    if(one==0)
    {
        rep(i,0,n)
        {
            cout<<1<<endl;
        }
        return ;
    }
    if(one-1==0)
    {
        sum[0]=0;
    }
    else
    rep(i,0,n)
    {
        if(s[i]=='1')
        sum[0]=(sum[0]+expo(2,i,one-1))%(one-1);
    }
    rep(i,0,n)
    {
        if(s[i]=='1')
        sum[1]=(sum[1]+expo(2,i,one+1))%(one+1);
    }
    // cout<<sum[0]<<" "<<sum[1]<<endl;
    vi ans1;
    rep(i,0,n)
    {
        if(s[i]=='0')
        {
            ll ans=(sum[1]+expo(2,i,one+1))%(one+1);
            ans1.pb(fun(ans)+1);
        }
        else
        {
            if(one-1==0)
            {
                ans1.pb(0);
                continue;
            }

            ll ans=(sum[0]-expo(2,i,one-1)+one-1)%(one-1);
            ans1.pb(fun(ans)+1);
        }
    }
    reverse(all(ans1));
    for(auto u:ans1)
        cout<<u<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5508
import numpy as np
import sys
# 距離K以内にxが居ない
# xからの距離を測る

buf = sys.stdin.buffer
R,C = map(int,buf.readline().split())
black = np.zeros((R+2,C+2),dtype=np.bool)
black[1:-1,1:] = (np.frombuffer(buf.read(R*(C+1)),dtype='S1') == b'#').reshape(R,C+1)

INF = 10 ** 9
dist = np.zeros((R,C),dtype=np.int32)
dist[~black[1:-1,1:-1]] = INF

for n in range(1,R):
  np.minimum(dist[n-1]+1,dist[n],out=dist[n])
for n in range(R-2,-1,-1):
  np.minimum(dist[n+1]+1,dist[n],out=dist[n])

for n in range(1,C):
  np.minimum(dist[:,n-1]+1,dist[:,n],out=dist[:,n])
for n in range(C-2,-1,-1):
  np.minimum(dist[:,n+1]+1,dist[:,n],out=dist[:,n])

answer = dist.max()
print(answer)


Measured memory_bytes: 18336
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    long long x;
    cin>>x;
    long long p = 100,amount=100;
    int t = 0;
    while(amount<= x)
    {
        if(amount>=x)
            break;
        t++;
        amount = floor(p*pow(1.01,1));
        p = amount;
    }
    cout<<t<<endl;
    return 0;
}


Measured memory_bytes: 3716
L = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

K = int(input())

print(L[K-1])


Measured memory_bytes: 38384
#include<stdio.h>

void trace(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 j, i, 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;
    trace(A, N);
  }
}

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

  scanf("%d", &N);

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

  trace(A, N);
  insertionSort(A, N);

  return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)

const ll INF = 10010001010;
const int inf = 1000034000;
typedef vector<ll> vecl;
typedef vector<int> veci;
typedef tuple<string, int, int> TUP;

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


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout << fixed << setprecision(15);
    ll N;
    cin >> N;
    vector<char> C(N);
    ll red = 0;
    ll hani = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> C[i];
        if(C[i] == 'R'){
            red++;
        }
    }
    for (int i = 0; i < red;i++)
    {
        if(C[i] == 'R'){
            hani++;
        }
    }
    cout << red - hani << endl;
}


Measured memory_bytes: 3656
#include<stdio.h>
#include<map>

using namespace std;

map <int, int> gigi;

int main ()
{
    int n, x;
    scanf("%d", &n);

    for(int i = 0; i < n; i++) {
        scanf("%d", &x);
        if(gigi.count(x)) {
            gigi[x]++;
        } else {
            gigi[x] = 1;
        }
    }

    int sum = 0;
    for(auto &ii : gigi) {
        if(ii.second < ii.first) {
            sum += ii.second;
        } else {
            sum += (ii.second - ii.first);
        }
       // printf("%d %d\n", ii.first, ii.second);
    }

    printf("%d", sum);

    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

int main() {
    init();

    int n;
    cin >> n;
    VI a(n);
    FOR(i, 0, n)cin >> a[i];

    int ans = 0;
    FOR(i, 0, n - 1)if (a[i] == i + 1) {
            swap(a[i], a[i + 1]);
            ans++;
    }
    cout << ans + (a[n - 1] == n) << "\n";
}


Measured memory_bytes: 640
a, b = gets.chomp.split(" ").map(&:to_i)

counter = 0
(1..9).each do |i|
  (0..9).each do |j|
    (0..9).each do |k|
      num = %W(#{i}#{j}#{k}#{j}#{i}).join.to_i
      counter = counter.next if num.between?(a, b)
    end
  end
end

puts counter

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define ST first
#define ND second
#define ll long long
#define ld long double
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using namespace std;

const ll  INF = 1e9 + 9;
const ll  MOD = 1e9 + 7;
const long long LINF = (ll)1e18 + 3;
 
// secik.insert({x, t++});
// secik.erase(secik.lower_bound({x,-1}));
// *secik.find_by_order(x)).first << "\n";
// secik.order_of_key(x)
 
//random_device device;
//mt19937 gener(device());
//uniform_int_distribution<ll > gen(0,n-1);
//gen(gener); // generate random number

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

	int x; cin >> x;
	if(x % 1000 == 0) cout << 0;
	else cout << 1000 - (x % 1000);	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	

}

Measured memory_bytes: 3644
def sq(n):
    l = 0
    r = n
    while r-l > 1:
        m = (l+r) // 2
        if m*m < n:
            l = m
        else:
            r = m
    return l

Q = int(input())
for _ in range(Q):
    a, b = map(int, input().split())
    r = sq(a * b)
    if a == b:
        print(2*a-2)
    elif r*(r+1) < a*b:
        print(2*r-1)
    else:
        print(2*r-2)

Measured memory_bytes: 39152
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
//#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e9 + 7;
constexpr ll MOD = 1e9 + 7;

vector<int> b(2 * 200005);
vector<vector<int>> G(2 * 200005);

int main()
{
    ciosup;
    ll a,b,k;
    cin>>a>>b;
    if ((a+b) % 2 == 0){
        cout << (a + b) / 2 << endl;
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
}

Measured memory_bytes: 11264
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));



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

	string S;
	cin >> S;
	int s = 0, g = S.size() - 1,ans=0;
	
	while (s != g + 1 && s != g) {
		if (S[s] == S[g]) {
			s++;
			g--;
		}
		else if (S[s] != S[g] && S[s] != 'x' && S[g] != 'x') {
			cout << -1 << endl;
			return 0;
		}
		else if (S[s] == 'x') {
			ans++;
			s++;
		}
		else {
			ans++;
			g--;
		}
		
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 512
n1 = int(input())
n2 = [int(i) for i in input().split()]

t3 = 0

for i4 in range(n1):
    if n2[i4] != i4 - t3 + 1:
        t3 += 1



if t3 == n1:
    print(-1)
else:
    print(t3)

Measured memory_bytes: 26268
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	public static final void main(String[] args) {
		new Main();
	}

	int w;
	int h;
	char[][] map = new char[2][100*100];
	int sl;
	int sr;
	public Main() {
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if(w==0 && h==0)
				break;
			for(int i=0;i<h;i++){
				String s0 = sc.next();
				String s1 = sc.next();
				for(int j=0;j<w;j++){
					map[0][i*w+j] = s0.charAt(j);
					map[1][i*w+j] = s1.charAt(w-j-1);
					if(map[0][i*w+j]=='L')
						sl = i*w+j;
					if(map[1][i*w+j]=='R')
						sr = i*w+j;
					
				}
			}
			solve();
			System.gc();
		}
	}

	int[] dx = new int[]{-1, 0, 1, 0};
	int[] dy = new int[]{0, -1, 0, 1};
	private void solve() {
		LinkedList<int[]> queue = new LinkedList<int[]>();
		
		int[][] visited = new int[w*h][w*h];
		queue.add(new int[]{sl, sr});

		while(!queue.isEmpty()){
			int[] cp = queue.poll();
			int clp = cp[0];
			int crp = cp[1];
			
			if(visited[clp][crp]==1)
				continue;
			
			visited[clp][crp] = 1;
			for(int i=0;i<4;i++){
				int nlpx = clp%w +dx[i];
				int nlpy = clp/w +dy[i];
				int nrpx = crp%w +dx[i];
				int nrpy = crp/w +dy[i];
				
				if(nlpx<0 || w<=nlpx) nlpx = clp%w;
				if(nlpy<0 || h<=nlpy) nlpy = clp/w;
				if(nrpx<0 || w<=nrpx) nrpx = crp%w;
				if(nrpy<0 || h<=nrpy) nrpy = crp/w;
				
				int nlp = nlpx + nlpy*w;
				int nrp = nrpx + nrpy*w;
				if((nlp<0 || w*h<=nlp) && (nrp<0 || w*h<=nrp))
					continue;
				else if(nlp<0 || w*h<=nlp)
					nlp = clp;
				else if(nrp<0 || w*h<=nrp)
					nrp = crp;
				
				if(map[0][nlp]=='#' && map[1][nrp]=='#')
					continue;
				if(map[0][nlp]=='#')
					nlp = clp;
				if(map[1][nrp]=='#')
					nrp = crp;
				
				if(map[0][nlp]=='%' && map[1][nrp]=='%'){
					System.out.println("Yes");
					queue.clear();
					return;
				}else if(map[0][nlp]=='%' || map[1][nrp]=='%'){
					continue;
				}
if(visited[nlp][nrp]==0)
				queue.add(new int[]{nlp, nrp});
			}
		}
		
		System.out.println("No");
	}
}

Measured memory_bytes: 184328
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] l = new int[2 * n];
		for(int i = 0; i < 2 * n; i++) {
			l[i] = sc.nextInt();
		}
		Arrays.sort(l);
		int ans = 0;
		for(int i = 0; i < 2 * n; i += 2) {
			ans += l[i];
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;

// code
// ------------------------------------------------
int main() {

  ll n;
  string s;
  cin >> n >> s;
  ll ans = 0;
  for(ll i = 1;i < n ;i++)
  {
    string a,b;
    a = s.substr(0,i);
    b = s.substr(i);

    map<char,ll> x,y;
    rep(i,sz(a)) x[a[i]]++;
    rep(i,sz(b)) y[b[i]]++;
    ll cnt = 0;
    for(auto itr = x.begin();itr != x.end();itr++)
    {
      if(y[itr->first] > 0)
        cnt++;
    }
    ans = max(ans,cnt);

  }

  cout << ans << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
using System;
public class Wat {
    public static void Main() {
        string[] read = new string[3];
        read = Console.ReadLine().Split(' ');
        long N = long.Parse(read[0]);
        long A = long.Parse(read[1]);
        long B = long.Parse(read[2]);
        string[] read2 = new string[N];
        read2 = Console.ReadLine().Split(' ');
        long[] X = new long[N];
        for (int i = 0; i < N; i++) {
            X[i] = long.Parse(read2[i]);
        }
        long cost = 0;
        for (int i = 0; i < N - 1; i++) {
            if ((X[i + 1] - X[i]) * A <= B) {
                cost += (X[i + 1] - X[i]) * A;
            } else {
                cost += B;
            }
        }
        Console.WriteLine(cost);
    }
}

Measured memory_bytes: 13272
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from fractions import gcd

class SegmentTree:
    def __init__(self, N, func, I):
        self.sz = N
        self.func = func
        self.I = I
        self.seg = [I]*(N*2)
 
    def assign(self, k, x):
        self.seg[k + self.sz] = x
 
    def build(self):
        for i in range(self.sz - 1, 0, -1):
            self.seg[i] = gcd(self.seg[2 * i], self.seg[2 * i + 1])
 
    def update(self, k, x):
        k += self.sz
        self.seg[k] = x
        while k > 1:
            k //= 2
            self.seg[k] = gcd(self.seg[2 * k], self.seg[2 * k + 1])
 
    def query(self, a, b):
        R = self.I
        a += self.sz
        b += self.sz
        while a < b:
            if a % 2 == 1:
                R = gcd(R, self.seg[a])
                a += 1
            if b % 2 == 1:
                b -= 1
                R = gcd(self.seg[b], R)
            a //= 2
            b //= 2
        return R

def main():
    N = int(readline())
    m = map(int,read().split())
    seg = SegmentTree(N , gcd , 0)
    for i in range(N):
        seg.assign(i , next(m))
    seg.build()
    ans = 1
    for i in range(N):
        ans = max(ans,gcd(seg.query(0,i) , seg.query(i+1,N)))
    print(ans)

main()


Measured memory_bytes: 81340