akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  int n, m;
  cin >> n >> m;
  vi k(m), p(m);
  vector<vi> s(m);
  rep(i, m) {
    cin >> k[i];
    rep(j, k[i]) {
      int ss;
      cin >> ss;
      s[i].push_back(ss);
    }
  }
  rep(i, m) cin >> p[i];
  int ans = 0;
  rep(i, 1 << n) {
    bool ok = true;
    vb sw(n);
    rep(j, n) if(i >> j & 1) sw[j] = true;
    rep(j, m) {
      int num = 0;
      for(auto v : s[j])
        if(sw[v - 1]) num++;
      if(num % 2 != p[j]) ok = false;
    }
    if(ok) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()
{
	int a[4];
	for(int i=0;i<4;i++)cin>>a[i];
	sort(a,a+4);
	if(a[0]==1&&a[1]==4&&a[2]==7&&a[3]==9)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
cnt = Counter(A)

res = 0
for k, v in cnt.items():
    res += k*v

for _ in range(int(input())):
    B, C = map(int, input().split())
    res -= cnt[B]*B
    res += cnt[B]*C

    cnt[C] += cnt[B]
    cnt[B] = 0
    print(res)


Measured memory_bytes: 24128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public long MOD = 1000000007;
        public string S, T;
        public int Q;
        public int[] AS, BS, AT, BT;
        public void Run()
        {
            S = Console.ReadLine();
            T = Console.ReadLine();
            Q = Input.ReadInt();

            AS = new int[S.Length];
            AT = new int[T.Length];

            for (int i = 0; i < S.Length; i++)
            {
                if (S[i] == 'A') AS[i]++;
                else AS[i]--;
                if (i > 0) AS[i] += AS[i - 1];
            }

            for (int i = 0; i < T.Length; i++)
            {
                if (T[i] == 'A') AT[i]++;
                else AT[i]--;
                if (i > 0) AT[i] += AT[i - 1];
            }

            for (int q = 0; q < Q; q++)
            {
                var line = Input.ReadIntArray();
                int sL = line[0] - 1;
                int sR = line[1] - 1;
                int tL = line[2] - 1;
                int tR = line[3] - 1;

                int sa = AS[sR] - (sL == 0 ? 0 : AS[sL - 1]);
                int sb = AT[tR] - (tL == 0 ? 0 : AT[tL - 1]);

                sa = (sa + 3 * 1000000) % 3;
                sb = (sb + 3 * 1000000) % 3;

                Console.WriteLine(sa == sb ? "YES" : "NO");
            }




        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

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

typedef struct{int to,cost;}edge;
vector<edge>tree[100000];

long long depth[100000];

void dfs(int current_v,int parent,long long cost){
    depth[current_v]=cost;
    for(auto x:tree[current_v])if(x.to!=parent)dfs(x.to,current_v,cost+x.cost);//(木の子孫は全て未訪問)
    return;
}

int main(void){
    int n,u,v,w;
    cin>>n;
    for(int i=1;i<n;i++){
        cin>>u>>v>>w;
        tree[u-1].push_back(edge{v-1,w});
        tree[v-1].push_back(edge{u-1,w});
    }
    dfs(0,-1,0LL);
    for(int i=0;i<n;i++)cout<<depth[i]%2<<endl;
    return 0;
}

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

using namespace std;

int main(){
    int n;
    string s;
    int r=0,b=0;
    cin >> n >> s;
    for(int i=0;i<n;i++){
        if(s[i] == 'R'){
            r++;
        }else{
            b++;
        }
    }
    if(r>b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define M 1000000007
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n;
  cin>>n;
  ll arr[2*n];
  ll m=2*n;
  for(ll i=0;i<m;i++) cin>>arr[i];
  sort(arr,arr+m);
  ll sum=0;
  for(ll i=0;i<m;i+=2) sum+=arr[i];
  cout<<sum;
  
    
  
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<ll> v(100500);
    v[0]=1;
    FOR(i,0,100000){
        if(v[i] == 1){
            v[i+100] = 1;
            v[i+101] = 1;
            v[i+102] = 1;
            v[i+103] = 1;
            v[i+104] = 1;
            v[i+105] = 1;            
        }
    }
    ll n;
    cin>>n;
    cout<<v[n]<<endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 

int main(){
    string S;
    cin >> S;//"123"の場合S[0]=1, S[1]=2, S[2]=3になるので，
    reverse(S.begin(), S.end());//S[2]S[1]S[0]の向きにする
    //つまりS[2]=1, S[1]=2, S[0]=3;になった
    int N = S.size();

    //S[i+2]S[i+1]S[i]=S[i+2]*10^(i+2)+S[i+1]*10^(i+1)+S[i]*10^i
    //なので  その数列がa[i+2]+a[i+1]+a[i]になるようにする
    //vector<ll> a(N);
    //for(int i=0; i<N; i++) a[i] = S[i]*pow(10, i);
    // vector<ll> wa(N+1);
    // wa[0] = 0;
    // for(int i=0; i<N; i++){
    //   wa[i+1] = wa[i]+pow(10, i)*(S[i]-'0');
    // }

    const int MOD = 2019;
    map<int, int> mp;
    ll ans = 0;
    ll wa = 0;//累積和
    ll pow10_i = 1;// pow(10, i)%MOD
    for(int i=0; i<N; i++){
      mp[wa]++;
      //wa += (S[i] - '0') * pow(10, i);
      wa += (S[i] - '0') * pow10_i;
      wa %= MOD;
      ans += mp[wa];
      //mp[wa]++;
      pow10_i = pow10_i*10 % MOD;
    }

    cout << ans << endl;


}


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

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int ftravel = 0;
    if (a >= b) {
        ftravel = b;
    } else {
        ftravel = a;
    }
    if (c >= d) {
        ftravel = ftravel + d;
    } else {
        ftravel = ftravel + c;
    }
    cout << ftravel;
}

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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

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

int main(){
    ll a,b,c;cin>>a>>b>>c;
    if(a%2==0 or b%2==0 or c%2==0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << min(a*b,min(a*c,b*c)) << endl;
        return 0;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;
#define fast() ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

template <typename T>
struct edge
{
    int src, to;
    T cost;
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
    edge &operator=(const int &x)
    {
        to = x;
        return *this;
    }
    operator int() const { return to; }
};

template <typename T>
using Edges = vector<edge<T>>;

template <typename T>
using WeightedGraph = vector<Edges<T>>;

template <typename T>
using UnweightedGraph = vector<vector<T>>;

template <typename T>
using Matrix = vector<vector<T>>;

template <typename T>
vector<T> BellmanFrod(Edges<T> &edges, int N, int source)
{
    const auto INF = numeric_limits<T>::max();
    vector<T> dist(N, INF); //distance from source
    dist[source] = 0;
    for (int i = 0; i < N - 1; i++)
    {
        for (auto &e : edges)
        {
            if (dist[e.src] == INF)
                continue;
            dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
        }
    }

    // check for negative-weight cycles
    for (auto &e : edges)
    {
        if (dist[e.src] == INF)
            continue;
        if (dist[e.src] + e.cost < dist[e.to])
            return vector<T>();
    }
    return dist;
}

int N, M;

int main()
{
    cin >> N >> M;
    Edges<int> G;
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G.emplace_back(a, b, -1);
    }
    for (int i = 0; i < N && i < 1000; i += 2)
    {
        auto d = BellmanFrod(G, N, i);
        if (d.size() == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 384
import sys

n, k = map(int, input().split())
mod = 998244353

dp = [0] * (n+1)
dp[1] = 1
r = [tuple(map(int, input().split())) for _ in range(k)]
s = [0 for _ in range(k)]

for i in range(2, n + 1):
    sums = 0
    for j in range(k):
        s[j] += dp[max(0, i - r[j][0])] - dp[max(0, i - r[j][1] - 1)]
        s[j] %= mod
        sums = (sums + s[j]) % mod
    dp[i] = sums

print(dp[n])


Measured memory_bytes: 16788
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    string s;
    bool ans=true;
    cin>>a>>b>>s;
    int i=0;
    while(i<a){
        if(s[i]<48||s[i]>57)ans=false;
        i++;
    }
    if(s[i]!='-')ans=false;
    i++;
    while(i<a+b+1){
        if(s[i]<48||s[i]>57)ans=false;
        i++;
    }
    if(ans==true)puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
__int64_t N, C;
int main() {
  cin >> N >> C;
  __int64_t x[N+2],v[N+2],OA[N+2],rOA[N+2],OB[N+2],rOB[N+2],sum,out;
  OA[0]=rOA[0]=OB[0]=rOB[0]=sum=out=0;
  for (int i=0; i<N; i++) {
    cin >> x[i] >> v[i];
    sum += v[i];
    OA[i+1] = max(OA[i],sum-x[i]);
    rOA[i+1] = max(rOA[i],sum-2*x[i]);
  }
  sum = 0;
  for (int i=0; i<N; i++) {
    int n = N-1-i;
    sum += v[n];
    OB[i+1] = max(OB[i],sum-C+x[n]);
    rOB[i+1] = max(rOB[i],sum-2*(C-x[n]));
  }
  for (int i=0; i<N+1; i++) {
    out = max(out, OA[N-i]+rOB[i]);
    out = max(out, OB[i]+rOA[N-i]);
  }
  cout << out;
  return 0;
}

Measured memory_bytes: 4992
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
const int MAX =1e5+6;
const long long inf=1e18;
int main(){
	int n;
	cin>>n;
	double arr[n+1];
	double g=0;
	///long long l=1;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		g=g+(1/arr[i]);
	}
//	cout<<l;
//	cout<<ans;
	cout<<setprecision(9)<<1/g;


}

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

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

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

#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

long a[100005];
bool used[100005];

struct UnionFind {
    vector<ll> par;
    vector<ll> siz;
    vector<priority_queue<ll, vector<ll>, greater<ll>>> pq;

    UnionFind(ll N) : par(N), siz(N), pq(N) {
        for(int i = 0; i < N; i++) {
            par[i] = i;
            siz[i] = 1;
            pq[i].push(a[i]);
        }
    }

    ll root(ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    bool unite(ll x, ll y) {
        ll rx = root(x);
        ll ry = root(y);
        if (rx == ry) return false;
        if (siz[rx] < siz[ry]) swap(rx, ry);
        siz[rx] += siz[ry];
        par[ry] = rx;
        while (!pq[ry].empty()) {
          pq[rx].push(pq[ry].top());
          pq[ry].pop();
        }
        return true;
    }

    bool same(ll x, ll y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};


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

  int n, m;
  cin >> n >> m;
  
  rep(i, n) {
    cin >> a[i];
  }

  UnionFind uf(n);
  rep(i, m) {
    int x, y;
    cin >> x >> y; 
    uf.unite(x, y);
  }

  if ((n-1-m) * 2 > n) {
    cout << "Impossible" << endl;
  } else if (n-1 == m) {
    cout << 0 << endl;
  } else {
    priority_queue<ll, vector<ll>, greater<ll>> rem;
    long res = 0;
    int cnt = 0;
    rep(i, n) {
      int root = uf.root(i);
      if(used[root]) continue;
      cnt++;
      used[root] = true;
      res += uf.pq[root].top();
      uf.pq[root].pop();
      while(!uf.pq[root].empty()) {
        rem.push(uf.pq[root].top());
        uf.pq[root].pop();
      }
    }
    rep(i, (n-1-m)*2 - cnt) {
      res += rem.top();
      rem.pop();
    }
    cout << res << endl;
  }
}


Measured memory_bytes: 12532
n = int(input())
kugiri = [0,26,702,18278,475254,12356630,321272406,8353082582,217180147158,5646683826134,146813779479510,3817158266467286]
ans = ""

for i in range(len(kugiri)):
    if n <= kugiri[i]:
        keta = i
        break
        
n -= kugiri[i-1]

for i in range(keta):
    moji = -(-n // 26**(keta-1))
    ans += chr(moji+96)
    n -= (moji-1) * 26**(keta-1)
    keta -= 1
    
print(ans)

Measured memory_bytes: 9224
let ceil_exponent i k = 
  let rec ceil_exponent' i k res = 
    if i * (1 lsl res) >= k then res 
    else ceil_exponent' i k (res + 1) in
  ceil_exponent' i k 0
;;

let p n = 0.5 ** n;;

let solve n k = 
  let rec sum' n k res = 
    if n = 0 then res 
    else sum' (n - 1) k (res +. (ceil_exponent n k |> float_of_int |> p)) in
  (sum' n k 0.) /. (float_of_int n)
;;

let () = Scanf.scanf "%d %d" (fun n k -> print_float (solve n k));;

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

int main()
{
      ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   int n;
   cin>>n;
   int h[n+1];
   for(int i=1;i<=n;i++)
   cin>>h[i];
    vector< long long  > dp(n+1);
    dp[1]=0;
    dp[2]=dp[1]+abs(h[1]-h[2]);
    for(int i=3;i<=n;i++)
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    cout<<dp[n];
    return 0;    
}

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

typedef long long int ll;
typedef vector<int> vi;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pvec(v) for(auto e: v) cout << e << " ";
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i, a, b) for(int i = (a); i<(b); ++i)
#define pb push_back
#define INF 1000000005
#define MOD 1000000007
#define all(v) v.begin(), v.end()

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

ll power(ll x, ll y, ll p = MOD){  
    ll res = 1LL; 
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1LL)  
            res = (res*x) % p;
        y = y>>1LL; 
        x = (x*x) % p;  
    }  
    return res;  
}  

int main(){
	IO
	int n, w;
	cin >> n >> w;
	vll prev(w + 1, 0), curr(w + 1, -1);

	ll price, weight;
	rep(i, 1, n + 1){
		cin >> weight >> price;
		for(int wi = 0; wi <= w; ++wi){
			if ( wi < weight ) curr[wi] = prev[wi];
			else curr[wi] = max(prev[wi], prev[wi - weight] + price);
		}
		prev = curr;
	}

	ll ans = -1;
	rep(i, 0, w+1) ans = max(ans, prev[i]);

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

Measured memory_bytes: 4784
#include <iostream>
int main(void)
{
	int n, a, c = 0;
	std::cin >> n;
	for(int i = 0; i != n; i++){
		std::cin >> a;
		if(a % 2 != 0) c++;
	}
	if(c % 2 == 0) std::cout << "YES" << std::endl;
	else std::cout << "NO" << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int[] box = new int[a];
    int ans = 0;
    for(int i=0;i<a;i++){
      box[i] = sc.nextInt();
      if(box[i]>=b){
        ans++;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 47864
n = gets.to_i
nums = gets.split.map(&:to_i)

res = []
nums.each_with_index do |num, idx|
  if idx % 2 == 0
    res.push(num)
  else
    res.unshift(num)
  end
end
res.reverse! if n.odd?
puts res.join(' ')


Measured memory_bytes: 25692
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(void){
	int n;
	int a[101]={0};

	while(cin>>n){
        a[n]++;
	}
	int b=0;
    for(int i=0;i<100;i++){
        b=max(a[i],b);
    }
    for(int i=0;i<100;i++){
        if(a[i]==b)cout<<i<<endl;
    }
	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<string>
#include<math.h>
#include<numeric>
#include<complex>

using namespace std;
typedef long long ll;

#define REP(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void printVector(vector<ll> A){
    cout << "[vector]" << endl;
    for(int i=0; i<A.size(); i++){
        cout << A[i] << " ";
    }
    cout << endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    // input
    int N, K;
    cin >> N >> K;

    ll answer;

    if(K%2 == 1){
        int count = 0;
        FOR(i, 1, N+1){
            if(i%K==0){
                count++;
            }
        }
        answer = pow(count, 3);
    }
    else{
        int count0 = 0;
        FOR(i, 1, N+1){
            if(i%K == 0){
                count0++;
            }
        }
        int count1 = 0;
        FOR(i, 1, N+1){
            if(i%K == K/2){
                count1++;
            }
        }
        answer = pow(count0, 3) + pow(count1, 3);
    }

    p(answer);

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }


// https://atcoder.jp/contests/abc139/submissions/7297478

const int MAXN = 1005;
const int MAXV = MAXN * (MAXN - 1) * 2;
int id[MAXN][MAXN];
vector<int> from[MAXV];


bool visited[MAXV];
bool fin[MAXV];
int dp[MAXV];

int dfs(int v) {
    if (visited[v]) {
        if (fin[v] == 0) return -1;
        return dp[v];
    }
    
    visited[v] = 1;
    dp[v] = 1;
    for (int u : from[v]) {
        int res = dfs(u);
        if (res == -1) return -1;
        chmax(dp[v], res + 1);
    }
    
    fin[v] = 1;
    return dp[v];
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > a(n, vector<int>(n - 1));
    rep(i, n) rep(j, n - 1) { cin >> a[i][j]; a[i][j]--; }
    
    int c = 0;
    rep(i, n) rep3(j, i + 1, n) {
        id[i][j] = c++;
    }
    
    auto toId = [&](int i, int j) {
        if (i > j) swap(i, j);
        return id[i][j];
    };
    
    rep(i, n) {
        rep(j, n - 1) a[i][j] = toId(i, a[i][j]); // a[i][j]を再利用
        rep(j, n - 2) from[a[i][j + 1]].eb(a[i][j]);
    }
    
    int ans = 0;
    rep(i, c) {
        int res = dfs(i);
        if (res == -1) { puts("-1"); return 0; }
        chmax(ans, res);
    }
    cout << ans << endl;
}



Measured memory_bytes: 78848
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
const long long INF = 1LL << 60;
const int MOD = 1e9 + 7;

ll modpow(ll a, ll n, ll mod = MOD) {
    ll rtn = 1;
    while (n > 0) {
        if (n & 1) rtn = rtn * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return rtn;
}

ll modulo(ll a,ll mod = MOD){
    return (a % mod + mod) % mod;
}

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

	ll ans = 0;
	std::vector<ll> found(K+1);
	rep(i,K){
		//consider gcd(....) = (K-i)
		found.at(K-i)= modpow(K/(K-i),N,MOD);

		rep2(j,2,K/(K-i)+1){
			found.at(K-i) -= found.at(j*(K-i));
		}
		ans += found.at(K-i)*(K-i);
	}

	cout << ans % MOD << endl;
	return 0;

}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
int main() {
  double n;
  cin >> n;
  double x = 0;
  vector<int> co(n);
  for (int i=0; i<n; i++) {
    int q;
    cin >> q;
    co.at(i) = q;
    x += q;
  }
  double t = x/n;
  int ave = t;
  if (t*10 - ave*10 >= 5) {
    ave += 1;
  }
  int cost = 0;
  for (int i=0; i<n; i++) {
   int a = co.at(i) - ave;
   cost += pow(a,2);
  }
  cout << cost << endl;
}

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

using namespace std;

int N;
vector<pair<int, int>> A;
set<int> S;

int main()
{
    scanf("%d", &N);
    int a;
    for(int i=1; i<=N; i++)
    {
        scanf("%d", &a);
        A.push_back({a, i});
    }
    sort(A.begin(), A.end());
    S.insert(0);
    S.insert(N+1);
    long long ans=0;
    for(int i=0; i<N; i++)
    {
        auto it=S.lower_bound(A[i].second);
        auto pit=prev(it);
        long long l=A[i].second-*pit;
        long long r=*it-A[i].second;
        ans+=1LL*l*r*A[i].first;
        S.insert(A[i].second);
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 11120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _20180305_AOJ
{
    class ALDS1_4C
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line))
                {
                    break;
                }

                HashSet<string> ht = new HashSet<string>();
                int n = int.Parse(line);
                for (int i = 0; i < n; i++)
                {
                    string[] command = Console.ReadLine().Split(' ');
                    switch (command[0])
                    {
                        case "insert":
                            ht.Add(command[1]);
                            break;
                        case "find":
                            if (ht.Contains(command[1]))
                            {
                                Console.WriteLine("yes");
                            }
                            else
                            {
                                Console.WriteLine("no");
                            }
                            break;
                    }
                }
            }
        }
    }
}



Measured memory_bytes: 40212
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

int main(){
	ll x,a,b;cin>>x>>a>>b;
	if(-a+b<=0)cout<<"delicious"<<endl;
	else if(-a+b<=x)cout<<"safe"<<endl;
	else cout<<"dangerous"<<endl;
}


Measured memory_bytes: 256
/**
 *  author: Haunted_Cpp
**/

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

#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")

template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 1e6 + 5;

bitset<MAX_N> is_prime;
bitset<MAX_N> rep;
int fac[MAX_N], cnt[MAX_N];


int main () {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  int gcd = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    gcd = __gcd(gcd, arr[i]);
  }
  for (int i = 0; i < MAX_N; i++) {
    fac[i] = i;
    is_prime[i] = 1;
  }
  is_prime[0] = is_prime[1] = 0;
  for (int i = 4; i < MAX_N; i += 2) {
    is_prime[i] = 0;
    fac[i] = 2;
  }
  for (int i = 3; i * i < MAX_N; i += 2) {
    if (is_prime[i]) {
      for (int j = i * i; j < MAX_N; j += i) {
        is_prime[j] = 0;
        fac[j] = i;
      }
    }
  }
  vector<int> added;
  auto add_fac = [&](int delta) {
    added.clear();
    while(delta > 1) {
      added.emplace_back(fac[delta]);
      delta /= fac[delta];
    }
    for (auto to : added) {
      if (!rep[to]) {
        rep[to] = 1;
        ++cnt[to];
      }
    }
    for (auto to : added) {
      rep[to] = 0;
    }
  };
  for (int i = 0; i < n; i++) add_fac(arr[i]);
  int mx = *max_element(cnt, cnt + MAX_N);
  if (mx <= 1) {
    cout << "pairwise coprime" << '\n';
  } else if (gcd == 1) {
    cout << "setwise coprime" << '\n';
  } else {
    cout << "not coprime" << '\n';
  }
  return 0;
}


Measured memory_bytes: 15184
/**
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

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

#define DEBUG
#ifndef DEBUG
#define endl "\n"
#endif

const double PI = acos(-1);
typedef long long ll;
#define fori(n) for(ll i=0; i<(n); i++)

#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cinll(l) ll l; cin>>l;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinall(a, n) vll a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;
typedef vector<ll> vll;

void mygetline(string &s) {
	getline(cin, s);
	while (s.size() && s.back() == 13)
		s.pop_back();
}

ll atol(string &s) {
	istringstream iss(s);
	ll i;
	iss >> i;
	return i;
}

void atoli(string &s, vll &a) {
	istringstream iss(s);
	int i = 0;
	while (iss.good())
		cin >> a[i++];
}

void solve() {
	cinll(n);
	cinll(a);
	cinll(b);

	ll d = abs(a - b);
	if ((d & 1) == 0) {
		ll ans = d / 2;
		cout << ans << endl;
	} else {
		ll d1 = n - max(a, b);
		ll d2 = min(a, b) - 1;
		d1 += (abs(a - b) + 1) / 2;
		d2 += (abs(a - b) + 1) / 2;
		cout << min(d1, d2) << endl;
	}
}

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



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

public static class Program
{
    public static void Main(string[] args)
    {
        char[] ac = { 'A', 'C' };
        var nq = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var s = Console.ReadLine().ToCharArray();
        for (int i = 0; i < nq[0] - 1; i++)
        {
            if (s[i] == 'A' && s[i + 1] == 'C')
            {
                s[i] = 'a';
            }
        }
        var t = new int[nq[0]];
        for (int i = 0; i < nq[0] - 1; i++)
        {
            t[i + 1] = s[i] == 'a' ? t[i] + 1 : t[i];
        }
        for (int i = 0; i < nq[1]; i++)
        {
            var lr = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            Console.WriteLine(t[lr[1] - 1] - t[lr[0] - 1]);
        }
    }
}

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

typedef long long ll;

#define MOD 1000000007
#define INF LLONG_MAX
#define decimDigits(n) fixed << setprecision(n)
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define irep(it, arr) for(auto it = begin(arr); it != end(arr); it++)

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

int main(){

    ll N;
    cin >> N;

    vector<ll> T(N);
    rep(i, N)
        cin >> T[i];
    
    ll M;
    cin >> M;

    vector<ll> X(M);
    vector<ll> P(M);
    rep(i, M)
        cin >> P[i] >> X[i];
    
    ll sum = accumulate(all(T), 0LL);
    rep(i, M)
        cout << sum - T[P[i] - 1] + X[i] << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n ; cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a.at(i);

    vector<vector<ll>> dp(n,vector<ll>(n,0));

    for(int i=0;i<n-1;i++){
        dp.at(i).at(i+1) = abs(a.at(i)-a.at(i+1));
    }

    for(int j=2;j<n;j++){
        for(int i=0;i<n-j;i++){
            dp.at(i).at(i+j) = max(a.at(i) - dp.at(i+1).at(i+j) , a.at(i+j) - dp.at(i).at(i+j-1));  
        }
    }
    /*
    rep(i,n){
        rep(j,n){
            cout << dp.at(i).at(j) << " ";
        }
        cout << endl;
    } 
    */
   if(n!=1){
        cout << dp.at(0).at(n-1) << endl;
    }else{
        cout << a.at(0) << endl;
    }
}

Measured memory_bytes: 70784
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String res = sc.next();
        int day = res.length();
        int nday = 15-day;
        int cnt = 0;
        for(int i = 0;i < day;i++){
            char r = res.charAt(i);
            if(r == 'o')
            cnt++;
        }
        if((day <= 7)||((day >= 8)&&((cnt+nday) >= 8))){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
    }
}

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

using namespace std;
const long long MOD = 998244353;

///mt19937 mt(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 600100;

void solve() {
        string s;
        cin >> s;
        int sum = 0;
        for (auto x:s) {
                sum += (x - '0');
                sum %= 9;
        }
        if (sum == 0) cout << "Yes"; else cout << "No";
}


int main() {
#ifdef QWERTY
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
        ios_base::sync_with_stdio(false);


        int t = 1;
//        cin >> t;

        for (int i = 1; i <= t; i++) {
//                cout << "Case #" << i << ": ";
                solve();
        }

        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
        return 0;
}

Measured memory_bytes: 3780
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int main(void){
    long sup,inf;
    scanf("%ld %ld",&sup,&inf);
    int min=2019;
    long i,j;
    int mod;
    for(i=sup;i<=inf;i++){
        for(j=sup;j<i;j++){
            mod=(i*j)%2019;
            if(mod==0){
                printf("0");
                return 0;
            }
            else if(mod<min){
                min=mod;
            }
            
        }
    }
    printf("%d",min);
    return 0;
}

Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE BinaryLiterals #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE NumDecimals #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}

import Control.Applicative
import Control.Arrow
import Control.Monad
import Control.Monad.ST

import Data.Char
import Data.List
import Data.Maybe

import qualified Data.ByteString.Char8 as B

import Data.Array.ST.Safe
import Data.STRef

import Debug.Trace
import Text.Printf

readInt = readLn :: IO Int
readInteger = readLn :: IO Integer
readInts = map ( fst . fromJust . B.readInt ) . B.words <$> B.getLine
readIntegers = map ( fst . fromJust . B.readInteger ) . B.words <$> B.getLine

which a b f = if f then a else b
mp [ a, b ] = ( a, b )

modifyArray a i f = writeArray a i =<< f <$> readArray a i

main = do
	[ _, k ] <- readInts
	as <- sort <$> readInts
	print $ sum $ take k as

Measured memory_bytes: 4556
/**
 * ???????????£??????????????? 2?¬?????????????
 */

// #include {{{
#include <array>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iterator>
#include <tuple>
#include <utility>
#include <random>
#include <limits>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cstdint>
#include <cassert>
// }}}

using namespace std;

// macros {{{
template<typename T, size_t N>
constexpr size_t NELEMS(T (&)[N]) { return N; }

template<typename InputIt>
void PRINT_RANGE(InputIt first, InputIt last)
{
    for(; first != last; ++first)
        cout << *first << (first==last ? "" : " ");
    cout << "\n";
}

template<typename T>
void PRINT_MATRIX(T mat, size_t nr, size_t nc)
{
    for(size_t r = 0; r < nr; ++r) {
        for(size_t c = 0; c < nc; ++c) {
            cout << mat[r][c] << (c==nc-1 ? "" : " ");
        }
        cout << "\n";
    }
}

#define FOR(i, start, end) for(int i = (start); i < (end); ++i)
#define REP(i, n) FOR(i, 0, n)
// }}}

// types {{{
using ll  = long long;
using ull = unsigned long long;
// }}}

constexpr int INF = numeric_limits<int>::max();

int V;
int E;
vector<vector<int>> D;

void warshallfloyd()
{
    FOR(k, 0, V) {
        REP(i, V) {
            if(D[i][k] == INF) continue;
            REP(j, V) {
                if(D[k][j] == INF) continue;
                D[i][j] = min(D[i][j], D[i][k] + D[k][j]);
            }
        }
    }
}

void solve()
{
    warshallfloyd();

    bool ok = true;
    REP(v, V) {
        if(D[v][v] < 0) ok = false;
    }

    if(!ok) {
        cout << "NEGATIVE CYCLE" << "\n";
    }
    else {
        REP(i, V) {
            REP(j, V) {
                int d = D[i][j];
                if(d == INF) {
                    cout << "INF";
                }
                else {
                    cout << d;
                }
                cout << (j == V-1 ? "\n" : " ");
            }
        }
    }
}

int main()
{
    cin >> V >> E;
    D.resize(V);
    for(auto& row : D) {
        row.resize(V);
    }

    REP(from, V) {
        REP(to, V) {
            D[from][to] = (from == to ? 0 : INF);
        }
    }

    REP(_, E) {
        int s, t, d;
        cin >> s >> t >> d;
        D[s][t] = d;
    }

    solve();

    return 0;
}

Measured memory_bytes: 3112
#include <stdio.h>
#define rep(i,n)Rep(i,0,n)
#define Rep(i,a,n)for(int i=(int)(a);i<(int)(n);i++)
typedef long long ll;
typedef long double ld;

int main() {
	int n, a[100001], tmp;
	scanf("%d", &n);
	rep(i, n)scanf("%d", &a[i]);
	tmp = a[0];
	rep(i, 100002) {
		if (tmp == 2) { printf("%d", i + 1); return 0; }
		tmp = a[tmp - 1];
	}
	printf("-1"); return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int, char> P;
#define fs first
#define sc second

int main(){
    int N, Q;
    string s;
    cin >> N >> s >> Q;

    vector<ll> ans;
    for(int i = 0; i < Q; i++){
        int k;
        cin >> k;

        ll cntD = 0;
        ll cntM = 0;
        ll cntDM = 0;
        ll res = 0;
        deque<P> que;
        for(int j = 0; j < N; j++){
            //余分なものをpop
            while(true){
                if(que.size() == 0) break;
                else if(que.back().sc == 'D' && que.back().fs > j - k) break;
                else if(que.back().sc == 'M'){
                    //cout << "popM" << endl;
                    cntM--;
                    que.pop_back();
                }
                else if(que.back().sc == 'D' && que.back().fs <= j - k){
                    //cout << "popD" << endl;
                    cntD--;
                    cntDM -= cntM;
                    que.pop_back();
                }
            }

            if(s[j] == 'D'){
                //cout << "pushD" << endl;
                que.push_front(P(j, 'D'));
                cntD++;
            }

            else if(s[j] == 'M'){
                //cout << "pushM" << endl;
                que.push_front(P(j, 'M'));
                cntM++;
                cntDM += cntD;
            }

            else if(s[j] == 'C'){
                //cout << "pushC" << endl;
                res += cntDM;
            }

            //printf("j = %2d  cntD = %2d  cntM = %2d  cntDM = %2d\n", j, cntD, cntM, cntDM);
        }

        ans.push_back(res);
    }

    for(ll v : ans){
        cout << v << endl;
    }

    return 0;
}


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

int main(void) {
  int n, m, x;
  int c[12], a[12][12];
  
  cin >> n >> m >> x;
  
  for(int i = 0; i < n; i++) {
    cin >> c[i];
    for(int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  
  int result = 1e9;
  
  for(int k = 0; k < pow(2, n); k++) {
    int sum_c = 0;
    int u[12];
    for(int j = 0; j < m; j++) {
      u[j] = 0;
    }
    for(int i = 0; i < n; i++) {
      if((k>>i)%2 == 1) {
        sum_c += c[i];
        for(int j = 0; j < m; j++) {
          u[j] += a[i][j];
        }
      }
    }
    
    bool flag = true;
    for(int j = 0; j < m; j++) {
      if(x > u[j]) flag = false;
    }
    if(flag) {
      if(result > sum_c) {
      	result = sum_c;
      }
    }
  }
  
  if(result == 1e9) {
    cout << -1 << endl;
  } else {
    cout << result << endl;
  }
    
  return 0;
}


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

static const int N=100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>p[i-1]>>p[i];
    }

    for(int i=1; i<=n; i++) m[i][i]=0;
    for(int l=2; l<=n; l++){
        for(int i=1; i<=n-l+1; i++){
            int j = i + l - 1;
            m[i][j] = (l<<21);
            for(int k=i; k<=j-1; k++){
                m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j]);
            }
        }
    }

    cout<<m[1][n]<<endl;

    return 0;
}


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

const int N = 100 * 1000 + 10;

int n;
bool mark[N];
int nxt[N], color[N];
vector <int> adj[N];

struct Tree {
    int root;
    vector <int> child[N];

    int match(int v) {
        for (int pnt = 1; pnt < child[v].size(); pnt += 2) {
            int x = match(child[v][pnt - 1]), y = match(child[v][pnt]);
            adj[x].push_back(y);
            adj[y].push_back(x);
        }

        if (child[v].size() % 2)
            return match(child[v].back());
        return v;
    }
} T[2];

void input() {
    cin.tie(0);
    cin >> n;

    int pr;
    for (int j = 0; j < 2; j++)
        for (int i = 1; i <= n; i++) {
            cin >> pr;
            if (pr == -1)
                T[j].root = i;
            else
                T[j].child[pr].push_back(i);
        }
    return;
}

void run(int v) {
    mark[v] = true;
    for (int u : adj[v])
        if (!mark[u]) {
            color[u] = color[v] * -1;
            run(u);
        }
    return;
}

void solve() {
    for (int i = 1; i <= n; i++)
        if (T[0].child[i].size() % 2 != T[1].child[i].size() % 2) {
            cout << "IMPOSSIBLE" << endl;
            exit(0);
        }

    T[0].match(T[0].root);
    T[1].match(T[1].root);

    for (int i = 1; i <= n; i++)
        if (!mark[i] && !(T[0].child[i].size() % 2)) {
            color[i] = 1;
            run(i);
        }
    return;
}

void output() {
    cout.tie(0);
    cout << "POSSIBLE\n";

    for (int i = 1; i <= n; i++)
        cout << color[i] << ' ';

    cout << endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    input();
    solve();
    output();
    return 0;
}


Measured memory_bytes: 19072
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i < k; i++) {
			if (i % 2 == 0) {
				if (a % 2 == 1) {
					a--;
				}
				a /= 2;
				b += a;
			} else {
				if (b % 2 == 1) {
					b--;
				}
				b /= 2;
				a += b;
			}
		}
		System.out.println(a + " " + b);
	}
}


Measured memory_bytes: 21204
<?php

$num = trim(fgets(STDIN));
$LEN = ceil(log10($num) - log10(3));
$count = 0;
for($len = 3; $len <= $LEN; $len++){
    for($i = 0; $i < pow(3, $len); $i++){
        $map[0] = 0;
        $map[1] = 0;
        $map[2] = 0;
        $I = $i;
        $n = 0;
        for($j = 0; $j < $len; $j++){
            $map[$I % 3]++;
            $n = $n * 10 + (($I%3) * 2 + 3);
            $I = floor($I / 3);
        }
        if($n > $num){
            continue;
        }
        if(array_product($map)){
            $count++;
        }
    }
}
echo $count;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using  namespace std;
int main()
{
	int h[3]={1,2,3};
	int m,j;
	cin>>m>>j;
	for(int i=0;i<3;i++){
		if(h[i]!=m && h[i]!=j){
			cout<<h[i]<<"\n";
		}
		else{
			continue;
		}
	}
	return 0;
}


Measured memory_bytes: 256