akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set1;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,m,t;
	cin>>n>>m>>t;
	ll arr1[n],arr2[m];
	REP(i,0,n) cin>>arr1[i];
	REP(i,0,m) cin>>arr2[i];
	
	ll pref1[n+1] = {0},pref2[m+1] = {0};
	REP(i,1,n+1){
		pref1[i] = arr1[i-1];
		pref1[i] += pref1[i-1];
	}
	REP(i,1,m+1){
		pref2[i] = arr2[i-1];
		pref2[i] += pref2[i-1];
	}

	ll ct = 0;
	REP(i,0,n+1){
		ll curr = t - pref1[i];
		if(curr >= 0){
			ll p = upper_bound(pref2,pref2+m+1,curr) - pref2;
			ct = max(ct,p+i - 1);
		}
	}
	cout<<ct<<endl;
	return 0;
}

Measured memory_bytes: 9884
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr, tails)
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn :: IO Int
  d <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ sum [ x * y | x:xs <- tails d, y <- xs ]


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

int main(){

    int N;
    cin>>N;
    int all=1,bad=1;
    for(int i=0;i<N;i++){
        int a;
        cin>>a;
        if(a%2==0) bad*=2;
        all*=3;
    }
    cout<<all-bad<<endl;
}


Measured memory_bytes: 256
import itertools
n = int(input())
a = tuple(input().split())
b = tuple(input().split())

num = list(str(i) for i in range(1,n+1))
iters = list(itertools.permutations(num))

for i in range(len(iters)):
  if a == iters[i]:
    A = i
  elif b == iters[i]:
    B = i

if a == b:
  print(0)
else:
  print(abs(A-B))

Measured memory_bytes: 8052
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <cstring>
#include <queue>
#include<iomanip>
#include <numeric>

using namespace std;

//#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

typedef long long ll;

//static const ll MOD = 1000000007;

int main() {
    ll N;
    vector<ll> H;
    ll answer = 0;

    // input
    cin >> N;
    for (ll i = 0; i < N; i++) {
        ll h;
        cin >> h;
        H.emplace_back(h);
    }

    // process
    ll max = 0;
    for (ll i = 0; i < N - 1; i++) {
        if (H[i] >= H[i + 1]) {
            max++;
        } else {
            if (max > answer) {
                answer = max;
            }
            max = 0;
        }
    }

    if (max > answer) {
        answer = max;
    }

    cout << answer << endl;

    return 0;
}

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

int main()
{
  int64_t N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
  }
  int64_t GCD = __gcd(A[0], A[1]);
  for (int i = 0; i < N; i++)
  {
    GCD = __gcd(GCD, A[i]);
  }
  cout << GCD << endl;
}


Measured memory_bytes: 4052
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Vishal Burman
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AMultiplication1 solver = new AMultiplication1();
        solver.solve(1, in, out);
        out.close();
    }

    static class AMultiplication1 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            out.println(a * b);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



Measured memory_bytes: 32316
H, W = map(int, input().split())

S = []
for _ in range(H):
    hw = list(input())
    S.append(hw)

for i in range(H):
    for j in range(W):

        if S[i][j] == '.':
            continue

        # 上
        if i != 0 and S[i-1][j] == '#':
            continue
        # 下
        elif i != H-1 and S[i+1][j] == '#':
            continue
        # 左
        elif j != 0 and S[i][j-1] == '#':
            continue
        # 右
        elif j != W-1 and S[i][j+1] == '#':
            continue

        print('No')
        exit(0)
print('Yes')


Measured memory_bytes: 3064
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int z, k = 0,t=0,sum=0;
	char a[1000000];
	gets(a);
	z = strlen(a);
	//puts(a);
	//prlong long intf("%d\n", k );
	for (long long int i = 0; i < z; ++i)
	{
		k = a[i] + '0';
		t=k-96;
		//prlong long intf("%d\n",t );
		sum=sum+t;
		//prlong long intf("%d\n",sum );
	}
	if(sum%9==0)
		printf("Yes\n");
	else
		printf("No\n");






}

Measured memory_bytes: 1660
# -*- coding: utf-8 -*-
# スペース区切りの整数の入力
a = int(input())


ans = "No"
for i in range(a//4 + 1):
    for j in range(a//7 + 1):
        if i*4 + j*7 == a:
            ans = "Yes"
            break
    else:
        continue
    break

# 出力
print(ans)

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    char med = s[n / 2];
    int ans = 0;
    if(n % 2){
        for(int i = 0; i <= n / 2; i++){
            if(s[n / 2 + i] == med && s[n / 2 - i] == med) ans++;
            else break;
        }
    }
    else{
        for(int i = 0; i < n / 2; i++){
            if(s[n / 2 + i] == med && s[n / 2 - 1 - i] == med) ans++;
            else break;
        }
    }
    cout << n / 2 + ans << endl;
}

Measured memory_bytes: 512
#pragma GCC target (*sse4.2*)
#pragma GCC optimization ("O3")
#pragma GCC optimize ("Ofast")
#define mod 1000000007
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) int x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define S second
#define debug(x) cout<<("#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define INF 1<<10

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double d64;

int main(){
fast
read(n);read(k);
vector<int>num(n);
for(int i=0;i<n;i++){
    cin>>num[i];
}
sort(all(num));
int sum=0;
for(int i=0;i<k;i++){
    sum+=num[i];
}
cout<<sum;
return 0;
}


Measured memory_bytes: 3668
import sys


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def f(a, b):
    la = len(str(a))
    lb = len(str(b))
    return max(la, lb)


N = ii()
m = float("inf")
for n in range(1, int(N ** (1 / 2)) + 1):
    if N % n == 0:
        m = min(m, f(n, N // n))
print(m)


Measured memory_bytes: 3188
from fractions import gcd
 
n = int(input())
aaa = list(map(int, input().split()))
ans = aaa[0]
for a in aaa[1:]:
    ans = gcd(ans, a)
print(ans)
'''
最大公約数。
2匹の状態を考える。A1=22,A2=14とする。
常にHPの低い方を、高い方に攻撃させる。
phase  A1  A2
    1  22←14
    2   8→14
    3   8← 6
    4   2→ 6
    5   2→ 4
    6   2→ 2
    7   2   0    Ans:2
このプロセスは、2数の最大公約数を求めるユークリッドの互除法と
同じ操作になる。残る1匹のモンスターのHPは2数の最大公約数となる。
逆に、この2数同士の引き算だけで、最大公約数以下の値は作れない。
（最大公約数gの倍数同士の引き算では、gの倍数しか作れない）
最大公約数は必ず作れる＆最大公約数未満は作れない→答えは最大公約数。
3匹以上の場合も同じことが言える。 
N個の数の最大公約数は、3匹目は1匹目と2匹目で生き残った方、
4匹目はさらにそこで生き残った方…と闘わせれば作れる。
逆にこれらの数の引き算では最大公約数の倍数しか作れない。
'''

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

using namespace std;

typedef long long int ll;
const int maxn = 100100;

const int p = 1e9 + 7;
inline int add(const int a, const int b)
{
  ll z = 0ll + a + b;
  if (z >= p) z -= p;
  return z;
  return (0ll + a + b) % p;
}
inline int mul(const int a, const int b)
{
  ll z = 1ll * a * b;
  z -= z / p * p;
  return z;
  return (1ll * a * b) % p;
}

struct jsum
{
  int s[maxn];
  int qow(int a, int x)
  {
    int ret = 1;
    while (x)
    {
      if (1 & x) ret = mul(ret, a);
      a = mul(a, a);
      x >>= 1;
    }
    return ret;
  }
  jsum(void)
  {
    s[0] = 0;
    for (int i = 1; i < maxn; i++)
    {
      int d = qow(i, p - 2);
      s[i] = add(s[i - 1], d);
    }
  }
  int operator[](const unsigned pos) const { return s[pos]; }
}S;
struct fact
{
  int f[maxn];
  fact(void)
  {
    f[0] = 1;
    for (int i = 1; i < maxn; i++)
    {
      f[i] = mul(f[i - 1], i);
    }
  }
  int operator[](const unsigned pos) const { return f[pos]; }
}f;

int main(void)
{
  int N;
  int ans = 0;
  scanf("%d", &N);
  for (int i = 1; i <= N; i++)
  {
    int Ai;
    scanf("%d", &Ai);
    int d = add(add(S[i], S[N - i + 1]), p - 1);
    ans = add(ans, mul(Ai, d));
  }
  printf("%d\n", mul(ans, f[N]));
  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        String in1 = scan.next();
        String in2 = scan.next();
        int n = in1.length();
        int m = in2.length();
        char[] s = new char[n];
        char[] t = new char[m];
        for(int i = 0; i < n; i++) s[i] = in1.charAt(i);
        for(int i = 0; i < m; i++) t[i] = in2.charAt(i);
        int[][] dp = new int[n + 1][m + 1];
        for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                if(s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
                else dp[i + 1][j + 1] = Math.max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
        int l = dp[n][m];
        char[] out = new char[l];
        l--;
        while(l >= 0){
            if(s[n - 1] == t[m - 1]){
                out[l] = s[n - 1];
                n--;
                m--;
                l--;
            }else if(dp[n][m] == dp[n - 1][m]){
                n--;
            }else{
                m--;
            }
        }
        for(int i = 0; i < out.length; i++) System.out.print(out[i]);
        scan.close();
    }

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


Measured memory_bytes: 87244
integer(16) N
integer(16),allocatable,dimension(:)::A
integer(16) i,T,Y,Tkouho,Ykouho
read*,N
allocate(A(N))
read*,A
call heapsort(N,A)
T=0;Y=0;Tkouho=0;Ykouho=0
do i=N,1,-1
  if(Tkouho==A(i).and.T==0)then
    T=A(i)
    Tkouho=0
  else if(Tkouho/=A(i).and.T==0)then
    Tkouho=A(i)
  else if(Ykouho/=A(i).and.Y==0)then
    Ykouho=A(i)
  else if(Ykouho==A(i).and.Y==0)then
    Y=A(i)
  else
    exit
  endif
end do
print"(i0)",Y*T
contains
subroutine heapsort(n,array)
  implicit none
!ここの入力は状況に応じて変更すること
  integer(16),intent(in) :: n
  integer(16),intent(inout) :: array(1:n)
  integer(16)::i,k,j,l
  integer(16):: t

  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j<=k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
  return
end subroutine heapsort
end

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

ll K,N;
ll A[200000];

int main(){
    cin>>K>>N;
    rep(i,N) cin>>A[i];

    sort(A,A+N);

    ll max_d=K-A[N-1]+A[0];
    for(int i=0;i<N;i++){
        max_d=max(max_d,A[i+1]-A[i]);
    }

    ll ans=K-max_d;

    cout<<ans<<endl;
}

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

long long calc (int n, long long* a, bool isPositive) {
    long long nCount = 0, sum = 0;

    for (int i=0; i<n; ++i) {
        if (isPositive) {
            if ((a[i] + sum) < 0) {
                sum += a[i];
            } else {
                nCount +=  abs(a[i] + sum) + 1;
                sum = -1;
            }
            isPositive = !isPositive;
        } else {
            if ((a[i] + sum) > 0) {
                sum += a[i];
            } else {
                nCount += abs(a[i] + sum) + 1;
                sum = 1;
            }
            isPositive = !isPositive;
        }
    }
    return nCount;
}

int main() {
    int n;
    long long a[100005];

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

    bool isPositive;
    long long nCount[2];

    isPositive = true;
    nCount[0] = calc(n, a, isPositive);

    isPositive = false;
    nCount[1] = calc(n, a, isPositive);

    cout << min(nCount[0], nCount[1]);
    
}


Measured memory_bytes: 1024
#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>

// output
#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
// utility
#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 T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#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; 
  cin >> N;

  string s;
  cin >> s; cin >> s;

  vector<int> v;
  REP(i, N){
    if(i == N-1) v.emplace_back(1);
    else if(s[i] == s[i+1]) v.emplace_back(2), i++;
    else v.emplace_back(1);
  }

  N = v.size();

  int ans = 1;
  if(v[0] == 2) ans = 6;
  else ans = 3;

  FOR(i, 1, N){
    if(v[i-1]*v[i] == 1){
      ans *= 2;
    }else if(v[i-1]*v[i] == 4){
      ans *= 3;
    }else if(v[i-1] == 1){
      ans *= 2;
    }
    ans %= MOD;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<map>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;

void solver() {

    string s;
    cin>>s;
    int n=s.length();
    int my=n-1;
    int total=1<<my;
    long long ans=0;
    long long value=0;
    for(int i=0;i<total;i++)
    {

        for(int j=0;j<n-1;j++)
        {
            value=value*10;
            value+=s[j]-'0';
            if((i & 1<<j)!=0)
            {
                ans+=value;
                value=0;
            }
        }
        value=value*10;
        value+=s[n-1]-'0';
        ans+=value;
        value=0;

    }
    cout<<ans;







}

int main() {
    int n=1;
    //cin >> n;
    while (n--) {
        solver();
    }
}


Measured memory_bytes: 3148
#include <iomanip>
#include <random>
#include <time.h>
#include <vector>
#include <queue>
#include <functional>
#include <map>
#include <string>
#include <cstdlib>
#include <typeinfo>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <list>
#include <stack>
#include <set>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a[200020], ans[200020];
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (n % 2) {
			if (i == 1)ans[n / 2 + 1] = a[1];
			else if (i % 2)ans[n / 2 - i / 2 + 1] = a[i];
			else ans[n / 2 + 1 + i / 2] = a[i];
		}
		else {
			if (i % 2)ans[(i + 1) / 2 + n / 2] = a[i];
			else ans[n / 2 - i / 2 + 1] = a[i];
		}
	}
	for (int i = 1; i <= n; i++) {
		if (i != n)cout << ans[i] << " ";
		else cout << ans[i] << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    vector<vector<char>> vec(n + 1, vector<char>(n + 1));
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= n; ++j)
        cin >> vec[i][j];

    vector<vector<int>> vec2(n + 1, vector<int>(n + 1, 0));
    //for (int i = 0; i <= n; ++i)
    //  vec2[i][0] = vec2[0][i] = 0;

    int vmax = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        int vmin = min({vec2[i-1][j], vec2[i-1][j-1], vec2[i][j-1]});
        vec2[i][j] = (vec[i][j] == '*') ? 0 : vmin + 1;
        if (vmax < vec2[i][j])
          vmax = vec2[i][j];
      }
    }
    cout << vmax << endl;
  }
}


Measured memory_bytes: 7864
n = int(input())
G = [[] for i in range(n)]
for ni in range(n):
    u, k, *tmp = [int(i) for i in input().split()]
    for ki in range(k):
        G[ni].append(tmp[:2])
        del tmp[:2]

INF = 100*100000
D = [INF for i in range(n)]
D[0] = 0
C = [0 for i in range(n)]
while 0 in C:
    U = [INF if C[i] == 1 else D[i] for i in range(n)]
    u = U.index(min(U))

    for i in range(len(G[u])):
        v = G[u][i][0]
        if D[u] + G[u][i][1] < D[v]:
            D[v] = D[u] + G[u][i][1]
    C[u] = 1

for ni in range(n):
    print(ni, D[ni])


Measured memory_bytes: 6132
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a);i<=(b);i++)
#define ROF(i,a,b) for(int i = (a);i>=(b);i--)
#define MST(a,x) memset(a,x,sizeof(a))
#define ll long long
#define PB push_back
#define PH push
#define MP make_pair
#define FT first
#define SD second
#define N 105
#define M 51
#define INF 500
#define MOD 924844033
#define MOD2 1000000009
#define eps 1e-14
using namespace std;
inline int Max(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^b;
}
inline int Min(int a,int b)
{
    return (((b-a)>>(32-1))&(a^b))^a;
}

int n;

void solve() {
	int i,j,k,l,r,x,y; string s;

	cin>>n;
	ll ret=0;
	int pre=0;

	FOR(i,1,n) {
		cin>>x;
		if(pre==0) {
			ret += x-1;
			pre=1;
		}
		else if(x==pre+1) {
			pre++;
		}
		else if(x>pre+1) {
			ret += (x-1)/(pre+1);
		}
	}
	cout<<ret<<endl;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc129d()
}

fun abc129d() {
    val (h, w) = readLine()!!.split(' ').map { it.toInt() }
    val wall = (1..h).map { readLine()!!.map { it == '#' }.toBooleanArray() }

    // down,up,right,left
    val cSumD = Array(h) { IntArray(w) { 0 } }
    val cSumU = Array(h) { IntArray(w) { 0 } }
    val cSumR = Array(h) { IntArray(w) { 0 } }
    val cSumL = Array(h) { IntArray(w) { 0 } }

    for (x in 0 until w) {
        for (y in 0 until h) {
            cSumD[y][x] = if (wall[y][x]) 0 else if (y == 0) 1 else cSumD[y - 1][x] + 1
            cSumR[y][x] = if (wall[y][x]) 0 else if (x == 0) 1 else cSumR[y][x - 1] + 1
        }
    }
    for (x in w - 1 downTo 0) {
        for (y in h - 1 downTo 0) {
            cSumU[y][x] = if (wall[y][x]) 0 else if (y == h - 1) 1 else cSumU[y + 1][x] + 1
            cSumL[y][x] = if (wall[y][x]) 0 else if (x == w - 1) 1 else cSumL[y][x + 1] + 1
        }
    }

    var answer = 0
    for (y in 0 until h) {
        for (x in 0 until w) {
            answer = Math.max(answer, cSumD[y][x] + cSumU[y][x] + cSumR[y][x] + cSumL[y][x] - 3)
        }
    }
    println(answer)
}


Measured memory_bytes: 136636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    for(int i = 0; i < N; i++) {
        int A, B;
        cin >> A >> B;
        v[i] = {B, A};
    }
    sort(v.begin(), v.end());
    int time = 0;
    for(int i = 0; i < N; i++) {
        time += v[i].second;
        if(time > v[i].first) {
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
    return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;
  int s0 = S.size(), t0 = T.size();
  vector<string> s_box(0);
  for(int i = 0; i < s0 - t0 + 1; i++){
    bool nomatch = false;
    string ans = S;
    for(int j = 0; j < t0; j++){
      //cout << i << ':' << j << endl;
      if(S.at(i + j) != '?' && S.at(i + j) != T.at(j)){
        nomatch = true;
        break;
      } 
      else ans.at(i + j) = T.at(j);
    }
    if(nomatch) continue;
    else{
      for(int j = 0; j < s0; j++){
        if(ans.at(j) == '?') ans.at(j) = 'a';
      }
      s_box.push_back(ans);
    }
  }
  
  if(s_box.size() == 0) cout << "UNRESTORABLE" << endl;
  else{
    sort(s_box.begin(), s_box.end());
    cout << s_box.at(0) << endl;
  
  }
}

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

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

    int n;
    cin >> n;

    int res = 0;
    int cnt = 0;
    rep(i, n){
        int p;
        cin >> p;
        if(p-1 == i){
            ++cnt;
        }
        else{
            if(cnt){
                res += (cnt+1)/2;
                cnt = 0;
            }
        }
    }
    if(cnt) res += (cnt+1)/2;
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <limits>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdint>
#define rep(i, s, g) for (i = s; i < g; i++)
using namespace std;
using ll = long long;

const int INF = 1000000000; //10^9

int main() {
    ll n;
    cin >> n;
    vector<string> x(n);
    ll a=0,b=0,c=0,d=0;
    for (ll i = 0; i < n; i++)
    {
        cin >> x[i];
        if (x[i] == "AC")
        {
            a++;
        }
        if (x[i] == "WA")
        {
            b++;
        }
        if (x[i] == "TLE")
        {
            c++;
        }
        if (x[i] == "RE")
        {
            d++;
        }
        
    }
    cout << "AC" << " x " << a << endl;
    cout << "WA" << " x " << b << endl;
    cout << "TLE" << " x " << c << endl;
    cout << "RE" << " x " << d << endl; 

    
}

Measured memory_bytes: 6372
#include<stdio.h>
#include<time.h>

#define MAX 100005 

typedef struct tq{
	char name[100];
	int time;
} s;

int head, tail, n;
s Q[MAX];

s dequeue()
{
	s t; 
	t = Q[head];
	head = (head + 1) % MAX;
	return t;
}

void enqueue(s x)
{
	Q[tail] = x;
	tail = (tail + 1) % MAX;
}

int main()
{
	int q, n, i, count;
	s x;
	//freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    scanf("%d", &n);
    count = n;
    scanf("%d", &q);
    for(i=0;i<n;i++)
    {
    	scanf("%s", Q[i].name);
    	scanf("%d", &Q[i].time);
    	enqueue(Q[i]);
	}
	i = 0;
	while(head!=tail)
	{
		if(Q[head].time>q)
		{
		    Q[head].time -= q;
		    enqueue(dequeue());
		    i += q;
		} 
		else 
		{
			x = dequeue();
			i += x.time;
			printf("%s ", x.name);
			printf("%d\n", i);
		}
	}
    //printf("%lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}

Measured memory_bytes: 10756
import math
n = 1001
x = [1 for i in range(n)]
y = [0 for i in range(n)]
ang = 0
for i in range(2, n):
    ang += math.asin(1/math.sqrt(i - 1))
    x[i] = x[i - 1] + math.cos(ang)
    y[i] = y[i - 1] + math.sin(ang)

while True:
    n = int(input())
    if n == -1:
        break
    print(x[n])
    print(y[n])



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

int main(){
  int a,b,k=1;cin>>a>>b;
  int i=0;
  while(true){
    if((a-1)*i+1>=b)break;
    i++;
  }
  cout<<i<<endl;
}


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

int main()
{
    int n,k;
    cin>>n;
  int p[n];
  for(int i=0;i<n;i++){
    p[i]=0;
  }
    cin>>k;
  int d,a;
    for(int i=0;i<k;i++){
      cin>>d;
      for(int j=0;j<d;j++){
          cin>>a;
          if(p[a-1]==0){
            p[a-1]=1;
          }
      }
    }
  int c=0;
    for(int i=0;i<n;i++){
      if(p[i]==0){
        c++;
      }
    }
  cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 3632
require 'matrix'

n, m, x = gets.split.map(&:to_i)
a = Matrix.zero(n, m + 1)
n.times do |i|
  b = gets.split.map(&:to_i)
  0.upto(m) do |j|
    a[i, j] = b[j]
  end
end
1.upto(m) do |j|
  if a.column(j).to_a.sum < x
    puts "-1"
    exit
  end
end
min = Float::INFINITY
1.upto(2 ** n - 1) do |bit|
  ans = 0
  sum = 0
  1.upto(m) do |j|
    sum = 0
    n.times do |i|
      if bit[i] == 1
        sum += a[i, j]
      end
    end
    break if sum < x
  end
  if sum >= x
    n.times do |i|
      if bit[i] == 1
        ans += a[i, 0]
      end
    end
    min = ans if min > ans
  end
end
puts min

Measured memory_bytes: 15184
h, w = map(int, input().split())
aa = [list(input()) for i in range(h)]
bb = list(zip(*aa))

cc =  [b for b in bb if any(x == '#' for x in b)]
dd =list(zip(*cc))
ee = [d for d in dd if any(x == '#' for x in d)]


for i in range(len(ee)):
    print(''.join(ee[i]))

Measured memory_bytes: 9340
N, M = map(int, input().split())
H = list(map(int, input().split()))

l = []

for i in range(M):
    a, b = map(int, input().split())
    l.append([a-1, b-1])
    l.append([b-1, a-1])


l = sorted(l)

dai = [True for _ in range(N)]

for i in l:
    if H[i[0]] <= H[i[1]]:
        dai[i[0]] = False

ans = 0
for i in dai:
    if i:
        ans += 1

print(ans)


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

int main(){
	string s, t;
	cin >> s >> t;
	if (s.length() != t.length()) {
		cout << "No" << endl;
		return 0;
	}
	int a = s.length()-1;
	rep(i,s.length()) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		s = s.back() + s.substr(0,s.length()-1);
	}
	cout << "No" << endl;
 	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define rep(i,n) for(long long  i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;
 
const int INF = 1001001001;

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

    ll x;
    cin >> x;
    ll a,b;
    rep(i,400){
        rep(j,400){
            ll ans,ansb;
            ans = i*i*i*i*i;
            ansb = j*j*j*j*j;

            if(ans + ansb == x){
                a = i;
                b = -j;
                goto OUT;
            }
            if(ans - ansb == x){
                a = i;
                b = j;
                goto OUT;
            }
        }
    }
    OUT:
    cout << a << " " << b << endl;
    cout << endl;
    return 0;
}



Measured memory_bytes: 3668
input_list = input().rstrip().split(" ")

stack = []
for i in input_list:
    if i in ["+", "-", "*"]:
        num_1 = stack.pop()
        num_2 = stack.pop()
        stack.append(str(eval(num_2 + i + num_1)))
    else:
        stack.append(i)
answer = stack.pop()
print(answer)


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

int main(){
  int n;
  cin >> n;
  vector<bool> vec(1000000001);
  bool ans=true;
  for(int i=0; i<n; ++i){
    int x;
    cin >> x;
    if(vec.at(x) == false) vec.at(x) = true;
    else ans = false;
  }
  if(ans == true) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main(){
  string str;
  cin >> str;
  long i;
  long result = 0;
  long countwhite = 0;
  long bplace = -1;
  for(i = 0; i < str.size();  i++){
    if(str[i] == 'B'){
      bplace = i;
      break;
    }
  }
  if(bplace != -1){
    for(i = bplace ; i < str.size();  i++){
      if(str[i] == 'W'){
        result += i - countwhite - bplace;
        countwhite++;
      }
    }  
  }
  cout << result << endl;

  return 0;
}

Measured memory_bytes: 640
def F(Arri,S,F,C):
    if (Arri-S) <= 0:
        k=0
    else:
        k = (Arri-S) // F
        if (Arri-S) % F !=0:
            k += 1
    return S+F*k+C

N=int(input())
n=0
L=[]
l = [0,0,0]
while n < N-1:
    l[0],l[1],l[2] = map(int,input().split(' '))
    L.append(l.copy())
    n+=1
T = []
j = 0
while j < N-1:
    t=0
    t += L[j][0]+L[j][1]
    q=j+1
    while q < N-1:
        t = F(t,L[q][1],L[q][2],L[q][0])
        q += 1
    T.append(t)
    j += 1
T.append(0)
for i in T:
    print(i)

Measured memory_bytes: 3188
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]

    N,K = LI()
    pl = []
    mi = []
    z = 0
    for x in sys.stdin.readline().split():
        x = int(x)
        if x > 0:
            pl.append(x)
        elif x < 0:
            mi.append(-x)
        else:
            z += 1
    pl.sort()
    mi.sort()

    minus = len(pl) * len(mi)
    zero = z * (len(pl) + len(mi)) + z * (z-1) // 2

    h = INF
    l = -INF-1

    while l+1 < h:
        m = (h+l)//2

        if m > 0:
            k = minus + zero
            j = len(pl)-1
            for i in range(len(pl)-1):
                if i >= j: break
                while pl[i] * pl[j] > m:
                    j -= 1
                    if j == i: break
                else:
                    k += j - i
                    continue
                break
            j = len(mi)-1
            for i in range(len(mi)-1):
                if i >= j: break
                while mi[i] * mi[j] > m:
                    j -= 1
                    if j == i: break
                else:
                    k += j - i
                    continue
                break
        elif m < 0:
            k = 0
            j = 0
            if len(mi) > 0:
                for i in range(len(pl)-1,-1,-1):
                    while -pl[i] * mi[j] > m:
                        j += 1
                        if j == len(mi): break
                    else:
                        k += len(mi) - j
                        continue
                    break
        else:
            k = minus + zero

        if k < K:
            l = m
        else:
            h = m

    print(h)


if __name__ == '__main__':
    main()

Measured memory_bytes: 78280
#include <iostream>

using namespace std;

int main() {
    long long A, B;
    cin >> A >> B;
    long long cnt = 0;
    for (long long i = A; i <= B; i++) {
        long long j = (i % 10) * 10000 + ((i/10)%10) * 1000 + ((i/100)%10) * 100 + ((i/1000)%10) * 10 + ((i/10000)%10);
        if (i == j) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <math.h> // sqrt()
#include <iomanip>
#define rep(i , n) for (int i = 1; i <= (int)(n); i++)
#define repz(i , n) for (int i = 0; i < (int) n; i++)
#define repi(i , r, n) for (int i = r; i <= (int)(n); i++)
#define repd(i , r, n) for (int i = r; i >= (int)(n); i--)


using namespace std;


int main(){
    string s, t;
    cin >> s >> t;
    map<char , char> dict;
    map<char , char> dicttwo;
    bool one = true; bool two = true;
    repz( i , s.size()){
        if (not(dict[s.at(i)])) dict[s.at(i)] = t.at(i);
        else{
            if(dict[s.at(i)] != t.at(i)) one = false;
        }
        if (not(dicttwo[t.at(i)])) dicttwo[t.at(i)] = s.at(i);
        else{
            if(dicttwo[t.at(i)] != s.at(i)) two = false;
        }
    }
    if ( one & two) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    
}


Measured memory_bytes: 3920
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_set>
#include<unordered_map>

using namespace std;

char buf[10002];
string s;
int main(){
	scanf("%s", buf);
	s = buf;
	int w;
	cin >> w;
	int pos = 0;
	while (pos < s.size()){
		putchar(s[pos]);
		pos += w;
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <map>
#include <math.h>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <queue>
#include <sstream>
#include <stack>
#include <deque>
#include <memory.h>
#include <cassert>
#include <ctime>
#include <climits>
#include <list>
#include <time.h>
#include <unordered_map>
#include <bitset>
#include <exception>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
#define pb push_back
#define mp make_pair
#define FILE "file"
#define lc v << 1
#define rc (v << 1) + 1
#define inf 1e+9
#define linf ll(1e+18)
#define dinf 1e+14

typedef long long ll;
#define pb push_back
#define mp make_pair

bool good(char c)
{
    return ((c == 'A') || (c == 'C') || (c == 'G') || (c == 'T'));
}

void solve()
{
    string s;
    cin >> s;
    int n = (int) s.length();
    
    int res = 0;
    int temp = 0;
    for(int i = 0; i < n; i++)
    {
        if(good(s[i]))
        {
            temp++;
        }
        else
        {
            temp = 0;
        }
        res = max(res, temp);
    }
    cout << res;
}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    //freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.in", "r", stdin);freopen("/Users/bekhzodsoliev/Desktop/C++/cp/cp/file.out", "w", stdout);
    
    int t = 1;
    //cin >> t;
    
    while(t--)
    {
        solve();
    }
    
    return 0;
}


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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,p;
    cin >> n >> p;
    vector<pair<ll,ll>> a(n);
    for (int i = 0;i < n;++i) cin >> a[i].first >> a[i].second;
    sort(a.begin(),a.end(),[&](pair<ll,ll> x,pair<ll,ll> y)->bool{return x.first*(100-p)+x.second*p > y.first*(100-p)+y.second*p;});
    ll sum = 0;
    for (int i = 0;i < n;++i) sum -= a[i].second*p;
    for (int i = 0;i < n;++i) {
        sum += a[i].first*(100-p)+a[i].second*p;
        if (sum >= 0) {
            cout << i+1 << endl;
            return 0;
        }
    }
}

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

int main() {
  int64_t N,a=0,b=0,c=0,Z=1,Q=1000000007;
  cin>>N;
  for(int64_t i=0;i<N;i++){
    int64_t x;
    cin>>x;
    if(a==x){
      a++;
      if(b==x){
        if(c==x){
          Z=(Z*3)%Q;
        }
      else{
        Z=(Z*2)%Q;
      }
    }
    }
    else if(b==x){
      b++;
      if(c==x){
        Z=(Z*2)%Q;
      }
    }
    else if(c==x){
      c++;
    }
    else{
      Z=0;
    }
  }
  cout<<Z<<endl;
}

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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

typedef pair<ll, ll> P;

// 移動を簡単に表現するための配列
int dy[] = {1, 0, 0, -1};
int dx[] = {0, 1, -1, 0};

int main() {
    char a,b; cin >> a >> b;
    if((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
        cout << "H" << endl;
    } else {
        cout << "D" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
c11,c12,c13 = map(int,input().split())
c21,c22,c23 = map(int,input().split())
c31,c32,c33 = map(int,input().split())

def solve():
  if not (c11 - c12 == c21 - c22 == c31- c32):
    return False
  if not (c11 - c13 == c21 - c23 == c31 - c33):
    return False
  if not (c11 - c21 == c12 - c22 == c13 - c23):
    return False
  if not (c11 - c31 == c12 - c32 == c13 - c33):
    return False
  
  return True

print('Yes' if solve() else 'No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vvll x(n,vll(3));
  rep(i,n){
    cin>>x[i][0]>>x[i][1]>>x[i][2];
  }
  ll ans=0;
  for(int bit=0;bit<(1<<3);bit++){
    vll p(0);
    rep(i,n){
      ll cu=0;
      for(int j=0;j<3;j++){
        if(bit&(1<<j)){
          cu+=x[i][j];
        }
        else cu-=x[i][j];
      }
      p.pb(cu);
    }
    sort(rall(p));
    ll k=0;
    rep(i,m){
      k+=p[i];
    }
    ans=max(ans,k);
  }
  COUT(ans);
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<vector>
#include<algorithm>
#include<iterator>
#include<sstream>
#include<iomanip>
#include<map>
#include<queue>
#include<deque>
#include<fstream>

#define rep(i, n) for (ll i = 0; i < n; i++) 
#define rrep(i, n) for(ll i = n-1; i>=0; i--)
#define range(i, n, m) for (ll i = n; i < m; i++) 
#define rrange(i, n, m) for (ll i = n - 1; i => m; i--) 
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vp vector<pair<ll, ll> >
#define vvp vector<vector<pair<ll, ll> > >
#define First first
#define Second second.first
#define Third second.second
//#define MOD 998244353

typedef long long int ll;
typedef unsigned long long int ull;

using namespace std;

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

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
 
	return gcd(b, a%b);
}

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

	//std::ifstream in("../../test.txt");
	//std::cin.rdbuf(in.rdbuf());


	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll dst = gcd(C, D);
	ll bunbo = (C * D) / dst;
	ll aa = A;


	A = A - (A / C) - (A / D) + (A / bunbo);
	B = B - (B / C) - (B / D) + (B / bunbo);

	if (aa % C != 0 && aa % D != 0) B++;

	cout << B - A << endl;



	return 0;
}



Measured memory_bytes: 384
process.stdin.resume()
process.stdin.setEncoding('utf8')

var inputLines = ''

const parseInt10 = (v) => {
  return parseInt(v, 10)
}

process.stdin.on('data', function (chunk) {
  inputLines += chunk
})

process.stdin.on('end', function () {
  const lines = inputLines.trim().split('\n')
  solve(lines)
})

const solve = (lines) => {
  const d = lines[0].split(' ').map(parseInt10)
  console.log((d[0] + d[1]) % 24)
}


Measured memory_bytes: 11596
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        s: chars,
    }

    let mut ans: i64 = 0;

    for e in s {
        if e == '+' {
            ans += 1;
        } else {
            ans -= 1;
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
const int MAX = 36;

struct Card
{
	char suit;
	int num;
};

void swap(Card &c1, Card &c2)
{
	char suit_temp;
	int num_temp;

	suit_temp = c1.suit;
	num_temp = c1.num;

	c1.suit = c2.suit;
	c1.num = c2.num;
	c2.suit = suit_temp;
	c2.num = num_temp;

}

bool isEqual(Card c1[], Card c2[], int n)
{
	for(int i = 0; i < n; i++)
	{
		if((c1[i].suit != c2[i].suit) || (c1[i].num != c2[i].num))
			return false;
	}
	return true;
}

int main()
{
	int n, mini;

	cin >> n;

	Card c1[n], c2[n]; 
	for(int i = 0; i < n; i++)
	{
		cin >> c1[i].suit >> c1[i].num;
		c2[i].suit = c1[i].suit;
		c2[i].num = c1[i].num;
	}
	// BubbleSort
	for(int i = 0; i < n; i++)
	{
		for(int j = n-1; j >= i+1; j--)
		{
			if(c1[j-1].num > c1[j].num)
			{
				swap(c1[j-1], c1[j]);
			}
		}
	}
	// SelectionSort
	for(int i = 0; i < n; i++)
	{
		mini = i;
		for(int j = i; j < n; j++)
		{
			if(c2[mini].num > c2[j].num)
			{
				mini = j;
			}
		}
		if(mini != i)
		{
			swap(c2[mini], c2[i]);
		}
	}

	for(int i = 0; i < n-1; i++)
	{
		cout << c1[i].suit << c1[i].num << ' ';
	}
	cout << c1[n-1].suit << c1[n-1].num << endl;
	cout << "Stable\n";

	for(int i = 0; i < n-1; i++)
	{
		cout << c2[i].suit << c2[i].num << ' ';
	}
	cout << c2[n-1].suit << c2[n-1].num << endl;

	if(isEqual(c1, c2, n))
	{
		cout << "Stable\n";
	}
	else
	{
		cout << "Not stable\n";
	}

}


Measured memory_bytes: 3088