akhauriyash/Code-Regression huggingface dataset:
using System;
using static  System.Console;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            int ACGT = 0;
            int ans = 0;
            for (int i = 0; i < s.Length; i++)
            {
                if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T')
                {
                    ACGT++;
                }
                else
                {
                    if (ACGT > ans)
                    {
                        ans = ACGT;
                        ACGT = 0;
                    }
                }
            }
            if (ACGT > ans) ans = ACGT;
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

int a[510][510];

struct Info {
	int x1, y1, x2, y2;
	Info(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

signed main() {
	int H, W;
	cin >> H >> W;

	rep(y, H) rep(x, W) cin >> a[y][x];

	vector<Info> ret;

	int x = 0;
	int y = 0;
	int dx = 1;
	while (y < H) {
		int nx = x;
		int ny = y;
		nx += dx;
		if (nx == W) {
			nx--;
			ny++;
			dx = -1;
		} else if (nx == -1) {
			nx++;
			ny++;
			dx = 1;
		}

		if (ny == H) break;

		if (a[y][x] % 2) {
			ret.push_back(Info(x + 1, y + 1, nx + 1, ny + 1));
			a[y][x]--;
			a[ny][nx]++;
		}

		x = nx;
		y = ny;
	}

	cout << ret.size() << endl;
	for (auto &i : ret) cout << i.y1 << " " << i.x1 << " " << i.y2 << " " << i.x2 << endl;
}


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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

/*
struct B {
  ll p, b;
};

B Burger(int n) {

struct Result {
  ll p, b;
};

ll rec(int n, ll x) {

}
*/

int main() {
  in(ll, n, x);
  vector<ll> p(n + 1);
  vector<ll> b(n + 1);
  p[0] = 1;
  rep(i, n) {
    p[i + 1] = p[i] * 2 + 1;
    b[i + 1] = b[i] * 2 + 2;
  }
  function<ll(ll, ll)> rec = [&p, &b, &rec](ll n, ll x) {
    if (n == 0) return 1LL;
    if (x <= 1) return 0LL;
    --x;
    ll pb = p[n - 1] + b[n - 1];
    if (x <= pb) {
      return rec(n - 1, x);
    }
    x -= pb;
    ll ps = p[n - 1];
    if (x <= 1) {
      return x + ps;
    }
    --x;
    ++ps;
    if (x <= pb) {
      return ps + rec(n - 1, x);
    }
    return ps + p[n - 1];
  };
  out(rec(n, x));
}


Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100];
    rep(i, N) cin >> A[i];
    int ans = 1000;
    int cnt = 0;
    int left = 0, right = 0;
    while(left < N) {
        right = left;
        while(right + 1 < N && A[right] < A[right + 1]) right++;
        ans += (A[right] - A[left]) * (ans / A[left]);
        //cout << left << " " << right << " " << ans << endl;
        left = right + 1;
        
    }
    cout << ans <<  endl;
    


    return 0;
}


Measured memory_bytes: 3688
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    ll n, k;
    cin >> n >> k;

    ll x = n%k;
    x = min (x, abs(x-k));

    cout << min(n, x) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

int main()
{
	std::string str;

	std::cin >> str;

	bool flag[3];

	for (int i = 0; i < 3;i++) {
		flag[i] = false;
	}

	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			if (str[i] == ('a' + j)) {
				flag[j] = true;
			}
		}
	}

	if (flag[0] && flag[1] && flag[2]) {
		std::cout << "Yes" << std::endl;
	} else {
		std::cout << "No" << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    def bfs(s,g,n):
        bfs_map = [-1 for i in range(n)]
        bfs_map[s] = 0
        q = deque()
        q.append(s)
        fin = False
        while q:
            x = q.popleft()
            for y in range(n):
                if c[x][y] > 0 and bfs_map[y] < 0:
                    bfs_map[y] = bfs_map[x]+1
                    if y == g:
                        fin = True
                        break
                    q.append(y)
            if fin:
                break

        if bfs_map[g] == -1:
            return None,0
        path = [None]*(bfs_map[g]+1)
        m = float("inf")
        path[bfs_map[g]] = g
        y = g
        for i in range(bfs_map[g])[::-1]:
            for x in range(n):
                if c[x][y] > 0 and bfs_map[x] == bfs_map[y]-1:
                    path[i] = x
                    if c[x][y] < m:
                        m = c[x][y]
                    y = x
                    break
        return path,m

    def ford_fulkerson(s,g,c,n):
        f = 0
        while 1:
            p,m = bfs(s,g,n)
            if not m:break
            f += m
            for i in range(len(p)-1):
                c[p[i]][p[i+1]] -= m
                c[p[i+1]][p[i]] += m
        return f

    n = I()
    a = LI()
    e = n+2
    ma = 10**9
    c = [[0]*e for i in range(e)]
    for i in range(n):
        d = i+1
        j = 2*d
        c[0][d] = ma
        c[d][n+1] = ma-a[i]
        while j <= n:
            c[j][d] = float("inf")
            j += d
    print(ma*n-ford_fulkerson(0,n+1,c,e))
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 42096
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

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

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

LL mod = 1000000007;

struct hoge{
  public:
  LL a, b, c, d;
  public:
  LL num;

public:
  hoge(LL a, LL b, LL c, LL d,LL num) : a(a), b(b), c(c), d(d),num(num) {}
};

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

  LL n, q, k, d;
  cin >> n >> q >> k >> d;

  k--;
  d--;

  vector<hoge> v;

  v.push_back(hoge(d, d, d, d, 1));

  FOR(i,1,q+1){
    hoge prev = v[i - 1];
    hoge nowhoge = hoge((prev.a * 2) % n, (prev.b * 2) % n, (prev.c * 2) % n, (prev.d * 2+1) % n, (prev.num * 2));

    if(nowhoge.d<nowhoge.a){
      nowhoge.d += n;
    }

    if (nowhoge.num >= n)
    {
      nowhoge.d += n;
      v.push_back(nowhoge);
      break;
    }
    v.push_back(nowhoge);
  }

  hoge last = v[v.size() - 1];

  LL now = k;

  if(last.num>=n){
    for (LL i = 0; i < q - v.size() + 1;++i)
    {
      if(now%2==0){
        cout << 0 << endl;
      }
      else
      {
        cout << 1 << endl;
      }
      now /= 2;
    }
  }

  REP(i,v.size()-1){
    hoge nowhoge = v[v.size() - i-1];
    hoge nexthoge = v[v.size() - i-2];

    bool flag = false;
    REP(j, 2)
    {
      //cout << nowhoge.a << " " << now << " " << nowhoge.d << endl;
      if (nowhoge.a <= now && now <= nowhoge.d)
      {

        bool a = now % 2 == 0;

        now = ((now - nowhoge.a) / 2 + nexthoge.a) % n;

        if(a ^ (now/(n/2)!=0))
        {
          cout << 0 << endl;
        }else{
          cout << 1 << endl;
        }

        flag = true;
        break;
      }
      now += n;
    }
    if(flag)
      continue;

    cout << -1 << endl;
    break;
  }
}



Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX_N 1005
int n,m;
char flag[MAX_N][MAX_N];
char pat[3][3];
char JOI[]="JOI";
bool check(int x,int y)
{
	if(!(x>=0&&y>=0&&x<n-1&&y<m-1))return false;
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			if(flag[x+i][y+j]!=pat[i][j])return false;
		}
	}
	return true;
}
int main()
{
	cin >> n >> m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin >> flag[i][j];
		}
	}
	for(int i=0;i<2;i++)
	{
		for(int j=0;j<2;j++)
		{
			cin >> pat[i][j];
		}
	}
	int base=0,ans;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			if(check(i,j))base++;
		}
	}
	ans=base;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			char e = flag[i][j];
			int rem=0,cnt;	
			for(int k=0;k<2;k++)
			{
				for(int l=0;l<2;l++)
				{
					if(check(i-k,j-l))rem++;
				}
			}
			for(int s=0;s<3;s++)
			{
				cnt=0;
				flag[i][j]=JOI[s];
				for(int k=0;k<2;k++)
				{
					for(int l=0;l<2;l++)
					{
						if(check(i-k,j-l))cnt++;
					}
				}
				ans=max(ans,base-rem+cnt);
			}
			flag[i][j]=e;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2148
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x,'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x,'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x,'x') # rev => int(res, 16)
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(n=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(n+1)
    is_prime[0] = is_prime[1] = False
    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] = False
    return [i for i in range(n+1) if is_prime[i]]
def prime_factor(n):
    """Return a list of prime factorization numbers of n"""
    res = []
    for i in range(2,int(n**0.5)+1):
        while n%i==0: res.append(i); n //= i
    if n != 1: res.append(n)
    return res
## const ##
MOD=10**9+7
## libs ##
import itertools as it
import functools as ft
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#
def main():
    k = II()
    s = IS()
    n = len(s)
    if n > k:
        print(s[:k]+'...')
    else:
        print(s)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9628
main :: IO ()
main = do
  ls <- getLine
  print $ solve (map read (words ls))

solve :: [Int] -> Int
solve [c1,c5,c10,c50,c100,c500]
  | c1 + 5*c5 + 10*c10 + 50*c50 + 100*c100 + 500*c500 >= 1000 = 1
  | otherwise = 0

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		int d = scan.nextInt();
		int x = a*b;
		int y = c*d;
		if(x<y) {
			System.out.println(y);
		}else {
			System.out.println(x);
		}
	}

}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
int a;
double b;
int main()
{
    cin>>a;
    for(int i=a;i>=0;i--)
    {
        b=sqrt(i);
        if(int(sqrt(i))==b)
        {
            cout<<i<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int a;
    string s;
    cin >> a >> s;
    if (a < 3200) cout << "red" << endl;
    else cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll gcd(ll a, ll b)
{
	if (a < b) return gcd(b, a);
	if (b == 0) return a;
	else return gcd(b, a % b);
}

//最大公倍数
ll lcm(ll a, ll b)
{
	return a * (b / gcd(a, b));
}

int main()
{
	ll A, B;
	cin >> A >> B;
	cout << lcm(A, B) << endl;
}


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

namespace ABC129_1
{
    class C
    {
        static void Main(string[] args)
        {
            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = a[0]; var M = a[1];
            var b = Enumerable.Repeat(0, (int)M).Select(_ => long.Parse(Console.ReadLine())).ToArray();
            var mod = 1000000007;

            var res = new long[N + 1];
            res[0] = 1;
            res[1] = 1;
            //Console.WriteLine(Array.BinarySearch(b, 1));

            for (int i = 1; i <= N; i++)
            {
                if (Array.BinarySearch(b, i) >= 0) { res[i] = 0; }
                else if (1 < i) { res[i] = res[i - 1] % mod + res[i - 2] % mod; }
            }
            Console.WriteLine(res[N] % mod);
        }
    }
}


Measured memory_bytes: 18272
// abc.cpp : Green Bin
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

	map<string,ll> m;
	for(int i=0; i<n; i++){
		string s; cin>>s;
		sort(s.begin(), s.end());
		m[s]++;
	}

	ll ans=0;
	for(auto e: m) if(e.second>1) ans += e.second * (e.second-1) / 2;
	cout<< ans <<endl;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define M 1000000007
#define pb push_back
#define ll long long int
using namespace std;

ll dp[21][1<<21];

int main()
{
	int n;
	cin>>n;
	int a[n][n];
	int i,j;
	for(i=0;i<n;i++)
	{
		for(j=0;j<n;j++)
			cin>>a[i][j];
	}
	int p = (1<<n);
	for(i=0;i<n;i++)
	{
		for(j=0;j<p;j++)
		{
			dp[i][j] = 0;
			int k1 = 0, k2 = j;
			while(k2!=0)
			{
				if(k2&1)
					k1++;
				k2 = (k2>>1);
			}
			if(k1!=i+1)
				continue;

			dp[i][j] = 0;

			k2 = 1;
			int ind = 0;
			while(k2<=j)
			{
				if((k2&j) && a[i][ind])
				{
					
					if(i==0)
						dp[i][j] = 1;
					else
						dp[i][j] += dp[i-1][j^k2];
					dp[i][j] %= M;
				}
				k2 = (k2<<1);
				ind++;
			}
		}
	}
	cout<<dp[n-1][p-1];
	return 0;

}


Measured memory_bytes: 347628
N = gets.chomp.to_i
flowers_high = gets.chomp.split(" ").map(&:to_i)

new_list = []
flowers_high.each_with_index do |num,i|
  if i == 0
    new_list << num
  else
    new_list << num - flowers_high[i-1]
  end
end


puts new_list.select{|num| num >= 0}.inject(:+)

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

string S, T;
int match_count(int offset) {
  auto len = T.length();
  int cnt = 0;
  for(int i = 0; i < len; ++i) {
    if (S[offset + i] == T[i])
      ++cnt;
  }
  return cnt;
}
int main() { 
  cin >> S >> T;
  int max = 0;
  int len_diff = S.length() - T.length() + 1;
  for (int i = 0; i < len_diff; ++i) {
    max = std::max(max, match_count(i));
  }
  cout << T.length() - max << endl;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
using namespace std; 
typedef long long int ll;  
#define mp make_pair
#define pb push_back

int main() 
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m;cin>>n>>m;
	vector < pair<ll,int> > v;	
	ll a;int b;
	for (int i = 0; i < n; i++)
	{
		cin>>a>>b; v.pb(mp(a,b));
	}
	sort(v.begin(),v.end());
	int cnt = 0;
	ll cost = 0;
	for (int i = 0; i < n; i++)
	{
		if(cnt+v[i].second <= m)
		{
			cnt+=v[i].second;
			cost+= v[i].first * v[i].second;
			if(cnt == m)return cout<<cost,0;
		}
		else //if(cnt+v[i].second > m)
		{
			cost+= (m-cnt) * v[i].first;
			return cout<<cost,0;
		}
	}
}

Measured memory_bytes: 5308
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
#include<map>

using namespace std;

#define long long long
#define ft(i , a , b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i , a , b) for (long i = (long)a ; i >= (long)b ; i--)
#define lt(i , a , b , c) for (long i = (long)a ; i <= (long)b ; i += (long)c)
#define ld(i , a , b , c) for (long i = (long)a ; i >= (long)b ; i -= (long)c)

#define X first
#define Y second

#define pb push_back
#define mp make_pair

const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;

long TestCase;
long a[mxN];

void Solve() {
    long n , k , ans = 0;
    cin >> n >> k;
    ft(i , 1 , n) cin >> a[i];
    sort(a + 1 , a + n + 1);
    ft(i , 1 , k) ans += a[i];
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
    //cin >> TestCase;
    TestCase = 1;
    while(TestCase--)
        Solve();
    return 0;
}

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

#include <atcoder/all>

using namespace std;
using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<int, int>;
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> ret;
	for (ll i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
signed main() {
	ll N; cin >> N; N *= 2;
	ll ans = INF;
	auto mp = prime_factor(N);
	vector<ll>p;
	for (auto x : mp) {
		p.push_back(pow(x.first, x.second));
	}
	int n = p.size();
	for (int bit = 0; bit < (1 << n); bit++) {
		ll a = 1, b = 1;
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				a *= p[i];
			}
			else b *= p[i];
		}
		ll x, y;
		ll g = extgcd(a, b, x, y);
		if (x > 0) {
			ll now = x / b + 1;
			x -= b * now;
			y += a * now;
		}
		else {
			ll now = (abs(x) - 1) / b;
			x += b * now;
			y -= a * now;
		}
		ans = min(ans, abs(x*a));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int ans = 0;
		for(int i = 0 ; i < n ; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans += (r - l + 1);
		}
		System.out.println(ans);
		sc.close();

	}

}


Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int main(){
	int i,j,k,n,sum=0;
	cin>>n>>k;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	for(i=1;i<=n;i++){
		sum+=min(abs(0-a[i]),abs(k-a[i]))*2;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <deque>

using namespace std;
const long long P = 1000000007;

int main() {
  int a[5];
  int add = 0,sum = 0;
  int addmax = 0;
  for(int i = 0; i < 5; i++) {
    cin >> a[i];
    sum += a[i];
    if(a[i] % 10 != 0) {
      add += 10 - (a[i] % 10);
      addmax = max(addmax,10 - (a[i] % 10));
    }
  }
  cout << sum+add-addmax << endl;
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kishan Sairam Adapa
 */

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define ll long long int
#define MOD ((int)(1e9) + 7)

using namespace std;

class CCountOrder {
public:
    array<bool, 9> done;
    array<int, 9> curr;
    int cnt = 0;
    int ps=-1, qs=-1;
    array<int, 9> p, q;
    int n;
    void nextPerm(int id) {
        if(id == n) {
            cnt++;
            int i;
            for(i=0; i<n; i++) {
                if(p[i] != curr[i]) break;
            }
            if(i == n) ps = cnt;
            for(i=0; i<n; i++) {
                if(q[i] != curr[i]) break;
            }
            if(i == n) qs = cnt;
        } else {
            for(int i=1; i<=n; i++) {
                if(!done[i]) {
                    done[i] = true;
                    curr[id] = i;
                    nextPerm(id+1);
                    done[i] = false;
                }
            }
        }
    }
    void solve(istream& cin, ostream& cout) {
        for(int i=0; i<9; i++) {
            done[i] = false;
        }
        cin >> n;
        for(int i=0; i<n; i++) {
            int tp;
            cin >> tp;
            p[i] = tp;
        }
        for(int i=0; i<n; i++) {
            int tp;
            cin >> tp;
            q[i] = tp;
        }
        nextPerm(0);
        cout << abs(ps - qs) << '\n';
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    CCountOrder solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define BUGO(x) cerr << #x << " = " << (x) << '\n';
#define BUGOARR(a) cerr << #a << ": "; for (auto i: a) cerr << i << ' '; cerr << '\n';
#ifndef MANSON
#define BUGO(x)
#define BUGOARR(x)
#endif

vector<int> nei[200'005];

void DFS(int v, int par, int dep, vector<int>& a, vector<int>& b)
{
    if (dep % 2) a.push_back(v);
    else b.push_back(v);
    for (int to: nei[v])
        if (to != par)
            DFS(to, v, dep + 1, a, b);
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for (int i = 1; i < n; ++i)
    {
        int u, v;
        cin >> u >> v;
        nei[u].push_back(v);
        nei[v].push_back(u);
    }
    vector<int> a, b;
    DFS(1, -1, 0, a, b);
    vector<int> q[3];
    for (int i = 1; i <= n; ++i)
        q[i % 3].push_back(i);
    vector<int> ans(n + 1, -1);
    if (a.size() > b.size())
        a.swap(b);
    if (q[0].size() >= a.size())
    {
        for (int i: a)
            if (q[0].size()) {
                ans[i] = q[0].back();
                q[0].pop_back();
            }
        q[0].insert(q[0].end(), q[1].begin(), q[1].end());
        q[0].insert(q[0].end(), q[2].begin(), q[2].end());
        for (int i = 1; i <= n; ++i)
            if (ans[i] == -1) {
                ans[i] = q[0].back();
                q[0].pop_back();
            }
    }
    else
    {
        for (int i: a)
            if (q[1].size()) {
                ans[i] = q[1].back();
                q[1].pop_back();
            }
        for (int i: b)
            if (q[2].size()) {
                ans[i] = q[2].back();
                q[2].pop_back();
            }
        for (int i = 1; i <= n; ++i)
            if (ans[i] == -1) {
                ans[i] = q[0].back();
                q[0].pop_back();
            }
    }
    for (int i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
}


Measured memory_bytes: 26680
n = int(input())
s = input()
t = input()
mod = 10**9+7
if s[0]==t[0]:
  cou = 3
  start = 1
else:
  cou = 6
  start = 2
second = False
for i in range(start,n):
  if second:
    second = False
    continue
  else:
    if s[i]==t[i]:
      if s[i-1]==t[i-1]:
        cou *= 2
        cou %= mod
        
    else:
      if s[i-1]==t[i-1]:
        cou *= 2
        cou %= mod
        second = True
      else:
        cou *= 3
        cou %= mod
        second = True
        
 # print(i,cou)
print(cou)

Measured memory_bytes: 9148
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>

using namespace std;

#define C_MAX(a, b) ((a)>(b)?(a):(b))
#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    int N;
    cin >> N;

    vector<long long> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    bitset<40> B(0);
    long long sum = 0;
    long long ans = 0;

    int right = 0;
    for (int left = 0; left < N; left++) {
        if (right <= left) right = left;
        while (right < N && ((B ^ bitset<40>(A[right])) == (sum + A[right]))) {
            sum += A[right];
            B ^= bitset<40>(A[right]);
            right++;
        }
        ans += (right - left);
        sum -= A[left];
        B ^= A[left];
    }

    cout << ans << endl;

    return 0;
}














































Measured memory_bytes: 1792
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include<time.h>
using namespace std;
typedef long long int llint;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long& x, long long& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int h, w;
	cin >> h >> w;
	vector<string>str(h);
	rep(i, h) {
		cin >> str[i];
	}
	queue<pint>que;
	int cnt = 0;
	rep(i, h) {
		rep(j, w) {
			if (str[i][j] == '#') {
				que.push(make_pair(i, j));
				cnt++;
			}
		}
	}
	int ans = 0;
	int x[4] = { -1,1,0,0 }, y[4] = { 0,0,-1,1 };
	while (cnt < h * w) {
		int tmp = que.size();
		rep(i, tmp) {
			pint now = que.front();
			que.pop();
			rep(j, 4) {
				if (now.first + x[j] < 0 || h - 1 < now.first + x[j] ||
					now.second + y[j] < 0 || w - 1 < now.second + y[j]) {
					continue;
				}
				if (str[now.first + x[j]][now.second + y[j]] == '.') {
					str[now.first + x[j]][now.second + y[j]] = '#';
					cnt++;
					que.push(make_pair(now.first + x[j], now.second + y[j]));
				}
			}
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 9488
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int main(){
    double A,B,H,M;
    cin>>A>>B>>H>>M;
    double choshin=30*H+(double)M*30.0/60.0;
    double tanshin=M*6;
    double nasukaku=abs(tanshin-choshin);
    double PI=acos(-1);
    double res2=A*A+B*B-2*A*B*cos(nasukaku/360.0*2.0*PI);
    cout<<fixed<<setprecision(20)<<sqrt(res2)<<endl;
    return 0;
}

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

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

   int a,b,c,k;
   cin>>a>>b>>c>>k;
   int ans=0;
   for(int i=1;i<=k;i++)
   {
       if(i<=a)
        ans++;
       else if(i<=a+b);
       else if(i<=a+b+c)
        ans--;
   }
   cout<<ans;
}


Measured memory_bytes: 3572
#include<stdio.h>
int main(){
      int a,b,result,Surroundings,square;
      scanf("%d%d",&a, &b);
      //scanf("%d",&b);
      square=a*b;
      Surroundings=a*2+b*2;
	printf("%d ",square);
	printf("%d\n",Surroundings);
	return 0;
}

Measured memory_bytes: 596
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        abc: [[i64; 3]; n]
    }

    let mut dp = vec![vec![0; 3]; n];
    dp[0] = abc[0].clone();
    for i in 1..n {
        for act in 0..3 {
            let act2 = (act + 1) % 3;
            let act3 = (act + 2) % 3;
            dp[i][act] = max(dp[i-1][act2], dp[i-1][act3]) + abc[i][act]; 
        }
    }
    let ans = dp[n-1].iter().max().unwrap();
    println!("{}", ans);
}


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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define endl "\n"

ll h[100005];
ll mini[100005];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	ll N;
	cin >> N;

	for(ll i=0; i<N; i++)
	{
		cin >> h[i];
	}

	mini[0] = h[0];
	mini[1] = abs(h[1]-h[0]);
	mini[2] = min(mini[1]+abs(h[2]-h[1]), abs(h[2]-h[0]));

	for(ll j=3; j<N; j++)
	{
		mini[j] = min(mini[j-1]+abs(h[j]-h[j-1]), mini[j-2]+abs(h[j]-h[j-2]));
	}

	cout << mini[N-1] << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main (void) {
    int N;
    string S;

    cin >> N;
    cin >> S;

    int ans = 0;
    for (int i = 1; i < N; i++) {
        string X = S.substr(0, i);
        string Y = S.substr(i, N - i);
        int xInclude[26] = {0};
        int yInclude[26] = {0};
        for (int j = 0, len = X.length(); j < len; j++) {
            xInclude[X[j] - 'a']++;
        }
        for (int j = 0, len = Y.length(); j < len; j++) {
            yInclude[Y[j] - 'a']++;
        }
        int cnt = 0;
        for (int j = 0; j < 26; j++) {
            if (xInclude[j] && yInclude[j]) {
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
# 参考 https://atcoder.jp/contests/abc140/submissions/7411285
import sys
input = sys.stdin.readline

def main():
    n = int(input()[:-1])
    aa = list(map(int, input().split()))
    ans = 0
    pos = [0] * (n + 1)
    for i, a in enumerate(aa):
        pos[a] = i + 2
    Lnext = [1, 1] + list(range(1, n + 1)) + [n, n]
    Rnext = [3, 3] + list(range(3, n + 3)) + [n + 2, n + 2]
    for a in range(1,n + 1):
        i = pos[a]
        l0 = Lnext[i]
        l1 = Lnext[l0]
        r0 = Rnext[i]
        r1 = Rnext[r0]
        ans += a * ((l0 - l1) * (r0 - i) + (i - l0) * (r1 - r0))
        Lnext[r0] = l0
        Rnext[l0] = r0
    print(ans)

main()


Measured memory_bytes: 19544
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    
    long long int mini = min(k, x/d);
    k -= mini;
    x -= mini * (d);
    
    if(k%2 == 0){
        cout << x << endl;
    }
    else{
        cout << d-x << endl;
    }
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int a, d, n;
		
		boolean primes[] = new boolean[1000000];
		primes[0] = primes[1] = true;
		for(int i = 2; i * i < 1000000; i++){
			for(int j = 2; j * i < 1000000; j++){
				primes[i * j] = true;
			}
		}
		
		while(!(string = reader.readLine()).equals("0 0 0")){
			a = Integer.valueOf(string.split(" ")[0]);
			d = Integer.valueOf(string.split(" ")[1]);
			n = Integer.valueOf(string.split(" ")[2]);
			
			for(; n != 0; a += d){
				if(!primes[a]) --n;
			}
			System.out.println(a - d);
		}
		reader.close();
	}
}

Measured memory_bytes: 27956
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int h,w,m; cin >> h >> w >> m;
  vector<pair<int,int>> p(m);
  rep(i,m) {
    cin >> p[i].first >> p[i].second;
    p[i].first--, p[i].second--;
  }

  set<pair<int,int>> exists;
  rep(i,m) exists.emplace(p[i].first, p[i].second);

  vector<int> yoko(h), tate(w);
  rep(i,m) {
    yoko[p[i].first]++;
    tate[p[i].second]++;
  }

  //map<int,int> yyy;
  //rep(i, h) if(yoko[i]!=0) yyy[yoko[i]] = i;

  //map<int,int> ttt;
  //rep(i, w) if(tate[i]!=0) ttt[tate[i]] = i;

  vector<pair<int,int>> tt;
  rep(i, w) if(tate[i]!=0) tt.emplace_back(tate[i], i);
  sort(ALL(tt), greater<pair<int,int>>());

  //cerr << "====" << endl;
  //for(auto i : tt) cerr << i.first << " " << i.second << endl;;
  //cerr << "====" << endl;

  ll ans = 0;
  rep(i, h) {
    ll s = yoko[i];
    for(auto r:tt) {
      if(exists.count({i, r.second})) {
        umax(ans, s + r.first - 1);
      }
      else {
        umax(ans, s + r.first);
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using datas=pair<ll,ll>;
using tdata=pair<datas,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll modncrlistp[200000],modncrlistm[200000];

ll modncrs(ll n,ll r){
  ll i,j;
  if(modncrlistp[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistp[i])break;
    }
    if(i<0){
      modncrlistp[0]=1;
      rep1(i,n+1){
        modncrlistp[i]=(modncrlistp[i-1]*i)%mod;
      }
    }else{
      For(j,i+1,n+1){
        modncrlistp[j]=(modncrlistp[j-1]*j)%mod;
      }
    }
  }
  if(modncrlistm[n]==0){
    for(i=n;i>=0;i--){
      if(modncrlistm[i])break;
    }
    if(i<0){
      modncrlistm[0]=1;
      rep1(i,n+1){
        modncrlistm[i]=(modncrlistm[i-1]*modinv(i))%mod;
      }
    }else{
      For(j,i+1,n+1)modncrlistm[j]=(modncrlistm[j-1]*modinv(j))%mod;
    }
  }
  return (((modncrlistp[n]*modncrlistm[r])%mod)*modncrlistm[n-r])%mod;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

int main(){
  ll i,N,ans=0;
  cin>>N;
  vec b(N,LLONG_MAX),a(N);
  rep1(i,N){
    cin>>b[i];
  }
  rep1(i,N){
    a[i]=b[i];
    if(b[i]<b[i-1]){
      a[i-1]=b[i];
    }
  }
  rep(i,N){
    ans+=a[i];
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#define ll long long
using namespace std;
const int INF =1001001001;
vector<int> x[100005];
int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--;b--;
        x[a].push_back(b);
        x[b].push_back(a);
    }

    queue<ll> q;
    vector<int>dist(n,INF);
    vector<int> pre(n,-1);
    dist[0]=0;
    q.push(0);
    while(!q.empty()){
        int v=q.front();q.pop();
        for(int u:x[v]){
            if(dist[u]!=INF) continue;
            dist[u]=dist[v]+1;
            pre[u]=v;
            q.push(u);
        }
    }
    cout<<"Yes"<<endl;
    for(int i=0;i<n;i++){
        if(i==0) continue;
        int ans=pre[i];
        ++ans;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 10844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

int main(){
	int n;
	ll h[100000];
	cin >> n;
	for(int i=0;i<n;i++) cin >> h[i];

	for(int i=n-1;i>0;i--){
		if(h[i-1]>h[i]+1){
			cout<<"No"<<endl;
			return 0;
		}else{
			if(h[i-1]==h[i]+1){
				h[i-1]--;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define LL long long
#define Fi first
#define Se second
using namespace std;
static const LL INF = 1LL<<61LL;
typedef pair<int,int> PII;

int N,D;
int Z[1010],O[1010];
string X;

int main(){
    memset(Z,-1,sizeof(Z));
    memset(Z,-1,sizeof(Z));
    cin>>N;
    cin>>X;
    cin>>D;
    int temp=0;
    int cnt=1;
    int t=0;
    int k=0;
    rep(i,X.size()){
        if(X[i]=='0'){
            temp++;
            Z[t]=i;
            t++;
        }
        else{
            O[k]=i;
            k++;
        }

    }
    if(temp>=D){
        rep(i,X.size()){
            if(cnt<=D){
                if(X[i]!='1'){
                    cout<<1;
                    cnt++;
                }
                else cout<<X[i];
            }
            else cout<<X[i];
        }
    }
    else {
        int l=k-1;
        //cout<<O[l]<<endl;
        rep(i,D){
            //cout<<Z[i]<<" "<<O[l]<<endl;
            if(Z[i]!=-1)X[Z[i]]='1';
            else {
                if(O[l]!=-1)X[O[l]]='0';
                l--;
            }
        }
        cout<<X;
    }
    cout<<endl;
}

Measured memory_bytes: 1212
import sys
input = sys.stdin.readline
from collections import defaultdict


class PrimeFactor():

    def __init__(self, n):                  # エラトステネス　O(N loglog N)
        self.n = n
        self.table = list(range(n+1))
        self.table[2::2] = [2]*(n//2)
        for p in range(3, int(n**0.5) + 2, 2):
            if self.table[p] == p:
                for q in range(p * p, n + 1, 2 * p):
                    if self.table[q] == q:
                        self.table[q] = p

    def is_prime(self, x):  # 素数判定　O(1)
        if x < 2:
            return False
        return self.table[x] == x

    def prime_factors(self, x):             # 素因数分解 O(logN)
        res = []
        if x < 2:
            return res
        while self.table[x] != 1:
            res.append(self.table[x])
            x //= self.table[x]
        return res

    def prime_counter(self, x):             # 素因数分解（個数のリスト）
        res = defaultdict(int)
        if x < 2:
            return res
        while self.table[x] != 1:
            res[self.table[x]] += 1
            x //= self.table[x]
        return res

    def prime_gcd(self, X):                 # n個の最大公約数　X:n個のリスト
        exponents = self.prime_counter(X[0])
        for x in X[1:]:
            Y = self.prime_counter(x)
            for prime, exp in exponents.items():
                if Y[prime] < exp:
                    exponents[prime] = Y[prime]
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp)
        return res

    def prime_lcm(self, X, mod=None):       # n個の最小公倍数　X:n個のリスト
        exponents = defaultdict(int)
        for x in X:
            for prime, exp in self.prime_counter(x).items():
                if exp > exponents[prime]:
                    exponents[prime] = exp
        res = 1
        for prime, exp in exponents.items():
            res *= pow(prime, exp, mod)
        if mod == None:
            return res
        else:
            return res % mod

mod = 10 ** 9 + 7

N = int(input())
A = list(map(int, input().split()))
A.sort()
table = PrimeFactor(10**6)
num = table.prime_lcm(A,mod)

res = 0
for a in A:
    res += num * pow(a, mod - 2, mod)

print(res % mod)


Measured memory_bytes: 81552
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define compress(v) sort(all(v)), v.erase(unique(all(v)), v.end())
using namespace std;

typedef long long ll;

int n; ll ans;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    cin >> n;
    for(int i=1; i<=n; i++){
        ll t = n / i;
        ans += i * t * (t+1) / 2;
    }
    cout << ans;
}

Measured memory_bytes: 3604
#include <iostream>
using namespace std;
int main(void){
    int n,ch1=0,ch2=0;
    cin>>n;
    int ans=0;
    char stand='n';
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(stand=='n'){
            if(ch1==0)ch1=a;
            else if(ch1!=a&&ch2==0){
                ch2=a;
                if(ch1>ch2)stand='d';
                if(ch1<ch2)stand='u';
            }
            
            
        }
        else{
            if(stand=='d'){
                if(ch2<a){
                    ans++;
                    stand='n';
                    ch1=a,ch2=0;
                }
                else ch2=a;
            }
            
            if(stand=='u'){
                if(ch2>a){
                    ans++;
                    stand='n';
                    ch1=a,ch2=0;
                }
                else ch2=a;
            }
        }
    }
    cout<<ans+1<<endl;
}


Measured memory_bytes: 256