akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


int main()
{
  string s; cin >> s;
  string ans;
  for(auto c : s) {
    if(c == 'B') {
      if(!ans.empty()) ans.pop_back();
    }
    else ans += c;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n; cin >> n;
    int d[n];
    rep(i,n) cin >> d[i];
    ll ans = 0;
    rep(i,n){
        for(int j=i+1;j<n;j++){
            ans += d[i]*d[j];
        }
    }
    cout << ans << endl;
}



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

#define int long long
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; }

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

	int tmp = n/200; 
	cout << 10-tmp << endl; 

	return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long all = (1 + n) * n / 2;
        long n3 = n / 3;
        long all3 = (3 + 3 * n3) * n3 / 2;
        long n5 = n / 5;
        long all5 = (5 + 5 * n5) * n5 / 2;
        long n15 = n / 15;
        long all15 = (15 + 15 * n15) * n15 / 2;
        long sum = all - all3 - all5 + all15;
        System.out.println(sum);
    }
}

Measured memory_bytes: 35776
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,m; 
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
signed main(){
	int h1,h2,s1,s2,k;
	cin>>h1>>s1>>h2>>s2>>k;
	int cnt=(h2-h1)*60+s2-s1-k;
	if(cnt<=0)
	   cout<<0<<endl;
	else 
	  cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<vector<ll>> Matrix;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a, b);}

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

  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = max(a*b, max(a+b, a-b));
  cout << ans << endl;
  return 0;
}


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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    double n,k;cin>>n>>k;

    vector<double> dp(max(2*k+3, n+5), 1);
    rep(i, k){
        dp[i] = 0;
    }
    rrep(i, 1, k){
        dp[i] = dp[2*i]/2;
    }

    double ans = 0;
    rep(i, 1, n+1){
        ans += dp[i];
    }
    printf("%.12f", ans/n);
    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

template<long long mod>
class modint{
private:
  long long num;
  long long extgcd(long long a, long long b, long long&x, long long&y)const {
    long long d = a;
    if(b != 0){d = extgcd(b, a%b, y, x);  y -= (a/b) * x;}
    else{x = 1; y = 0;}
    return d;
  }
  long long modinverse()const{
    long long x, y;
    extgcd(num, mod, x, y);
    return (mod + x%mod)%mod;
  }
public:
  modint():num(0){}
  modint(const long long x):num((x < 0?(x+mod):x)%mod ){}
  friend modint operator+(const modint&a, const modint&b)
  {    return modint(a.num + b.num);  }
  friend modint operator-(const modint&a, const modint&b)
  {    return modint(a.num - b.num);  }
  friend modint operator*(const modint&a, const modint&b)
  {    return modint(a.num * b.num);  }
  friend modint operator/(const modint&a, const modint&b)
  {    return modint(a*b.modinverse());  }
  modint& operator+=(const modint&b)
  {    return (*this) = (*this) + b;  }
  modint& operator-=(const modint&b)
  {    return (*this) = (*this) - b;  }
  modint& operator*=(const modint&b)
  {    return (*this) = (*this) * b;  }
  modint& operator/=(const modint&b)
  {    return (*this) = (*this) / b;  }
  modint& operator++()
  {    (*this)+=1; return (*this);  }
  modint& operator--()
  {    (*this)-=1; return (*this);  }
  modint operator++(int){
    modint tmp(*this);
    ++(*this);
    return tmp;
  }
  modint operator--(int){
    modint tmp(*this);
    --(*this);
    return tmp;
  }    
  modint pow(unsigned long long i){
    if(i == 0) return 1;
    if(i & 1){
      return (*this) * (this->pow(i-1));
    }
    modint<mod>hpow = (this->pow(i>>1));
    return hpow * hpow;
  }
  friend ostream& operator<<(ostream&os, const modint&a){
    os << a.num;
    return os;
  }
  friend istream& operator>>(istream&is, modint&a){
    long long x; is >> x;
    a = x;
    return is;
  }
};

using mint = modint<1000000007>;

int main(){
  int n; cin >> n;
  string s1,s2;cin >> s1 >> s2;
  vector<bool> v;
  for(int i = 0; i < n; ++i){
    v.push_back(s1[i] == s2[i]);
    i += (s1[i] != s2[i]);
  }
  mint ans = v[0] ? 3 : 6;
  for(int i = 1; i < (int)v.size(); ++i){
    if(v[i-1]){
      ans *= 2;
    } else if(!v[i]){
      ans *= 3;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3584
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        StringBuilder sb = new StringBuilder();
        sb.append(2);
        sb.append(" ");
        sb.append(7);
        sb.append(" ");
        int count=3;
        int cur = 17;
        while(count<=N){
            if(isPrime(cur)){
                sb.append(cur);
                sb.append(" ");
                count++;
            }
            cur += 10;
        }
        System.out.print(sb.toString());
    }
    public static boolean isPrime(int t){
        for (int i=2; i <= t/2+1; i++) {
            if (t % i == 0) {
                return false;
            }
        }
        return true;
    }
}

Measured memory_bytes: 20564
def solve():
    MOD = 10**9 + 7
    INF = 10**10

    N, K = map(int, input().split())
    As = list(map(int, input().split()))

    if K == N:
        ans = 1
        for A in As:
            ans *= A
            ans %= MOD
        print(ans)
        return

    As.sort(key=lambda x: abs(x))

    if max(As) < 0 and K%2 != 0:
        ans = 1
        for A in As[:K]:
            ans *= A
            ans %= MOD
        print(ans)
        return

    As.reverse()

    ans = 1
    sgn = 1
    for A in As[:K]:
        ans *= A
        ans %= MOD
        if A < 0:
            sgn *= -1
        elif A == 0:
            sgn = 0

    if sgn >= 0:
        print(ans)
        return

    maxNeg, maxNotNeg = -INF, -INF
    minNeg, minPos = INF, INF
    for A in As[:K]:
        if A < 0:
            maxNeg = max(maxNeg, A)
        if A > 0:
            minPos = min(minPos, A)
    for A in As[K:]:
        if A < 0:
            minNeg = min(minNeg, A)
        if A >= 0:
            maxNotNeg = max(maxNotNeg, A)

    if maxNeg == -INF or maxNotNeg == -INF:
        ans *= pow(minPos, MOD-2, MOD) * minNeg
        ans %= MOD
    elif minNeg == INF or minPos == INF:
        ans *= pow(maxNeg, MOD-2, MOD) * maxNotNeg
        ans %= MOD
    else:
        if abs(maxNeg)*abs(minNeg) >= abs(minPos)*abs(maxNotNeg):
            ans *= pow(minPos, MOD-2, MOD) * minNeg
            ans %= MOD
        else:
            ans *= pow(maxNeg, MOD-2, MOD) * maxNotNeg
            ans %= MOD

    print(ans)


solve()


Measured memory_bytes: 32048
#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,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
   int n, k;
   cin >> n >> k;
   vector<int>v(n);
   rep(i, 0, n)cin >> v[i];
   sort(v.begin(),v.end());
   int ans = 0;
   rep(i, 0, k)ans += v[i];
   cout << ans << endl;
}

Measured memory_bytes: 3596
#include <iostream>

int main(){
  int n;
  std::cin >> n;

  int digit_odd = 0;
  
  if(n < 10) digit_odd = n;
  else if(n < 100) digit_odd = 9;
  else if(n < 1000) digit_odd = 9 + (n - 99);
  else if(n < 10000) digit_odd = 9 + (999 - 99); 
  else if(n == 100000) digit_odd = 9 + (999 - 99) + (99999 - 9999);
  else digit_odd = 9 + (999-99) + (n - 9999);
  

  std::cout << digit_odd << std::endl;

  return 0;
}


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


int main(){
    int n;
    cin >> n;
    
    long long ans = 0;
    for(int k = 1; k <= n; k++){
        ans += (double(k)/2)*floor(n/k)*floor(1 + n/k);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, Q;
	cin >> N >> Q;
	ll black = (ll)(N - 2) * (N - 2);
	
	vector<int> row(N, N - 1), col(N, N - 1);
	int rowmin = N - 1, colmin = N - 1;
	while (Q--) {
		int q, x;
		scanf("%d %d", &q, &x); --x;
		if (q == 1) {
			// col x
			if (colmin > x) {
				FOR(i, x, colmin) col[i] = col[colmin];
				row[col[x]] = x;
				colmin = x;
			}
			black -= col[x] - 1;
		}
		else {
			// row x
			if (rowmin > x) {
				FOR(i, x, rowmin) row[i] = row[rowmin];
				col[row[x]] = x;
				rowmin = x;
			}
			black -= row[x] - 1;
		}
	}
	
	cout << black << endl;
	return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x, y, z) max((x), max((y), (z)))
#define tmin(x, y, z) min((x), min((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
template<class T> inline bool chmin(T& a, T b){ if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b){ if(a < b){ a = b; return true;} return false;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
using Graph = vector<vector<ll>>;
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);


struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n, -1){ }
    void init(int n){ par.assign(n, -1); }

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool unite(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};


int main() {
    ll n, k, l;
    cin >> n >> k >> l;
    UnionFind road(n), train(n);
    rep(i, k){
        ll p, q;
        cin >> p >> q;
        p--, q--;
        road.unite(p, q);
    }
    rep(i, l){
        ll r, s;
        cin >> r >> s;
        r--, s--;
        train.unite(r, s);
    }

    vector<pair<ll, ll>> v(n);
    map<pair<ll, ll>, ll> mp;
    rep(i, n){
        v[i] = make_pair(road.root(i), train.root(i));
        mp[v[i]]++;
    }
    rep(i, n){
        cout << mp[v[i]] << ' ';
    }
    cout << endl;
}


Measured memory_bytes: 19364
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n;
    ll k;
    cin >> n >> k;
    ll a[n];
    REP(i,n){
        cin >> a[i];
        a[i]--;
    }
    ll sum[n + 1] = {};
    REP(i,n){
        sum[i + 1] = (sum[i] + a[i]) % k;
    }
    ll right = 0;
    ll ans = 0;
    map<ll, ll> mp;
    for(ll left = 0; left < n; left++){
        while(right - left < k && right <= n){
            ans += mp[sum[right]];
            mp[sum[right]]++;
            right++;
        }
        mp[sum[left]]--;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15872
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N = ii()

print((N-1)//2)

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
const int MOD = 1000000007;

int main(){
  string s;
  cin >> s;
  vector<int> len;
  char curr = 'R';
  int count = 1;
  for(int i=1;i<s.length();i++){
    if(curr == s[i]) count++;
    else{
      len.push_back(count);
      count = 1;
      curr = s[i];
    } 
  }
  len.push_back(count);
  int sum = 0;
  for(int i=0;i<len.size()/2;i++){
    for(int j=0;j<len[i*2]-1;j++) cout << "0 ";
    if((len[i*2]+len[i*2+1])%2 == 0){
      cout << (len[i*2]+len[i*2+1])/2 << " ";
      cout << (len[i*2]+len[i*2+1])/2 << " ";
    }else{
      if(max(len[i*2],len[i*2+1])%2 == 1){
        if(len[i*2] > len[i*2+1]){
          cout << (len[i*2]+len[i*2+1])/2+1 << " ";
          cout << (len[i*2]+len[i*2+1])/2 << " ";
        }else{
          cout << (len[i*2]+len[i*2+1])/2 << " ";
          cout << (len[i*2]+len[i*2+1])/2+1 << " ";
        }
      }else{ 
        if(len[i*2] > len[i*2+1]){
          cout << (len[i*2]+len[i*2+1])/2 << " ";
          cout << (len[i*2]+len[i*2+1])/2+1 << " ";
        }else{
          cout << (len[i*2]+len[i*2+1])/2+1 << " ";
          cout << (len[i*2]+len[i*2+1])/2 << " ";
        }
      }
    }
    for(int j=0;j<len[i*2+1]-1;j++) cout << "0 ";
  }
}


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

int main (){
    int n;
    int sum = 0;
    int a[20] = {};
    int b[20] = {};
    int c[20] = {};

    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    rep(i,n){
        cin >> b[i];
    }
    rep(i,n-1){
        cin >> c[i];
    }

    rep(i,n){
        sum = sum + b[a[i]-1];
        //cout << sum << endl;
        if(a[i] == a[i-1] + 1){
            sum += c[a[i]-2];
        }
    }

    cout << sum << endl;

}

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

int main() {
  int N;
  cin >> N;

  int cnt=1410065407;
  rep(i, N){
    int A;
    cin >> A;

    int tmp=0;
    while(A%2==0){
      A /= 2;
      tmp++;
    }
    cnt = min(cnt, tmp);
  }

  cout << cnt << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll W,H,x,y;
  cin>>W>>H>>x>>y;
  long double ans1=W/2.0*H;
  int ans2=0;
  if(2*x==W && 2*y==H)ans2=1;
  cout<<setprecision(12)<<ans1<<" "<<ans2<<endl;
}


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

const int N = 1e6 + 5;

#define st first
#define nd second
#define make(a,b) make_pair(a,b)

typedef pair<int,int> pun;
typedef long long ll;

vector<int> colors;

int res[5000][5000];

int main() {
	int w, h, k;
	scanf("%d%d%d", &w, &h, &k);
	colors.push_back(0);
	for (int i = 0; i < k; i ++) {
		int a;
		scanf("%d", &a);
		colors.push_back(a);
	}
	int wsk = 1;
	for (int i = 0; i < w; i ++) {
		if (i % 2 == 0) {
			for (int j = 0; j < h; j ++) {
				res[i][j] = wsk;
				colors[wsk] --;
				if (colors[wsk] == 0) wsk ++;
			}
		} else {
			for (int j = h-1; j >= 0; j --) {
				res[i][j] = wsk;
				colors[wsk] --;
				if (colors[wsk] == 0) wsk ++;
			}
		}
	}
	for (int i = 0; i < w; i ++) {
		for (int j = 0; j < h; j ++) {
			printf("%d ", res[i][j]);
		}
		printf("\n");
	}
}


Measured memory_bytes: 768
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]
    K,X = LMIIS()
    if K*500 >= X:
        print('Yes')
    else:
        print('No')




if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
// 20
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define forr(_, x, n) for (int _ = x; _ > n; _--)
#define fos(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fos(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;

int sign(li x) { return x < 0 ? -1 : x > 0; }
// a / b
li ceil(li a, li b) {
  if (sign(a) == sign(b) && a % b)
    return a / b + 1;
  else
    return a / b;
}

li floor(li a, li b) {
  if (sign(a) != sign(b) && a % b)
    return a / b - 1;
  else
    return a / b;
}

// 12
void _main(int tc) {
  li a, b, x;
  cin >> a >> b >> x;
  li l = x * ceil(a, x);
  li r = x * floor(b, x);
  cout << ceil((r - (l - 1)), x) << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0);
  return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public static void Main(){
        var N = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var b = a.Clone() as int[];
        
        Array.Sort(b);
        for(var i = 0;i < N;i++){
            if(a[i] < b[N / 2]){
                Console.WriteLine(b[N / 2]);
            }else{
                Console.WriteLine(b[N / 2 - 1]);
            }
        }
        
    }
}


Measured memory_bytes: 36188
n = gets.to_i
arr = gets.to_s.split(' ').map(&:to_i)

bool = 'Yes'

if arr.size == 2
  if arr[0] <= arr[1]
    puts 'Yes'
  else
    puts 'No'
  end
else
  i = 1
  while i < n
    prev = arr[i - 1]
    now = arr[i]

    bool = 'No' if prev - 1 > now

    # 4 3 3 3 2 みたいなパターンの検出
    while now == arr[i + 1]
      i += 1
    end

    if prev - 1 == now && now - 1 == arr[i + 1]
      bool = 'No' if (prev - arr[i + 1] == 2)
    end
    i += 1
  end
  puts bool
end


Measured memory_bytes: 11012
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define SZ size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define S second
#define ld long double
#define eps 0.00000000001
#define MAX 1000000007
#define vll vector <ll> 
#define pll pair <ll,ll> 

using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ll powc(ll a, ll b){
    if(b<0){
        return -1;
    }
    ll res=1;
    while(b>0){
        if(b&1){
            res*=a;
        }
        a*=a;
        //res%=m9, a%=m9;
        b>>=1;
    }
    return res;
}



///target expert

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector <ll> sieve(1e6+10,1);
    for(ll i=2; i*i<1e6+10; ++i){
        if(sieve[i]==1){
            sieve[i]=i;
            for(ll j=i*i; j<1e6+10; j+=i ){
                if(sieve[j]==1){
                    sieve[j]=i;
                }
            }
        }
    }
    for(ll i=2; i<1e6+10; ++i){
        if(sieve[i]==1){
            sieve[i]=i;
        }
    }
    ll n; cin>>n;
    vector <ll> v(n);
    REP(i,0,n){
        cin>>v[i];
    }
    map <ll,ll> mp;
    REP(i,0,n){
        ll temp= v[i]; ll prev=-1;
        while(sieve[temp]!=1){
            if(sieve[temp]==prev){
                temp/=sieve[temp];
            }else{
                mp[sieve[temp]]++;
                prev= sieve[temp];
                temp/=sieve[temp];
            }
        }
        
    }
    bool pr=1, st=1;
    REP(i,2,1e6+1){
        if(mp[i]>1){
            pr=0;
        }
        if(mp[i]==n){
            st=0;
        }
    }
    if(pr){
        cout<<"pairwise coprime";
        return 0;
    }
    if(st){
        cout<<"setwise coprime"; return 0;
    }
    cout<<"not coprime";
}



Measured memory_bytes: 81300
import java.util.Scanner;

/**
 * Created by oka on 2018/06/10.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n < 1000) {
            System.out.println("ABC");
        } else {
            System.out.println("ABD");
        }
    }
}


Measured memory_bytes: 21972
#include <stdio.h>
int main(){

  int n,m,badm=0,goodm=0,sa[1000],y=0,blank,o,x,i,j;

  scanf("%d %d",&n,&m);

  for(i = 0; i < m; i++){

    scanf("%d %d",&o,&x);

    if(o >= n) goodm++;
    else{
      
      sa[badm]=n-o;
      badm++;

    }

  }

  /*  printf("%d\n",goodm); */
  
  if(goodm >= m-1){
    
    printf("0\n");
    return 0;
    
  }

  for(j = 0; j < badm; j++){

    for(i = 0; i < badm-1; i++){

      if(sa[i] > sa[i+1]){

	blank=sa[i];
	sa[i]=sa[i+1];
	sa[i+1]=blank;

      }

    }

  }

  /*  for(j = 0; j < badm; j++) printf("%d\n",sa[j]); */

  for(i = 0; i < m-1-goodm; i++){

    y += sa[i];

  }

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

  return 0;

}

Measured memory_bytes: 604
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<map>
#include<list>
#include<set>
using namespace std;

int main(){

  int n,k[10001],ans=0,fl=0;

  while(cin >> n && n){
    fl = 0;
    ans = 0;
    for(int i=0;i<n;i++){
      cin >> k[i];
    }
    for(int i=1;i<=2;i++){
      for(int j=0;j<n;j++){
        if(i == 1&&k[j] > 0){
          ans++;
        }
        if(i == 2&&k[j] >= 2&& fl == 0){
          ans++;
          fl = 1;
        }
      }
    }

    if(fl == 0){
      cout << "NA" << endl;
    }else{
      cout << ans << endl;
    }
  }
  return 0;
}




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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);

template<class T>
bool binary_search(std::vector<T> &vec, T t) {
  int low = 0;
  int high = (int)vec.size();

  while(low <= high) {
    int x = (low + high) / 2;
    if (vec[x] == t) return true;
    else if (t < vec[x]) high = x - 1;
    else low = x + 1;
  }
  return false;
}

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

  vector<int> v(n);

  REP (i, n) {
    scanf("%d", &v[i]);
  }

  int q;
  scanf("%d", &q);

  vector<int> t(q);
  REP (i, q) {
    scanf("%d", &t[i]);
  }
  int sum = 0;

  for (int a: t) {
    bool flag = binary_search(v, a);
    if (flag) sum++;
  }

  printf("%d\n", sum);
}



Measured memory_bytes: 3320
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> H(N), able(N, 0);

    rep(i, N) cin >> H[i];

    rep(i, M) {
        int A, B;
        cin >> A >> B;
        A--; B--;
        if (H[A] < H[B]) {
            able[A] = 1;
        }
        else if (H[A] > H[B]) {
            able[B] = 1;
        }
        else if (H[A] == H[B]){
            able[A] = 1;
            able[B] = 1;
        }
    }

    int ans = 0;
    rep(i, N) {
        if (able[i] == 0) ans++;
    }

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

Measured memory_bytes: 4048
import sys 
stdin = sys.stdin
 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n = ni()
a = na()
bunbo = 0
for ai in a:
     bunbo += 1/ai
print(1/bunbo)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int x, y;
    while (1)
    {
        scanf("%d %d", &x, &y);

        if (x == 0 && y == 0)

            break;
        else if (x > y)
            printf("%d %d\n", y, x);
        else
            printf("%d %d\n", x, y);
    }
    return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<string>

int main(){
  std::string s;
  std::cin >> s;
  std::string alphabet = "abcdefghijklmnopqrstuvwxyz";
  bool isNone = true;
  for(int i = 0; i < 26; i++){
    int check = s.find(alphabet.at(i));
    if(check == -1){
      isNone = false;
      std::cout << alphabet.at(i) << std::endl;
      break;
    }
  }
  if(isNone) std::cout << "None" << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
#define INF 100000000000
using namespace std;
int main()
{
    vector<vector<ll> >dp(101,vector<ll>(100001,INF));
    vector<ll>val(101);
    vector<ll>w(101);
    ll a,b,c,d,e,f,g,h,n,m,t,W,ans=0;
    ios_base::sync_with_stdio(false);
    cin>>n>>W;
    for(int i=1;i<=n;i++)cin>>w[i]>>val[i];
    /**/for(int i=0;i<=100;i++)dp[i][0]=0;
    m=n*1000;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            /**/a=w[i];
            b=dp[i-1][j];
            if(val[i]<=j)a=dp[i-1][j-val[i]]+w[i];
            dp[i][j]=min(a,b);
        }
    }
    for(int i=1;i<=m;i++){
            if(dp[n][i]>W||dp[n][i]==0)continue;
            ans=i;
    }
    cout<<ans<<endl;
    return 0;
}


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



int main(void)
{
	int i,j;
	char a[200] = {0}, b[200] = {0}, temp[200] = {0};
	int m,n,num,h[100] = {0};

	while(1)
	{

		scanf("%s", a);
		n = strlen(a);

		if (a[0] == '-')
		{
			break;
		}

		scanf("%d", &m);

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

		for(i = 0; i < m; i++)
		{
			num = h[i];

			for(j = 0; j < num; j++)
			{
				temp[j] = a[j];
			}

			for(j = num; j < n; j++)
			{
				a[j - num] = a[j];
			}

			for(j = 0; j < num; j++)
			{
				a[j + n + - num] = temp[j];
			}

		}

		for(i = 0; i < n; i++)
		{
			printf("%c", a[i]);
		}
		printf("\n");

	}

	return 0;
}

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

int main() {
int A,B,C;
  cin >> A >> B >> C;
if(A+B<=B+C&&A+C>=A+B){
  cout << A+B << endl;
} else if (A+C<A+B&&A+C<=B+C) {
  cout << A+C <<endl;
} else {
  cout << C+B<< endl;
}
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

ll mod = 1e9+7;
ll dp[210][55][55][55] = {0};
ll add(ll a, ll b) {
	return (a + b) % mod;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	int A, T, G, C; cin >> A >> T >> G >> C;
	int M; cin >> M;
	vector< vector<string> > v(M);
	map<string, int> tbl;
	{
		string str;
		int p = -1;
		while (cin >> str) {
			int n = str.size();
			if (str[n-1] == ':') {
				tbl[str.substr(0, n-1)] = ++p;
			}
			else {
				v[p].pb(str);
			}
		}
	}
	map<char, int> it{{'A', 0}, {'T', 1}, {'G', 2}, {'C', 3}};
	vector< vector< vector<int> > > ig(M);
	int S = A + T + G + C;
	RREP(i, M) {
		EACH(str, v[i]) {
			if (ig[i].size() > S) break;
			if (str[0] == '[') {
				vector<int> item(4, 0);
				str = str.substr(1, (int)str.size()-2);
				REP(j, str.size()) {
					item[it[str[j]]] = 1;
				}
				ig[i].pb(item);
			}
			else {
				EACH(item, ig[tbl[str]]) {
					ig[i].pb(item);
					if (ig[i].size() > S) break;
				}
			}
		}
	}
	vector< vector<int> > items = ig[0];
	int N = items.size();
	if (N != S) {
		cout << 0 << endl;
		return 0;
	}
//	cout << items << endl;
	dp[0][0][0][0] = 1;
	REP(i, N) REP(a, A+1) REP(t, T+1) REP(g, G+1) {
		int c = i-(a+t+g);
		if (c < 0) continue;
		if (items[i][0] && a+1 <= A) {
			dp[i+1][a+1][t][g] = add(dp[i+1][a+1][t][g], dp[i][a][t][g]);
		}
		if (items[i][1] && t+1 <= T) {
			dp[i+1][a][t+1][g] = add(dp[i+1][a][t+1][g], dp[i][a][t][g]);
		}
		if (items[i][2] && g+1 <= G) {
			dp[i+1][a][t][g+1] = add(dp[i+1][a][t][g+1], dp[i][a][t][g]);
		}
		if (items[i][3] && c+1 <= C) {
			dp[i+1][a][t][g] = add(dp[i+1][a][t][g], dp[i][a][t][g]);
		}
	}
	cout << dp[N][A][T][G] << endl;
}

Measured memory_bytes: 183588
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
 
#define ff first
#define ss second
#define pb emplace_back
#define all(x) (x).begin(), (x).end()
#define mem(a) memset(a , 0 ,sizeof a)
#define rep(i,a,b) for(int i=a ; i<b ; ++i)
#define deb(x) cout << #x << " - " << x << "\n";
#define deb2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define D2(x) { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define clz(x) __builtin_clzll(x)
#define bit(x) __builtin_popcount(x)
//(a / b) + ((a % b) != 0);
 
#define PI 3.141592653589793
const ll MOD = 1e9 + 7;
const ll INF = 10000000000000000;
const ll MAX_N = 1e5 + 7;

int main() {
    IOS;
    ll n,k; cin>>n>>k;
    vi v(n+1),temp(n+1,0);
    vi loop,intial;
    rep(i,1,n+1) cin>>v[i];
    ll i=1;
    temp[i]=1;
    while(1){
        ll curr = v[i];
        intial.pb(curr);
        temp[curr]++;
        if(temp[v[i]] == 2){
            temp[v[i]]--;
            intial.pop_back();
            while(1){
                ll curr = v[i];
                temp[curr]++;
                if(temp[v[i]] == 3) break;
                loop.pb(v[i]);
                i = v[i];
            }
            break;
        }
        i = v[i];
    
    }
    if(k<intial.size()){
        cout<<intial[k-1];
    } else{
        k -= intial.size();
        k = k % loop.size();
        if(k==0) cout<<loop[loop.size()-1];
        else cout<<loop[k-1];
    }
    // D2(loop);
    // D2(intial);
    return 0;
}

Measured memory_bytes: 7108
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>

using namespace std;
#define LL long long
#define pb push_back
#define mk make_pair
#define pill pair<int, int>
#define mst(a, b)	memset(a, b, sizeof a)
#define REP(i, x, n)	for(int i = x; i <= n; ++i)
const int MOD = 1e9 + 7;
const int qq = 200 + 10;
const LL INF = 1e15;
LL dis[qq][qq];
int n, m, R;
int num[qq];

int main(){
	scanf("%d%d%d", &n, &m, &R);
	for(int i = 0; i < R; ++i) {
		scanf("%d", num + i);
	}
	sort(num, num + R);
	for(int i = 1; i <= n; ++i) {
		for(int j = 1; j <= n; ++j) {
			dis[i][j] = INF;
		}
	}
	int a, b;
	LL c;
	for(int i = 0; i < m; ++i) {
		scanf("%d%d%lld", &a, &b, &c);
		dis[a][b] = dis[b][a] = min(c, dis[a][b]);
	}
	for(int k = 1; k <= n; ++k) {
		for(int i = 1; i <= n; ++i) {
			for(int j = 1; j <= n; ++j) {
				dis[i][j] = min(dis[i][j], dis[i][k] + dis[k][j]);
			}
		}
	}
	LL ans = INF;
	do {
		LL cnt = 0;
		for(int i = 1; i < R; ++i) {
			if(dis[num[i - 1]][num[i]] == INF) {
				cnt = INF;
				break;
			}
			cnt += dis[num[i - 1]][num[i]];
		}
		ans = min(ans, cnt);
	}while(next_permutation(num, num + R));
	printf("%lld\n", ans);
	return 0;
}	

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

const int N = 2005;

vector<int> g[N];
int f[N];

int n, k, pt, ant, siz;

static bool dfs(int u, int dep = 0) {
	siz-= 1;
	f[u] = pt;

	if (dep == k / 2)
		return true;

	bool flag = false;
	for (auto v: g[u]) if (f[v] != pt)
		flag|= dfs(v, dep + 1);

	return flag; }

int main() {
#ifdef HOME
	freopen("agc1c.in", "r", stdin);
	freopen("agc1c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int a, b;
	bool flag;

	cin >> n >> k;
	for (int i = 1; i < n; ++i) {
		cin >> a >> b;
		g[a].push_back(b);
		g[b].push_back(a); }

	ant = 1e9;
	flag = false;

	if (k % 2 == 0) {
		for (int good, u = 1; u <= n; ++u) {
			siz = n - 1;
			good = 0;
			f[u] = ++pt;
			for (auto v: g[u])
				good+= int(dfs(v, 1));

			if (good >= 2) {
				flag = true;
				ant = min(ant, siz); } } }
	else {
		for (int u = 1; u <= n; ++u) {
			for (auto v: g[u]) if (v < u) {
				f[u] = f[v] = ++pt;
				siz = n;
				if (dfs(u) && dfs(v)) {
					flag = true;
					ant = min(ant, siz); } } } }

	cout << (flag ? ant : 0) << endl;

	return 0; }


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, M;
	vector<int> K;
	int temp;
	int count = 0;

	cin >> N >> M;

	vector<vector<int>> food_list(N);

	REP(i, N) {
		cin >> temp;
		K.push_back(temp);

		REP(j,K[i]) {
			cin >> temp;
			food_list[i].push_back(temp);
		}
		sort(food_list[i].begin(), food_list[i].end());
	}

	REP(i, K[0]) {
		temp = 0;
		REP(j, N - 1) {
			REP(k, K[j + 1]) {
				if (food_list[j+1][k] == food_list[0][i])
				{
					temp = 1;
					break;
				}
				else
				{
					temp = 0;
				}
			}
			if (temp == 0)break;
		}
		if (temp == 1)
		{
			count++;
		}
	}

	if (N == 1) {
		cout << K[0] << endl;
	}
	else
	{
	cout << count << endl;
	}


	return 0;
}

Measured memory_bytes: 256
n = int(input())

dic = {}

for i in range(n):
    word = input()

    if word in dic:
        dic[word] += 1
    else:
        dic[word] = 1

m = int(input())

for j in range(m):
    word = input()

    if word in dic:
        dic[word] -= 1
    else:
        dic[word] = -1


print(max(0,max(dic[x] for x in dic)))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n;
    map<ll,ll> mp;
    cin>>n;
    ll temp;
    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        cin>>temp;
        mp[temp]++;
        sum += temp;
    }
    ll q;
    cin>>q;
    ll t1,t2;
    for(int i=0;i<q;i++)
    {
        cin>>t1>>t2;
        ll num = mp[t1];
        sum -= mp[t1]*t1;
        sum -= mp[t2]*t2;
        mp[t1] = 0;
        mp[t2] += num;
        sum += mp[t2]*t2;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 9540
#include<iostream>
#include<algorithm>
#include<string>
#include<functional>
#include<utility>
#include<stack>
#include<queue>
#include<cmath>
#include<list>
#include<cstdint>
#include<vector>
#include<map>
#define rep(i,rept)	for(ll i = 0; i<rept;i++)
typedef long long ll;
using namespace std;

int a = 0, b = 0, c = 1, x = 0, y = 0, z = 0, maxy = -1, mini = 9999, counter = 0,startp=0,endp=0,checker=0;
std::vector<unsigned long long int> vec{}, vecsec{};
unsigned long long int iremono[101];
std::vector<char>kinds{}, ans{}, kaku{};

bool okada = false,okada2=false;
std::string output, output2, input, one, two;
char cutcount[201];
int kakunou2[50][50] = {};

int ctoi(const char c) {
	if ('0' <= c && c <= '9') return (c - '0');
	return -1;
}
unsigned long long int LCM(unsigned long long int a, unsigned long long int b) {
	unsigned long long int i, j;
	i = a; j = b;
	while (true) {

		c = i % j;
		i = j;
		if (c != 0) {

			j = c;

		}
		else {
			break;
		}
	}
	return j * (a / j) * (b / j);
}
int main()
{
	cin >> a;
	cin >> input;
	for (int j = 0; j < input.size() - 1; j++) {
		//jとj+1の間を切る
		one = input.substr(0, j + 1);
		
		for (int m = 0; m < one.size(); m++) {
			kinds.push_back(one[m]);
		
		}
	
		std::sort(kinds.begin(), kinds.end());
		kinds.push_back('1');
		//ここ
		for (int n = 0; n < kinds.size()-1; n++) {
			if (kinds[n] != kinds[n + 1]) {
				kaku.push_back(kinds[n]);
			}
		}


		two = input.substr(j+1,a-j+1);
			
		for (int k = 0; k < kaku.size(); k++) {
				z = -1;
				z=two.find(kaku[k]);
				if (z >= 0) {
					y++;
				}
		}

		if (maxy < y) {
				maxy = y;
		}
			
	    kinds.clear();
		kaku.clear();
		y = 0;
	}
	
	

	cout << maxy << endl;
		
}

	
	





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    vector<string>v(n);
    rep(i,n){
        string s;cin>>s;
        sort(s.begin(),s.end());
        v[i]=s;
    }
    sort(v.begin(),v.end());
    v.push_back("");
    ll now=0,k=0,ans=0;
    while(now<=n){
        if(v[now]==v[k])now++;
        else{
            ans+=(now-k)*(now-k-1)/2;
            k=now;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 6528
#include<stdio.h>                                                               
                                                                                
signed main()                                                                   
{                                                                               
  int r,g,b,n;                                                                  
  scanf("%d %d %d %d",&r,&g,&b,&n);                                             
                                                                                
  int ans = 0;                                                                  
  int i,j;                                                                      
  for( i = 0; i <= n; ++i ){                                                    
    for( j = 0; j <= n; ++j ){                                                  
                                                                                
        if( (r*i)+(g*j) <= n && ( n - ((r*i)+(g*j)) ) % b == 0 ) ans += 1;      
                                                                                
      }                                                                         
    }                                                                           
                                                                                
  printf("%d\n",ans);                                                           
                                                                                
  return 0;                                                                     
                                                                                
}                                                                               

Measured memory_bytes: 128