akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE OverloadedStrings #-}
import Data.Maybe
import Data.Char
import Data.List
import Data.Function
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as VU

main :: IO()
main = do
  getLine
  ns <- getIntList
  print . maximum . unfoldr slice $ ns

slice [] = Nothing
slice (n:ns) = Just $ cut n ns
  where
    cut n [] = (0, [])
    cut n mss@(m:ms)
      | n >= m = let (n, ls) = cut m ms in (n+1, ls)
      | otherwise = (0, mss)

-- IO
readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getIntVec :: Int -> IO (VU.Vector Int)
getIntVec n = VU.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine


Measured memory_bytes: 11644
// AtCode.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>

using namespace std;



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

	if (A + B <= K) cout << "0 0" << endl;
	else if (A >= K) cout << A - K << " " << B << endl;
	else cout << "0 " << (A + B - K) << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

struct mission{int l,r,x;};

int main(void){
	ll x;cin>>x;
	int i = 0;
	ll sum = 0;
	while(sum < x){
		i++;
		sum += i;
	}
	cout<<i<<endl;
	return 0;
}


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

int fav[100005];

int main()
{
	int N;
	cin >> N;

	memset(fav, 0, sizeof(fav));
	for(int i=0; i<N; i++)
	{
		int l,r;
		cin >> l >> r;
		fav[l-1]++;
		fav[r]--;
	}

	int res=0, mem=0;
	for(int i=1; i<=N+1; i++) {
		mem+=fav[i];
		if(mem >= i) res = i;
	}

	cout << res << endl;
}

Measured memory_bytes: 1224
from collections import deque
N,M = map(int,input().split())
node = [[10**9]*3 for i in range(N)]
KENPA = 3
side = [[]for i in range(N)]
for i in range(M):
    u,v = map(int,input().split())
    side[u-1].append(v-1)
S,T = map(int,input().split())
node[S-1][2] = 0
queue = deque([[S-1,2]])
while queue:
    x,y = queue.popleft()
    y2 = (y+1)%KENPA
    for i in side[x]:
        if node[i][y2] > node[x][y]+1:
            node[i][y2] = node[x][y]+1
            queue.append([i,y2])
if node[T-1][2] == 10**9:
    print(-1)
else:
    print(node[T-1][2] // 3)


Measured memory_bytes: 70764
N,X = [int(i) for i in input().split()]
L = [int(i) for i in input().split()]

c = 1
before_x = 0
for i in range(N) :
    if (before_x + L[i] <= X) :
        c += 1
        before_x += L[i]
    else :
        break

print(c)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int H = scanner.nextInt();
        int W = scanner.nextInt();
        int N = scanner.nextInt();
        int[] a = new int[N];
        int[][] grid = new int[H][W];
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                grid[i][j] = -1;
            }
        }
        int tmp = -1;
        for (int i = 0; i < a.length; i++) {
            a[i] = scanner.nextInt();
        }
        for (int i = 1; i <= a.length; i++) {
            tmp = a[i - 1];
            while (tmp > 0) {
                for (int h = 0; h < H; h++) {
                    if (h % 2 == 0) {
                        for (int w = 0; w < W; w++) {
                            if (grid[h][w] == -1) {
                                grid[h][w] = i;
                                tmp--;
                            }
                            if (tmp == 0) break;
                        }
                    } else {
                        for (int w = W - 1; w >= 0; w--) {
                            if (grid[h][w] == -1) {
                                grid[h][w] = i;
                                tmp--;
                            }
                            if (tmp == 0) break;
                        }
                    }
                    if (tmp == 0) break;
                }
                if (tmp == 0) break;
            }
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                System.out.print(grid[i][j] + " ");
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34580
#include <stdio.h>

int main(){
  int n,i,j,cnt=0,min=0,tmp=0;
  int a[100];
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  
  for(i=0;i<n-1;i++){
    min=i;
    for(j=i;j<n;j++){
      if(a[j]<a[min]) min=j;
    }
      tmp=a[min];
      a[min]=a[i];
      a[i]=tmp;
      if(i!=min) cnt++;
  }

  for(i=0;i<n;i++){
     printf("%d",a[i]);
     if(i==n-1) printf("\n");
     else printf(" ");
  }
  printf("%d\n",cnt);

  return 0;
}

Measured memory_bytes: 604
import collections
import numpy as np

# = input()
# = int(input())
# = map(int, input().split())
# = list(map(int, input().split()))
#

N = int(input())

ans = 'No'
for i in range(9):
  for j in range(9):
    if (i + 1) * (j + 1) == N:
      ans = 'Yes'

print(ans)

Measured memory_bytes: 21256
#include<bits/stdc++.h>
// __builtin_ctz : no of trailing zeros
#define ll long long
#define pp pair<ll,ll>
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
using namespace std;
ll max(ll x, ll y)
{
    return x>y ? x : y;
}
ll min(ll x, ll y)
{
    return x<y ? x : y;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a,p;cin >> a >> p;cout << (a*3+p)/2;
    }

Measured memory_bytes: 256
/* ****Ragnar7 -SHINIGAMI- _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		vector<ld> v(n+1,0);
		for(int i=1;i<=n;i++)
			cin>>v[i];
		ld dp[n+1][n+1];
		memset(dp,0.0,sizeof(dp));
		dp[0][0] = 1.0;
		for(ll i=1;i<=n;i++)
			dp[0][i]=dp[0][i-1]*(1.0-v[i]);
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				dp[i][j] = dp[i][j-1]*(1-v[j]) + dp[i-1][j-1]*(v[j]);
			}
		}
		// for(ll i=1;i<=n;i++)
		// {
		// 	for(ll j=1;j<=n;j++)
		// 		cout<<dp[i][j]<<" ";
		// 	cout<<endl;
		// }
		ld ans = 0;
		for(ll i=n/2+1;i<=n;i++)
			ans += dp[i][n];
		cout<<setprecision(100)<<ans<<endl;
	}

	
	time
	return 0;
}

Measured memory_bytes: 144404
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
m_list = [list(map(int, input().split())) for i in range(m)]

ans = min(a_list) + min(b_list)

for i in range(m):
    ans = min(ans, a_list[m_list[i][0] - 1] + b_list[m_list[i][1] - 1] - m_list[i][2])

print(ans)

Measured memory_bytes: 80196
# -*- coding: utf-8 -*-
S=input()  
ans=0
num=0

def count(S,binnumber,i):
    if i==1:
        if binnumber[0]=="1":
            return int(S[0])+int(S[1:])
        return int(S)
    elif binnumber[i-1]=="1":
            return int(S[i:])+count(S[:i],binnumber,i-1)
    return count(S,binnumber,i-1)

for i in range(len(S)-1):
    num=num+2**i

for i in range(num+1): 
    binnumber=str(format(i,"b").zfill(len(S)-1))
    j=len(binnumber)
    ans=ans+count(S,binnumber,j)
    
print(ans)

Measured memory_bytes: 3064
n = int(input())
s = []
t = []
for i in range(n):
    tmp = input().split()
    s.append(str(tmp[0]))
    t.append(int(tmp[1]))

x = str(input())

index = -1
for i in range(n):
    if s[i] == x:
        index = i
        break

ans = 0
for i in range(index+1,n):
    ans += t[i]

print(ans)


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef pair<double, double> P;

void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

struct Edge {
    ll to, cost;
};

class Dijkstra {
    ll vector_count;

    vector<ll> distances;
    vector<vector<Edge>> edges;

public:
    Dijkstra(ll n) {
        vector_count = n;
        distances.resize(n, INF);
        edges.resize(n);
    }

    void insertTowWay(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
        edges[to].push_back({from, cost});
    }

    void insert(ll from, ll to, ll cost) {
        edges[from].push_back({to, cost});
    }

    void dijkstra(ll k) {
        distances[k] = 0;  // 始点sへの最短距離は0

        priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
        que.push(P(0, k));
        while (!que.empty()) {
            P p = que.top();
            que.pop();
            int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
            if (distances[v] < p.first) {
                continue;
            }
            for (auto e : edges[v]) {  // 頂点vから出る辺eを走査
                if (distances[e.to] > distances[v] + e.cost) {
                    distances[e.to] = distances[v] + e.cost;
                    que.push(P(distances[e.to], e.to));
                }
            }
        }
    }

    ll calcDistance(ll to) {
        return distances[to];
    }

};


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

    int n;
    cin >> n;

    Dijkstra dijkstra(n);
    rep(i, n) {
        int j, k;
        cin >> j >> k;

        rep(l, k) {
            int u, c;
            cin >> u >> c;
            dijkstra.insert(j, u, c);
        }
    }
    dijkstra.dijkstra(0);


    rep(i, n) cout << i << ' ' << dijkstra.calcDistance(i) << endl;

}




Measured memory_bytes: 11852
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        sc.close();

        int ans = x + n;

        for (int i = 0; i < n; i++) {
            for (int j = 1; j < 100; j++) {
                if (arr[i] * j < d) {
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
}

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

map<char, string> mp;

int main() {
    string t = "abc";
    rep(i, t.size()) {
        string input; cin >> input;
        mp[t[i]] = input;
    }

    char next = 'a';
    // cout << current << endl;
    // return 0;
    
    // 誰かが勝つまで
    while (true) {
        string a = mp[next];
        char current = next;
        if (a.size() == 0) {
            break;
        }
        next = a[0];
        a.erase(0, 1);

        mp[current] = a;
        // printf("next: %c %s\n", next, a.c_str());
    }

    cout << (char)toupper(next) << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var n = Console.ReadLine();
		var nl = n.ToLong();
		long wa = 0;
		for(int i = 0; i < n.Length; i++)
		{
			wa += n.Substring(i, 1).ToInt();
		}
		Console.WriteLine(nl % wa == 0 ? "Yes" : "No");
	}

	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static long Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 13140
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut ans = 0.0;
    for _ in 0..n {
        let v = read::<f64>();
        let s = read::<String>();
        if s == "JPY" {
            ans += v;
        } else {
            ans += v * 380000.0;
        }
    }
    println!("{:.8}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  vector<vector<pair<int, int> > > edge(N);
  for(int i=1;i<N;++i) {
    edge[i].push_back(mp(i-1, 0));
  }
  int L, R, C;
  for(int i=0;i<M;++i) {
    cin>>L>>R>>C;
    L--;
    R--;
    edge[L].push_back(mp(R, C));
  }
  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;
  pair<ll, int> state;
  que.push(mp(0, 0));
  map<int, ll> amap;
  for(int i=0;i<N;++i) amap[i] = -1;
  ll node, cost;
  while(!que.empty()) {
    state = que.top();que.pop();
    node = state.se;
    cost = state.fi;
    if(amap[node]>-1) continue;
    amap[node] = cost;
    for(int i=0;i<edge[node].size();++i) {
      if(amap[edge[node][i].fi]>-1 && amap[edge[node][i].fi]<=cost+edge[node][i].se) continue;
      que.push(mp(cost+edge[node][i].se, edge[node][i].fi));
    }
  }
  cout<<amap[N-1]<<endl;
}



Measured memory_bytes: 16932
package main

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

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	k := sc.ReadInt()
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		a[i] = sc.ReadInt()
	}

	visitTowns := make([]int, 0, n+1)
	visitTimes := make([]int, n+1)
	curTown := 1
	timeBackTo := 0
	for curTime := 0; ; curTime++ {
		if visitTimes[curTown] > 0 {
			timeBackTo = visitTimes[curTown]
			break
		}

		visitTowns = append(visitTowns, curTown)
		visitTimes[curTown] = curTime

		// teleport
		curTown = a[curTown]
	}

	nonLoopCount := timeBackTo
	loopSpan := len(visitTowns) - nonLoopCount

	if k <= nonLoopCount {
		fmt.Println(visitTowns[k])
		return
	}

	rem := (k - nonLoopCount) % loopSpan
	fmt.Println(visitTowns[nonLoopCount+rem])
}

type Book struct {
	Price  int
	Powers []int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   sortutil

func ReverseInts(a []int) {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
}

func ReverseStrings(a []string) {
	sort.Sort(sort.Reverse(sort.StringSlice(a)))
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


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

namespace AtCoder
{
    class Program
    {
        static long C;
        static long D;
        static long lcm;

        static void Main(string[] args)
        {
            //[summary]C - Anti-Division
            var line = ReadLine();
            long A = line[0];
            long B = line[1];
            C = line[2];
            D = line[3];

            var lib = new Library.Gcd();
            lcm = lib.GetLcm(C, D);

            long ans = CountAntiDivisions(B) - CountAntiDivisions(A - 1);
            Console.WriteLine(ans);
        }

        static long CountAntiDivisions(long B)
        {
            var divisors = B / C + B / D - B / lcm;
            return B - divisors;
        }

        static List<long> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => long.Parse(x)).ToList();
        }
    }
}

namespace Library
{
    public class Gcd
    {
        public long GetGcd(long a, long b)
        {
            //[summary]a,b2つの数の最大公約数を求める
            //Gcd: Greatest Common Divisor
            //以下リンクを参考に実装
            //https://qiita.com/gushwell/items/e9614b4ac2bea3fc6486

            if (a < b)
            {
                //引数を入れ替えて自分を呼び出す
                return GetGcd(b, a);
            }
            else
            {
                while (b > 0)
                {
                    long remainder = a % b;

                    a = b;
                    b = remainder;
                }

                return a;
            }
        }

        public long GetLcm(long a, long b)
        {
            //[summary]a,b2つの数の最小公倍数を求める
            //Lcm: Least Common Multiple
            //以下リンクを参考に実装
            //https://qiita.com/gushwell/items/f08d0e71fa0480dbb396

            long gcd = GetGcd(a, b);

            //先に割り算をしておくとオーバーフローしない
            return a / gcd * b;
        }
    }
}

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

int main() {
	int N, M;
	cin >> N >> M;
	vector<bool>A(N);
	for (int i = 0; i < M; ++i) {
		int x, y;
		cin >> x >> y;
		if (x == 1) {
			if (A[y]) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
			else {
				A[y] = true;
			}
		}
		if (y == N) {
			if (A[x]) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
			else {
				A[x] = true;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 3596
import Data.List

is2nd :: Int -> Int -> Int -> Bool
is2nd p1 p2 p3 = (p2 `elemIndex` sort [p1, p2, p3]) == Just 1

solve :: [Int] -> Int
solve [p1, p2, p3] = if is2nd p1 p2 p3 then 1 else 0
solve (p1:p2:p3:ps) = solve (p2:p3:ps) + if is2nd p1 p2 p3 then 1 else 0

main :: IO ()
main = do
  getLine
  ps <- map read . words <$> getLine
  print $ solve ps

Measured memory_bytes: 508
#include <iostream>
#include <cmath>

struct Circle {
    const double x, y, r;
    Circle(const double x, const double y, const double r)
        :x(x), y(y), r(r) {};
    ~Circle() = default;
    bool include(Circle &C);
};

inline double distance(Circle &A, Circle &B) {
    return std::sqrt((A.x - B.x) * (A.x - B.x) + (A.y - B.y) * (A.y - B.y));
}

bool Circle::include(Circle &C) {
    auto d = distance(*this, C);
    return (d*d < (r - C.r)*(r - C.r) && r > C.r);
}

int circles_intersection(Circle &A, Circle &B) {
    auto d = distance(A, B);
    if (d > A.r + B.r)      return  0;
    else if (A.include(B))  return  2;
    else if (B.include(A))  return -2;
    else                    return  1;

}

int main(void) {
    u_int n;
    double xa, ya, ra, xb, yb, rb;

    std::cin >> n;
    for (u_int i = 0; i < n; ++i) {
        std::cin >> xa >> ya >> ra >> xb >> yb >> rb;
        Circle A(xa, ya, ra), B(xb, yb, rb);
        std::cout << circles_intersection(A, B) << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1240
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 083 B "Some Sums"
 *   https://abc083.contest.atcoder.jp/tasks/abc083_b/
 */
public class Main {

	public static void main(String[] args) {

		InputScanner in = new InputScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int N = in.nextInt();
		int A = in.nextInt();
		int B = in.nextInt();

		int ans = 0;
		for (int i = 1; i <= N; i++) {

			int target = i;
			int sum = 0;

			while (target > 0) {

				sum += target % 10;
				target /= 10;

			}

			if (A <= sum & sum <= B) {
				ans += i;
			}

		}

		out.println(ans);

		in.close();
		out.close();
	}

	/*
	 * extends java.util.Scanner
	 */
	static class InputScanner {

		Scanner scanner;

		public InputScanner(InputStream inputStream) {
			this.scanner = new Scanner(inputStream);
		}

		public int nextInt() {
			return scanner.nextInt();
		}

		public long nextLong() {
			return scanner.nextLong();
		}

		public double nextDouble() {
			return scanner.nextDouble();
		}
		public String next() {
			return scanner.next();
		}

		public int[] nextIntArray(int n) {
			int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextInt();
			}
			return ret;
		}

		public int[][] nextIntArray(int h, int w) {
			int[][] ret = new int[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextInt();
				}
			}
			return ret;
		}

		public long[] nextLongArray(int n) {
			long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextLong();
			}
			return ret;
		}

		public long[][] nextlongArray(int h, int w) {
			long[][] ret = new long[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public double[] nextDoubleArray(int n) {
			double[] ret = new double[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.nextDouble();
			}
			return ret;
		}

		public double[][] nextDoubleArray(int h, int w) {
			double[][] ret = new double[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.nextLong();
				}
			}
			return ret;
		}

		public String[] nextStringArray(int n) {
			String[] ret = new String[n];
			for (int i = 0; i < n; i++) {
				ret[i] = scanner.next();
			}
			return ret;
		}

		public String[] nextStringArray(int n, String split) {
			String[] ret = scanner.next().split(split);
			return ret;
		}

		public String[][] nextStringArray(int h, int w) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					ret[i][j] = scanner.next();
				}
			}
			return ret;
		}

		public String[][] nextStringArray(int h, int w, String split) {
			String[][] ret = new String[h][w];
			for (int i = 0; i < h; i++) {
				ret[i] = scanner.next().split(split);
			}
			return ret;
		}

		public void close() {
			scanner.close();
		}

	}

}


Measured memory_bytes: 22996
#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 N, K; 
  cin >> N >> K;

  vector<int> A(N);
  REP(i, N) cin >> A[i];
  sort(ALL(A));

  auto check = [&](int x){
    int ret = 0;

    REP(i, N){
      if(A[i]*A[i] <= x) ret--;

      if(A[i] == 0){
        if(0 <= x) ret += N;
      }else if(A[i] > 0){
        int ok = -1;
        int ng = N;
        while(ng-ok > 1){
          int mid = (ok+ng)/2;
          if(A[i]*A[mid] <= x) ok = mid;
          else ng = mid;
        }
        ret += ok+1;
      }else{
        int ok = N;
        int ng = -1;
        while(ok-ng > 1){
          int mid = (ok+ng)/2;
          if(A[i]*A[mid] <= x) ok = mid;
          else ng = mid;
        }
        ret += N-ok;
      }
    }
    
    return (ret/2 >= K);
  };

  int ok = INF;
  int ng = -INF;

  while(ok-ng > 1){
    int mid = (ok+ng)/2;
    (check(mid)? ok: ng) = mid;
  }

  cout << ok << "\n";

  return 0;
}

Measured memory_bytes: 1792
H, W = gets.split(' ').map(&:to_i)
grid = []
H.times do
  line = gets.chomp
  if line.include?('#')
    grid.push(line)
  end
end
row = []
(W - 1).downto(0) do |i|
  if grid.all?{|l| l[i] == '.'}
    row.push(i)
  end
end
grid.each do |l|
  row.each do |i|
    l[i] = ''
  end
end
puts grid

Measured memory_bytes: 1788
#include <cstdio>
#include <algorithm>
#include <queue>

#define EiP 40320
#define MAX 100000
using namespace std;

int dis[EiP];
int vx[] = {0,0,1,-1};
int vy[] = {1,-1,0,0};
int a[8]={0,1,2,3,4,5,6,7};
int ans;


void IntegerToMatrix(int n,int* a){
	int rank=1;
	for(int i=2;i<9;i++) rank *= i;
	bool b[8];
	for(int i=0;i<8;i++) b[i] = true;
	
	for(int i=0;i<8;i++){
		rank = rank/(8-i);
		int j,sum=0;
		for(j=0;j<8;j++){
			if(b[j]) sum++;
			if(sum == n/rank+1) break;
		}
		b[j] = false;
		a[i] = j;
		n = n%rank;
	}
}

void MatrixToInteger(int a[8], int* n){
	int l=7; *n = 0;
	bool b[8];
	for(int i=0;i<8;i++) b[i] = true;
	for(int i=0;i<7;i++){
		int sum=0;
		b[a[i]] = false;
		for(int j=0;j<a[i];j++)
			if(b[j]) sum++;
		*n = (7-i)*(*n+sum);
	}
}

void trade(int a[8], int b, int c){
	int k = a[b];
	a[b] = a[c];
	a[c] = k;
}

void set(){
	queue<int> que;
	MatrixToInteger(a,&ans);
	dis[ans] = 0;
	que.push(ans);
	
	int c[8];
	while(!que.empty()){
		int v=que.front(); que.pop();
		IntegerToMatrix(v,c);
		int z;
		for(int i=0;i<8;i++)
			if(c[i] == 0) z = i;
		for(int i=0;i<4;i++){
			int px,py;
			px = z/4 + vx[i];
			py = z%4 + vy[i];
			if(-1<px&&px<2&&-1<py&&py<4){
				int id,pz;
				pz = 4*px+py;
				trade(c,z,pz);
				MatrixToInteger(c,&id);
				if(dis[v]+1<dis[id]){
					que.push(id);
					dis[id] = dis[v]+1;
				}
				trade(c,z,pz);
			}
		}
	}
}

void solve(){
	MatrixToInteger(a,&ans);
	printf("%d\n",dis[ans]);
}

int main(){
	for(int i=0;i<EiP;i++) dis[i] = MAX;
	set();
	for(int p=0;p<1000;p++){
		for(int i=0;i<8;i++){
			if(EOF == scanf(" %d",&a[i])){
				return 0;
			}
		}
		solve();
	}
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <variant>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int h,w,m;
  cin>>h>>w>>m;
  vecint ch(h), cw(w);
  set<tuple<int,int>> s;
  REP(i,m) {
    int y,x;
    cin>>y>>x;
    --y;--x;
    ++ch[y];
    ++cw[x];
    s.emplace(y,x);
  }
  int mxh = *max_element(ALL(ch));
  int mxw = *max_element(ALL(cw));
  vecint hi, wi;
  REP(i,h) {
    if (ch[i] == mxh) hi.push_back(i);
  }
  REP(i,w) {
    if (cw[i] == mxw) wi.push_back(i);
  }
  if (size(hi) * size(wi) > m) {
    cout<<mxh+mxw<<endl;
    return 0;
  }
  for(auto&&y:hi){
    for(auto&&x:wi){
      if (s.count(make_tuple(y,x)) == 0) {
        cout<<mxh+mxw<<endl;
        return 0;
      }
    }
  }
  cout<<(mxh+mxw-1)<<endl;
  return 0;
}


Measured memory_bytes: 23816
#include<bits/stdc++.h>
#define LL long long
using namespace std;
int main(){
  LL n;
  while(~scanf("%lld",&n)){
      LL ans=1e18;
      for (int i=1;i<=sqrt(n)+1;i++){
          if (n%i==0){
            ans=min(ans,n/i+i);
          }
      }
      ans--;
      ans--;
      printf("%lld\n",ans);
  }
  return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int k;
    cin >> k;

    int cur = 7 % k, ret = 1;
    vector<bool> vis(k);
    while (!vis[cur]) {
        if (cur == 0) {
            cout << ret << "\n";
            return 0;
        }
        vis[cur] = true;
        cur = (10 * cur + 7) % k;
        ret++;
    }
    cout << "-1\n";

    return 0;
}


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

#include <iostream>
using namespace std;

int main() {
    int n;
    int a;
    int b;
    int c;
    int d;
    int t[101]={};
    cin>>n;
	for(int i=1; i<n*(n-1)/2+1; i++){
		cin>>a>>b>>c>>d;
		if(c<d)t[b]+=3;
		if(c>d)t[a]+=3;
		if(c==d){
			t[a]+=1;
			t[b]+=1;
		}
	}
	for(int j=1; j<n+1; j++){
		int juni=1;
		for(int i=1; i<n+1; i++){
			if(t[j]<t[i])juni+=1;
		}
		cout<<juni<<endl;
	}
}

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

signed main() {
int n,q;
cin>>n>>q;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
if(n==2){
  int x;
  for(int i=0;i<q;i++){
    cin>>x;
    cout<<a[1]<<endl;
  }
  return 0;
}
int t[(n-1)/2],ans[(n-1)/2+1]={};
for(int i=0;n-1-2*i>=0;i++)ans[0]+=a[n-1-2*i];
for(int i=1;i<(n-1)/2+1;i++)ans[i]=ans[i-1]+a[n-1-i]-a[n-1-2*i];
for(int i=1;i<=(n-1)/2;i++){
  t[i-1]=a[n-1-i]+a[n-1-2*i];
}
int x,ok,ng,mid;
for(int i=0;i<q;i++){
  cin>>x;
  ok=(n-1)/2;ng=-1;
  while(abs(ok-ng)>1){
    mid=(ok+ng)/2;
    if(t[mid]<2*x){
      ok=mid;
    }else ng=mid;
  }
  cout<<ans[ok]<<endl;
}

return 0;
}


Measured memory_bytes: 3328
#ABC075-B
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]

def mine(x,y,grid):
    if grid[x][y] == ".":
        cnt = 0
        for dx,dy in ((1,0),(1,1),(0,1),(-1,1),(-1,0),(-1,-1),(0,-1),(1,-1)):
            nx,ny = x + dx,y + dy
            if 0 <= nx and 0 <= ny and nx <= h-1 and ny <= w-1 and grid[nx][ny] == "#":
                cnt += 1
        grid[x][y] = str(cnt)    
        
for i in range(h):
    for j in range(w):
        mine(i,j,s)
        
for i in range(h):
    print("".join(s[i]))
    

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

int main(void){
    long long A,B,C,K;cin>>A>>B>>C>>K;
    if(K%2==1){
        cout<<B-A<<endl;
    }
    else{
        cout<<A-B<<endl;
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;
//問題読み間違えた．．．
int main(){

    ll N, K;
    cin >> N >> K;
    //奇数同士を選ぶと最大の選び方ができる
    if(N / 2 + N % 2 >= K){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
    const int MAX =200002;
const int MOD =1000000007;


     signed main(){
         string s;
         cin>>s;
         if(s=="RSR"){
             cout<<1<<endl;
             return 0;
         }
         int ans=0;
         for(int i=0;i<3;i++)if(s[i]=='R')ans++;
         cout<<ans<<endl;
       
       


     }


 


 






    





      

        


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

#define IO std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL);
#define FIN freopen("entrada.in", "r", stdin);
#define FOUT freopen("saida.sol", "w", stdout);

#define ull unsigned long long
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define MAX int(50000)+10

const int INF = 0x3f3f3f3f;
using namespace std;

int main() {

    IO

    vector<int> vet(5);
    for (int &i:vet) {
        cin >> i;
    }
    sort(vet.begin(), vet.end());
    int i = 0;
    for (int j:vet) {
        if (i != j) {
            cout << i << "\n";
            return 0;
        }
        i++;
    }
    cout << "5\n";

    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
    using namespace std;
     
    int N;
     
    int main() {
    	cin >> N;
    	int buf = N;
    	int sum = 0;
    	while (buf > 0) {
    		sum += buf % 10;
    		buf = buf / 10;
    	}
    	if (N%sum == 0) cout << "Yes" << endl;
    	else cout << "No" << endl;
    }

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


//コインの金額
bool solve(int n){
    for(int i=2; i>=0; i--){
        double ii = i;
        int tmp = pow(10.0, ii);
        int t = n / tmp;
        if(t==7){
            return true;
            break;
        }
        n = n-tmp*t;
    }
    return false;
}
int main(){
    int n;
    cin >> n;
    bool ans;
    ans = solve(n);
    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3760
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
  static Scanner sc = new Scanner(System.in);
  static final int INF = Integer.MAX_VALUE;
  static Node[] nodes;

  public static void main(String[] args) {
    boolean result = solve();
    if (result) {
      System.out.println("Yes");
      for (int i = 0; i < nodes.length; i++) {
        System.out.println(nodes[i].v);
      }
    } else {
      System.out.println("No");
    }
  }

  static boolean solve() {
    int N = sc.nextInt();
    nodes = new Node[N];
    for (int i = 0; i < N; i++) {
      nodes[i] = new Node(i);
    }
    for (int i = 0; i < N - 1; i++) {
      int A = Integer.parseInt(sc.next()) - 1;
      int B = Integer.parseInt(sc.next()) - 1;
      nodes[A].next.add(nodes[B]);
      nodes[B].next.add(nodes[A]);
    }
    int K = sc.nextInt();
    for (int i = 0; i < K; i++) {
      int V = Integer.parseInt(sc.next()) - 1;
      int P = Integer.parseInt(sc.next());
      nodes[V].v = nodes[V].min = nodes[V].max = P;
    }
    Node[] order = new Node[N];
    order[0] = nodes[0];
    nodes[0].parent = -1;
    for (int i = 0, pos = 1; i < N; i++) {
      for (Node c : order[i].next) {
        if (c.parent != INF) continue;
        c.parent = order[i].id;
        c.depth = order[i].depth + 1;
        order[pos++] = c;
      }
    }
    int parity = -1;
    for (int i = 0; i < N; i++) {
      if (order[i].v == INF) continue;
      int p = (order[i].v ^ order[i].depth) & 1;
      if (parity == -1) {
        parity = p;
      } else if (parity != p) {
        return false;
      }
    }
    for (int i = N - 1; i >= 0; i--) {
      for (Node c : order[i].next) {
        if (c.id == order[i].parent) continue;
        order[i].min = Math.max(order[i].min, c.min - 1);
        order[i].max = Math.min(order[i].max, c.max + 1);
      }
      if (order[i].min > order[i].max) return false;
    }
    for (int i = 1; i < N; i++) {
      order[i].min = Math.max(order[i].min, nodes[order[i].parent].min - 1);
      order[i].max = Math.min(order[i].max, nodes[order[i].parent].max + 1);
      if (order[i].min > order[i].max) return false;
    }
    order[0].v = order[0].min;
    for (int i = 1; i < N; i++) {
      int pv = nodes[order[i].parent].v;
      if (order[i].min <= pv - 1 && pv - 1 <= order[i].max) {
        order[i].v = pv - 1;
      } else {
        order[i].v = pv + 1;
      }
    }
    return true;
  }


  static class Node {
    int id, depth, parent = INF, v = INF, min = -INF / 2, max = INF / 2;
    ArrayList<Node> next = new ArrayList<>();

    public Node(int id) {
      this.id = id;
    }
  }
}


Measured memory_bytes: 93068
from collections import deque
n,m=map(int,input().split())

q=deque([])

edge=[set([]) for _ in range(n+1)]
mark=[-1 for _ in range(n+1)]
used=[False for _ in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edge[a].add(b)
    edge[b].add(a)

q.append(1)
mark[1]=1
used[1]=True
while(len(q)>0):
    vi=q.popleft()
    ei=edge[vi]
    for eij in ei:
        if(used[eij]):
            continue
        else:
            mark[eij]=vi
            used[eij]=True
            q.append(eij)

print('Yes')
for i in range(2,len(mark)):
    print(mark[i])

Measured memory_bytes: 63312
import java.util.*;

public class Main {

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		sc.close();
		String ans[] = {"Yes", "No"};
		int an = 1;
		char st = s.charAt(0);
		for(int i = 0; i < s.length(); ++i){
			if(st != s.charAt(i))an = 0;
		}
		System.out.println(ans[an]);
	}
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define MAX 1000000007

int main(){
    long long N,K;
    cin >> N >> K;
    long long ans=0;
    for(long long i=K;i<=N+1;i++){
        ans += i*(N-i+1) + 1;
        ans %= MAX;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	static int[] parents;
	static int[] weights;
	static void set(int x) {
		parents[x] = x;
		weights[x] = 1; // initialize weights
	}
	static int find(int x) { // with path compression
		int curr = x;
		while (parents[curr] != curr) curr = parents[curr];
		return curr;
	}
	static void union(int x, int y) {
		int r1 = find(x);
		int r2 = find(y);
		if (r1 != r2) {
			if (weights[r1] > weights[r2]) {
				parents[r2] = r1;
				weights[r1] += weights[r2];
			} else {
				parents[r1] = r2;
				weights[r2] += weights[r1];
			}
			
		}
	}
	
	static boolean areConnected(int x, int y) {
		int r1 = find(x);
		int r2 = find(y);
		return (r1 == r2);
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int users = in.nextInt();
		parents = new int[users];
		weights = new int[users];
		int relations = in.nextInt();
		for (int i = 0; i < users; i++) {
			set(i);
		}
		for (int i = 0; i < relations; i++) {
			union(in.nextInt(), in.nextInt());
		}
		int checks = in.nextInt();
		for (int i = 0; i < checks; i++) {
			if (areConnected(in.nextInt(),in.nextInt())) {
				System.out.println("yes");
			} else System.out.println("no");
		}
		in.close();
	}
}



Measured memory_bytes: 100268
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define inf 1000000007

ll N;
vector<ll>A(100010);
map<ll,ll> S;

int main() {
    cin >> N;
    rep(i,N) {
        cin >> A[i];
    }
    sort(A.begin(),A.begin()+N);
    ll res = 0;
    ll active = 0;
    ll now = 0;
    while(now < N){
        ll temp = 0;
        active = now;
        while(active < N && A[active] == A[now]){
            active++;
            temp++;
        }
        if (temp%2) res++;
        now = active;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int mod=1e9+7;
const int N=2e6+5;
long long fac[N];
long long inv[N];
long long quickmod(long long a,long long b) {

    long long ans=1;
    while(b)
    {
        if(b%2==1) ans=ans*a%mod;
        a=a*a%mod;
        b=b/2;
    }
    return ans;
}
inline long long C(int n,int m) {
    return fac[n]*inv[m]%mod*inv[n-m]%mod; }

int main()
{
    int n,m;
    fac[0]=1;
    for(int i=1;i<N;i++)
        fac[i]=fac[i-1]*i%mod; inv[N-1]=quickmod(fac[N-1],mod-2);
        for(int i=N-2;i>=0;i--)
        inv[i]=inv[i+1]*(i+1)%mod;
    while(cin>>n>>m)
    {
        int a=n,b=0;
        while(2*a+b>m)
        {
            a-=2;
            b++;
        }
        if(a+b*2!=n||a*2+b!=m||a+b<=0||a<0||b<0)
        {
            printf("0\n");
            continue;
        }
        printf("%lld\n",C(a+b,a));
    }
    return 0;
}

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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)
#define allof(v) (v).begin(), (v).end()

string a, b, c;

inline bool ok() {
	return (a.back() == b[0] && b.back() == c[0]);
}

int main(void)
{
	cin >> a >> b >> c;
	cout << (ok() ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] B = new int[N];
		for (int i = 0; i < N - 1; ++i) {
			B[i] = sc.nextInt();
		}
		// B[i] >= max(A[i], A[i+1]
		// B[i-1] >= max(A[i-1], A[i])
		// min(B[i], B[i-1]) >= A[i]
		long ans = 0;
		for (int i = 0; i < N; ++i) {
			ans += Math.min((i == N - 1 ? 1L << 60 : B[i]), (i > 0 ? B[i - 1] : 1L << 60));
		}
		System.out.println(ans);
	}

	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 25044
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>

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

using namespace std;

int main()
{
    int A, B ,C;
    cin >> A >> B >> C;
    if(C >= A && C <= B) { printf("Yes\n"); }
    else { printf("No\n"); }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;

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

	string s;
	cin >> s;
	
	int n = s.length();
	for (int i = 0; i < n-1; i++) {
		if (s[i] == s[i+1]) {
			cout << (i+1) << ' ' << (i+2) << endl;
			return 0;
		}
		if (i < n-2 && s[i] == s[i+2]) {
			cout << (i+1) << ' ' << (i+3) << endl;
			return 0;
		}			
	}
	
	cout << "-1 -1\n";
}


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

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

int MOD=1e9+7;
ll INF=1e18;

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

int main(){
    int n; cin>>n;
    vector<int> x(n), a(n);
    for(int i=0; i<n; i++) cin>>x[i], a[i]=x[i];
    sort(x.begin(), x.end());
    int med1=x[n/2-1], med2=x[n/2];
    for(int i=0; i<n; i++){
        if(a[i]<=med1) cout << med2 << endl;
        else cout << med1 << endl;
    }
}

Measured memory_bytes: 3712
#include<stdio.h>

int main(void){
  int W,H,x,y,r;
  scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
  if((x-r>=0) && (x+r<=W) && (y-r>=0) && (y+r<=H)) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 584
def solve():
    # n, k = map(int, input().split())
    # h = [int(input()) for _ in range(n)]
    n, k, *h = map(int, open(0).read().split())
    h.sort()
    hk = [h[i+k-1] - h[i] for i in range(n - k + 1)]
    print(min(hk))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 20160
#include <iostream>
using namespace std;
int main(){
  int a,b;
  int sum=0;
  cin >> a >> b;
  if(max(a,b) == a)
    sum += a + max(b,a-1);
  else
    sum += b + max(a,b-1);
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256