akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <sstream>
using namespace std;
int main(){
int x,a,b;
cin>>x>>a>>b;
int ai=abs(a-x);
int bi=abs(b-x);
if(ai>bi){
	cout<<"B"<<endl;
}else if(ai<bi){
	cout<<"A"<<endl;
}
return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
ks = [[0] for i in range(m)]
jud = []
for i in range(m):
    tmp = list([int(i)-1 for i in input().split()])
    ks[i] = tmp[1:]
jud = list(map(int, input().split()))

ans = 0
c = True
for i in range(2 ** n):
    c = True
    ib = format(i, 'b')
    for iks, j in enumerate(ks):
        ch = 0
        for m in j:
            if len(ib) >= m+1:
                ch += int(ib[-m-1])
        if ch % 2 != jud[iks]:
            c = False
            break
    if c:
        ans += 1
print(ans)


Measured memory_bytes: 40432
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int A, B, M;
	cin >> A >> B >> M;
	
	vector<ll> a(A), b(B);
	for(int i = 0; i < A; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < B; ++i) {
		cin >> b[i];
	}
	
	ll amin = *min_element(a.begin(), a.end());
	ll bmin = *min_element(b.begin(), b.end());
	
	ll ans = amin + bmin;
	
	vector<int> x(M), y(M);
	vector<ll> c(M);
	
	for(int i = 0; i < M; ++i) {
		cin >> x[i] >> y[i] >> c[i];
		
		ans = min(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3328
def dp_table(*counts):  # dp[x][y]を作りたかったら dp_table(xのサイズ,yのサイズ)
    if counts:
        return [dp_table(*counts[1:]) for _ in range(counts[0])]
    else:
        return 0


def main():

    N = int(input())
    A = [int(input()) for _ in range(N)]
    mod = 998244353
    ans = pow(3, N, mod)
    sum_A = sum(A)
    dp = [[0] * (sum_A+1) for i in range(N)]
    # dp[i][j]: i番目までの中から辺をいくつか選んで、長さがjになるパターン数

    # init
    dp[0][A[0]] = 1
    dp[0][0] = 2  # 他の色のうちどちらに入れるかで2通り

    # init2
    dp2 = [[0] * (sum_A+1) for i in range(N)]  # ある二色でsum_Aを等分するパターンを数える
    dp2[0][A[0]] = 1
    dp2[0][0] = 1  # 今度は片方に集中したパターン

    # dp
    sum_now = A[0]
    for i in range(1, N):
        a = A[i]
        sum_now += a
        for length in range(sum_now+1):
            # A[i]を追加しないのなら他の２食のうちどちらに入れるかで2倍選択肢がある
            if length >= a:
                dp[i][length] = dp[i - 1][length - a] + \
                    (dp[i - 1][length] << 1)
            else:
                dp[i][length] = dp[i-1][length] << 1
            dp[i][length] %= mod

        for length in range(min(sum_now + 1, sum_A // 2 + 1)):
            if length >= a:
                dp2[i][length] = dp2[i - 1][length - a] + dp2[i - 1][length]
            else:
                dp2[i][length] = dp2[i-1][length]
            dp2[i][length] %= mod
    # print(sum(dp[N-1][sum_A//2]))
    # print(dp)
    ans -= 3*sum(dp[N-1][(sum_A+1)//2:])
    if sum_A % 2 == 0:
        ans += 3*dp2[N-1][sum_A//2]
    print(ans % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 455964
n=int(input())
b=list(map(int,input().split()))

if n==2:
    print(b[0]*2)
    exit(0)

a=[]
    
a.append(b[0])
a.append(b[n-2])

for i in range(len(b)-1):
    a.append(min(b[i],b[i+1]))
print(sum(a))



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

const int maxn = 3005;
vector<vector<pair<long long, int>>> dp;

pair<long long, int> f(int left, int right, const vector<int> &v) {
  if (left > right) {
    return {0, 0};
  }

  if (left == right) {
    return {v[left], 0};
  }

  if (dp[left][right] == make_pair(-1LL, -1)) {
    auto a = f(left + 1, right, v);
    auto b = f(left, right - 1, v);

    long long score_a = v[left] + (a.second == 0 ? (f(left + 2, right, v)).first : (f(left + 1, right - 1, v)).first);
    long long score_b = v[right] + (b.second == 0 ? (f(left + 1, right - 1, v)).first : (f(left, right - 2, v)).first);

    if ((score_a - a.first) >= (score_b - b.first)) {
      dp[left][right] = {score_a, 0};
    } else {
      dp[left][right] = {score_b, 1};
    }
  }

  return dp[left][right];
}

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

  vector<int> v(n);
  for (auto &x : v) cin >> x;

  dp.resize(maxn);
  for (auto &v : dp) {
    v.resize(maxn);
    fill(v.begin(), v.end(), make_pair(-1LL, -1));
  }

  auto score = f(0, n - 1, v);
  long long ans = score.first - (score.second == 0 ? (f(1, n - 1, v)).first : (f(0, n - 2, v)).first);
  cout << ans << endl;

  return 0;
}


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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    
    int ans=0;
    rep(i,N-2){
        if(S[i]=='A' && S[i+1]=='B' && S[i+2]=='C') ans++;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    long long a;
    long long ans = 1;
    long long up = std::pow(10,18);
    for (int i = 0; i < n; i++)
    {
      cin >> a;
      if (a == 0 || ans == 0) {
        ans = 0;
      }
      else if (ans > 0 && ans <= up / a) {
        ans *= a;
      }
      else {
        ans = -1;
      }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
N = gets.strip.to_i

def chmin(a, b) a < b ? a : b end

INF = N
dp = Array.new(1001000) { INF } 

dp[0] = 0
N.times do |i|
  dp[i + 1] = chmin(dp[i] + 1, dp[i + 1])

  [6, 9].each do |p|
    j = p
    while j <= N
      dp[i + j] = chmin(dp[i] + 1, dp[i + j])
      j *= p
    end
  end
end

puts dp[N]


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

int main(){
    int n, m;
    cin >> n >> m;
    int k[m], s[10][10];
    rep(i, m){
        cin >> k[i];
        rep(j, k[i]){
            cin >> s[i][j];
        }
    }
    int p[m];

    rep(i, m){
        cin >> p[i];
    }

    int cnt = 0;
    rep(i, (int)pow(2,n)){
        int aa = i;
        int a[n];
        rep(j, n){
            if(aa%2==1){
                a[j]=1;
            }else{
                a[j]=0;
            }
            aa /= 2;
        }
        bool f = true;
        rep(j, m){
            int sum = 0;
            rep(l, k[j]){
                sum += a[s[j][l]-1];
            }
            // printf("%d %d\n", j, sum);
            if(sum%2 != p[j]){
                f = false;
            }
        }

        if(f){
            // printf("%d\n", i);
            cnt++;
        }
    }

    printf("%d\n", cnt);
    return 0;
}

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

int main() {
  int n;
  vector<int> a;

  cin >> n;
  for (int k = 0; k < n; k++) {
    int t;
    cin >> t;
    a.push_back(t);
  }

  sort(a.begin(), a.end(), greater<int>());

  int ans = 0;
  for (int k = 0; k < n; k++) {
    ans += (k % 2 == 0 ? a[k] : -a[k]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
m = "R"
ans = [0]*len(S)
lcnt, rcnt = 0, 0
tmp = 0
for i in range(len(S)):
    if m =="R" and S[i] =="L":
        tmp = i - 1        
    if i == len(S) - 1 or (m =="L" and S[i] =="R"):
        if i == len(S) - 1: lcnt += 1
        if (rcnt + lcnt) % 2 == 0:
            ans[tmp], ans[tmp + 1] = (rcnt+lcnt)//2, (rcnt+lcnt)//2
        elif (rcnt > lcnt and rcnt%2 == 0) or (lcnt > rcnt and lcnt%2 == 1):
            ans[tmp], ans[tmp + 1] = (rcnt+lcnt)//2, (rcnt+lcnt)//2 + 1
        else:
            ans[tmp], ans[tmp + 1] = (rcnt+lcnt)//2 + 1, (rcnt+lcnt)//2
        rcnt, lcnt = 0, 0
    if S[i] == "L":
        lcnt += 1
        m = "L"
    if S[i] == "R":
        rcnt += 1
        m ="R"
print(*ans)


Measured memory_bytes: 6400
while True :
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    ans = 0
    if op == '?' :
        break
    if op == "+" :
        ans = a + b
    elif op == "-" :
        ans = a - b
    elif op == "*" :
        ans = a * b
    elif op == "/" :
        ans = a // b
    print(ans)




Measured memory_bytes: 5596
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    rep(i, s.size()-1){
        if(s[i] != s[i+1]){
            ans++;
        }
    }
    cout << ans << endl;
}


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

int main(){
  vector<int> data(3);
  int counter = 0;
  for(int i = 0 ;i < 3;i++){
    cin >> data[i];
  }

  sort(data.begin(),data.end());

  counter += data[2] - data[1];
  
  if((data[1] - data[0]) % 2 != 0){
    counter += 1;
    data[1] += 1;
  }

  counter += (data[1] - data[0]) / 2;

  cout << counter << endl;

  
}

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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
//const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    ll ans = 0;
    int prev = 0;
    for (int i=0;i<N;i++){
        if (prev <= A[i]) {
            ans += prev;
            A[i] -= prev;
            ans += A[i]/2;
            prev = A[i]%2;
        } else {
            ans += A[i];
            prev = 0;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3704
#include <iostream>
#include<string>
#include<math.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !

int n;
int m=100000;
cin>>n;
for(;n--;){
if(int(m*1.05)%1000==0) m=int(m*1.05);
else m=int(m*1.05)+(1000-int(m*1.05)%1000); 
}

cout<<m<<endl;
return 0;
}

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

int main(){
	string S;
	cin >> S;
	for(int i(0);i<S.size();++i){
		if(i%2 == 0 && S[i] == 'L'){
			cout << "No" << endl;
			return 0;
		}
		if(i%2 == 1 && S[i] == 'R'){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
origin = S[1:]
summary = [origin.count("E")]
for i in range(N-1):
    s = summary[-1]
    if S[i] == "W":
        if S[i+1] == "E":
            delta = 0
        else:
            delta = 1
    else:
        if S[i+1] == "E":
            delta = -1
        else:
            delta = 0
    summary.append(delta+s)
print(min(summary))  

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

using namespace std;


int main()
{
    int N;
    long long K;
    vector <int> A;
    int temp;

    cin >> N >> K;

    //N = 4;
    //K = 5;
    //int a[] = {3,2,4,1};


    for(int i =0;i < N;i ++){
        cin >> temp;
        A.push_back(temp);
        //A.push_back(a[i]);
    }

    int point = 0;
/*
    while(K > 0){
        point = A.at(point) - 1;
        K --;
    }
    */

   vector <int> r(N,-1);
   r.at(0) = 0;
   int k = 0;
   int check = 0;
   while (K > k)
   {
       k++;
       point = A.at(point) - 1;
       if(r.at(point) != -1){
           check = 1;
           break;
       }
       r.at(point) = k;
   }

   int loop;


   if(check == 1){
       loop = k - r.at(point);
       temp = (K - r.at(point)) % loop;
       while(temp > 0){
           point = A.at(point) - 1;
           temp --;
       }
       cout << point + 1 << endl;
   }else{
       cout << point + 1 << endl;
   }


    return 0;
    

}

Measured memory_bytes: 4696
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

vector<vector<edge>> g;

vector<bool> see;


int main() {

	ll N, K;
	cin >> N >> K;

	ll ans = 1;

	repn(i, N) {
		ans = min(2 * ans, ans + K);
	}

	cout << ans;
	
	system("PAUSE");

	

}


Measured memory_bytes: 504
import sys

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)

for line in sys.stdin:
    a,b = map(int, line.split())
    if a<b:
        tem = a
        a = b
        b = tem
    gc = gcd(a,b)
    print(gc, a*b//gc)

Measured memory_bytes: 7612
import java.util.*;

class Main{
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		int iin = sc.nextInt();
		int iil = 0;
		int iir = 0;
		int retsum = 0;
		for(int i=0;i<iin;i++){
			iil = sc.nextInt();
			iir = sc.nextInt();
			retsum += iir - iil + 1;
		}
		System.out.println(retsum);
    }
}


Measured memory_bytes: 25700
#include <stdio.h>

int main(){
	int a,b,c;
	int sum=0;
	scanf ("%d %d %d", &c,&a,&b);
	for(int i=1;i<=c;i++){
        int x = 0;
        int y = i;
        while(y != 0){
            x += (y%10);
            y = y / 10;
        }
        if(x >= a && x <= b){
        sum += i;
    }
}
	printf("%d",sum);  
    return 0;
}

Measured memory_bytes: 1728
import heapq as hq
n,m=map(int,input().split())
J=[[] for i in range(m)]
for i in range(n):
    a,b=map(int,input().split())
    if a<=m:
        J[a-1].append(b) #日数ごとに報酬を入れる

ans=0
Q=[]
hq.heapify(Q)
for j in J: #最終日から数えてj日目において
    for k in j:
        hq.heappush(Q,-k) #それまでにやるべき仕事を入れる
    if Q:
        ans-=hq.heappop(Q) #今やるべき仕事のなかで一番高いやつを取る
print(ans)

Measured memory_bytes: 18376
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] city = new int[N];

		for(int i = 0; i < M; i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			city[a-1]++;
			city[b-1]++;
		}
		sc.close();

		for(int i = 0; i < N; i++){
			System.out.println(city[i]);
		}
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std; inline void fileio(const char* in, const char* out) { freopen(in, "r", stdin); freopen(out, "w", stdout); } 
#define TD typedef
#define forx(i,n) for(int i = 0; i < (n); ++i)
#define forxr(i,n) for(int i = (n)-1; i >= 0; --i)
TD long long ll; TD long double ld; TD pair<int,int> pii; TD pair<ll,ll> pll; TD vector<int> VI; TD vector<bool> VB; TD vector<ll> VL;
const char nl = '\n'; const int INF = 0x3f3f3f3f; const ll LINF = 0x3f3f3f3f3f3f3f3fll; const ld EPS = 1e-9, PI = acos(-1);
#define ff first
#define ss second
#define all(c) c.begin(),c.end()

const int N = 2e5 + 5;
ll cnt[N];
int a[N];
int n;

int main() { // Emily <3
  atexit([](){ cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << nl; });
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cout << fixed << setprecision(12);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans += cnt[i]*(cnt[i]-1ll)/2ll;
  }
  for (int i = 0; i < n; ++i) {
    if (cnt[a[i]]) {
      cout << (ans - cnt[a[i]] + 1) << nl;
    } else {
      cout << ans << nl;
    }
  }

  return 0;
}



Measured memory_bytes: 3968
#include <iostream>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < n;i++)
int main() {
	int n, ans = 0;cin >> n;vector<int>a(n + 1);
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++) {
		if (i == a[a[i]]) ans++;
	}
	cout << ans / 2 << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
const double EPS=1e-6;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int)((a).size())
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) a.rbegin(),a.rend()
#define FLL(a,b) memset((a),b,sizeof(a))
#define CLR(a) FLL(a,0)
#define declare(a,it) __typeof(a) it=(a)
#define FOR(it,a) for(declare(a.begin(),it);it!=a.end();++it)
#define FORR(it,a) for(declare(a.rbegin(),it);it!=a.rend();++it)
template<class T,class U> ostream& operator<< (ostream& o, const pair<T,U>& v){return o << "(" << v.F << ", " << v.S << ")";}
template<class T> ostream& operator<< (ostream& o, const vector<T>& v){o << "{";rep(i,SZ(v)) o << (i?", ":"") << v[i];return o << "}";}
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
int s2i(string& a){stringstream ss(a);int r;ss>>r;return r;}
int geti(){int n;scanf("%d", &n);return n;}

double dp[20][20][2];

vector<pair<int, double> > G[20][20];
int x[20], y[20];

main(){
  int n;
  double r, th;
  cin >> n >> r >> th;
  for(int i = 0; i < n; ++i)
    cin >> x[i] >> y[i];

  for(int i = 0; i < n; ++i){
    for(int j = 0; j < n; ++j){
      if(i == j) continue;
      int ax = x[j] - x[i];
      int ay = y[j] - y[i];
      for(int k = 0; k < n; ++k){
        if(k == j) continue;
        int bx = x[k] - x[j];
        int by = y[k] - y[j];
        double ac = (ax*bx + ay*by);
        ac /= sqrt(ax*ax+ay*ay);
        ac /= sqrt(bx*bx+by*by);
        if(acos(-1)*th/180 >= acos(ac))
          G[i][j].push_back({k,sqrt(bx*bx+by*by)});
      }
    }
  }

  for(int i = 0; i < n; ++i)
    for(int j = 0; j < n; ++j){
      dp[i][j][0] = dp[i][j][1] = r+200;
    }

  int ans = 0;
  for(int i = 1; i < n; ++i){
    int ax = x[i] - x[0];
    int ay = y[i] - y[0];
    if(ax*ax+ay*ay <= r*r){
      dp[0][i][0] = sqrt(ax*ax+ay*ay);
      ans = 1;
    }
  }
  
  while(ans){
    bool end = true;
    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j){
        dp[i][j][ans&1] = r*2+200;
      }

    for(int i = 0; i < n; ++i)
      for(int j = 0; j < n; ++j){
        if(dp[i][j][~ans&1] < r){
          for(auto& e : G[i][j])
            if(dp[i][j][~ans&1]+e.second < r){
              end = false;
              dp[j][e.first][ans&1] =
                min(dp[j][e.first][ans&1],
                    dp[i][j][~ans&1]+e.second);
            }
        }
      }
    
    if(end) break;
    ++ans;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1528
#include<bits/stdc++.h>
using namespace std;
#define MAXN	100005
#define INF	1e18
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
long long dp[3][MAXN], a[MAXN];
void update (long long &x, long long y) {
	x = max(x, y);
}
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]);
	for (int i = 0; i < MAXN; i++)
		dp[0][i] = dp[1][i] = dp[2][i] = -INF;
	dp[0][1] = a[1];
	for (int i = 1; i < n; i++)
		if (a[i + 1] >= 0) {
			//Non - parentheses
			update(dp[0][i + 1], dp[0][i] + a[i + 1]);
			update(dp[1][i + 1], dp[1][i] - a[i + 1]);
			update(dp[0][i + 1], dp[1][i] - a[i + 1]);
			update(dp[2][i + 1], dp[2][i] + a[i + 1]);
			update(dp[1][i + 1], dp[2][i] + a[i + 1]);
			update(dp[0][i + 1], dp[2][i] + a[i + 1]);
		} else {
			//Non - parentheses
			update(dp[0][i + 1], dp[0][i] + a[i + 1]);
			update(dp[1][i + 1], dp[1][i] - a[i + 1]);
			update(dp[0][i + 1], dp[1][i] - a[i + 1]);
			update(dp[2][i + 1], dp[2][i] + a[i + 1]);
			update(dp[1][i + 1], dp[2][i] + a[i + 1]);
			update(dp[0][i + 1], dp[2][i] + a[i + 1]);
			//Add - parentheses
			update(dp[1][i + 1], dp[0][i] + a[i + 1]);
			update(dp[2][i + 1], dp[1][i] - a[i + 1]);
		}
	cout << dp[0][n] << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	ll X, year = 0, yen = 100;
	cin >> X;
	while(1)
	{

		if (yen >= X)
		{
			cout << year << '\n';
			break;
		}
		yen += yen * 0.01;
		year++;
	}
	return 0;
}


Measured memory_bytes: 3612
N = int(input())
a = input()
wc = int(0)
rc = int(0)
c = int(0)

for i in range(N):
  if a[i] == "W":
    wc += 1
  else:
    rc += 1

if rc == 0:
  print("0")
else:
  for i in range(rc):
    if a[i] == "W":
      c += 1
  print(c)

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;
const int mod = 1000000007;

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

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

  ll cd = lcm(c, d);

  ll nc = b/c - (a-1)/c;
  ll nd = b/d - (a-1)/d;
  ll ncd = b/cd - (a-1)/cd;
  ll ans = b - a + 1 - (nc + nd - ncd);
  cout << ans << endl;
  return 0;
}

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

int main(int argc, char const *argv[])
{
    int n, x; cin >> n >> x;
    int l[n]; for (int i=0; i<n; i++) cin >> l[i];
    
    int sum = 0;
    for (int i=0; i<n; i++) {
        sum += l[i];
        if (x < sum) {
            cout << i + 1 << endl; return 0;
        }
    }
    cout << n + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc159/tasks/abc159_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "unordered_map"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  unordered_map<ll, ll> ct_map;

  for (auto a : as) ++ct_map[a];

  ll all_ct = 0;

  for (auto p : ct_map) {
    ll ct = p.se;
    all_ct += ct * (ct - 1) / 2;
  }

  for (auto a : as) {
    ll res = all_ct;
    ll ct = ct_map[a];
    res -= ct * (ct - 1) / 2;
    res += (ct - 1) * (ct - 2) / 2;
    cout << res << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

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

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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


#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

class E{
public:
  char c;
  int a,b;
  E(char c,int a,int b):c(c),a(a),b(b){}
};

int n;
vector<E> in;

bool input(){
  cin>>n;
  if(n==0)return false;

  in.clear();
  rep(i,n){
    char c;
    int a,b;
    cin>>c;
    if(c=='W')cin>>a>>b;
    else cin>>a;
    in.push_back(E(c,a,b));
  }
  return true;
}

class D{
public:
  int prev;
  int next;
  int num;
  int len;
  D(int prev, int next,int num,int len):prev(prev),next(next),num(num),len(len){}
};


vector<D> data;

void calc_write(int num,int len){
  int now = 0;
  while(1){
    int prev = data[now].prev;
    int next = data[now].next;

    if(data[now].num==-1){
      if(len<=data[now].len){
	data[now].len -= len;

	D ad = D(prev, now, num, len);
	data[now].prev = data.size();
	data[prev].next = data.size();

	data.push_back(ad);
	break;
      }else{
	data[now].num = num;
	len-=data[now].len;
      }
    }
    if(data[now].next==-1)break;
    now = next;
  }
}

void calc_del(int num){
  int now = 0;
  while(1){
    int next = data[now].next;
    if(data[now].num==num)data[now].num=-1;
    if(next==-1)break;
    now = next;
  }
}

int  calc_read(int len){
  int now = 0;
  int sum = 0;
  while(1){
    int next = data[now].next;
    sum += data[now].len;
    if(sum  > len)return data[now].num;
    if(next==-1)break;
    now = next;
  }
  return -1;
}

void print(){
  int now=0;
  while(1){
    int next = data[now].next;
    printf("num=%d len=%d  (now=%d)\n",data[now].num,data[now].len,now);
    if(data[now].next==-1)break;
    now=next;
  }
}

void solve(){
  data.clear();
  data.push_back(D(-1,1,-2,0));
  data.push_back(D(0,-1,-1,1100000000));

  //int();

  rep(i,in.size()){
    //printf("%c  %d %d\n",in[i].c,in[i].a,in[i].b);
    if(in[i].c=='W')calc_write(in[i].a,in[i].b);
    if(in[i].c=='R')printf("%d\n",calc_read(in[i].a));
    if(in[i].c=='D')calc_del(in[i].a);
    //print();
  }
  puts("");
}

int main(){
  while(input())solve();
}

Measured memory_bytes: 1424
//let's do it
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 100001

int a[maxn],inc[maxn],sinc[maxn],de[maxn],sdec[maxn],n,dp[maxn];
int check_inc(int l,int r)
{
	assert(l<=r);
	if(l==r)
	return 1;
	if(r==l+1)
	return a[r]>=a[l];
	return ((sinc[r]-sinc[l])==r-l);
}
int check_dec(int l,int r)
{
	assert(l<=r);
	if(l==r)
	return 1;
	if(r==l+1)
	return a[r]<=a[l];
	return ((sdec[r]-sdec[l])==r-l);
}
int main()
{
	boost1;boost2;
	int i,j,lo,mid,hi,x,y;
	cin>>n;
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=2;i<=n;i++)
	{
		if(a[i]>=a[i-1])
		inc[i]=1;
		sinc[i]=sinc[i-1]+inc[i];
	}
	for(i=2;i<=n;i++)
	{
		if(a[i]<=a[i-1])
		de[i]=1;
		sdec[i]=sdec[i-1]+de[i];
	}
	/*for(i=1;i<=n;i++)
	cout<<inc[i]<<" ";
	cout<<endl;
	for(i=1;i<=n;i++)
	cout<<sdec[i]<<" ";
	cout<<endl;
	cout<<check_dec(2,4)<<endl;*/
	for(i=0;i<=n;i++)
	dp[i]=n+1;
	dp[0]=0;
	dp[1]=1;
	//cout<<check_inc(1,3)<<endl;
	for(i=2;i<=n;i++)
	{
		dp[i]=1+dp[i-1];
		dp[i]=min(dp[i],1+dp[i-2]);

		if(a[i]>=a[i-1])
		{
			lo=0;
			hi=i;
			while(hi-lo>1)
			{
				mid=(lo+hi)/2;
				if(check_inc(mid,i))
				hi=mid;
				else
				lo=mid;
			}
			//if(i==4)
			//cout<<hi<<endl;
			dp[i]=min(dp[i],dp[hi-1]+1);
		}
		
		if(a[i]<=a[i-1])
		{
			lo=0;
			hi=i;
			while(hi-lo>1)
			{
				mid=(lo+hi)/2;
				if(check_dec(mid,i))
				hi=mid;
				else
				lo=mid;
			}
		//	if(i==4)
		//	cout<<hi<<endl;
			dp[i]=min(dp[i],dp[hi-1]+1);
		}
		
	}
	/*for(i=1;i<=n;i++)
	cout<<dp[i]<<" ";
	cout<<endl;*/
	cout<<dp[n];
	return 0;
}


Measured memory_bytes: 2560
/*"You can do anything you set your mind to,man" - Eminem*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define llpow(a,b) (ll)(pow(a,b)+0.5)
#define l_b(a,val) min((int)a.size()-1, (int)(lower_bound(a.begin(),a.end(),val)-a.begin()))
#define f first
#define up(a,b) max(a,b)
#define s second
#define INF 9223372036854775807
const  int mod = 1000000007;
template <typename T> T add(T& a, T b){a+=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T mul(T& a, T b){a*=b;while(a>=mod)a-=mod;while(a<0)a+=mod;}
template <typename T> T up_self(T& a, T b){a = up(a,b);}
template <typename T> T min_self(T& a, T b){a = min(a,b);}
ll binexpomodulo(ll x, ll y){ll res =1;x%=mod;if(!x)return 0;while(y){if(y&1){mul(res, x);}mul(x,x);y>>=1;}return res;}
ll nCrInOr(ll n, ll r){ll res = 1;if(r>n-r)r = n-r;ll rin = 1;for(ll i = 1; i <=r ; i++)rin = (rin*i)%mod;rin = binexpomodulo(rin,mod-2);for(ll i = 1; i <= r; i++)res = (res*(n-i+1))%mod;res = (res*rin)%mod;return res;}
int msb(ll n){int ans;for(int i = 0 ; i < 64;  i++)if(n&(1LL<<i))ans = i+1;return ans;}
/*All the macros below are copied from nik_y(OG)*/
#define test() int t; cin>>t; while(t--)
#define Shazam ios_base::sync_with_stdio(false);   cin.tie(NULL); cout.tie(NULL);
#define all(c) c.begin(),c.end()
#define endl "\n"
#define get(a,n) fl(i,0,n)  cin>>a[i];
#define pr(a,n) fl(i,0,n) cout<<a[i]<<" ";	cout<<endl;
int main()
{
	Shazam;
	int n; cin>>n;
	vector<vector<int>> can(n, vector<int>(n));
	for(int i = 0 ; i < n ; i++){
		for(int j =0 ; j < n; j++){
			cin>>can[i][j];
		}
	}
	vector<ll> dp(1LL<<n);
	dp[0]=1;
	for(int mask = 0; mask < (1<<n)-1; mask++){
		int i = __builtin_popcount(mask);
		for(int j = 0 ; j <  n; j++){
			if(can[i][j] && !(mask&(1<<j))){
				add(dp[mask|(1<<j)],dp[mask]);
			}
		}
	}
	cout<<dp[(1LL<<n)-1]<<endl;
  	return 0;
}

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

int main(){
  int n, ans=0; cin>>n;
  string s; cin>>s;
  for(int i=0;i<=n-3;i++){
    if(s.substr(i,3)=="ABC"){
      ans++;
      i+=2;
    }
  }
  
  cout<<ans<<endl;
  return 0;
}

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

int n,y;
int main()
{
	cin>>n>>y;
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n-i;j++)
		{
			int p=n-i-j;
			if(10000*i+5000*j+1000*p==y){
				cout<<i<<' '<<j<<' '<<p;
				return 0;
			}
		}
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;

int main() {
	long long N, M;
	cin >> N >> M;
	vector<long long>X(N), Y(M);
	for (size_t i = 0; i < N; i++)
	{
		cin >> X.at(i);
	}
	sort(X.begin(), X.end(),greater<long long>());
	long long sx = 0;
	for (long long i = 0; i < N; i++)
	{
		sx += (X.at(i)+mod) * (long long)(N - 1 - 2 * i+mod);
		sx %= mod;
	}
	for (long long i = 0; i < M; i++)
	{
		cin >> Y.at(i);
	}
	sort(Y.begin(), Y.end(), greater<long long>());
	long long sy = 0;
	for (size_t i = 0; i < M; i++)
	{
		sy += (Y.at(i) + mod) * (long long)(M - 1 - 2 * i+mod);
		sy %= mod;
	}
	long long ans = sx * sy;
	cout << ans%mod;
}

Measured memory_bytes: 1792
#encoding: utf-8
import os, sys
import math

def read_items_in_line(cast=int):
    return [cast(x) for x in sys.stdin.readline().strip(' \n').split(' ')]

N = read_items_in_line()[0]
d = []
for i in range(N):
    d += [read_items_in_line()[0]]

print(len(set(d)))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
  #include "dbgtoki.hpp"
  #define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i)  
#else
  #define DUMP(i)  
#endif

#define GETTYPE(i) 
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define SSTR( x ) static_cast< std::ostringstream & >( \
        ( std::ostringstream() << std::dec << x ) ).str()
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
using namespace std;
typedef long long unsigned int llu;
typedef long long ll;

const int EPS = 1e-9;

int main (){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  while(cin >> n){
    ll dp[n];
    dp[0] = 2l;
    dp[1] = 1l;
    FOR(i,2,n+1){
      dp[i] = dp[i-1] + dp[i-2];
    }
    cout << dp[n] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
n = int(input())
ans = 0
al = []
xy = [[] for _ in range(n)]
for k in range(n):
    a = int(input())
    al.append(a)
    for l in range(a):
        x,y = map(int,input().split())
        xy[k].append([x,y])
for i in range(2**n):
    kinds = [0]*n
    jud = 1
    for j in range(n):
        if (i >> j) & 1:
            kinds[j] = 1
    for k in range(n):
        if kinds[k] == 1:
            a = al[k]
            for l in range(a):
                x = xy[k][l][0]
                y = xy[k][l][1]
                if kinds[x-1] != y:
                    jud = 0
    if jud == 1:
        ans = max(ans,kinds.count(1))
print(ans)


Measured memory_bytes: 9176
#include <cstdio>
#include <iostream>
using namespace std;
	int n,s,a,b; 
 	long long x[120000],p[120000],ans;
 int main(){
 	scanf("%d%d",&n,&s);
 	 for (int i=1; i<=n; i++)
 	 scanf("%d%d",&x[i],&p[i]);
 	   a=1,b=n;
 	  while (a<=b){
 	  	if (s<=x[a]) {
 	  		ans+=x[b]-s;
 	  		break;
 	  	}
 	  	if (s>=x[b]) {
 	  		ans+=s-x[a];
 	  		break;
 	  	}
 	  	if (p[a]>=p[b]){
 	  		ans+=x[b]-x[a];
			   while (a<b && p[a]>=p[b]) {
			   p[a]+=p[b];	
			   b--;
 	  	}
 	  }
 	  else{
 	    ans+=x[b]-x[a];
			   while (a<b && p[a]<p[b]) {
			   p[b]+=p[a];	
			   a++;
 	  	}
 	  }
 }
 	  printf("%lld",ans);
 	  return 0;
 } 

Measured memory_bytes: 1792
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vector<vector<int> > input(n,vector<int>(3));
    for(int i=0;i<n;++i){
        for(int j=0;j<3;++j){
            cin>>input[i][j];
        }
    }
    vector<vector<int> > dp(n,vector<int>(3,0));
    dp[n-1][0]=input[n-1][0];
    dp[n-1][1]=input[n-1][1];
    dp[n-1][2]=input[n-1][2];
    for(int i=n-2;i>=0;--i){
        dp[i][0]=input[i][0]+max(dp[i+1][1],dp[i+1][2]);
        dp[i][1]=input[i][1]+max(dp[i+1][0],dp[i+1][2]);
        dp[i][2]=input[i][2]+max(dp[i+1][0],dp[i+1][1]);
    }
    cout<<max(dp[0][0],max(dp[0][1],dp[0][2]));
    cout<<endl;
}


Measured memory_bytes: 14268
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val N = next().toInt()
    var A = nextIntList()
    var ans = 0
    while (A.all { it % 2 == 0 }) {
        A = A.map { it / 2 }
        ans++
    }
    println(ans)
}

Measured memory_bytes: 36032
H, W, K = map(int, input().split())
c = [list(input()) for _ in range(H)]
ans = 0
for i in range(1 << H):
    for j in range(1 << W):
        count = 0
        for m in range(H):
            for l in range(W):
                if i >> m & 1 or j>> l & 1:
                    continue 
                if c[m][l] == '#':
                   count+=1
        if count == K:
            ans += 1

print(ans)

Measured memory_bytes: 9192
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int n, k, result = 0;
	int fruit[1000];
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%d", &fruit[i]);
	}

	sort(fruit, fruit + n);

	for (int i = 0; i < k; i++) {
		result += fruit[i];
	}
	printf("%d\n", result);

	return 0;
}


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

const int inf = 1e9;

int solve(vector<int> &c, int index) {
  int n = c.size(), ans = 0;
  vector<pair<int, int>> even, odd, combined(n);
  for (int i = 0; i < n; i++) {
    if (i % 2 == ((index >> i) & 1)) {
      even.emplace_back(c.at(i), i);
    } else {
      odd.emplace_back(c.at(i), i);
    }
  }
  for (int i = 1; i < even.size(); i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (even.at(j) <= even.at(j + 1)) break;
      swap(even.at(j), even.at(j + 1));
    }
  }
  for (int i = 1; i < odd.size(); i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (odd.at(j) <= odd.at(j + 1)) break;
      swap(odd.at(j), odd.at(j + 1));
    }
  }
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      combined.at(i) = even.at(i / 2);
    } else {
      combined.at(i) = odd.at(i / 2);
    }
  }
  for (int i = 1; i < n; i++) {
    if (combined.at(i).first < combined.at(i - 1).first) return inf;
  }
  for (int i = 1; i < n; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (combined.at(j).second <= combined.at(j + 1).second) break;
      swap(combined.at(j), combined.at(j + 1));
      ans++;
    }
  }
  return ans;
}

int main() {
  int n, ans = inf;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) cin >> a.at(i);
  for (int i = 0; i < n; i++) cin >> b.at(i);
  for (int i = 0; i < (1 << n); i++) {
    if (__builtin_popcount(i & 0x55555) != __builtin_popcount(i & 0xAAAAA)) continue;
    vector<int> c(n);
    for (int j = 0; j < n; j++) {
      if (i & (1 << j)) {
        c.at(j) = b.at(j);
      } else {
        c.at(j) = a.at(j);
      }
    }
    ans = min(ans, solve(c, i));
  }
  if (ans == inf) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
}


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

int main() {
    int x[3];
    cin >> x[0] >> x[1] >> x[2];
    sort(x, x+3);
    int cost = 0;
    cost += (x[1]-x[0]);
    cost += (x[2]-x[1]);
    cout << cost << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const int inf = 1e9;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, b, a) for (int i = a - 1; i >= b; i--)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dxx[8] = {1, 1, 1, 0, 0, -1, -1, -1}, dyy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

string ans, s;
void dfs (int now, int sum, string t) {
    if (now == 3) {
        if (sum == 7) {
            ans = t;
            // cout << now << ans << "\n";
            return;
        } else {
            return;
        }
    }
    dfs (now + 1, sum + (s[now + 1] - '0'), t + "+");
    dfs (now + 1, sum - (s[now + 1] - '0'), t + "-");
}

int main() {
    cin >> s;
    dfs (0, s[0] - '0', "");
    string anss = "";
    rep (i, 0, 3) { anss = anss + s[i] + ans[i]; }
    anss = anss + s[3] + "=7";
    cout << anss << "\n";
    // cout << ans << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

//ここから書き始める
int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    int n,q;
    cin >> n >> q;
    queue<pair<string, int>> que;
    vector<pair<string, int>> task(n);
    vector<pair<string, int>> ans(n);

    REP(i,n)
    {
        string tmp1;
        int tmp2;
        cin >> tmp1 >> tmp2;
        task[i] = make_pair(tmp1,tmp2);
        que.push(task[i]);
    }
    int nowtime = 0;
    int k = 0;
    while(!que.empty())
    {
        string name;
        int time;

        name = que.front().first;
        time = que.front().second;
        que.pop();
        if(time <= q)
        {
            int anstime = nowtime + time;
            nowtime = anstime;
            ans[k] = make_pair(name,anstime);
            k++;
        }
        else
        {
            time -= q;
            nowtime += q;
            que.push(make_pair(name,time));
        }
    }

    REP(i,n)
    {
        cout << ans[i].first << " " << ans[i].second << endl;
    }



}



Measured memory_bytes: 7656
#include <stdio.h>
int main(void){
char s[2],ss[2];
  scanf("%s",&s);
    scanf("%s",&ss);
  if(s[0]=='H'){
  if(ss[0]=='H'){printf("H");}
    else {printf("D");}
  }
  else if(s[0]=='D'){
  if(ss[0]=='H'){printf("D");}
    else {printf("H");}
  }
return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int n;
	scanf("%d",&n);
	if(n%10==3)
		puts("bon");
	else if(n%10==0||n%10==1||n%10==6||n%10==8)
		puts("pon");
	else
		puts("hon");
}


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

namespace Yuzuki
{
    class Yukari
    {
        public static void Main(string[] args)
        {
            string[] buf = Console.ReadLine().Split();
            int a = int.Parse(buf[0]);
            int b = int.Parse(buf[1]);
            int m = int.Parse(buf[2]);

            int[] As = new int[a];
            int[] Bs = new int[b];

            buf = Console.ReadLine().Split();
            for (int _ = 0; _ < a; _++)
            {
                As[_] = int.Parse(buf[_]);
            }
            buf = Console.ReadLine().Split();
            for (int _ = 0; _ < b; _++)
            {
                Bs[_] = int.Parse(buf[_]);
            }

            int ans = As.Min() + Bs.Min();

            for (int i = 0; i < m; i++)
            {
                buf = Console.ReadLine().Split();             
                int x = int.Parse(buf[0]);
                int y = int.Parse(buf[1]);
                int c = int.Parse(buf[2]);
                ans = Min(ans, As[x - 1] + Bs[y - 1] - c);
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 31324
#include <iostream>
using namespace std;
int main(void) {
  int w, h, x, y, r;
  cin >> w >> h >> x >> y >> r;
  if(min(x, y) >= r && w - x >= r && h - y >= r)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



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

int main() {
  long long s;
  cin >> s;
  
  long long x, y, ma = pow(10, 9);
  y = (s + ma - 1) / ma, x = y * ma - s;
  
  cout << 0 << " " << 0 << " " << ma << " " << 1 << " " << x << " " << y << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
lint lcm(lint a,lint b){
      return a/__gcd(a,b)*b;
  }
  int main(){
    lint N,Q;
    string s,t;
    cin>>N>>Q;
  lint x=min(N,Q);
  if(x==N){
      rep(i,Q){
          cout<<N;
      }
  }
 else if(x==Q){
      rep(i,N){
          cout<<Q;
      }
  }

  }
  

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
int taro=0,hana=0,i,
n;
char a[100],b[100];

scanf("%d",&n);
for(i=0;i<n;i++){

scanf("%s %s",a,b);

strcmp(a,b);

if(strcmp(a,b)==0){
taro++;
hana++;}

else if(strcmp(a,b)>0)taro+=3;
else hana+=3;
}


printf("%d %d\n",taro,hana);








return 0;
}

    

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

int main() {
    vector<int>a={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin>>k;
    cout<<a[k-1]<<endl;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
		int evens = scan.nextInt();
		int odds = scan.nextInt();
		int sum = 0;
		sum += (evens * (evens - 1)) / 2;
		sum += (odds * (odds - 1)) / 2;
		System.out.println(sum);
	}

}


Measured memory_bytes: 23252
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let w: Vec<i32> = (0..n).map(|_| read()).collect();

    let ans: i32 = (1..n)
        .map(|t| {
            let (left, right) = w.split_at(t);
            (left.iter().sum::<i32>() - right.iter().sum::<i32>()).abs()
        })
        .min()
        .unwrap();

    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352