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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define req(i,f,N) for(int i = f; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd_(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    lint A, B, C, D;
    cin >> A >> B >> C >> D;
    lint ans = B - A + 1;
    ans -= B / C + B / D;
    ans += (A - 1) / C + (A - 1) / D;
    ans += (B / lcm_(C, D));
    ans -= ((A - 1) / lcm_(C, D));
    cou(ans);
}

Measured memory_bytes: 256
n,k=map(int,input().split())
scores=list(map(int,input().split()))
t=input()
winner={'r':2,'s':0,'p':1}
ans=0
for i in range(k):
  ts=''
  for j in range(n):
    if k*j+i>=n:
      break
    ts+=t[k*j+i]
  ts+='?'
  l=len(ts)
  hand=ts[0]
  cnt=1
  for j in range(1,l):
    if hand==ts[j]:
      cnt+=1
    else:
      ans+=scores[winner[hand]]*((cnt+1)//2)
      hand=ts[j]
      cnt=1
print(ans)

Measured memory_bytes: 3444
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;

public class Main {

    static MyScanner sc;
    private static PrintWriter out;
    static long M = 1000000007;

    public static void main(String[] s) throws Exception {
        StringBuilder stringBuilder = new StringBuilder();

        if (stringBuilder.length() == 0) {
            sc = new MyScanner(System.in);
        } else {
            sc = new MyScanner(new BufferedReader(new StringReader(stringBuilder.toString())));
        }

        out = new PrintWriter(new OutputStreamWriter(System.out));
        initData();
        solve();
        out.flush();
    }

    private static void initData() {


    }

    private static void solve() {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        out.println(Math.abs(a - b - 1) % 2 == 1? "Alice" : "Borys");

    }


    private static void solveT() {
        int t = sc.nextInt();
        while (t-- > 0) {
            solve();
        }
    }


    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        MyScanner(BufferedReader br) {
            this.br = br;
        }

        public MyScanner(InputStream in) {
            this(new BufferedReader(new InputStreamReader(in)));
        }

        void findToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
        }

        String next() {
            findToken();
            return st.nextToken();
        }

        int[] na(int n) {
            int[] k = new int[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextInt();
            }
            return k;
        }

        long[] nl(int n) {
            long[] k = new long[n];
            for (int i = 0; i < n; i++) {
                k[i] = sc.nextLong();
            }
            return k;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }

}

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

using namespace std;

typedef complex<double> Point;
struct Line : public vector<Point> {
    Line () {}
    Line(Point a, Point b){
        push_back(a);
        push_back(b);
    }
    Point vector() const {
        return back() - front();
    }
};
double dot(Point a, Point b){
    return real(conj(a) * b);
}
double cross(Point a, Point b){
    return imag(conj(a) * b);
}
// (left, right)
pair<Point, Point> lr_align(Point a, Point b){
    if(cross(a, b) > 0) swap(a, b);
    return make_pair(a, b);
}
// 点pから直線lに対する射影
Point projection(Line l, Point p){
    double t = dot(p - l[0], l.vector()) / norm(l.vector());
    return l[0] + t * l.vector();
}

// 点pの直線lに関する反射
Point reflection(Line l, Point p){
    return 2.0 * projection(l, p) - p;
}

const double EPS = 1e-6;

int main(){
    int N;
    while(cin >> N && N){
        double sx, sy;
        cin >> sx >> sy;
        vector<Point> ps(N);
        REP(i, N){
            double x, y;
            cin >> x >> y;
            ps[i] = Point(x - sx, y - sy);
        }
        vector<Line> lv(N);
        REP(i, N){
            lv[i] = Line(ps[i], ps[(i + 1) % N]);
        }
        vector<int> perm(N);
        REP(i, N) perm[i] = i;
        int ans = 0;
        do{
            vector<Line> l(N);
            REP(i, N){
                l[i] = lv[ perm[i] ];
            }

            Point left;
            Point right;

            for(int i = 0; i < N; i++){
                // cout << "i = " << i << endl;
                for(int j = 0; j < i; j++){
                    l[i][0] = reflection(l[j], l[i][0]);
                    l[i][1] = reflection(l[j], l[i][1]);
                }
                Point vec = l[i].vector() / abs(l[i].vector());
                l[i][0] += EPS * vec;
                l[i][1] -= EPS * vec;
                // cout << l[i][0] << " " << l[i][1] << endl;
                pair<Point, Point> pp = lr_align(l[i][0], l[i][1]);
                // cout << pp.first << " " << pp.second << endl;
                if(i == 0) {
                    left = pp.first, right = pp.second;
                }else{
                    left = lr_align(left, pp.first).second;
                    right = lr_align(right, pp.second).first;
                }
                if(cross(right, left) < EPS){
                    break;
                }
                if(i == N - 1) {
                    ans++;
                }
                // cout << "left : " << left << " right : " << right << endl;
            }
        }while(next_permutation(perm.begin(), perm.end()));

        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1264
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 200_003
R = 2  # primitive root

@njit((i8[:], ), cache=True)
def precompute(A):
    exp = np.zeros(MOD - 1, np.int64)
    log = np.zeros(MOD, np.int64)
    exp[0] = 1
    for k in range(1, MOD - 1):
        exp[k] = exp[k - 1] * R % MOD
        log[exp[k]] = k
    # r^k の個数を B[k] に入れる
    B = np.zeros(MOD - 1, np.int64)
    for x in A:
        if x != 0:
            B[log[x]] += 1
    return exp, log, B

@njit((i8[:], i8[:], i8[:], i8[:]), cache=True)
def get_ans(A, C, exp, log):
    # 順序対について集計
    ans = 0
    for i in range(len(C)):
        x = exp[i % (MOD - 1)]
        ans += x * C[i]
    for a in A:
        x = a * a % MOD
        ans -= x
    return ans // 2

A = np.array(read().split(), np.int64)[1:]

exp, log, B = precompute(A)
fft, ifft = np.fft.fft, np.fft.ifft
fft_len = 1 << 19
FB = fft(B, fft_len)
C = np.rint(ifft(FB * FB, fft_len)).astype(np.int64)

print(get_ans(A, C, exp, log))


Measured memory_bytes: 153988
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int a; cin >> a;
  string s; cin >> s;
  if (a>=3200) {cout << s;}
  else {cout << "red";}

  return 0;
}


Measured memory_bytes: 256
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int N, X, M; scanf("%d %d %d\n", &N, &X, &M);
    struct T {
       int l, r, s;
    } 
    auto P = new T[M];
    foreach (i; 0 .. M) {
        int L, R, S;
        scanf("%d %d %d\n", &L, &R, &S);
        L--; R--;
        P[i] = T(L, R, S);
    }

    auto res = new int[N];

    int F() {
        auto sum = new int[N + 1];
        sum[0] = 0;
        foreach (i; 1 .. N + 1) {
            sum[i] = sum[i - 1] + res[i - 1];
        }
        foreach (i; 0 .. M) {
            if (sum[ P[i].r + 1 ] - sum[ P[i].l ] != P[i].s) return -1;
        }
        return sum[N];
    }

    int Ans = -1;
    int[] AnsA;
    void dfs(int x) {
        if (x == N) {
            int f = F;
            if (Ans < f) {
                Ans = f;
                AnsA = res.dup;
            }
            return;
        }
        for (int i = 0; i <= X; i++) {
            res[x] = i;
            dfs(x + 1);
        }
    }

    dfs(0);
    if (Ans < 0) {
        writeln(-1);
    } else {
        writefln("%(%s %)", AnsA);
    }
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};


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

  LL N, M;
  cin >> N >> M;

  UnionFind uf(N);

  REP(i,M){
    LL x, y, z;
    cin >> x >> y >> z;

    x--;
    y--;
    uf.unionSet(x, y);
  }

  vector<bool> isr(N, false);

  REP(i,N){
    isr[uf.root(i)] = true;
  }

  LL cnt = 0;

  REP(i,N){
    if(isr[i]){
      cnt++;
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main(void){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    // cout << sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)) << endl;
    printf("%0.8f\n",sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2)));
    
    return 0;
    
}

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int cnt = 0;
  for(int j = 0; j < n-2; j++){
    int max = a[j];
    int min = 0;
    if(a[j+2] > a[j]){
      max = a[j+2];
      min = a[j];
    }else{
      min = a[j+2];
    }
    if(a[j+1] < max && a[j+1] > min)
      cnt += 1;
  }
  cout << cnt << endl;
  return 0;
}

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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String s = br.readLine();	//?????????????????????????????????
        String p = br.readLine();	//?????????????????????????????????
        sb.append(s);				//sb?????????????????¨??????????????????????????¨??????????????????
        sb.append(s);
        if(sb.indexOf(p) != -1){
        	//??????????????????????±??????????????????????????????????????????????indexOf??§??????
        	//????±?????????????????????£?????´?????????-1??????????????§!=?????¶?????????
        	System.out.println("Yes");
        	//-1??\????????£??????Yes??????????????????
        }else{
        	System.out.println("No");
        	//-1?????£??????No??????????????????
        }
     }
}

Measured memory_bytes: 17044
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define N 50000
int main() {
    int i, j, cnt, p[N] = { 0 }, n;
    for (i = 2; i <= (int)sqrt((double)N); ++i) if (!p[i]) for (j = 2; j*i < N; j++) p[i*j] = 1;
    while (1) {
        scanf("%d", &n);
        if (n == 0) break;
        cnt = 0;
        for (i = 2; i <= n/2; i++) if (!p[i]&&!p[n - i]) cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}

Measured memory_bytes: 800
n , m = map(int,input().split())
ainf = -334334334334334334334334
es = []

def bf():
    d = [ainf] * n
    d[0] = 0
    i = 0 
    sa = 0
    ta = 0
    
    for i in range(n+1):
        for p,q,r in es:
            if d[p] != ainf and d[q] < d[p] + r:
                d[q] = d[p] + r
                if i == n-1:
                    sa = d[n-1]
                if i == n:
                    ta = d[n-1]
                
    return sa,ta,d[n-1]

for _ in range(m):
    x , y , z = map(int,input().split())
    es.append([x-1,y-1,z])
    
s,t,u = bf()

if s == t:
    print(u)
else:
    print("inf")

Measured memory_bytes: 45528
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]


macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [$t:tt]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    ($arg:expr) => (println!("{:?}",$arg));
}


#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}


use std::cmp;
use std::collections::HashMap;



use std::ops::{ Add, Sub , Div , Mul };




fn main() {

    input! { 
       n: i64,
    }

    
    
    println!("{}",n.pow(3));


}


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

#define ll long long
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define x first
#define y second

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

	string t;
	cin>>t;
	for (int i=0; i<t.size(); i++)
		if (t[i]=='?') t[i]='D';
	cout<<t<<endl;
	return 0;
}

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

using namespace std;

int main() {
  string s;
  cin >> s;
  int n = s.size(), c = 0, ans = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == 'S') {
      c++;
    } else {
      if (0 < c) {
        ans += 2;
        c--;
      }
    }
  }
  cout << n - ans << endl;

  return 0;
}

Measured memory_bytes: 640
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b,ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}
void YES(){puts("YES");exit(0);}
void Yes(){puts("Yes");exit(0);}
void NO(){puts("NO");exit(0);}
void No(){puts("No");exit(0);}

int n;
int a[maxn];
vector<int>edge[maxn];

int dfs(int root,int fa)
{
	if(edge[root].size()==1)
	{
		return a[root];
	}
	vector<int>num;
	ll sum=0;
	for(int i=0;i<edge[root].size();i++)
	{
		int k =edge[root][i];
		if(k==fa)continue;
		int t=dfs(k,root);
		sum+=t;
		num.push_back(t);
	}
	num.push_back(2*a[root]-sum);
	for(int i=0;i<num.size();i++)
	{
		if(num[i]<0)NO();
		if(num[i]>a[root])NO();
	}
	return 2*a[root]-sum;
}

void solve()
{
	sa(n);
	repp(i,1,n)
	{
		sa(a[i]);
	}
	repp(i,1,n-1)
	{
		int x,y;
		sa(x),sa(y);
		edge[x].push_back(y);
		edge[y].push_back(x);
	}
	if(n==2)
	{
		if(a[1]!=a[2])NO();
		else YES();
	}
	int root=1;
	while(edge[root].size()==1)root++;
	if(!dfs(root,-1))
	{
		YES();
	}
	else
	{
		NO();
	}
}

int main()
{

	solve();    
    return 0;
}


Measured memory_bytes: 16768
fn main() {
    let n = read::<u32>();
    let k = read::<u32>();
    let x = read::<u32>();
    let y = read::<u32>();

    let ans = if n <= k {
        n * x
    } else {
        k * x + (n - k) * y
    };
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#1　正直
#0　不親切
#「不親切な人」を「常に嘘を付く」と誤解してしまった結果
#僕は無限にWAを生成することとなってしまいました。
#つらいンゴ…

#誤読には気をつけよう！（注意喚起）

import itertools
N=int(input())
B=[[] for i in range(N)]
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        B[i].append((x-1,y))
ans=0
#print(B)
for seq in itertools.product(range(2),repeat=N):
    flag=1
    for i in range(N):
        for r in B[i]:
            x,y=r
            if seq[i]==1 and seq[x]!=y:
                flag=0
                break
        if flag==0:
            break
    if flag==1:
        ans=max(ans,sum(seq))
print(ans)



Measured memory_bytes: 42864
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000;
unsigned int x = 55555555;
unsigned int rng(){
  x = (x << 5) ^ x;
  x = (x >> 8) ^ x;
  x = (x << 11) ^ x;
  return x;
}
int main(){
  random_device rnd;
  mt19937 mt(rnd());
  while (1){
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0){
      break;
    }
    vector<vector<int>> b(n, vector<int>(m));
    for (int i = 0; i < n; i++){
      for (int j = 0; j < m; j++){
        char c;
        cin >> c;
        b[i][j] = c - '0';
      }
    }
    int BIT = min(27 - (int) log2(n), 20);
    vector<vector<bool>> use_hash(BIT, vector<bool>(m, false));
    for (int i = 0; i < BIT; i++){
      for (int j = 0; j < m; j++){
        if (rng() % 3 < 2){
          use_hash[i][j] = true;
        }
      }
    }
    vector<int> hash(n, 0);
    for (int i = 0; i < n; i++){
      for (int j = 0; j < BIT; j++){
        for (int k = 0; k < m; k++){
          if (use_hash[j][k] && b[i][k] == 1){
            hash[i] ^= (1 << j);
          }
        }
      }
    }
    vector<int> dp(1 << BIT, -INF);
    dp[0] = 0;
    for (int i = 0; i < n; i++){
      vector<int> dp2 = dp;
      for (int j = 0; j < (1 << BIT); j++){
        if (dp[j] >= 0){
          dp2[j ^ hash[i]] = max(dp2[j ^ hash[i]], dp[j] + 1);
        }
      }
      swap(dp, dp2);
    }
    cout << dp[0] << endl;
  }
}


Measured memory_bytes: 11328
import java.util.*;
public class Main {
  
  public static void main(String args[]) {
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] arr = new int[n];
    
    for(int ind = 0; ind < n; ind++) {
      arr[ind] = sc.nextInt();
    }
    if(n == 1)
    {
      System.out.println(0);
      return;
    }
    if(n == 2) {
      System.out.println(Math.abs(arr[1] - arr[0]));
      return;
    }
    int[] dp = new int[n];
    dp[1] = Math.abs(arr[1] - arr[0]);
    for(int ind = 2; ind < n;ind++) {
      int cost1 = Math.abs(arr[ind] - arr[ind - 1]) + dp[ind - 1];
      int cost2 = Math.abs(arr[ind] - arr[ind - 2]) + dp[ind - 2];
      if(cost1 < cost2)
        dp[ind] = cost1;
      else
        dp[ind] = cost2;
    }

    System.out.println(dp[arr.length - 1]);
  }
}


Measured memory_bytes: 60044
#include<bits/stdc++.h>
using namespace std;
const int maxn=5e5+10;
struct edge{
	int be[maxn],tot;
	int to[maxn],ne[maxn],w[maxn];
	void add(int u,int v,int z){
		to[++tot]=v;
		ne[tot]=be[u];
		w[tot]=z;
		be[u]=tot;
	}
}G;
struct data{
	int u,dis;
	data(){};
	data(int u,int dis):u(u),dis(dis){};
	friend bool operator < (data a,data b){
		return a.dis>b.dis;
	}
};
int n,dis[maxn];

#define Eor(i,u) for(int i=G.be[u],v;i;i=G.ne[i])
void solve(){
	scanf("%d",&n);
	for(int i=1,u,v;i<=n;++i){
		u=i%n,v=i*10%n;
		if(u!=v)G.add(u,v,0);
		if(i%10!=9){
			u=i%n,v=(i+1)%n;
			if(u!=v)G.add(u,v,1);
		}
	}
	priority_queue<data> pq;
	for(int i=0;i<n;++i)dis[i]=0x3f3f3f3f;
	dis[1]=1;
	
	pq.push(data(1,0));
	for(int u;!pq.empty();){
		u=pq.top().u;pq.pop();
		Eor(i,u)if(dis[v=G.to[i]]>dis[u]+G.w[i]){
			dis[v]=dis[u]+G.w[i];
			pq.push(data(v,dis[v]));
		}
	}
	printf("%d\n",dis[0]);
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 7932
// 問題文の意味はわからんがサンプルを眺めてて浮かんだ
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	MOD := 998244353
	D := make(map[int]int)
	maxN := 0
	for i := 0; i < N; i++ {
		var V int
		fmt.Scan(&V)
		// 最初必ず0なので
		if i == 0 && V != 0 {
			fmt.Println(0)
			return
		}
		D[V]++
		maxN = max(maxN, V)
	}
	// 0はひとつ
	if D[0] > 1 {
		fmt.Println(0)
		return
	}
	// 順番を飛ばしていたら存在しなさそう
	for i := 0; i <= maxN; i++ {
		if _, ok := D[i]; !ok {
			fmt.Println(0)
			return
		}
	}
	// はい やっと本質
	keys := []int{}
	for k := range D {
		keys = append(keys, k)
	}
	sort.Ints(keys)
	ans := 1
	for i := 1; i < len(keys); i++ {
		ans = ans * powMod(D[i-1], D[i], MOD)
		ans %= MOD
	}
	fmt.Println(ans)
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}


Measured memory_bytes: 9472
S = input()
CountC = S[2:-1].count('C')
WhereC = S.find('C')

if S[0]=='A' and CountC == 1 and S[1:WhereC].islower()==True and S[WhereC+1:].islower()==True:
    print('AC')
else:
    print('WA')

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

int a[100005],n,sum1[100005],sum2[100005],ans;
inline void swap(int x,int y){
	int t=x;
	x=y;
	y=t;
}
int gcd(int a,int b){
	if (a<b) swap(a,b);
	if (b==0){
		return a;
	}
	else return gcd(b,a%b);
}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){
		cin>>a[i];
	}
	sum1[1]=a[1];
	for (int i=2;i<=n;i++){
		sum1[i]=gcd(sum1[i-1],a[i]);
	}
	sum2[n]=a[n];
	for (int i=n-1;i>=1;i--){
		sum2[i]=gcd(sum2[i+1],a[i]);
	}
	for (int i=1;i<=n;i++){
		ans=max(ans,gcd(sum1[i-1],sum2[i+1]));
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>

//#define NDEBUG

#ifdef NDEBUG
#define DEBUG_PRINT(fmt, ...) ((void)0)
#else
#define DEBUG_PRINT(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
#endif
#define ASSERT_RANGE(min,x,max) assert(((x)>=(min)) && ((x)<=(max)))


#define N_MIN 1
#define N_MAX 100

int sort_int(int *a, int N) {// {{{
	int i;
	for (i = 0; i < N-1; i++) {
		int j;
		for (j = i + 1; j < N; j++) {
			if (a[i] > a[j]) {
				int tmp = a[i];
				a[i] = a[j];
				a[j] = tmp;
			}
		}
	}
	return 0;
}// }}}

int main(int argc, char **argv) {
	int N;
	fscanf(stdin,"%d",&N);
	ASSERT_RANGE(N_MIN,N,N_MAX);


	{
		int ret[N_MAX+1];
		int i;
		memset(ret,0,sizeof(int)*(N_MAX+1));
		for (i = 1; i < 10; i++) {
			int j;
			for (j = 1; j < 10; j++) {
				ret[i*j] = 1;
			}
		}
		if (ret[N] == 1) {
			fprintf(stdout,"Yes\n");
		} else {
			fprintf(stdout,"No\n");
		}
	}
	return 0;
}


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

int main(){
    vector<tuple<ll, ll, char, ll, string>> v;
    ll n, t1, t2, t4;
    char t3;
    string t5;
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> t1 >> t2 >> t3 >> t4 >> t5;
        v.push_back(make_tuple(t1, t2, t3, t4,t5));
    }
    sort(v.begin(), v.end());
    for(auto i = v.begin(); i != v.end(); i++){
        cout << get<0>(*i) << " " << get<1>(*i) << " " << get<2>(*i) << " " << get<3>(*i) << " " << get<4>(*i) << endl;
    }
    return 0;
}


Measured memory_bytes: 13048
//It’s never too late to become what you might have been....
 #include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost1 ios::sync_with_stdio(false);
#define boost2 cin.tie(0);
#define mem(a,val) memset(a,val,sizeof a)
#define endl "\n"
#define maxn 1005

ll dp[maxn][maxn];
int main()
{
	boost1;boost2;	
	ll i,j,n,k,sum=0;
	cin>>n>>k;
	for(i=1;i<=k;i++)
	dp[1][i]=1;
	sum=k;
	for(i=2;i<=n;i++)
	{
		for(j=1;j<=k;j++)
		dp[i][j]+=(sum-dp[i-1][j]);
		sum=0;
		for(j=1;j<=k;j++)
		sum+=dp[i][j];
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 4224
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	REPN(i, k, n + 1){
		ans += (2 * n - i + 1) * i / 2;
		ans -= (i - 1) * i / 2;
		ans++;
	}
	co(ans % MOD);

	return 0;
}


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

using namespace std;
typedef long long ll;

int main(void)
{
   int n;
   cin >> n;
   vector<long long> c(5, 0);
   for (int i = 0; i < n; i++){
       string s;
       cin >> s;
       if(s.at(0)=='M')
           c.at(0)++;
        else if(s.at(0)=='A')
            c.at(1)++;
        else if(s.at(0)=='R')
            c.at(2)++;
        else if(s.at(0)=='C')
            c.at(3)++;
        else if(s.at(0)=='H')
            c.at(4)++;
   }


   long long ans = 0;
   for (int i = 0; i < 3; i++){
       for (int j = i + 1; j < 4;j++){
           for (int k = j + 1; k < 5;k++){
               ans += c.at(i) * c.at(j) * c.at(k);
           }
       }
   }
   cout << ans << endl;
   return 0;
}

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

typedef long long ll;
typedef pair<int,int> ii;

const int mod=1e9+7;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll n; cin>>n;
	ll ret=1;
	for (ll x=1; x<=n; x++)
		ret=(ret*x)%mod;
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
// 2020-08-23 22:43:49
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0, cur = 0;
  rep(i, n) {
    if(cur <= a[i]) cur = a[i];
    else ans += cur - a[i];
  }
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);

	string s;
	ll g[2];
	cin >> s >> g[0] >> g[1];

	vector<int> len[2];
	ll st[2] = {0,0}, dr = -1;
	for(auto c: s){
		if( c == 'F' ){
			if( dr < 0 ) st[0]++;
			else len[dr].back()++;
		}else{
			if( dr < 0 ) dr = 1;
			else dr ^= 1;
			if(len[dr].empty() || len[dr].back() > 0) len[dr].push_back(0);
		}
	}

	bool dp[2][2][20004] = {};
	rep(k,2) dp[k][0][10000+st[k]] = true;
	rep(k,2) rep(i,(int)len[k].size()){
		int t = len[k][i];
		rep(x,20004){
			if(x+t < 20000) dp[k][(i+1)%2][x+t] |= dp[k][i%2][x];
			if(x-t > 0    ) dp[k][(i+1)%2][x-t] |= dp[k][i%2][x];
		}
		rep(x,20004) dp[k][i%2][x] = false;
	}

	//cout << st[0] << " "<< st[1] << endl;
	//for(auto t: len[0]) cout << t << " "; cout << endl;
	//for(auto t: len[1]) cout << t << " "; cout << endl;

	bool ans = true;
	rep(k,2) ans &= dp[k][len[k].size()%2][10000+g[k]];

	cout << (ans ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<functional>
using namespace std;
#define LL long long
#define MOD 100000
#define inf 1999999999

char stb(char c) { return 'A' + (c - 'a'); }

int main() {
	string a, b, c;
	cin >> a >> b >> c;
	cout << stb(a[0]) << stb(b[0]) << stb(c[0]) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long int

ll a,b,c,k;

int main(){

  scanf("%lld%lld%lld%lld",&a,&b,&c,&k);

  if(a>=k){
    printf("%lld\n",k);}
  else{
    if(a+b>=k){
      printf("%lld\n",a);}
    else{
      printf("%lld\n",a-(k-a-b));}}

  
  return 0;
}


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

int main() {
        int a, b;
        vector<int> ans(3);

        cin >> a >> b;
        ans[0] = a + b;
        ans[1] = a - b;
        ans[2] = a * b;

  cout << *max_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 256
import           Control.Monad
import           Control.Applicative
import           Data.IORef
import           Data.List.Split
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
  [w, a, b] <- map read . words <$> getLine
  print $ solve (a, a + w) (b, b + w)

solve (as, ag) (bs, bg)
  | (as <= bs && bs <= ag) || (as <= bg && bg <= ag) = 0
  | otherwise = minimum $ map abs [as - bs,as - bg, ag - bs, ag - bg]

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

#define ll long long int
#define f(i,x,n)  for(int i=x;i<n;i++)
#define FASTIO cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
#define sz(a) int((a).size())
#define mod 1000000007
#define inf LLONG_MAX
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
template <typename T>
inline T gcd(T a, T b)
{
    while (b != 0) swap(b, a %= b);
    return a;
}

template <typename T>
inline void seethis(vector<T>vect)
{
    for(T x : vect)
        cout << x << " ";
    cout << "\n";
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
//LCM
int lcm(int a, int b)
{
    return a * (b / gcd(a, b));
}

//For sort by second
bool cmp(const pair<int, int> &a)
{
    return a.first < a.second;
}

//Tree
/* const int MAXN = 1e5 + 5;
vector<ll> adj[MAXN];*/

//ModPower
ll modpower(ll a, ll b, ll c)
{
    ll res = 1;
    while(b)
    {
        if(b & 1LL)
            res = (res * a) % c;
        a = (a * a) % c;
        b >>= 1;
    }
    return res;
}

int main()
{
    FASTIO;
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ll n, w;
    cin >> n >> w;

    vector<ll>val(n + 1);
    vector<ll>wt(n + 1);

    for(int i = 1; i <= n; i++)
    {
        cin >>wt[i]>>val[i];
    }

    ll dp[2][w + 1];

    memset(dp, 0, sizeof dp);

    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= w; j++)
        {
            ll res = -inf;
            if(j >= wt[i])
            {
                res = max(res, dp[0][j - wt[i]] + val[i]);
            }

            res = max(res, dp[0][j]);
            dp[1][j] = res;
        }


        // for(int i = 0; i < 2; i++)
        // {
        //     for(int j = 0; j <= w; j++)
        //     {
        //         cout << dp[i][j] << " ";
        //     }
        //     cout << "\n";
        // }
        // cout<<"\n";

        for(int k = 1; k <= w; k++)
        {
            dp[0][k] = dp[1][k];
            dp[1][k] = 0;
        }


    }


    cout << dp[0][w] << "\n";


    return 0;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) ((y)<0||(x)<0||(y)>=(h)||(x)>=(w))
#define dump(...)
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vi sum(n);
    sum[0] = a[0];
    REPF(i, 1, n) sum[i] += sum[i-1] + a[i];

    map<int, int> cnt;
    cnt[0]=1;
    int ans = 0;
    REP(i, n) {
        ans += cnt[sum[i]];
        dump(i, ans, cnt[sum[i]]);
        cnt[sum[i]]++;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 15872
MOD = 1_000_000_007

_ = gets.chomp.split.map(&:to_i)
arr = gets.chomp.split.map(&:to_i)
r_arr = arr.reverse
r_arr_sums = []
tmp = 0
r_arr.each do |s|
  r_arr_sums << ((tmp += s) % MOD)
end

ans = 0
r_arr_sums.pop # 最後の要素はいらん
r_arr_sums.reverse.each_with_index do |sum, i|
  ans = (ans + (arr[i] * sum) % MOD)% MOD
end

puts ans

Measured memory_bytes: 35188
import java.util.*;

class Main{
  public static int gcd(int m, int n) {
    int r;
    while (n > 0) {
        r = m % n;
        m = n;
        n = r;
    }
    return m;
}
  public static void main(String args[]){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    n = n+1;
    int[] x = new int[n];
    for(int i = 0;i < n;i++){
      x[i] = scan.nextInt();
    }
    Arrays.sort(x);
    int m=0;
    for(int i = 0;i < n-1;i++){
      if(i == 0&&x.length >2){
        m = gcd(x[i+1]-x[i],x[i+2]-x[i+1]);
        continue;
      }else if(i == 0){
        m = x[i+1] - x[i];
      }
      m = gcd(m,x[i+1]-x[i]);
    }
    System.out.println(m);
  }
}


Measured memory_bytes: 50820
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;
const int INF = numeric_limits<int>::max();
const ll INFL = numeric_limits<ll>::max();


// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

ll factorial(ll n) {
    ll res = 1;
    for (ll i = 1; i <= n; i++) {
        res *= i;
    }
    return res;
}

int main()
{
    ll n; cin >> n;
    ll t = 0;
    while (t*(t+1)/2 < n) t++;
    cout << t<< endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for (const T &i : v) os << i << ' ';
    return os;
}
void co() { cout << '\n'; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << '\n'; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1000000001;
constexpr ll LINF = 1000000000000000001;
constexpr ll MOD = 1000000007;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

ll op(ll a, ll b){
    return max(a, b);
}

ll e(){
    return -LINF;
}

ll target;
bool f(ll v){
    return v < target;
}

int main(void) {
    ll n, q;
    cin >> n >> q;
    Vec a(n);
    rep(i, n) cin >> a[i];

    segtree<ll, op, e> st(a);
    while(q--){
        ll t, x, y;
        cin >> t >> x >> y;
        if (t == 1) st.set(--x, y);
        else if(t == 2)
            co(st.prod(--x, y));
        else{
            target = y;
            co(st.max_right<f>(--x) + 1);
        }
    }

    return 0;
}

Measured memory_bytes: 9072
import math

a, b, h, m = map(int, input().split())
h=h*60+m

ang=abs(h*0.5-m*6)
if ang > 180:
  ang = 360-ang
if ang==180:
  print(a+b)
elif(ang==0):
  print(abs(b-a))
else:
  ans=(a**2)+(b**2)-(2*a*b*math.cos(math.radians(ang)))
  print(math.sqrt(ans))

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

void fnInput(vector<int>& rvnMtrx)
{
  int nMaxSiz;
  cin >> nMaxSiz;
  rvnMtrx.resize(nMaxSiz + 1);

  for (int i = 0; i < nMaxSiz; ++i)
    cin >> rvnMtrx[i] >> rvnMtrx[i + 1];
}

int fnMtrxChainMultpl(vector<vector<int>>& rvvnDetDP, const vector<int>& cnrvnMtrx)
{
  const int nMAXSIZ = cnrvnMtrx.size() - 1;
  for (int i = 1; i <= nMAXSIZ; ++i)  rvvnDetDP[i][i] = 0;

  for (int nDif = 1; nDif <= nMAXSIZ - 1; ++nDif)
    for (int nFrt = 1; nFrt <= nMAXSIZ - nDif; ++nFrt)
    {
      int nBak = nFrt + nDif;
      for (int nx = nFrt; nx <= nBak - 1; ++nx)
        rvvnDetDP[nFrt][nBak] =
          min(rvvnDetDP[nFrt][nBak],
              rvvnDetDP[nFrt][nx] + rvvnDetDP[nx + 1][nBak] 
                                  + cnrvnMtrx[nFrt - 1] * cnrvnMtrx[nx] * cnrvnMtrx[nBak]);
    }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<int>> vvnDetDP; 
  vector<int> vnMtrx;

  fnInput(vnMtrx);
  vvnDetDP.resize(vnMtrx.size(), vector<int>(vnMtrx.size(), INT_MAX));

  fnMtrxChainMultpl(vvnDetDP, vnMtrx);
  cout << vvnDetDP[1][vnMtrx.size() - 1] << endl;
  return 0;
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<int,ii>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000005
#define MOD 1000000007 
#define N 150005
#define M 1000003
#define LOG 20
#define KOK 250
#define EPS 0.0000001
using namespace std;

int n;
int v[2][N];
ll dp[2];
vector<int> op,pos;

void fsol(int w) {

	printf("%lld\n",dp[w]);

	for(int i=1;i<=n;i++) {

		if((i&1)==w && v[w][(i+1)/2]>0) {

			pos.pb(i);

		} 

	}

	if(!sz(pos)) {

		for(int i=1;i<=n;i++) {

			if((i&1)==w && v[w][(i+1)/2]==dp[w]) {

				pos.pb(i);

				break ;

			} 			

		}

	}

	for(int i=n;i>pos.back();i--) op.pb(i);
	for(int i=1;i<pos[0];i++) op.pb(1);

	int ld=pos[0]-1;

	for(int i=sz(pos)-1;i>0;i--) {

		for(int j=1;j<=(pos[i]-pos[i-1]-1)/2;j++) op.pb(pos[i-1]+2-ld);

		op.pb(pos[i-1]+1-ld);

	}

	printf("%d\n",sz(op));

	for(int x:op) printf("%d\n",x);

}

ll solve(int w) {

	for(int i=1;i<=(n+w)/2;i++) {

		dp[w]=dp[w]+max(0,v[w][i]);

	}

	if(dp[w]==0) return dp[w]=*max_element(v[w]+1,v[w]+1+(n+w)/2);

	return dp[w];

}

int main() {

	scanf("%d",&n);

	for(int i=1;i<=n;i++) {

		int x;

		scanf("%d",&x);

		v[i&1][(i+1)/2]=x;

	}

	if(solve(1)>solve(0)) fsol(1);
	else fsol(0);

}

Measured memory_bytes: 256