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

int main(){
  int n,m;
  cin >>n >>m;
  vector<int>a(n,0);
  for(int i=0;i<m*2;i++){
      int z;
      cin >>z;
      a.at(z-1)++;
      }
      for(int i=0;i<n;i++){
          cout << a.at(i)<<endl;
      }
}

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


long long gcd(int a,int b){
    if(b==0){
        return a;
    }
    return gcd(b,a%b);
}
long long addgcd(int a,int b,int c){
    long long result = gcd(a, b);
    result = gcd(result, c);
    return result;
}

int main()
{
    long long result = 0;
    int k;
    cin >> k;
        for (int i = 1; i < k+1;i++){
        for (int j = 1; j < k+1;j++){
            for (int l = 1; l < k+1;l++){
                result = result + addgcd(i, j, l);
            }
        }
    }
    cout << result;
}


Measured memory_bytes: 3656
n=int(input())
s=input()

ans=0
for i in range(1000):
  t=str(i)
  u="0"*(3-len(t))+t
  j=0
  exi=0
  p=u[0]
  for x in s:
    if x==p:
      j+=1
      if j==3:
        ans+=1
        break
      p=u[j]
    
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

static const int INFTY = (1 << 21);

class Edge{
public:
    int from, to, cost;
    Edge(int from = 0, int to = 0, int cost = 0) :
            from(from), to(to), cost(cost){}

    bool operator < (const Edge &e) const{
        return cost < e.cost;
    }
    bool operator >(const Edge &e) const{
        return cost > e.cost;
    }

};

class Node{
public:
    vector<Edge> edges;
    int dist;
    Node(){
        dist = INFTY;
    }
};

class Graph{
public:
    vector<Node> nodes;
    Graph(int n) {
        rep(i, n) { Node n;  nodes.push_back(n); }
    }
    Node& operator[](int i){
        return nodes[i];
    }
};

class Data{

public:
    int dist;
    Edge *edge;
    Data(int dist, Edge *edge) {
        this->dist = dist;
        this->edge = edge;
    }

    bool operator < (const Data &d) const{
        return dist < d.dist;
    }
    bool operator >(const Data &d) const{
        return dist > d.dist;
    }
};

Graph G(0);

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;

class City{
public:
    int i;
    ll x, y;
};

int N;
City cs[100000];

int main() {

    cin >> N;
    rep(i, N){
        cs[i].i = i;
        cin >> cs[i].x >> cs[i].y;
    }

    G = Graph(N);

    sort(&cs[0], &cs[N],  [](const City &a, const City &b) -> bool {return a.x < b.x; });
    // rep(i, N){ fprintf(stderr, "%d %d %d %d\n", i, cs[i].i, cs[i].x, cs[i].y); };
    rep(i, N-1){
        City c1 = cs[i]; City c2 = cs[i + 1];
        G[c1.i].edges.push_back(Edge(c1.i, c2.i, c2.x - c1.x));
        G[c2.i].edges.push_back(Edge(c2.i, c1.i, c2.x - c1.x));
    }
    sort(&cs[0], &cs[N],  [](const City &a, const City &b) -> bool {return a.y < b.y; });
    // rep(i, N){ fprintf(stderr, "%d %d %d %d\n", i, cs[i].i, cs[i].x, cs[i].y); };
    rep(i, N-1){
        City c1 = cs[i]; City c2 = cs[i + 1];
        G[c1.i].edges.push_back(Edge(c1.i, c2.i, c2.y - c1.y));
        G[c2.i].edges.push_back(Edge(c2.i, c1.i, c2.y - c1.y));
    }

    // prim
    priority_queue<Data, vector<Data>, greater<Data> > pq;
    Edge e0(-1, 0, 0);
    pq.push(Data(0, &e0));

    ll cost = 0;

    while (!pq.empty()){
        Data d = pq.top(); pq.pop();
        Edge& e = *d.edge;
        Node& n = G[e.to];
        if (n.dist != INFTY){ continue; }
        n.dist = 0;
        cost += e.cost;

        for (auto &ee : n.edges){
            Data d(ee.cost, &ee);
            pq.push(d);
        }
    }

    cout << cost << endl;

}

Measured memory_bytes: 21228
//インクルード(アルファベット順)
#ifndef TEMPLATE
#define TEMPLATE
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<ctime>
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
//#include<unordered_map>//イテレータあるけど順序保持しないmap
//#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
#include<valarray>//なんとなく追加
//メモ：表示桁数を大きくする　　cout << fixed << setprecision(20) << cm << endl;
using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define PI acos(-1.0)
#define answer(ans) cout<<ans<<endl;
#define input(N) cin >> N ;

#endif // TEMPLATE




signed main() {
int N,ans;
cin >> N;
if(N==0) ans=1;
else ans=0;

answer(ans);
return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a, b, c, d;
	cin >>a>>b >> c >> d;
	long long ans = 0, ans1=0, ans2 = 0, ans3 = 0;
	ans = a*c;
	ans1 = b*d;
	ans2 = d*a;
	ans3 = c*b;
	cout << max({ans, ans1, ans2, ans3}) <<endl;
	
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<stack>
using namespace std;
#define MAX 100000
#define NIL -1

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r,int c)
{
    stack<int> s;
    s.push(r);
    color[r]=c;
    while(!s.empty())
    {
        int u=s.top();s.pop();
        for(int i=0;i<G[u].size();i++)
        {
            int v=G[u][i];
            if(color[v]==NIL)
            {
                color[v]=c;
                s.push(v);
            }
        }
    }
}

void assignColor()
{
    int id=0;
    for(int i=0;i<n;i++)
    {
        color[i]=NIL;
    }
    for(int u=0;u<n;u++)
    {
        if(color[u]==NIL)dfs(u,id);
        id++;
    }
}

int main()
{
    int s,t,m,q;
    cin >> n >> m;

    for(int i=0;i<m;i++)
    {
        cin >> s >>t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >>q;
    for(int i=0;i<q;i++)
    {
        cin >> s >> t;
        if(color[s]==color[t]){
            cout << "yes" << endl;
        }else
        {
            cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 8964
# ABC068C - Cat Snuke and a Voyage (ARC079C)
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    s, d = set(), set()  # start, destination
    for _ in range(m):
        a, b = map(int, input().split())
        if a == 1:
            s.add(b)  # 1 to X
        elif b == n:
            d.add(a)  # X to n
    # if the same X in both s & d -> possible
    print("POSSIBLE" if s & d else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 18884
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int c[6];
	rep(i,6)cin>>c[i];
	int sum=c[0]+c[1]*5+c[2]*10+c[3]*50+c[4]*100+c[5]*500;
	if(sum>=1000)cout<<1<<endl;
	else cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include<iostream>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int s1=s.size(),t1=t.size();
	string dp[2][t1+1];
	for(int i=0;i<=t1;++i)
		dp[0][i]="";
	for(int i=1;i<=s1;++i)
	{
		dp[1][0]="";
		dp[0][0]="";
		for(int j=1;j<=t1;++j)
		{
			if(s[i-1]==t[j-1])
			{
				dp[1][j]=dp[0][j-1];
				dp[1][j]+=s[i-1];
			}
			else
			{
				if(dp[0][j].size()>dp[1][j-1].size())
					dp[1][j]=dp[0][j];
				else
					dp[1][j]=dp[1][j-1];
			}
		}

		for(int k=0;k<=t1;++k)
			dp[0][k]=dp[1][k];
	}
	cout<<dp[1][t1];
}


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

int main (void)
{
    int n;
    cin >> n;
    vector<pair<ll,ll>> x(n);

    for (int i = 0;i < n;i++)
    {
        ll _x,_y;
        cin >> _x >> _y;
        x[i].first = _x-_y;
        x[i].second = _x+_y;
    }
    
    sort(x.begin(),x.end(),
         [](pair<ll,ll> a, pair<ll,ll> b)
         {
             if (a.second == b.second) return a.first < a.second;
             else return a.second < b.second;
         });

    int ans = 1;
    ll posi = x[0].second;
    for (int i = 1;i < n;i++)
    {
        if (posi > x[i].first) continue;
        posi = x[i].second;
        ans++;
    }

    cout << ans << endl;

    
    
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <stdlib.h>

using namespace std;

string S;

int main(void)
{
	cin >> S;
	S = "#" + S + "#";
	int l = S.size();
	
	int ans = 0;
	
	int cnt_i, cnt_j;
	int i = 0, j = l-1;
	
	while(i < j){
		cnt_i = cnt_j = 0;
		i++, j--;
		for(;S[i] == 'x'; i++) cnt_i++;
		for(;S[j] == 'x'; j--) cnt_j++;
		if(S[i] != S[j]){
			ans = -1;
			break;
		}
		ans += abs(cnt_i - cnt_j);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
using namespace std;
typedef long long LL;

int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(a + b > c + d) cout << "Left" << endl;
	else if(a + b < c + d) cout << "Right" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
t_hp, t_atk, a_hp, a_atk = gets.split.map(&:to_i)
result = 'No'
while t_hp > 0 || a_hp > 0
  a_hp = a_hp - t_atk
  if 0 >= a_hp 
    result = 'Yes'
    break
  end
  t_hp = t_hp - a_atk
  if 0 >= t_hp 
    break
  end
end

puts result

Measured memory_bytes: 14264
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  string s;
  cin >> s;
  int ans = n-1;
  int face = 0;
  for(int i=1;i<n;i++){
    if(s[i] != s[i-1])face++;
  }
  
  face -= k*2;
  ans -= max(face,0);
  cout << ans << endl;
  

}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int n;
int a[3030];
ll dp[3010][3010];

ll rec(int i, int j) {
  if (0 < dp[i][j]) return dp[i][j];
  if (i == j) return a[i];
  ll res1 = 1ll * a[i] - rec(i + 1, j);
  ll res2 = 1ll * a[j] - rec(i, j - 1);
  return dp[i][j] = max(res1, res2);
}

int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      dp[i][j] = -1e18;
    }
  }
  cout << rec(1, n) << endl;
  return 0;
}

Measured memory_bytes: 71040
import java.util.*;

class Main {
	public static void main(String[] args) {
      	Scanner sc = new Scanner(System.in);
      	int a = sc.nextInt();
      	int b = sc.nextInt();
      	String ans = "";
      
      	if (a <= 8 && b <= 8) {
          ans = "Yay!";
        } else {
          ans = ":(";
        }
      	
      System.out.println(ans);
    } 
}

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

#define ll long long

vector <int> V;
ll n,W,w,v;
ll dp[110][100010];

int main()
{
    cin >> n >> W;
    for (int i=1;i<=n;i++){
        cin >> w >> v;
        for (int j=1;j<=W;j++){
            dp[i][j]=dp[i-1][j];
            if (j-w>=0) dp[i][j]=max(dp[i][j],dp[i-1][j-w]+v);
        }
    }
    cout << dp[n][W];
}


Measured memory_bytes: 81640
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long dp[1010][1010];
int main(){
	cin>>n>>m;
	dp[1][1]=1;
	char ch;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++){
			cin>>ch;
			if(ch=='.'){
				dp[i][j]+=(dp[i-1][j]+dp[i][j-1])%(1000000007);
			}
		}
	cout<<dp[n][m];
	return 0;
}

Measured memory_bytes: 8192
#include<cstdio>
#include<algorithm>
#include<iostream>
typedef long long ll;
using namespace std;

ll T,a,b,c,d,g;
ll gcd(ll a,ll b){ return b ? gcd(b,a%b) : a; }

int main(){
	for (cin>>T; T--; ){
		cin>>a>>b>>c>>d; g=gcd(d,b);
		if (a<b || d<b || (a-(a-c-1)/g*g)-b<0) cout<<"No\n"; else cout<<"Yes\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n, w; cin >> n >> w;
  vector<int> a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  vvi dp(n+1, vi(w+1, -1));
  dp[0][0] = 1;
  for(int i=0;i<n;++i) {
    vvi nxt(n+1, vi(w+1, -1));
    for(int j=0;j<=n;++j) {
      for(int k=0;k<=w;++k) {
        if(dp[j][k] == -1) continue;
        nxt[j][k] = max(0, nxt[j][k]) + dp[j][k];
        nxt[j][k] %= MOD;
        if(k+a[i] <= w) {
          if(i == j) {
            nxt[i+1][k+a[i]] = max(0, nxt[i+1][k+a[i]]) + dp[j][k];
            nxt[i+1][k+a[i]] %= MOD;
          } else {
            nxt[j][k+a[i]] = max(0, nxt[j][k+a[i]]) + dp[j][k];
            nxt[j][k+a[i]] %= MOD;
          }
        }
      }
    }
    dp = nxt;
  }
  ll ans = 0;
  for(int i=0;i<=n;++i) {
    for(int j=0;j<=w;++j) {
      if(i == n || j + a[i] > w) {
        ans += max(0, dp[i][j]);
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
}



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

int main(){
	string s; cin>>s;
	int ans1=0,ans2=0;
	for(int i=0;i<s.size();++i){
		if((i&1)!=s.at(i)-'0')++ans1;
		else ++ans2;
	}
	cout<<min(ans1,ans2)<<"\n"s;
}

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
  int n,i,l;
  int max = 0;
  int sum = 0;
  
  scanf("%d", &n);
  
  for (i = 0; i < n; i++){
    scanf("%d ", &l);
    sum += l;
    if (l > max){
      max = l;
    }
  }
  
  sum -= max;
  if (sum > max){
    printf("Yes");
  } else {
    printf("No");
  }
  
  return 0;
}

Measured memory_bytes: 128
T_str=input()
T=list(T_str)

if T[0]=="?":T[0]="D"

for i in range(1,len(T)):
    if T[i]=="?":
        if T[i-1]=="P":T[i]="D"
        else:T[i]="D"
    else:pass

print("".join(T))
    

Measured memory_bytes: 10672
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(vec) (vec).begin(), (vec).end()
#define SUM(...) accumulate(ALL(__VA_ARGS__),0LL)
#define DSUM(...) accumulate(ALL(__VA_ARGS__),0.0)
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 便利関数
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

// 初期時読み込み
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;

const int INF = 2002002002;

void solve(long long x, long long a, long long b){
    if (abs(x - a) < abs(x - b)) print('A');
    else print('B');
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long x;
    scanf("%lld",&x);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(x, a, b);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n; cin>>n;
ll a[n]={};
ll b[n]={};
for(ll i=0; i<n; i++){
cin>>a[i];
b[i]=a[i];}
sort(b,b+n);
ll m=b[n-1];
ll m1=b[n-2];
for(ll i=0; i<n; i++){
if(m==a[i]){
cout<<m1<<endl;}
else{
cout<<m<<endl;}}}

Measured memory_bytes: 4736
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		in.close();
		System.out.println(debtHell(n));
	}

	static int debtHell(int n) {
		double debt = 100000;
		for (int i = 0; i < n; i++) {
			debt *= 1.05;
			//System.out.print(debt);
			debt = Math.ceil(debt / 1000.0) * 1000;
			//System.out.println("\t" + debt);
		}
		return (int) debt;
	}
}

Measured memory_bytes: 26120
#include <iostream>
using namespace std;
int main()
{
	int priceA, priceB, priceAB, numA, numB, total_price;
  	cin >> priceA >> priceB >> priceAB >> numA >> numB;
  	if (priceA + priceB <= priceAB * 2){
    	total_price = priceA * numA + priceB * numB;
    } else {
    	if (numA > numB){
        	if (priceA > priceAB * 2){
            	total_price = priceAB * numA * 2;
            } else {
            	total_price = priceAB * numB * 2 + priceA * (numA - numB);
            }
        } else if (numA < numB){
        	if (priceB > priceAB * 2){
            	total_price = priceAB * numB * 2;
            } else {
            	total_price = priceAB * numA * 2 + priceB * (numB - numA);
            }
        } else {
        	total_price = priceAB * numA * 2;
        }
    }
  	cout << total_price;
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			int z = scanner.nextInt();
			if ((x | y | z) == 0)
				break;
			int[] v = new int[x];
			for (int i = 0; i < x; i++) {
				v[i] = scanner.nextInt();
			}
			int[][] ev = new int[y + 1][2];
			for (int i = 0; i < z; i++) {
				int b = scanner.nextInt();
				ev[b][0] = scanner.nextInt();
				ev[b][1] = scanner.nextInt();
			}
			Map<Integer, double[]> memo = new HashMap<Integer, double[]>();
			double[] a = new double[y + 1];
			a[0] = 1.0;
			memo.put(0, a);
			for (int i = 0; i < y; i++) {
				Map<Integer, double[]> tmpMap= new HashMap<Integer, double[]>();
				tmpMap.putAll(memo);
				for (Iterator<Entry<Integer, double[]>> iterator = memo
						.entrySet().iterator(); iterator.hasNext();) {
					Entry<Integer, double[]> entry = iterator.next();
					
					if (entry.getValue()[i] == 0)
						continue;
					for (int j = 0; j < x; j++) {
						int key = entry.getKey();
						double[] val = entry.getValue();
						int nm = Math.min(y, i + v[j]);
						if (ev[nm][0] == 1)
							nm = Math.min(y, nm + ev[nm][1]);
						else if (ev[nm][0] == 2)
							key += ev[nm][1];
						else if (ev[nm][0] == 3)
							key = Math.max(0, key - ev[nm][1]);
						if (!tmpMap.containsKey(key)) {
							double[] d = new double[y + 1];
							d[nm] = val[i] / x;
							tmpMap.put(key, d);
						} else {
							double[] d = tmpMap.get(key);
							d[nm] += val[i] / x;
						}
					}
				}
				memo = tmpMap;

			}
			double ans = 0;
			for (Entry<Integer, double[]> entry : memo.entrySet()) {
				ans += entry.getKey() * entry.getValue()[y];
			}
			System.out.println((int) ans);
		}
	}
}

Measured memory_bytes: 70436
def ch(s):
	a = True
	for k, x in enumerate(s):
		if x != s[-k-1]:
			a = False
			break
	return a

s = input()
ns = s.replace("x", "")
if ch(ns):
	a = [0]*(len(ns)+1)
	k = 0
	b = True
	for i in s:
		if b:
			if i == 'x':
				a[k] += 1
			else:
				b = False
				k += 1
		else:
			if i == 'x':
				b = True
				a[k] += 1
			else:
				k += 1
	k = 0
	for i in range(len(a)//2):
		if a[i] != a[-i-1]:
			k += abs(a[i] - a[-i-1])
	print(k)
else:
	print(-1)

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i = (int)(n)-1; i>=0; --i)
#define For(i,a,b) for(auto i=(a);i<=(b);++i)
#define rFor(i,a,b) for(auto i=(b);i>=(a);--i)
#define call(var) cerr<<#var<<"="<<var<<"\n";
#define dup(x,y) (((x)+(y)-1)/(y))
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const double pi = acos(-1);
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}
template<class T> istream& operator>>(istream& is, vector<T>& a){rep(i,a.size()) is >> a[i]; return is;}
template<class T> ostream& operator<<(ostream& os, vector<T>& a){rep(i,a.size()) os << a[i] << " "; return os;}
template<class T, class U> istream& operator>>(istream& is, pair<T,U>& p){is >> p.first >> p.second; return is;}
template<class T, class U> ostream& operator<<(ostream& os, const pair<T,U>& p){os << "("<< p.first << "," << p.second << ")"; return os;}
template<class T, class U> ostream& operator<<(ostream& os, const map<T,U>& mp){for(auto& t : mp) os << t.first << " " << t.second << "\n"; return os;}

int main(){
    int n;cin >> n;
    for(int i=1;i<=n;++i){
        int ans = 0;
        for(int x=1;x*x<=i;++x){
            for(int y=1;y*y + x*x + x*y<=i;++y){
                for(int z=1;x*x + y*y + z*z + x*y + y*z + z*x<=i;++z){
                    if(x*x + y*y + z*z + x*y + y*z + z*x == i){
                        ++ans;
                    }
                }
            }
        }
        //cerr << "i = " << i << " : ";
        cout << ans << endl;
    }
}

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

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
using namespace std;
int mod = 1'000'000'000 + 7;
struct edge {
    int to;
    ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int main() {
    COME_LET_THE_GAMES_BEGIN();
    ll N, a[100];
    cin >> N;
    rep(i, N)cin >> a[i];
    ll ans = LLONG_MAX;
    for (int i = -100; i <= 100; i++) {
        ll r = 0;
        rep(j, N) {
            r += pow(a[j] - i, 2);
        }
        ans = min(ans, r);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
h = [int(x) for x in input().split()]
ans_li = [True] * n
ans = 0
for i in range(m):
    a,b = map(int,input().split())
    tmp1 = h[a-1]
    tmp2 = h[b-1]
    if tmp1 > tmp2:
        ans_li[b-1] = False
    elif tmp1 < tmp2:
        ans_li[a-1] = False
    elif tmp1 == tmp2:
        ans_li[a-1] = False
        ans_li[b-1] = False

for i in range(len(ans_li)):
    if ans_li[i] == True:
        ans += 1

print(ans)


Measured memory_bytes: 20048
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static int[] sumA;
	static int[] sumB;
	static List<List<Integer>> list;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sumA = new int[n];
		sumB = new int[n];
		list = new ArrayList<>(n);
		for(int i = 0; i < n; i++) list.add(new ArrayList<>());
		for(int i = 0; i < n - 1; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			list.get(a).add(b);
			list.get(b).add(a);
		}
		dfsA(0, -1, 0);
		dfsB(n - 1, -1, 0);
		int a = 0, b = 0;
		for(int i = 0; i < n; i++) {
			if(sumA[i] <= sumB[i]) a++;
			else b++;
		}
		if(a > b) {
			System.out.println("Fennec");
		} else {
			System.out.println("Snuke");
		}
//		System.out.println(Arrays.toString(sumA));
//		System.out.println(Arrays.toString(sumB));
	}

	static void dfsA(int s, int p, int d) {
		List<Integer> edge = list.get(s);
		for(int v : edge) {
			if(p != v) {
				sumA[v] = d + 1;
				dfsA(v, s, d + 1);
			}
		}
	}

	static void dfsB(int s, int p, int d) {
		List<Integer> edge = list.get(s);
		for(int v : edge) {
			if(p != v) {
				sumB[v] += sumB[s] + 1;
				dfsB(v, s, d + 1);
			}
		}
	}

}


Measured memory_bytes: 111492
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
r_num = t.count("r")
s_num = t.count("s")
p_num = t.count("p")
for i in range(n-k):
    if t[i] == t[i+k]:
        if t[i] == "r":
            r_num -= 1
        elif t[i] == "s":
            s_num -= 1
        else:
            p_num -= 1
        t[i+k] = "a"
print(p*r_num + r*s_num + s*p_num)

Measured memory_bytes: 4084
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int N;
vector <int > H;





int main()
{

	cin >> N;


	int ans=0;
	REP(i,N){
		int a,b;
		cin >>a>>b;
		ans+=b-a+1;
	}
	cout << ans << endl;




}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x=scan.nextInt();
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=(x-a);
		System.out.println(c%b);

	}

}


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

int main(){
  int n , y;
  cin >> n >> y;
  int res10000 = -1, res5000 = -1, res1000 = -1;
  for(int a = 0; a <= n; ++a) {
    for( int b = 0; b + a <= n; ++b ){
      int c = n - a - b;
      int total = 10000*a + 5000*b + 1000*c;
      if(total == y){
        res10000 = a;
        res5000 = b;
        res1000 = c;
      }
    }
  }
  cout << res10000 << " " << res5000 << " " << res1000 << endl;
  return 0;
}


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

using namespace std;
typedef pair<int, int> pii;

int main(){
	int caseNum = 1;
	while(true){
		int W, N;
		cin >> W;
		if(W == 0){ break; }
		cin >> N;
		vector<pii> items(N);
		for(int i = 0; i < N; ++i){
			char c;
			cin >> items[i].first >> c >> items[i].second;
		}
		vector<int> dp(W + 1, -1);
		dp[0] = 0;
		for(int i = 0; i < N; ++i){
			for(int j = W; j >= 0; --j){
				if(dp[j] < 0){ continue; }
				int weight = j + items[i].second;
				if(weight > W){ continue; }
				dp[weight] = max(dp[weight], dp[j] + items[i].first);
			}
		}
		int answer = 0;
		for(int i = 0; i <= W; ++i){
			if(dp[i] > dp[answer]){ answer = i; }
		}
		cout << "Case " << caseNum++ << ":" << endl;
		cout << dp[answer] << endl << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()

from collections import defaultdict

def main():
    N, M = LI()
    edges = defaultdict(list)
    for _ in range(M):
        a, b = LI_()
        edges[a].append(b)
        edges[b].append(a)
    quads = []
    large = 0
    for i, e in edges.items():
        c = len(e)
        if c % 2 == 1:
            return 'No'
        if c >= 6:
            large += 1
        if c == 4:
            quads.append(i)
    if large > 0:
        return 'Yes'
    if len(quads) > 2:
        return 'Yes'
    if len(quads) < 2:
        return 'No'
    for v in edges[quads[0]]:
        visited = [0] * N
        visited[quads[0]] = 1
        while v != quads[1]:
            visited[v] = 1
            for to in edges[v]:
                if visited[to] == 0:
                    v = to
                    break
            if visited[v] == 1:
                break
        if v != quads[1]:
            return 'Yes'

    return 'No'

print(main())


Measured memory_bytes: 28380
#include<string>
#include<iostream>
using namespace std;
int main(){
    string s,p;
    getline(cin,s);
    getline(cin,p);
    s=s+s;
    for(int i=0;i<(int)s.size();i++){
        for(int j=0;j<(int)p.size();j++){
            if(s[i+j]!=p[j]){
                break;
            }
            if(j==(int)p.size()-1){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){
    double L;
    cin>>L;
    L/=3.0;
    cout<<setprecision(15)<<L*L*L<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
using namespace std;
int main() 
{
    int n;
    float high;
    vector<int> num(6,0);
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%f",&high);
        if (high<165.0) {
            num[0]++;
        }
        else if (high<170.0) {
            num[1]++;
        }
        else if (high<175.0) {
            num[2]++;
        }
        else if (high<180.0) {
            num[3]++;
        }
        else if (high<185.0) {
            num[4]++;
        }
        else {
            num[5]++;
        }
    }
    for (int i=1; i<=6; i++) {
        printf("%d:",i);
        for (int j=0; j<num[i-1]; j++) printf("*");
        printf("\n");
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>                 // [PRIMES]               1777 ~2^10.80
using namespace std;                     //                       10333 ~2^13.33
using ll = long long;                    // seq 1 128 | factor   100333 ~2^16.61
using vl = vector<ll>;                   //   | grep -v ' .* '  1300111 ~2^20.31
using vvl = vector<vl>;                  //                    10300777 ~2^23.30
using pll = pair<ll,ll>;                 //                   100400999 ~2^26.58
using vb = vector<bool>;                 //                  1300400999 ~2^30.28
const ll oo = 0x3f3f3f3f3f3f3f3fLL;      //                 10200500333 ~2^33.25
const double eps = 1e-9;                 //                100200400777 ~2^36.54
#define sz(c) ll((c).size())             //               1200300700111 ~2^40.13
#define all(c) begin(c),end(c)           //              10200300500777 ~2^43.21
#define mp make_pair                     //             100200300400777 ~2^46.51
#define mt make_tuple                    //            1200300400600999 ~2^50.09
#define pb push_back                     //           10200300400600111 ~2^53.18
#define eb emplace_back                  //          100200300400600333 ~2^56.48
#define xx first                         //         1200300400500800999 ~2^60.06
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

ll n_slimes;
vvl slimes;
vvl dp;

//begin inclusive, end exclusive
ll rec(ll begin_slime, ll end_slime){

    if(begin_slime+1 == end_slime){
        return 0;
    }
    if(dp[begin_slime][end_slime-1] != -1){
        return dp[begin_slime][end_slime-1];
    }
    ll res = oo;
    FOR(i, begin_slime+1, end_slime){
        ll left_res = rec(begin_slime, i);
        ll right_res = rec(i, end_slime);
        ll tmp_new = left_res + right_res + slimes[i-begin_slime-1][begin_slime] + slimes[end_slime-i-1][i];
        res = min(tmp_new, res);
    }
    dp[begin_slime][end_slime-1] = res;
    return res;
}


int main() {

    cin >> n_slimes;
    slimes.assign(n_slimes, vl(n_slimes, 0));
    dp.assign(n_slimes, vl(n_slimes, -1));
    FOR(i, 0, n_slimes){
        cin >> slimes[0][i];
    }

    FOR(i, 1, n_slimes){
        FOR(j, 0, n_slimes-i){
            slimes[i][j] = slimes[i-1][j] + slimes[0][j+i];
        }
    }
   
    cout << rec(0, n_slimes) << endl;

    return 0;
}



Measured memory_bytes: 2816
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int ans = 0;
	rep(i,s.size()){
		if(s[i] == '0') ++ans;
	}
	ans = min(ans, (int)s.size()-ans) * 2;
	cout << ans << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int g[100][100];

int main() {
  int n;
  cin >> n;
  REP(i, n) {
    int u, k;
    cin >> u >> k;
    REP(j, k) {
      int v;
      cin >> v;
      g[u - 1][v - 1] = 1;
    }
  }
  REP(i, n) {
    REP(j, n) {
      if (j) cout << " ";
      cout << g[i][j];
    }
    cout << "\n";
  }
  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    int n; cin >> n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < n - 2; i++){
        if(s[i] == 'A'){
            if(s[i+1] == 'B' && s[i+2] == 'C'){
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint a,b;

void solve(){
  cin >> a >> b;
  cout << a*b  << " " << 2*a+2*b<< endl;
}

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



Measured memory_bytes: 3092
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

template <class T>void Sort(vector<T> & a) { sort(a.begin(), a.end()); }
template <class T>void ReSort(vector<T>& a) { sort(a.rbegin(), a.rend()); }
template <class T>void Reverse(vector<T>& a) { reverse(a.begin(), a.end()); }
template <class T>void Unique(vector<T>& a) { a.erase(unique(a.begin(), a.end()), a.end()); }
template <class T>T Sum(vector<T> a, T init = 0) { return accumulate(a.begin(), a.end(), init); }

//INPUT//
void CINPUT() {}
template<class H, class ...T> void CINPUT(H&& h, T&& ...t) { cin >> h; CINPUT(forward<T>(t)...); }
#define in(...) int __VA_ARGS__; CINPUT(__VA_ARGS__);
#define In(T,...) T __VA_ARGS__; CINPUT(__VA_ARGS__);
#define Vin(T,name,n) int n; cin>>n; vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn(T,name,n) vector<T> name(n); rep(i,n)cin>>name[i];
#define VIn2(T,name,name2,n) vector<T> name(n),name2(n); rep(i,n)cin>>name[i]>>name2[i];

//OUTPUT//
void print() { cout << endl; }
template <class H> void print(H&& h) { cout << h << endl; }
template <class H, class... T> void print(H&& h, T&& ... t) { cout << h << " "; print(forward<T>(t)...); }
template<class T>void out(T n) { cout << n << endl; }
template<class T>void out(vector<T> a, string sep = " ", string end = "\n") { for (int i = 0; i < (int)a.size(); ++i)cout << a[i] << (i == (int)a.size() - 1 ? end : sep); }
void yes(bool f) { puts(f ? "yes" : "no"); }
void Yes(bool f) { puts(f ? "Yes" : "No"); }
void YES(bool f) { puts(f ? "YES" : "NO"); }
void poss(bool f) { puts(f ? "possible" : "impossible"); }
void Poss(bool f) { puts(f ? "Possible" : "Impossible"); }
void POSS(bool f) { puts(f ? "POSSIBLE" : "IMPOSSIBLE"); }

int main() {
	in(h, w);
	VIn(string, c, h);
	rep(i, h) { out(c[i]); out(c[i]);
	}
}

Measured memory_bytes: 256
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            var swapNum = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                for (int j = nums.Length-1; j>i; j--)
                {
                    if (nums[j] < nums[j - 1])
                    {
                        Swap(ref nums[j], ref nums[j - 1]);
                        swapNum++;
                    }
                }
            }

            Console.WriteLine(string.Join(" ",Array.ConvertAll(nums,x=>x.ToString())));
            Console.WriteLine(swapNum);
        }

        private static void Swap<T>(ref T p1, ref T p2)
        {
            var temp = p1;
            p1 = p2;
            p2 = temp;
        }
    }
}

Measured memory_bytes: 17864
#include <iostream>

using namespace std;

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

int inout[10010][1300];
int use[10010][1300];

int main(){
    while(true){
        int N, M, r;
        cin >> N >> M;
        if (N==0) break;

        cin >> r;

        REP(i, M){
            REP(j, 1261){
                inout[i][j] = 0;
                use[i][j] = 0;
            }
        }

        REP(i, r){
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            if (s==1) {
                inout[m-1][t] += 1;
            } else {
                inout[m-1][t] += -1;
            }
        }

        // syakutori method
        REP(i, M) {
            int status = 0;
            for (int t=540; t<=1260; t++) {
                status += inout[i][t];
                use[i][t] = status;
            }
        }

        int q;
        cin >> q;
        REP(i, q) {
            int ts, te, m;
            cin >> ts >> te >> m;
            int output = 0;
            for (int t=ts; t<te; t++) {
                if (use[m-1][t] > 0) {
                    output += 1;
                }
            }
            printf("%d\n", output);
        }
    }
}



Measured memory_bytes: 101388
n, k = map(int, input().split())
ans = 0
for x in range(1, n + 1):
    tmp = x
    count = 0
    while True:
        if tmp >= k:
            break
        tmp *= 2
        count += 1
    if x < k:
        ans += (1 / n) * ((1 / 2)**count)
    else:
        ans += (1/n)
    count -= 1

print(ans)


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

typedef long long int ll;

int main()
{
    ll n, k;
    cin >> n >> k;
    vector<ll> x(n);
    for(ll i = 0;i < n;i++){
        cin >> x[i];
    }

    ll ans = 0;
    for(ll i = 0;i < n;i++){
        ans += min(x[i] - 0, k - x[i]);
    }

    ans *= 2;

    cout << ans;
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}


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

	ll  d, n, m, k, ans = 0, ret = M;
	bool flag = false, flag2 = false;
	string s, t;
	cin >> s;
	rep(i, s.size()) if (s[i] == 'p') ans++;
	cout << s.size()/2 - ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int a, b;
    cin >> a >> b;
    if (a > b) swap(a, b);
    char c = a + '0';
    rep(i, b) cout << c;
    cout << endl;
}


Measured memory_bytes: 256
def check(ymd):
        if ymd < 18680908:
            print "pre-meiji"
        elif ymd < 19120730:
            print "meiji",y-1867,m,d
        elif ymd < 19261225:
            print "taisho",y-1911,m,d
        elif ymd < 19890108:
            print "showa",y-1925,m,d
        else:
            print "heisei",y-1988,m,d

while True:
    try:
        y, m, d = map(int, raw_input().split())
        ymd = 10000*y + 100*m + d
        check(ymd)
    except:
        break

Measured memory_bytes: 4208
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
set<int> s[200005];


int main() {
    int n;cin >> n;
    vector<int> a(n);
    for(int i = 1;i<=n;i++){
        for(int j = 2;j*i<=n;j++){
            s[j * i].insert(i);
        }
    }
    rep(i,n)cin >> a[i];
    vector<int> piyo(n);
    rep(i,n)piyo[i] = a[i];
    rrep(i,n){
        int f = a[i];
        if(f&1){
            for(auto v:s[i+1]){
                a[v-1] =! a[v-1];
            }
        }
    }
    // rep(i,n)cerr << a[i] << " ";;
    // cerr << endl;
    rep(i,n){
        int ans = 0;
        for(int j = i  ;j<n;j+=i+1){
            ans+= a[j];
        }
        //cout << ans << " " << piyo[i]<< " " << ans << endl;
        if((ans&1) != piyo[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    int m = 0;
    rep(i,n){
        if(a[i])m++;
    }
    cout << m << endl;
    rep(i,n){
        if(a[i])cout << i + 1 << endl;
    }

 }


Measured memory_bytes: 118272
#include<stdio.h>
#include<stdlib.h>
        int h[100000];
        int dp[100000]={0};
     
    int min(int a,int b){
        return a<b?a:b;
    }
     
    int main(){
        int n;
     
        int i;;
        scanf("%d",&n);
        for(i=0;i<n;i++){
            scanf("%d",&h[i]);
        }
     
        dp[1]=abs(h[1]-h[0]);
     
        for(i=2;i<n;i++){
            dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
        }
        printf("%d\n",dp[n-1]);
    }

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint32_t X, A;
  cin >> X >> A;

  if (X < A) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }

  return 0;
}


Measured memory_bytes: 256