akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <cassert>
#include <array>
#include <tuple>
#include <initializer_list>
#include <unordered_set>
#include <unordered_map>
#include <forward_list>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

struct union_find {
    std::vector<int> parent;
    int __size;
    union_find(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) std::swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

using pii = pair<int, int>;
vector<pii> road, rail;

int n, k, l;

int main() {
    while (cin >> n >> k >> l) {

        road.resize(k);
        road.resize(l);
        
        union_find uf_r(n);
        union_find uf_l(n);
        
        for (int i = 0; i < k; i++) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            uf_r.unite(a, b);
        }

        for (int i = 0; i < l; i++) {
            int a, b;
            cin >> a >> b;
            --a; --b;
            uf_l.unite(a, b);
        }
        map<pair<int, int>, vector<int>> mp;
        for (int i = 0; i < n; i++) {
            mp[make_pair(uf_l.find(i), uf_r.find(i))].push_back(i);
        }
        vector<int> ans(n);
        for (int i = 0; i < n; i++) {
            ans[i] = mp[make_pair(uf_l.find(i), uf_r.find(i))].size();
        }
        for (int i = 0; i < n-1; i++) {
            cout << ans[i] << ' ';
        }
        cout << ans[n - 1] << endl;
    }
}

Measured memory_bytes: 23732
import java.util.Scanner

fun main(args: Array<String>) {
  val cin = Scanner(System.`in`)
  val n = cin.nextInt()

  var p = Array<Int>(n, {0})

  for (i in 0.. n - 1) {
    p[i] = cin.nextInt()
  }

  var ct = 0
  var tmpForSwap: Int
  for (i in 0..n - 1) {
    if (p[i] == i + 1) {
      var j: Int
      if (i + 1 == n) {
        j = i - 1
      } else {
        j = i + 1
      }
      tmpForSwap = p[i]
      p[i] = p[j]
      p[j] = tmpForSwap
      ct++
    }
  }

  println(ct)
  cin.close()
}

Measured memory_bytes: 54244
open Batteries

let scan fmt f =
  Scanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> String.split_on_char ' '
  |> List.map cnv

let scan_array n m e conv =
  let arr = Array.make_matrix n m e in
  Enum.Labels.iter (0 --^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list conv);
  arr

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let dbg x = Printf.eprintf "[debug]%s\n" @@ dump x; x

let n = scan "%d" identity
let s = scan "%s" identity

let () =
  Enum.Labels.map (0 --^ 1000)
    ~f:(fun i ->
        let d = String.to_list @@ Printf.sprintf "%03d" i in
        let last = List.Labels.fold_left d
            ~init:0 ~f:(fun i c ->
                if i < n then
                  match String.Exceptionless.find_from s i @@ String.of_char c with
                  | Some i -> succ i
                  | None -> n+1
                else n+1)
        in
        if last < n+1 then 1 else 0)
  |> Enum.sum
  |> Printf.printf "%d\n"


Measured memory_bytes: 3712
from collections import deque

class mf_graph:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
    
    def add_edge(self,v,w,cap):
        edge = [w,cap,None]
        edge[2] = rev_edge = [v,0,edge]
        self.graph[v].append(edge)
        self.graph[w].append(rev_edge)
    
    def bfs(self,s,t):
        self.level = [None]*self.N
        dq = deque([s])
        self.level[s] = 0
        while dq:
            v = dq.popleft()
            nlevel = self.level[v]+1
            for w,cap,_ in self.graph[v]:
                if cap and self.level[w] is None:
                    self.level[w] = nlevel
                    dq.append(w)
        return self.level[t] is not None
    
    def dfs(self,s,v,f):
        if v == s:
            return f
        for rev in self.it[v]:
            w,_,e = rev
            cap = e[1]
            if cap and self.level[w] is not None:
                if self.level[v] > self.level[w]:
                    d = self.dfs(s,w,min(f,cap))
                    if d:
                        e[1] -= d
                        rev[1] += d
                        return d
        self.level[v] == self.N
        return 0
    
    def flow(self,s,t,flow_limit=float('inf')):
        flow = 0
        while self.bfs(s,t):
            *self.it, = map(iter,self.graph)
            f = flow_limit
            while f:
                f = self.dfs(s,t,flow_limit-flow)
                flow += f
        return flow

N,M = map(int, input().split())
S = [list(input()) for i in range(N)]
dc = mf_graph(N*M+2)

s =N*M
t = N*M+1
for i in range(N):
    for j in range(M):
        if (i+j) % 2 == 0:
            dc.add_edge(s,M*i+j,1)
        else:
            dc.add_edge(M*i+j,t,1)

for i in range(N):
    for j in range(M):
        if j+1 < M and S[i][j] == "." and S[i][j+1] == ".":
            u,v = M*i+j,M*i+j+1
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)
        if i+1 < N and S[i][j] == "." and S[i+1][j] == ".":
            u,v = M*i+j, M*(i+1)+j
            if (i+j) % 2 == 1:
                u,v = v,u
            dc.add_edge(u,v,1)

print(dc.flow(s,t,10**9))
for u in range(N*M+2):
    for v,cap,_ in dc.graph[u]:
        ui,uj = divmod(u,M)
        vi,vj = divmod(v,M)
        if (ui+uj) % 2 == 0 and cap == 0 and u != s and u != t and v != s and v!= t:
            if ui+1 == vi:
                S[ui][uj] = "v"
                S[vi][vj] = "^"
            elif ui == vi+1:
                S[ui][uj] = "^"
                S[vi][vj] = "v"
            elif uj+1 == vj:
                S[ui][uj] = ">"
                S[vi][vj] = "<"
            elif uj == vj+1:
                S[ui][uj] = "<"
                S[vi][vj] = ">"

for res in S:
    print("".join(res))

Measured memory_bytes: 18524
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#define int long long
typedef long long ll;
using namespace std;

ll N;
vector<ll> vemp;
map<ll, char> M;

void vecdp(vector<ll> v){
    //for(ll i=0;i<v.size();i++) cout << v[i];
    for(ll i=0;i<v.size();i++) cout << M[v[i]];
    cout << endl;
}

void dfs(ll count, ll id, vector<ll> v){
    if(count==N-1) {
        vecdp(v);
        return;
    }
    ll i=0;
    while(i<=id+1){
        //cout << i;
        v[count+1] = i;
        if(i==id+1) dfs(count+1, id+1, v);
        else dfs(count+1, id, v);
        i++;
    }
    /*
    for(ll i=0;i<=id+1;i++){
        cout << i;
        v[count+1] = i;
        if(i==id+1) dfs(count+1, id+1, v);
        else dfs(count+1, id, v);
    }
    */
}

signed main(){
    cin >> N;
    vemp.resize(N);
    for(ll i=0;i<N;i++) {
        vemp[i] = 0;
        M[i] = 'a'+i;
        //cout << M[i];
    }
    dfs(0, 0, vemp);
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
using namespace std;
vector<int> AA(int n,string a[])
{
    vector<int> aa={0,0,0,0};
    for (int i = 0; i <n ; ++i) {
        if(a[i]=="AC")aa[0]++;
        if(a[i]=="TLE")aa[2]++;
        if(a[i]=="WA")aa[1]++;
        if(a[i]=="RE")aa[3]++;
    }
    return aa;
}
int main() {
vector<int>aa;
int n;
cin>>n;
string a[n];
    for (int i = 0; i <n ; ++i) {
        cin>>a[i];
    }
    aa=AA(n,a);
    cout<< "AC x "<<aa[0]<<endl;
    cout<< "WA x "<<aa[1]<<endl;
    cout<< "TLE x "<<aa[2]<<endl;
    cout<< "RE x "<<aa[3]<<endl;

}


Measured memory_bytes: 6748
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll lmax(ll a, ll b){if(a>= b) return a;return b;}
ll lmin(ll a, ll b){if(a>= b) return b;return a;}

int main() {
  int n, m; cin >> n >> m;
  vector<ll> h(n);
  rep(i, n) cin >> h[i];
  vector<vector<int>> v(n, vector<int>(0));
  rep(i, m){
    int a, b; cin >> a >> b;
    --a; --b;
    v[a].pb(b);
    v[b].pb(a);
  }

  int ans = 0;
  rep(i, n){
    bool flag = true;
    for(auto x:v[i]){
      if(h[i] <= h[x]) flag = false;
    }
    if(flag) ++ans;
  }

  cout << ans << endl;
}


Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp setprecision(12)<<fixed
#define ss second
#define fori(v) for(ll i=0; i<v; i++)
#define forj(v) for(ll j=0; j<v; j++)
#define fork(v) for(ll k=0; k<v; k++)
#define forl(v) for(ll l=0; l<v; l++)
#define fort(v) for(ll t=0; t<v; t++)
#define forz(v) for(ll z=0; z<v; z++)
#define forx(v) for(ll x=0; x<v; x++)
#define ll long long
#define double long double
#define MAX (int)(5*pow(10,3) + 10)
#define pb(a) push_back(a)
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll INF = inf;
ll modulo = pow(10,9) + 7;
double eps = 1e-10;
ifstream in;
ofstream out;

void deal(){
	ll n , m;
	cin>>n>>m;
	vector<pair<ll,ll> > all;
	fori(n){
		ll ai, bi;
		cin>>ai>>bi;
		all.pb(mp(bi,ai));
	}
	sort(all.rbegin(), all.rend());
	set<ll> not_taken;
	fori(m+1)
		not_taken.insert(i);
	ll sum = 0;
	fori(n){
		ll reward = all[i].ff;
		ll when   = all[i].ss;
		auto it = not_taken.lower_bound(when);
		if(it!=not_taken.end())
			not_taken.erase(it), sum+=reward;
	}
	cout<<sum;
}
 
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}

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

// template {{{
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); (i) += 1)
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); (i) -= 1)

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// }}}

void solver() {
    int X = input();
    int a = 0;
    range(i, 0, 360) {
        (a += X) %= 360;
        if (a == 0) {
            cout << i + 1 << endl;
            return;
        }
    }
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 3648
X, N = map(int, input().split())
if(N != 0):
    p = set(list(map(int, input().split())))
else:
    print(X)
    exit()

result = []

for i in range(102):
    result.append(i)

ans = set(result)-p
ans1 = 1*10**50


for count, i in enumerate(ans):
    if (ans1 > abs(i-X)):
        ans1 = abs(i-X)
        index = count

print(list(ans)[index])


Measured memory_bytes: 9196
while True:
    n, x = map(int, input().split())
    
    if n == 0 and x == 0:
        break
    
    ans = 0
    
    for i in range(1, n + 1):
        for j in range(1, i):
            for k in range(1, j):
                if i + j + k == x:
                    ans += 1
    print(ans)


Measured memory_bytes: 5592
#include<cstdio>
#include<iostream>
#define ll long long
using namespace std;
int n,num,m;
ll a[101010];
ll f[101010],s[101010];
void sol(ll x,ll doe)
{
	if (x<a[1])
	{
		s[x]+=doe;
		return;
	}
	int l=1,r=n;
	int y;
	while (l<=r)
	{
		int mid=(l+r)/2;
		if (a[mid]<=x)
		{
			y=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	f[y]+=doe*(x/a[y]);
	x=x%a[y];
	if (x) sol(x,doe);
}
int main()
{
//	freopen("E.in","r",stdin);
//	freopen("E.out","w",stdout);
	scanf("%d%d",&n,&m);
	num=1;
	a[1]=n;
	ll x;
	for (int i=1;i<=m;++i)
	{
		scanf("%lld",&x);
		while (x<=a[num] && num)
			--num;
		++num;
		a[num]=x;
	}
	m=n;
	n=num;
	f[n]=1;
	for (int i=n-1;i>=1;--i)
	{
		f[i]+=f[i+1]*(a[i+1]/a[i]);
		sol(a[i+1]%a[i],f[i+1]);
	}
	for (int i=a[1];i>=1;--i)
		s[i]+=s[i+1];
	for (int i=1;i<=a[1];++i)
		s[i]+=f[1];
	for (int i=1;i<=m;++i)
		printf("%lld\n",s[i]);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

const int MAX_N=100010;

int N;
vector<ll> A(MAX_N);
vector<ll> propagate(MAX_N,0);
vector<vector<int>> G(MAX_N);
bool ok=true;

void dfs(int v,int p){
    ll M=0,sum;
    for (auto nv:G[v]){
        if (nv==p) continue;
        dfs(nv,v);
        propagate[v]+=A[nv];
        chmax(M,A[nv]);
    }
    if (M*2<propagate[v]) sum=propagate[v]/2;
    else sum=propagate[v]-M;
    if (p!=-1){
        if (G[v].size()==2&&A[v]!=propagate[v]) ok=false;
        if (G[v].size()>2&&(propagate[v]<A[v]||2*A[v]<propagate[v]||sum<propagate[v]-A[v])) ok=false;
        if (G[v].size()>1) A[v]=2*A[v]-propagate[v];
    }
    else {
        if (G[v].size()==1&&A[v]!=propagate[v]) ok=false;
        if (G[v].size()>1&&2*A[v]!=propagate[v]) ok=false;
    }
}


int main(){
    cin >> N;
    rep(i,N) cin >> A[i];
    rep(i,N-1){
        int a,b;
        cin >> a >> b;
        --a,--b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    dfs(0,-1);
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 13952
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int,int);
void dfs( vector< vector<int> >&, int , vector<int>& );
void bfs( vector< vector<int> >&, int , vector<int>& );

void solve()
{
    int n;
    cin>>n;

    vector< pair<int,int> > p;

    rep(i,0,n)
    {
        int x,y;
        cin>>x>>y;
        p.pb(mp(x,y));
    }
    double sum = 0;
    rep(i,0,p.size())
    {
        rep(j,i+1,p.size())
        {
            sum += sqrt((p[j].ft-p[i].ft)*(p[j].ft-p[i].ft) + (p[j].sd-p[i].sd)*(p[j].sd-p[i].sd));
        }
    }

    sum = 2*sum*(n-1);

    sum = sum/(double)(n*(n-1));

    cout<<setprecision(20)<<sum<<endl;
}

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

void dfs ( vector< vector<int> > &v , int x , vector<int> &vis )
{
    vis[x] = 1;

    rep(i,0,v[x].size())
    {
        if( vis[v[x][i]] == 0 )
        {
            dfs(v,v[x][i],vis);
        }
    }
}

void bfs( vector< vector<int> > &v , int x , vector<int> &vis )
{
    queue<int> q;
    q.push(x);

    while( !q.empty() )
    {
        int p = q.front();
        q.pop();

        rep(i,0,v[p].size())
        {
            if ( vis[v[p][i]] == 0 )
            {
                vis[v[p][i]] = 1;
                q.push(v[p][i]);
            }
        }
    }
}

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

ex_pre = 0
for i in range(k):
    ex_pre += (p[i]+1)/2

ex_max = ex_pre
for i in range(k, n):
    ex = ex_pre + (p[i]+1)/2 - (p[i-k]+1)/2
    ex_max = max(ex, ex_max)
    ex_pre = ex

print(ex_max)


Measured memory_bytes: 24804
#include<bits/stdc++.h>
using namespace std;
const int maxn=610;
struct node{
	int x,y;
};
int n;
vector<node> nex;
vector<node> g1[maxn][maxn],g2[maxn][maxn];
int c1[maxn][maxn],c2[maxn][maxn];
void dfs1(int x,int y){
	for(vector<node>::iterator it=g1[x][y].begin();it!=g1[x][y].end();it++){
		if(c1[(*it).x][(*it).y]) continue;
		c1[(*it).x][(*it).y]=3-c1[x][y];
		dfs1((*it).x,(*it).y);
	}
}
void dfs2(int x,int y){
	for(vector<node>::iterator it=g2[x][y].begin();it!=g2[x][y].end();it++){
		if(c2[(*it).x][(*it).y]) continue;
		c2[(*it).x][(*it).y]=3-c2[x][y];
		dfs2((*it).x,(*it).y);
	}
}
bool out(int x,int y){
	if(x>n*2||x<1) return 1;
	if(y>n*2||y<1) return 1;
	return 0;
}
int main(){
	int D1,D2;
	scanf("%d%d%d",&n,&D1,&D2);
	int x;
	for(int i=0;i*i<=D1;i++){
		x=sqrt(D1-i*i);
		if(x*x+i*i==D1)
			nex.push_back((node){x,i});
	}
	for(int i=1;i<=n*2;i++)
		for(int j=1;j<=n*2;j++)
			for(vector<node>::iterator it=nex.begin();it!=nex.end();it++){
				if(!out(i+(*it).x,j+(*it).y))
					g1[i][j].push_back((node){i+(*it).x,j+(*it).y});
				if(j!=0&&!out(i+(*it).x,j-(*it).y))
					g1[i][j].push_back((node){i+(*it).x,j-(*it).y});
				if(i!=0&&!out(i-(*it).x,j+(*it).y))
					g1[i][j].push_back((node){i-(*it).x,j+(*it).y});
				if(i!=0&&j!=0&&!out(i-(*it).x,j-(*it).y))
					g1[i][j].push_back((node){i-(*it).x,j-(*it).y});
			}
	for(int i=1;i<=n*2;i++){
		for(int j=1;j<=n*2;j++){
			if(c1[i][j]) continue;
			c1[i][j]=1;
			dfs1(i,j);
		}
	}
	nex.clear();
	for(int i=0;i*i<=D2;i++){
		x=sqrt(D2-i*i);
		if(x*x+i*i==D2)
			nex.push_back((node){x,i});
	}
	for(int i=1;i<=n*2;i++)
		for(int j=1;j<=n*2;j++)
			for(vector<node>::iterator it=nex.begin();it!=nex.end();it++){
				if(!out(i+(*it).x,j+(*it).y))
					g2[i][j].push_back((node){i+(*it).x,j+(*it).y});
				if(j!=0&&!out(i+(*it).x,j-(*it).y))
					g2[i][j].push_back((node){i+(*it).x,j-(*it).y});
				if(i!=0&&!out(i-(*it).x,j+(*it).y))
					g2[i][j].push_back((node){i-(*it).x,j+(*it).y});
				if(i!=0&&j!=0&&!out(i-(*it).x,j-(*it).y))
					g2[i][j].push_back((node){i-(*it).x,j-(*it).y});
			}
	for(int i=1;i<=n*2;i++){
		for(int j=1;j<=n*2;j++){
			if(c2[i][j]) continue;
			c2[i][j]=1;
			dfs2(i,j);
		}
	}
	static int cnt[4];
	int zt;
	for(int i=1;i<=n*2;i++)
		for(int j=1;j<=n*2;j++){
			zt=0;
			if(c1[i][j]==1) zt|=1;
			if(c2[i][j]==1) zt|=2;
			cnt[zt]++;
		}
	int zlt;
	for(zlt=0;zlt<=3;zlt++)
		if(cnt[zlt]>=n*n)
			break;
	int lef=n*n;
	for(int i=1;i<=n*2;i++)
		for(int j=1;j<=n*2;j++){
			zt=0;
			if(c1[i][j]==1) zt|=1;
			if(c2[i][j]==1) zt|=2;
			if(zt==zlt){
				printf("%d %d\n",i-1,j-1);
				lef--;
				if(lef==0) return 0;
			}
		}
	return 0;
}


Measured memory_bytes: 179328
N = int(input())
S = [tuple(map(int, input().split())) for i in range(N)]
T = list(map(lambda j:(j[0]-j[1], j[0]+j[1]), S))

T.sort(key=lambda x: x[1])

for i, t in enumerate(T):
  if i>0:
    if end <= t[0]:
      res += 1
      start = t[0]
      end = t[1]
  else:
    start = t[0]
    end = t[1]
    res = 1

print(res)

Measured memory_bytes: 31700
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		String α = in.next();
		if(Character.isUpperCase(α.charAt(0))) {
			System.out.println("A");
		}else {
			System.out.println("a");
		}
	}
}

Measured memory_bytes: 35660
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    List<String> a = new ArrayList<String>();
    while (scanner.hasNext()) {
      a.add(scanner.nextLine());
    }
    Collections.sort(a);
    String preWord = "";
    String page = "";
    for (int ii = 0; ii < a.size(); ii++) {
      String[] works = a.get(ii).split(" ");
      if (ii != 0 && !works[0].equals(preWord)) {
        System.out.println(preWord);
        System.out.println(aaaa(page));
        page = "";
      }
      page += works[1] + " ";
      preWord = works[0];
    }
    if (preWord.length() != 0) {
      System.out.println(preWord);
    }
    if (page.length() != 0) {
      System.out.println(aaaa(page));
    }
  }

  private static String aaaa (String aa) {
    String[] works = aa.trim().split(" ");
    for (int ii = 0; ii < works.length; ii++) {
      works[ii] = "000" + works[ii];
      works[ii] = works[ii].substring(works[ii].length() - 4);
    }
    Arrays.sort(works);
    String out = "";
    for (int ii = 0; ii < works.length; ii++) {
      out += Integer.parseInt(works[ii]) + " ";
    }
    return out.trim();
  }
}

Measured memory_bytes: 17472
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
using namespace std;

signed main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s[0] == 'Y'&&s[1] == 'A'&&s[2] == 'K'&&s[3] == 'I')cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
module Main where

-- import Debug.Trace
-- import Data.Maybe

{-
 - Next lexicographical permutation algorithm
 - by Project Nayuki, 2016. Public domain.
 - https://www.nayuki.io/page/next-lexicographical-permutation-algorithm
 -
 - Computes the next lexicographical permutation of the specified finite list of numbers.
 - Returns Nothing if the argument is already the highest permutation.
 -}
nextPermutation :: Ord a => [a] -> Maybe [a]
nextPermutation xs =
  let
    len = length xs
    revSuffix = findPrefix (reverse xs)  -- Reverse of longest non-increasing suffix
    suffixLen = length revSuffix
    prefixMinusPivot = take (len - suffixLen - 1) xs
    pivot = xs !! (len - suffixLen - 1)
    suffixHead = takeWhile (<= pivot) revSuffix
    newPivot : suffixTail = drop (length suffixHead) revSuffix
    newSuffix = suffixHead ++ (pivot : suffixTail)
  in
    if suffixLen == len then Nothing else Just (prefixMinusPivot ++ (newPivot : newSuffix))
  where
    findPrefix [] = []
    findPrefix (x:xs) = x : (if xs /= [] && x <= (head xs) then (findPrefix xs) else [])

-- debug = flip trace

permutationEqual a b = all (==True) (zipWith (\a b -> a == b) a b)

solve :: (Int, Maybe [Int], Int, Int) -> (Int, [Int], [Int]) -> (Int, Maybe [Int], Int, Int)
solve (idx, Nothing, pi, qi) (size, ps, qs) = (idx, Nothing, pi, qi)
solve (idx, _, pi, qi) _ | pi /= 0 && qi /= 0 = (idx, Nothing, pi, qi)
solve (idx, Just permutation, pi, qi) (size, ps, qs)
  | permutationEqual permutation ps = (idx + 1, npermutation, idx, qi) -- `debug` (mconcat [show permutation, show npermutation])
  | permutationEqual permutation qs = (idx + 1, npermutation, pi, idx) -- `debug` (mconcat [show permutation, show npermutation])
  | otherwise = (idx + 1, npermutation, pi, qi) -- `debug` (mconcat [show permutation, show npermutation])
  where
    npermutation = nextPermutation permutation

main =
  read <$> getLine >>= \size ->
  fmap (map read . words) getLine >>= \ps ->
  fmap (map read . words) getLine >>= \qs ->
  let
    factorial n = product [1..n]
    (_, _, pi, qi) = head $ dropWhile (\(_, _, pix, qix) -> pix == 0 || qix == 0)
                   $ scanl solve (1, Just [1..size], 0, 0) [(size, ps, qs) | d <- [1..factorial size]]
    result = abs (pi - qi)
   in
   if permutationEqual ps qs
      then putStrLn "0"
      else putStrLn $ show result


Measured memory_bytes: 3836
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    
    cout << string(w+2, '#') << endl;
    for(int i=0; i<h; ++i){
        string s;
        cin >> s;
        cout << '#' << s << '#' << endl;
    }
    cout << string(w+2, '#') << endl;

    return 0;
}


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

typedef long long ll;

const int MAXN = 3002;

ll dp[MAXN][MAXN][2];
bool vis[MAXN][MAXN];
int A[MAXN], N;

// ll solve(int i, int j, int p, int diff) {

// 	if (j == i)
// 	{	if (p == 1)
// 			return diff + A[i];
// 		else return diff - A[i];
// 	}
// 	//if (j < i) return diff;
// 	if (dp[i][j][p][diff] != -1)return dp[i][j][p][diff];
// 	int X = 0, Y = 0;
// 	if (p == 1)
// 	{
// 		X = solve(i, j - 1, p ^ 1, diff + A[j]);
// 		Y = solve(i + 1, j, p ^ 1, diff + A[i]);
// 	} else {
// 		X = solve(i, j - 1, p ^ 1, diff - A[j]);
// 		Y = solve(i + 1, j, p ^ 1, diff - A[i]);
// 	}

// 	if (p == 1)
// 		dp[i][j][p][diff] = max(X, Y);
// 	else  dp[i][j][p][diff] = min(X, Y);

// 	if (p == 1)
// 		return max(X, Y);
// 	else return min(X, Y);
// }
ll solve(int i, int j, int p) {

	if (j == i)
	{	if (p == 1)
			return A[i];
		else return  - A[i];
	}
	//if (j < i) return diff;
	if (dp[i][j][p]  != -1)return dp[i][j][p] ;

	if (p == 1)
	{
		dp[i][j][p] = max( A[j] + solve(i, j - 1, p ^ 1), A[i] + solve(i + 1, j, p ^ 1));

	} else {
		dp[i][j][p] = min(-A[j] + solve(i, j - 1, p ^ 1), -A[i] + solve(i + 1, j, p ^ 1));
	}

	// if (p == 1)
	// 	dp[i][j][p][diff] = max(X, Y);
	// else  dp[i][j][p][diff] = min(X, Y);

	// if (p == 1)
	// 	return max(X, Y);
	// else return min(X, Y);
	return dp[i][j][p];
}
int main() {

	memset(dp, -1, sizeof(dp));
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}
	cout << solve(1, N, 1);
	//cout << abs(X - Y) << endl;

	return 0;

}

Measured memory_bytes: 141952
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n; cin >> n;
  lint l; cin >> l;
  V<string> s(n); for (int i = 0; i < n; i++) cin >> s[i];

  struct node { V<node*> chi; node() { chi.resize(2); } };
  node* tree = new node;
  auto add_str = [&](string s) {
    node* p = tree;
    for (char c : s) {
      if (p->chi[c -= '0'] == nullptr) p->chi[c] = new node;
      p = p->chi[c];
    }
  };
  for (int i = 0; i < n; i++) add_str(s[i]);

  lint grundy = 0;
  queue< pair<node*, lint> > q;
  q.emplace(tree, l);
  while (!q.empty()) {
    node* p; lint h; tie(p, h) = q.front(); q.pop();
    if ((p->chi[0] != nullptr) ^ (p->chi[1] != nullptr)) grundy ^= h & -h;
    for (int i = 0; i < 2; i++) if (p->chi[i] != nullptr) q.emplace(p->chi[i], h - 1);
  }
  cout << (grundy ? "Alice" : "Bob") << '\n';
}

Measured memory_bytes: 6736
#include <iostream>
#include <algorithm>
#include <functional>
#include <utility>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
using namespace std;

#define rep(i,end)          rep2((i),0,(end))
#define rep2(i,beg,end)   for (int (i)=(beg);(i)<(end);(i)++)
#define all(cont)           begin(cont), end(cont)
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll, ll> pii;
typedef pair<ll, string> pis;
typedef pair<string, ll> psi;

string gets(bool skipnewline);


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vi v(n+1, 0);
    rep2(x, 2, n+1)
    {
        int t = x;
        rep2(p, 2, x + 1)
        {
            while ((t%p) == 0) {
                v[p]++;
                t /= p;
            }
            if (t == 1) break;
        }
    }
    ull cnt = 1;
    rep(i, v.size())
    {
        if (v[i] == 0) continue;
        cnt = (cnt * (v[i] + 1)) % 1000000007LL;
    }
    cout << cnt << endl;
    return 0;
}

string gets(bool skipToNextline)
{
    if (skipToNextline) gets(false);
    const int LINE_MAX = 1024;
    char buf[LINE_MAX];
    cin.getline(buf, sizeof(buf));
    return buf;
}



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

#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 RREP(i, n) for(int i = (n)-1; i >= 0; i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define loop while(true)

#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()

#define PII pair<int, int>
#define pii pair<int, int>
#define VB vector<bool>
#define VVB vector<vector<bool> >
#define VI vector<int>
#define VVI vector<vector<int> >

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;

signed main()
{
    loop{
        int n;
        cin >> n;
        if(n == 0) break;

        VVB gem(21);
        rep(i, 21){
            gem[i].resize(21);
        }
        
        rep(i, n){
            int x, y;
            cin >> x >> y;
            gem[y][x] = true;
        }

        int pos_x = 10;
        int pos_y = 10;

        int m;
        cin >> m;
        int gem_num = 0;
        rep(i, m){
            char dir;
            int leng;
            cin >> dir >> leng;
            switch(dir){
            case 'N':
                rep(dy, leng){
                    if(gem[++pos_y][pos_x]){
                        gem_num++;
                        gem[pos_y][pos_x] = false;
                    }
                }
                break;
            case 'E':
                rep(dx, leng){
                    if(gem[pos_y][++pos_x]){
                        gem_num++;
                        gem[pos_y][pos_x] = false;
                    }
                }
                break;
            case 'S':
                rep(dy, leng){
                    if(gem[--pos_y][pos_x]){
                        gem_num++;
                        gem[pos_y][pos_x] = false;
                    }
                }
                break;
            case 'W':
                rep(dx, leng){
                    if(gem[pos_y][--pos_x]){
                        gem_num++;
                        gem[pos_y][pos_x] = false;
                    }
                }
                break;
            }

        }

        if(gem_num == n){
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    
    return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;
constexpr int mod = 1e9 + 7;

int main(){ 
  int n;
  cin >> n;
  int res = 1000;
  while (res < n) {
    res += 1000;
  }
  cout << res - n << endl;
  return 0;
} 

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

int main() {
  
  int N,K;
  
  cin >> N >> K ;
  
  if (N%K > 0){
    cout << "1" << endl;
  }if (N%K == 0){
    cout << "0" << endl;
  }
  
 }



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>

using namespace std;
typedef long long int ll;

int main(){

    ll N = 0;
    cin >> N;
    vector<ll > B(N-1);

    for(ll i = 0; i < B.size(); i++){
        cin >> B[i];
        //cout << B[i] << endl;
    }

    //A0格納 
    ll ans = B[0];

    for(ll i = 0; i < B.size() - 1 ; i++){
        //cout << ans << endl;
        if(B[i] <= B[i + 1]){
            ans += B[i];
        }else{
            ans += B[i + 1];
        }
    }
    ans += B[B.size()-1];
    cout << ans << endl;

} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;i++)
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    ll ans=0;
    ll cnt=0;
    int n=s.size();
    for(ll i=n-2;i>=0;){
        if(s.substr(i,2)=="BC"){
            if(i==0) break;
            cnt++;
            if(s[i-1]=='A')i--;
            else{
                if(i-2>=0){
                    if(s.substr(i-2,2)!="BC")cnt=0;
                }else break;
                i-=2;
            }
        }else if(s[i]=='A'){
            ans+=cnt;
            if(i==0)break;
            if(s[i-1]=='A')i--;
            else{
                if(i-2>=0){
                    if(s.substr(i-2,2)!="BC")cnt=0;
                }else break;
                i-=2;
            }
        }else{
            cnt=0;
            i--;
        }
    }
    cout<<ans<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

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

template<typename F> struct FixPoint : F {
    FixPoint(F&& f) : F(forward<F>(f)) { }
    template<typename... Args> decltype(auto) operator()(Args&&... args) const {
        return F::operator()(*this, forward<Args>(args)...);
    }
};
template<typename F> inline decltype(auto) MFP(F&& f) {     // makeFixPoint
    return FixPoint<F>{forward<F>(f)};
}

int main() {
    int n; cin >> n;
    int cnt = 0;
    auto dfs = MFP([&](auto dfs, long long cur, int mask) {
        if (cur > n) return ;
        if (mask == 7) cnt++;
        dfs(cur * 10 + 7, mask | 4);
        dfs(cur * 10 + 5, mask | 2);
        dfs(cur * 10 + 3, mask | 1);
    });
    dfs(0, 0);
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
class Program
{
	static void Main(string[] args)
	{
		var input = Console.ReadLine();
        var array = input.ToCharArray(0, 3);
		var count = 0;
		for (int i = 0; i < array.Length; i++)
		{
			if (array[i] == '1')
			{
				count++;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 11092
a=input()
b=int(a[0]+a[1])
c=int(a[2]+a[3])

if 0<b<13:
    if 0<c<13:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if 0<c<13:
        print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define MOD @
#define ADD(X,Y) ((X) = ((X) + (Y)%MOD) % MOD)
typedef long long i64; typedef vector<int> ivec; typedef vector<string> svec;

int N;
vector<int> S[1000];

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

	int a = -1;
	for (int i = 1; i <= 1000; ++i) {
		if (i * (i - 1) / 2 == N) {
			a = i;
			break;
		}
	}
	if (a == -1) {
		puts("No");
		return 0;
	}
	puts("Yes");
	printf("%d\n", a);

	int idx = 1;
	for (int i = 0; i < a; ++i) {
		for (int j = i + 1; j < a; ++j) {
			S[i].push_back(idx);
			S[j].push_back(idx++);
		}
	}
	for (int i = 0; i < a; ++i) {
		printf("%d", S[i].size());
		for (int j : S[i]) printf(" %d", j);
		puts("");
	}

	return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>

int main(){
  int n,q,s[10001],t,i,j = 0,ans = 0;

  scanf("%d",&n);
  for(i = 0;i < n;i++) scanf("%d",s + i);

  scanf("%d",&q);
  for(i = 0;i < q;i++){
    scanf("%d",&t);
    s[n] = t;
    while(s[j] != t) j++;
    if(j != n) ans += 1;
    j = 0;
  }

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

  return 0;
}



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

#define REP(i, n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()
#define square(x) (x) * (x)
#define cube(x) (x) * (x) * (x)

const int INF = 1e9;

using namespace std;

int main() {
    int n, k;
    int total = 0;
    vector<int> w;
    cin >> n >> k;
    REP(i, n){
        int x;
        cin >> x;
        w.push_back(x);
        total += x;
    }
    int p = total / k;
    while(1){
        int num = 0;
        int track[k];
        REP(i, k){
            track[i] = 0;
            while(num < n && i < k && track[i] + w[num] <= p){
                track[i] += w[num];
                num++;
            }
        }
        if(num == n)
            break;
        p++;
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 2064
#include <stdio.h>
#include <string.h>


void sortToBig(char str[], int left, int right)
{
	char sample = str[left];
	int lptr = left, rptr = right;
	if (lptr < rptr){
		while (lptr != rptr){
			while ((sample < str[rptr]) && (lptr != rptr)) rptr--;
			if (lptr != rptr) str[lptr++] = str[rptr];
			while ((str[lptr] < sample) && (lptr != rptr)) lptr++;
			if (lptr != rptr) str[rptr--] = str[lptr];
		}
		str[lptr] = sample;
		sortToBig(str, left, lptr - 1);
		sortToBig(str, rptr + 1, right);
	}
}

void sortToS(char str[], int left, int right)
{
	char sample = str[left];
	int lptr = left, rptr = right;
	if (lptr < rptr){
		while (lptr != rptr){
			while ((sample > str[rptr]) && (lptr != rptr)) rptr--;
			if (lptr != rptr) str[lptr++] = str[rptr];
			while ((str[lptr] > sample) && (lptr != rptr)) lptr++;
			if (lptr != rptr) str[rptr--] = str[lptr];
		}
		str[lptr] = sample;
		sortToS(str, left, lptr - 1);
		sortToS(str, rptr + 1, right);
	}
}

int main(void)
{
	char s[200], t[200];
	scanf("%s", s);
	scanf("%s", t);

	int N = strlen(s); int M = strlen(t);

	sortToBig(s, 0, N- 1);
	sortToS(t, 0, M- 1);

	int min = (N < M) ? N : M;

	if (strcmp(s,t)<0) printf("Yes\n");
	else printf("No\n");

	return 0;
}

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

using namespace std;

vector<int> a;

int main()
{
    int n;
    scanf("%d", &n);
    long long ans = 0;
    for (int i = 1; i <= n; ++i) {
        int v;
        scanf("%d", &v);
        if (v%2) {
            ans += v/2;
            a.push_back(i);
        }
        else if (v > 0){
            ans += v/2-1;
            a.push_back(i);
            a.push_back(i);
        }
    }
    for (int i = 0; i+1 < a.size(); ++i) {
        if (a[i+1]-a[i] <= 1) {
            ++ans;
            ++i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<cstring>
#include<cmath>

using namespace std;

const int mod = 1e9+7;

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	char s[n][m+1];
	for(int i=0; i<n; i++) {
		scanf("%s", s[i]);
	}
	int dp[n][m];
	memset(dp, 0, sizeof dp);
	dp[0][0] = 1;
	for(int j=1; j<m; j++) {
		if(s[0][j]=='#')
			break;
		dp[0][j] = 1;
	}
	for(int i=1; i<n; i++) {
		if(s[i][0]=='#')
			break;
		dp[i][0] = 1;
	}
	for(int i=1; i<n; i++) {
		for(int j=1; j<m; j++) {
			if(s[i][j]=='#') dp[i][j] = 0;
			else {
				dp[i][j] = dp[i][j-1] + dp[i-1][j];
				if(dp[i][j]>=mod) dp[i][j]-=mod;
			}
		}
	}
	printf("%d\n", dp[n-1][m-1]);
    return 0;
}

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

public class Main {
    static final Scanner sc  = new Scanner(System.in);
    static final int MOD = (int) 1E9 + 7;
    static final int INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) {
        int N = nint();
        long K = nlong();
        int Q = nint();
        int[] A = nints(Q);
        int[] score = new int[N+1];
        
        for (int i = 0; i < Q; i++) {
            score[A[i]]++;
        }
        
        for (int i = 1; i <= N; i++) {
            if (score[i] > Q - K) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        }
    }
    
    
    private static int nint() {
        return sc.nextInt();
    }

    private static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    private static int[] nints(int n, int padL, int padR) {
        int[] a = new int[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nint();
        return a;
    }

    private static long nlong() {
        return sc.nextLong();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0, 0);
    }

    private static long[] nlongs(int n, int padL, int padR) {
        long[] a = new long[padL + n + padR];
        for (int i = 0; i < n; i++)
            a[padL + i] = nlong();
        return a;
    }

    private static double ndouble() {
        return sc.nextDouble();
    }
    
    private static double[] ndoubles(int n) {
        return ndoubles(n, 0, 0);
    }
    
    private static double[] ndoubles(int n, int padL, int padR) {
        double[] d = new double[n + padL + padR];
        for (int i = 0; i < n; i++) {
            d[padL + i] = ndouble();
        }
        return d;
    }

    private static String nstr() {
        return sc.next();
    }

    private static char[] nchars() {
        return sc.next().toCharArray();
    }

    private static char[] nchars(int padL, int padR) {
        char[] temp = sc.next().toCharArray();
        char[] ret = new char[temp.length + padL + padR];
        System.arraycopy(temp, 0, ret, padL, temp.length);
        return ret;
    }
    
    private static char[][] nchars2(int h, int w) {
        return nchars2(h, w, 0, 0);
    }

    private static char[][] nchars2(int h, int w, int padLU, int padRD) {
        char[][] a2 = new char[h + padLU + padRD][w + padLU + padRD];
        for (int i = 0; i < h; i++)
            System.arraycopy(nchars(), 0, a2[padLU + i], padLU, w);
        return a2;
    }
    
    private static long min(long... ls) {
        return Arrays.stream(ls).min().getAsLong();
    }
    
    private static long max(long... ls) {
        return Arrays.stream(ls).max().getAsLong();
    }
    
    private static long abs(long a, long b) {
        return Math.abs(a - b);
    }
}


Measured memory_bytes: 56560
/*
    Author : zzugzx
    Lang : C++
    Blog : blog.csdn.net/qq_43756519
*/
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define SZ(x) (int)x.size()
#define mem(a, b) memset(a, b, sizeof(a))

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

const int mod = 1e9 + 7;
//const int mod = 998244353;
const double eps = 1e-6;
const double pi = acos(-1.0);
const int maxn = 2e6 + 10;
const int N = 2e4 + 5;
const ll inf = 0x3f3f3f3f;
const int dir[][2]={{0, 1}, {1, 0}, {0, -1}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
    int n, ans = 0;
    double d;
    cin >> n >> d;
    for (int i = 1; i <= n; i++) {
        double x, y;
        cin >> x >> y;
        double dis = sqrt(x * x + y * y);
        if (fabs(dis - d) <= eps || dis < d) ans++;
    }
    cout << ans;
}


Measured memory_bytes: 3856
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MX=100005;
int c[MX];

int main()
{
    ll s=0;
    int n,q,x,y;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&x);
        s+=(ll)x,c[x]++;
    }
    scanf("%d",&q);
    while(q--){
        scanf("%d %d",&x,&y);
        s-=(ll)x*(ll)c[x];
        s+=(ll)y*(ll)c[x];
        c[y]+=c[x];
        c[x]=0;
        printf("%lld\n",s);
    }
    return 0;
}

Measured memory_bytes: 4012
#include <bits/stdc++.h>
#define prob(a,b) cout<<contador<<" "<<target<<endl;
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long int n, target, contador=0, res=0;
	cin>>n>>target;
	
	vector<int> reb(n);
	
	for (int i=0; i<n; i++)
	{
			cin>>reb[i];
	}
	
	for (int i=0; i<=n; i++)
	{
		if (contador<=target)
		{
			res++;
		}
			contador+=reb[i];
		
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	int c[a];
	for (int i = 0 ; i < a ; i++) cin >> c[i];
	sort(c,c + a);
	int x = 0;
	for (int i = a - 1 ; i > a - 1 - b ; i--) {
		x += c[i];
	}
	cout << x;
}

Measured memory_bytes: 256