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

vector<string> v;
vector<int> len;
vector<bool> ch[3];

int solve();

int main() {
  for(int i = 0; i < 3; ++i) {
    string s;
    cin >> s;
    v.push_back(s);
    len.push_back(s.size());
  }
  cout << solve() << endl;
  return 0;
}

int solve() {
  int res = len[0] + len[1] + len[2], sum;
  sum = res;
  ch[0].assign(2 * sum, 1);
  for(int i = 0; i < 2 * sum; ++i) {
    for(int j = 0; j < len[0]; ++j)
      if(i + j >= sum && i + j - sum < len[1])
        ch[0][i] =
            ch[0][i] &
            (v[0][j] == '?' || v[1][i + j - sum] == '?' ||
             v[0][j] == v[1][i + j - sum]);
  }
  ch[1].assign(2 * sum, 1);
  for(int i = 0; i < 2 * sum; ++i) {
    for(int j = 0; j < len[2]; ++j)
      if(i + j >= sum && i + j - sum < len[1])
        ch[1][i] =
            ch[1][i] &
            (v[2][j] == '?' || v[1][i + j - sum] == '?' ||
             v[2][j] == v[1][i + j - sum]);
  }
  ch[2].assign(2 * sum, 1);
  for(int i = 0; i < 2 * sum; ++i) {
    for(int j = 0; j < len[2]; ++j)
      if(i + j >= sum && i + j - sum < len[0])
        ch[2][i] =
            ch[2][i] &
            (v[2][j] == '?' || v[0][i + j - sum] == '?' ||
             v[2][j] == v[0][i + j - sum]);
  }

  for(int i = 0; i < 2 * sum; ++i)
    for(int j = 0; j < 2 * sum; ++j)
      if(ch[0][i] && ch[1][j] && j - i + sum >= 0 &&
         j - i + sum < 2 * sum && ch[2][j - i + sum]) {
        int nowl = min({sum, i, j}),
            nowr =
                max({sum + len[1], i + len[0], j + len[2]});
        res = min(res, nowr - nowl);
      }
  return res;
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>

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

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<string, int> P;
#define mod 1e9 + 7;
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}

int ab[100010];

int main()
{
	ios_base::sync_with_stdio(false);
	ll a, b, c, n, m;
	string s;
	cin >> n >> a;
	cout << n - a + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
"""
j−i != k−j
の条件がなければ、Rの数*Gの数*Bの数(*1)が答え

そこでまず*1を求めて、次に
j-i == k-j
となるような場合の数を求め、*1から引いたものが答え
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
n = int(readline())
s = readline()

a = [0]*n
for i in range(n):
    if s[i] == 'R': a[i] = 0
    if s[i] == 'G': a[i] = 1
    if s[i] == 'B': a[i] = 2

cnt = [0]*3
for i in range(n):
    cnt[a[i]] += 1
    
ans = 1
for i in range(3):
    ans *= cnt[i]

for j in range(n):
    for i in range(j):
        k = j + (j-i)
        if k < n:
            if a[i] == a[j]: continue
            if a[i] == a[k]: continue
            if a[k] == a[j]: continue
            ans -= 1

print(ans)

Measured memory_bytes: 9256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 5e3 + 10;
ii a[N];
int64 dp[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
  }
  sort(a, a + n, [](const ii& a, const ii& b) {
      return a.first + a.second < b.first + b.second;
    });
  for (int i = 1; i <= n; ++i) dp[i] = 1LL << 60;
  dp[0] = 0;
  dp[1] = a[0].second;
  for (int i = 1; i < n; ++i) {
    // trace(a[i].first, a[i].second);
    // for (int j = 1; j <= i; ++j) {
    //   cout << dp[j] << " ";
    // }
    // cout << endl;
    for (int j = i + 1; j >= 1; --j) {
      if (a[i].first >= dp[j - 1]) {
        dp[j] = min(dp[j - 1] + a[i].second, dp[j]);
      }
    }
  }
  for (int j = n; j >= 0; --j) {
    if (dp[j] != (1LL << 60)) {
      printf("%d\n", j);
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 384
x, y = map(int, input().split())
if (y - 2 * x) % 2 == 0 and y - 2 * x >= 0:
    b = (y - 2 * x) // 2
else:
    print('No')
    exit()
if x - b >= 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9180
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define FORR(i, a, b) for(int i = (a); i > (b); --i)
#define REP(i, n) FOR(i, 0, n)
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define FINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) ((a) <= (i) && (i) <= (b))
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a > b) { a = b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a < b) { a = b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(begin(a), end(a)); }
template <typename T> inline void REV(T& a) { reverse(begin(a), end(a)); }
template <typename T> inline void UNI(T& a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); }
template <typename S, typename T> inline T LB(S& v, T a) { return *lower_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int LBP(S& v, T a) { return lower_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> inline T UB(S& v, T a) { return *upper_bound(begin(v), end(v), a); }
template <typename S, typename T> inline int UBP(S& v, T a) { return upper_bound(begin(v), end(v), a) - begin(v); }
template <typename S, typename T> ostream& operator << (ostream& os, const pair<S, T>& p) { os << p.first << " " << p.second; return os; }
template <typename S, typename T> istream& operator >> (istream& is, pair<S, T>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator << (ostream& os, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator >> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> 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); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int X;

void _main() {
    cin >> X;
    cout << (X == 3 || X == 5 || X == 7 ? "YES" : "NO") << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(ll L, ll R) {
    ll answer = LONG_LONG_MAX;
    REP(i,0,2020) {
        REP(j,i+1,2020) {
            if (L+i > R || L+j > R) break;
            answer = min((L+i) * (L+j) % 2019, answer);
        }
    }
	stringstream ss;
	ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    ll L, R;
    cin >> L >> R;
    
//    vector<int> A(N);
//    REP(i,0,N) cin >> A[i];
    
    solve(L, R);
    
    return 0;
}



Measured memory_bytes: 256
N = int(input())
*H, = map(int, input().split())

max = 0
temp = 0

for h_index in range(0, len(H)-1, 1):
    if H[h_index]>=H[h_index+1]:
        temp = temp + 1
        continue
    if max < temp:
        max = temp
    temp = 0
if max < temp:
    max = temp

print(max)

Measured memory_bytes: 14252
package main

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

var sc *bufio.Scanner

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	hArray := make([]int, n)
	for i := range hArray {
		hArray[i] = nextInt()
	}

	ans := 0
	subAns := 0
	for i := 0; i < n-1; i++ {
		switch {
		case hArray[i] >= hArray[i+1]:
			subAns++
		default:
			ans = maxInt(ans, subAns)
			subAns = 0
		}
	}
	ans = maxInt(ans, subAns)
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main() {
    string s;
    cin >> s;
    if (s.length() <= 1) {
        cout << s << endl;
        return 0;
    }
    int x = 0;
    for (int i = 1; i < s.length(); ++i) {
        if (s[i] != '9') {
            cout << x + atoi(s.substr(i-1, 1).c_str()) - 1 + 9 * (s.length()-i) << endl;
            return 0;
        }
        x += atoi(s.substr(i-1, 1).c_str());
    }

    cout << x + 9 << endl;

    
    return 0;
}


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

const double INF = 1e30;
typedef complex<double> P;
double dp[14][2][1<<14];

int main()
{
	int caseNum = 0;
	int N;
	while(cin >> N, N) {
		vector<P> points(2*N);

		double sum = 0;
		for(int i=0; i<N; i++) {
			double a,b,x,y;
			cin >> a >> b >> x >> y;
			points[2*i + 0] = P(a,b);
			points[2*i + 1] = P(x,y);

			sum += abs(points[2*i] - points[2*i + 1]);
		}

		for(int i=0; i<(1<<N); i++)	
		for(int j=0; j<14; j++)
		for(int k=0; k<2; k++)
			dp[j][k][i] = INF;

		for(int i=0; i<N; i++)
		for(int j=0; j<2; j++)
			dp[i][j][1<<i] = 0;

		for(int i=0; i<(1<<N); i++) 
			for(int j=0; j<N; j++) {
				if(!(i >> j & 1)) continue;
				for(int a=0; a<2; a++)
				for(int k=0; k<N; k++) {
					if(i >> k & 1) continue;
					for(int b=0; b<2; b++) {

					dp[k][b][i | (1<<k)] = min(dp[k][b][i | (1<<k)], dp[j][a][i] + abs(points[2*j + (a+1)%2] - points[2*k + b]));
				}
			}
		}

		double res = INF;
		for(int i=0; i<2; i++)
		for(int j=0; j<N; j++)
			res = min(res, dp[j][i][(1<<N)-1]);

		cout.setf(ios::fixed);
		cout.precision(10);
		cout << "Case " << ++caseNum << ": " << res + sum << endl;


	}
}

Measured memory_bytes: 4612
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <numeric>


using namespace std;
#define ll long long

vector<int> prime(ll f){
  vector<int> ans(1,2);
  for(int i = 3;i <= sqrt(f);i ++){
    int p = 0;
    bool jud = true;
    while(ans[p]<=sqrt(i)){
      if(i % ans[p] == 0){
        jud = false;
        break;
      }
      p++;
    }
    if(jud == true){
      ans.insert(ans.end(),i);
    }
  }
  return ans;
}

int main(void){
  ll a,b;
  cin >> a >> b;
  while(a !=  b){
    if(a > b){
      if(a % b == 0){
        a = b;
      }else{
        a = a % b;
      }
    }else{
      if(b % a == 0){
        b = a;
      }else{
        b = b % a;
      }
    }
  }
  vector<int> pri = prime(a);
  vector<int> prnum(pri.size()+1,0);
  int s = pri.size();
  for(int i = 0;i < s;i ++){
    while(a % pri[i] == 0){
      a = a / pri[i];
      prnum[i] ++;
    }
    if(a == 1){
      break;
    }
  }
  if(a != 1){
    prnum[pri.size()]++;
  }
  int ans = 1;
  s = prnum.size();
  for(int i = 0;i < s;i ++){
    if(prnum[i]>0){
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 4048
#![allow(non_snake_case)]
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use whiteread::parse_line;
use std::collections::*;
use num::*;
use num_traits::*;
use superslice::*;
use std::ops::*;

use itertools::Itertools;
use itertools_num::ItertoolsNum;

#[fastout]
fn main() {
    input!{
        a: isize, b: isize, c: isize,
    }

    let flag = if b-a == c-b { true } else { false };

    if flag {
        println!("YES");
    } else {
        println!("NO");
    }
    

    println!("", );
}


Measured memory_bytes: 2124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3],a5=0,a7=0;
    cin>>a[0]>>a[1]>>a[2];
    for(int i=0;i<3;i++)
    {
        if(a[i]==5)  a5++;
        else if(a[i]==7)  a7++;
    }
    if(a5==2&&a7==1)  cout<<"YES";
    else  cout<<"NO";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
use std::io::Read;
use std::cmp::{max, min};


#[derive(Debug)]
struct BIT{
    bit: Vec<i64>,
}

impl BIT{
    pub fn new(n: &usize) -> BIT{
        BIT{bit:vec![0;*n+1]}
    }
    pub fn add(&mut self, pos: &usize, val: &i64){
        let mut ind:i64 = *pos as i64 + 1;
        while ind < self.bit.len() as i64{
            self.bit[ind as usize] += *val;
            ind += ind & -ind;
        }
    }
    
    pub fn get(&self, pos: &usize)->i64{
        let mut ind:i64 = *pos as i64 + 1;
        let mut res = 0i64;
        while ind > 0{
            res += self.bit[ind as usize];
            ind -= ind & -ind;
        }
        res
    }
}

fn mod_pow(x: &i64, n: &i64, m: &i64) -> i64{
    if *n == 0{
        return 1;
    }
    if n % 2 == 0{
        let half = mod_pow(&x, &(n / 2), &m);
        return half * half % m;
    }
    else{
        let dec = mod_pow(&x, &(n-1), m);
        return dec * x % m;
    }
}
    
fn main(){
    let mut buf = String::new();
    
    let mod_val = 998244353i64;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n:i64 = iter.next().unwrap().parse().unwrap();
    let mut points = vec![];
    let mut xs = vec![];
    let mut ys = vec![];
    for _ in 0..n{
        let x:i64 = iter.next().unwrap().parse().unwrap();
        let y:i64 = iter.next().unwrap().parse().unwrap();
        xs.push(x.clone());
        ys.push(y.clone());
        points.push((x,y));
    }
    xs.sort();
    ys.sort();
    for i in 0..n{
        let (x,y) = points[i as usize];
        let nx = xs.binary_search(&x).unwrap() as i64;
        let ny = ys.binary_search(&y).unwrap() as i64;
        points[i as usize] = (nx, ny);
    }
    points.sort();
    let mut res = (mod_pow(&2, &n, &mod_val) - 1) * n % mod_val;
    for i in 0..n{
        res -= mod_pow(&2, &(n-i-1), &mod_val) - 1;res %= mod_val;
        res -= mod_pow(&2, &(n-i-1), &mod_val) - 1;res %= mod_val;
        res -= mod_pow(&2, &(i), &mod_val) - 1;res %= mod_val;
        res -= mod_pow(&2, &(i), &mod_val) - 1;res %= mod_val;
    }
    let mut bit1 = BIT::new(&(n as usize));
    for i in 0..n{
        let &(x,y) = &points[i as usize];
        let up = bit1.get(&(y as usize));
        let down = i - bit1.get(&(y as usize));
        res += mod_pow(&2, &up, &mod_val)-1;res %= mod_val;
        res += mod_pow(&2, &down, &mod_val)-1;res %= mod_val;
        bit1.add(&(y as usize), &1i64);
    }
    let mut bit2 = BIT::new(&(n as usize));
    for i in 0..n{
        let &(x,y) = &points[(n-i-1) as usize];
        let up = bit2.get(&(y as usize));
        let down = i - bit2.get(&(y as usize));
        res += mod_pow(&2, &up, &mod_val)-1;res %= mod_val;
        res += mod_pow(&2, &down, &mod_val)-1;res %= mod_val;
        bit2.add(&(y as usize), &1i64);
    }
    println!("{}", res);
}




Measured memory_bytes: 20956
#include <stdio.h>

int main(){
  int a,b,c[4000],d,i,j,n;
  long long int p,q,r[4000];
  while(scanf("%d",&n)){
    if(n==0)break;
    for(i=0;i<4000;i++){c[i]=0;r[i]=0;}
    b=0;
    for(i=0;i<n;i++){
      scanf("%d %lld %lld",&d,&p,&q);
      if(b==0) j=0; else for(j=0;j<=b;j++) if(c[j]==d) break;
      c[j]=d;
      r[j]+=p*q;
      if(j>b++)b=j;
    }
    a=0;
    for(i=0;i<=b;i++)if(r[i]>999999){printf("%d\n",c[i]);a=1;}
    if(a==0)printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 0
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min (ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))

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

const int limit = 50;

int n, m;
int a[limit], b[limit];
bool graph[limit][limit];
bool visited[limit];

// 訪問可否判定DFS
void dfs(int v) {
    // v番目を訪問済み化（今いる場所）
    visited[v] = true;

    // v番目から連結している　かつ 未訪問　を全て訪問
    for (int v2 = 0; v2 < n; v2++) {
    // 未連結対応
    if (graph[v][v2] == false) continue;
    // 訪問済みは無視
    if (visited[v2] == true) continue;
    // 移動先を起点にして再起
    dfs(v2);
    }
}

int main(void) {
     cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        // A➡︎BとB➡︎Aの両方をつなげる
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    int ans = 0;

    for (int i = 0; i < m; ++i) {
        // i番目の連結を切る
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;

        // 全てを未訪問化
        for (int j = 0; j < n; ++j) visited[j] = false;
        
        // 訪問可否判定
        dfs(0);

        // 未訪問があれば橋としてカウント        
        bool bridge = false;
        for (int j = 0; j < n; ++j) if (visited[j] == false) bridge = true;
        if (bridge) ans += 1;
        
        // i番目の連結を元に戻す
        graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
    }

    // 結果の出力
    cout << ans << endl;
    return 0;
}

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

int main()
{
    int k, q;
    cin>>k>>q;
    vector<long long> d(k);
    for (long long &x: d)
        cin>>x;

    for (int qi=0; qi<q; qi++)
    {
        long long n, x, m;
        cin>>n>>x>>m;

        long long t = 0;
        for (int i=0; i<k; i++)
            t += (d[i]+m-1)%m+1;
        long long s = x+(n-1)/k*t;
        for (int i=(n-1)/k*k; i<n-1; i++)
            s += (d[i%k]+m-1)%m+1;
        cout<<n-1-(s/m-x/m)<<endl;
    }
}


Measured memory_bytes: 760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for(int i=1; i<=n; i++) {
            int nn = Integer.toString(i).length();
            if(nn % 2 != 0) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 40808
import math
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
pi=math.pi
hl=[[pi,0,0,-pi] for i in range(n)]
for i in range(n):
    x1,y1=l[i]
    for j in range(i+1,n):
        x2,y2=l[j]
        if x1==x2:
            if y1>y2:
                hl[i][3]=0
                hl[j][0]=0
            else:
                hl[i][0]=0
                hl[j][3]=0
        else:
            r=math.atan((y2-y1)/(x2-x1))+pi/2
            if x2>x1:
                hl[j][3]=max(hl[j][3],r-pi)
                hl[j][0]=min(hl[j][0],r)
                hl[i][1]=max(hl[i][1],r)
                hl[i][2]=min(hl[i][2],r-pi)
            else:
                hl[i][3]=max(hl[i][3],r-pi)
                hl[i][0]=min(hl[i][0],r)
                hl[j][1]=max(hl[j][1],r)
                hl[j][2]=min(hl[j][2],r-pi)
for i in hl:
    a,b,c,d=i
    print((max(0,a-b)+max(0,c-d))/(2*pi))

Measured memory_bytes: 3188
#include <vector>
#include <iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>

using namespace std;

int main()
{
    int n,x,y,k=1,l,r;
    double ans=0;
    vector<pair<int,int> > v;
    vector<int> a;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        k*=i;
        cin>>x>>y;
        v.push_back(make_pair(x,y));
    }
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++) 
        {
            x=v[i].first;
            y=v[i].second;
            l=v[j].first;
            r=v[j].second;
            ans+=sqrt( (x-l) * (x-l) + (y-r) * (y-r));
        }
    }
    ans*=2;
    ans/=n;
    cout<<fixed<<setprecision(10)<<ans;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := iSScan(n)
	d := make(map[int]int)
	for _, v := range a {
		d[v]++
	}
	if len(d) == 3 {
		ks := make([]int, 0)
		for k, _ := range d {
			ks = append(ks, k)
		}
		if ks[0]^ks[1]^ks[2] == 0 && d[ks[0]] == d[ks[1]] && d[ks[1]] == d[ks[2]] {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else if len(d) == 2 {
		ks := make([]int, 0)
		for k, _ := range d {
			ks = append(ks, k)
		}
		if d[ks[0]]*2 == d[ks[1]] {
			if ks[0] == 0 {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		} else if d[ks[1]]*2 == d[ks[0]] {
			if ks[1] == 0 {
				fmt.Println("Yes")
			} else {
				fmt.Println("No")
			}
		} else {
			fmt.Println("No")
		}
	} else if len(d) == 1 {
		if a[0] == 0 {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 9308
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] abo = new int[4];
		while (scanner.hasNext()) {
			
			String str = scanner.nextLine().split(",")[1];
			if (str.equals("A"))
				abo[0]++;
			else if (str.equals("B"))
				abo[1]++;
			else if (str.equals("AB"))
				abo[2]++;
			else
				abo[3]++;
		}
		for (int t : abo)
			System.out.println(t);
	}

}

Measured memory_bytes: 17172
#include <iostream>
#include <climits>
#define rep(i,a) for(i = 0; i < a; i++)
using namespace std;

int count = 0;
void marge(int *, int,int,int);
void margeSort(int *, int,int);

int main(void) {
  int i,n,l,r;
  cin >> n;
  int S[n];
  rep(i,n) {
    cin >> S[i];
  }
  l = 0;
  r = n;
  margeSort(S,l,r);
  rep(i,n){
    cout << S[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  cout << count << endl;
  return 0;
}

void marge(int *A, int l, int m, int r) {
  int n1,n2,i,j,k;
  n1 = m - l;
  n2 = r - m;
  int L[n1+1], R[n2+1];
  rep(i,n1) {
    L[i] = A[l + i];
  }
  rep(i,n2) {
    R[i] = A[m + i];
  }
  L[n1] = INT_MAX/2;
  R[n2] = INT_MAX/2;
  i = 0;
  j = 0;
  for(k = l; k < r; k++) {
    if(L[i] <= R[j]) {
      A[k] = L[i];
      i++;
    } else {
      A[k] = R[j];
      j++;
    }
    count++;
  }
}

void margeSort(int *A, int l, int r) {
  if(l+1 < r) {
    int m = (l + r) / 2;
    margeSort(A,l,m);
    margeSort(A,m,r);
    marge(A,l,m,r);
  }
}

Measured memory_bytes: 5064
#include<bits/stdc++.h>
using namespace std;
#define int long long int
typedef long double ld;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define mxe max_element
#define mne min_element
#define vi vector<int>
#define vvi vector<vi>
#define pi pair<int,int>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define mod 1000000007
#define inf 1000000000
vi h(100000);
vi dp(100000,-1);
int cost(int x){
	if(dp[x]!=-1) return dp[x];
	if(x==1 || x==2){
		return dp[x] = abs(h[x]-h[0]);
     }
     return dp[x] = min({(abs(h[x]-h[x-1])+cost(x-1)),(abs(h[x]-h[x-2])+cost(x-2))});
}
void solve(){
    int n;
    cin>>n;
    rep(i,0,n) cin>>h[i];
    cout<<cost(n-1);

 }
 

signed main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
	int test;
	//cin>>test;
	test=1;
	while(test--){
         solve();
         cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 6528
n, m = map(int, raw_input().split())

a = []
for i in range(10):
	a.append(map(int, raw_input().split()))

for i in range(10):
	for j in range(10):
		for k in range(10):
			for l in range(10):
				if a[j][l] > a[j][k] + a[k][l]:
					a[j][l] = a[j][k] + a[k][l]

s = 0
for i in range(n):
	for x in map(int, raw_input().split()):
		if x != -1:
			s += a[x][1]
print s


Measured memory_bytes: 2568
using System;
using System.Collections.Generic;
using System.Linq;
class abc168_b{
  public static void Main(){
    int n = int.Parse(Console.ReadLine());
    String str = Console.ReadLine();
    if(n < str.Length){
      Console.Write(str.Substring(0,n));
      Console.WriteLine("...");
    }
    else{
      Console.WriteLine(str);
    }
  }
}


Measured memory_bytes: 17632
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const int MOD = 1e9+7;
const ll INF =1e18;

int main(){
  int a,p;cin>>a>>p;
  cout<<(3*a+p)/2<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int minB = Integer.MAX_VALUE;
        int maxA = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            maxA = Math.max(maxA, a[i]);
            minB = Math.min(minB, b[i]);
        }

        System.out.println(maxA + minB);
    }

}

Measured memory_bytes: 65032
import sys
sys.setrecursionlimit(100000)

dxdy = {(-1, 0), (1, 0), (0, -1), (0, 1)}

h,w = map(int,input().split())
s = [str(input()) for i in range(h)]

ch = [[0] * w for i in range(h)]

ans = 0

for i in range(h):
    for j in range(w):
        if ch[i][j] == 0:
            black,white = 0,0
            q = [(i,j)]
            while q:
                y,x = q.pop()
                if ch[y][x] == 0:
                    if s[y][x] == "#":black += 1
                    else:white += 1
                    ch[y][x] = 1
                    for dx,dy in dxdy:
                        if 0 <= x + dx < w and 0 <= y + dy < h and ch[y+dy][x+dx] == 0 and s[y+dy][x+dx] != s[y][x]:
                            q.append((y+dy,x+dx))
            ans += black * white

print(ans)

Measured memory_bytes: 54620
package main

import (
	"fmt"
)

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	count := 0

	for i := a; i <= b; i++ {
		if i/10000 == i%10 {
			if (i/1000)%10 == (i%100)/10 {
				count++
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <bitset>
#include <sstream> 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;

#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()

#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y)  ? ( (x) > (z) ? (x) : (z)  ) : ( (y) > (z) ? (y) : (z) )  )
#define MIN3(x, y, z) ( (x) < (y)  ? ( (x) < (z) ? (x) : (z)  ) : ( (y) < (z) ? (y) : (z) )  )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))


#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)

#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)

#define INF 987654321
#define IINF 987654321987654321

int N,M,K,T,tc;
int main(void){
	ll x; cin >> x;
	ll ans = 1;
	while(true){
		ll t = (ans)*(ans+1)/2;
		if( t >= x ) break;
		ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

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

int main() {
	string s;
	cin >> s;

	reverse(s.begin(), s.end());

	
	int found = 0;
	int len = s.length();

	string samp[4] = { "maerd","remaerd","esare","resare" };

	for (int i = 0;i < len; ) {

		found = 0;
		for (int k = 0;k < 4;k++) {
			int samlen = samp[k].length();
			if (s.substr(i, samlen) == samp[k]) {
				i += samlen;
				found = 1;
				break;
			}
		}

		if (found == 0) break;
	}


	cout << (found ? "YES" : "NO") << endl;
	return 0;
}

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

int main(){
  int a, b;
  vector<int> vec(3);
  for (int i = 0; i < 3; i++){
    cin >> vec.at(i);
  }
  if(vec.at(0) % 2 == 1 || vec.at(1) % 2 == 1 || vec.at(2) % 2 == 1){
    cout << 0;
    return 0;
  }
  sort(vec.begin(), vec.end());
  a = vec.at(2) - vec.at(1);
  b = vec.at(1) - vec.at(0);
  int ca = -1, cb = -1, tmp;
  tmp = a;
  if (a != 0){
    ca = 0;
    while(tmp % 2 == 0){
      tmp /= 2;
      ca++;
    }
  }
  tmp = b;
  if (b != 0){
    cb = 0;
    while(tmp % 2 == 0){
      tmp /= 2;
      cb++;
    }
  }
  if(ca == -1) cout << cb;
  else if(cb == -1) cout << ca;
  else cout << min(ca, cb);
  return 0;
}

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

string s;

int di[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dj[] = {1, -1, 1, 0, -1, 1, 0, -1};

char check(int i, int j, int di, int dj) {
    char last = '?';
    for (int t = 0; t < 3; ++t) {
        if (i < 0 || i >= 3 || j < 0 || j >= 3) {
            return 'd';
        }
        if (last != '?' && last != s[i * 3 + j]) {
            return 'd';
        }
        last = s[i * 3 + j];
        i += di;
        j += dj;
    }
    if (last == 'o' || last == 'x') return last;
    return 'd';
}

int main() {
    while(cin >> s) {
        // cout << s<< endl;
        char ans = 'd';
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                for (int k = 0; k < 8; ++k) {
                    char tmp = check(i, j, di[k], dj[k]);
                    // cout <<  i << " " << j << " " << tmp << endl;
                    if (tmp != 'd') {
                        ans = tmp;
                        break;
                    }
                }
                if (ans != 'd') break;
            }
            if (ans != 'd') break;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3180
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]

l = [[(a_i in B) for a_i in a] for a in A]

x = [
    [(0, 0), (0, 1), (0, 2)],
    [(1, 0), (1, 1), (1, 2)],
    [(2, 0), (2, 1), (2, 2)],

    [(0, 0), (1, 0), (2, 0)],
    [(0, 1), (1, 1), (2, 1)],
    [(0, 2), (1, 2), (2, 2)],

    [(0, 0), (1, 1), (2, 2)],
    [(0, 2), (1, 1), (2, 0)],
]

flag = any(all(l[y][x] for x, y in pos_l) for pos_l in x)
# print(l)

# flag = 0
# for y in range(3):
#     flag |= all(l[y])

# for x in range(3):
#     flag |= all([l[x][y] for y in range(3)])

# flag |= all([l[y][x] for x, y in [(0, 0), (1, 1), (2, 2)]])

# flag |= all([l[y][x] for x, y in [(0, 2), (1, 1), (2, 0)]])

print("Yes" if flag else "No")

Measured memory_bytes: 3064
/*@author Vipen Loka*/
#include <bits/stdc++.h>
#define endl '\n'
#define ff first
#define ss second
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define deb(x) cout << #x << ':' << x << '\n';

using namespace std;

void solve(){
	int i,j;
	int n,wt;
	ll sum=0;
	cin >> n >> wt;
	vector<int> w(n),v(n);

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

	vector<vector<ll>> dp(n+1,vector<ll>(sum+1,INT_MAX));
	ll ans=0;

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

	for (int i = 1; i < n+1; ++i)
	{
		for (ll j = 0; j < sum+1; ++j)
		{
		
			dp[i][j]=dp[i-1][j];

			if(j>=v[i-1]){
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i-1]]+w[i-1]);
			}

			if(dp[i][j]<=wt){
				ans=max(ans,j);
			}
			
			

		}
	}

	printf("%lld\n",ans);
	

	
}


int main(){
	int T=1;
	// cin >> T;
	while (T--){
		solve();
	}
}


Measured memory_bytes: 83136
#include <iostream>
#include <string>
#include <vector>

using namespace std;

void solve()
{
	vector<string> abacus(10);
	abacus[0] = "* = ****";
	abacus[1] = "* =* ***";
	abacus[2] = "* =** **";
	abacus[3] = "* =*** *";
	abacus[4] = "* =**** ";
	abacus[5] = " *= ****";
	abacus[6] = " *=* ***";
	abacus[7] = " *=** **";
	abacus[8] = " *=*** *";
	abacus[9] = " *=**** ";
	bool first = true;
	string input;
	while(cin >> input)
	{
		if(!first)
		{
			cout << endl;
		}
		first = false;
		string str;
		if(input.size() < 5)
		{
			for(int i = 0; i < 5 - input.size(); ++i)
			{
				str += "0";
			}
			str += input;
		}
		else
		{
			str = input;
		}
		vector<string> data(5);
		for(int i = 0; i < str.size(); ++i)
		{
			data[i] = abacus[str[i] - '0'];
		}
		for(int i = 0; i < 8; ++i)
		{
			for(int j = 0; j < 5; ++j)
			{
				cout << data[j][i];
			}
			cout << endl;
		}
	}
}

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

Measured memory_bytes: 1184
import java.util.*;
public class Main {
  
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int A = sc.nextInt();

    if (X < A) {
      System.out.println(0);
    } else {
      System.out.println(10);
    }
  }
}


Measured memory_bytes: 21716
use std::io::prelude::*;

fn main() {
    let stdin = std::io::stdin();
    let mut reader = std::io::BufReader::new(stdin.lock());

    let mut s = String::new();
    let _ = reader.read_line(&mut s);

    let mut v: Vec<u32> = s.split_whitespace().map(|x| x.parse().unwrap()).collect();

    v.sort();

    println!("{}", v[2] * 10 + v[1] + v[0]);
}


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

int main(){
    int n;
    vector <int> vt;
    cin>>n;
    for (int i=0;i<n;i++){
        int x;
        cin>>x;
        vt.push_back(x);
    }
    sort(vt.begin(),vt.end());
    cout<<(vt.back()-vt.front())<<endl;
    
    return 0;
}

Measured memory_bytes: 256
import numpy as np
import scipy.sparse.csgraph as csg

from copy import deepcopy

h, w = map(int, input().split())
c = []
for i in range(10):
    c.append(list(map(int, input().split())))

a = []
for i in range(h):
    a.append(list(map(int, input().split())))

d = csg.floyd_warshall(c)

# for k in range(10):
#     for i in range(10):
#         for j in range(10):
#             d[i][j] = min(d[i][j], d[i][k] + d[k][j])

ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] != -1:
            ans += d[a[i][j]][1]

print(int(ans))


Measured memory_bytes: 14092
def calc( rpn )
	stack = Array.new

	while rpn.size > 0
		c = rpn.shift
		if c == '+'
			n1 = stack.pop
			n2 = stack.pop
			stack.push( n2 + n1 )
		elsif c == '-'
			n1 = stack.pop
			n2 = stack.pop
			stack.push( n2 - n1 )
		elsif c == '*'
			n1 = stack.pop
			n2 = stack.pop
			stack.push( n2 * n1 )
		elsif c == '/'
			n1 = stack.pop
			n2 = stack.pop
			stack.push( n2 / n1 )
		else
			stack.push( c.to_f )
		end
	end
	return stack.pop
end

def main
	answers = Array.new
	while line = $stdin.gets
		rpn = line.chomp.split( /\s/ )
		answers << calc( rpn )
	end
	answers.each{ |a| printf( "%.6f\n", a)}
end
main


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

int main(){

	int n;
	cin >> n;

	int hanako = 0;
	int taro = 0;
	for(int i=0;i<n;i++) {

		string str1, str2;
		cin >> str1 >> str2;

        if(str1.compare(str2) == 0){
                hanako++;
                taro++;
        }
        else if(str1.compare(str2) < 0) taro += 3;
        else hanako += 3;
	}

	cout << hanako << " " << taro << endl;

    return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds; 
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define T pair<int, int>
#define ordered_set tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        sum += a[i];
    }
    cerr << sum << endl;
    long double no = 1.0*sum/(1.0*4*m);
    cerr << no << endl;
    bool f = false;
    sort(a.begin(), a.end(), greater<int>());
    int c = 0;
    for(int i=0; i<m; i++){
        if(a[i] >= no){
            c++;
        }
    }
    if(c < m)   puts("No");
    else puts("Yes");
}

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

int main()
{
   int N,K;
   int x[100] = {0};
   cin >> N >> K;
   for (int i=0;i<N;i++)
   {
      cin >> x[i];
   }

   int steps = 0;

   for (int i=0;i<N;i++)
   {
      if (x[i] > K/2)
      {
         steps += (K-x[i])*2;
      }
      else
      {
         steps += x[i]*2;
      }  
   }
   cout << steps << endl;
}

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

int main(){
  int N_dol;
  int Cake_num,Dounut_num;
  bool exist = false;
  cin >> N_dol;
  for(int i = 0;i < 25;i++){
    for(int j = 0;i+j<25;j++){
      if(N_dol == i*4+j*7){
        exist = true; 
      }
    }
  }
  if(exist) cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    long double L;
    cin >> L;
    cout << (L / 3) * (L / 3) * (L / 3) << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector h_s(n, vector(3, 0));
    rep(i, n)
    {
        cin >> h_s[i][0] >> h_s[i][1] >> h_s[i][2];
    }

    // i日後の幸福度
    vector dp(n + 1, vector(3, 0));
    dp[0] = {0, 0, 0};
    FOR(i, 1, n)
    {
        rep(j, 3)
        {
            dp[i][j] = max(dp[i - 1][(j + 1) % 3] + h_s[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3] + h_s[i - 1][(j + 2) % 3]);
        }
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << '\n';

    return 0;
}


Measured memory_bytes: 14188
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-01-18 20:36:11
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n; cin >> n;
  vector<pair<int64, int64>> v;
  for (int i = 0; i < n; ++i) {
    int64 x, l; cin >> x >> l;
    v.emplace_back(x - l, x + l);
  }

  sort(v.begin(), v.end(), [](const pair<int64, int64>& p, const pair<int64, int64>& q){
    return p.second < q.second;
  });

  debug(v);

  int64 last = v[0].second;
  int ans = 0;

  for (int i = 1; i < n; ++i) {
    if (v[i].first < last) {
      ++ans; continue;
    }
    last = v[i].second;
  }

  cout << n - ans << endl;

  return 0;
}

Measured memory_bytes: 2420
'use strict'
const multiply = (a, b) => {

  //2**53-1以上の整数を安全に扱うため、a * b をstringとして実現、出力

  let aa = a
    .toString()
    .split('')
    .reverse()
    .map(v => ~~v)
  let bb = b
    .toString()
    .split('')
    .reverse()
    .map(v => ~~v)
  let cc = Array.apply(null, {
    length: aa.length + bb.length
  }).map(a => 0)

  let ary1 = aa.length >= bb.length ? aa : bb //length（桁）の長い方
  let ary2 = aa.length < bb.length ? aa : bb

  //描く桁ごとに計算　代入する配列の桁は i+j
  //筆算のように扱う

  for (let i = 0; i < ary1.length; i++) {
    for (let j = 0; j < ary2.length; j++) {
      let tmp = ary1[i] * ary2[j]
      cc[i + j] += tmp
    }
  }

  //桁上がり
  for (let i = 0; i < cc.length; i++) {
    let tmp = cc[i]
      .toString()
      .split('')
      .reverse()
      .map(v => ~~v)
    cc[i] = tmp[0]
    for (let j = 1; j < tmp.length; j++) {
      cc[i + j] += tmp[j]
    }
    // console.log(tmp)
  }

  //並び替え、stringに変換、先頭の0を削除
  let tmp = cc.reverse().join('')
  tmp = tmp.replace(/^0+/, '')

  return tmp
}


function main(input) {
  input = input.split(/\r?\n/)
  input = input[1]
    .split(' ')
    .map(v => ~~v)
    .sort((a, b) => b - a)

  let ans = 0
  let sticks = [] // 2本ずつ、2本ずつ、
  let prev = input[0]
  for (let i = 1; i < input.length; i++) {
    if (prev == input[i]) {
      // sticks.push(prev)
      sticks.push(input[i])
      prev = 0
    } else {
      prev = input[i]
    }
  }
  if (sticks.length >= 2) {
    ans = multiply(sticks[0], sticks[1])
    console.log(ans)
  } else {
    console.log(0)
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
	string S, T;
	cin >> S >> T;

	for (int i = 0; i < S.size(); i++)
	{
		if (S == T)
		{
			cout << "Yes" << endl;
			return 0;
		}

		char tmp = S[S.size()-1];
		S.pop_back();
		S = tmp + S;
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256