akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template <typename X>
struct RLE{
  string array;
  int n;

  RLE(string _array){
    array = _array;
    n = array.size();
  }

  vector<ll> compress(){
    vector<ll> res(0);
    ll cnt = 1;
    rep(i,n-1){
      if(array[i]==array[i+1]){
	cnt++;
      }
      else{
	res.push_back(cnt);
	cnt = 1;
      }
    }
    res.push_back(cnt);
    return res;
  }
  
};

int main()
{
  string s;
  cin >> s;
  ll k;
  cin >> k;
  RLE<string> rle(s);
  vector<ll> vec = rle.compress();
  int m = vec.size();
  ll res = 0;
  if(m==1){
    res += (vec[0]*k)/2;
  }
  else{
    rep1(i,m-2){
      res += vec[i]/2 * k;
    }
    if(s[0]==s[s.size()-1]){
      res += (vec[0]+vec[m-1])/2 * (k-1);
      res += vec[0]/2 + vec[m-1]/2;
    }
    else{
      res += vec[0]/2 * k;
      res += vec[m-1]/2 * k;
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;


int main(){
	ll a;
	cin>>a;
	cout<<a+a*a+a*a*a<<endl;



	return 0;
}






Measured memory_bytes: 3620
#include<iostream>
using namespace std;
int main(){
  int n,m,a[10005],sum = 0;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>a[i];
    sum += a[i];
  }
  if(n>=sum){
    cout<<n-sum<<'\n';
  }
  else if(n<sum){
    cout<<-1<<'\n';
  }
  return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>

int main()
{
	char S[100];
	char T[100];

	scanf("%s",&S);
	scanf("%s",&T);

	int flag=0;
	int i=0;

	while(S[i]!='\0')
	{
		if(S[i]!=T[i])
		{
			flag=1;
		}
		if(flag==1)
		{
			break;
		}
		i++;
	}

	if(flag==1)
		printf("No\n");
	else
	{
		printf("Yes\n");
	}
	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
#define def 0
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return max(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};

/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N, H[201010], A[201010];
SegTree<ll, 1 << 18> dp;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> H[i];
    rep(i, 0, N) cin >> A[i];

    vector<int> z;
    z.push_back(-1);
    rep(i, 0, N) z.push_back(H[i]);
    sort(all(z));
    z.erase(unique(all(z)), z.end());
    rep(i, 0, N) H[i] = lower_bound(all(z), H[i]) - z.begin();

    rep(i, 0, N) {
        ll opt = dp.get(0, H[i]) + A[i];
        dp.update(H[i], max(dp[H[i]], opt));
    }

    cout << dp.get(0, z.size()) << endl;
}


Measured memory_bytes: 7032
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl
#define YN(x)         cout << ((x) ? "YES" : "NO") << endl
#define Yn(x)         cout << ((x) ? "Yes" : "No") << endl
#define yn(x)         cout << ((x) ? "yes" : "no") << endl
#define absi(x)       ( ((x) >= 0) ? (x) : (-(x)) )
#define debugvec(v)   rep(i, v.size()) cerr << "L" << __LINE__ << ": " << #v << "[" << i << "] = " << v[i] << endl;
#define debugvec2(v)  cerr << "L" << __LINE__ << ": " << #v << " = { "; rep(i, v.size()) cerr << v[i] << (i + 1 == v.size() ? "" : ", "); cerr << " }" << endl;
typedef long long ll;  // 10^18 くらいまでいける

// for DP
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; } 

const ll INF = 1LL << 60;

int main(){

  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) scanf("%d", &l[i]);

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

  ll ans = 0;
  for (int i=0; i<n-2; i++){
    for (int j=i+1; j<n-1; j++){
      for (int k=j+1; k<n; k++){
        if (l[i] >= l[j]+l[k])
          continue;
        if (l[j] >= l[i]+l[k])
          continue;
        if (l[k] >= l[i]+l[j])
          continue;
        ans++;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
from math import ceil, floor

a, b = [int(v) for v in input().split()]
ca, cb = ceil(a / 0.08), ceil(b / 0.1)
res = max(ca, cb)
if ca != res and floor(res * 0.08) != a:
    print("-1")
elif cb != res and floor(res * 0.1) != b:
    print("-1")
else:
    print(res)


Measured memory_bytes: 38480
def puyo_one(A):
  ans = 0
  now = 1
  for i in range(1, 5):
    if A[i] == A[i - 1]:
      now += 1
    else:
      if now >= 3:
        ans += now * A[i - 1]
      now = 1
  return ans

def puyo(A):#A:配列
  p = 0#消せるものがなくなったらp=1とし、ansを返す
  ans = 0
  while p == 0:
    this = 0
    #ぷよを消して加点
    for i in range(len(A)):
      now = 1 
      for j in range(1, 5):
        if (A[i][j] == A[i][j - 1]) and (A[i][j] != 0):
          now += 1
        else:
          if now >= 3:
            this = 1
            ans += A[i][j - 1] * now 
            for k in range(j - now, j):
              A[i][k] = 0
          now = 1
      if now >= 3:
        this = 1
        ans += A[i][j - 1] * now 
        for k in range(j - now + 1, j + 1):
          A[i][k] = 0
    #print(A, this, ans)
    #一回も消してない場合
    if this == 0:
      p = 1
    #残ったぷよを落とす
    #落とすところ
    N = len(A)
    for i in range(1, N + 1):
      for j in range(5):
        if (A[N - i][j] == 0) and (i != N):
          k = 1
          while (A[N - i - k][j] == 0) and (k + i < N):
            k += 1
          A[N - i][j] = A[N - i - k][j]
          A[N - i - k][j] = 0
    #一つもない行がある時、その行ごと消す
    q = 0
    while q == 0:
      if [0, 0, 0, 0, 0] in A:
        A.pop(A.index([0, 0, 0, 0, 0]))
      else:
        q = 1
    #print(A)
  return ans

l = 0
while l == 0:
  H = int(input())
  if H == 0:
    quit()
  else:
    A = [0] * H
    for i in range(H):
      A[i] = list(map(int, input().split()))
      #print(A)
    print(puyo(A))
      
    
    
  
  


Measured memory_bytes: 5628
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    string S;
    cin >> S;

    if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3])
        cout << "Bad" << endl;
    else
        cout << "Good" << endl;
    
}

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

int n, k;
ll a[200200], ans = 1, mod = 1e9 + 7;

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> k;
	for(int i=1;i<=n;i++) cin >> a[i];
	sort(a+1, a+1+n);
	
	int l = 1, r = n;
	if(k % 2) ans = a[r], r--, k--;
	while(k){
		k -= 2;
		ll x = a[l] * a[l+1] * (ans < 0 ? -1 : 1), y = a[r] * a[r-1] * (ans < 0 ? -1 : 1);
		if(x > y) ans = ans * a[l] % mod * a[l+1] % mod, l += 2;
		else ans = ans * a[r] % mod * a[r-1] % mod, r -= 2;
	}
	cout << (ans + mod) % mod;
}

Measured memory_bytes: 5152
#include<stdio.h>

int main(void)
{
  int i,n;
  double x,sum=0;
  char s[11];
  
  scanf("%d",&n);
    
  for(i=0;i<n;i++){
    scanf("%lf %s",&x,s);
    if(s[0]=='B'&&s[1]=='T'&&s[2]=='C'&&s[3]=='\0'){
      x*=380000;
      sum+=x;
    }
    if(s[0]=='J'&&s[1]=='P'&&s[2]=='Y'&&s[3]=='\0'){
    sum+=x;
    }
  }
  

  

  
  printf("%f\n",sum);
  return 0;
}

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

int main() {
  int k,n;
  cin >> k >> n;
  vector<int> a(n);
  for (int i = 0;i<n;i++) {
    cin >> a[i];
  }
  int x = a[0]+k-a[n-1];
  vector<int> b(n-1);
  for(int i = 0;i<n-1;i++) {
    b[i] = a[i+1]-a[i];
  }
  sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  int y = b[0];
  cout << k-max(x,y) <<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

// using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}

	void warshallFloyd(std::vector<std::vector<int>>& path, int n) {
		rep(k, n) {
			rep(i, n) {
				rep(j, n) {
					path[i][j] = std::min(path[i][j], path[i][k] + path[k][j]);
				}
			}
		}
	}
}

int main() {

	int n;
	std::cin >> n;
	std::vector<int> s(n);
	rep(i, n) std::cin >> s[i];

	int sum = std::accumulate(allof(s), 0);

	std::sort(allof(s));

	if (sum % 10) {
		std::cout << sum << std::endl;
		return 0;
	}

	rep(i, n) {
		int tmp = sum;
		tmp -= s[i];
		if (tmp % 10) {
			std::cout << tmp << std::endl;
			return 0;
		}
	}

	std::cout << 0 << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;
    vector<int> v(n + 1, 0);
    for(int i = 1; i <= n; i ++)
        cin >> v[i];
    sort(v.begin() + 1, v.end());

    int a = v[n / 2], b = v[n / 2 + 1];
    cout << b - a;

    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

const int N = 1e6;

void insertionSort(int a[], int n, int gap, int& count) {
    for (int i = gap; i < n; i++) {
        int value = a[i];
        int j = i - gap;
        while (j >= 0 && a[j] > value) {
            a[j + gap] = a[j];
            j -= gap;
            count++;
        }
        a[j + gap] = value;
    }
}

vector<int> generateGaps(int n) {
    vector<int> gaps;
    int h = 1;
    while (true) {
        if (h > n)
            break;
        gaps.push_back(h);
        h = 3 * h + 1;
    }
    return gaps;
}

void shellSort(int a[], int n) {
    int count = 0;
    vector<int> gaps = generateGaps(n);
    for (int i = gaps.size() - 1; i >= 0; i--)
        insertionSort(a, n, gaps[i], count);
    
    cout << gaps.size() << endl;
    for (int i = gaps.size() - 1; i >= 0; i--) {
        cout << gaps[i];
        if (i > 0)
            cout << " ";
    }
    cout << endl;
    cout << count << endl;
    for (int i = 0; i < n; i++)
        cout << a[i] << endl;
}

int main() {
    int n;
    cin >> n;
    int a[N];
    for (int i = 0; i < n; i++)
        cin >> a[i];

    shellSort(a, n);

    return 0;
}



Measured memory_bytes: 7004
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n],b[n],c[n];
    for(i=0;i<n;i++)cin>>a[i]>>b[i]>>c[i];
    ll dp[n][3];
    mms(dp,0);
    i=0;
    dp[0][0]=a[i];
    dp[0][1]=b[i];
    dp[0][2]=c[i];
    for(i=1;i<n;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][0],dp[i-1][1])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}


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

int main() {
    int A,B,sum=0;
    cin >> A >> B;
    for(int i=0;i<2;i++){
      if(A < B){
        sum+=B;
        B--;
      }else{
        sum+=A;
        A--;
      }
    }
    cout << sum << endl;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;



int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    if(n >= m) {
        printf("%d", 0);
        return 0;
    }
    vector<int> data(m);
    rp(i, 0, m) scanf("%d", &data.at(i));
    sort(data.begin(), data.end());
    int ans = data.at(m-1) - data.at(0);
    vector<int> dist(m-1);
    rp(i, 0, m-1) {
        dist.at(i) = data.at(i+1) - data.at(i); 
    }
    sort(dist.begin(), dist.end());
    rp(i, 0, n-1) {
        ans -= dist.at(m-2-i);
    }
    printf("%d", ans);
    return 0;
} 

Measured memory_bytes: 1024
use v5.18;
use warnings;
sub read_line { chomp(my $str = <STDIN>); $str }
sub splited_read_line { split / /, read_line }

my ($A, $B, $C, $K) = splited_read_line;
my @sums;
$sums[0] = [$B + $C, $A + $C, $A + $B];
$sums[1] = [$sums[0][1] + $sums[0][2], $sums[0][0] + $sums[0][2], $sums[0][0] + $sums[0][1]]; 
say $K % 2 == 1 ? $sums[0][0] - $sums[0][1] : $sums[1][0] - $sums[1][1];


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

int main(){
  int N;
  cin >> N;
  vector<int> v(N);
  
  for(int i = 0; i < N; i++){
    cin >> v.at(i);
  }
  
  int tmpans = 1000000;
  for(int sep = 1; sep < N -1; sep++){
    int left = 0;
    int right = 0;
    
    for(int i = 0; i <= sep; i++){
      left += v.at(i);
    }
    for(int i = sep + 1; i < N; i++){
      right += v.at(i);
    }
    int tmp = abs(left - right);
    if(tmp < tmpans){
      tmpans = tmp;
    }
  }
  cout << tmpans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <numeric>
#include <vector>
#include <queue>
#include <map>
typedef unsigned long long ull;
typedef long long ll;
#define MAX 10005
using namespace std;

int main() {
  int n, count=0;
  ull a;
  cin >> n;
  for(int i=0;i<n;i++) {
    cin >> a;
    while(a>0 && a%2 == 0) {
      a/=2;
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] p = new int[n];

		for (int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}

		int min = n+1;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			if (p[i] < min) {
				min = p[i];
				ans++;
			}			
		}

		System.out.println(ans);
	}
}

Measured memory_bytes: 65048
#include <iostream>
#include <vector>
#include<algorithm>
#include<iomanip>
#include<queue>
#include<map>
#include<bitset>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
const int inf   = 1e9+7;
const ll  longinf = 1LL<<60;
const int mod=1e9+7;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main(){
  int n;
  cin>>n;
  int a[n];
  int ma=0;
  rep(i,n){
    cin>>a[i];
    ma=max(a[i],ma);
    }
  int k=(ma+1)/2;
  int mi=0;
  rep(i,n){
    if(abs(a[i]-k)<abs(mi-k))
      mi=a[i];
    }
  cout<<ma<<" "<<mi<<endl;
  return 0;
    
  }

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if (a!=b&&a!=c&&b!=c){
        cout << "No";
    }else if (a==b&&b==c){
        cout << "No";
    }else{
        cout <<"Yes";
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define int long long
using namespace std;
signed main() {
    int X,Y,Z;
    cin>>X>>Y>>Z;
    
    cout<<Z<<" "<<X<<" "<<Y<<endl;
    
}

Measured memory_bytes: 3600
import sys
import itertools


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n = int(input().rstrip('\n'))
    d = list(map(int, input().rstrip('\n').split()))
    t = 0
    for v in itertools.combinations(d, 2):
        t += (v[0] * v[1])
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38512
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();
    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let t: i32 = iter.next().unwrap().parse().unwrap();

    let count: i32 = t / a;
    println!("{}", count * b);
}


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


void solve(long long A, long long B){
    for(int i=0;i<=1000;i++)
    {
        if(floor(i*0.08) == A && floor(i*0.1) == B)
        {
            cout<<i<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define all(a) a.begin(),a.end()
#define endl '\n'
#define y1 y123123
#define int ll

using namespace std;

const int N = 3e3 + 3;
const int inf = 1e9 + 3;
const int md = 1e9 + 7;


main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cout << fixed;
    cout << setprecision(10);
    int n;
    long double sum = 0;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        long double x;
        cin >> x;
        sum = sum + (1.0 / x);
    }
    cout << (1.0 / sum) << endl;

}


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

long long p = 1000000007;

int main(){
    long long N, M;
    long long dp[100010] = {0};
    cin >> N >> M;
    int a;
    for(int i=0;i<M;i++){
        cin >> a;
        dp[a] = -1;
    }
    dp[0] = 1;
    if(dp[1] != -1){
        dp[1] = 1;
    }
    for(int i=2;i<=N;i++){
        if(dp[i] == -1) continue;
        if(dp[i-2] != -1) dp[i] = dp[i-2];
        if(dp[i-1] != -1) dp[i] += dp[i-1];
        dp[i] %= p;
    }
    cout << dp[N];
    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
INF = float("inf")


def yes():
    print("Yes")  # type: str


def no():
    print("No")  # type: str


def solve(H: int, W: int, s: "List[str]"):
    n = [[0]*(W+2) for _ in range(H+2)]
    for i in range(H):
        for j in range(W):
            if s[i][j] == "#":
                n[i+1][j+1] = 1  # 外枠を作りつつ

    flag = True
    for i in range(1, H+1):
        for j in range(1, W+1):
            # print(i, j)
            if n[i][j] == 1 and n[i-1][j]+n[i+1][j]+n[i][j-1]+n[i][j+1] == 0:
                flag = False
                break
        if flag == False:
            break
    if flag == False:
        no()
    else:
        yes()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    s = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, s)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int a = n % 10;
        int b = n / 10 % 10;
        int c = n / 100 % 10;
        if(a == 1) a = 9;
        else a = 1;
        if(b == 1) b = 9;
        else b = 1;
        if(c == 1) c = 9;
        else c = 1;
        System.out.println(c*100+b*10+a);
    }
    public static int min(int a, int b) {
        if(a <= b) return a;
        else return b;
    }
    public static int max(int a, int b) {
        if(a <= b) return b;
        else return a;
    }
    public static int saiyaku(int a, int b) {
        if(a < b) return saiyaku(b, a);
        if(b == 0) return a;
        int w = b;
        a = a % b;
        b = w;
        return saiyaku(a, b);
    }
}

Measured memory_bytes: 23252
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
  a[i], b[i] = map(int, input().split())
c, d = [0] * M, [0] * M
for i in range(M):
  c[i], d[i] = map(int, input().split())

for i in range(N):
  min_dist = float("inf")
  ans = -1
  for j in range(M):
    dist = abs(a[i] - c[j]) + abs(b[i] - d[j])
    if dist < min_dist:
      min_dist = dist
      ans = j + 1
    elif dist == min_dist:
      ans = min(ans, j + 1)
  print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
 
#define vl vector<ll>
#define vi vector<int>
 
#define ff first
#define ss second
 
#define pb push_back
#define MOD 1000000007
//const int nax = 1e6+5;
#define inf 4e18
 
#define display(v) for(int i =0;i<v.size();++i)cout << v[i] << " "
#define all(v) v.begin(),v.end()
ll sqr(ll x){return x*x;}
inline ll add(ll a, ll b){ ll c = a + b; if(c >= MOD) c -= MOD; return c; }
inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
const int nax = 1000*1000 + 10;

int cnt[nax];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n; cin>>n;
    vi v(n);
    unordered_set<int> s;
    for(int i =0;i<n;++i){
        cin>>v[i];
        cnt[v[i]]++;
        s.insert(v[i]);
    }
    if(s.count(1)){
        if(cnt[1] > 1){
            cout << 0;
        }
        else cout << 1;
        return 0;
    }
    int ans =0;
    for(int i= 0;i<n;++i){
        int val  = v[i];
        int ok = 1;
        if(cnt[val] > 1)continue;
        for(int j = 2;j*j<=val;++j){
            if(val%j == 0){
                if(s.count(j) || s.count(val/j)){
                    ok = 0;
                    break;
                }
            }
        }
        if(ok)ans++;
    }
    cout << ans;


    
    
  
   
    return 0;
}
    

Measured memory_bytes: 15588
n = int(input())
a = [int(input()) for i in range(n)]
ans = 0
flag = 0
for i in range(n):
    if flag and a[i] >= 1:
        ans += 1
        a[i] -= 1
    flag = a[i] % 2
    ans += a[i] // 2
print(ans)

Measured memory_bytes: 50008
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#define int long long
#define pb push_back
#define x first
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}
const int INF = 1e9, MOD = 1e9 + 7; /// think
const ll LINF = 1e18;


const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
inline bool inside (int x, int y, int n, int m) {
    return 0 <= x && 0 <= y && x < n && y < m;
}

template<class T> bool umin (T &a, T b) {return a > b ? (a = b, true) : false; }
template<class T> bool umax (T &a, T b) {return a < b ? (a = b, true) : false; }

const int N = 82;
int a[N][N] = {};
bitset<2 * N * N> dp[N][N];
main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i + 1][j + 1];
        }
    }
    for (int i = 0, x; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> x;
            a[i + 1][j + 1] -= x;
            a[i + 1][j + 1] = abs(a[i + 1][j + 1]);
        }
    }
    dp[0][1][N * N] = dp[1][0][N * N] = 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = dp[i - 1][j] | dp[i][j - 1];
            dp[i][j] = (dp[i][j] << a[i][j]) | (dp[i][j] >> a[i][j]);
        }
    }
    int ans = INF;
    for (int i = 0; i < 2 * N * N; i++) {
        if (dp[n][m][i]) {
            umin(ans, abs(N * N - i));
        }
    }
    cout << ans << '\n';
}


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

int main(void)
{
    int N, M;
    long long K;
    cin >> N >> M >> K;
    
    vector<long long> A(N+1,0),B(M+1,0);

    for (int i = 1; i <= N; i++) cin >> A[i];
    for (int i = 1; i <= M; i++) cin >> B[i];

    for (int i = 1; i <= N; i++) A[i] += A[i-1];
    for (int i = 1; i <= M; i++) B[i] += B[i-1];

    int j = M;
    int ans = 0;
    for (int i = 0; i <= N; i++){
        if (A[i] > K) break;

        while (B[j] > K - A[i]) j--;

        ans = max( ans, i + j);
    }
    

    cout << ans << endl;
}

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll fac[400030];
ll inv[400030];
const ll maxn=400010;
ll fpow(ll a,ll b){
	ll c=1;
	while(b){
		if(b&1) c=a*c%mod;
		a=a*a%mod;
		b>>=1;
	}
	return c;
}
ll p(){
	fac[0]=1;                               //re0
	for(int i=1;i<=maxn;i++){
		fac[i]=i*fac[i-1]%mod;
	}
	inv[maxn]=fpow(fac[maxn],mod-2)%mod;
	for(int i=maxn-1;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
ll C(int n,int m){
	return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
int main(){
	p();
	int n,k;
	cin>>n>>k;
	if(k>=n){
		cout<<C(2*n-1,n-1)<<'\n';
	}
	else{
		ll ans=C(2*n-1,n-1);
		for(int i=1;i<n-k;i++){
			ans-=C(n,i)*C(n-1,i-1)%mod;
			ans+=mod;
			ans%=mod;
		}
		cout<<ans<<'\n';
	}
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int g(string s){
	return atoi(s.c_str());
}

int f(string t){
	int h=g(t.substr(0,2));
	int m=g(t.substr(3,2));
	int s=g(t.substr(6,2));
	return h*60*60+m*60+s;
}

const int M=100000;

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		vvi a(5,vi(n));
		for(int i=n-1;i>=0;i--) for(int j=0;j<5;j++) cin>>a[j][i];
		int res=0;
		while(1){
			bool B=0;
			for(int i=0;i<a[2].size();i++){
				int l=2,r=2;
				while(l>0&&i<a[l-1].size()&&a[l-1][i]==a[2][i]) l--;
				while(r<4&&i<a[r+1].size()&&a[r+1][i]==a[2][i]) r++;
				if(r-l+1>=3){
					for(int j=l;j<=r;j++) res+=a[j][i],a[j][i]=0;
					B=1;
				}
			}
			vvi b(5);
			for(int i=0;i<5;i++) for(auto j:a[i]) if(j) b[i].push_back(j);
			a=b;
			if(!B) break;
		}
		cout<<res<<endl;
	}
}


Measured memory_bytes: 3148
/*#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}

int main()
{
    fast_cin;
      string s,t;
      cin>>s>>t;
      int n=s.length();
      int m=t.length();
      unsigned int dp[n+1][m+1];
      string ans;
      for(int i=0;i<=n;i++)
      {
          for(int j=0;j<=m;j++)
          {
              if(i==0||j==0)
                dp[i][j]=0;
              else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
              else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
              /*if(ans.length()<dp[i][j])
                ans+=s[i];
          }
      }
      cout<<dp[n][m]<<endl;
      //cout<<ans<<endl;
    return 0;
}*/
#include <iostream>
#include <bits/stdc++.h>
#define fast_cin ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define ll long long int
using namespace std;

vector<ll> dp(100005,0);
int m=1e9+7;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    if(a.second==b.second)
        return a.first<b.first;
    else
        return a.second<b.second;
}

bool cmp_(pair<int,pair<int,int> >&a,pair<int,pair<int,int> >&b)
{
   return a.second.first<b.second.first;
}

void factorial()
{
    dp[1]=1;
    for(int i=2;i<=100000;i++)
    {
        dp[i]=((dp[i-1]%m)*(i%m))%m;
    }
}
void binary(int n)
{
    // array to store binary number
    int binaryNum[32];

    // counter for binary array
    int i = 0;
    while (n > 0) {

        // storing remainder in binary array
        binaryNum[i] = n % 2;
        n = n / 2;
        i++;
    }

    // printing binary array in reverse order
    for (int j = i - 1; j >= 0; j--)
        cout << binaryNum[j];
}
int main()
{
    fast_cin;
    ll n,x,t;
    cin>>n>>x>>t;
    ll ans=n/x;
    if(n%x)
        ans++;
    ans*=t;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3860
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	a := make([]string, n)
	as := make([]string, n)
	an := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = nextString(sc)
		as[i] = a[i][0:1]
		var err error
		an[i], err = strconv.ParseInt(a[i][1:2], 10, 64)
		if err != nil {
			panic(err)
		}
	}

	ban, bas := bubbleSort(n, an, as)
	san, sas := selectionSort(n, an, as)
	b := make([]string, n)
	s := make([]string, n)
	isSame := true
	for i := int64(0); i < n; i++ {
		b[i] = fmt.Sprintf("%s%d", bas[i], ban[i])
		s[i] = fmt.Sprintf("%s%d", sas[i], san[i])
		if b[i] != s[i] {
			isSame = false
		}
	}

	fmt.Println(strings.Trim(fmt.Sprint(b), "[]"))
	fmt.Println("Stable")
	fmt.Println(strings.Trim(fmt.Sprint(s), "[]"))
	if isSame {
		fmt.Println("Stable")
	} else {
		fmt.Println("Not stable")
	}
}

func bubbleSort(n int64, sa []int64, ss []string) ([]int64, []string) {
	a := make([]int64, cap(sa))
	copy(a, sa)

	s := make([]string, cap(ss))
	copy(s, ss)

	isIncomp := true

	for isIncomp {
		isIncomp = false
		for j := n - 1; j >= 1; j-- {
			if a[j] < a[j-1] {
				t := a[j-1]
				a[j-1] = a[j]
				a[j] = t

				ts := s[j-1]
				s[j-1] = s[j]
				s[j] = ts

				isIncomp = true
			}
		}
	}
	return a, s
}

func selectionSort(n int64, sa []int64, ss []string) ([]int64, []string) {
	a := make([]int64, cap(sa))
	copy(a, sa)

	s := make([]string, cap(ss))
	copy(s, ss)

	for i := int64(0); i <= n-1; i++ {
		minJ := i
		for j := int64(i); j <= n-1; j++ {
			if a[j] < a[minJ] {
				minJ = j
			}
		}
		t := a[minJ]
		a[minJ] = a[i]
		a[i] = t

		ts := s[minJ]
		s[minJ] = s[i]
		s[i] = ts
	}
	return a, s
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



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

using namespace std;

long long a, b, c, k;

int main(){
	scanf("%lld%lld%lld%lld", &a, &b, &c, &k);
	
	if(k % 2)
	printf("%lld\n", b - a);
	else
	printf("%lld\n", a - b);
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
input:
3 5
0 1 1
0 2 2
0 3 3
1 1 2
1 2 2

output:
3
2
"""

import sys


class BinaryIndexedTree(object):
    __slots__ = ('length', 'dat')

    def __init__(self, n):
        """
        Init a BIT with update and find for range sum queries.
        """
        self.length = int(n)
        self.dat = [0] * (self.length + 1)

    # sum(A[1] ... A[i])
    def __init_sum(self, i):
        _sum = 0
        while i > 0:
            _sum += self.dat[i]
            i &= (i - 1)
        return _sum

    def sum_st(self, s, t):
        return self.__init_sum(t) - self.__init_sum(s - 1)

    # A[i] += x
    def assign_ix(self, i, x):
        while i <= self.length:
            self.dat[i] += x
            i += i & (-i)
        return None


def action():
    _input = sys.stdin.readlines()
    n_num, q_num = map(int, _input[0].split())
    queries = map(lambda x: x.split(), _input[1:])
    case = BinaryIndexedTree(n_num)

    for query in queries:
        cmd, ele_1, ele_2 = map(int, query)
        if cmd == 0:
            case.assign_ix(ele_1, ele_2)
        elif cmd == 1:
            res = case.sum_st(ele_1, ele_2)
            print(res)

    return case


if __name__ == '__main__':
    action()

Measured memory_bytes: 17984
#include <bits/stdc++.h>
#define INF 1e18
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
#define MAX 1000
#define ll long long
#define P pair<int,int>
#define cout_set(n) cout << setprecision(10) << (n) << endl; 
const double PI=3.14159265358979323846;
using namespace std;
const int mod = 1000000007; 
int vy[4] ={1,-1,0,0}, vx[4] = {0,0,-1,1}; //up,down,left,right 

int main(){
    int a,b; cin >> a >> b;
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

//#define N 1000000

int main(){
  int a,b,c,count;

  while(scanf("%d %d",&a,&b)!=EOF){
    c=a+b;
    count=0;
    while(1){
      count++;
      if(c/10==0)break;

      c=c/10;
    }

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

  return 0;
}

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

int main(){
   int n;
   cin >> n;
   if(n%10==3) cout << "bon" << endl;
   else if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9) cout << "hon" << endl;
   else cout << "pon" << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll res = 0;
  if(abs(a-b) > 1e18){
    cout << "Unfair" << endl;
    return 0;
  }
  if(d%2 == 0){
    res = a-b;
  }
  else{
    res = b-a;
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
const long long MODULO = 1000000007;
 
using namespace std;
 
vector<long long> fact(100001);
 
void precalc() {
  	fact[0] = 1;
  	for (int i = 1; i <= 100000; ++i) {
      fact[i] = fact[i - 1] * i;
  	  fact[i] %= MODULO;
	}
  	return;
}
 
long long binpow(long long a, long long b) {
	long long res = 1;
  	while (b) {
    	if (b & 1) {
        	res *= a;
          	res %= MODULO;
        }
      	a *= a;
      	a %= MODULO;
      	b >>= 1;
    }
  	return res;
}
 
long long C(long long n, long long k) {
	if (n < k) return 0;
  	return (((fact[n] * binpow(fact[n - k], MODULO - 2)) % MODULO) * binpow(fact[k], MODULO - 2)) % MODULO;
}
 
int main() {
  	precalc();
	int n, k;
  	cin >> n >> k;
  	vector<long long> a(n);
  	for (int i = 0; i < n; ++i)
    	cin >> a[i];
  	sort(a.begin(), a.end());
  	long long ans = 0;
  	for (int i = 0; i < n; ++i) {
    	ans += (a[i] * C(i, k - 1))	% MODULO;
     	ans %= MODULO;
      	ans += MODULO;
      	ans -= (a[i] * C(n - i - 1, k - 1)) % MODULO;
      	ans %= MODULO;
    }
  	cout << ans << '\n';
  	return 0;
}


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

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0, ke2 = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
          ke2 = 1;
          break;
        }
      }
      if (ke2 == 1)
        break;
    }
  }
  return 0;
}

Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    int color[6][6];
    char tmp;
    int ans = 0;
    rep(i,h)rep(j,w) {
        cin >> tmp;
        if(tmp == '.') {
            color[i][j] = 0;
        } else {
            color[i][j] = 1;
        }
    }

    int bit_h = 1 << h;
    int bit_w = 1 << w;
    vector<int> h_list;
    vector<int> w_list;
    rep(i, bit_h){
        rep(j,bit_w){
            h_list.clear();
            w_list.clear();
            rep (a, h) {
                if (i >> a & 1) h_list.push_back(a);
            }
            rep (b, w) {
                if (j >> b & 1) w_list.push_back(b);
            }
            
            int cnt = 0;
            rep(a, h_list.size()){
                rep(b, w_list.size()){
                    if (color[h_list[a]][w_list[b]]) cnt++;
                }
            }
            
            if (cnt == k) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <sstream>
using namespace std;

map<char,int> mcxi = {
    {'m',1000}, {'c',100}, {'x',10}, {'i',1}
};
map<int,char> mcxi_rev = {
    {1000,'m'}, {100,'c'}, {10,'x'}, {1,'i'}
};

int toInt(string s) {
    int ret = 0;
    for (int i=0; i<(int)s.size(); ++i) {
        if (isalpha(s[i])) {
            ret += mcxi[s[i]];
        } else {
            ret += (s[i] - '0') * mcxi[s[i+1]];
            ++i;
        }
    }
    return ret;
}

string toMCXI(int n) {
    stringstream ss;
    for (int i=1000; i>=1; i/=10) {
        int d = (n % (i*10)) / i;
        if (d == 0) {
            continue;
        } else if (d == 1) {
            ss << mcxi_rev[i];
        } else {
            ss << d << mcxi_rev[i];
        }
    }
    return ss.str();
}

int main() {
    int n;
    cin >> n;
    string a, b;
    while (n--) {
        cin >> a >> b;
        cout << toMCXI(toInt(a) + toInt(b)) << endl;
    }
    return 0;
}

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

using namespace std;

int n, m, x[100010];
int d[100010];

int main(){
    scanf("%d %d", &m, &n);
    for(int i = 1; i <= n; i++) scanf("%d", &x[i]);
    sort(x + 1, x + 1 + n);
    if(m >= n) return puts("0"), 0;

    int ans = x[n] - x[1];
    for(int i = 1; i < n; i++) d[i] = x[i + 1] - x[i];
    sort(d + 1, d + n);

    for(int i = 1, j = n - 1; i <= m - 1; i++, j--)
        ans -= d[j];

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
//using namespace __gnu_pbds;

//template<typename T>
//using ordered_set =
//tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)


vector<int> LIS(vector<int> &a){    // O(n log k) k is the longest increasing subsequence
   int n = (int)a.size();
   vector<int> d(n , -1);  // parent[] , d[i] is the maximum subsequence ending in i
   vector<int> lis;
   for(int i = 0 ; i < n ; ++i){
      int j = lower_bound(lis.begin() , lis.end() , a[i]) - lis.begin();
      if(j == (int)lis.size())lis.push_back(a[i]);
      else lis[j] = a[i];
      d[i] = j + 1;
   }
}

const int N = 2e5 + 4;
int a[N] , n , rs[N];
vector<int> adj[N] , lis;
void dfs(int u , int p){
   // do
   int tmp = -1;
   int j = lower_bound(lis.begin() , lis.end() , a[u]) - lis.begin();
   if(j == (int)lis.size())lis.push_back(a[u]);
   else tmp = lis[j] , lis[j] = a[u];
   rs[u] = lis.size();
   for(int c : adj[u]){
      if(c == p)continue;
      dfs(c , u);
   }
   // undo
   if(tmp == -1)lis.pop_back();
   else lis[j] = tmp;
}

int main() {
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   cin >> n;
   for(int i = 1 ; i <= n ; ++i){
      cin >> a[i];
   }
   for(int i = 1 ; i < n ; ++i){
      int u , v;
      cin >> u >> v;
      adj[u].pb(v);
      adj[v].pb(u);
   }

   dfs(1 , -1);
   for(int i = 1 ; i <= n ; ++i)
      cout << rs[i] << "\n";
}

Measured memory_bytes: 27568
#include<bits/stdc++.h>
using namespace std;
int main()
{
    std::ios::sync_with_stdio(false);
    float n,x,t,s=0,sm=1005,dif,total;
    float e;
    cin>>n>>x;
    for(int i=0; i<n; i++)
    {
        cin>>t;
        s+=t;
        if(sm>t)
            sm=t;
    }
    dif=x-s;
    total=dif/sm;
    total=total+n;
    cout<<(int)total<<endl;












return 0;
}



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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{
  gearup;
  string s; cin >> s;
  if(s == "Sunny")out("Cloudy");
  else if(s == "Cloudy")out("Rainy");
  else out("Sunny");
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;

int main(){
	int n =1;
	int m;
	int mj = 30;

	cin >> n >> m;
	vector<mp::cpp_int> a(n);
	int b[mj];

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < mj; i++) {
		b[i] = n-1;
	}

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

	for (int i = 0; i < m; i++) {
		int maxj = 0;
		mp::cpp_int max = 0;
		for (int j = 0; j < mj; j++) {
			if (a[b[j]] > max) {
				max = a[b[j]];
				maxj = j;
			}
		}
		a[b[maxj]] /= 2;
		if (a[b[maxj]] < a[b[maxj] - 1]) {
			b[maxj]--;
		}
	}

	mp::cpp_int res = 0;
	for (int i = 0; i < n; i++) {
		res += a[i];
	}

	cout << res;
	
	return 0;
}

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

int main() {

  int a,b,c,d,e,f;

  cin >> a>>b;
  
  if(b%a==0) {
    e=a+b;
  }
 
          else{
            e=b-a;
          }
  cout<<e<<endl;
}


Measured memory_bytes: 256