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

  double ans=0.0;
  int n,t=2,s=1;
  cin >> n;
  int x[n], y[n];
  for(int i=2; i<=n; i++) t *= (i-1);
  for(int i=1; i<=n; i++) s *= i;
  for(int i=0; i<n; i++) cin >> x[i] >> y[i];
  for(int i=0; i<n; i++){
    for(int j=0; j<n; j++){
      if(i==j) continue;
      ans += t*sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
    }
  }
  cout << setprecision(10) << ans/s/2 << endl;

  return 0;
}


Measured memory_bytes: 256
from collections import deque
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall


def bfs(links):
    color = [-1] * n
    last_v = None
    q = deque([(0, 0)])
    while q:
        v, c = q.popleft()
        if color[v] != -1:
            if color[v] != c:
                return -1
            continue
        else:
            color[v] = c
        last_v = v
        new_c = c ^ 1
        for u in links[v]:
            if color[u] != -1:
                if color[u] != new_c:
                    return -1
                continue
            q.append((u, new_c))
    return last_v


def bfs2(s, links):
    visited = set()
    q = deque([(s, 1)])
    last_d = -1
    while q:
        v, d = q.popleft()
        if v in visited:
            continue
        visited.add(v)
        last_d = d
        for u in links[v]:
            if u in visited:
                continue
            q.append((u, d + 1))
    return last_d


def solve(n, links, matrix):
    res = bfs(links)
    if res == -1:
        return -1
    # return bfs2(res, links)
    g = csgraph_from_dense(matrix)
    f = floyd_warshall(g)
    return int(f.max()) + 1


n = int(input())
links = [set() for _ in range(n)]
matrix = []
for i in range(n):
    s = input().strip()
    for j, c in enumerate(s):
        if c == '0':
            continue
        links[i].add(j)
    matrix.append(list(map(int, s)))

print(solve(n, links, matrix))


Measured memory_bytes: 16892
def readinput():
    n,m,k=list(map(int,input().split()))
    return n,m,k

def main(n,m,k):
    for x in range(0,m+1):
        for y in range(0,n+1):
            if (n-y)*x+y*(m-x)==k:
                return 'Yes'
    return 'No'

if __name__=='__main__':
    n,m,k=readinput()
    ans=main(n,m,k)
    print(ans)


Measured memory_bytes: 9192
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharp_practice
{
    class Program
    {
        static void Main(string[] args)
        {
            int r = int.Parse(Console.ReadLine());
            Console.WriteLine(r * r);
        }
    }
}


Measured memory_bytes: 13140
import sys
from collections import deque, defaultdict


def bfs01(s, t, links):
    q = deque([(0, s, -1)])  # cost, station, last-company
    visited = set()
    while q:
        d, v, e = q.popleft()
        if v == t:
            return d
        if (v, e) in visited:
            continue
        visited.add((v, e))
        if e == 0:
            for c, us in links[v].items():
                for u in us:
                    if (u, c) in visited:
                        continue
                    q.append((d + 1, u, c))
        else:
            for u in links[v][e]:
                if (u, e) in visited:
                    continue
                q.appendleft((d, u, e))
            if (v, 0) not in visited:
                q.appendleft((d, v, 0))

    return -1


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

n, m = map(int, readline().split())
links = [defaultdict(set) for _ in range(n)]
pqc = list(map(int, read().split()))
for p, q, c in zip(pqc[0::3], pqc[1::3], pqc[2::3]):
    p -= 1
    q -= 1
    links[p][c].add(q)
    links[q][c].add(p)

print(bfs01(0, n - 1, links))


Measured memory_bytes: 216480
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int n, i, j, f=1;
	scanf("%d", &n);
	double a[n], b[n], sum=0;
	for(i=0; i<n; i++){
		scanf("%lf%lf", &a[i], &b[i]);
		//printf("%lf\n", a[i]);
	}

	for(i=1; i<=n; i++){
		f*=i;
	}

	for(i=0; i<n; i++){
		for(j=i+1; j<n; j++){
			sum+=sqrt((a[i]-a[j])*(a[i]-a[j])+(b[i]-b[j])*(b[i]-b[j]))*f/n*2;
		}
	}

	printf("%f", sum/f);

    return 0;
}


Measured memory_bytes: 128
#include <cstdio>

int main()
{
  int h,w,a,b;
  scanf("%d%d%d%d",&h,&w,&a,&b);
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      putchar((i<b)!=(j<a)?'1':'0');
    }
    putchar('\n');
  }
  return 0;
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)

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

//C++14 (GCC 5.4.1)
int main() {
    int N,K;
    cin >>N>>K;

    string S;
    cin >>S;
    //-----------------------------------
    int ans=0;

    vector<int> howoz;//0101....の個数
    if(S[0]=='1'){
        howoz.push_back(1);
    }else{
        howoz.push_back(0);
        howoz.push_back(1);
    }
    repd(i,1,N){
        if(S[i]==S[i-1]) howoz.back()++;
            else howoz.push_back(1);
    }
    if(S.back()=='0')howoz.push_back(0);//1で蓋
    int cnt = 2*K+1-howoz.size();
    if(cnt>0){
        rep(i,cnt) howoz.push_back(0);
    }

    vector<int> howozS(howoz.size()+1);
    howozS.at(0)=0;
    rep(i,howoz.size())howozS.at(i+1)=howozS.at(i)+howoz.at(i);

    cnt = howoz.size()/2-K+1;
    rep(i,cnt) chmax(ans, howozS.at(2*i+1+2*K)-howozS.at(2*i));

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

Measured memory_bytes: 2164
import math

class UnionFind:
    def __init__(self, size):
        self.parent_indexes = [-1] * size
        
    def find(self, n):
        if self.parent_indexes[n] < 0:
            return n
        # 探しているnodeが指し示しているのが現在の親ではない場合、
        # 現在の親に書き換え(メモ化) した上で返す
        self.parent_indexes[n] = self.find(self.parent_indexes[n])
        return self.parent_indexes[n] 
    
    def union(self, n1, n2):
        if self.same_group(n1, n2):
            return False
        
        # サイズの大きい方の集団の親が親であり続ける
        if self.size(n1) >= self.size(n2):
            tmp = self.size(n2)
            self.parent_indexes[self.find(n2)] = self.find(n1)
            self.parent_indexes[self.find(n1)] -= tmp
            return True
        
        # サイズが小さい方の集団の親は親を引退する
        tmp = self.size(n1)
        self.parent_indexes[self.find(n1)] = self.find(n2)
        self.parent_indexes[self.find(n2)] -= tmp
        return True
        
    # その要素が所属する集団の要素数
    def size(self, n):
        return -self.parent_indexes[self.find(n)]
    
    def same_group(self, n1, n2):
        return self.find(n1) == self.find(n2)

n, m = map(lambda x: int(x), input().split())


uf = UnionFind(n)

for _ in range(m):
    a, b = map(lambda x: int(x), input().split())
    uf.union(a-1, b-1)
    
num_parents = 0
    
for p_index in uf.parent_indexes:
    if p_index < 0:
        num_parents += 1
# print(uf.parent_indexes)
print(num_parents - 1)

Measured memory_bytes: 10816
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = True
show_flg = False


# エラトステネスのふるい 素数の列挙
def primes(n):
    is_prime = [1] * (n + 1)
    is_prime[0] = 0
    is_prime[1] = 0
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = 0
    return is_prime


def main():
    Q = I()
    l = [0] * Q
    r = [0] * Q

    for i in range(Q):
        l[i], r[i] = MI()

    prime_list = primes(10**5+1)
    arr = []
    for i in range(10**5+1):
        if i % 2 == 1:
            arr.append(int(prime_list[i] and prime_list[(i+1)//2]))
        else:
            arr.append(0)
    ARR = list(accumulate([0] + arr))

    for i in range(Q):
        # print(r[i]+1, l[i], ARR[r[i]+1], ARR[l[i]])
        # print(ARR[:r[i]+1])
        print(ARR[r[i]+1] - ARR[l[i]])


if __name__ == '__main__':
    main()


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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	double n,d,x,a;
	cin>>n>>d>>x;
	for(int i=0;i<n;i++){
		cin>>a;
		x+=ceil(d/a);
	}
	cout<<x<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author aakas
 */
public class Main{
    static int n;
    static double[] p;
    static boolean v[][];
    static double dp[][];
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        p = new double[n];
        v = new boolean[n+1][n+1];
        dp = new double[n+1][n+1];
        for(int i=0;i<n;i++)
        {
            p[i] = sc.nextDouble();
        }
        double sum = 0;
        for(int i=0;i<Math.ceil((double)n/2.0);i++)
        {
            sum += s(n-i,i);
        }
        System.out.println(sum);
    }
    public static double s(int i,int j)
    {
        if(i==0 && j==1)
            return 1-p[i+j-1];
        if(i==1 && j==0)
            return p[i+j-1];
        if(i==0 && j==0)
            return 0;
        if(i<0 || j<0)
            return 0;
        if(v[i][j])
            return dp[i][j];
        v[i][j] = true;
        return dp[i][j] = p[i+j-1]*s(i-1,j) + (1-p[i+j-1])*(s(i,j-1)); 
    }
}


Measured memory_bytes: 135872
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int b, n;
	char a[N];
	f(i, N)a[i] = 0;
	scanf("%s", a);
	n = strlen(a);
	b = 0;
	f(i, n) {
		if (a[i] == 'N')b |= 1;
		if (a[i] == 'W')b |= 2;
		if (a[i] == 'S')b |= 4;
		if (a[i] == 'E')b |= 8;
	}
	if (b % 5 == 0)printf("Yes\n");
	else printf("No\n");


	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

int main() {
#ifdef ELEGIA
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  cin >> a;

  auto tr = [&]() {
    vector<int> sum(n);
    for (int i = 0; i < n; ++i) {
      ++sum[max(i - a[i], 0)];
      if (i + a[i] + 1 < n) --sum[i + a[i] + 1];
    }
    for (int i = 1; i < n; ++i) sum[i] += sum[i - 1];
    swap(a, sum);
  };

  while (k--) {
    tr();
    if (count(a.begin(), a.end(), n) == n)
      break;
  }
  cout << a << '\n';

#ifdef ELEGIA
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


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

int main(){
  vector<char> ytenki(3);
  vector<char> jtenki(3);
  for (int i = 0; i< 3; i++){
    cin >> ytenki.at(i);
  }
  for (int i = 0; i< 3; i++){
    cin >> jtenki.at(i);
  }
  
  int count = 0;
  for(int i = 0; i<3; i++){
    if(ytenki.at(i) ==jtenki.at(i)){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;

const long long mod = 1000000007;
int n, a, b; long long d[2][5050], e[2][5050];

void add(long long& a, long long b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

int main()
{
	scanf ("%d %d %d", &n, &a, &b);

	long long all = 1;
	for (int i = 0; i < n; i++) all = all * 2 % mod;

	long long ans = 0;

	if (a > 1 && b > 1){
		if (a < b) swap(a, b);
		d[0][1] = 1;
		for (int i = 1; i < a; i++){
			add(d[0][i + 1], d[0][i]);
			add(d[0][i + 1], d[1][i]);
			if (i + b < a) add(d[1][i + b], d[0][i]);
			add(d[1][i + 1], d[1][i]);
		}

		e[0][0] = e[1][0] = 1;
		for (int j = 1; j < a; j++) e[0][j] = d[1][j];
		for (int i = 0; i < n; i++){
			for (int j = 1; j < a && i + j <= n; j++) add(e[0][i + j], e[1][i] * d[0][j] % mod);
			for (int j = 1; j < b && i + j <= n; j++) add(e[1][i + j], e[0][i]);
		}

		add(ans, e[0][n]);
		add(ans, e[1][n]);
		for (int j = 1; j < a; j++) add(ans, e[1][n - j] * d[1][j] % mod);
	}

	ans = all + mod - ans;
	if (ans >= mod) ans -= mod;

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

	return 0;
}

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

int main(){
  int N,K,total=0;
  cin >> N >> K;
  rep(i,N){
    int x;
    cin >> x;
    if(x <= K-x)
      total += x*2;
    else
      total += (K-x)*2;
  }
  cout << total << endl;
}
  


Measured memory_bytes: 384
def main():
  n = int(input())
  p = list(map(int,input().split()))
  ans = 0 
  up = 1 # state of up or down if up, p[i] < p[i+1]
  for i in range(n-2):
    """if p[i+1] > p[i+2]:
      up = 0"""
    if (p[i]-p[i+1])*(p[i+1]-p[i+2]) > 0 :
      ans += 1
  print(ans)
main()


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int a, b, c;
  	cin >> a >> b >> c;
	cout << a*b/2 << endl;
	return;
}

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


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

using namespace std;
typedef long long ll;

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	int n; cin >> n;
  	while (n) {
      	if (n % 10 == 7) {
          	return cout << "Yes" << endl, 0;
        }
      	n /= 10;
    }
  	cout << "No" << endl;
  	return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef pair<int,string> P;
 
int main(){
    int n,num;
    string str;
    map<P,int> m;
     
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> str >> num;
        m[P(str.size(),str)] += num;
    }     
    map<P,int>::iterator it;
    for(it = m.begin() ; it != m.end() ; it++){
        cout << it->first.second << ' ' << it->second << endl;
    }
    return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,x;
int main(){
    n=read();
    int tt=0;
    int ans=0;
    for(int i=1;i<=n;i++){
    	x=read();
    	if(x>=tt) ans++;
    	tt=max(tt,x);
	}
	printf("%d",ans);
	
	return 0;
}

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

#define ll long long
#define rep(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

#define fi first
#define se second
#define all(A) A.begin(),A.end()

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)
#define vv vector

ll gcd(ll p,ll q){
    if(q==0){
        return p;
    }
    return gcd(q, p % q);
}


ll N,A[1010101];


ll i, j, k;

int main(){
    scanf("%lld", &N);
    rep(i,0,N){
        scanf("%lld", &A[i]);
    }
    j = A[0];
    rep(i,1,N){
        j = gcd(j, A[i]);
    }

    if(j!=1){
        printf("not coprime\n");
        return 0;
    }
    const ll Amx = 1010101;
    vv<ll> mk(Amx+10),mk2(Amx+10);
    rep(i,0,N){
        ++mk2[A[i]];
    }
    rep(i,2,Amx){
        if(mk[i]){
            continue;
        }
        ll a = 0;
        for (j = i; j < Amx; j += i){
            ++mk[j];
            a += mk2[j];
        }
        if(a>=2)
        break;
    }
    if(i==Amx){
        printf("pairwise coprime\n");
    }else{
        printf("setwise coprime\n");
    }

    return 0;
}

Measured memory_bytes: 26760
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int q;
    cin>>q;
    vector <int> A;
    for(int i=0;i<q;i++){
        int a,b;
        cin>>a;
        if(a!=2) cin>>b;
        if(a==0) A.push_back(b);
        else if(a==1) cout<<A[b]<<endl;
        else A.erase(A.end()-1);
    }
    return 0;
}


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

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K; for (ll i = 0; i < N; ++i) {ll a; cin >> a;}
	ll res{1};
	for (ll i = K; i < N; i+=(K-1)) ++res;
	std::cout << res << std::endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)



int main() {
    int A, B;
    cin >> A >> B;

    if (A >= 13) {
        cout << B << endl;
    } else if (A <= 5) {
        cout << 0 << endl;
        
    } else {
        cout << B/2 << endl;
    } 

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int toi(char c){
  if(isdigit(c)) return c - '2';
  if(c == 'T') return 8;
  if(c == 'J') return 9;
  if(c == 'Q') return 10;
  if(c == 'K') return 11;
  if(c == 'A') return 12;
}

int main(){
  char c;
  string deb[4] = {"norst", "east", "south", "west"};
  while(cin>>c && c != '#'){
    int point[2] = {};
    string card[4][13];
    REP(i, 4)REP(j, 13) cin>>card[i][j];
    char d = card[0][0][1];
    REP(i, 13){
      int high = -24;
      int win = -1;
      REP(j, 4){
        string s = card[j][i];
        int n = toi(s[0]);
        if(s[1] == c) n += 13;
        else if(s[1] != d) n -= 13;
        //assert(high != n);
        if(high < n){
          high = n;
          win = j;
        }
      }
      if(i != 12){
        d = card[win][i + 1][1];
      }
      point[win % 2] += 1;
    }
    if(point[0] > point[1]){
      cout<<"NS"<<" "<<point[0] - 6<<endl;
    }else{
      cout<<"EW"<<" "<<point[1] - 6<<endl;
    }
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define REPD(i,n) FOR(i,n-1,0)
#define PB push_back
#define mod 1000000007


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin>>x;
    long long int ans=0;
    ans=(x/500)*(500)+(x-(x%5));
    cout<<ans;
    return 0;   
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
  int minutes = abs((h2 * 60 +  m2) - (h1 * 60 + m1));
  minutes = minutes - k;
  cout << minutes << endl;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;

int main() {
  int cnt[100] = {0};
  int n;
  cin >> n;

  rep (i, n) {
    int tmp = i + 1;
    REP (j, 2, n) {
      while (tmp % j == 0) {
        cnt[j]++;
        tmp /= j;
      }
    }
  }

  int a, b, c;
  a = b = c = 0;
  REP (i, 1, n) {
    if (cnt[i] >= 74) a++;
    REP (j, 1, n) {
      if (i == j) continue;
      if (cnt[i] >= 2 && cnt[j] >= 24) b++;
      if (cnt[i] >= 4 && cnt[j] >= 14) b++;
      REP (k, 1, n) {
        if (i == k || j == k) continue;
        if (cnt[i] >= 2 && cnt[j] >= 4 && cnt[k] >= 4) c++;
      }
    }
  }

  cout << a + b + c / 2 << endl;
}


Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll k;cin >> k;
  str s; cin >> s;
  if(s.size() <= k) fin(s);
  else
  {
    cout << s.substr(0, k) << "..." << endl;
  }
  
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  //cout << setfill('0') << internal << setw(4); 0埋め４桁
  Main();
  return 0;
}


Measured memory_bytes: 3616
n = int(input())
a = list(map(int,input().split()))
now = 1000
st = 0
for i in range(n-1):
  if a[i] < a[i+1]:
    tmp = now // a[i]
    now %= a[i]
    st += tmp
  else:
    now += st * a[i]
    st = 0
  #print(now,st)
print(now + a[-1] * st)

Measured memory_bytes: 61772
from itertools import permutations

def solve(a):
    res = []
    for p in permutations(range(3)):
        cur = sum([abs(a[p[i+1]] - a[p[i]]) for i in range(2)])
        res.append(cur)
    return min(res)

assert solve([1,6,3]) == 5
assert solve([11,5,5]) == 6
assert solve([100,100,100]) == 0
a = map(int, raw_input().split())
print solve(a)

Measured memory_bytes: 2692
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


//??¨?????´???
#define MAX_V 100000

struct edge{ int to,weight; };
pii dfs(int prev, int v, const vector<edge> graph[MAX_V]){   //searching farthest node
    pii r(0,v);
    
    rep(i,graph[v].size()){
        struct edge e = graph[v][i];
        if(e.to == prev) continue;
        pii tmp = dfs(v,e.to,graph);
        tmp.first += e.weight;
        if(r.first < tmp.first) r = tmp;
    }
    return r;
}


int diameter( const vector<edge> graph[MAX_V] ) {
    pii r = dfs(-1, 0, graph);
    pii t = dfs(-1, r.second, graph);
    return t.first; // (r.second, t.second) is farthest pair
}


vector<edge> G[MAX_V];

int main(){
    int n;
    cin>>n;
    rep(i,n-1){
        int s,t,w;
        cin>>s>>t>>w;
        G[s].pb(edge{t,w});
        G[t].pb(edge{s,w});
    }
    
    cout<<diameter( G )<<endl;
}

Measured memory_bytes: 17984
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < (n); ++(i))
#define repeat_from(i, m, n) for (int i = (m); (i) < (n); ++(i))
using namespace std;
template <class T>
void setmax(T &a, T const &b) {
    if (a < b) a = b;
}

template <class T>
void setmin(T &a, T const &b) {
    if (a > b) a = b;
}

template <typename T, typename X>
auto vectors(T a, X x) { return vector<T>(x, a); }

template <typename T, typename X, typename Y, typename... Zs>
auto vectors(T a, X x, Y y, Zs... zs) {
    auto cont = vectors(a, y, zs...);
    return vector<decltype(cont)>(x, cont);
}

int main() {
    int A, B;
    cin >> A >> B;
    vector<string> res(100);
    repeat(i, 100) {
        res[i] = "";
        repeat(j, 100) {
            res[i] += (i < 50) ? '#' : '.';
        }
    }

    int num = 0;
    int x = 0, y = 0;
    while (num < A - 1) {
        res[x][y] = '.';
        y += 2;
        if (y >= 100) {
            x += 2;
            y = 0;
        }
        num++;
    }

    num = 0;
    x = 99, y = 0;
    while (num < B - 1) {
        res[x][y] = '#';
        y += 2;
        if (y >= 100) {
            x -= 2;
            y = 0;
        }
        num++;
    }

    cout << "100 100" << endl;
    repeat(i, 100) {
        assert(res[i].size() == 100);
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vec vector

int main(void)
{
    int n;
    cin >> n;
    vec<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i];
        y[i] = x[i];
    }

    sort(x.begin(), x.end());
    int l = x[n / 2 - 1];
    int r = x[n / 2];

    if (l == r) rep(i, n) cout << l << endl;
    else {
        rep(i, n) {
            if (y[i] <= l) cout << r << endl;
            else cout << l << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#include <math.h>

int main(void) {
	int n, x;
	double f;
	scanf("%d %d", &n, &x);
	
	
	if(n==1)
	printf("%d\n", x);
	
	else{
		f=x*pow(x-1, n-1);
		printf("%d\n", (int)f);
	}

	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
int main(void){
    int A,B,SUM=0;
    scanf("%d %d",&A,&B);
    for (int i=0; i<2; i++) {
        if(A>B){
            SUM+=A;
            A--;
        }
        else{
            SUM+=B;
            B--;
        }
    }
    printf("%d\n",SUM);
    
    return 0;
}


Measured memory_bytes: 128
m = int(input())
s = list(map(int, input().split()))
bs = [0] * m

cnt = 0
for i in range(m, 0, -1):
  b = sum(list(map(lambda x: bs[x-1], list(range(i, m+1, i)))))
  if s[i-1] is 0:
    if  b%2 is 0:
      bs[i-1] = 0
    else:
      cnt += 1
      bs[i-1] = 1
  else:
    if  b%2 is 0:
      cnt += 1
      bs[i-1] = 1
    else:
      bs[i-1] = 0

print(cnt)
if cnt > 0:
  print(" ".join([str(i+1) for i, b in enumerate(bs) if b > 0]))

Measured memory_bytes: 16084
# -*- coding: utf-8 -*-

from math import factorial

MOD = 10 ** 9 + 7

def readInts():
  return [int(s) for s in input().split(" ")]

def combi(n, r):
  num = 1
  den1 = 1
  den2 = 1

  for i in range(1, n + 1):
    num = (num * i) % MOD

  for i in range(1, r + 1):
    den1 = (den1 * i) % MOD

  for i in range(1, n - r + 1):
    den2 = (den2 * i) % MOD

  return (num * pow(den1 * den2, MOD - 2, MOD)) % MOD

def solve():
  X, Y = readInts()

  X, Y = max(X, Y), min(X, Y)

  if (X + Y) % 3 != 0:
    return 0

  a = (2 * X - Y) // 3
  b = (2 * Y - X) // 3

  if a < 0 or b < 0:
    return 0

  return combi(a + b, min(a, b)) % MOD

def main():
  print(solve())

if __name__ == "__main__":
  main()


Measured memory_bytes: 3064
#input N
#      H1,H2,,,,HN
N=int(input())
H_list=list(map(int,input().split()))

count=0

for i,H in enumerate(H_list):
    is_view=True
    j=i
    while(is_view and j>0):
        if H_list[j-1]>H:
            is_view=False
        j=j-1
    if is_view:
        count=count+1

print(count)


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

int main(){
long long int N,K;
cin >> N >> K;
N = N%K;
long long int minValue = 0;
long long int t = K;
while(t--){
    N = abs(N-K);
    if(N == abs(abs(N-K)-K)){
        minValue = min(N,abs(N-K));
        break;
    }
}
cout << minValue;
return 0;
}


Measured memory_bytes: 256
from collections import deque


def nth_ll(k):
    if k < 10:
        return k
    queue = deque([i for i in range(1, 10)])
    cnt = 9
    while True:
        n = queue.popleft()
        first_d = n % 10
        for i in range(-1, 2):
            if first_d + i < 0 or first_d + i > 9:
                continue
            queue.append(10 * n + first_d + i)
            cnt += 1
            if cnt == k:
                return queue.pop()

print(nth_ll(int(input())))


Measured memory_bytes: 6112
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int A, B, T;
  cin >> A >> B >> T;

  cout << (T/A)*B << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int A = 0;
  int B = 0;
  scanf("%d", &A);
  scanf("%d", &B);
  if(A <= 8 && B <= 8){
    printf("Yay!\n");
  }else{
    printf(":(\n");
  }

  return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;

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

	int ans = 1010;

	for (int i = 0; i <= s.size()-t.size(); i++) {
		int k = i;
		int j = 0;
		int count = 0;

		while (j<t.size()) {
			if (s[k] != t[j])	count++;
			k++;
			j++;
		}

		if (count < ans)ans = count;
		
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    string s, ans = "";
    cin >> s;

    rep(i, s.size()) {
        if(s[i] == '0') {
            ans += "0";
        }
        else if(s[i] == '1') {
            ans += "1";
        }
        else {
            if(ans != "") {
                ans.pop_back();
            }
        }
    }

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

Measured memory_bytes: 256
n=int(input())
t,a=map(int,input().split())
H=list(map(int,input().split()))

m=float('inf')
for i in range(n):
  if abs(a-t+0.006*H[i])<m:
    m=abs(a-t+0.006*H[i])
    ans=i
print(ans+1)

Measured memory_bytes: 62512
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] A = new int[N];
        int count1 = 0;  //総投票数
        int count2 = 0;  //総投票数の1/4M以上の票を集めた商品数
        
        for(int i=0; i<N; i++){
            A[i] = scanner.nextInt();
            count1 += A[i]; 
        }
        
        for(int i=0; i<N; i++){
            if((double)((double)count1/(4*(double)M))<=A[i]){
                count2 += 1;
            }
        }
        
        if(count2>=M){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

    }
}


Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 100011;
char s[maxn];
int main() {
  int n, k, m = 0;
  scanf("%d%d%s", &n, &k, s);
  char c = (s[0] == 'L' ? 'R' : 'L');
  int pre = -1;
  for (int i = 0; i < n; ++i) {
    if (s[i] == c) {
      if (pre == -1)  pre = i;
    } else {
      if (k && pre >= 0) {
        for (int j = pre; j < i; ++j) {
          s[j] = s[0];
        }
        --k;
        pre = -1;
      }
    }
  }
  if (k && pre >= 0) {
    for (int j = pre; j < n; ++j) s[j] = s[0];
  }
  int ans = 0;
  for (int i = 1; i < n; ++i)
    ans += (s[i] == s[i - 1]);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 384
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
    
N = int(input())
A = [int(x) for x in input().split()]

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = gcd(tmp, A[i])

print(tmp)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9 + 1;
const ll MOD = 1e9 + 7;
const double PI = 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799;

int n, d;

int main(){
  cin >> n >> d;
  cout << (n + 2*d)/(2*d+1) <<endl;
}

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

long long solve(long long N) {
    if (N % 2 == 1) return 0;

    long long res = 0;
    N /= 2;
    while (N) {
        res += N / 5;
        N /= 5;
    }
    return res;
}

 
int main() {
    long long N; cin >> N;
    cout << solve(N) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;
ll dp[upperlimit];
ll fact[upperlimit];
ll invfact[upperlimit];
bool visited[upperlimit];
int subtr[upperlimit];
vi adj[upperlimit];
ll ncr(int n,int r){
	ll ans=fact[n];
	ans*=invfact[r];ans%=mod;
	ans*=invfact[n-r];ans%=mod;
	return ans;
}
int n;
void dfs(int node){
	visited[node]=true;
	subtr[node]=1;
	dp[node]=1;
	for(int i = 0; i < adj[node].size(); i++){
		if(! visited[adj[node][i]]){
			dfs(adj[node][i]);
			subtr[node]+=subtr[adj[node][i]];
			dp[node]*=invfact[subtr[adj[node][i]]];dp[node]%=mod;
			dp[node]*=dp[adj[node][i]];dp[node]%=mod;
		}
	}
	dp[node]*=fact[subtr[node]-1];dp[node]%=mod;
}
void dfs2(int node){
	visited[node]=true;
	for(int i = 0; i < adj[node].size(); i++){
		if(! visited[adj[node][i]]){
			ll temp=dp[node];temp*=powmod(ncr(n-1,n-1-subtr[adj[node][i]]),mod-2,mod);temp%=mod;
			temp*=powmod(dp[adj[node][i]],mod-2,mod);temp%=mod;
			dp[adj[node][i]]*=ncr(n-1,n-subtr[adj[node][i]]);dp[adj[node][i]]%=mod;
			dp[adj[node][i]]*=temp;dp[adj[node][i]]%=mod;
			dfs2(adj[node][i]);
		}
	}
}
int main() {
	fact[0]=1;invfact[0]=1;
	for(int i = 1; i < upperlimit; i++){
		fact[i]=fact[i-1];fact[i]*=i;fact[i]%=mod;
		invfact[i]=powmod(fact[i],mod-2,mod);
	}
	int a,b;
	sd(n);
	for(int i = 1; i < n; i++){
		sd(a);sd(b);
		adj[a].pb(b);adj[b].pb(a);
	}
	dfs(1);
	for(int i = 1; i <= n; i++) visited[i]=false;
	dfs2(1);
	for(int i = 1; i <= n; i++) plldn(dp[i]);
	return 0;
}

Measured memory_bytes: 54260
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e2+7;

int n,ar[maxn];
bool vis[maxn];
int ans[maxn];
int main()
{
    scanf("%d",&n);
    int s;
    if(n & 1){
        s = n;
        printf("%d\n",(n-1)*(n-1)/2);
    }
    else{
        s = n+1;
        printf("%d\n",n*(n-2)/2);
    }
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            if(i+j != s)printf("%d %d\n",i,j);
        }
    }
    
    

    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;;
    cin >> s;
    if(s=="SUN")    cout << 7;
    else if(s=="MON") cout << 6;
    else if(s=="TUE") cout << 5;
    else if(s=="WED") cout << 4;
    else if(s=="THU") cout << 3;
    else if(s=="FRI") cout << 2;
    else cout << 1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	string S; cin >> S;
	if (S == "SUN") cout << "7" << endl;
	if (S == "MON") cout << "6" << endl;
	if (S == "TUE") cout << "5" << endl;
	if (S == "WED") cout << "4" << endl;
	if (S == "THU") cout << "3" << endl;
	if (S == "FRI") cout << "2" << endl;
	if (S == "SAT") cout << "1" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys

n = int(input())
b = list(map(int,input().split()))
a = [0]*n
a[0] = b[0]
a[n-1] = b[n-2]

for i in range(1,n-1):
    if b[i] > b[i-1]:
       a[i] = b[i-1]
    else:
        a[i] = b[i]

print(sum(a))


Measured memory_bytes: 3060
//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
#include <bitset>
using namespace std;
//namespace mp = boost::multiprecision;
//using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll n,ans=0;
  cin>>n;
  vector<ll>v(n,0);
  for(ll i=0;i<n;i++){
    cin>>v[i];
  }
  for(ll i=0;i<n-1;i++){
    for(ll j=i+1;j<n;j++){
      ans+=v[i]*v[j];
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	ll x, k, d;
	cin >> x >> k >> d;
	x = abs(x);
	if (x > 0){
		double xx = x, kk = k, dd = d;
		if (xx/kk <  dd){
			k -= x/d;
			x %= d;
			if (k % 2 == 0) cout << x << endl;
			else cout << abs(x - d) << endl;
		}else{
			cout << x - k * d << endl;
		}
	}else{
		if (k % 2 == 0) cout << 0 << endl;
		else cout << d << endl;
	}
	return 0;
}


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

int main(void){
	int n, a[2][100];
	int ans = 0;

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

	int tmp = 0;
	for (int i = 0; i < n; i++){
		for (int j = 0; j <= i; j++) tmp += a[0][j];
		for (int j = i; j < n; j++) tmp += a[1][j];
		if (tmp > ans) ans = tmp;
		tmp = 0;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

int n, pos;
int pre[40], in[40], post[40];
bool preused[40];

inline int toinnode(int prenode) {
    for (int i = 0; i < n; ++i) {
        if (in[i] == pre[prenode]) {
            return i;
        }
    }
}

inline int toprenode(int innode) {
    for (int i = 0; i < n; ++i) {
        if (pre[i] == in[innode]) {
            return i;
        }
    }
}

inline void topost(int preroot, int num) {

//    printf("[topost] preroot = %d, num = %d\n", preroot, num);

    int inroot = toinnode(preroot), leftnodenum = 0;

    // whether preroot has a left tree or not. 
    if (inroot - 1 >= 0 && !preused[toprenode(inroot - 1)]) {
        preused[preroot + 1] = true;
        int inleftroot = toinnode(preroot + 1);
        for (int i = inleftroot - 1;
                i >= 0 && !preused[toprenode(i)]; --i, ++leftnodenum) { };
        for (int i = inleftroot + 1;
                i < n && !preused[toprenode(i)]; ++i, ++leftnodenum) { };
        ++leftnodenum;
        topost(preroot + 1, toprenode(inroot - 1) - preroot);
    }

    // whether preroot has a right tree or not. 
    if (inroot + 1 < n && !preused[toprenode(inroot + 1)]) {
        int prerightroot = preroot + leftnodenum + 1;
        preused[prerightroot] = true;
        topost(prerightroot, num - leftnodenum);
    }

    post[pos++] = pre[preroot];
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0; i < n; ++i) {
        scanf("%d", &pre[i]);
    }

    for (int i = 0; i < n; ++i) {
        scanf("%d", &in[i]);
    }

    preused[0] = true;
    topost(0, n);

    printf("%d", post[0]);
    for (int i = 1; i < n; ++i) {
        printf(" %d", post[i]);
    }
    printf("\n");

    return 0;
}

Measured memory_bytes: 1196
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use proconio::input;
use proconio::marker::*;
use itertools::Itertools;

fn main() {
    input! {
        r: usize,
        c: usize,
        k: usize,
        v: [(Usize1, Usize1, usize); k],
    }

    let mut value = vec![vec![0; c]; r];

    for &(y, x, v) in &v {
        value[y][x] = v;
    }

    let mut dp = vec![vec![vec![0; 4]; c]; r];

    dp[0][0][1] = value[0][0];

    for y in 0..r {
        for x in 0..c {
            if x == 0 && y == 0 {
                continue;
            }

            for i in 1..=3 {
                dp[y][x][i] = std::cmp::max(
                    std::cmp::max(
                        if x != 0 {dp[y][x - 1][i]} else { 0 },
                        if y != 0 {*dp[y - 1][x].iter().max().unwrap()} else { 0 }
                    ),
                    std::cmp::max(
                        if x != 0 {dp[y][x - 1][i - 1]} else { 0 },
                        if y != 0 {*dp[y - 1][x].iter().max().unwrap()} else { 0 }
                    ) + value[y][x],
                )
            }
        }
    }

    let ans = dp[r - 1][c - 1].iter().max().unwrap();
    println!("{}", ans);
}


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

const int INF = 1001001001;

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  --x; --y;
  vector<int> ans(n);
  rep(sv,n) {
    vector<int> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      if (dist[v] != INF) return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      int d = dist[v];
      if (v-1 >= 0) push(v-1, d+1);
      if (v+1 < n) push(v+1, d+1);
      if (v == x) push(y, d+1);
      if (v == y) push(x, d+1);
    }
    rep(i,n) ans[dist[i]]++;
  }
  rep(i,n) ans[i] /= 2;
  for (int i = 1; i <= n-1; ++i) {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=5e5+20;
char s[N];
int st,ed,op,n;

void in(int x,char c) {
	if(x^op) s[++ed]=c;
	else s[--st]=c;
}

int main() {
	scanf("%s",s+(st=2e5+10));
	ed=strlen(s+st)+st-1;op=0;
	scanf("%d",&n); while(n--) {
		int t,f; char c;
		scanf("%d",&t);
		if(t==1)op^=1;
		else {
			scanf("%d %c",&f,&c);
			in(--f,c);
		}
	}
	if(op)reverse(s+st,s+ed+1);
	puts(s+st);
	return 0;
}


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

int main(void){
    int n, r, g, b, x;
    string color;
    cin >> n;
    cin >> color;
    r = g = b = x = 0;
    int64_t cnt = 0;
    
    for(int i=0; i<n; i++){
        if(color[i] == 'R') r++;
        else if(color[i] == 'G') g++;
        else b++;
        for(int j=i+1, k=i+2; k<n; j++, k+=2)
            if(color[i]!=color[j] && color[j]!=color[k] && color[k]!=color[i]) x++;
    }
    cout << (int64_t)r*g*b - x << '\n';
    return 0;
}

Measured memory_bytes: 3628
N,M = map(int,input().split())
t = [-1]*N
for i in range(M):
    s, c=map(int, input().split())
   
    if t[s-1] != -1 and t[s-1] != c:
        print(-1)
        exit()
    t[s-1] = c
if N != 1:
    if t[0] == 0:
        print(-1)
        exit()
    if t[0] == -1:
        t[0] =1
    for i in range(1,N):
        if t[i] == -1:
            t[i] = 0
else:
    if t[0] == -1:
        t[0] = 0
print("".join(map(str,t)))
        


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

using namespace std;

#define forsn(i, s, n) for(int i=s;i<int(n);i++)
#define forn(i, n) forsn(i, 0, n)
#define all(v) v.begin(), v.end()

typedef long long tint;

int main(){
	int a, b; cin >> a >> b; cout << max(max(a+b, a-b), a*b) << endl;
}


Measured memory_bytes: 256