akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    private static long[] add(long[] a, long add) {
        long[] res = new long[a.length];
        for (int i = 0; i < a.length; i++) {
            res[i] = a[i];
        }
        res[0] += add;
        return res;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextInt()) {
            int n = sc.nextInt();
            long[] a = new long[n];

            for (int i = 0; i < n; i++) {
                a[i] = sc.nextLong();
            }

            boolean isZero = (a[0] == 0);
            long ans = Long.MAX_VALUE;

            if ( isZero ) {
                long[] ta = add(a, 1);
                ans = Math.min(ans, solve(ta) + 1);

                ta = add(a, -1);
                ans = Math.min(ans, solve(ta) + 1);
            } else {
                ans = Math.min(ans, solve(a));

                long[] ta = add(a, -a[0] + (a[0] < 0 ? 1 : -1));
                ans = Math.min(ans, solve(ta) + Math.abs(a[0]) + 1);
            }

            System.out.println(ans);
        }
    }

    private static long solve(long[] a) {
        long res = 0;
        long sum = a[0];
        boolean isPositive = sum > 0;

        for (int i = 1; i < a.length; i++) {
            isPositive = !isPositive;
            sum += a[i];
            if ( isPositive && sum <= 0 ) {
                res += Math.abs(sum) + 1;
                sum = 1;
            } else if ( !isPositive && sum >= 0 ) {
                res += Math.abs(sum) + 1;
                sum = -1;
            }
        }

        return res;
    }
}


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

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

const int nmax = 2e5;
int v[nmax + 1];

multiset<int> s;

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

    for (int i = 1; i <= n; ++ i) {
        cin >> v[i];
        s.insert(v[i]);
    }

    sort(v + 1, v + n + 1);
    int ans = 0;
    for (int i = n; i > 0; -- i) {
        if (s.find(v[i]) == s.end())
            continue;

        s.erase(s.find(v[i]));

        int p2;
        for (p2 = 1; p2 <= v[i]; p2 <<= 1) {
        }
        int x = p2 - v[i];

        if (s.find(x) != s.end()) {
            ++ ans;
            s.erase(s.find(x));
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 10368
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll X;
int k;
const int maxN = 1e5 + 10;
ll le[maxN], ri[maxN], val1[maxN], val2[maxN], c[maxN];
ll r[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> X >> k;
    le[0] = 0;
    ri[0] = X;
    val1[0] = 0;
    val2[0] = X;
    c[0] = 0;
    for (int i = 1; i <= k; i++) {
        cin >> r[i];
        int delta = r[i] - r[i - 1];
        if (i % 2 == 1) {
            //we decrease
            c[i] = c[i - 1] - delta;
            val1[i] = max(0LL, val1[i - 1] - delta);
            val2[i] = max(0LL, val2[i - 1] - delta);
            le[i] = max(le[i - 1], val1[i] - c[i]);
            ri[i] = min(ri[i - 1], val2[i] - c[i]);
        }
        else {
            //we increase
            c[i] = c[i - 1] + delta;
            val1[i] = min(X, val1[i - 1] + delta);
            val2[i] = min(X, val2[i - 1] + delta);
            le[i] = max(le[i - 1], val1[i] - c[i]);
            ri[i] = min(ri[i - 1], val2[i] - c[i]);
        }
    }
    int q;
    cin >> q;
    while (q--) {
        ll t, a;
        cin >> t >> a;
        int p = upper_bound(r, r + k + 1, t) - r - 1;
        ll val_bef = 0;
        if (a < le[p]) {
            val_bef = val1[p];
        }
        else if (a > ri[p]) {
            val_bef = val2[p];
        }
        else {
            val_bef = a + c[p];
        }
        ll delta = t - r[p];
        if (p % 2 == 1) {
            // we increase
            val_bef = min(X, val_bef + delta);
        }
        else {
            val_bef = max(0LL, val_bef - delta);
        }
        cout << val_bef << '\n';
    }
    return 0;
}

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

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

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


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/


int main() {
    string s;
    cin >> s;
    int a, z;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }

    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }

    cout << z - a + 1 << endl;
    return 0;
}

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

int main() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
  int A,B;
  cin>>A>>B;
  char grid[100][100];
  for (int i=0; i<50; i++) {
    for (int j=0; j<100; j++) {
      grid[i][j]='.';
    }
  }
  for (int i=50; i<100; i++) {
    for (int j=0; j<100; j++) {
      grid[i][j]='#';
    }
  }
  A--,B--;
  for (int i=0; i<50; i+=2) {
    for (int j=0; j<100 && B; j+=2) {
      grid[i][j]='#';
      B--;
    }
  }
  for (int i=51; i<100; i+=2) {
    for (int j=0; j<100 && A; j+=2) {
      grid[i][j]='.';
      A--;
    }
  }
  cout<<100<<" "<<100<<endl;
  for (int i=0; i<100; i++) {
    for (int j=0; j<100; j++) {
      cout<<grid[i][j]<<flush;
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 384
li=[input() for i in range(5)]
mi=10
for i in range(5):
    if int(li[i][-1])!=0:
        mi = min(mi, int(li[i][-1]))
ans = 0

for i in range(5):
    if int(li[i])%10 !=0:
        ans += int(li[i])+(10-int(li[i])%10)
    else:
        ans += int(li[i])
print(ans-10+mi)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REP(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

// bool comp(pair<ll, ll> a, pair<ll, ll >b) {
//   a.second < b.second;
// }

int main() {

  ll H, N;
  cin >> H >> N;

  vector<ll> A, B;
  ll temp;
  REP(i, 0, N) {
    cin >> temp;
    A.push_back(temp);
    cin >> temp;
    B.push_back(temp);
  }
  vector<pair<ll, ll> > p(N);
  REP(i, 0, N) {
    p[i] = make_pair(A[i], B[i]);
  }
  // sort(p.begin(), p.end(), comp); // sort by maryoku syohi (3, 2, 1 ...)

  // debug
  // cout << endl;
  // REP(i, 0, N) {
  //   cout << A[i] << " " << B[i] << endl;
  // }
  // cout << endl;
  // REP(i, 0, N) {
  //   cout << p[i].first << " " << p[i].second << endl;
  // }
  // cout << endl;

  // use DP
  vector<ll> DP;
  for(ll i=0; i<=H; i++) {
    DP.push_back(-1);
  }

  DP[0] = 0;
  for(ll i=1; i<=H; i++) {
    ll min_cost = longinf;
    for(vector<pair<ll, ll> >::iterator it = p.begin(); it!=p.end(); it++) {
      if (i - (*it).first < 0) {
        min_cost = min(min_cost, (*it).second);
      }
      else {
        min_cost = min(min_cost, DP[i - (*it).first] + (*it).second);
      }
    }
    DP[i] = min_cost;
  }

  cout << DP[H] << endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
  long long int n, a[5001], t, s;

  while(cin>>n && n){
    for(int i = 0; i < n; i++){
      cin >> a[i];
    }
    t = a[0];

    for(int i = 0; i < n; i++){
      s = a[i];
      t = max(t, s);
      for(int j = i+1; j < n; j++){
	t = max(t, s+a[j]);
	s += a[j];
      }
    }

    cout << t << endl;
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits.h>
#include <climits>
#include <map>
#include <unordered_map>
#include <cmath>
#include <set>
#include <unordered_set>
#include <iterator>
#include <deque>
#include <assert.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
ull min(ull x, ull y){ if (x<y) return x; return y;}
ull max(ull x, ull y){ if (x<y) return y; return x;}
ll min(ll x, ll y){ if (x<y) return x; return y;}
ll max(ll x, ll y){ if (x<y) return y; return x;}
double min(double x, double y){ if (x<y) return x; return y;}
double max(double x, double y){ if (x<y) return y; return x;}
ull gcd(ull x, ull y){
    if (!x) return y;
    if (!y) return x;
    if (x>y) swap(x,y);
    return gcd(x, y%x);
}
ull inv(ull a, ull c){ // a,c are coprime and a<c
    if (a==1){
        return 1;
    }
    return ((c-(c/a))*inv(c%a,c))%c;
}


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


    ll n, k;
    cin>>n>>k;
    
    n%=k;
    cout<<min(n,k-n)<<"\n";

    return 0;
    
}



Measured memory_bytes: 256
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]

    def group_members(self, x):  # x が属する集合の要素を返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  # すべての根をリストで返す
        return [i for i, x in enumerate(self.parent) if i == x]

    def group_count(self):  # 木の数を返す
        return len(self.roots())

    def all_group_members(self):  # すべての木の要素を辞書で返す
        return {r: self.group_members(r) for r in self.roots()}

    def __str__(self):  # print 表示用
        return '\n'.join('{}: {}'.format(r, self.group_members(r)) for r in self.roots())


N, M = map(int, input().split())
p = list(map(int, input().split()))

P = [[p[i]-1, i] for i in range(N)]

uf = UnionFind(N)

for _ in range(M):
    x, y = map(int, input().split())
    uf.unite(x-1, y-1)

ans = 0
for i in range(N):
    if uf.is_same(i, p[i]-1):
        ans += 1
print(ans)


Measured memory_bytes: 29156
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,mn=200001,cnt=0,tmp;
  cin >> n;
  rep(i,n){
    cin >> tmp;
    if(mn>tmp){
      mn=tmp;
      cnt++;
    }
  }
  cout << cnt << endl;
}
  

Measured memory_bytes: 256
n = int(input())
l_list = list(map(int, input().split()))
l_list.sort()
ans = 0

for i in range(len(l_list)):
    for j in range(i + 1, len(l_list)):
        for k in range(j + 1, len(l_list)):
            if l_list[i] + l_list[j] > l_list[k] \
                    and l_list[i] != l_list[j] \
                    and l_list[j] != l_list[k] \
                    and l_list[k] != l_list[i]:
                ans += 1
print(ans)

Measured memory_bytes: 9112
;;; Utils

(defmacro read-numbers-to-list ()
  `(read-from-string
    (concatenate 'string "(" (read-line) ")")))


(defmacro read-line-to-array (dimension)
  (if (< dimension 0)
      (error "invalid arguments for dimension.")
      `(make-array ,dimension :initial-contents (read-numbers-to-list))))

(defmacro read-line-to--char-list ()
  `(concatenate 'list (read-line)))

(defmethod make-cumlative-sum ((sequence list))
  (labels ((inner (sequence &optional (acc '(0)))
             (if (null sequence)
                 (reverse acc)
                 (inner (rest sequence) (cons (+ (first sequence)
                                                 (first acc))
                                              acc)))))
    (inner sequence)))





(defmethod princ-for-each-line ((sequence list))
  (labels ((inner (sequence)
             (if (null sequence)
                 nil
                 (progn
                   (fresh-line)
                   (princ (first sequence))
                   (inner (rest sequence))))))
    (inner sequence)))

(defmethod princ-for-each-line ((sequence array))
  (dotimes (i (length sequence))
    (fresh-line)
    (princ (aref sequence i))))



;;; Write code here

(defun factorize-number-to-lst (x)
  (assert (and (numberp x)
               (plusp x)))
  (labels
      ((inner (x)
         (if (= x 1)
             1)
         (let ((res nil)
               (f 2))
           (loop while (<= (* f f) x) do
                (if (zerop (mod x f))
                    (progn
                      (setf x (truncate x f))
                      (push f res))
                    (incf f))
              finally
                (progn
                  (when (/= x 1)
                    (push x res))
                  (return (reverse res)))))))
    (inner x)))


(defun setwise-p (xs)
  (=
   (reduce #'gcd xs)
   1))


(defun step-sum (sequence start end step)
  (assert (arrayp sequence))
  (labels ((inner (start end step &optional (acc 0))
             (if (< start end)
                 (inner (+ start step) end step (+ acc
                                                   (aref sequence start)))
                 acc)))
    (inner start end step)))

(defun pairwise-p (n xs)
  (assert (and (plusp n)
               (every #'numberp xs)))
  (let ((memo (make-array (1+ (expt 10 6))::initial-element 0))
        (flag t))
    (dotimes (i n)
      (incf (aref memo (first xs)))
      (pop xs))
    (let ((f 2))
      (loop while (<= f (expt 10 6)) do
           (when (> (step-sum memo f (1+ (expt 10 6)) f) 1)
             (setf flag nil))
           (incf f)
         finally
           (return flag)))))



(defun solve (n a)
  (cond
    ((pairwise-p n a) "pairwise coprime")
    ((setwise-p a)  "setwise coprime")
    (t "not coprime")))


(defun main ()
  (let ((n (read))
        (a (sort (read-numbers-to-list) #'<)))
    (format t "~a~%" (solve n a))))

(main)


Measured memory_bytes: 137816
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
//rep(i, v.size()) v[i]=i;
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

signed main(){
  string S,T;
  cin >> S >> T;
  cout << T + S << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int K = cin.nextint;
        var dp = new long[12, 11];
        int p = (N - 2) / 11;
        int q = (N - 2) % 11;
        int now = 4;

        for (int i = 1; i < 12; i++)
        {
            for (int j = 0; j < 11; j++)
            {
                dp[i, j] = dp[i - 1, j];
            }
            int tmp = now;
            for (int j = 0; j < 5; j++)
            {
                dp[i, tmp]++;
                tmp = (tmp + 9) % 11;
            }
            now = (now + 8) % 11;
        }

        WriteLine(dp[11, K] * p + dp[q, K]);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public string join<T>(IEnumerable<T> values) { return string.Join(" ", values); }
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 1e7 + 10;
const int P = 1e9 + 7;

int prod[MAXN], inv[MAXN], k, s;
char str[MAXN];

int Combine(int n, int m) { return 1ll * prod[n] * inv[n - m] % P * inv[m] % P; }

int qpower(int a, int x) {
    int res = 1;
    for (; x; x >>= 1, a = 1ll * a * a % P) x & 1 ? res = 1ll * res * a % P : 0;
    return res;
}

void add(int& a, int b) { a = a + b > P ? a + b - P : a + b; }

int main() {
    prod[0] = 1;
    rep(i, 1, MAXN) prod[i] = 1ll * prod[i - 1] * i % P;
    inv[0] = inv[1] = 1;
    rep(i, 2, MAXN) inv[i] = 1ll * (P - P / i) * inv[P % i] % P;
    rep(i, 2, MAXN) inv[i] = 1ll * inv[i] * inv[i - 1] % P;
    IO::read(k);
    scanf("%s", str + 1);
    s = strlen(str + 1);
    int ans = 0;
    rep(i, s, k + s) {
        // printf("%d\n", Combine(k + s, i));
        add(ans, 1ll * Combine(k + s, i) * qpower(25, k + s - i) % P);
    }
    printf("%d\n", ans);
    return 0;
}

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

using namespace std;
using ll = long long;

const vector<vector<int>> dir4 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}};
const vector<vector<int>> dir8 = {{0, 1}, {1, 0}, {-1, 0}, {0, -1}, {1, 1}, {-1, 1}, {1, -1}, {-1, -1}};

int main()
{
    int h, w; cin >> h >> w;
    vector<string> gr(h + 2, string(w + 2, '.'));
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            char c; cin >> c; gr[i][j] = c;
        }
    }

    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(gr[i][j] != '#')continue;
            bool r = false;
            for(auto d: dir4) if(gr[i + d[0]][j + d[1]] == '#')r = true;
            if(!r) {cout << "No" << endl; return 0;}
        }
    }
    cout << "Yes" << endl;
}

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

typedef long long ll;

ll n,m,l;
ll k[2222];
ll sum[111111];

ll dp[2222][2222];

vector<ll> magic[2];

ll solve(int m1,int m2){
  if(dp[m1][m2]) return dp[m1][m2];

  if(m1 >= n-1) return (sum[k[n-1]] - sum[k[m2] - 1]) / l;
  if(m2 >= n-1) return (sum[k[n-1]] - sum[k[m1] - 1]) / l;

  ll ret = 0;
  
  int next = max(m1,m2) + 1;

  ret = min(solve(next,m2) + (sum[k[next]] - sum[k[m1] - 1]) / l,
	    solve(next,m1) + (sum[k[next]] - sum[k[m2] - 1]) / l);
  return dp[m1][m2] = ret;
}

int main(void)
{
  cin >> n >> m >> l;
  for(int i = 0; i < n; i++){
    cin >> k[i];
  }
  for(int i = 1; i <= m; i++){
    int s;
    cin >> s;
    sum[i] = sum[i-1] + s;
  }

  sort(k, k + n);

  /*
  magic[0].push_back(k[0]);
  magic[1].push_back(k[0]);
  for(int i = 1; i < n - 1; i++){
    if(sum[k[i]] - sum[magic[0][magic[0].size()-1] - 1] < 
       sum[k[i]] - sum[magic[1][magic[1].size()-1] - 1]){
      magic[0].push_back(k[i]);
    }else{
      magic[1].push_back(k[i]);
    }
  }
  magic[0].push_back(k[n-1]);
  magic[1].push_back(k[n-1]);

  ll ret = 0;

  for(int i = 0; i < 2; i++){
    for(int j = 1; j < (int)magic[i].size(); j++){
      ret += ( sum[magic[i][j]] - sum[magic[i][j-1] - 1] ) / l;
    }
  }
  cout << ret << endl;
  */

  cout << solve(0,0) << endl;
}

Measured memory_bytes: 37112
#include<stdio.h>
#include<math.h>
int main(void){
  int x;
  scanf("%d",&x);
  for(int a=-188;a<=119;a++){
    for(int b=-199;b<=118;b++){
      if((pow(a,5))-(pow(b,5))==x){
        printf("%d %d",a,b);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 2528
n,m=map(int,input().split())
s=[list(map(int,input().split())) for _ in range(m)]
p=list(map(int,input().split()))
num = 0
for i in range(2**n):
    onof = format(i,'b').zfill(n)
    for j in range(m):
        sum_onof = 0
        for k in range(s[j][0]):
            sum_onof += int(onof[s[j][k+1]-1])
        if sum_onof%2 != p[j]:
            break
        elif j == m-1:
            num += 1
print(num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <functional>
#include <climits>

struct euler_tour {
	template<typename T>
	struct segment_tree {
		long long N;				// the size of V
		long long M;				// the number of leaves
		std::vector<T> V;			// 1-indexed
		std::function<T(T, T)> OP;	// binary operation
		T ID;						// identity element of OP

		segment_tree() {}

		void init(std::vector<T>& a, std::function<T(T, T)> f, T t) {
			OP = f; ID = t;
			M = 1;
			while (M < a.size()) M *= 2;
			N = 2 * M;
			V.resize(N, ID);
			for (long long i = 0; i < a.size(); i++) V[M + i] = a[i];
			for (long long i = a.size(); i < M; i++) V[M + i] = ID;
			for (long long i = M - 1; i > 0; i--) {
				V[i] = OP(V[2 * i], V[2 * i + 1]);
			}
		}

		void point_update(long long i, T x) {
			i += M;
			V[i] = x;
			while (i / 2 < i) {
				i /= 2;
				V[i] = OP(V[2 * i], V[2 * i + 1]);
			}
		}

		T range_subfunc(
			long long cur_node, long long cur_left, long long cur_right,
			long long l, long long r
		) {
			if (cur_right <= l || r <= cur_left) return ID;
			if (l <= cur_left && cur_right <= r) return V[cur_node];
			long long mid = (cur_left + cur_right) / 2;
			return OP(
				range_subfunc(cur_node * 2, cur_left, mid, l, r),
				range_subfunc(cur_node * 2 + 1, mid, cur_right, l, r)
			);
		}

		T range_fold(long long l, long long r) {
			return range_subfunc(1, 0, M, l, r);
		}
	};

	using P = std::pair<long long, long long>;
	long long N;
	long long R;
	std::vector<std::vector<long long>> adj_list;
	std::vector<P> dfs_order;
	std::vector<P> LR;
	segment_tree<P> sg;

	euler_tour(
		long long R,
		std::vector<std::vector<long long>>& adj_list
	) : R(R), adj_list(adj_list) {
		N = adj_list.size();
		dfs(-1, R, 0);
		LR.resize(N, {-1, -1});
		for (long long i = 0; i < 2 * N - 1; i++) {
			if (LR[dfs_order[i].second].first == -1) {
				LR[dfs_order[i].second].first = i;
			}
			LR[dfs_order[i].second].second = i;
		}
		auto f = [] (P x, P y) {return std::min(x, y);};
		sg.init(dfs_order, f, {LLONG_MAX, LLONG_MAX});
	}

	void dfs(long long parent, long long current, long long depth) {
		if (current && adj_list[current].size() == 1) {
			dfs_order.push_back({depth, current});
			return;
		}
		for (auto i : adj_list[current]) {
			if (i == parent) continue;
			dfs_order.push_back({depth, current});
			dfs(current, i, depth + 1);
		}
		dfs_order.push_back({depth, current});
	}

	// return {LCA, distance}
	P lca(long long i, long long j) {
		long long l = std::min(LR[i].first, LR[j].first);
		long long r = std::max(LR[i].second, LR[j].second) + 1;
		P x = sg.range_fold(l, r);
		long long dist = dfs_order[l].first + dfs_order[r].first - 2 * x.first;
		return {x.second, dist};
	}
};

int main() {
	long long n;
	std::cin >> n;
	std::vector<std::vector<long long>> adj_list(n);
	for (long long i = 0; i < n; i++) {
		long long k;
		std::cin >> k;
		while (k--) {
			long long c;
			std::cin >> c;
			adj_list[i].push_back(c);
			adj_list[c].push_back(i);
		}
	}
	euler_tour et(0, adj_list);
	long long q;
	std::cin >> q;
	while (q--) {
		long long u, v;
		std::cin >> u >> v;
		std::cout << et.lca(u, v).first << '\n';
	}
}


Measured memory_bytes: 31020
fun main(args: Array<String>) {
    val (d, t, s) = readIntList()

    if (d.toDouble() / s <= t.toDouble()) {
        println("Yes")
    } else {
        println("No")
    }
}

// read
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


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


int main(){
  string S;
  string T;
  cin >> S;
  reverse(S.begin(), S.end());
  vector<string> words{"dream", "dreamer", "erase", "eraser"};
  for(int i = 0; i < words.size(); i++)	reverse(words.at(i).begin(), words.at(i).end());

  string temp = "";
  for(int i = 0; i < S.size(); i++){
    temp.push_back(S.at(i));
    for(word : words){
      if(temp == word) temp = "";
    }
  }
  if(temp == "")	cout << "YES" << endl;
  else				cout << "NO" << endl;

}

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

int gcd(int x, int y){
  if(x<y){
    swap(x,y);
  }
  while(y>0){
    int r = x%y;
    x = y;
    y = r;
  }
  return x;
}

int main(){
  int x,y;
  cin >> x >> y;

  cout << gcd(x,y) << endl;

  return 0;
}



Measured memory_bytes: 3072
from itertools import*
n,*t=map(int,open(0).read().split())
e={0}
for a in zip(t[1::2],t[2::2]):e|={a,a[::-1]}
print(sum(all(u in e for u in zip(t,t[1:]))for t in permutations(range(1,n+1))if t[0]<2))

Measured memory_bytes: 3060
a, b, c =map(int,input().split())

if a <= b <= c:
    print(a, b, c)
elif a <= c <= b:
    print(a, c, b)
elif b <= a <= c:
    print(b, a, c)
elif b <= c <= a:
    print(b, c, a)
elif c <= a <= b:
    print(c, a, b)
elif c <= b <= a:
    print(c, b, a)


Measured memory_bytes: 5596
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 1, n, k, counter = 0, w, h;
string s;
char c;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
map<ll, string> mp;
/*--------------------template--------------------*/

int main() {
	int x, y, z, count = 0;
	cin >> n >> k;
	for (x = 0; x <= n; ++x) {
		for (y = 0; y <= n; ++y) {
			z = k - x - y;
			if (0 <= z && z <= n) {
				count++;
			}
		}
	}
	cout << count << endl;
}

Measured memory_bytes: 256
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                       O\  =  /O
                    ____/`---'\____
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

using int64 = long long;
using uint64 = unsigned long long;
using vi = vector<int>;
using vl = vector<int64>;
using pii = pair<int, int>;
using pll = pair<int64, int64>;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
#define dbg(v) for (size_t _ = 0; _ < v.size(); ++_){cerr << #v << "[" << _ << "] : " << v[_] << '\n';}
// constant
const int INF = (1<<30) - 1;
const int64 INF64 = (1LL<<62) - 1;

int main(){
    cout << fixed << setprecision(15);

    int n1, n2, n3, n4;
    cin >> n1 >> n2 >> n3 >> n4;
    set<int> st{n1, n2, n3, n4};
    set<int> s{1, 9, 7, 4};
    if (st == s) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(a) cout << #a << ": " << a << endl
#define sz(a) int(a.size())
#define vi vector<int>
#define rep(i,n) for(int i=0;i<n;i++)
#define forr(i, st, en) for(int i = st; i <= en; i++)
#define all(v) (v).begin(),(v).end()
#define fast cin.tie(0); ios::sync_with_stdio(false)

//int cnt[1<<20];
map<int, int> cnt;
int32_t main(){ fast;
               int a; cin>>a;
               cout<<a + a * a + a * a * a;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

const int W = 5;
int H;
vector< vector<int> > m;
ll check() {
	ll res = 0;
	// erase and add score
	REP(y, H) {
		REP(x, W) {
			int l = x, r = x;
			FOR(i, x, W) {
				if (m[y][x] != m[y][i]) break;
				r = i;
			}
			++r;
			if (r-l < 3) continue;
			res += (ll)(r-l) * m[y][x];
			FOR(i, x, r) {
				m[y][i] = 0;
			}
		}
	}
//	cout << m << endl;
//	cout << endl;
	// fall
	REP(t, H) {
		RFOR(y, 1, H) {
			REP(x, W) {
				if (m[y][x] == 0) {
					m[y][x] = m[y-1][x];
					m[y-1][x] = 0;
				}
			}
		}
	}
//	cout << m << endl;
//	cout << endl;
	return res;
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while (cin >> H, H) {
		m = vector< vector<int> >(H, vector<int>(W, 0));
		cin >> m;
		ll ans = 0;
		while (1) {
			int c = check();
			ans += c;
			if (c == 0) break;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3204
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <cstdio>
#include <climits>
#include <cmath>
#include <array>
#include <functional>
#include <sstream>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const double eps=1e-9;
const int inf=1e9;
typedef pair<int,int> P;
struct Point
{
  double x,y;
  Point(){x=0;y=0;}
  Point(double d_x,double d_y){x=d_x,y=d_y;}
  double operator*(Point obj){return obj.x*x+obj.y*y;}
  double operator%(Point obj){return obj.y*x-obj.x*y;}
  Point operator*(double b){Point tmp;tmp.x=x*b;tmp.y=y*b;return tmp;}
  Point operator/(double b){Point tmp;tmp.x=x/b;tmp.y=y/b;return tmp;}
  Point operator+(Point obj){Point tmp;tmp.x=x+obj.x;tmp.y=y+obj.y;return tmp;}
  Point operator-(){Point tmp;tmp.x=-x;tmp.y=-y;return tmp;}
  Point operator-(Point obj){Point tmp;tmp.x=x-obj.x;tmp.y=y-obj.y;return tmp;}
  Point operator-=(Point obj){x-=obj.x;y-=obj.y;return *this;}
  Point operator+=(Point obj){x+=obj.x;y+=obj.y;return *this;}
  Point operator/=(double b){x=x/b;y=y/b;return *this;}
  Point operator*=(double b){x=x*b;y=y*b;return *this;}
  double size(){return hypot(x,y);}
  Point unit(){return Point(x/size(),y/size());}
  Point normal(){return Point(y,-x);}
  double atan(){return atan2(y,x);}
};

bool operator<(Point a,Point b){return a.x!=b.x?a.x<b.x:a.y<b.y;}
bool operator>(Point a,Point b){return b<a;}
bool operator<=(Point a,Point b){return !(b<a);}
bool operator>=(Point a,Point b){return !(a<b);}
bool operator==(Point a,Point b){return (a-b).size()<eps;}
bool operator!=(Point a,Point b){return !(a==b);}

bool equal(double a,double b){return abs(a-b)<eps;}
double cross(Point a,Point b){return a%b;}
double dot(Point a,Point b){return a*b;}

int ccw(Point a,Point b,Point c)
{
  b=b-a;
  c=c-a;
  if(b%c>0) return +1;
  else if(b%c<0)return -1;
  else if(b*c<0) return +2;
  else if(b.size()<c.size()) return -2;
  else return 0;
}

bool mprime[300005];
bool mosat[300005];
int n;
void sieve()
{
  for(int i=0;i<=300000;i++) mosat[i]=(i%7==1 || i%7==6) ? true : false;
  for(int i=0;i<=300000;i++) mprime[i]= (mosat[i]) ? true : false;
  for(int i=6;i<=300000;i++)
    {
      if(!mprime[i]) continue;
      for(int j=2;i*j<=300000;j++)
	{
	  if(mosat[j]) mprime[i*j]=false;
	}
    }
}
int main(int argc,char const* argv[])
{
  sieve();
  while(1)
    {
      cin >> n;
      if(n==1) break;
      cout << n << ":";
      for(int i=2;i<=n;i++)
	{
	  if(mprime[i] && n%i==0)
	    {
	      cout << " " << i;
	    }
	}
      cout << endl;
    }
  return 0;
}



Measured memory_bytes: 3568
package main

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

func main() {
	N, M := ReadInt(), ReadInt()
	uf := MakeUnionFind(N)
	for m := 0; m < M; m++ {
		x, y, _ := ReadInt()-1, ReadInt()-1, ReadInt()
		uf.Unite(x, y)
	}

	m := make(map[int]bool)
	for i := 0; i < N; i++ {
		m[uf.Root(i)] = true
	}
	fmt.Println(len(m))
}

type UnionFind []int

func MakeUnionFind(size int) UnionFind {
	parent := make([]int, size)
	for i := 0; i < size; i++ {
		parent[i] = i
	}
	return parent
}
func (uf UnionFind) Unite(x, y int) {
	x = uf.Root(x)
	y = uf.Root(y)
	if x != y {
		uf[x] = y
	}
}
func (uf UnionFind) Connected(x, y int) bool { return uf.Root(x) == uf.Root(y) }
func (uf UnionFind) Root(x int) int {
	if uf[x] == x {
		return x
	}
	uf[x] = uf.Root(uf[x])
	return uf[x]
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> bucket(n);
    for(int i=0;i<m;i++){
        int a,b;
        cin >> a >> b;
        bucket.at(a-1)++;
        bucket.at(b-1)++;
    }
    for(int i=0;i<n;i++) cout << bucket.at(i) << endl;
}

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

int main(){
    long long n,x,a,b,c,ans=0;
    cin >> n >> x;
    if(n%x==0 || n%(n-x)==0){
        cout << 3*max((n-x),x) << endl;
    }else if(2*x<n){
        a = n-x;
        b = x;
        c = a%b;
        while(c!=0){
            c = a%b;
            ans += (a-a%b)*2;
            a = b;
            b = c;
        }
        cout << ans + n - a << endl;
    }else{
        a = x;
        b = n-x;
        c = a%b;
        while(c!=0){
            c = a%b;
            ans += (a-a%b)*2;
            a = b;
            b = c;
        }
        cout << ans + n - a << endl;
    }
}


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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 200111, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    ll cnt1 = 0, cnt2 = 0;
    for (int j = k; j <= n; j += k) {
        ++cnt1;
    }
    if (k % 2 == 0) {
        for (int j = k / 2; j <= n; j += k) {
            ++cnt2;
        }
    }
    cout << cnt1 * cnt1 * cnt1 + cnt2 * cnt2 * cnt2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
ll dp[100010][4];//dp[i][j]:=長さi "ABCの個数"jコの文字列の個数
const string ABC = "ABC";
int N;
string s;
const int MOD = 1e9 + 7;
ll rec(int i, int j) {//rec(i,j):=i文字目以降ですでにjコあるとき、何通りの文字列
	if (dp[i][j] != -1) {
		return dp[i][j]%MOD;
	}
	//終了条件
	if (i == N) {//0インデックスで考えているから、すべての文字を見終わった後
		if (j == 3) {
			return 1;
		}
		else {
			return 0;
		}
	}
	ll res=0;
	if (j == 3) {
		if(s[i]=='?')res=(3*rec(i + 1, j)) % MOD;
		 else res=rec(i+1, j)%MOD;
	}
	
	else {
		if (s[i] == '?') {
			res = (rec(i + 1, j + 1) + 3 * rec(i + 1, j)) % MOD;
		}
		else if (s[i] == ABC[j]) {
			res = (rec(i + 1, j + 1) + rec(i + 1, j)) % MOD;
		}
		else if (s[i] != ABC[j]) {
			res = rec(i + 1, j) % MOD;
		}
	}
	dp[i][j] = res%MOD;
	return  res%MOD;
}
int main() {

	cin >> s;
	 N = s.size();
	 memset(dp, -1, sizeof(dp));
	dp[N][3] = 1;
	//int number = 0;
	//number++;
	
	cout << rec(0,0) << endl;
}

Measured memory_bytes: 8320
#include<bits/stdc++.h>
using namespace std;
int main()
{
	pair<pair<string,int>,int> p[120];
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		string s;
		cin>>s;
		int m;
		cin>>m;
		p[i] = make_pair(make_pair(s,-m),i+1);
	}
	sort(p,p+n);
	for (int i = 0; i < n; ++i)
	{
		cout<<p[i].second<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	
	int r = sc.nextInt();             //?????????????????§???
	int c = sc.nextInt();             //?????????????????§???
	int[][] num = new int[r+1][c+1] ; //??\?????????????????§???
	
	for(int i = 0; i < r ; i++) {
		for(int j = 0; j < c ; j++) {
		   num[i][j] = sc.nextInt();
		   
		   num[i][c] += num[i][j];  //?????°???????¨???§???
		   num[r][j] += num[i][j];  //?????°???????¨???§???
		   if(i < r & j < c)
		   num[r][c] += num[i][j];  //?????????????????°???????¨???§???
		   
		}
	 }
	
//???????????????????????????????????????	
	for(int i = 0; i < r+1 ; i++) {
		for(int j = 0; j < c ; j++) {
			System.out.print(num[i][j] + " ");
		}
		System.out.println(num[i][c]);   //?????????????????????????????°???????¨??????????????????????
	}
   sc.close();	
  }

}

Measured memory_bytes: 41176
import java.util.Arrays;
import java.util.Scanner;

class Solver {
	static final Solver INSTANCE = new Solver();

	void solve(Scanner sc) {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		Arrays.sort(A);

		int max = A[N - 1];
		int r = -1;
		int actual = -1;
		for (int i = 0; i < A.length - 1; i++) {
			int calc = max / 2 < A[i] ? max - A[i] : A[i];
			if (calc > r) {
				r = calc;
				actual = A[i];
			}
		}
		System.out.printf("%d %d\n", max, actual);
	}
}

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

		Solver.INSTANCE.solve(in);

		in.close();
	}
}

Measured memory_bytes: 52452
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(set(a)))
while len(a) > 1:
  b = a.pop(0)
  d = []
  for i in a:
    c = i%b
    if c != 0:
      d.append(c)
  a = sorted(list(set(d+[b])))
print(a[0])

Measured memory_bytes: 14480
import java.util.Scanner;
class Main 
{
  public static void main(String[] args)
  {
  	Scanner inp=new Scanner(System.in);
  	int K=inp.nextInt();
  	int T[]=new int[inp.nextInt()];
  	int a=0;
  	for(int i=0;i<T.length;i++)
  	{
  		T[i]=inp.nextInt();
  	}
  	a=T[0];
  	for(int i=0;i<T.length;i++)
  	{
  		if(a<T[i])a=T[i];
  	}
  	a=a+a-K-1;
  	if(a<0)a=0;
  	System.out.println(a);
  }
}

Measured memory_bytes: 9808
import java.util.Scanner;
 
public class Main {
	
	public static void main(String[] args) throws Exception{	
		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		
		int n = 0;
		String x = "";
		for(int i=0; i<s.length(); i++){
			if(!x.equals(s.substring(i, i+1))){
				x = s.substring(i, i+1);
				n++;
			}
		}
		
		System.out.println(n-1);
		
		sc.close();
	}
}

Measured memory_bytes: 22124
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let a:Vec<_> = s.trim().split(' ').collect();
    let n: usize = a[0].parse().unwrap();
    let m: usize = a[1].parse().unwrap();
    let mut ans = vec![0;n];
    for i in 0..m {
        let s = getline();
        let a:Vec<_> = s.trim().split(' ').collect();
        let x:usize = a[0].parse().unwrap();
        let y:usize = a[1].parse().unwrap();
        ans[x-1] += 1;
        ans[y-1] += 1;
    }
    for e in ans {
        println!("{}", e);
    }
}


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

int main()
{
    int n;
scanf("%i",&n);

for(int i=2;i>0;i--){
    n=n%(int)(pow(10,i));
}
    if((n==2)||(n==4)||(n==5)||(n==7)||(n==9)){
        printf("hon\n");
    }
    else if((n==0)||(n==1)||(n==6)||(n==8)){
        printf("pon\n");
    }
    else{
        printf("bon\n");
    }

    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int N; cin >> N;
  int a, b;
  vector<vector<int>> t(N);
  rep(i,N-1){
    cin >> a >> b;
    a--; b--;
    t[a].pb(b);
    t[b].pb(a);
  }
  vector<int>df(N); rep(i,N) df[i]=-1;
  queue<int> qf;
  qf.push(0); df[0]=0;
  while(!qf.empty()){
    int now = qf.front(); qf.pop();
    rep(i,sz(t[now])){
      if(df[t[now][i]]>=0) continue;
      qf.push(t[now][i]);
      df[t[now][i]] = df[now]+1;
    }
  }
  vector<int>ds(N); rep(i,N) ds[i]=-1;
  queue<int> qs;
  qs.push(N-1); ds[N-1]=0;
  while(!qs.empty()){
    int now = qs.front(); qs.pop();
    rep(i,sz(t[now])){
      if(ds[t[now][i]]>=0) continue;
      qs.push(t[now][i]);
      ds[t[now][i]] = ds[now]+1;
    }
  }
  int f=0;
  rep(i,N){
    //cout << df[i] << " " << ds[i] << endl;
    if(df[i]<=ds[i]) f++;
  }
  int s=N-f;
  if(f>s) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 6528
A, B, C = map(int, input().split())
K = int(input())


# C > B > A
for i in range(K):
    if C >= A and A >= B:
        # C >= A >= B
        B = B * 2
    else:
        C = C * 2

if C > B and B > A:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9112
fun main() = abc165a()

@OptIn(ExperimentalStdlibApi::class)
fun abc165a() {
    val k = readLine()!!.toInt()
    val (a, b) = readLine()!!.split(' ').map { it.toInt() }

    val list = (1..2000).map { it * k }

    val answer = if (list.any { it in a..b }) "OK" else "NG"

    println(answer)
}


Measured memory_bytes: 36636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[102][100002];

ll knapsack1(ll v[], ll w[], ll W, ll n){
	if(n==0 || W==0)
		return 0;
	
	if(dp[n][W]!=-1)
		return dp[n][W];

	if(w[n]<=W)
		return dp[n][W] = max(v[n] + knapsack1(v,w,W-w[n],n-1), knapsack1(v,w,W,n-1));
	else
		return dp[n][W] = knapsack1(v,w,W,n-1);
}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,W;
    cin>>n>>W;
    ll w[n+1],v[n+1];
    for(int i=1;i<=n;i++){
    	cin>>w[i]>>v[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<knapsack1(v,w,W,n);
}


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

int S,T,U,N,O,D;
int e[100], c[100];
int a[100], h[100];
int dp1[101][101][101], dp2[10100], dp3[101][101];

int main(){
  cin >> S >> T >> U >> N >> O >> D;

  int C = 0;
  for(int i=0;i<T;i++)cin >> e[i] >> c[i], C += c[i];
  for(int i=0;i<N;i++)cin >> h[i] >> a[i];

  memset(dp1,-1,sizeof(dp1));
  dp1[0][0][0] = 0;
  for(int i=0;i<T;i++){
    for(int j=0;j<=U;j++){
      for(int k=0;k<=S;k++){
	if(dp1[i][j][k] < 0)continue;
	dp1[i+1][j][k] = max(dp1[i+1][j][k], dp1[i][j][k]);
	if(j+1<=U && k+e[i]<=S){
	  dp1[i+1][j+1][k+e[i]] = max(dp1[i+1][j+1][k+e[i]], dp1[i][j][k] + c[i]);
	}
      }
    }
  }

  memset(dp2,0,sizeof(dp2));
  for(int i=0;i<N;i++){
    for(int j=0;j<=C;j++){
      if(j+a[i]<=C)dp2[j+a[i]] = max(dp2[j+a[i]], dp2[j] + h[i]);
    }
  }

  memset(dp3,-1,sizeof(dp3));
  dp3[0][S] = 0;
  for(int i=0;i<D;i++){
    for(int j=0;j<=S;j++){
      if(dp3[i][j]<0)continue;
      for(int k=0;k<=j;k++){
	if(dp1[T][U][k]<0)continue;
	int nextS = min(S, j-k+O);
	dp3[i+1][nextS] = max(dp3[i+1][nextS], dp3[i][j] + dp2[dp1[T][U][k]]);
      }
    }
  }

  int res = -1;
  for(int i=0;i<=S;i++)res = max(res, dp3[D][i]);
  cout << res << endl;
}

Measured memory_bytes: 5276
from sys import stdin
n=int(stdin.readline())
ans=0
now=list(map(int,stdin.readline().split()))
a=0
for i in range(len(now)-1):
    if now[i]>=now[i+1]:
        a+=1
    else :
        a=0
    # print(a)
    ans=max(ans,a)
print(ans)

Measured memory_bytes: 14252