akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, N):
        self.N = N
        self.parent = list(range(N))

    def root(self, x):
        path_to_root = []
        while self.parent[x] != x:
            path_to_root.append(x)
            x = self.parent[x]
        for node in path_to_root:
            self.parent[node] = x  # パス圧縮
        return x

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        self.parent[self.root(x)] = self.root(y)

    def __str__(self):
        groups = {}
        for x in range(self.N):
            root = self.root(x)
            if root in groups.keys():
                groups[root].append(x)
            else:
                groups[root] = [x]
        result = ""
        for root in groups.keys():
            result += str(groups[root]) + "\n"
        return result

n, q = map(int, input().split())
u = UnionFind(n)
for i in range(q):
    com, x, y = map(int, input().split())
    if com == 0:
        u.unite(x, y)
    else:
        if u.same(x, y):
            print(1)
        else:
            print(0)



Measured memory_bytes: 6036
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    let t: Vec<char> = itr.next().unwrap().chars().collect();

    let mut ans = 300;
    for i in 0..n {
        let mut j = 0;
        while i + j < n && s[i + j] == t[j] {
            j += 1;
        }
        ans = min(ans, n * 2 - j);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
c = []
for i in range(3):
    c.append(list(map(int,input().split())))
a1 = 0
b1 = c[0][0]
b2 = c[1][0]
b3 = c[2][0]
a2 = c[0][1]-b1
a3 = c[0][2]-b1
if a2 + b2 == c[1][1] and a3 + b2 == c[1][2] and a2 + b3 == c[2][1] and a3 + b3 == c[2][2]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
a = int(input())
b = int(input())

if (a == 1 and b == 2) or (a == 2 and b == 1):
    print(3)
elif (a == 1 and b == 3) or (a == 3 and b == 1):
    print(2)
elif (a == 2 and b == 3) or (a == 3 or b == 2):
    print(1)

Measured memory_bytes: 38256
#include <stdio.h>

#define MYSCAN scanf

int main(void){
	int n, p, d1, d2, king, record;

	while (true){
		king = -1;
		record = -1;

		MYSCAN("%d", &n);
		if (n == 0){ break; }
		for (int i = 0; i < n; i++){
			MYSCAN("%d%d%d", &p, &d1, &d2);
			if (record < d1 + d2){
				record = d1 + d2;
				king = p;
			}
		}
		printf("%d %d\n", king, record);
	}	
	return 0;
}

Measured memory_bytes: 1028
class Tree:
    root = None

    def insert(self, node):
        y = None
        x = self.root
        while x:
            y = x
            x = x.left if node.key < x.key else x.right

        if not y:
            self.root = node
        elif node.key < y.key:
            y.left = node
        else:
            y.right = node

    def find(self, value):
        print('yes' if self.root.find(value) else 'no')

    def print(self):
        print(' ', end='')
        print(*self.root.print_in())
        print(' ', end='')
        print(*self.root.print_pre())


class Node:
    def __init__(self, key):
        self.left = None
        self.right = None
        self.key = key

    def find(self, value):
        diff = self.key - value
        if diff == 0:
            return True
        elif diff > 0:
            return self.left and self.left.find(value)
        else:
            return self.right and self.right.find(value)

    def print_pre(self):
        yield self.key
        if self.left:
            for k in self.left.print_pre(): yield k
        if self.right:
            for k in self.right.print_pre(): yield k

    def print_in(self):
        if self.left:
            for k in self.left.print_in(): yield k
        yield self.key
        if self.right:
            for k in self.right.print_in(): yield k


tree = Tree()
m = int(input())

while m:
    l = input()
    f = l[0]
    if f == 'i':
        tree.insert(Node(int(l.split()[1])))
    elif f == 'f':
        tree.find(int(l.split()[1]))
    else:
        tree.print()
    m -= 1

Measured memory_bytes: 93268
M, K = map( int, input().split())
ANS = []
ans = 0
if M == 0:
    if  K == 0:
        ans = 0
        ANS = [0,0]
    else:
        ans = -1
elif M == 1:
    if  K == 0:
        ans = 0
        ANS = [0,0,1,1]
    else:
        ans = -1
elif M >= 2:
    if K >= 2**M:
        ans = -1
if M >= 2 and ans == 0:
    ANS = list( range(K+1)) + list( range(K))[::-1] + list( range(K,2**M))[::-1] + list(range(K+1,2**M))
if ans == -1:
    print(ans)
else:
    print(" ".join( map( str, ANS)))


Measured memory_bytes: 93520
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  int R;
  cin>>R;
  cout<<R*R<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MOD 1000000007
#define ll long long
int main(){
    int n,i;
    ll k,ans1=0,count=0;
    scanf("%d%lld",&n,&k);
    int a[n];
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++){
        for(int j=i+1;j<n;j++)
            if(a[i]>a[j])
                ans1++;
        for(int j=0;j<i;j++)
            if(a[i]>a[j])
                count++;
    }
    ll ans=0;
    ans=(ans1+count)*(((k-1)*k/2)%(MOD))+ans1*k;
    printf("%lld\n",ans%MOD);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;

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;
}
using namespace std;

void solve(){
    ll N,h,n,w;
    cin>>N;
    for(h=1;h<=3500;++h){
        for(n=1;n<=3500;++n){
            if((4*h*n-N*n-N*h)>0&&(N*h*n)%(4*h*n-N*n-N*h)==0){
                w=(N*h*n)/(4*h*n-N*n-N*h);
                cout<<h<<" "<<n<<" "<<w<<"\n";
                return;
            }
        }
    }

}

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


Measured memory_bytes: 256
from collections import deque
import copy
h,w = map(int,input().split())
maze = [["#"] * (w+2)]
for i in range(h):
    lu = list(input())
    l = ["#"] + lu + ["#"]
    maze.append(l)
maze.append(["#"] * (w+2))


def breadth_first_search(start,W,Wn):
    work_q = deque([])
    visited = set()
    work_q.append(start)
    visited.add(start)
    Wn[start[0]][start[1]] = 0
    while work_q:
        here = work_q.popleft()
        move = [(here[0]+1,here[1]), (here[0],here[1]+1),
                (here[0]-1,here[1]),(here[0],here[1]-1)]
        for i in move:
            if W[i[0]][i[1]] == "." and i not in visited:
                work_q.append(i)
                visited.add(i)
                Wn[i[0]][i[1]] = Wn[here[0]][here[1]] + 1

    return Wn


ans = 0
for i in range(h+2):
    for j in range(w+2):
        maze_num = copy.deepcopy(maze)
        if maze[i][j] == ".":
            start = (i,j)
            wn =breadth_first_search(start,maze, maze_num)
            wn_max = 0
            for k in range(h+2):
                for l in range(w+2):
                    if wn[k][l] != "#":
                        wn_max = max(wn_max, wn[k][l])
            ans = max(ans, wn_max)
print(ans)


Measured memory_bytes: 3572
a,b = map(int,input().split())	

if a>b and a-1>=b:
    print(a+a-1)
    
elif a>b and a-1<b:
    print(a+b)

elif a<b and a<=b-1:
    print(b+b-1)

elif a<b and a >b-1:
    print(b+a)
    
else:
    print(a+b)


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin>>n;
  vll x(n),y(n);
  REP(i,n)cin>>x[i]>>y[i];

  vpl xp(n),yp(n);
  REP(i,n){
    xp[i].FI=x[i];
    yp[i].FI=y[i];
    xp[i].SE=yp[i].SE=i;
  }

  sort(xp.begin(),xp.end());
  sort(yp.begin(),yp.end());

  vector<vpl> edge(n);
  REP1(i,n){
    pll l=xp[i-1];
    pll r=xp[i];
    ll diff=abs(r.FI-l.FI);
    edge[l.SE].push_back(pll(diff, r.SE));
    edge[r.SE].push_back(pll(diff, l.SE));
  }
  REP1(i,n){
    pll l=yp[i-1];
    pll r=yp[i];
    ll diff=abs(r.FI-l.FI);
    edge[l.SE].push_back(pll(diff, r.SE));
    edge[r.SE].push_back(pll(diff, l.SE));
  }


  //dijkstra
  priority_queue<pll,vector<pll>, greater<pll>> que;
  que.push(pll(0,0));
  bool visited[n];
  REP(i,n)visited[i]=false;

  ll ans=0;
  while(!(que.empty())){
    pll p=que.top();
    que.pop();
    if(visited[p.SE])
      continue;
    ans+=p.FI;
    visited[p.SE]=true;

    for(auto e:edge[p.SE]){
      if(!visited[e.SE])
        que.push(e);
    }
  }

  cout<<ans<<endl;

}


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

int main(){
    ll x;
    cin >> x;
    ll y = 100;
    ll res = 0;
    while(y < x){
        y = y + y / 100;
        res++;
    }
    cout << res << endl;

    return 0;
} 

Measured memory_bytes: 3636
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


ll N, M;
map<ll, vector<ll>> G;

void solve(ll n, set<ll>& s, ll& ans) {
    if (s.size() == N) {
        ++ans;
        return;
    }
    for (auto i : G[n]) {
        if (s.count(i)) continue;
        s.ist(i);
        solve(i, s, ans);
        s.erase(i);
    }
}


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    cin >> N >> M;
    rep (i, M) {
        ll a, b;
        cin >> a >> b;
        G[a].pb(b);
        G[b].pb(a);
    }
    ll ans = 0;
    set<ll> s = {1};
    solve(1, s, ans);
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
a.sort()
b = []
d = []
for i in range(n):
    c = i // 2
    if i%2 == 0:
        b.append(a[c])
    else:
        b.append(a[n-1-c])
        
for i in range(n):
    c = i // 2
    if i%2 == 1:
        d.append(a[c])
    else:
        d.append(a[n-1-c])
        
b.append(a[0])
d.append(a[n-1])
sa = []
sa2 = []
for i in range(n):
    sa.append(abs(b[i+1] - b[i]))
    sa2.append(abs(d[i+1] - d[i]))
    
print(max(sum(sa) - min(sa) , sum(sa2) - min(sa2)))

Measured memory_bytes: 64856
using System;

class ACorWA
{
    static void Main(string[] args)
    {
        var ans = "";

        var input = Console.ReadLine().Split(' ');
        if(int.Parse(input[0]) == int.Parse(input[1]))
        {
            ans = "Yes";
        }
        else
        {
            ans = "No";
        }

        Console.WriteLine(ans);

    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;scanf("%d",&n);
    for(int i=1;i*i<=n;i++)
    {
        if(n%i==0)
        {
            int t1=i,t2=n/i;
            if(t1<=9&&t1>=1&&t2<=9&&t2>=1)
            {
                return 0*printf("Yes\n");
            }
        }
    }
    printf("No\n");
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  vector<int> a(26);
  for(int i = 0; i < s.size(); i++){
    a[s[i]-'a']++;
  }
  for(int i = 0; i < 26; i++){
    if(a[i] % 2 != 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

using namespace std;

int main() {

    int N;
    int current = 0;
    int largest = 0;
    vector < int > h;
    cin >> N;

    h.push_back(0);
    cin >> h[0];

    for (int i = 1; i < N; i++) {

        h.push_back(0);
        cin >> h[i];
        if (h[i-1] >= h[i]) current++;
        else {

            if (current > largest) largest = current;
            current = 0;
        } 
    }

    cout << max(largest, current) << endl;
    return 0;
}

Measured memory_bytes: 892
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int N, M, arr[1005];

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    while (true) {
        cin >> N >> M;
        if (N == 0 && M == 0) break;
        arr[0] = 0; ++N;
        for (int j = 1; j < N; ++j) {
            cin >> arr[j];
        }
        vector<int> arr2;
        for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) if (arr[j] + arr[k] <= M) {
            arr2.push_back(arr[j] + arr[k]);
        }
        sort(begin(arr2), end(arr2));
        const int NN = arr2.size();

        int ans = 0, r = NN-1;
        for (int j = 0; j < NN; ++j) {
            while (arr2[j] + arr2[r] > M) --r;
            if (arr2[j] + arr2[r] <= M) {
                ans = max(ans, arr2[j] + arr2[r]);
            }
        }

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

Measured memory_bytes: 10692
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
ll n;
vector<bool> tobit(ll inp) {
    vector<bool> v(n, 0);
    int i = 0;
    while(inp) {
        v[i] = inp % 2;
        inp /= 2;
        i++;
    }
    return v;
}
int main() {
    ll k;
    cin >> n >> k;
    vector<ll> a(n);
    for(size_t i = 0; i < n; i++) {
        cin >> a[i];
    }

    ll ans = LLONG_MAX;
    for(ll i = 0; i < (1LL << n); i++) {
        ll tmp = 0;
        auto v = tobit(i);
        auto cp = a;
        for(int j = 0; j < n; j++) {
            if(v[j]) {
                ll m = -1;
                for(int p = 0; p < j; p++) {
                    m = max(m, cp[p]);
                }

                if(m >= cp[j]) {
                    tmp += m + 1 - cp[j];
                    cp[j] = m + 1;
                }
            }
        }
        ll tm = -1;
        ll cnt = 0;
        for(int j = 0; j < n; j++) {
            if(tm < cp[j]) {
                cnt++;
            }
            tm = max(tm, cp[j]);
        }
        if(cnt >= k) {
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;
}


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

int main(){
	int N, D;
	cin >> N >> D;
	
	vector<vector<int>> data(N, vector<int>(D));
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			cin >> data.at(i).at(j);
		}
	}
	int sum=0, ans=0;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if (i<j){
				sum = 0;
				for(int k=0;k<D;k++){
						sum += (data.at(i).at(k)-data.at(j).at(k))*(data.at(i).at(k)-data.at(j).at(k));
				}
				double dis = sqrt(sum);
				if (int(dis)-dis==0){
				ans++;
			}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define fi first
#define se second
#define endl "\n" 
using namespace std;
using db = double;
using ll = long long;
using ull = unsigned long long; 
using pII = pair <int, int>;
using pLL = pair <ll, ll>;
constexpr int mod = 1e9 + 7;
template <class T1, class T2> inline void chadd(T1 &x, T2 y) { x += y; while (x >= mod) x -= mod; while (x < 0) x += mod; } 
template <class T1, class T2> inline void chmax(T1 &x, T2 y) { if (x < y) x = y; }
template <class T1, class T2> inline void chmin(T1 &x, T2 y) { if (x > y) x = y; }
inline int rd() { int x; cin >> x; return x; }
template <class T> inline void rd(T &x) { cin >> x; }
template <class T> inline void rd(vector <T> &vec) { for (auto &it : vec) cin >> it; }  
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0) 
void err() { cout << "\033[39;0m" << endl; } 
template <class T, class... Ts> void err(const T& arg, const Ts&... args) { cout << arg << ' '; err(args...); }
template <template<typename...> class T, typename t, typename... A> 
void err(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; err(args...); }
inline void pt() { cout << endl; } 
template <class T, class... Ts> void pt(const T& arg, const Ts&... args) { cout << arg << ' '; pt(args...); }
template <template<typename...> class T, typename t, typename... A> 
void pt(const T <t> &arg, const A&... args) { for (auto &v : arg) cout << v << ' '; pt(args...); }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
inline ll qpow(ll base, ll n) { ll res = 1; while (n) { if (n & 1) res = res * base % mod; base = base * base % mod; n >>= 1; } return res; }
//head
constexpr int N = 3e5 + 10;
int n, a[N], res, tot;
priority_queue <int, vector <int>, less<int> > pq; 
bool ok(int k) {
	while (!pq.empty()) {
		int top = pq.top(); pq.pop();
		if (top > res) {
			pq.push(top - 1);
			--tot;
		} else {
			pq.push(top);
			break;
		}
	}
	return tot / k >= res;
}
void run() {
	memset(a, 0, sizeof a);
	while (!pq.empty()) pq.pop();
	for (int i = 1; i <= n; ++i) ++a[rd()];
	for (int i = 1; i <= n; ++i) pq.push(a[i]);
	res = n; tot = n; 
	for (int i = 1; i <= n; ++i) {
		while (res && !ok(i)) --res;
		pt(res);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr); cout.tie(nullptr);
	cout << fixed << setprecision(20);
	while (cin >> n) run();
	return 0;
}


Measured memory_bytes: 3696
#  search

n = int(input())
S = list(set(map(int,input().split())))
q = int(input())
T = list(map(int,input().split()))

S.sort()
T.sort()
ans = 0

i = 0
for elm in S:
    if elm > T[i]:
        while i < q-1 and elm > T[i]:
            i += 1
        
        if elm == T[i]:
            ans += 1
    elif elm == T[i]:
        ans += 1
    elif elm < T[i]:
        pass

print(ans)


Measured memory_bytes: 6060
from enum import Enum
from queue import Queue
import collections
import bisect

import sys
import math

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001

N = int(input())
L = list(map(int,input().split()))

L.sort()
ans = 0
for i in range(N):
    for j in range(i+1,N):
        key = bisect.bisect_left(L,L[j]-L[i]+1)
        ans += max([0,i-key])

print(ans)


Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,count=0; cin>>N;
  ll ans=N;
  vector<ll>A(N+1),B(N+1);
  string S; cin>>S;
  //A:iより左にある黒の個数
  for(int i=0; i<N; i++){
    if(S[i]=='#') count++;
    A[i+1]=count;
  }
  //B:iより右にある白の個数
  count=0;
  for(int i=N-1; i>=0; i--){
    if(S[i]=='.') count++;
    B[i]=count;
  }
  for(int i=0; i<=N; i++){
//    cout<<"i:"<<i<<" A[i];"<<A[i]<<" B[i]:"<<B[i]<<endl;
    ans=min(A[i]+B[i],ans);
  }
  cout<<ans<<endl;  
}

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];
  sort(d.begin(), d.end());
  int l = d[N/2-1];
  int r = d[N/2];
  int ans = r-l;
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;

const int MAX = 1e6+1;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
  if(n >= MAX){
    ll tmp = 1;
    rep(i,k){
      tmp *= (n-i);
      tmp %= MOD;
    }
    return tmp*finv[k]%MOD;
  }

  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll POW(ll x, ll n){
  ll ret = 1;

  if(n < 0){// n < 0 にも対応
    n *= -1;
    x = inv[x];
  }

  while(0 < n){
    if(n%2 == 0){
      x = x*x%MOD;
      n /= 2;
    }
    else{
      ret = ret*x%MOD;
      n--;
    }
  }

  return ret;
}

vi MP(string s){
  vi A(s.size()+1);
  A[0] = -1;
  int j = -1;
  rep(i,s.size()) {
    while(j >= 0 && s[i] != s[j]) j = A[j];
    j++;
    A[i+1] = j;
  }
  return A;
}

vi Manacher(string s){
  vi R(s.size());
  int i = 0, j = 0;
  while(i < s.size()){
    while(i-j >= 0 && i+j < s.size() && s[i-j] == s[i+j]) ++j;
    R[i] = j;
    int k = 1;
    while(i-k >= 0 && i+k < s.size() && k+R[i-k] < j) R[i+k] = R[i-k], k++;
    i += k; j -= k;
  }
  return R;
}

vi Z_algorithm(string &s){
  vi Z(s.size());
  Z[0] = s.size();
  int i = 1, j = 0;
  while(i < s.size()){
    while(i+j < s.size() && s[j] == s[i+j]) j++;
    Z[i] = j;
    if(j == 0){++i; continue;}
    int k = 1;
    while(i+k < s.size() && k+Z[k] < j) Z[i+k] = Z[k], ++k;
    i += k; j -= k;
  }
  return Z;
}

int main(){
  string s; cin >> s;
  map<char,int> C;
  rep(i,s.size()) C[s[i]]++;
  cout << (C.size() == 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
using namespace std;
int n,m,i,j,pos,cnt[1000005],ans;
queue<int> qx;
string s,t;
int main()
{
	scanf("%d",&n);
	rdst(s,1000005);
	rdst(t,1000005);
	if(s==t){puts("0");return 0;}
	s=" "+s;t=" "+t;
	int lst=pos=n;
	fd1(i,n){
		if(t[i]==t[i-1])continue;
		pos=min(pos,i);
		while(pos>0&&s[pos]!=t[i])pos--;
		if(s[pos]!=t[i]){puts("-1");return 0;}
		while(!qx.empty()){
			if(qx.front()-qx.size()>=i){
				qx.pop();
			}
			else break;
		}
		qx.push(pos);
		if(pos!=i){
			ans=max(ans,(int)qx.size());
		}
	}
	cout<<ans+1<<endl;
	return 0;
}

Measured memory_bytes: 10072
#include <bits/stdc++.h>
#define INF 100000000000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int k;
ll a[100009];

ll C(ll v){
	for(int i=0;i<k;i++){
		v=v-v%a[i];
	}
	return v;
}

int main(void){
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		scanf("%lld",&a[i]);
	}
	ll l=0,r=INF;
	while(l+1LL<r){
		ll mid=(l+r)/2LL;
		if(C(mid)<2LL)l=mid;
		else r=mid;
	}
	ll a1=r;
	l=0,r=INF;
	while(l+1LL<r){
		ll mid=(l+r)/2LL;
		if(C(mid)<=2LL)l=mid;
		else r=mid;
	}
	ll a2=l;
	if(C(a1)!=2LL || C(a2)!=2LL){
		printf("-1\n");
		return 0;
	}
	printf("%lld %lld\n",a1,a2);
	return 0;
}

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

int main(){
	int n;
	int total = 0;
	cin >> n;
	vector<int> d(n);
	rep(i,n) cin >> d[i];
	rep(i,n)for(int j=i+1; j<n; j++) {
		total += d[i]*d[j];
	}
	
	cout << total << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
h = [list(map(int,input().split()))for _ in range(n)]

x = []*n
y = []*2

for i in range(n):
  y.append(h[i][0]-h[i][1]) #腕が届く地点の最小値
  y.append(h[i][0]+h[i][1]) #腕が届く地点の最大値
  x.append(y) #xに保存
  y = []*2 #yを初期化

x.sort(key = lambda x:x[1]) #腕が届く地点の最大値が小さい順にソート

k = 0	#配列xのtale

for i in range(n-1):
  if x[k][1] > x[k+1][0]: #k番目の最大値よりもk+1の最小値の方が小さい時(つまり腕が重なる時)
    x.pop(k+1) #k+1番目を取り出す

  else:
    k += 1 #taleを一個後ろに下げる

print(len(x)) #要素数(残ったロボットの数)を出力


Measured memory_bytes: 42792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int N, M;
    cin >> N >> M;
    vector<vector<int>> graph(N);
    for(int i = 0; i < M; ++i){
        int A, B;
        cin >> A >> B;
        --A, --B;
        graph[A].emplace_back(B);
        graph[B].emplace_back(A);
    }
    
    vector<bool> used(N, false);
    deque<int> deq;
    auto dfs = [&](auto&& self, int cur = 0) -> void {
        used[cur] = true;
        deq.push_back(cur);
        for(int nxt : graph[cur]){
            if(used[nxt])   continue;
            self(self, nxt);
            break;
        }
    };
    dfs(dfs);
    auto dfs2 = [&](auto&& self, int cur = 0) -> void {
        used[cur] = true;
        if(cur != 0)    deq.push_front(cur);
        for(int nxt : graph[cur]){
            if(used[nxt])   continue;
            self(self, nxt);
            break;
        }
    };
    used[0] = false;
    dfs2(dfs2);

    int ans = deq.size();
    cout << ans << '\n';
    for(int i = 0; i < ans; ++i){
        cout << deq.front() + 1;
        deq.pop_front();
        cout << ((i == ans - 1) ? '\n' : ' ');
    }
}

Measured memory_bytes: 8860
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
using VI = vector<int>;

string rot(string s) {
    return s.back() + s.substr(0, s.size() - 1);
}

int main() {
    string s, t;
    cin >> s >> t;
    for (int i = 0; i < s.size(); i++) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = rot(s);
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
from heapq import heapify, heappush, heappop


def solve(N: int, A: "List[int]", B: "List[int]"):

    lh = []
    for i, b in enumerate(B):
        heappush(lh, (-b, i))

    count = 0
    while lh:
        b, i = heappop(lh)
        a, b = A[i], B[i]
        c = B[i-1]+B[(i+1) % N]
        if b > a and b >= c:
            d, m = divmod(b-a, c)
            if d == 0:
                break
            count += d
            B[i] = a+m
            if m != 0:
                heappush(lh, (-B[i], i))

    if A != B:
        count = -1

    print(count)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 122828
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b,d,r;
    cin >> a >> b;
    double f;
  double a2=a;
  double b2=b;
    
    d = a/b;
    r = a%b;
    f = a2/b2;
    
    cout << d << " " << r << " ";
    
    cout << fixed << setprecision(5);
    
    cout << f << endl;
}


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

#define EPS (1e-7)
#define INF (1<<25)
#define PI (acos(-1))

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

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

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; }

using ll = long long;

int main() {
  int N; cin >> N;
  string s1, s2; cin >> s1 >> s2;
  ll ans;
  bool f = false;
  if (s1[0] == s2[0]) ans = 3, f = true;
  else ans = 6;
  for (int i = 1; i < N; ++i) {
    if (s1[i] == s1[i-1]) continue;
    if (s1[i] == s2[i]) {
      if (f) ans *= 2, ans %= 1000000007;
      f = true;
    } else {
      if (f) ans *= 2, ans %= 1000000007;
      else ans *= 3, ans %= 1000000007;
      f = false;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
int main(){
	int N;
  cin >>N;
  vector<int> A(N);
  for(int i=0;i<N;i++)cin >>A[i];
  for(int i=0;i<N;i++)if(A[i]<0)A[i]=-A[i];
  sort(A.begin(),A.end());
  cout << A[N-1]-A[0] <<endl;
  
    
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    class BIT():
        def __init__(self,n):
            self.num=n
            self.dat=[0]*(self.num+1)
        
        def add(self,i,x):
            i+=1
            while i<=self.num:
                self.dat[i]+=x
                i+=i&-i
        
        def sum(self,i):
            i+=1
            s=0
            while i>0:
                s+=self.dat[i]
                i-=i&-i
            return s
    
    N=int(input())
    S=list(input())
    Q=int(input())
    bit=[BIT(N) for _ in range(26)]
    
    S2=[0]*N
    
    for i in range(N):
        S2[i]=ord(S[i])-ord('a')
    
    for i,x in enumerate(S2):
        bit[x].add(i,1)
    
    for _ in range(Q):
        a,b,c=input().split()
        if a=='1':
            b=int(b)-1
            c=ord(c)-ord('a')
            bit[c].add(b,1)
            bit[S2[b]].add(b,-1)
            S2[b]=c
        else:
            b=int(b)-1
            c=int(c)-1
            ans=0
            for i in range(26):
                if bit[i].sum(c)-bit[i].sum(b-1):
                    ans+=1
            print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 168348
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  string s; cin >> s;
  if (s[2] == s[3] and s[4] == s[5]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
N=int(input())
S=input()
Alp={"A":0,"B":1,"C":2,"D":3,"E":4,"F":5,"G":6,"H":7,"I":8,"J":9,"K":10,"L":11,"M":12,"N":13,"O":14,"P":15,"Q":16,"R":17,"S":18,"T":19,"U":20,"V":21,"W":22,"X":23,"Y":24,"Z":25}
new_Alp=[]

for i in range(len(S)):
  num=Alp[S[i]]
  num+=N
  num%=26
  
  for key,atai in Alp.items():
    if atai==num:
      new_Alp.append(key)

new_alp="".join(new_Alp)
print(new_alp)

Measured memory_bytes: 39536
/* 	* In the name of GOD 
 	* Thanks God */
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
const int N = 201234;
int a[N];

int32_t main(){
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = 0; i < n - k; i++) {\
		cout << (a[i] < a[i + k] ? "Yes\n" : "No\n");
	}
}


Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  ll a, b, c; cin >> a >> b >> c;
  ll A[] = {a, b, c};
  vector<ll> L(n); rep(i, n) cin >> L[i];
  ll mn = longinf;
  rep(i, 1<<(2*n)) {
    vector<ll> len(4);
    vector<ll> cnt(4);
    rep(j, n) {
      len[(i>>(2*j))%4] += L[j];
      cnt[(i>>(2*j))%4]++;
    }
    if(len[0]*len[1]*len[2]==0) continue;
    ll tmp = 0;
    rep(j, 3) {
      tmp += (cnt[j]-1) * 10LL;
      tmp += abs(A[j]-len[j]);
    }
    mn = min(tmp, mn);
  }
  cout << mn << "\n";
  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
typedef long long ll;
using namespace std;



int main()
{
    int n,m,x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int> > A(n,vector<int>(m));
    for(int i = 0; i < n; i++)
    {
        cin >> c[i];
        for(int j = 0; j < m; j++)
        {
            cin >> A[i][j];
        }
    }
    vector<int> skill(m);
    vector<int> ok(m);
    ll ans = 100000000;
    for (int bit = 0; bit < (1 << n); bit++)
    {
        for(int i = 0; i < m; i++)
        {
            skill[i] = 0;
            ok[i] = false;
        }
        ll price = 0;
        for(int i = 0 ; i < n; i++)
        {

            if(bit&(1 << i)) //何冊目の本が選ばれているか
            {
              //  cout <<"ssss" << bitset<12>(bit)  << "sssss"<< endl;
                price += c[i];
                for(int j = 0; j < m; j++)
                {
                    skill[j] += A[i][j]; //スキルアップ
                    if(skill[j] >= x) //アップしたスキルがxに届いたら
                    {
                      // cout <<"ssss    " << j  << "   sssss"<< endl;
                      // cout <<"skill j =  " << skill[j]  << "  sssss"<< endl;
                        ok[j] = true;
                    }
                }
            }
        }
        int count = 0;
        for(int k = 0; k < m; k++)
        {
            if(ok[k] == false)
            {
             //    cout <<"ssss" << bitset<12>(bit)  << "sssss"<< endl;
                break; //すべてx以上にはできなかった
            }
            count++;
        }
      //  cout <<"ssss" << bitset<12>(bit)  << "sssss"<< endl;
       // cout << price << endl;
       if(count == m) ans = min(ans,price);
      // cout << ans << endl;
    }
    if(ans == 100000000) ans = -1;
    cout << ans << endl;
    return (0);
}

Measured memory_bytes: 3232
# -*- coding: utf-8 -*-
import math
#from collections import Counter


def combinations_count(n, r):
    if n < r:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def main():
    N = int(input())
    combi = {}
    for i in range(N):
        t = ''.join(sorted(input()))
        #print(t)
        if t not in combi.keys():
            #combi.append(t)
            combi[t] = 1
        else:
            combi[t] += 1

    ans = 0
    for v in combi.values():
        ans += combinations_count(v,2)
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 17848
#include <iostream>
#include <algorithm>
int main(){
  char a[51][51],m[51][51];int i,j,k,h,w,c;
  std::cin>>h>>w;
  for(i=0;i<h;++i)for(j=0;j<w;++j)std::cin>>m[i][j];
  int dx[]={0,0,1,1,1,-1,-1,-1},dy[]={1,-1,0,1,-1,0,1,-1};
  for(i=0;i<h;++i){
    for(j=0;j<w;++j){
      if(m[i][j]=='#')std::cout<<'#';
      else{
        c=0;
        for(k=0;k<8;++k)if(i+dy[k]>=0&&i+dy[k]<h&&j+dx[k]>=0&&j+dx[k]<w)(m[i+dy[k]][j+dx[k]]=='#'?++c:0);
        std::cout<<c;
      }
    }
    std::cout<<"\n";
  }
}

Measured memory_bytes: 256
#include <iostream>
int main(){
  int n, c[501], s[501], f[501], a[501]={}, i=0, j, t;
  std::cin>>n;
  while(std::cin>>c[i]>>s[i]>>f[i])i++;
  for(i=0;i<n-1;++i){
    t=0;
    for(j=i;j<n-1;++j){
      if(t<s[j])t=s[j];
      if(t%f[j]==0)t+=c[j];
      else t+=c[j]+f[j]-t%f[j];
    }
    a[i] = t;
  }
  for(i=0;i<n;++i)std::cout<<a[i]<<"\n";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a[3],max=0,i;
  scanf("%d %d %d",&a[0],&a[1],&a[2]);
  
  for(i=0;i<3;i++){
    if(max<a[i]) max = a[i];
  }
  
  printf("%d\n",a[0]+a[1]+a[2]-max);
  
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll i,j;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,y;
    cin>>n>>y;
    for(i=0; i<=n; i++)
    {
        ll tmp=i*10000;
        for(j=0; i+j<=n; j++)
        {
            ll tmp2=tmp+j*5000;
            ll tmp3=y-tmp2;
            if(tmp3>=0 && tmp3%1000==0)
            {
                ll k=tmp3/1000;
                if(i+j+k==n)
                {
                    cout<<i<<" "<<j<<" "<<k<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
}



Measured memory_bytes: 256
import java.util.*;
class Main {
     
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        Dice dice = new Dice(stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt(),stdIn.nextInt());
        String a = stdIn.next();
        for(int i = 0; i < a.length(); i++) {
            if(a.charAt(i) == 'N') {
                dice.TurnN();
            }
            else if(a.charAt(i) == 'W') {
                dice.TurnW();
            }
            else if(a.charAt(i) == 'E') {
                dice.TurnE();
            }
            else {
                dice.TurnS();
            }
        }
        System.out.println(dice.Top);
    }
     
     
}
 
class Dice {
    int Top; 
    int Bottom; 
    int N; 
    int S; 
    int W;
    int E; 
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }
     
}


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


int main() {

    ll N , k ;
     cin>>N >> k ;
      ll Arr[N];
      for(ll i =0 ; i < N ; i ++){
          cin>>Arr[i];
      }
      sort(Arr,Arr+N);
      ll counter=0;
      for(ll i=0 ; i<N-k ;i++){
          counter+=Arr[i];
      }
      cout<<counter;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) cin >> a[i];
  int m = 4000000;
  for (int i = -100; i <= 100; i++){
    int c = 0;
    for (int j = 0; j < N; j++){
      c += (a[j] - i) * (a[j] - i);
    }
    m = min(m,c);
  }
  cout << m;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
#1のindexを取得
# one_idx = a.index(1)
#
# from decimal import Decimal
#
# left_list_len = one_idx
# right_list_len = n - one_idx - 1
#
#
# print(left_list_len//(k-1)+ right_list_len//(k-1) + min(left_list_len%(k-1),1) + min(right_list_len%(k-1),1))

#左からk-1個を1に変える操作を繰り返す(k=2の時だけ別)
if k==2:
    ret = n-1
else:
    ret = (n-1)//(k-1)+min((n-1)%(k-1),1)
print(ret)

Measured memory_bytes: 13876
#include<iostream>
#include<set>
#include<vector>
#include<array>
#include<algorithm>
#include<chrono>

uint64_t xor64(void) {
  static uint64_t x = 88172645463325252ULL;
  x = x ^ (x << 7);
  return x = x ^ (x >> 9);
}

auto b_cl = std::chrono::system_clock::now();
inline double get_time() {
  auto e_cl = std::chrono::system_clock::now();
  double msec = std::chrono::duration_cast<std::chrono::milliseconds>(e_cl - b_cl).count();
  return msec;
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int D; std::cin >> D;
  int c[26];
  for(auto& ci: c) std::cin >> ci;
  std::vector<std::array<int,26>> s(D);
  for(int d = 0; d < D; ++d) {
    for(auto& si: s[d]) std::cin >> si;
  }
  std::vector<int> t(D);
  for(int i = 0; i < D; ++i) t[i] = i%26;
  std::set<int> last[26];
  for(auto& li: last) li.insert(-1); // sentinel
  int ans = 0;
  for(int d = 0; d < D; ++d) {
    int t1 = t[d];
    ans += s[d][t1];
    last[t1].insert(d);
    for(int i = 0; i < 26; ++i) {
      ans -= c[i]*(d - *last[i].rbegin());
    }
  }
  for(auto& li: last) li.insert(D); // sentinel
  
  // additional score when t[d] = i compare to t[d] = -1
  auto sum_up = [](int d) { return d*(d-1)/2; };
  auto score = [&](int d, int i)->int {
    int res = s[d][i];
    auto it = last[i].lower_bound(d);
    int nd = *it;
    int pd = *--it;
    int diff = sum_up(d-pd) + sum_up(nd-d) - sum_up(nd-pd);
    res -= c[i]*diff;
    return res;
  };
  int lm = 0, renew = 0;
  int sc[26];
  auto one_day = [&](int d) {
    int pi = t[d];
    last[pi].erase(d);
    for(int i = 0; i < 26; ++i) sc[i] = score(d, i);
    int mi = std::max_element(sc, sc+26) - sc;
    if(mi != pi) {
      ans += sc[mi] - sc[pi];
      ++renew;
    }
    last[mi].insert(d);
  };
  
  // hill climbing
  int range = 16;
  for(int rep = 0;; ++rep) {
    if((xor64()>>25)%2) {
      one_day(xor64()%365);
    } else {
      // swap
      int d1 = xor64()%D, d2 = xor64()%D;
      while(d1 < d2-range || d2 < d1-range || t[d1] == t[d2]) {
          d1 = xor64()%D; d2 = xor64()%D;
      }
      int pi1 = t[d1], pi2 = t[d2];
      last[pi1].erase(d1);
      int diff = score(d1, pi2) - score(d1, pi1);
      last[pi2].insert(d1);
      last[pi2].erase(d2);
      diff += score(d2, pi1) - score(d2, pi2);
      if(diff > 0) {
        last[pi1].insert(d2);
        t[d1] = pi2;
        t[d2] = pi1;
        lm = 0;
      } else {
        last[pi2].insert(d2);
        last[pi2].erase(d1);
        last[pi1].insert(d1);
      }
    }
    if(rep%100 == 0) {
      int x = get_time();
      if(x > 1980) break;
      //if(x > 200) range = 25;
      //if(x > 400) range = 20;
      //if(x > 700) range = 15;
      //if(x > 1000) range = 10;
    }
  }
  for(auto ti: t) std::cout << ti+1 << "\n";
  return 0;
}


Measured memory_bytes: 3644
n = int(input())
words = []
ans = 1
for i in range(n):
    word = input()
    if word not in words:
        words.append(word)
    else:
        ans = 0
if len(words) == n:
    for i in range(n-1):
        word = words[i]
        if words[i][len(word)-1] == words[i+1][0]:
            continue
        else:
            ans = 0
            break

if ans == 0:
    print("No")
else:
    print("Yes")

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

int main(){ 
    int n;
    string s;
    cin>>n;
    cin>>s;
    int a=0;
    for(int i=0;i<n;i++){
        if(s[i]!=s[i+1]){
            a++;
        }
    }
    cout <<a;
    return 0;
}


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

using namespace std;

#define MAX 100000

struct TRAMP{
    char mark;
    int number,inputed_order;
};

TRAMP cards[MAX];

int n;

int Partition(int left,int right){
    int i = left-1,pivot = cards[right].number;
    for(int start = left; start < right; start++){
        if(cards[start].number <= pivot){
                i++;
                std::swap(cards[i],cards[start]);
        }
    }

    std::swap(cards[i+1],cards[right]);

    return i+1;
}

void quickSort(int left,int right){
    if(left < right){
        int q = Partition(left,right);
        quickSort(left,q-1);
        quickSort(q+1,right);
    }
}


int main(){

    bool stableFLG = true;
    scanf("%d",&n);

    for(int i = 0; i < n; i++){
        scanf("%s %d",&cards[i].mark,&cards[i].number);
        cards[i].inputed_order = i;
    }

    quickSort(0,n-1);

    for(int i = 1; i < n; i++){
        if(cards[i].number == cards[i-1].number && cards[i].inputed_order < cards[i-1].inputed_order){
        	stableFLG = false;
        	break;
        }
    }

    if(stableFLG){
        printf("Stable\n");
    }else{
        printf("Not stable\n");
    }

    for(int i = 0; i < n; i++)   printf("%c %d\n",cards[i].mark,cards[i].number);
}


Measured memory_bytes: 4280