akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Arrays;

public class Main {
    public static class UnionFind {
        int[] parent;
        public UnionFind(int n) {
            this.parent = new int[n];
            Arrays.fill(parent, -1);
        }
 
        public boolean union(int a, int b) {
            if(isSame(a, b)) return false;
            parent[find(a)] = find(b);
            return true;
        }
 
        public int find(int a) {
            if(parent[a] < 0) return a;
            else {
                parent[a] = find(parent[a]);
                return parent[a];
            }
        }
 
        public boolean isSame(int a, int b) {
            return find(a) == find(b);
        }
    }

	public static void main(String[] args) {
		FS r = new FS();
		int n = r.nextInt();
		int q = r.nextInt();
		UnionFind uf = new UnionFind(n);
		for(int i=0; i<q; i++) {
			int c = r.nextInt();
			int x = r.nextInt();
			int y = r.nextInt();
			if(c == 0) {
				uf.union(x, y);
			} else {
				if(uf.isSame(x, y)) System.out.println(1);
				else System.out.println(0);
			}
		}
	}
	
	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}
	
		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	
		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N;
    ll cost = 0;
    ll mini;
    string S;
    cin >> N >> S;
    for(ll i = 1;i < N;i++) if(S[i] == 'E') cost++;
    mini = cost;
    for(ll i = 1;i < N;i++) {
        if(S[i] == 'E') cost--;
        if(S[i - 1] == 'W') cost++;
        mini = min(mini, cost);
    }
    cout << mini << endl;
    return 0;
}


Measured memory_bytes: 900
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            String line = sc.nextLine();
            String answer = "";
            int length = line.length();
            for (int i = 0; i < length; i++) {
            char ch = line.charAt(i); // 文字列(line)からi番目の文字を取り出す
            // Character.isLowerCase で小文字かどうか判断可能
            // Character.toUpperCase, Character.toLowerCase で変換
            // 記号は上記メソッドで変換にかけても変化しない
            if(Character.isLowerCase(ch)){
                ch = Character.toUpperCase(ch);
            }else{
                ch = Character.toLowerCase(ch);
            }

            answer = answer + ch; 
            }
            System.out.println(answer);
            }
    }
}


Measured memory_bytes: 31520
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#define F first
#define S second
#define pb push_back
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vLL vector<LL>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned long long LU;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, m, ans = 0;
    cin >> n >> m;
    if (n >= 2)
    {
        ans += (n * (n - 1)) / 2;
    }
    if (m >= 2)
    {
        ans += (m * (m - 1)) / 2;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+10;
struct xxx{
	int y,nxt;
}a[N*2];
int h[N];
struct Data{
	int id;
	ll val;
	Data(){}
	Data(int id1,ll val1){id=id1; val=val1;}
	friend bool operator < (Data x,Data y){return x.val<y.val;}
}d[N];
ll sz[N],Dis[N];
ll fa[N];
int n,m,tot;
void add(int x,int y){a[++tot].y=y; a[tot].nxt=h[x]; h[x]=tot;}
bool solve(){
	int pre;
	sort(d+1,d+1+n);
	for (int i=1;i<=n;++i) sz[i]=1;
	for (int i=n;i>=2;--i){
		pre=lower_bound(d+1,d+1+n,Data(0,d[i].val-n+2*sz[i]))-d;
		if (pre==-1||d[pre].val!=d[i].val-n+2*sz[i]||pre==i) return false;
		fa[i]=pre; 
		sz[fa[i]]+=sz[i];
	}
	return true;
}
void dfs1(int x,int d){
	int u;
	Dis[1]+=d;
	for (int i=h[x];i!=-1;i=a[i].nxt){
		u=a[i].y;
		dfs1(u,d+1);
	}
}
void dfs2(int x){
	int u;
	for (int i=h[x];i!=-1;i=a[i].nxt){
		u=a[i].y;
		Dis[u]=Dis[x]+n-2*sz[u];
		dfs2(u);
	}
}
bool doublecheck(){
	memset(h,-1,sizeof(h));
	for (int i=1;i<=n;++i)
		add(fa[i],i);
	dfs1(1,0);
	dfs2(1);
	sort(Dis+1,Dis+1+n);
	for (int i=1;i<=n;++i) 
		if (Dis[i]!=d[i].val) return false;
	return true;
}

int main(){
#ifndef ONLINE_JUDGE
	//freopen("a.in","r",stdin);
#endif
	scanf("%d",&n);
	for (int i=1;i<=n;++i) scanf("%lld",&d[i].val),d[i].id=i;
	if (solve()){
		if (doublecheck())
			for (int i=2;i<=n;++i) cout<<d[fa[i]].id<<" "<<d[i].id<<endl;
		else printf("-1\n");
	}
	else
		printf("-1\n");
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll fact[50];
#define eps 1e-9
ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=ans*a%c;
    }
    a=a*a%c;
    b=b/2;
  }
  return ans;
}
ll ncr(ll n,ll r){
    if(r>n)return 0;
    if(r==n)return 1;
    ll z=fact[n];
    z=z*power(fact[r],mod-2,mod)%mod;
    z=z*power(fact[n-r],mod-2,mod)%mod;
    return z;
}
ll min(ll a,ll b){return a<b?a:b;}
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        vector<ll> num[13][10];
        set<ll> s;
        for(int i=0;i<=9;++i){
            num[0][i].push_back(i);
        }
        for(int i=1;i<=9;++i)s.insert(i);
        for(ll i=1;i<=12;++i){
            for(ll j=0;j<=9;j++){
                ll x=j+1;
                ll pp=(ll)pow(10,i);
                if(x<10){
                    for(int k=0;k<num[i-1][x].size();k++){
                        num[i][j].push_back(j*pp+num[i-1][x][k]);
                        s.insert(j*pp+num[i-1][x][k]);
                    }
                }
                x=j-1;
                if(x>=0){
                    for(int k=0;k<num[i-1][x].size();++k){
                        num[i][j].push_back(j*pp+num[i-1][x][k]);
                        s.insert(j*pp+num[i-1][x][k]);
                    }
                }
                x=j;
                for(int k=0;k<num[i-1][x].size();++k){
                        num[i][j].push_back(j*pp+num[i-1][x][k]);
                        s.insert(j*pp+num[i-1][x][k]);
                }
                if(s.size()>=100000)break;
            }
            if(s.size()>=100000)break;
        }
        vector<ll> re;
        for(auto x: s){re.push_back(x);  }
        int rank; cin>>rank; cout<<re[rank];
        return 0;
}


Measured memory_bytes: 7800
n = int(input())
a = [0] + list(map(int, input().split())) + [0]
s = sum(abs(a[i + 1] - a[i]) for i in range(n + 1))

for i in range(1, n + 1):
    ans = s
    ans -= abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1])
    ans += abs(a[i + 1] - a[i - 1])
    print(ans)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
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 gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




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

  ll ans=0;
  for(ll i=1;i*i<n;i++){
    if(n%i==0 && i+1!=n/i) {
      ans+=n/i-1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
def s():return int(input())
def mp():return map(int,input().split())
a = s()
b = list(mp())
ans=0
t = sum(b)%(10**9+7)
for i in range(a):
	t-=b[i]
	ans+=b[i]*t
	ans%=(10**9+7)
print(ans)

Measured memory_bytes: 105288
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
signed main() {
    INCANT;
    int n, k, h, res = 0;
    cin>>n>>k;
    priority_queue<int> q;
    rep(i, n) {
        cin>>h;
        q.push(h);
    }
    while(k-- && !q.empty()) {
        q.pop();
    }
    while(!q.empty()) {
        res += q.top();
        q.pop();
    }
    cout<<res<<endl;
}


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

int f(int);

int main()
{
  int s;
  cin >> s;
  set<int> a_s;
  
  a_s.insert(s);
  int prev_size = a_s.size();
  int curr_size;
  int a = s;
  int count = 1;
  while(1)
  {
    a = f(a);
    a_s.insert(a);
    count ++;
    curr_size = a_s.size();
    if (prev_size == curr_size) break;
    prev_size = curr_size;
  }
  
  cout << count << endl;
  
  return 0;
}

int f(int n)
{
  if (n % 2 == 0) return n / 2;
  else return 3 * n + 1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
struct beet{
  string s;
  int b,i;
  beet(){}
  beet(string s,int b,int i):s(s),b(b),i(i){}
  bool operator<(const beet&a)const{
    if(b!=a.b) return b<a.b;
    return i<a.i;
  }
};
signed main(){
  int n;
  cin>>n;
  map<string,int> ms;
  set<beet> w,x;// w:working / x:not
  vector<beet> vb(n);
  for(int i=0;i<n;i++){
    string s;
    int b;
    cin>>s>>b;
    vb[i]=beet(s,b,i);
    x.insert(vb[i]);
    ms[s]=i;
  }
  auto work=[&](bool f=0){
    while(w.size()<(w.size()+x.size())/5){
      beet b=*--x.end();
      x.erase(b);
      w.insert(b);
      if(f) cout<<b.s<<" is working hard now."<<endl;
    }
  };
  auto rest=[&](bool f=0){
    while(w.size()>(w.size()+x.size())/5){
      beet b=*w.begin();
      w.erase(b);
      x.insert(b);
      if(f) cout<<b.s<<" is not working now."<<endl;
    }
  };
  auto join=[&](int i){
    beet b=vb[i];
    if((w.size()+x.size()+1)%5==0){
      if(*--x.end()<b){
	w.insert(b);
	cout<<b.s<<" is working hard now."<<endl;
      }else{
	x.insert(b);
	cout<<b.s<<" is not working now."<<endl;
      }
      
    }else{
      if(!w.empty()&&*w.begin()<b){
	w.insert(b);
	cout<<b.s<<" is working hard now."<<endl;
      }else{
	x.insert(b);
	cout<<b.s<<" is not working now."<<endl;
      }
    }
  };
  auto remo=[&](int i){
    beet b=vb[i];
    if(w.count(b)){
      w.erase(b);
      //cout<<b.s<<" is not working now."<<endl;
    }
    if(x.count(b)) x.erase(b);
  };
  work();
  //exit(0);
  
  int m;
  cin>>m;
  vb.resize(n+m);
  for(int i=n;i<n+m;i++){
    char c;
    string s;
    cin>>c>>s;
    if(c=='+'){
      int b;
      cin>>b;
      vb[i]=beet(s,b,i);
      ms[s]=i;
      join(i);
    }else{
      remo(ms[s]);
    }
    work(1);
    rest(1);
  }
  return 0;
}

Measured memory_bytes: 13544
D, N = list(map(int,input().split()))

n = []
for i in range(1,1001):
    if i % 100 !=0:
        if D == 0:
            n.append(i)
        elif  D == 1:
            n.append(100*i)
        elif D == 2:
            n.append(10000*i)
print(n[N-1])

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) {
        cin >> c[i];
    }
    int ans = 0;
    for (int bith = 0; bith < (1 << h); bith++) {
        for (int bitw = 0; bitw < (1 << w); bitw++) {
            int black = 0;
            for (int i = 0; i < h; i++) {
                if (bith & (1 << i)) {
                    for (int j = 0; j < w; j++) {
                        if (bitw & (1 << j)) {
                            if (c[i][j] == '#')
                                black++;
                        }
                    }
                }
            }
            if (black == k)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b;
	c=a-b;
	if(c<0){
		c=0;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a<=c){
    if(c<b){
      if(b<d) cout << b-c << "\n";
      else cout << d-c << "\n";
    }
    else cout << 0 << "\n";
  }
  else {
    if(a<d){
      if(d<b) cout << d-a << "\n";
      else cout << b-a << "\n";
    }
    else cout << 0 << "\n";
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
int main() {
	int maisuu = 0, kingaku = 0;
	std::cin >> maisuu >> kingaku;

	for (int x = 0; x <= maisuu; x++) {
		for (int y = 0; y <= maisuu; y++) {
				if (kingaku == 10000 * x + 5000 * y + 1000 * (maisuu-x-y)&&maisuu>=x+y) {
					std::cout << x << " " << y << " " << maisuu-x-y << std::endl;
					return 0;
				}
		}
	}
	std::cout << "-1 -1 -1" << std::endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		while(true){
			int rem = 0;
			if (x > y) {
				rem = x % y;
				x = rem;
				if (rem == 0) {
					System.out.println(y);
					return;
				}
			} else {
				rem = y % x;
				y = rem;
				if (rem == 0) {
					System.out.println(x);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

vector<int> G[10000];
int c[10000],num[10000],cnt;

void dfs(int v){
    num[v]=c[cnt++];
    for(int u:G[v]){
        if(num[u]==0){
            dfs(u);
        }
    }
}

int main(){
    int n;
    cin>>n;
    pair<int,int> p[n];
    for(int i=0;i<n-1;i++){
        int a,b;
        cin>>a>>b;
        --a;--b;
        G[a].push_back(b);
        G[b].push_back(a);
        p[i]={a,b};
    }
    for(int i=0;i<n;i++){
        cin>>c[i];
    }
    sort(c,c+n,greater<int>());
    dfs(0);
    int ans=0;
    for(int i=0;i<n-1;i++){
        auto tmp=p[i];
        ans+=min(num[p[i].first],num[p[i].second]);
    }
    cout<<ans<<endl;
    for(int i=0;i<n;i++){
        if(i)cout<<" ";
        cout<<num[i];
    }
    cout<<endl;
}


Measured memory_bytes: 1280
# ABC 92, B - chocolate
import itertools

n = int(input())
d, x = map(int, input().split(' '))
A = [int(input()) for i in range(n)]
S = 0

for i in range(n):
    for j in itertools.count(0):
        if j*A[i] + 1 <= d:
            S += 1
        else:
            break

print(x + S)


Measured memory_bytes: 3064
from collections import Counter

n = int(input())
s = []
for i in range(n):
    s.append(input().rstrip())

c = Counter(s)
m = c.most_common()

top_count = m[0][1]
ans = [m[0][0]]
for word, count in m[1:]:
    if count == top_count:
        ans.append(word)
    else:
        break

print('\n'.join(sorted(ans)))


Measured memory_bytes: 51824
N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for _ in range(M)]

UF = list(range(N + 1))
SIZE = [1] * (N + 1)


def find(x):
    if UF[x] != x:
        UF[x] = find(UF[x])
    return UF[x]


def unite(x, y):
    m = min(find(x), find(y))
    SIZE[m] = SIZE[find(x)] + SIZE[find(y)]
    UF[find(x)] = m
    UF[find(y)] = m


def is_same(x, y):
    return find(x) == find(y)


ans = [N * (N - 1) // 2]
for a, b in AB[::-1]:
    if not is_same(a, b):
        ans += [ans[-1] - SIZE[find(a)] * SIZE[find(b)]]
        unite(a, b)
    else:
        ans += [ans[-1]]
print(*ans[M - 1::-1], sep='\n')


Measured memory_bytes: 31124
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>
#include <stdlib.h>

#define PI 3.1415926
void swap(int* x, int* y) {
	int a = *x;
	int b = *y;
	*x = b;
	*y = a;
}
void dainyu(int X[], int Y[ ],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[i];
	}
}
void Dscanf(int X[], int n, int m) {
	for (int i = n; i <= m;i++) {
		scanf("%d", &X[i]);
	}
}
void Dprintf(int X[], int n, int m) {
	for (int i = n; i <= m; i++) {
		printf("%d\n", X[i]);
	}
}
void reverse(int X[], int Y[],int n,int m) {
	for (int i = n; i <= m; i++) {
		Y[i] = X[n + m - i];
	}
}

int factorial(int n);
int sum(int n, int*);
int ave(int n, int*);
int min(int n, int*), min(int n, int m);
int max(int n, int*), max(int n, int m);

int main() {
	int A, B, C, D, E;
	scanf("%d %d %d %d %d", &A, &B, &C, &D, &E);
	int t = 0;
	if (A < 0) {
		t = -A *C+D+B*E;
	}
	else {
		t = (B - A)*E;
	}
	printf("%d\n", t);
	return 0;
}

int factorial(int n) {
	if (n > 0) {
		return n * factorial(n - 1);
	}
	else {
		return 1;
	}
}
int sum(int n, int *all) {
	int total = 0;
	for (int i = 0; i < n; ++i) {
		total += all[i];
	}
	return total;
}
int ave(int n, int *all) {
	int total = 0;
	for (int i = 0; i<n; ++i) {
		total += all[i];
	}
	return total / n;
}
int min(int n, int *all) {

	int min = all[0];
	for (int i = 1; i < n; ++i) {
		if (all[0] > all[i]) {
			min = all[i];
		}
	}
	return min;
}
int max(int n, int *all) {
	int max = all[0];
	for (int i = 1; i<n; ++i) {
		if (all[0]<all[i]) {
			max = all[i];
		}
	}
	return max;
}
int max(int n, int m) {
	if (n >= m) {
		return n;
	}
	else {
		return m;
	}
}
int min(int n, int m) {
	if (n >= m) {
		return m;
	}
	else {
		return n;
	}
}

Measured memory_bytes: 2680
// ABC160 D

#include <iostream>
#include <vector>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>


using namespace std;

int main(){
    int n, x, y, buf;
    cin >> n >> x >> y;
    vector<long int> anw(n-1, 0); 
    for(int i = 1; i < n+1; i++){
        for(int j = i+1; j < n+1; j++){
            buf = min({j-i, abs(x-i)+1+abs(y-j), abs(y-i)+1+abs(x-j)});
            // cout << i << "<-i  j->" << j << "  dis:" << buf << endl;
            anw[buf-1]++;
        }
    }
    vector<long int>::iterator itr;
    for(itr = anw.begin(); itr != anw.end(); itr++){
        cout << *itr << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <sstream>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;

int main(void)
{
    long a;
    cin >> a;
    cout << a + a * a + a * a * a << endl;
    return 0;
}

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

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
    //int t=1 ; cin>>t ; while(t--)
    {
		string s, t;
      cin >> s >> t;
      cout << t << s;
    }
    
    cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
    return 0;
}



Measured memory_bytes: 256
import sys
from collections import Counter

n, *v = map(int, sys.stdin.read().split())

def main():
    c1 = sorted(Counter(v[::2]).items(), key=lambda x: -x[1])
    c2 = sorted(Counter(v[1::2]).items(), key=lambda x: -x[1])
    if c1[0][0] != c2[0][0]: res = n - c1[0][1] - c2[0][1]
    else:
        if len(c1) > len(c2): c1, c2 = c2, c1
        if len(c2) == 1: res = n // 2
        else:
            if len(c1) == 1: res = n - c1[0][1] - c2[1][1]
            else:
                res = n - max(c1[0][1] + c2[1][1], c1[1][1] + c2[0][1])
    print(res)

if __name__ ==  '__main__':
    main()

Measured memory_bytes: 20564
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/priority_queue.hpp>
#define MAXN 405
#define MAXM 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> P;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef __gnu_pbds::priority_queue<int,greater<int>,pairing_heap_tag> pq;
int n,m;
int x[MAXM],y[MAXM];
bitset<400> bs[MAXN];
bool valid[MAXN];
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=0;i<m;i++) {scanf("%d%d",&x[i],&y[i]); x[i]--;y[i]--;}
    memset(valid,true,sizeof(valid));
    for(int i=0;i<n;i++)
    {
        bs[i].set(i);
        for(int j=m-1;j>=0;j--)
        {
            if(bs[i][x[j]]&&bs[i][y[j]])
            {
                valid[i]=false;
                break;
            }
            else if(bs[i][x[j]]) bs[i][y[j]]=true;
            else if(bs[i][y[j]]) bs[i][x[j]]=true;
        }
    }
    int ans=0;
    for(int i=0;i<n;i++)
        for(int j=i+1;j<n;j++)
            if(valid[i]&&valid[j]&&!((bs[i]&bs[j]).count())) ans++;
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
#include <math.h>
#define min(a,b) (a)>(b)?(b):(a)
#define max(a,b) (a)<(b)?(b):(a)
#define ll long long
int main (void)  
{  
	int a,b,c,sum;
	int x,y,z;
	scanf("%d%d%d",&x,&y,&z);
	a=min(x,min(y,z));
	c=max(x,max(y,z));
	b=x+y+z-a-c;
	c-=a;b-=a;a=0;
	sum+=b/2;
	b%=2;
	c=c-sum*2;
	if(b)
	  sum++;
	printf("%d\n",sum+c);
    return 0;  
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(50000)


n, x = map(int, input().split())

sum_berger = {0: 1}


# 考え方 xがレベルいくつのバーガーのどの位置かを考える
# レベルnのバーガー = "B" + レベルn-1のバーガー + "P" + レベルn-1のバーガー + "B"
# という式から再帰的にどのバーガーにいるかを考える。
def recursive(n):
    if n in sum_berger.keys():
        return sum_berger[n]
    else:
        sum_berger[n] = 1 + recursive(n - 1) + 1 + recursive(n - 1) + 1
        return sum_berger[n]


patties = {0: 1}


def patti(n):
    if n in patties.keys():
        return patties[n]
    else:
        patties[n] = patti(n - 1) * 2 + 1
        return patties[n]


def answer(n, x):
    if x == 1:
        if n == 0:
            return 1
        else:
            return 0
    elif x == sum_berger[n]:
        return patties[n]
    elif x < sum_berger[n] // 2+1:
        return answer(n-1, x-1)
    elif x == sum_berger[n] // 2 + 1:
        return patties[n] // 2 + 1
    elif x > sum_berger[n] // 2 + 1:
        return answer(n-1, x-(sum_berger[n] // 2 + 1)) + patties[n] // 2 + 1


patti(50)
recursive(50)

print(answer(n, x))
# BBBBPPPBPBPPPBBPBBPPPBPBPPPBBBPBBBPPPBPBPPPBBPBBPPPBPBPPPBBBB
# BBBPPPBPBPPPBBPBBPPPBPBPPPBBB
# BBPPPBPBPPPBB
# BPPPB
# P

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a = b; a<c; a++)
using namespace std;
vector<string> str;
int nato[2][7]={{1,3,5,7,8,10,12},{4,6,9,11}};
int main(){
    int n,m;
    bool a=false,b=false;
    cin >> n >> m;
    if(n==m&&n==2){
        cout << "Yes" << endl;
    }else{
        rep(i,0,7){
            if(nato[0][i]==n)a=true;
            if(nato[0][i]==m)b=true;
        }
        if(a&&b)cout << "Yes" << endl;
        else{
            a=false;b=false;
            rep(j,0,4){
                if(nato[1][j]==n)a=true;
                if(nato[1][j]==m)b=true;
            }
            if(a&&b)cout << "Yes" << endl;
            else cout << "No" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import math

n,m=map(int,input().split())
mod=10**9+7
ans=0

if abs(n-m)>=2:
    print("0")
elif abs(n-m)==1:
    print(math.factorial(n)*math.factorial(m)%mod)
else:
    print((math.factorial(n)*math.factorial(m)*2)%mod)



Measured memory_bytes: 5180
from collections import defaultdict

class Edge:
    def __init__(self, inputs):
        start, end, self.dist = [ int(i) for i in inputs ]
        self.nodes = [start, end]

    def isConnect(self, node):
        return node in self.nodes

    def other_side(self, node):
        if self.nodes[0] == node:
            return self.nodes[1]
        else:
            return self.nodes[0]

    def __str__(self):
        return "%d - %d (%d)" % (self.nodes[0], self.nodes[1], self.dist)

def calc_cost(list, tickets):
    s_list = sorted( list, reverse=True )
    return sum( c / t for c, t in zip(s_list, tickets) )

while True:
    n, m, p, a, b = [ int(i) for i in input().split() ]

    # print("ticktes: %d, m: %d, edge_num: %d, %d -> %d)" % (n, m, p, a, b))

    if n == m == p == a == b == 0:
        quit()

    tickets = sorted( [int(i) for i in input().split()] , reverse=True)

    e = defaultdict(list)

    for i in range(p):
        start, end, cost = [ int(i) for i in input().split() ]
        e[start].append((end, cost))
        e[end].append((start, cost))

    m_cost = defaultdict(lambda: float('inf'))

    # edges = [ Edge(input().split()) for i in range(p) ]

    # print(tickets)

    result = (a, [a], [], float('inf'))

    if p == 0:
        print("Impossible")
        continue

    q = [ (e[0], [a, e[0]], [e[1]], calc_cost([e[1]], tickets)) for e in e[a] ]

    while len(q) != 0:
        now = q.pop()

        # print("now: ", now)

        # ?????±????????°????¶?????????´???
        if len(now[1]) - 1 > n:
            continue

        if m_cost[now[0]] < now[3]:
            continue
        else:
            m_cost[now[0]] = now[3]


        # ??????????????????????????£?????´???
        if now[0] == b and now[3] < result[3]:
            result = now

        q.extend([ (e[0], now[1] + [e[0]], now[2] + [e[1]],  calc_cost(now[2] + [e[1]], tickets))
            for e in e[now[0]] if e[0] not in now[1] ])

    if result[0] == b:
        print(result[3])
    else:
        print("Impossible")

Measured memory_bytes: 8124
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n; n = in.nextInt();
		int a = (n + 999) / 1000;
		n = 1000 * a - n;
		System.out.println(n);
	}
}


Measured memory_bytes: 35456
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    seika s;
    cin >> s;
    if (s[1] == 'B')
    {
        s[1] = 'R';
    }
    else
    {
        s[1] = 'B';
    }
    cout << s << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	for (int i; cin >> i&&i;) {
		int o = 32;
		vector<int> a(i);
		rep(j, 0, i)cin >> a[j];
		for (int j = 0; ; (++j) %= i) {
			o -= (o - 1) % 5;
			cout << o << endl;
			o -= a[j];
			if (o <= 0) {
				cout << 0 << endl;
				break;
			}
			cout << o << endl;
		}
	}

	return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0;i < (n);++i)

int main() {
  int N, R;
  std::cin >> N >> R;
  if (N < 10) std::cout << R+(100*(10-N)) << '\n';
  else std::cout << R << '\n';
}


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

using namespace std;

const int INF = 1 << 30;


int main()
{
  int N, E, T, W[300];
  vector< vector< int > > g[300];

  cin >> N >> E >> T;
  --T;
  for(int i = 0; i < N; i++) {
    cin >> W[i];
  }
  for(int i = 0; i < E; i++) {
    int G, C;
    cin >> G >> C;
    --G;
    vector< int > vv;
    for(int j = 0; j < C; j++) {
      int S;
      cin >> S;
      --S;
      vv.push_back(S);
    }
    g[G].push_back(vv);
  }

  int dp[300];
  fill_n(dp, 300, INF);
  for(int k = 0; k < N; k++) if(W[k] == 1) dp[k] = 0;

  for(int i = 0; i < N; i++) {
    for(int j = 0; j < N; j++) {
      for(auto &k : g[j]) {
        int all = 0;
        bool beet = true;
        for(auto &l : k) {
          if(dp[l] == INF) beet = false;
        }
        if(!beet) continue;
        vector< int > vs;
        for(auto &l : k) {
          vs.push_back(dp[l]);
        }
        sort(vs.rbegin(), vs.rend());
        for(int l = 0; l < vs.size(); l++) {
          all = max(all, vs[l] + l);
        }
        dp[j] = min(dp[j], all);
      }
    }
  }

  if(dp[T] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[T] + 1 << endl;
  }
}

Measured memory_bytes: 3216
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  vector <int> P(N), Q(N);

  for (int i = 0; i < N; i++) cin >> P[i];
  for (int i = 0; i < N; i++) cin >> Q[i];

  vector <int> order(N);
  for (int i = 0; i < N; i++) order[i] = i + 1;

  int p, q, cnt = 0;
  do{
    if (P == order) p = cnt;
    if (Q == order) q = cnt;
    cnt++;
  } while (next_permutation(order.begin(), order.end()));
  
  cout << abs(p - q) << endl;
  
  return 0;
}

Measured memory_bytes: 256
url = "https://atcoder.jp/contests/abc090/tasks/abc090_b"

def main():
    f = list(map(int, input().split(' ')))
    count = 0
    for i in range(f[0], f[1] + 1):
        n_str = list(str(i))
        n_str_r = list(reversed(n_str))
        flg = True
        for n in n_str:
            if n_str != n_str_r:
                flg = False
        if flg:
            count += 1
    print(count)


if __name__ == '__main__':
    main()




Measured memory_bytes: 3060
#include <string>
#include <iostream>
using namespace std;
int main() {
	string s;
	cin >> s;
	string T = "AKIHABARA";
	bool ok = false;
	for (int i = 0; i < 1 << 9; ++i) {
		bool valid = true;
		string tar;
		for (int j = 0; j < 9; ++j) {
			if ((i >> j) & 1) {
				tar += T[j];
			}
			else if (T[j] != 'A') {
				valid = false;
			}
		}
		if (valid && tar == s) {
			ok = true;
		}
	}
	cout << (ok ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	char c[21];
	char a;
	int i=0;

	while(1){
		a=getchar();
		if(a == EOF){
			break;
		}else{
			c[i]=a;
			i++;
		}
	}
	i--;
	i--;
	while(i>=0){
		printf("%c",c[i]);
		i--;
	}
	puts("");
	return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define INF 2000000
#define MAX 20000
int m[MAX][MAX],color[MAX],d[MAX],num;
int spaning(){
	for(int i=0;i<num;i++){
		color[i]=0;d[i]=INF;
	}
	d[0]=0;
	int sum=0;
	int min_now=INF;
	while(1){
		int v=-1;
	for(int i=0;i<num;i++){
		if(!color[i]&&(v==-1||d[v]>d[i])){
			v=i;
		}}
		if(v==-1) break;
		sum+=d[v];
		color[v]=1;
	for(int i=0;i<num;i++){
		if(!color[i]){
			d[i]=min(d[i],m[v][i]);
		}
	
	}
	}
	return sum;
}
int main(){
	int a;
	cin>>num;
	for(int i=0;i<num;i++){
		for(int j=0;j<num;j++){
			cin>>a;
			if(a==-1) m[i][j]=INF;
			else m[i][j]=a;
		}
	}
	int s=spaning(); 
	cout<<s<<endl;
}


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

int main () {
    int n,Q;
    cin >> n >> Q;
    dsu d(n);
    while(Q--) {
        int type,u,v;
        cin >> type >> u >> v;
        if(type == 0) d.merge(u,v);
        if(type == 1) cout << d.same(u,v) << endl;
    }
    return 0;
}


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

const long long mod = 1000000007;

signed main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n, cnt[3] = {}, k, l, r;
	cin >> n >> k;
	vector<long long> a(n), p, m;
	long long ans = 1LL;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		if (a[i] == 0) {
			++cnt[1];
			p.push_back(a[i]);
		} 
		else if (a[i] < 0) {
			m.push_back(a[i]);
			++cnt[0];
		} 
		else {
			++cnt[2];
			p.push_back(a[i]);
		}
	}
	sort(a.begin(), a.end());
	sort(p.begin(), p.end());
	sort(m.begin(), m.end());
	if (k > cnt[0] + cnt[2]) {
		cout << 0 << '\n';
		return 0;
	}
	if (n == k) {
		for (int i = 0; i < n; i++) {
			if (a[i] < 0) 
				ans *= (a[i] + mod);
			else 
				ans *= a[i];
			ans %= mod;
		}
		if (ans < 0) {
			ans += 10000LL * mod;
			ans %= mod;
		}
		cout << ans << '\n';
		return 0;
	}
	if (k % 2 == 1 && cnt[0] == n) {
		for (int i = 0; i < k; i++) {
			ans *= (a[n - 1 - i] + mod);
			ans %= mod;
		}
		if (ans < 0) {
			ans += 10000LL * mod;
			ans %= mod;
		}
		cout << ans << '\n';
		return 0;
	}
	if (k % 2 == 1 && cnt[2] == 0) {
		cout << 0 << '\n';
		return 0;
	}
	l = 0;
	r = n - 1;
	for (int i = 0; i < k; i++) {
		if (i < k - 1 && a[l] * a[l + 1] > a[r] * a[r - 1]) {
			ans *= (a[l] + mod);
			ans %= mod;
			ans *= (a[l + 1] + mod);
			ans %= mod;
			l += 2;
			i++;
		} 
		else {
			ans *= (a[r] + mod) % mod;
			ans %= mod;
			r--;
		}
	}
	cout << (ans + mod) % mod << '\n';
}


Measured memory_bytes: 6928
use std::vec::Vec;
use std::cmp::*;

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

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

fn main() {
  let n: usize = read();
  let a: Vec<usize> = read_vec();
  let mut count: Vec<usize> = vec![0; 3];
  for &e in &a {
    if e % 2 != 0 {
      count[0] += 1;
    } else {
      if e % 4 != 0 {
        count[1] += 1;
      } else {
        count[2] += 1;
      }
    }
  }

  if count[2] > count[0] {
    println!("Yes");
  } else if count[2] == count[0] {
    println!("Yes");
  } else if count[2] + 1 == count[0] && count[1] == 0 {
    println!("Yes")
  } else {
    println!("No");
  }

}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  vector<string> W(N);
  rep(i,N) {
    cin >>W.at(i);
  }
  int count=0;
  bool answer=false;
  repl(i,1,N) {
    if(   (W.at(i-1).at(W.at(i-1).size()-1))==(W.at(i).at(0))   ) {
      count++;
    }
       
       }
       if(count==N-1) {
         answer=true;
       }
       
    rep(i,N-1) {
      repl(j,i+1,N) {
        if(W.at(j)==W.at(i)) {
          answer=false;
        }
      }
    }
       if(answer) {
         cout <<"Yes"<< endl;
       }
else {
  cout<< "No" << endl;
}
       }
    
    

Measured memory_bytes: 384
#include<iostream>
#include<vector>
long long LCM(long long a,long long b);
long long GCD(long long a,long long b);
using namespace std;
int main(){
    int n;
    cin>>n;
    int i;
    vector<int> x(n+1);
    for(i=1;i<=n;i++){
        cin>>x[i];
    }

    long long ans;
    ans=LCM(x[1],x[2]);
    for(i=3;i<=n;i++){
        ans=LCM(ans,x[i]);
    }

    cout<<ans<<"\n";
}
long long LCM(long long a,long long b){
    return(a/GCD(a,b)*b);
}
long long GCD(long long a,long long b){
    while(b!=0){
        long long r=a%b;
        a=b;
        b=r;
    }
    return(a);
}


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


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, a[100];
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }

    int sum = 0, seq = 1, start = a[0];
    for(int i = 1; i < n; i++) {
        if (start != a[i]) {
            sum += seq / 2;
            start = a[i];
            seq = 0;
        }
        seq++;
        if (i == n - 1) {
            sum += seq / 2;
        }
    }
    cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cost = [0] * (n + 1)
for i in range(1, n + 1):
    cost[i] = cost[i - 1]
    cost[i] += a[i - 1]
ans = float('inf')
for i in range(1, n):
    ans = min(ans, abs(cost[i] - cost[n] + cost[i]))
print(ans)

Measured memory_bytes: 24620
import heapq

N, M = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
BC = []

for i in range(M):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)
    BC.append([b, c])

BC.sort(reverse=True, key=lambda x: x[1])

heapq.heapify(A)

flag = True
for bc in BC:
    for j in range(bc[0]):
        min_a = heapq.heappop(A)
        if min_a >= bc[1]:
            heapq.heappush(A, min_a)
            flag = False
            break
        else:
            min_a = bc[1]
        heapq.heappush(A, min_a)
    if not flag:
        break

print(sum(A))

Measured memory_bytes: 109976
public class Main {

  private static void solve() {
    int n = ni();
    double odd = 0;
    for (int i = 1; i <= n; i++) {
      if (i % 2 == 1) {
        odd++;
      }
    }
    System.out.println(odd / n);

  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

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

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}



Measured memory_bytes: 21204
S = input()
a = S.count('N')
b = S.count('S')
c = S.count('E') 
d = S.count('W')

if a*b*c*d > 0:
  print('Yes')
elif a*b > 0 and c==0 and d==0:
  print('Yes')
elif c*d >0 and a==0 and b==0:
  print('Yes')
elif a==0 and b==0 and c==0 and d==0:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
// ProblemURL : https://atcoder.jp/contests/agc038/tasks/agc038_a
// ---------------------------------------------
package main

import (
	"fmt"
	"strings"
)

func main() {
	var h, w, a, b int
	fmt.Scan(&h, &w, &a, &b)
	ans := ""
	for i := 0; i < b; i++ {
		ans += strings.Repeat("0", a)
		ans += strings.Repeat("1", w-a)
		ans += "\n"
	}
	for i := 0; i < h-b; i++ {
		ans += strings.Repeat("1", a)
		ans += strings.Repeat("0", w-a)
		ans += "\n"
	}
	fmt.Println(ans)
}


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

ll n;
vector<int> x;

// int c;

// int count(int num) {
//     int i = 0;
//     ll sum = 0;
//     int c = 0;
//     while(1) {
//         ++i;
//         sum += i;
//         if (sum > num) break;
//         c++;
//     }
//     return c;
// }

void dec(ll num){
	for (ll i = 2; i*i <= num; ++i) {
        int y = 0;
        while (num % i == 0) { 
            num /= i;
            ++y;
        }
        if (y != 0) x.push_back(y);
	}
    if (num != 1) x.push_back(1);
}

int main(){
    cin >> n;
    dec(n);
    int ans = 0;
    for(auto i : x){
        int b = 1;
        while(b <= i){
            i -= b;
            ++b;
            ++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

#define maxN 100011

ll n, a, b, i;
ll x[maxN];
ll dist = 0;

int main()
{
    //freopen("test.in","r",stdin);

    scanf("%lld%lld%lld", &n, &a, &b);
    for (i = 1; i <= n; i++) scanf("%lld", &x[i]);
    for (i = 2; i <= n; i++) {
        dist += min(b, a * (x[i] - x[i - 1]));
    }

    printf("%lld", dist);


    return 0;
}


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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) <= (m); ++(i))

int main(){
  vector<vector<int>> A(3, vector<int> (3));
  REP(i, 3){
    REP(j, 3){
      cin >> A[i][j];
    }
  }
  int N;
  cin >> N;
  vector<int> b(N);
  REP(i, N){
    cin >> b[i];
  }
  REP(k, N){
    REP(i, 3){
      REP(j, 3){
        if(A[i][j] == b[k]){
          A[i][j] = -1;
        }
      }
    }
  }
  REP(i, 3){
    bool flag = true;
    REP(j, 3){
      if(A[i][j] != -1){
        flag = false;
      }
    }
    if(flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  REP(j, 3){
    bool flag = true;
    REP(i, 3){
      if(A[i][j] != -1){
        flag = false;
      }
    }
    if(flag){
      cout << "Yes" << endl;
      return 0;
    }
  }
  bool flag = true;
  REP(i, 3){
    if(A[i][i] != -1){
      flag = false;
    }
  }
  if(flag){
    cout << "Yes" << endl;
    return 0;
  }
  flag = true;
  REP(i, 3){
    if(A[2-i][i] != -1){
      flag =false;
    }
  }
  if(flag){
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
w = input()
dct_str = dict.fromkeys(w, 0)
 
for alp in w:
    dct_str[alp] += 1
flag = True
for alp in dct_str.keys():
    if dct_str[alp] % 2 != 0:
        flag = False
 
if flag == True:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

stock = A.zip(B).map { |a, b| a - b }.sort

diff = 0
ans = 0

N.times do |i|
  if A[i] < B[i]
    ans += 1
    diff += A[i] - B[i]
  end

  while diff < 0 && !stock.empty?
    diff += stock.pop
    ans += 1
  end
end

if diff < 0
  puts -1
else
  puts ans
end


Measured memory_bytes: 22292