akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	void grading(){
		Scanner s = new Scanner(System.in);
		int m,f,r;
		m = s.nextInt();
		f = s.nextInt();
		r = s.nextInt();
		while(m != -1 || f != -1 || r != -1){
			if(m != -1 && f != -1){
				int tmp = m + f;
				if(tmp >= 80){
					System.out.println("A");
				}else if(tmp >= 65){
					System.out.println("B");
				}else if(tmp >= 50){
					System.out.println("C");
				}else if(tmp >= 30){
					if(r >= 50){
						System.out.println("C");
					}else{
						System.out.println("D");
					}
				}else{
					System.out.println("F");
				}
			}else{
				System.out.println("F");
			}
			m = s.nextInt();
			f = s.nextInt();
			r = s.nextInt();
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.grading();
	}
}

Measured memory_bytes: 25852
import java.io.File;
import java.io.IOException;
import java.util.*;
 
public class Main {
 
	public static void main(String[] args) throws IOException {
		//File file = new File("input.txt");
		//Scanner sc = new Scanner(file);
		
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		if(N == 1) System.out.println(1);
		else{
			long n1 = 2, n2 = 1, n3 = 0;
			for(int i = 1; i < N; i++){
				n3 = n2 + n1;
				n1 = n2;
				n2 = n3;
			}
			System.out.println(n3);
		}
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int A,B;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>A>>B;
	if(A>=13)
		cout<<B<<endl;
	else if(A>=6)
		cout<<B/2<<endl;
	else
		cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for(int i = 0; i < (int)(n); i++)
#define Repi(i, a, b) for(int i = int(a); i < (int)(b); i++)
#define Repl(i, list) for(int i : list)
#define Sort(v) sort(v.begin(), v.end())
template<typename _T> void Out(_T x) { cout << x << endl; }
template<typename _T> void PrintVec(vector<_T> vec) { Rep(i, vec.size()) { cout << vec.at(i) << " "; } cout << endl; }

bool checkTriangle(int a, int b, int c) {
    if (a < b + c){
        if (b < c + a){
            if (c < a + b){
                return true;
            }
        }
    }
    return false;
}

int main()
{
    // input
    int N;
    cin >> N;
    vector<int> L(N);
    Rep(i, N){
        cin >> L.at(i);
    }

    Sort(L);
    //PrintVec(L);
    int sum = 0;
    
    // output
    Rep(i, N){
        Repi(j, i+1, N){
            sum += distance(L.begin(), lower_bound(L.begin(), L.end(), L.at(i) + L.at(j))) - j - 1;
        }
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

func mode(nums map[int]int) (int, int) {
	m := 0
	s := 0
	for k, v := range nums {
		if v > nums[m] {
			m = k
		} else if v > nums[s] {
			s = k
		}
	}
	return m, s
}

func min(n, m int) int {
	if n < m {
		return n
	}
	return m
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	odds := make(map[int]int)
	evens := make(map[int]int)
	for i := 0; i < n/2; i++ {
		sc.Scan()
		m1, _ := strconv.Atoi(sc.Text())
		odds[m1]++
		sc.Scan()
		m2, _ := strconv.Atoi(sc.Text())
		evens[m2]++
	}

	em, es := mode(evens)
	om, os := mode(odds)

	if em == om {
		fmt.Println(min(n-evens[em]-odds[os], n-evens[es]-odds[om]))
	} else {
		fmt.Println(n - evens[em] - odds[om])
	}
}


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

int main()
{
    int n,l,i;
    cin >> n >> l;
    vector<int> a(n);
    for(i = 0;i < n;++i){
        a.at(i) = l+i;
    }
    int min = abs(a.at(0));
    int min_number = 0;
    for(i = 1;i < n;++i){
        if(abs(a.at(i)) < min){
            min = abs(a.at(i));
            min_number = i;
        }
    }
    int sum = 0;
    for(i = 0;i < n;++i){
        sum += a.at(i);
    }
    cout << sum-a.at(min_number) << endl;
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
as = gets.split.map(&:to_i)

l = 0
r = 1
sum = as[l]
ans = as.size
while r < N
  if sum ^ as[r] == sum + as[r]
    ans += r - l
    sum = sum + as[r]
    r += 1
  else
    sum -= as[l]
    l += 1
  end
  if l == r
    sum = as[l]
    r += 1
  end
end
puts ans


Measured memory_bytes: 15372
N=int(input())
S=input().split()
alphabet=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]

S_list=list(*S)

new_Sindex=(alphabet.index(S_list[0])+N)%26

new_S=""
for i in range(len(S_list)):
  new_Sindex=(alphabet.index(S_list[i])+N)%26
  new_S+=alphabet[new_Sindex]

print(new_S)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

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

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


void Main() {
	int N, K, Q; cin >> N >> K >> Q;
	vint cnt(N, K);
	for (int i = 0; i < Q; i++) {
		int A;
		cin >> A; --A;
		cnt[A]++;
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (cnt[i] - Q > 0) {
			cout << "Yes" << el;
		} else {
			cout << "No" << el;
		}
	}
}

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long ans[10005LL];

int main()
{
	long long x,y,z;
	long long out;
	memset(ans,0LL,sizeof(ans));
	for(x=1LL;x<=120LL;x++)
	{
		for(y=1LL;y<=120LL;y++)
		{
			for(z=1LL;z<=120LL;z++)
			{
				out=(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x);
				if(out<10002LL && out >=0LL)
				{
					ans[out]++;
				//	cout << out << endl;
				}
			}
		}
	}
	long long n,i;
	cin >> n;
	for(i=1;i<=n;i++)
	{
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin >> n;
    vector<string> name(n);
    map<char,int> mp;
    for(int i=0; i<n; i++){
        cin >> name[i];
        if(name[i][0]=='M'||name[i][0]=='A'||name[i][0]=='R'||name[i][0]=='C'||name[i][0]=='H'){
            mp[name[i][0]]++;
        }
    }
    vector<ll> num(5);
    int i=0;
    int cnt=0;
    for(auto p:mp){
        num[i]=p.second;
        if(num[i]!=0)cnt++;
        i++;
    }

    ll sum=0;
    for(int i=0; i<3; i++){
        for(int j=i+1; j<4; j++){
            for(int k=j+1; k<5; k++){
                sum+=num[i]*num[j]*num[k];
            }
        }
    }
    cout << sum << endl;

}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d; 
  if ((a + b) > (c + d)) {
    cout << "Left" << endl;
  } else if ((a + b) == (c + d)) {
    cout << "Balanced" << endl;
  } else { 
    cout << "Right" << endl;
  }
             
}

  

Measured memory_bytes: 3524
import java.io.*;
public class Main{
	public static void main(String[] args){
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] linearr;
		int n = -1;
		int r = -1;
		int p = -1;
		int c = -1;
		int i;
		int[] fuda;
		int[] _fuda;
		//0 ~ n: ???????????????
		try{
			while(null != (line=reader.readLine())){
				linearr = line.split(" ");
				n = Integer.parseInt(linearr[0]);
				r = Integer.parseInt(linearr[1]);
				if(n==0 && r==0){
					break;
				}
				fuda = new int[n];
				for(i=0; i<n; i++){
					fuda[i] = i+1;
				}
				for(i=0; i<r; i++){
					line = reader.readLine();
					linearr = line.split(" ");
					p = Integer.parseInt(linearr[0]);
					c = Integer.parseInt(linearr[1]);
					_fuda = (int[])fuda.clone();
					System.arraycopy(fuda, n-p-c+1, fuda, n-c, c);
					System.arraycopy(_fuda, n-p+1, fuda, n-p-c+1, p-1);
					//System.out.println("<"+fuda+", "+_fuda+">");
				}
				System.out.println(fuda[fuda.length-1]);
			}
		}catch(IOException e){
			System.out.println(e);
		}
		
	}
}

Measured memory_bytes: 26312
n,m=map(int,input().split())
s=[]
c=[]
def mdistance(a,b,c,d):
  return abs(a-c)+abs(b-d)
for i in range(n):
  a=list(map(int,input().split()))
  s.append(a)
for i in range(m):
  c.append(list(map(int,input().split())))
for i in range(n):
  anspoint=0
  for j in range(m):
    if mdistance(s[i][0],s[i][1],c[j][0],c[j][1])<mdistance(s[i][0],s[i][1],c[anspoint][0],c[anspoint][1]):
      anspoint=j
  print(anspoint+1)



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

int main() {
  string s,t; cin >> s >> t;
  int n = s.size();
  int count = 0;
  for (int i = 0; i < n; i++){
    if(s.at(i) == t.at(i)){
      count++;
      continue;
    }
    else{
      cout << "No";
      break;
    }
  }
  if (count == n){
    cout << "Yes";
  }
}

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

int main() {
	int N,A,B;
	cin>>N>>A>>B;
  
  int T =N*A;
  
  if(T<B){
    cout<<T<<endl;
}
  
  else{
  	cout<<B<<endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  int r=0,g=0,b=0,t=0;
  std::cin>>r>>g>>b;
  t=r*100+g*10+b;
  if(t%4==0){
    std::cout << "YES" << '\n';
  }else{
    std::cout << "NO" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
I=->{gets.split.map &:to_i};q=0..k=I[][0];G=q.map{[]};k.times{q,k,c=I[];c&&G[q]<<[k,c]&&G[k]<<[q,c]};s=[[k,0,0]];while s!=[];v,u,p=s.pop;G[v].map{|t,c|p!=t&&s<<[t,u+c,v]};G[v]=u;end;q.times{x,y=I[];p G[x]+G[y]}

Measured memory_bytes: 34812
#include <algorithm>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod 10000000
#define int long long
#define double long double
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, a[200010];
signed main() {
	cin >> n;
	int ma = -INF, ma2 = -INF;;
	rep(i, n) {
		cin >> a[i];
		if (ma < a[i]) {
			ma2 = ma;
			ma = a[i];
		}
		else if (ma2 < a[i])ma2 = a[i];
	}
	int cnt = 0;
	rep(i, n) {
		if (a[i] == ma)cnt++;
	}
	rep(i, n) {
		if (cnt == 1 && a[i] == ma)cout << ma2 << endl;
		else cout << ma << endl;
	}
	return 0;
}

Measured memory_bytes: 3200
Alice = 0
Bob = 0

N = int(input())
A = [None] * N
A = list(map(int, input().split()))

for i in range(N):
    if i % 2:
        Bob = Bob + max(A)
        A.remove(max(A))
    else:
        Alice = Alice + max(A)
        A.remove(max(A))

print(Alice - Bob)

Measured memory_bytes: 3064
function main(input){
    const args = input.split("\n");
    const N = args[0],
        nums = args.slice(1, args.length-1);
    
    console.log(nums.filter((n, i)=> nums.indexOf(n) === i).length);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7500
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using pii = std::pair<int, int>;
using namespace std;

int main() {
  ld N, D;
  cin >> N >> D;
  vec<vec<ld>> X(N, vec<ld>(D));
  REP(i, N) REP(j, D) cin >> X[i][j];

  int answer = 0;
  set<pii> uos;
  REP(i, N) {
    REP(j, N) {
      if (i == j || uos.count(make_pair(i, j)) > 0 ||
          uos.count(make_pair(j, i)) > 0) {
        continue;
      }
      const ld d =
          sqrt(inner_product(ALL(X[i]), X[j].begin(), 0, plus<>(),
                             [](ld x, ld y) { return (x - y) * (x - y); }));
      uos.emplace(i, j);
      if (d == nearbyint(d)) {
        answer++;
      }
    }
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3824
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);

	    long N = Integer.parseInt(scanner.next());
	    long[] A = new long[100001];

	    for (long i = 0; i < N; i++) {
	        int index = Integer.parseInt(scanner.next());
	        A[index]++;
	    }

	    int Q = Integer.parseInt(scanner.next());
	    long sum = 0;
	    for (int i = 0; i < A.length; i++) {
	        sum += (long)i * A[i];
	    }

	    for (int i = 0; i < Q; i++) {
	        int B = Integer.parseInt(scanner.next());
	        int C = Integer.parseInt(scanner.next());
	        sum += (C - B) * A[B];
	        A[C] += A[B];
	        A[B] = 0;
		    System.out.println(sum);
	    }
	}
}

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

int main(){
  int s;
  cin >> s;
  int a, b;
  a = s / 100;
  b = s % 100;
  if (a == 0 || a > 12) {
    if (b == 0 || b > 12) {
      cout << "NA" << endl;
    } else {
      cout << "YYMM" << endl;
    }
  } else {
    if (b == 0 || b > 12) {
      cout << "MMYY" << endl;
    } else {
      cout << "AMBIGUOUS" << endl;
    }
  }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main() {
    ll K; cin >> K;
    ll N = 7;
    for (int i = 1; i < 1e8; ++i) {
        if (N % K == 0) {
            cout << i << endl;
            return 0;
        }
        N %= K;
        N = N * 10 + 7;
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 3500
import numpy as np
n = int(input())
a = [ list(map(int, input().split())) for _ in range(2) ]
na = np.array(a)

top_sum = na[0].cumsum()
under_sum = na[1][::-1].cumsum()[::-1]

amount = [top_sum[i] + under_sum[i] for i in range(n)]
print(max(amount)) 

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

int main() {
	int a,b;
	cin>>a>>b;
	if(a>b){
		cout<<"a > b"<<endl;
	}else{if(a<b){
		cout<<"a < b"<<endl;
	}else{
		cout<<"a == b"<<endl;
	}
}
}

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

int main(){
    int h, w, d, q, r, l;
    vector<pair<int,int>> a(100000, pair<int,int>(0,0));
    vector<int> dif(100000, 0);
    cin >> h >> w >> d;
    for(int i = 0;i<h;i++){
        for(int j = 0;j<w;j++){
            cin >> q;
            a[q] = pair<int,int>(i,j);
        }
    }
    for(int i = d+1;i<=h*w;i++){
        dif[i] = dif[i-d] + abs(a[i].first - a[i-d].first) + abs(a[i].second - a[i-d].second);
    }
    cin >> q;
    while(q--){
        cin >> l >> r;
        cout << dif[r] - dif[l] << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	c := readInt()
	k := readInt()
	t := readIntSlice(n)
	sort.Ints(t)

	ans := 1
	from := t[0]
	cur := 1
	for i := 1; i < n; i++ {
		if from+k < t[i] || cur == c {
			ans++
			cur = 0
			from = t[i]
		}
		cur++
	}
	println(ans)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();
        int C = scanner.nextInt();
        int tmp;
        tmp = A;
        A = B;
        B = tmp;

        tmp = A;
        A = C;
        C = tmp;
        System.out.println(String.format("%d %d %d", A, B, C));
    }
}


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

using namespace std;

unsigned long long a, b, n;

int main(){
  cin >> a >> b >> n;
  cin.ignore();

  // xにて、mod bが一番大きいとき
  if(b - 1 <= n){
    cout << (a * (b - 1)) / b << endl;
  } else {
    cout << (a * n) / b << endl;
  }
  return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int D,G;
    cin>>D>>G;
    vll p(D),c(D);
    rep(i,0,D)cin>>p[i]>>c[i];
    ll res=INF;
    for(ll ch=0;ch<1<<D;ch++){
        ll cnt=0;
        ll sum=0;
        set<int> idx;
        rep(i,0,D){
            if((ch>>i)&1){
                cnt+=p[i];
                sum+=(i+1)*p[i]*100+c[i];
                idx.insert(i);
            }
        }
        if(sum>=G)chmin(res,cnt);
        else{
            bool fin=false;
            irep(i,0,D){
                if(fin)break;
                if(idx.find(i)==idx.end()){
                    rep(j,0,p[i]){
                        if((j+1)*(i+1)*100+sum>=G){
                            chmin(res,j+1+cnt);
                            fin=true;
                            break;
                        }
                    }
                }
            }
        }
    }
    cout<<res<<endl;
    return 0;
}




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

bool check(string a){
  char ch = a[0];
  for(int i=0;i<(int)a.size();i++)if(a[i]!=ch) return 0;
  return 1; 
}

int dfs(string s,char ch){
  if(check(s)) return 0;
  
  string ns;
  for(int i=0;i<(int)s.size()-1;i++){
    if(s[i+1] == ch) ns+=ch;
    else ns += s[i];
  }
  return 1+dfs(ns,ch);
}

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

  int ans = 1e9;
  for(int i='a';i<='z';i++)ans=min(ans,dfs(str,i));
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int n;
  cin >> n;
  vector<int> b(n - 1);
  rep(i, 0, n - 1) cin >> b[i];

  ll ans = b[0] + b[b.size() - 1];
  repr(i, 1, n - 1) ans += min(b[i], b[i - 1]);

  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

#define el '\n'

int n, m;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> m;
    priority_queue<ll> pq;
    for(int i = 0; i < n; i++){
        ll x;
        cin >> x;
        pq.push(x);
    }

    while(m--){
        ll vtop = pq.top();
        pq.pop();

        pq.push(vtop / 2);
    }

    ll sum = 0;
    while(!pq.empty()){
        sum += pq.top();
        pq.pop();
    }

    cout << sum << el;
    return 0;
}

Measured memory_bytes: 1400
N = gets.to_i
A = gets.split.map(&:to_i)
A.unshift 0
A.push 0
price = 0
(N+1).times do |i|
    price += (A[i]-A[i+1]).abs
end
N.times do |i|
    j = i + 1
    p1 = A[i]
    p2 = A[i + 1]
    p3 = A[i + 2]
    puts price + (p1-p3).abs - ( (p1-p2).abs + (p2-p3).abs )
end

Measured memory_bytes: 12036
N,A,B=map(int,input().split())
if A>B:
  print(0)
  exit()
if N==1:
  if A==B:
    print(1)
    exit()
  else:
    print(0)
    exit()
s=A*(N-1)+B
l=B*(N-1)+A
print(l-s+1)

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)
#define Rep(i, n) for(i = 1; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int a, b, k;
	cin >> a >> b >> k;

	set<int> ans;

	for (int i = a; i <= b; i++)
	{
		if (i >= a + k) break;
		ans.insert(i);
	}

	for (int i = b; i >= a; i--)
	{
		if (i <= b - k) break;
		ans.insert(i);
	}

	for (auto itr = ans.begin(); itr != ans.end(); ++itr) {
		cout << *itr << endl;
	}
}


Measured memory_bytes: 256
# -*- coding:utf-8 -*-
a, b = map(int, input().split())

x = [1, 3, 5, 7, 8, 10, 12]
y = [4, 6, 9, 11]
z = 2

ans = str()

if a in x and b in x:
    ans = 'Yes'
elif a in y and b in y:
    ans = 'Yes'
elif a == z and b == z:
    ans = 'Yes'
else:
    ans = 'No'

print(ans)



if __name__ == '__main__':
    pass

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoderBeginnerContest155
{
	class Program
	{
		static void Main(string[] args)
		{
			var numbers = ReadIntArray();
			if (numbers.Distinct().Count() == 2)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

		public static string ReadString()
			=> Console.ReadLine();

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


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



long long mod = 1000000007;


long long inf = 100000000;
multiset<long long> s;

long long ii(long long a, long long b){
	return a * inf + b;
}
int main(){
	//freopen("i.txt","r",stdin);
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	long long n, m;
	cin >> n >> m;
	string ss;
	cin >> ss;
	
	long long dp[n+1];
	dp[0] = 0;
	s.insert(0);
	for(int i = 1;i <= n;i++){
		if(i > m){
			s.erase(ii(dp[i-m-1]/inf,i-m-1));
		}
		if(ss[i] == '0'){
			long long x = *s.begin();
			
			dp[i] = ii(x/inf+1,x%inf);
			
			s.insert(ii(dp[i]/inf,i));
		}
		else{
			dp[i] = ii(inf,i);
			s.insert(ii(inf,i));
		}
		//cout << dp[i] / inf << " " << dp[i] % inf << "\n";
	}
	
	if(dp[n] / inf >= inf - 10){
		cout << -1;
		return 0;
	}
	
	vector<int> v;
	int x = n;
	while(x != 0){
		v.push_back(x);
		x = dp[x] % inf;
		//cout << x << "\n";
	}
	v.push_back(0);
	
	reverse(v.begin(),v.end());
	
	for(int i = 1;i < v.size();i++){
		cout << v[i] - v[i-1] << " ";
	}
	
}


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

int main() {
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(A,A+N);
    double y = (A[0]+A[1])/2.0;
    if (N == 2) {
        cout << y;
        return 0;
    }
    for (int i = 2; i < N; i++) {
        y += A[i];
        y = y / 2.0;
    }
    cout << y;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD (long long)(1E9+7)
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	cout << ((a-1)/d>=(c-1)/b ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3528
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>


typedef struct{
    char name[20];
    int time;
}QUEUE;

int main(int argc, const char * argv[]){
    
    //Input
    int t_slice, num;
    int size;
    int front = 0;
    int rear = 0;;
    int ctime = 0;
    
    scanf("%d %d", &num, &t_slice);
    
    size = 2 * num;
    
    QUEUE q[size];
    
    
    for(rear = 0; rear < num; rear++){
        scanf("%s %d", q[rear].name, &(q[rear].time));
    }
    
    
    while(front != rear){
        
        if(q[front].time > t_slice){
            q[front].time -= t_slice;
            q[rear] = q[front];
            rear = (rear + 1) % size;
            ctime += t_slice;
        }else{
            printf("%s %d\n", q[front].name, ctime + q[front].time);
            ctime += q[front].time;
        }
        front = (front + 1) % size;
    }
    
    return 0;
}

Measured memory_bytes: 3372
#include <iostream>

typedef long long int ll;

using namespace std;

long double muli(long double* probs, ll t){
	long double res=1.0;
	for(ll i=0;i<t;i++){
		res = res*(1.0-probs[i]);
	}
	return res;
}

long double probdp(long double* probs, ll n){
	long double dp[n+1][n+1];
	for (ll t=0;t<=n;t++){
		for(ll j=0;j<=n;j++){
			if(t<j)dp[t][j]=0;
			else if(j==0)dp[t][j] = muli(probs,t);
			else{
				dp[t][j] = dp[t-1][j]*(1.0-probs[t-1])+dp[t-1][j-1]*probs[t-1];
			}
			//cout<<"t:"<<t<<" j:"<<j<<" val:"<<dp[t][j]<<endl;
		}
	}
	long double sum=0;
	for(ll t=(n/2)+1; t<=n;t++)
		sum+=dp[n][t];
		
	return sum;
}

int main(){
	ll N;
	cin>>N;
	long double probs[N];
	for (ll i=0;i<N;i++) cin>>probs[i];
	//now call the dp function and print the answer
	printf("%0.10Lf\n", probdp(probs, N));
	
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int n, ans = 0, tmp = 0;
    cin >> n;
    vector<int> h(n);
    rep(i, n) { cin >> h[i]; }
    reverse(h.begin(), h.end());
    for (int i = 1; i < n; ++i) {
        if (h[i - 1] <= h[i])
            tmp++;
        else
            tmp = 0;
        ans = max(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] a = new int[n];
		for(int i=0; i<a.length; ++i){
			a[i] = scn.nextInt();
		}
		int sum = 0;
		for(int i=0; i<a.length; ++i){
			sum = sum + a[i];
		}
		int ans = sum - n;
		System.out.println(ans);
	}
}


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

int main(void){
    int n,t,ans=0;
    cin>>n>>t;
    int t1=0,t2=0;
    for(int i=0;i<n;i++){
        t1 = t2;
        cin>>t2;
        ans += min(t2-t1,t);
    }
    ans += t;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int n,s[1000],i;
    double ex1,ex2,b;
    while(scanf("%d",&n),n){
                ex1=ex2=0;
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            ex1+=s[i]*s[i];
            ex2+=s[i];
        }
        b=sqrt((ex1/n)-pow(ex2/n,2));
        printf("%.8f\n",b);
    }
    return 0;
}


Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,ans=0;
  cin >> n;
  int p[n];
  for(int i=0;i<n;++i) cin >> p[i];
  for(int i=1;i<n-1;++i) {
    if((p[i]>=p[i-1]&&p[i]<=p[i+1])||(p[i]<=p[i-1]&&p[i]>=p[i+1])) {
      ans++;
    }
  }
  cout << ans << endl;  
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define inc( i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec( i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

template<typename T> void swap(T & x, T & y) { T t = x; x = y; y = t; return; }
template<typename T> T abs(T x) { return (0 <= x ? x : -x); }
template<typename T> T max(T a, T b) { return (b <= a ? a : b); }
template<typename T> T min(T a, T b) { return (a <= b ? a : b); }
template<typename T> bool setmin(T & a, T b) { if(a <= b) { return false; } else { a = b; return true; } }
template<typename T> bool setmax(T & a, T b) { if(b <= a) { return false; } else { a = b; return true; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

char s[100001];
char d[] = "dream";
char e[] = "erase";
char er[] = "er";
char era[] = "era";

bool eq(int p, char t[]) {
	int i = 0;
	while(true) {
		if(t[i] == '\0') { return true; }
		if(t[i] == s[p + i]) { i++; } else { return false; }
	}
}

int main() {
	scanf("%s", s);
	
	int i = 0;
	bool flag = true;
	while(flag) {
		if(s[i] == '\0') { break; }
		if(s[i] == 'd') {
			if(eq(i, d)) {
				i += 5;
				if(eq(i, er) && ! eq(i, era) ) { i += 2; }
			} else { flag = false; break; }
		} else if(s[i] == 'e') {
			if(eq(i, e)) {
				i += 5;
				if(s[i] == 'r') { i++; }
			} else { flag = false; break; }
		} else { flag = false; break; }
	}
	
	printf("%s\n", flag ? "YES" : "NO");
	
	return 0;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

using ll    = long long;
using vll   = vector<ll>;
using pll   = pair<ll,ll>;
using ld    = long double;

const ll mod = (ll)1e9 + 7;

void solve() {
	ll n,x=0;
	cin>>n;
	vll A(n); for(int i=0;i<n;i++) cin>>A[i];
	for(int i=0;i<n;i++) x^=A[i];
	for(int i=0;i<n;i++) cout<<(x^A[i])<<" ";
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
//	pre();
//	ll t;cin>>t;while (t--)
		solve();
}


Measured memory_bytes: 4700
#include <stdio.h>
int main(void){
    // Your code here!
    int n,x;
    int a=0,count=0,t=0;
    scanf("%d %d",&n,&x);
    
    int l[n];
    for(int i=0; i<n; i++){
        scanf("%d",&l[i]);    
    }
        
    while(a<=x){
        a+=l[t];
        t++;
    }
    
    printf("%d\n",t);
    return 0;
}


Measured memory_bytes: 128
using System;
					
public class Program
{
	public static void Main()
	{
		string[] str = Console.ReadLine().Split(' ');
        int N = int.Parse(str[0]);
        int M = int.Parse(str[1]); 
		
		string[] str2 = Console.ReadLine().Split(' ');
		int a=0;
		
		for(int i=0; i<M; i++){
			a = a + int.Parse(str2[i]);
		}
        
		if(a>N){
			Console.WriteLine("-1");
		}else{
			Console.WriteLine(N-a);
		}
		
	}
}

Measured memory_bytes: 19280
def insertionSort(A, n, g):
    for i in range(n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt[0] += 1
        A[j+g] = v
    return cnt

def shellSort(A, n):
    # make the list of G
    h = 1
    G = [1]
    while h*3+1 < n:
        h = h*3+1
        G.append(h)
    G.reverse()
    print(len(G))
    print(*G)
    for g in range(len(G)):
        insertionSort(A, n, G[g])
        
n = int(input())
'''A = []
for i in range(n):
    inpu = int(input())
    A.append(inpu)'''
A = [int(input()) for i in range(n)]

cnt = [0]
shellSort(A,n)

print(cnt[0])
for a in A:
    print(a)


Measured memory_bytes: 45524
//============================================================================
// Name        : tenka1_2019C.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;

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

	int r_bs = 0;
	int r_ws = 0;
	int l_bs = 0;
	int l_ws = 0;
	for(int i = 0; i < s.length(); ++i){
		if(s[i] == '.')++r_ws;
		else ++r_bs;
	}

	int count = 2147483647;
	for(int i = 0; i < s.length(); ++i){
		count = min(count, r_ws + l_bs);
		if(s[i] == '.'){
			++l_ws;
			--r_ws;
		}
		else{
			++l_bs;
			--r_bs;
		}
	}
	count = min(count, r_ws + l_bs);
	cout << count << endl;

	return 0;
}


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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = (ll)1<<62;
const ll MOD = 1e9+7;

ll MAXN = 1000005;
vector<int> primes;
map<int, int> mp;

void sieve(){
	vector<bool> prime(MAXN, true);
	int cnt = 0;
	for(int i=2;i<=MAXN;i++){
		if(prime[i]){
			mp[i] = cnt++;
			primes.pb(i);
			for(int p=i*2;p<=MAXN;p+=i){
				prime[p] = false;
			}
		}
	}
}

vector<pair<int, int> > factorize(int n){
	vector<pair<int, int> > ret;
	for(int p=2;p*p<=n;p++){
		int cnt = 0;
		while(n%p==0){
			cnt++;
			n/=p;
		}
		if(cnt)
			ret.pb({p, cnt});
	}
	if(n>1){
		for(int i=0;i<ret.size();i++){
			if(ret[i].first == n){
				ret[i].second++;
				return ret;
			}
		}
		ret.pb({n, 1});
		return ret;
	}
	else{
		return ret;
	}
}

ll powx(ll b, ll exp){
	if(exp == 0)
		return 1;
	ll tmp = powx(b, exp/2);
	ll ans = (tmp*tmp)%MOD;
	if(exp%2)
		ans = ans*b;
	return ans;
}

ll x, y;

ll extended_euclid(ll a, ll b){
	if(b==0){
		x = 1;
		y = 0;
		return a;
	}
	else{
		ll g = extended_euclid(b, a%b);
		/*
			bx + y(a-a/b*b)
			ay + b(x-a/b*y)

		*/
		ll tmp = x;
		x = y;
		y = tmp-a/b*y;
		return g;
	}
}

ll mod_inverse(ll a){
	ll g = extended_euclid(a, MOD);
	while(x<0)
		x+=MOD;
	return x;
}

int main(){
	int N;
	vector<int> A;
	cin>>N;
	A.assign(N, 0);
	ll maxi = 0;
	for(int i=0;i<N;i++){
		cin>>A[i];
		maxi = max(maxi, (ll)A[i]);
	}
	
	MAXN = maxi+5;

	sieve();
	
	vector<int> lcm(primes.size(), 0);
	
	for(int i=0;i<N;i++){
		vector<pair<int, int> > factors = factorize(A[i]);
		for(int j=0;j<factors.size();j++){
			int f = factors[j].first;
			int p = factors[j].second;
			//cout<<"("<<f<<" "<<p<<"), ";
			lcm[mp[f]] = max(lcm[mp[f]], p);	
		}
	}

	ll l = 1;
	for(int i=0;i<primes.size();i++){
		l = (l*powx(primes[i], lcm[i]))%MOD;
	}

	ll sum = 0;
	for(int i=0;i<N;i++){
		sum = (sum + l*mod_inverse(A[i]))%MOD;
	}

	cout<<sum<<"\n";

	return 0;
}

/*
A1*B1 = A2*B2 = A3*B3 = A4*B4 = LCM(A1, A2, A3, A4)
*/

Measured memory_bytes: 4728
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

ll inv[100005],a[100001],invsum[100005];
int main() {
	fup(i,1,100004,1)inv[i]=POW(i,MOD-2);
	fup(i,1,100004,1)invsum[i]=(invsum[i-1]+inv[i])%MOD;
	int n;
	scanf("%d",&n);
	fup(i,1,n,1)scanf("%lld",a+i);
	ll ans=0;
	fup(j,1,n,1)
	{
		ll t=(invsum[j]+invsum[n-j+1]-1)%MOD;
		ans=(ans+a[j]*t)%MOD;
	}
	fup(i,1,n,1)ans=(ans*i)%MOD;
	printf("%lld",ans);
}

Measured memory_bytes: 2560
for i in range(int(input())):
    xa, ya, xb, yb = map(int, input().split())
    n = int(input())
    ip = []
    for j in range(n):
        xs, ys, xt, yt, o, l = map(int, input().split())
        d = (xb - xa) * (yt - ys) - (yb - ya) * (xt - xs)
        if d == 0:
            continue
        t0 = ((yt - ys) * (xs - xa) - (xt - xs) * (ys - ya)) / d
        t1 = ((yb - ya) * (xs - xa) - (xb - xa) * (ys - ya)) / d
        if (t0 > 0 and t0 < 1) and (t1 > 0 and t1 < 1):
            ip.append((t0, o == l))
    count = 0
    if len(ip) > 0:
        ip.sort(key=lambda x: x[0])
        for j in range(len(ip) - 1):
            if ip[j][1] != ip[j + 1][1]:
                count += 1
    print(count)

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

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

int64_t e()
{
	return 0;
}

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<int64_t> as(n);
	for (auto &&a : as)
	{
		cin >> a;
	}

	// seg[i] := 最後にiを使ったときの長さの最大値

	segtree<int64_t, op, e> seg(300001);

	for (auto &&a : as)
	{
		seg.set(a, seg.prod(max<int64_t>(0, a - k), min<int64_t>(a + k + 1, 300001)) + 1);
	}

	cout << seg.all_prod() << endl;

	return 0;
}

Measured memory_bytes: 16228
N, K = map(int, input().split())

lower = 0
upper = ((N-1) * (N-2)) // 2

ans = []

if lower <= K  and K <= upper:

    for i in range(N-1):
        ans.append((i+1, N))

    add = upper - K

    remains = []
    for i in range(N-1):
        for j in range(i):
            remains.append((i+1, j+1))
    
    for i in range(add):
        ans.append(remains[i])

    print(len(ans))
    for a in ans:
        print('{} {}'.format(a[0], a[1]))

else:
    print('-1')

Measured memory_bytes: 3732
#include<stdio.h>
int main(void){
	int a[5];
	int b;
	int c[5]={};
	int max=0;
	int total=0;
	for(b=0;b<5;b++){
		scanf("%d",&a[b]);
		while((a[b]%10)!=0){
			a[b]++;
			c[b]++;
		}
		if(c[b]>max){
			max=c[b];
		}
		total+=a[b];
	}
	total-=max;
	printf("%d",total);
return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,X;
  cin >> N>>X;
  vector<int> m(N);
  for (int i=0;i<N;i++){
    cin>>m.at(i);
    X=X-m.at(i);
  }
  sort(m.begin(),m.end());
  cout << N+X/m.at(0) <<endl;

}  


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};

// Problem Specific Parameter:

int main() {
  int h, w; cin >> h >> w;
  vector<string> s(h); for(int i = 0; i < h; i++) cin >> s[i];
  vector<bool> row(h, false);
  vector<bool> col(w, false);
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(s[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }
  for(int i  = 0; i < h; i++) {
    if(row[i]) {
      for(int j = 0; j < w; j++) {
        if(col[j]) {
          cout << s[i][j];
        }
      }
      cout << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H==0 && W==0){
                break;
            }
            for(int i=0;i<H;i++){
                for(int j=0;j<W;j++){
                    int w = i+j;
                    if(w%2==0){
                        System.out.printf("#");
                    }else{
                        System.out.printf(".");
                    }
                }
                System.out.printf("\n");
            }
            System.out.printf("\n");
        }
    }
}



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

int main(void){
  int n;
  cin >> n;
  for(int count4 = 0; count4 <= 25; count4++){
    for(int count7 = 0; count7 <= 14; count7++){
      if(count4*4 + count7*7 == n){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


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

int main() {
  int i, count=0;
  string s1, s2;
  cin >> s1 >> s2;
  for(i=0; i<s1.length(); i++){
    if(s1[i] != s2[i])
      count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 3912
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    int ans;
    for(int i = N; i >= 1; i--) {
        double D = pow(i, 0.5);
        dump(D);
        if(D == floor(D)) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

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

int main(){
    int length; cin>>length; int arr[length];
    for(int i=0; i<length; ++i) cin>>arr[i];
    int count = 1;
    int minimum = arr[0];
    for(int i=0; i<length; ++i){
        if(arr[i]<minimum){
            minimum = arr[i];
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){

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

	vector<int> dp(n,1e9);

	dp[0] = 0;

	for(int i = 0; i+1 < n; i++){
		dp[i+1] = min(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
		if(i+2 < n)
			dp[i+2] = min(dp[i+2], dp[i] + abs(h[i] - h[i+2]));		
	}

	cout << dp[n-1] << endl;




	
}	

int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";

		solution();
	} 
	return 0;
}


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

int main(){


 int N,Q,i,j;
 typedef pair<int, int> P;
 cin >> N >> Q;

 vector<int> X(N),S(N),T(N),D(Q);
 set<pair<int, int>> shugo;

 rep(i,N){
  cin >> S[i] >> T[i] >> X[i];
}
 rep(i,Q){
  cin >> D[i];
 }
 rep(i,Q){
  shugo.insert(P(D[i],i));
}


vector<tuple<int, int, int>> a(N);
rep(i,N){
a[i] = tie(X[i], S[i], T[i]);
}
sort(a.begin(), a.end());

vector<int> ans;
rep(i,Q){
ans.push_back(-1);
}
rep(i,N){
 int x,l,r;
 tie(x,l,r)=a[i];
 auto it = shugo.lower_bound(P(l-x,-1));
 while(it!=shugo.end()){
  if((it->first) >= r-x){ break; }
  ans[it->second] = x;
  shugo.erase(it++);
}
}

rep(i,Q){
 cout << ans[i] << endl;
}

}

Measured memory_bytes: 17656
# ABC079C - Train Ticket.py
abcd = tuple(map(int, input()))
ans = []

for i in range(8, 16):
    s = abcd[0]
    eq = [str(s)]
    for j in range(1, 4):
        if int(bin(i)[-j]):
            s += abcd[j]
            eq.append("+" + str(abcd[j]))
        else:
            s -= abcd[j]
            eq.append("-" + str(abcd[j]))

    if s == 7:
        eq.append("=7")
        ans.append("".join(eq))

print(ans[0])


Measured memory_bytes: 3064