akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

struct unionfind{
  vector<int> par;
  vector<int> rank;
  unionfind(int n=1){
    init(n);
  }
  void init(int n=1){
      par.resize(n); rank.resize(n);
      for(int i=0;i<n;++i) par[i]=i,rank[i]=0;
  }
  int root(int x){
    if(par[x]==x){
      return x;
    }
    else{
      int r=root(par[x]);
      return par[x]=r;
    }
  }
  bool issame(int x,int y){
    return root(x)==root(y);
  }
  bool merge(int x,int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(rank[x]<rank[y]) swap(x,y);
    if(rank[x]==rank[y]) ++rank[x];
    par[y]=x;
    return true;
  }
};

int main(){
  int N,M;
  cin >> N >> M;
  unionfind uf(N);
  vector<int> p(N);
  rep(i,N){
    int a;
    cin >> a;
    a--;
    p[i]=a;
  }
  rep(i,M){
    int a,b;
    cin >> a >> b;
    a--; b--;
    uf.merge(a,b);
  }
  int ans=0;
  rep(i,N){
    if(uf.issame(i,p[i])) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int mxn = 1e7+1;
ll dp[mxn];
void solve(){
	int n;
	cin >> n;
	// ll dp[n+1];
	memset(dp,0ll,sizeof(dp));
	// dp[1] = 1;
	for(ll i =1;i<=n;i++){
		for(ll j = i;j<=n;j+=i)
			dp[j]++;
	}
	ll ans = 0;
	for(ll i =1;i<=n;i++){
		ans += (i*dp[i]);
		// cout << dp[i] << ' ' << endl;
	}
	cout << ans << endl;

}

int main(){
	fast;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 81772
def judge_aux(t, k):
    found=False
    for i in range(3):
        if t[i] == list(k*3):
            found=True
            break
    if found:
        return(k)

    found=False
    for j in range(3):
        if t[0][j]==t[1][j]==t[2][j]==k:
            found=True
            break
    if found:
        return(k)
        
    if t[0][0] == t[1][1]==t[2][2] == k:
        return(k)
        
    if t[0][2] == t[1][1]==t[2][0] == k:
        return(k)
    
def judge(t):
    if judge_aux(t,"o"):
        return("o")
    elif judge_aux(t,"x"):
        return("x")
    else:
        return("d")

while True:
    try:
        s = list(input().strip())
        t = [[s[3*i+j] for j in range(3)] for i in range(3)]
        print(judge(t))

    except EOFError:
        break

Measured memory_bytes: 7412
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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 namespace std;

int main(){
    Init();
    ll n; cin >> n;
    cout << (ll)((1+n)*(n/2.0)) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }
    
    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }
    
    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int gcd(int a, int b){
    while(b){
        int t = a;
        a = b;
        b = t%b;
    }
    return a;
}

int lcm(int a, int b){
    return a*b/gcd(a, b);
}


vector<ll> S;
vector<ll> P;

ll solve(ll i, ll k){
//    cout << i << " " << k << endl;
//    if(i==0){
//        if(k==0) return 0;
//        else return 1;
//    }
    if(k==1){
        if(i==0) return 1;
        else return 0;
    }
    else if(k<S[i-1]+2) return solve(i-1, k-1);
    else if(k==S[i-1]+2) return P[i-1] + 1;
    else if(k<=2 * S[i-1]+2) return P[i-1] + 1 + solve(i-1, k - S[i-1] - 2);
    return 2 * P[i-1] + 1;
}


int main() {
    ll N, K; cin >> N >> K;
    S.resize(N+1);
    P.resize(N+1);
    S[0] = 1;
    P[0] = 1;
    for(int i=0; i<N; i++){
        S[i+1] = 2 * S[i] + 3;
    }
    
    for(int i=0; i<N; i++){
        P[i+1] = 2 * P[i] + 1;
    }

    
    cout << solve(N, K) << endl;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main(){
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;
	int z = min(x,y);
	ll ans = 0;
	if(a+b >= 2*c) {
		ans += z*2*c;
		if(a>=2*c) ans += (x-z)*2*c;
		else ans += (x-z)*a;
		if(b>=2*c) ans += (y-z)*2*c;
		else ans += (y-z)*b;
    }
	else{
		ans += x*a + y*b;
	}
	cout << ans << endl;
	return;
}

int main(){
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,M = LI()
    g = [i for i in range(0,N+M+1)]
    g_num = [0] + [1 for _ in range(N)] + [0 for _ in range(M)]
    def find(x):
        if g[x] == x: return x
        g[x] = find(g[x])
        return g[x]

    def union(x,y):
        if find(x) == find(y): return
        g_num[g[x]] += g_num[g[y]]
        g_num[g[y]] = 0
        g[g[y]] = g[x]


    for i in range(1,N+1):
        for l in LI()[1:]: union(i,N+l)

    if g_num[N] == N:
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

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

int main(void) {
	int R;
	cin >> R;
	if (R < 1200) {
		cout << "ABC" << endl;
	}
	else if(R >= 1200 && R < 2800) {
		cout << "ARC" << endl;
	}
	else {
		cout << "AGC" << endl;
	}

}

Measured memory_bytes: 256
#include <iostream>
#include <string> 
using namespace std;
bool din(string s,char c){
	int i;
	for (i=0;i<s.size();i++)if (s[i]==c)return true;
	return false;
}
int main(){
	int i;
	string s;
	cin>>s;
	for (i=0;i<26;i++){
		char c=i+'a';
		if (!din(s,c)){
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
//#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
int main(){
	
	/*string s;
	int f=1,f1=1,co=0;
	cin>>s;
	/*char a='Z';
	cout<<(int)a<<endl;*/
	/*
	if(s[0]!='A')f=0;
	if(s[s.size()-1]=='C')f=0;
	for(int i=1;i<s.size();i++){
		if(65<=(int)s[i] && (int)s[i]<=90 && s[i]!='A' && s[i]!='C')f=0;
		if(s[i]=='C')co++;
		if(co!=1)f=0;
		cout<<f;
	}
	cout<<endl;
	if(f)cout<<"AC"<<endl;
	else cout<<"WA"<<endl;*/
	int a,b;
	cin>>a>>b;
	if((a*b)%2==0)cout<<"Even"<<endl;
	else cout<<"Odd"<<endl;
	
	
	
}

Measured memory_bytes: 256
(defun shift-only (n a)
  (let ((res 0)
        (exist-odd nil))
    (loop
       (dotimes (i n)
         (if (not (zerop (rem (aref a i) 2)))
             (setf exist-odd t)))
       (if (eq exist-odd t) (return))
       (dotimes (i n)
         (setf (aref a i) (/ (aref a i) 2)))
       (incf res))
    res))

(defun create-data ()
  (let* ((n (read))
         (a (make-array `(,n))))
    (dotimes (i n)
      (setf (aref a i) (read)))
    (values n a)))

(multiple-value-bind (n a) (create-data)
  (format t "~A~%" (shift-only n a)))

Measured memory_bytes: 6500
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int Q;
string S;
char T[214514];
char D[214514];

bool checkL(int x) {
  rep(i, Q) {
    if (S[x] == T[i]) {
      if (D[i] == 'L') --x;
      else if (D[i] == 'R') ++x;
      else assert(0);
    }

    if (x < 0) return true;
    if (x >= N) return false;
  }
  return false;
}

bool checkR(int x) {
  rep(i, Q) {
    if (S[x] == T[i]) {
      if (D[i] == 'L') --x;
      else if (D[i] == 'R') ++x;
      else assert(0);
    }

    if (x < 0) return false;
    if (x >= N) return true;
  }
  return false;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> Q;
  cin >> S;
  rep(i, Q) {
    cin >> T[i];
    cin >> D[i];
  }

  int ans = N;
  { 
    int low = -1;
    int high = N;
    while (high - low > 1) {
      int mid = (high+low)/2;
      if (checkL(mid)) low = mid;
      else high = mid;
    }
    ans -= low+1;
  }

  { 
    int low = -1;
    int high = N;
    while (high - low > 1) {
      int mid = (high+low)/2;
      if (checkR(mid)) high = mid;
      else low = mid;
    }
    ans -= N - high;
  }
  cout << ans << endl;

}


Measured memory_bytes: 1044
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <set>
#include <utility>
#include <cstdlib>
#include <queue>
#include <iomanip>
#include <cstdio>
#include <map>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    vector<vector<int>> graph(n, vector<int>());
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    queue<int> q;
    q.push(0);
    vector<bool> visited(n, false);
    visited[0] = true;
    vector<int> lvl(n,0);
    while(!q.empty()){
        int v = q.front();
        if(v == n-1){
            cout << "POSSIBLE";
            return 0;
        }
        q.pop();
        for(int u : graph[v]){
            if(!visited[u] && lvl[v] < 2){
                lvl[u] = lvl[v]+1;
                q.push(u);
                visited[u] = true;
            }
        }
    }

    cout << "IMPOSSIBLE" << endl;
    return 0;
}



Measured memory_bytes: 13168
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

# Written by NoKnowledgeGG @YlePhan

#import math
#mod = 10**9+7



def main():
  n = int(input())
  ma_ = 1
  while n != 1:
    p = n
    cnt = 0
    while p != 1:
      if p % 2 == 0:
        cnt += 1
        p //= 2
      else:
        p = 1
    ma_ = max(ma_,2**cnt)
    n -= 1
  print(ma_)
if __name__ == '__main__':
  main()

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

int main()
{
	int n,k,s=0,a[100005];
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		if(a[i]>=k) s++;
	cout<<s<<endl;
}

Measured memory_bytes: 640
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  ld n; // to input 
  ll a;
  ll b;

  scan = scanf("%Lf", &n);
  a = 0;
  while (1)
  {
    b = 0;
    while (b <= a)
    {
      if (pow((ld)a, 5) - pow((ld)b, 5) == n)
      {
        printf("%lld %lld", a, b);
        return (0);
      }
      if (pow((ld)a, 5) * (-1) - pow((ld)b, 5) == n)
      {
        printf("%lld %lld", a * (-1), b);
        return (0);
      }
      if (pow((ld)a, 5) - pow((ld)b, 5) * (-1) == n)
      {
        printf("%lld %lld", a, b * (-1));
        return (0);
      }
      if (pow((ld)a, 5) * (-1) - pow((ld)b, 5) * (-1) == n)
      {
        printf("%lld %lld", a * (-1), b * (-1));
        return (0);
      }
      b++;
    }
    a++;
  }
}


Measured memory_bytes: 2584
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
# import heapq
import decimal
# import statistics
import queue

# import numpy as np

sys.setrecursionlimit(10 ** 9)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    naf = lambda: list(map(float, sys.stdin.readline().split()))

    n = ni()
    p = naf()

    dp = [[0 for _ in range(n + 1)] for __ in range(n + 1)]
    dp[0][0] = 1

    # dp[i][j] : pのうちi個めまでを投げて、表がj個出る確率
    for i in range(n):
        for j in range(i+1):
            dp[i + 1][j + 1] += dp[i][j] * p[i]
            dp[i + 1][j] += dp[i][j] * (1 - p[i])

    print(sum(dp[n][(n + 1) // 2:]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 228592
local function getgcd(x, y)
  while 0 < x do
    x, y = y % x, x
  end
  return y
end
local n = io.read("*n")
local a = io.read("*n")
for i = 2, n do
  local b = io.read("*n")
  a = getgcd(a, b)
end
print(a)


Measured memory_bytes: 760
from heapq import heappush, heappop, heapreplace

n, m = map(int, input().split())
a = list(map(int, input().split()))
b_c = []
for _ in range(m):
    bc = tuple(map(int, input().split()))
    b_c.append(bc)
b_c.sort(key=lambda x: -x[1])
heap = []
for item in a:
    heappush(heap, item)
# print(f'a: {a}, heap: {heap}')
# print(heap)
# print(heappop(heap))
# print(heappop(heap))
# print(heappop(heap))

for b, c in b_c:
    if c <= heap[0]:
        break
    for i in range(b):
        if heap[0] < c:
            heapreplace(heap, c)
        else:
            break

# print(f'final_heap:{heap}, sum: {sum(heap)}')
print(sum(heap))
    

Measured memory_bytes: 25328
#include <iostream>
#include <sstream>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

typedef   signed long long int slli;
typedef unsigned long long int ulli;
const slli MAX_SLLI = 0x7FFFFFFFFFFFFFFF;
const slli MIN_SLLI = 0x8000000000000000;
const ulli MAX_ULLI = 0xFFFFFFFFFFFFFFFF;
const ulli MIN_ULLI = 0x0000000000000000;

#define N_TIMES(i, n)     for (ulli i = 0;     i <  n; ++i)
#define N_TIMES_REV(i, n) for (slli i = n - 1; i >= 0; --i)

#ifdef __DEBUG__
template<typename T>
std::ostream& operator<<(std::ostream &os, const std::list<T> &list)
{
  const std::string delim = ", ";
  typename std::list<T>::const_iterator itr = list.begin();
  while (itr != list.end()) {
    os << *itr;
    ++itr;
    if(itr != list.end()) os << delim;
  }
  return os;
}

template<typename T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v)
{
  const std::string delim = ", ";
  for (unsigned n = 0; n < v.size(); ++n) {
    os << v[n];
    if((n + 1) < v.size()) os << delim;
  }
  return os;
}
#endif

int main()
{
  unsigned N;
  std::cin >> N;
  
  std::vector<ulli> a(3 * N);
  N_TIMES (n, 3 * N) {
    std::cin >> a[n];
  }
  
  std::sort(a.begin(), a.end());
  // std::cerr << a << std::endl;
  
  ulli S = 0;
  
  N_TIMES (i, N) {
    S += a[(3 * N) - (2 * (i + 1))];
  }
  
  std::cout << S << std::endl;
  
  return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
int main()
{
   ios_base::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);

   string a;
   cin>>a;
   ll l=a.size();

   if(a[l-1]=='s')
   {
       cout<<a<<"es"<<endl;
   }
   else cout<<a<<"s"<<endl;

   return 0;
}


Measured memory_bytes: 3632
table = list(map(int,input().split()))

for i in range(2,0,-1):
    k=0
    while k<i:
        if table[k]>table[k+1]:
            table[k],table[k+1]=table[k+1],table[k]
        k+= 1;

print(table[0],table[1],table[2])


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

int main(){
    int a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b),x(q);
    rep(i,a) cin>>s[i];
    rep(i,b) cin>>t[i];
    rep(i,q) cin>>x[i];
    
    
    
    sort(ALL(s));
    sort(ALL(t));
    
    rep(i,q){
        
        int leftt,rightt,lefts,rights;
        
        auto Iter1 = lower_bound(ALL(s), x[i]);
        auto Iter2 = lower_bound(ALL(t), x[i]);
        
        
        rights=Iter1-s.begin();
        rightt=Iter2-t.begin();
        
        lefts=max(rights-1,0);
        leftt=max(rightt-1,0);
        
        ll ans=10000000000000;
        ll tmp=0;
        // l,r
        tmp+=abs(s[lefts]-t[rightt]);
        tmp+=min(abs(x[i]-s[lefts]),abs(x[i]-t[rightt]));
        
        ans=min(ans,tmp);
        //r,l
        tmp=abs(s[rights]-t[leftt]);
        tmp+=min(abs(x[i]-s[rights]),abs(x[i]-t[leftt]));
        
        ans=min(ans,tmp);
        
        //l,l
        tmp=abs(s[lefts]-t[leftt]);
        tmp+=min(abs(x[i]-s[lefts]),abs(x[i]-t[leftt]));
        
        ans=min(ans,tmp);
        
        //r,r
        tmp=abs(s[rights]-t[rightt]);
        tmp+=min(abs(x[i]-s[rights]),abs(x[i]-t[rightt]));
        
        ans=min(ans,tmp);
        
        cout<<ans<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 3712
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
H = LIST()

print(sum(sorted(H, reverse=True)[K:]))


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;

// macros
#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

// constants
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;

  map<ll, ll> factor;
  REP1(i, n+1){
    ll now = i;
    for(ll k = 2; k <= sqrt(i); k++){
      while(now%k==0){
        now /= k;
        factor[k] += 1;
      }
    }

    if(now != 1)
      factor[now] += 1;

  }

  vll fac3, fac5, fac15, fac25, fac75;
  REP1(i, n){
    ll now = factor[i];
    if(now >= 2)
      fac3.push_back(i);
    if(now >= 4)
      fac5.push_back(i);
    if(now >= 14)
      fac15.push_back(i);
    if(now >= 24)
      fac25.push_back(i);
    if(now >= 74)
      fac75.push_back(i);
  }

  ll ans = 0;
  //3*5*5
  REP(i, fac3.size()){
    REP(j, fac5.size()){
      for(ll k = j+1; k<fac5.size(); k++){
        if(fac3[i] == fac5[j] || fac3[i] == fac5[k])
          continue;
        ans++;
      }
    }
  }


  //3*25
  REP(i, fac3.size()){
    REP(j, fac25.size()){
      if(fac3[i] == fac25[j])
        continue;
      ans++;
    }
  }

  //5*15
  REP(i, fac5.size()){
    REP(j, fac15.size()){
      if(fac5[i] == fac15[j])
        continue;
      ans++;
    }
  }

  ans += fac75.size();

  cout << ans << endl;

}


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

int main() {
  while (true) {
    string s;
    cin >> s;
    if (s.at(0) - '0' == 0) {
      break;
    }
    int sum = 0;
    rep(i, s.size()) {
      sum += s.at(i) - '0';
    }
    cout << sum << endl;
  }
}



Measured memory_bytes: 3176
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        Console.WriteLine(Solve());
        //Solve();
        return;
    }

    public static string Solve()
    {
        long N = ReadLong();
        return ((1 + N) * N / 2 - (N / 3 + 1) * (N / 3) / 2 * 3 - (N / 5 + 1) * (N / 5) / 2 * 5 + (N / 15 + 1) * (N / 15) / 2 * 15).ToString();
    }

    private static string Read() { return Console.ReadLine(); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
}


Measured memory_bytes: 17648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		final int K = Integer.parseInt(sc.next());
		final int X = Integer.parseInt(sc.next());
		int start  = X - K + 1;
		int end =  X + K - 1;
		for(int i = start; i < end; i++) {
			System.out.print(i);
			System.out.print(' ');
		}
		System.out.println(end);

	}

}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;

int n;
ll a[500][500];
ll rsum[500][500];
ll dp[500][500];
ll range[500][500];
ll rev[501][500];
ll revs[501][500];

void init() {
    rep(i,n) {
        for (int j = i+1; j < n; j++) {
            rsum[i][j] = rsum[i][j-1] + a[i][j];
        }
    }
    for (int i = n-1; i >= 0; i--) {
        for (int j = 0; j < i; j++) {
            rev[i][j] = rev[i+1][j] + a[i][j];
        }
    }
    rep(i,n) {
        rep(j,n) {
            if (j == 0) revs[i][j] = rev[i][j];
            else revs[i][j] = rev[i][j] + revs[i][j-1];
        }
    }
    rep(i,n) {
        for (int j = i+1; j < n; j++) {
            for (int k = i; k < j; k++) {
                range[i][j] += rsum[k][j-1];
            }
        }
    }
}

int main() {
    cin >> n;
    rep(i,n) rep(j,n) {
        if (i == j) continue;
        cin >> a[i][j];
    }
    init();
    rep(i,n) rep(j,n) dp[i][j] = linf;
    dp[0][0] = 0;
    rep(i,n) {
        for (int j = i; j < n; j++) {
            for (int k = j+1; k < n; k++) {
                /*
                ll cnt = 0;
                for (int u = j; u < k; u++) {
                    cnt += rsum[u][k-1];
                    for (int v = u+1; v < k; v++) {
                        cnt += a[u][v];
                    }
                }
                */
                ll cnt = range[j][k];
                /*
                for (int u = k; u < n; u++) {
                    for (int v = i; v < j; v++) {
                        cnt += a[u][v];
                    }
                }
                */
                /*
                for (int v = i; v < j; v++) {
                    cnt += rev[k][v];
                }
                */
                if (j > 0) cnt += revs[k][j-1]-(i==0?0:revs[k][i-1]);
                dp[k][j] = min(dp[k][j], dp[j][i] + cnt);
            }
        }
    }
    ll ans = linf;
    rep(i,n) {
        for (int j = i+1; j < n; j++) {
            ll cnt = 0;
            for (int k = j; k < n; k++) {
                cnt += rsum[k][n-1];
                /*
                for (int l = k+1; l < n; l++) {
                    cnt += a[k][l];
                }
                */
            }
            ans = min(ans, dp[j][i]+cnt);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 11904
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>








const int N=1e5+10;
ll n,m,x,c[N],c2[N],mn,mx,res;






void solve()
{
	cin>>n>>m;
	for(int i=0;i<=m;i++)c[i]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>x;
		c[x%m]++;
		c2[x]++;
	}
	res=(c[0]/2);
	if(m%2==0)res+=c[m/2]/2;
	for(int i=1,j=m-1;i*2<m;i++,j--)
	{
		mn=min(c[i],c[j]);
		res+=mn;
		c[i]-=mn;
		c[j]-=mn;
	}
	for(int i=1;i+4<N;i++)
	{
		if(i%m==0||(i%m)*2==m)continue;
		mn=min(c[i%m]/2,c2[i]/2);
		res+=mn;
		c[i%m]-=mn*2;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

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

int main() {
    int a, b, c;
    int t[5];
    int f;
    int ans = 0;
    
    cin >> a >> b;
    
    for (int i = a; i <= b; i++) {
        c = i;
        f = true;
        
        for (int ii = 0; ii < 5; ii++) {
            t[ii] = c % 10;
            c /= 10;
        }
        
        for (int ii = 0; ii < 2; ii++) {
            if (t[ii] != t[4 - ii]) {
                f = false;
                break;
            }
        }
        
        if (f) {
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

ll patties(int l) {
	return l == 0 ? 1 : 2 * patties(l - 1) + 1;
}

ll layers(int l) {
	return l == 0 ? 1 : 2 * layers(l - 1) + 3;
}

ll patties(int l, ll i) {
	if(l == 0)
		return i == 1;
	if(i >= layers(l) - l)
		return patties(l);
	ll ans = 0;
	if(i >= layers(l - 1) + 1) {
		ans += patties(l - 1);
		if(i >= layers(l - 1) + 2) {
			ans++;
			if(i > layers(l - 1) + 2)
				ans += patties(l - 1, i - layers(l - 1) - 2);
		}
	}
	else {
		ans += patties(l - 1, i - 1);
	}
	return ans;
}

int main() {
	int N;
	ll X;
	cin >> N >> X;
	cout << patties(N, X) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define int long long
#define Mod 1000000007ll
#define pow ksm
inline int ksm(int a,int x){
	LL ans=1,w=a;
	while(x){
		if(x&1)ans=ans*w%Mod;
		x>>=1;
		w=w*w%Mod;
	}
	return ans;
}
#define MN 4000005
#define mn 2005
int fac[MN],dfac[MN],n,k,f[mn][mn];
inline int C(int n,int m){
	return 1ll*fac[m]*dfac[n]%Mod*dfac[m-n]%Mod;
}
void init(int N){
	fac[0]=1;
	for(int i=1;i<=N;++i)
		fac[i]=fac[i-1]*i%Mod;
	dfac[N]=ksm(fac[N],Mod-2);
	for(int i=N-1;i>=0;--i){
		dfac[i]=(LL)dfac[i+1]*(LL)(i+1)%Mod;
	}
}
signed main(){
	scanf("%lld%lld",&n,&k);
	if(k==1){
		puts("1");
		return 0;
	}
	init(n*k);
	f[0][0]=1;
	for(int i=1;i<=n;++i)
		for(int j=0;j<=i;++j){
			f[i][j]=(f[i][j]+f[i-1][j])%Mod;
			if(j)f[i][j]=(f[i][j]+(f[i][j-1]*(n-j+1)%Mod*C(k-2,n-i+(k-1ll)*(n-j+1ll)-1ll)+Mod))%Mod;	
			//tm这式子谁顶得住啊
			//n-j+1: 有这么多种颜色可以这次放
			//k-2:放k-2个，为了不重，钦定第一个放剩下的第一个没填的格子
			//n-i+(k-1)*(n-j+1)-1：还剩下的格子数，-1的理由同上
		}
	printf("%lld",f[n][n]);
	return 0;
}


Measured memory_bytes: 92672
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
n=int(input())
a=list(map(int,input().split()))
b_d=[[0,0] for _ in range(n+1)]
b_u=[[0,0] for _ in range(n+1)]
b_d[n]=[a[n],a[n]]
b_u[0]=[1,1]
for i in range(1,n+1):
    l=(1+b_d[n+1-i][0])//2+a[n-i]
    r=(b_d[n+1-i][1])+a[n-i]
    if l>r:
        print(-1)
        exit()
        break
    b_d[n-i]=[l,r]
    l=max(0,b_u[i-1][0]-a[i-1])
    r=2*(b_u[i-1][1]-a[i-1])
    if l>r:
        print(-1)
        exit()
        break
    b_u[i]=[l,r]
ans=0

for i in range(n+1):
    if b_d[i][0]>b_u[i][1] or b_u[i][0]>b_d[i][1]:
        print(-1)
        exit()
    else:
        ans+=min(b_u[i][1],b_d[i][1])
print(ans)

Measured memory_bytes: 699260
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::{i32, i64, i128, u32, u64, u128, f64};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
#[allow(unused_imports)]
use proconio::marker::{Isize1, Usize1, Bytes, Chars};

#[proconio::fastout]
fn main() {
    proconio::input!{
        a: i32,
        b: i32,
    }
    println!("{}", a * b)
}


Measured memory_bytes: 2200
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1000000007, INF = 1e9;

int main()
{
    priority_queue<int> q;
    rep(i, 3){
        int a; cin >> a;
        q.push(a);
    }
    int k;
    cin >> k;
    rep(i, k){
        int a = q.top();
        q.pop();
        a *= 2;
        q.push(a);
    }
    int ans = 0;
    rep(i, 3){
        ans += q.top();
        q.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, a, b, ans = 0;
  scanf("%lld%lld", &a, &b);
  if(a + b == 15) printf("+");
  else if(a * b == 15) printf("*");
  else printf("x");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
using namespace std;
#define INF	100000000
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define sz(x) ((int)(x).size())
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef pair<int, int> P;
typedef long long int ll;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<int> PQ;

int main(){
	long double xa, ya, xb, yb, xc, yc, xd, yd;
	while(cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd){
		if(xb == xa && yd == yc) cout << "YES" << endl;
		else if(yb == ya && xd == xc) cout << "YES" << endl;
		else if(xb == xa || xd == xc) cout << "NO" << endl;
		else if((yb-ya)*(yd-yc)/(xb-xa)/(xd-xc) == -1) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1220
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();
    if (a >= 3200) {
      System.out.println(s);
    } else {
      System.out.println("red"); 
    }
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	string n; cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') {
		puts("Yes");
	}
	else puts("No");
	return 0;
}


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

int X, N;
int P[110];
int L;
int M;

int ans;

main(){

    cin >> X >> N;

    if (N == 0) {
        ans = X;
    } else {
        for (int i = 1;i <= N ;i++) cin >> P[i];

        int PE[102] = {0};
        for (int i = 1; i <= N; i++) PE[P[i]] = 1;

        L = X;
        M = X;
        while (PE[L] == 1 && PE[M] == 1) {
            L--;
            M++;
        }
        if (PE[L] == 1){
            ans = M;
        } else {
            ans = L;
        }
    }

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

Measured memory_bytes: 3620
from itertools import permutations, accumulate, combinations, combinations_with_replacement
import sys
input = sys.stdin.readline


def main():
    n, m, q = map(int, input().split())
    # <方針>：Aを全列挙する
    ans = 0
    a = [0] * q
    b = [0] * q
    c = [0] * q
    d = [0] * q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
        a[i] -= 1
        b[i] -= 1
    for A in combinations_with_replacement(range(1, m + 1), n):
        tmp = 0
        for i in range(q):
            if A[b[i]] - A[a[i]] == c[i]:
                tmp += d[i]
        ans = max(ans, tmp)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 9148
#include<cstdio>
#include<algorithm>
#include<set>
#include<cmath>
using namespace std;
int a,f[200001],t;
long long ans;
int main()
{
	int n,l,r,m;
	scanf("%d",&n);
	ans=n;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a);
		f[i]=f[i-1]^a;
		if (i==1) continue;
		if (a&(f[i-1]^f[i-2])) t=0;
		else
		{
			l=1; r=t+2;
			while (l+1<r)
			{
				m=(l+r)>>1;
				if ((f[i-1]^f[i-m-1])&a) r=m;
				else l=m;
			}
			t=l;
			ans+=t;
		}
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 896
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            c[i] = Integer.parseInt(stdin.readLine());
        }

        Deque<Integer> b = new ArrayDeque<>();
        b.addLast(c[0]);
        for (int i = 1; i < n; i++) {
            if (b.getLast() != c[i]) {
                b.addLast(c[i]);
            }
        }


        long mod = 1000000000 + 7;
        Map<Integer, Long> sm = new HashMap<>();
        long[] dp = new long[b.size() + 1];
        dp[0] = 1;
        for (int i = 0; i < dp.length - 1; i++) {
            int v = b.removeFirst();
            dp[i + 1] += dp[i] + sm.getOrDefault(v, 0L);
            dp[i + 1] %= mod;
            sm.put(v, sm.getOrDefault(v, 0L) + dp[i]);
        }

        stdout.println(dp[dp.length - 1]);
    }


    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


Measured memory_bytes: 56444
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> red = vector<int>(max(X, A), 0);
    vector<int> green = vector<int>(max(X, B), 0);
    vector<int> white = vector<int>(C, 0);
    for (int i = 0; i < A; i++) {
        cin >> red[i];
    }
    for (int i = 0; i < B; i++) {
        cin >> green[i];
    }
    for (int i = 0; i < C; i++) {
        cin >> white[i];
    }
    vector<int> needReplace = vector<int>();
    
    sort(red.begin(), red.end());
    sort(green.begin(), green.end());
    sort(white.begin(), white.end());
    
    int idxA = max(X, A) - X;
    int maxA = max(X, A);
    int idxB = max(Y, B) - Y;
    int maxB = max(X, B);
    int idxC = C - 1;
    
    long long sum = 0;
    for (int i = idxC; i >= 0; i--) {
//        cout << red[idxA] << ", " << green[idxB] << ", " << white[i] << endl;
        if (idxA < maxA && idxB < maxB) {
            if (red[idxA] < green[idxB]) {
                if (red[idxA] > white[i]) {
                    break;
                } else {
                    sum += white[i];
                    idxA++;
                }
            } else {
                if (green[idxB] > white[i]) {
                    break;
                } else {
                    sum += white[i];
                    idxB++;
                }
            }
        } else if (idxA < maxA) {
            if (red[idxA] > white[i]) {
                break;
            } else {
                sum += white[i];
                idxA++;
            }
        } else if (idxB < maxB) {
            if (green[idxB] > white[i]) {
                break;
            } else {
                sum += white[i];
                idxB++;
            }
        }
    }
    for (int i = idxA; i < maxA; i++) {
        sum += red[i];
    }
    for (int i = idxB; i < maxB; i++) {
        sum += green[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main()
{
	int a, b, c, d;
	cin >> a >> b >> c >> d;

	if (a + b > c + d) ANS("Left");
	else if (a + b < c + d) ANS("Right");
	else ANS("Balanced");
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;

int main()
{
    ll n,k;cin >>n>>k;
    V l(n,0);
    ll ans=0;
    rep(i,k){
        ll d;cin >>d;
        rep(j,d){
        ll a;
         cin >>a;
         a--;
         l[a]++;
        }
    }
    rep(i,n){
        if(l[i]==0)ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define boost std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

using namespace std;
using LL = long long;

constexpr int MAXN = 505;
constexpr LL M = 998244353;

template <typename T> inline void read(T &x) {
    int f = 1; x = 0;
    char ch = getchar();
    while (!isdigit(ch)) f = (ch == '-') ? -1 : 1, ch = getchar();
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}


int main() {
    boost;
    LL n, k;
    cin >> n >> k;
    n = min(n % k, (-n) % k + k);
    cout << n << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var A = cin.ReadInt;
            var B = cin.ReadInt;

            WriteLine(A*B);
            
        }

        public void Display(int[] array)
        {
            var txt = "";
            foreach (var item in array)
            {
                txt += " " + item.ToString();
            }
            WriteLine("{0}", txt);
        }

        public void Display(int index,int[] array)
        {
            var txt = "";
            foreach (var item in array)
            {
                txt += " " + item.ToString();
            }
            WriteLine("{0} : {1}", index,txt);
        }

        public void Display(List<int>[] list) 
        {
            for (int i = 0; i < list.Length; i++)
            {
                Display(i, list[i].ToArray());
            }
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 27884
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
#include <deque>
using namespace std;
typedef long long ll;

const ll MOD = 1e9+7;

deque<ll> ans;

int main()
{
	ll m,k;
	ll num[2];
	cin>>m>>k;
	if(k>=(1<<m))
	{
		cout<<-1<<endl;
		return 0;
	}
	if(k==1 && m==1)
	{
		cout<<-1<<endl;
		return 0;
	}
	ans.push_front(k);
	ans.push_back(0LL);
	for(ll i=1;i<(1<<m);i++)
	{
		if(i==k)
			continue;
		ans.push_front(i);
		ans.push_back(i);
	}

	//余ったやつ
	if(k!=0)
	{
		ans.push_front(k);
		ans.push_back(0LL);
	}

	for(int i=0;i<ans.size();i++)
		cout<<ans[i]<<" ";
	cout<<endl;
	return 0;
}

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

#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

#define MAXX 100005


#define PI 3.14159265358979323846264338327950

#define ll   long long int
ll mod = 1000000007;
ll a[MAXX], b[MAXX];
char str[MAXX];

int main()
{
	FAST;
	ll n, k;
	cin >> n;
	ll ans = 0;
	for(ll i = 1; i<= n; i++){
		cin >> k;
		a[k] ++;
		ans += k;
	}
	ll t;
	cin >> t;
	while(t --){
		ll b , c;
		cin >> b >> c;
		ll d = c - b;
		ans += (a[b] * d);
		a[c] += a[b];
		a[b] = 0;
		cout << ans << endl;;
	}


}


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

int N, K, m=1e9;

void func(int sum, int depth){
    if(depth==N){
        if(sum<m) m=sum;
        return;
    }
    func(sum*2, depth+1);
    func(sum+K, depth+1);
}

int main(){
    cin >> N >> K;
    /*
    int sum=1;
    for(int i=0; i<N; i++){
        sum=1;
        for(int j=0; j<i; j++){
            sum *= 2;
        }
        for(int j=i; j<N; j++){
            sum += K;
        }
        cout << sum << endl;
        if(sum<m) m=sum;
    }
     */
    
    func(1, 0);
    
    cout << m << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

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

    int A[n];
    int B[n];
    int C[n - 1];
    int count = 0;
    for(int i = 0; i < n; i++){
        scanf("%d", &A[i]);
        /* printf("A_%d = %d\n", i, A[i]); */
        }
    for(int i  = 0; i < n; i++){
        scanf("%d", &B[i]);
        /* printf("B_%d = %d\n", i, B[i]); */
        }

    for(int i = 0; i < n - 1; i++){
        scanf("%d", &C[i]);
        /* printf("C_%d = %d\n", i, C[i]); */
        }
    for(int j=0 ; j < n ; j++){
        count += B[j];
        /* printf("add B_%d = %d\n", j, B[j]); */
        if(A[j] == A[j+1] - 1){
            index=A[j];
            count += C[index - 1];
            /* printf("add C_%d = %d\n", index - 1, C[index -1]); */
        }
        /* printf("coun = %d\n", count); */
    }
    printf("%d", count);
}


Measured memory_bytes: 128