akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main()
{
    double a,b,h,m; cin >> a >> b >> h >> m;
    double theta,theta1,theta2;
    const double pi = 3.141592653589793;
    theta1 = h * 30 + m * 0.5;
    theta2 = m * 6;
    if(theta1 > theta2){
        if(theta1-theta2 > 180) theta = 360-(theta1-theta2);
        else theta = theta1-theta2;
    }else{
        if(theta2 - theta1 > 180) theta = 360-(theta2-theta1);
        else theta = theta2-theta1;
    }
    theta = theta * pi / 180;

    double ans2 = a*a + b*b - (2*a*b*cos(theta));
    cout << fixed << setprecision(20);
    cout << pow(ans2, 0.5) << endl;
    
    
}

/*
Ctrl+@ でコンソールを開け、以下で実行。
g++ b.cpp
./a.out
*/

Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define MAX 100005

using namespace std;

int h[MAX];
int minimum[MAX];

int n, k;

int main(){
    cin>>n>>k;
    for(int i=0; i<n; i++)
        cin>>h[i];
    memset(minimum, -1, sizeof(minimum));
    minimum[0]=0;
    for(int i=0; i<n; i++){
        for(int j=1; j<=k && i+j<n; j++){
                //cout<<"v";
                if(minimum[i+j]<0) minimum[i+j] = minimum[i]+abs(h[i]-h[i+j]);
                minimum[i+j] = min(minimum[i+j], minimum[i]+abs(h[i]-h[i+j]));
        }
    }
    cout<<minimum[n-1]<<"\n";
    return 0;
}
/*
4
10 30 40 20
0  20 30 30

4
10 50 10 10
*/



Measured memory_bytes: 4304
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
string S;
int i;
int check(string str){
    int t = i;
    for(int j = str.size()-1;j >= 0;--j){
        if(t < 0) return 0;
        if(str[j] != S[t--]) return 0;
    }
    return 1;
}
int main(){
    string S1 = "dream";
    string S2 = "dreamer";
    string S3 = "erase";
    string S4 = "eraser";
    while(cin >> S){
        // 01234 56789 10
        // dream erase r

        // dreaeeraser
        for(i = S.size()-1;i >= 0;){
            if(check(S1)){
                i -= S1.size();
                continue;
            }
            if(check(S2)){
                i -= S2.size();
                continue;
            }
            if(check(S3)){
                i -= S3.size();
                continue;
            }
            if(check(S4)){
                i -= S4.size();
                continue;
            }
            break;
        }
        if(i != -1) cout << "NO" << endl;
        else cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 640
using System;

namespace B_tententen__Triple_Dots_
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            string s = Console.ReadLine();

            if (s.Length <= k)
            {
                Console.WriteLine(s);
            }
            else
            {
                s = s.Substring(0, k);
                Console.WriteLine(s + "...");
            }
        }
    }
}

Measured memory_bytes: 27536
import java.util.*;
 
 
class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        int n= s.length();
        long sum = 0;

        for(int i = 0;i < Math.pow(2,n - 1) ;i++){
            String num = String.valueOf(s.charAt(0));
            for(int j=0; j<n-1; j++){
                if((1&i>>j) == 1) { 
                    sum += Integer.parseInt(num);
                    num = "";
                }
                num += String.valueOf(s.charAt(j+1));
            }
            sum += Long.parseLong(num);
        }
        
        System.out.println(sum);
    }
}

Measured memory_bytes: 22484
def main():
  #n = int(input())
  #s = input()
  #s = input().split()
  #a,b = list(map(int,input().split()))
  #a = [list(map(int,input().split())) for i in range(6)]
  a = [int(input()) for i in range(6)]
  ans = 0
  
  
  if a[4] - a[0] > a[5]:
    print(":(")
    exit()
  print("Yay!")
  
if __name__ == '__main__':
  main()

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

int main() {
    long n, x, ans = 0, a, temp = 0;
    cin >> n >> x;
    rep(i, n) {
        cin >> a;
        if(temp + a <= x) {
            temp = a;
        } else {
            ans += (a + temp - x);
            temp = x - temp;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
string to_str(ll A){
    stringstream ss;
    ss << A;
    return ss.str();
}
int func(string s){
    if(s.length() == 1)return 0;
    ll maxi = 0;
    rep(i,1,s.length()){
        ll num = stoi(s.substr(0,i) ) * stoi(s.substr(i) );    
        maxi = max(maxi, num);
    }
    return 1 + func(to_str(maxi));
}

main(){
    int N;
    cin >> N;
    rep(i,0,N){
        int num;
        cin >> num;
        cout << func(to_str(num) ) << endl;
    }
}


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

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

LL dp[3010][3010][4];
LL value[3010][3010];

int main(){
	int R, C, K;
	cin >> R >> C >> K;
	vector<int> r(K), c(K);
	vector<LL> v(K);
	rep(i,K) cin >> r[i] >> c[i] >> v[i];
	rep(i,K) r[i]--, c[i]--;
	rep(i,K) value[r[i]][c[i]]=v[i];
	dp[0][0][1]=value[0][0];
	rep(i,R){
		rep(j,C){
			rep(k,4){
				dp[i][j+1][k]=max(dp[i][j+1][k],dp[i][j][k]);
				dp[i+1][j][0]=max(dp[i+1][j][0],dp[i][j][k]);
				if(value[i+1][j]>0){
					dp[i+1][j][1]=max(dp[i+1][j][1],dp[i][j][k]+value[i+1][j]);
				}
				if(value[i][j+1]>0 and k<3){
					dp[i][j+1][k+1]=max(dp[i][j+1][k+1],dp[i][j][k]+value[i][j+1]);
				}
			}
		}
	}
	LL ans=0;
	rep(i,4) ans=max(ans,dp[R-1][C-1][i]);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 359128
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const n: number = +input[0];
const p: number[] = input[1].split(' ').map((x: string): number => +x);

let ans: number = 0;
for(let i = 1; i < n-1; i++){
    if((p[i-1] < p[i] && p[i] < p[i+1]) || (p[i-1] > p[i] && p[i] > p[i+1])){
        ans++
    }
}
console.log(ans);

Measured memory_bytes: 7372
#include<stdio.h>

int main(){
  int i, j, n, m, x, y, w, h, _x, _y, count;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%d %d %d %d", &x, &y, &w, &h);
    scanf("%d", &m);

    for(j=0, count=0; j<m; j++){
      scanf("%d %d", &_x, &_y);
      if(_x >= x && _x <= x+w && _y >= y && _y <= y+h) count++;
    }
    printf("%d\n", count);
  }
  return 0;
}

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

ll restmax1(ll rest,ll kaisuu,vector<ll> P,vector<ll> PP,vector<ll> C){
  ll rM=-1000000005;
  if(rest==0){
    return 0;
  }
  else{
    for(ll i=0;i<kaisuu;i++){
      ll x=PP.at(i);
      ll current=0;
      for(ll j=0;j<rest;j++){
        x=P.at(x-1);
        current+=C.at(x-1);
        rM=max(current,rM);
      }
    }
    return rM;
  }
}

ll restmax0(ll rest,ll kaisuu,vector<ll> P,vector<ll> PP,vector<ll> C){
  ll rM=0;
  if(rest==0){
    return 0;
  }
  else{
    for(ll i=0;i<kaisuu;i++){
      ll x=PP.at(i);
      ll current=0;
      for(ll j=0;j<rest;j++){
        x=P.at(x-1);
        current+=C.at(x-1);
        rM=max(current,rM);
      }
    }
    return rM;
  }
}

int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> P(N);
  for(ll i=0;i<N;i++){
    cin >> P.at(i);
  }
  vector<ll> C(N);
  for(ll i=0;i<N;i++){
    cin >> C.at(i);
  }
  vector<bool> TF(N,true);
  vector<vector<ll>> Loop(0);
  vector<ll> LoopInc(0);
  vector<ll> Loopkaisuu(0);
  for(ll i=0;i<N;i++){
    if(TF.at(i)){
      TF.at(i)=false;
      ll x=i+1;
      vector<ll> L(1,x);
      ll LI=0;
      for(ll j=0;j<N;j++){
        if(j!=0 && P.at(x-1)==i+1){
          LI+=C.at(P.at(x-1)-1);
          break;
        }
        else{
          x=P.at(x-1);
          TF.at(x-1)=false;
          L.push_back(x);
          LI+=C.at(x-1);
        }
      }
      Loop.push_back(L);
      LoopInc.push_back(LI);
      Loopkaisuu.push_back(L.size());
    }
  }
  ll LoopNumber=Loop.size();
  ll M=-1000000005;
  for(ll i=0;i<LoopNumber;i++){
    vector<ll> PP=Loop.at(i);
    ll Inc=LoopInc.at(i);
    ll kaisuu=Loopkaisuu.at(i);
    ll rest=K%kaisuu;
    if(Inc<=0){
      M=max(M,restmax1(kaisuu-1,kaisuu,P,PP,C));
    }
    else if(Inc>0){
      if(K/kaisuu==0){
        M=max(M,restmax1(K,kaisuu,P,PP,C));
      }
      else if(K/kaisuu==1){
        M=max(max(M,K/kaisuu*Inc+restmax0(rest,kaisuu,P,PP,C)),restmax1(kaisuu-1,kaisuu,P,PP,C));
      }
      if(K/kaisuu>=2){
        M=max(max(max(M,K/kaisuu*Inc+restmax0(rest,kaisuu,P,PP,C)),restmax1(kaisuu-1,kaisuu,P,PP,C)),(K/kaisuu-1)*Inc+restmax0(kaisuu-1,kaisuu,P,PP,C));
      }
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 4004
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));

  const a = s[0];
  const b = s[1];

  const sum = a + b;

  const ans = (sum < 10) ? sum : 'error';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <map>
#include <algorithm>
#include <functional>
#include <string>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
using namespace std;

#define REP(i,p,n) for(ll i=p;i<ll(n);++i)
#define rep(i,n) REP(i,0,n)

using ll = long long int;
using pll = pair<ll, ll>;

const ll MAXN = 100000;
const ll INF = 10000000;
vector<ll> G[MAXN];

queue<ll> Q;
ll costs[MAXN];

bool visited1[MAXN];
bool visited2[MAXN];

int main()
{
    ll n, m;
    cin >> n >> m;

    rep (i, m)
    {
        ll u, v;
        cin >> u >> v;

        --u;
        --v;

        G[u].push_back(v);
        // G[v].push_back(u);
    }

    ll s, t;
    cin >> s >> t;
    --s;
    --t;

    fill(costs, costs + n, INF);

    Q.push(s);
    costs[s] = 0;

    while (!Q.empty())
    {
        const auto u = Q.front();
        Q.pop();

        for (const auto& v1 : G[u])
        {
            if (visited1[v1]) { continue; }
            visited1[v1] = true;

            for (const auto& v2 : G[v1])
            {
                if (visited2[v2]) { continue; }
                visited2[v2] = true;

                for (const auto& v3 : G[v2])
                {
                    if (costs[v3] != INF) { continue; }

                    costs[v3] = costs[u] + 1;
                    Q.push(v3);
                }
            }
        }
    }

    if (costs[t] != INF)
    {
        cout << costs[t] << endl;
    }
    else
    {
        cout << -1 << endl;
    }

    return 0;
}


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

using namespace std;
using int64 = long long;
const int mod = 1e9 + 7;
//const int mod = 998244353;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << "\n";

}




Measured memory_bytes: 3640
import math

a, b = map(int, input().split(' '))
aa = math.ceil(a / 0.08)
bb = math.ceil(b / 0.1)

if aa == bb:
    ans = aa
elif aa < bb:
    if math.floor(bb * 0.08) != a:
        ans = -1
    else:
        ans = bb
else:
    if math.floor(aa * 0.1) != b:
        ans = -1
    else:
        ans = aa
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL inf=1e18;
int n;
char s[100005][2];
LL a[100005],dp[100005][3];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%lld%s",&a[i],s[i]);scanf("%lld",&a[n]);
	dp[1][0]=a[1];dp[1][1]=dp[1][2]=-inf;
	for(int i=2;i<=n;i++)
	{
		if(s[i-1][0]=='-')
		{
			dp[i][0]=-inf;
			dp[i][1]=max(dp[i-1][0],dp[i-1][1])-a[i];
			dp[i][2]=max(dp[i-1][2],dp[i-1][1])+a[i];
		}
		else
		{
			dp[i][0]=max(dp[i-1][0],dp[i-1][1])+a[i];
			dp[i][1]=max(dp[i-1][1],dp[i-1][2])-a[i];
			dp[i][2]=dp[i-1][2]+a[i];
		}
	}
	printf("%lld\n",max(max(dp[n][0],dp[n][1]),dp[n][2]));
	return 0;
}


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

int main(int argc, char const *argv[])
{
    int a,b,d,r;
    double f;
    cin >> a >> b;
    d = a/b;
    r = a%b;
    f = a*1.0/b;
    printf("%d %d %f\n", d,r,f);
    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    double ans = w * h / 2.0;
    bool flag = false;
    if (w%2 == 0 && h%2 == 0 && w/2 == x && h/2 == y) flag = true;
    cout << fixed << setprecision(10) << ans << " " << flag << endl;
}

Measured memory_bytes: 256
import collections

n = int(input())
a = list(map(int, input().split()))
b = collections.deque()

for i in range(n):
    if i % 2 == 0:
        b.append(a[i])
    else:
        b.appendleft(a[i])

if n % 2 == 1:
    b.reverse()

print(*b)

Measured memory_bytes: 25540
l=list(map(int,input().split()))
l.sort()
a=l[2]-l[1]
b=l[2]-l[0]
if(a%2==0 and b%2==0):
    print(a//2+b//2)
elif(a%2==1 and b%2==1):
    print(a//2+b//2+1)
else:
    print(a//2+b//2+2)

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

int main(void) {
	int a, b, k;
	cin >> a >> b >> k;
	int m = min(a, b);
	int cnt = 0;
	int ans;
	for (int i = m; i > 0; i--) {
		if (a % i == 0 && b % i == 0) {
			cnt++;
			if(cnt == k) {
				ans = i;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
T = 165.step(185, 5).to_a
cs = Array.new 6, 0
gets.to_i.times do
  h = gets.to_f
  cs[T.find_index {|x| h < x } || 5] += 1
end
puts cs.map.with_index {|c, i| "#{i+1}:#{?**c}" }.join ?\n

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

int main() {
    string s;
    while (cin >> s) {
        if (s == "#") break;
        reverse(s.begin(), s.end());
        int cnt = 0, deg = 0;
        for (int i = 0; i < s.size(); cnt++) {
            if (s[i] == 'h') {
                if (i != 0) deg *= 2, deg--;
                i += 5;
            } else if (s[i] == 't') {
                deg *= 2, deg++;
                i += 4;
            }
        }
        deg *= 90;
        int all = 1 << (cnt - 1);
        while (deg % 2 == 0 && all % 2 == 0) deg /= 2, all /= 2;
        if (all == 1)
            cout << deg << endl;
        else
            cout << deg << "/" << all << endl;
    }
    return 0;
}


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

using namespace std;

void solve()
{
	int k;
	while(cin >> k, k)
	{
		int c = k * (k - 1) / 2;
		vector<int> Vec(c);
		for(int i = 0; i < c; ++i)
		{
			cin >> Vec[i];
		}
		int sum = 0;
		for(int i = 0; i < c; ++i)
		{
			sum += Vec[i];
		}
		sum /= (k - 1);
		cout << sum << endl;
	}
}

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

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

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

using namespace std;

int main(){
  int n;cin>>n;
  int x=n;

  int fx = 0;
  while(n!=0){
    fx += n%10;
    n/=10;
  }

  if(x%fx==0){
    cout<<"Yes";
  }else{
    cout<<"No";
  }

  return 0;
}

Measured memory_bytes: 256
n = int(input())
li = list(map(int,input().split()))
count = 0
for i in range(n-2):
    if(li[i] < li[i+1] and li[i+1] < li[i+2]):
        count += 1
    elif(li[i] > li[i+1] and li[i+1] > li[i+2]):
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

char s[4];
int main(){
	scanf("%s", s);
	REP(i, 3){
		if(s[i] == '7'){
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std ;
 
int main(){
    int N;
    cin >> N;
    vector<int> vec(N);

    for(int i=0; i<N; i++){
        cin >> vec.at(i);
    }

    sort(vec.begin(), vec.end());
    reverse(vec.begin(), vec.end());

    int alice=0;
    int bob=0;

    for(int i=0; i<N; i++){
        if(0 == i % 2){
            alice += vec.at(i);
        }
        else{
            bob += vec.at(i);
        }
    }
    
    cout << alice - bob << endl;
} 

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

int main()
{
    string res;
    cin>>res;
    int n=res.size();
    int right=0,ans=0;
    if(n==0)
    {
        cout<<ans;
        return 0;
    }
    else
    {
        int count=0;
        while(right<n)
        {
            if(res[right]=='R')
            {
                count++;
                ans=max(ans,count);
                right++;
            }
            else
            {
                count=0;
                right++;
            }
        }
    }
    
    
    cout<<ans;

    return 0;
}


Measured memory_bytes: 3620
$debug = false

def diff( box, cust )
	sum = 0
	0.upto( 8 - 1 ){|i|
		if( cust[ i ] >= box[ i ] )
			n = box[ i ]
		else 
			n = cust[ i ]
		end
		sum += (cust[ i ] - n)
	}
	return sum
end

def to_num( b )
	 b.inject{ |sum,item| sum * 10 + item }
end


answers = Array.new
box = [4,1,4,1,2,1,2,1]

while line = $stdin.gets
	cust = line.chomp.split( /\s/ ).map{ |e| e.to_i }

	b = box
	min_num = diff( b, cust )
	min_pat  = to_num( b )
	min_pat2 = b.dup

	1.upto( 7 ){
		b << b.shift
		left = diff( b, cust )

		if left < min_num
			min_num  = left
			min_pat  = to_num( b )
			min_pat2 = b.dup
		elsif left == min_num
			temp_pat = to_num(b)
			if temp_pat < min_pat
				min_pat  = temp_pat
				min_pat2 = b.dup
			end
		end
	}
	p min_pat2 if $debug
	answers << min_pat2
end

answers.each{ |a|
	a.each_with_index{ |e,i|
		print "#{e}" 
		print " " if i < 7 
	}
	puts
}


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

int j=0;
long long int n=10000,a=1000000000,min=1000000,max=-1000000,sum=0;

scanf("%lld",&n);

for(j=1;j<=n;j++){
	scanf("%lld, ",&a);
	
	
	if(a<=min){
		min=a;
	}
	if(a>=max){
		max=a;
	}
		sum+=a;
}

	printf("%lld %lld %lld\n",min,max,sum);
	
return 0;
}


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

int main()
{
    // 入力
    int N;
    cin >> N;

    vector<int> a(N);
    vector<int> box(N);
    rep(i, N) {
        cin >> a[i];
        box[i] = 0;
    }

    int M = 0;
    vector<int> b(N);
    for (int i = N - 1; i >= 0; i--) {
        int box_num = i + 1;

        int count = 0;
        for (int j = i; j < N; j += box_num) {
            if (box[j] == 1) {
                count++;
            }
        }

        if (count % 2 != a[i]) {
            box[i] = 1;
            b[M] = box_num;
            M++;
        }
    }

    // 出力
    if (M == 0) {
        cout << 0 << endl;
    } else {
        cout << M << endl;
        rep(i, M) {
            printf("%d%c", b[i], i != M - 1 ? ' ' : '\n');
        }
    }
    return 0;
}


Measured memory_bytes: 3200
#include <iostream>

using namespace std;

int main(){
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.size()<=k){
        for(int i=0;i<s.size();i++){
            cout<<s[i];
        }
        cout<<endl;
        
    }
    
    else {
       for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
        
    }
    
    return 0;
}

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

int main(){
	int n,k;
	cin >> n >> k;
	
	vector<int> h(n);
	rep(i,n) cin >> h[i];
	
	sort(h.begin(), h.end());
	
	int res = 1e9;
	
	rep(i,n){
		if(i+k-1 < n){
			res = min(res,h[i+k-1]-h[i]);
		}
	}
	
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s
}

fn main() {
	let n = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<String>>();

	let a = n[0].trim().split("").collect::<Vec<&str>>();
	let b = n[1].trim().split("").collect::<Vec<&str>>();
	let c = n[2].trim().split("").collect::<Vec<&str>>();

	if a[a.len() - 2] == b[1] && b[b.len() - 2] == c[1] {
		println!("YES");
	}else{
		println!("NO");
	}

}


Measured memory_bytes: 4352
table =[[[0]*10 for i in range(0,3)] for k in range(0,4)]
N = int(input())

for loop in range(N):
    B , F , R, V =map(int, input().split())
    table[B - 1][F - 1][R - 1] += V

x = 0

for i in range(4):
    if x != 0:
        print('#'*20)
    x += 1

    for k in range(3):

        for j in range(10):

            print(" %d" %(table[i][k][j]), end = '')
        print()




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

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (1<<(4*4-1))
#define MOD 1000000007

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

   int N;
   cin>>N;
   vector<ll>A(N),B(N);
   for(int i=0;i<N;i++)cin>>A[i];
   for(int i=0;i<N;i++)cin>>B[i];

   ll sumA = 0;
   ll sumB = 0;
   for(int i=0;i<N;i++){
      sumA += A[i];
      sumB += B[i];
   }

   if(sumA <= sumB){
      cout<<-1<<endl;
      return 0;
   }

   ll m = 0;
   ll p = 0;
   ll ans = 0;
   vector<ll>d;
   for(int i=0;i<N;i++){
      //cout<<A[i]<<" "<<B[i]<<endl;
      d.push_back(A[i]-B[i]);
   }

   ll n=0;
   sort(d.begin(),d.end());
   ll a=0;
   for(auto it:d){
      //cout<<it<<endl;
      if(it<0){
         a-=it;
         ans++;
      }
   }

   //cout<<a<<endl;
   if(ans==0){
      cout<<0<<endl;
      return 0;
   }

   //cout<<a<<endl;
   for(int i=N-1;i>=0;i--){
      //cout<<1<<endl;
      if(d[i]>0){
         //cout<<a<<" "<<d[i]<<endl;
         if(a<=d[i]){
            ans++;
            cout<<ans<<endl;
            return 0;
         }
         ans++;
         a-=d[i];
      }
   }

   cout<<-1<<endl;
   return 0;
}


Measured memory_bytes: 2936
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)

#define LEN 500010
#define INF 0x3f3f3f3f
using namespace std;

void merge(int*, int, int, int);
void merge_sort(int*, int, int);

int cnt = 0;

signed main()
{
   int N;
   int a[LEN];
   cin.tie(0), ios::sync_with_stdio(false);

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

   merge_sort(a, 0, N);
   rep(i, N){
      cout << a[i] << (i+1 < N ? ' ' : '\n') ;
   }
   outl( cnt );
}

void merge(int* a, int left, int mid, int right)
{
   const int hl = mid - left;
   const int hr = right - mid;
   int L[hl+1], R[hr+1];

   rep(i, hl) L[i] = a[left+i];
   rep(i, hr) R[i] = a[mid +i];
   L[hl] = R[hr] = INF;

   int i=0, j = 0;
   for(int k = left; k < right; ++k){
      if(L[i] <= R[j])
         a[k] = L[i++];
      else
         a[k] = R[j++];
      ++cnt;
   }
   return;
}

void merge_sort(int *a, int left, int right)
{
   if( left + 1 < right ){
      const int mid = (left + right) / 2;
      merge_sort(a, left, mid);
      merge_sort(a, mid, right);
      merge(a, left, mid, right);
   }
}




Measured memory_bytes: 7044
package main

import "fmt"

func main() {
	var a string
	var b string
	fmt.Scan(&a)
	fmt.Scan(&b)
	var ans int
	for i := 0; i < len(a); i++ {
		if a[i] != b[i] {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4492
#include <string>
#include <vector>
#include <array>
#include <memory>
#include <iostream>
#include <algorithm>

using namespace std;
int main(void) {
	//boost::shared_ptr<vector<string>>  log(boost::make_shared<vector<string>>());
	//log->push_back("dd");
	//log->push_back("dde");
	//boost::shared_ptr<vector<string>>  blog(boost::make_shared<vector<string>>());
	//blog->push_back("fsdfsdfd");
	//OpChara a(3,log);
	//OpChara b(2,log);
	//OpChara c(1, log);
	//log->push_back("dde3");
	//std::ofstream ofs("output1.txt");
	//assert(ofs);
	//boost::archive::text_oarchive oa(ofs);
	//oa << (a);
	//ofs.close();
	//std::ofstream cofs("output2.txt");
	//assert(cofs);
	//boost::archive::text_oarchive coa(cofs);
	//coa << (b);
	//cofs.close();

	//// de-serialize
	//std::ifstream ifs("output1.txt");
	//assert(ifs);
	//boost::archive::text_iarchive ia(ifs);

	//ia >> (b);
	//
	//ifs.close();
	//std::ifstream cifs("output2.txt");
	//assert(cifs);
	//boost::archive::text_iarchive iac(cifs);
	//iac >> c;
	//
	//// check
	//b.actionlog->push_back("111");

	/*int n, m;
	cin >> n >> m;
	vector<vector<tyu>> Pots;
	for (int i = 0; i < n; ++i) {
		Pots.push_back(vector<tyu>());
		int k;
		cin >> k;
		for (int j = 0; j < k; ++j) {
			int s,h;
			cin >> s >> h;
			Pots[i].push_back({ s,h });
		}
	}
	double ans=0;
	while (1) {

	
		vector<memo> amemo;
		for (int i = 0; i < n; ++i) {
			double h = 0;
			int taiseki = 0;
			for (int j = 0; j < Pots[i].size(); ++j) {
				bool flag = false;
				if (m > taiseki+ Pots[i][j].height*Pots[i][j].wide) {
					h += Pots[i][j].height;
					taiseki += Pots[i][j].height*Pots[i][j].wide;
				}
				else {
					flag = true;
					h += (double(m - taiseki)) / Pots[i][j].wide;
					taiseki = m;
				}
				const double akouritu = double(taiseki) / h;
				amemo.push_back({ akouritu, i, h,j,taiseki });
				if (flag) { break; }
			}
		}
		sort(amemo.begin(), amemo.end(), [](const memo m1, const memo m2) {return m1.kouritu < m2.kouritu; });
		bool flag=false;
		memo me = *amemo.begin();
		m -= me.taiseki;
		if (m < 0.0000000001) {
			flag = true;
		}
		ans += me.height;
		for (int i = 0; i < me.num + 1;++i) {
			Pots[me.id].erase(Pots[me.id].begin());
		}
		if (flag) {
			break;
		}
		
	}
	printf("%.10d", &ans);
	cout << ans;*/
	int t;
	cin >> t;
	for (int k = 0; k < t; ++k) {
		long long int h, w;
		cin >> h >> w;
		if (h == w) {
			cout << 1 << " " << 0 << endl;
			continue;
		}
		long long int l = 1;
		long long int a = h;
		long long int b = w;
		while (1) {
			if (a > b) {
				a = a%b;
				if (a == 0) {
					l = b;
					break;
				}
			}
			else {
				if (a == b) {
					l = a; break;
				}
				long long int ddd = a;
				a = b;
				b = ddd;
			}
		}
		h /= l;
		w /= l;
		
		if (h % 2 == 1 && w % 2 == 1) {
			cout << (h*w + 1) / 2 << " " << (h*w - 1) / 2 << endl;
		}
		else {
			cout << 1 << " " << 1 << endl;
		}
		
	}
	
	return 0;

}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;

  int N, X;
  cin >> N >> X;
  int count = 1, sum = 0;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    sum += a;
    if(sum <= X){
      count++;
    }
  }
  cout << count <<endl;
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;

int N, W;
vector<vector<int>> dp;
int main() {
    cin >> N >> W;
    vector<int> v(N);
    vector<int> w(N);
    REP(i,N){
        cin >> v[i] >> w[i];
    }
    dp.assign(N+1, vector<int>(W+1,0));
    FOR(i,0,N){
        FOR(j,0,W+1){
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);//選ばない

            if(j-w[i] >= 0){//選ぶ
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
                dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
            }
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}



Measured memory_bytes: 6796
#pragma  warning (disable:4996) 
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<utility>
#include<iomanip>
#include<set>
#include <numeric>
#include<map>
using namespace std;
typedef long long ll;
const int dx[] = { -1,1,0,0,-1,-1,1,1 };
const int dy[] = { 0,0,-1,1,-1,1,-1,1 };

int main()
{
	int  x, y;
	scanf("%d%d", &x, &y);
	if (llabs(x - y) >= 2)
		printf("Alice\n");
	else
		printf("Brown\n");
}

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

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        int H = NextInt();
        int W = NextInt();
        long[,] dp = new long[H, W];
        string[] map = new string[H];
        for (int i = 0; i < H; i++) map[i] = NextString();
        dp[0, 0] = 1;
        for (int i = 0; i < H; i++)
            for (int j = 0; j < W; j++)
            {
                if (j != W - 1 && map[i][j + 1] != '#') { dp[i, j + 1] += dp[i, j]; dp[i, j + 1] %= INF; }
                if (i != H - 1 && map[i + 1][j] != '#') { dp[i + 1, j] += dp[i, j]; dp[i + 1, j] %= INF; }
                dp[i, j] %= INF;
            }
        Console.WriteLine(dp[H - 1, W - 1]);
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 29016
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

char in[200050];
int R[26][200050];
int L[26][200050];
int pos[200050];
int main() {
	scanf("%s", in + 1);
	int N = strlen(in + 1), i, j;
	for (i = 0; i < 26; i++) {
		for (j = 1; j <= N; j++) {
			L[i][j] = L[i][j - 1];
			if (in[j] == 'a' + i) L[i][j] = j;
		}
		R[i][N + 1] = N + 1;
		for (j = N; j >= 1; j--) {
			R[i][j] = R[i][j + 1];
			if (in[j] == 'a' + i) R[i][j] = j;
		}
	}

	int p = N+1, len = 0;
	pos[0] = N + 1;
	while (1) {
		len++;
		int mn = N + 1;
		for (i = 0; i < 26; i++) mn = min(mn, L[i][p - 1]);
		pos[len] = mn;
		if (mn == 0) break;
		p = mn;
	}
	
	for (i = 1, j = 1; i <= len; i++) {
		for (int k = 0; k < 26; k++) {
			int p = R[k][j];
			if (pos[len - i] <= p) {
				j = p + 1;
				printf("%c", 'a' + k);
				break;
			}
		}
	}
	return !printf("\n");
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main()
{
    int64 n;
    cin >> n;
    if(n == 1){
        ANS(0);
        return 0;
    }
    int64 ans = 0;
    for(int64 rem = 1; rem * rem <= n; rem++){    //remainder
        int64 m = (n - rem) / rem;
        if(m == 0)continue;
        if(n / m == n % m)ans += m;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
t_prev,a_prev=map(int,input().split())
for i in range(n-1):
  t,a=map(int,input().split())
  k=max(t_prev//t+min(1,t_prev%t),a_prev//a+min(1,a_prev%a))
  t_prev,a_prev=t*k,a*k
    
print(t_prev+a_prev)

Measured memory_bytes: 38768
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        lld x,k,d;
        cin>>x>>k>>d;
        x=abs(x);
        lld a=x/d;
        if(a<k)
        {
            x=x-a*d;
            k-=a;
            if(k%2==0)
                cout<<x<<endl;
            else
                cout<<min(abs(x+d),abs(x-d));
        }
        else
        {
            x=x-k*d;
            cout<<x<<endl;
        }
    }
}





Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;

int N, A[3][3], b[10];

int main(void){
  rep(i,3){
    rep(j,3){
      cin >> A[i][j];
    }
  }
  cin >> N;
  rep(i,N) cin >> b[i];

  bool appear[3][3];
  rep(i,3){
    rep(j,3){
      appear[i][j] = false;
      rep(k,N){
        if (A[i][j] == b[k]) appear[i][j] = true;
      }
    }
  }

  string ans = "No";
  rep(i,3){
    if (appear[i][0] && appear[i][1] && appear[i][2]) ans = "Yes";
    if (appear[0][i] && appear[1][i] && appear[2][i]) ans = "Yes";
  }
  if (appear[0][0] && appear[1][1] && appear[2][2]) ans = "Yes";
  if (appear[0][2] && appear[1][1] && appear[2][0]) ans = "Yes";

  cout << ans << endl;
}


Measured memory_bytes: 3572
def main():
    n = int(input())
    s = ['' for _ in range(n)]
    for i in range(n):
        s[i] = input()

    appearance = dict()
    for i in range(n):
        s[i] = tuple(sorted(s[i]))
        if s[i] not in appearance:
            appearance.update({s[i]: 1})
        else:
            appearance[s[i]] += 1

    ans = 0
    for _, x in appearance.items():
        ans += (x * (x - 1)) // 2

    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25240
#include<bits/stdc++.h>
using namespace std;
#define LL long long

int main(){
	// sengen
	string n;
	// nyuryoku
	cin >> n;
	// keisan
	int m = 0;
	int add;
	for(int i=0;i<n.size();i++){
		add = n[i] - '0';
		m = (m + add)%9;
	}
	// syutsuryoku
	if(m == 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  REP(i, n) {
    string s;
    cin >> s;
    sort(ALL(s));
    mp[s]++;
  }
  ll ans = 0;
  for (auto& x : mp) {
    ll c = x.second;
    ans += c * (c - 1) / 2;
  }
  cout << ans << endl;
}

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

int main()
{
        std::string s;
        std::cin >> s;
        int n = 0;
        for (char ch : s) {
                if (ch == '+')
                        ++n;
                if (ch == '-')
                        --n;
        }
        std::cout << n << "\n";
        return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
int a[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	int mx = 0;
	for(int i = 1; i <= n; i++){
		cin>>a[i];
		mx = max(mx, a[i]);
	}
	cout<<mx<<" ";
	int sn = (a[1] == mx)?a[2]:a[1];
	for(int i = 1; i <= n; i++){
		if(abs(mx - 2*sn) > abs(mx - 2*a[i]))sn = a[i];
	}
	cout<<sn<<'\n';


	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <functional>
#include <iostream>
#include <set>
#include<iomanip>
#include<queue>
#include <cstdint>
#include <string>


using namespace std;
int pow3(int n){
	int ret=1;
	for (int i=0;i<n;i++){
		ret = ret*3;
	}
	return ret;
}
int pow10(int n){
	int ret=1;
	for (int i=0;i<n;i++){
		ret = ret*10;
	}
	return ret;
}
bool meet_condition(int* digit_3,int size,int maxnum){
	bool three = false;
	bool five = false;
	bool seven = false;
	int num = 0;
	for(int i=0;i<size;i++){
		switch(digit_3[i]){
		case 0:
			three=true;
			num+=3*pow10(i);
			break;
		case 1:
			five = true;
			num+=5*pow10(i);
			break;
		case 2:
			seven = true;
			num+=7*pow10(i);
			break;
		}
	}
	return (three&&five&&seven&&(num<=maxnum));
}
int main() {
	int n;
	cin>>n;
	int ncopy=n;
	int digit[10];
	for(int i=9;i>=0;i--){
		digit[i]=ncopy/pow10(i);
		ncopy=ncopy-digit[i]*pow10(i);
	}
	int top_digit=0;
	for(int i=9;i>=0;i--){
		if(digit[i]!=0){
			top_digit=i;
			break;
		}
	}
	int ans=0;
	for(int i=2;i<=top_digit;i++){
		//i+1桁
		for(int k=0;k<=-(1-pow3(i+1));k++){
			int copy = k;
			//kを3進化する
			int digit_3[i+1];
			for(int l=i;l>=0;l--){
				digit_3[l]=copy/pow3(l);
				copy = copy - digit_3[l]*pow3(l);
			}
			if(meet_condition(digit_3,i+1,n)){
				ans++;
			}
		}
	}
	cout<<ans<<endl;



	return 0;

}


Measured memory_bytes: 256
main :: IO ()
main = do
 s <- getLine :: IO String 
 print $ fixBatch s
 
fixBatch :: String -> Int
fixBatch xs
  |even $ length xs = 
    let half = length xs `div` 2
      in length $ filter (\t -> fst t /= snd t) $ zip (take half xs) (reverse $ drop half xs)
  |otherwise =  
    let half = length xs `div` 2
      in length $ filter (\t -> fst t /= snd t) $ zip (take half xs) (reverse $ drop (half+1) xs)



Measured memory_bytes: 380
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=10000000000000007;
const int MOD=1000000007;
int dp[5][2][300000];
signed main(){
  int n;cin>>n;
  vector<int> a(n+5,-inf);
  rep1(i,n)cin>>a[i];
  rep1(i,n){
    a[i]+=MOD;
  }
  int res=0;
  rep(i,5){
    rep(j,300000){
      dp[i][0][j]=0;
      dp[i][1][j]=0;
    }
  }
  
  rep1(i,n){
    dp[0][0][i]=dp[0][1][i-1];
    dp[0][1][i]=dp[0][0][i-1]+a[i];
    dp[1][0][i]=max(dp[0][0][i-1],dp[1][1][i-1]);
    dp[1][1][i]=dp[1][0][i-1]+a[i];
    dp[2][0][i]=max(dp[2][1][i-1],max(-inf,dp[1][0][i-1]));
    dp[2][1][i]=dp[2][0][i-1]+a[i];
    if(i<=1){
      dp[1][1][i]=0;
      //dp[1][0][i]=0;
    }
    if(i<=1){
      dp[2][1][i]=0;
      //dp[2][0][i]=0;
    }
  }
  	if(n%2==0){
      cout<<max(dp[0][1][n],max(dp[0][0][n],dp[1][1][n]))-MOD*n/2<<endl;
    }
    else{
      //exit(1);
      res=max(max(-dp[2][0][n],dp[2][1][n]),max(dp[1][1][n],dp[1][0][n]));
      if(res==-dp[2][0][n])exit(1);
      cout<<res-n/(int)2*MOD<<endl;
      //cout<<dp[2][0][n]<<"\n";
      //cout<<dp[2][1][n]<<"\n";
    }
  return 0;
}


Measured memory_bytes: 28348
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long int> list(n+1);
  list.at(0) = 2;
  list.at(1) = 1;
  for (int i=2; i<=n; i++) {
    list.at(i) = list.at(i-1)+list.at(i-2);
  }
  cout << list.at(n) << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from itertools import accumulate
def main():
    n=int(input())
    A=[int(_) for _ in input().split()]
    A=list(accumulate(A))
    min_A=100000000000
    for a in A:
        min_A=min(min_A,abs(A[-1]/2-a))
    print(int(min_A*2))

if __name__=='__main__':
    main()

Measured memory_bytes: 91624
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
template <class T> void chmax(T &x, T y) { if (x < y) x = y; }
int A[200][200], B[200][200];
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int H, W; cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            for (int k = j + 1; k < W; k++) {
                B[j][k] = B[j][k] + A[i][j] + A[i][k];
            }
        }
        for (int k = 0; k < W; k++) {
            for (int j = 0; j + 1 < k; j++) {
                chmax(B[j + 1][k], B[j][k] + A[i][j + 1]);
            }
        }
        for (int j = 0; j < W; j++) {
            for (int k = j + 1; k + 1 < W; k++) {
                chmax(B[j][k + 1], B[j][k] + A[i][k + 1]);
            }
        }
        for (int k = 0; k < W; k++) {
            for (int j = 0; j + 1 < k; j++) {
                chmax(B[j + 1][k], B[j][k]);
            }
        }
    }
    cout << B[W - 2][W - 1] << endl;
    return 0;
}


Measured memory_bytes: 640
/*
      author : nishi5451
      created: 11.08.2020 20:57:02
*/

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


int main(){
    int a,b;
    cin >> a >> b;
    if(a*b%2==0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3520
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
const int INF=1e9+5;
const int N=2e5;
const int mod=998244353;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int A,B,M;
	cin>>A>>B>>M;
	int min_a=INF,min_b=INF;
	vector<int> a(A),b(B);
	int ans=INF*2;
	for(int i=0;i<A;++i) cin>>a[i],min_a=min(min_a,a[i]);
	for(int i=0;i<B;++i) cin>>b[i],min_b=min(min_b,b[i]);
	ans=min(ans,min_a+min_b);
	for(int i=0;i<M;++i){
		int x,y,c;
		cin>>x>>y>>c;
		--x;
		--y;
		ans=min(ans,a[x]+b[y]-c);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 1024
from sys import stdin

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        # self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        # self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
            #print(i)
    '''
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)
    '''

N,Q = map(int, stdin.readline().split())
c = list(map(int, stdin.readline().split()))

query = []

for i in range(Q):
    l,r = map(int, stdin.readline().split())
    query.append((i,l,r))

query.sort(key = lambda x:x[2])

###
#print(query)
###

ans = [0]*Q
place = [-1]*(N+1)###各色のいい玉がどこにあるか、なければ-1
next_query = 0

bit = BIT(N)

###
#print(bit)
###

for i in range(N):

    bit.add(i+1,1)

    if place[c[i]] != -1:
        bit.add(place[c[i]]+1,-1)

    place[c[i]] = i

    #print(i,bit.data,place)

    while next_query < len(query) and query[next_query][2] == i+1:
        ###
        #print(query[next_query])
        ###
        j,l,r = query[next_query]
        ans[j] = bit.sum(r)-bit.sum(l-1)###l,rは入力時のまま(1-indexed)であることに注意
        next_query += 1
        ###
        #print(i,ans)
        ###
        

    ###
    #print(i,ans)
    ###
    
'''
for i in range(Q):
    print(ans[i])
'''

print(*ans,sep='\n')





Measured memory_bytes: 189644