akhauriyash/Code-Regression huggingface dataset:
import sys
from heapq import heapify, heappop, heappush

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    Edge = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        Edge[a-1].append(b-1)
        Edge[b-1].append(a-1)

    Direc = [-1] * N
    q = []
    heapify(q)
    heappush(q, (0, 0, 0))
    while q:
        dist, now, pre = heappop(q)
        if Direc[now] == -1:
            Direc[now] = pre + 1
            for ne in Edge[now]:
                if ne != pre: heappush(q, (dist + 1, ne, now))
    print("Yes")
    print("\n".join(map(str, Direc[1:])))

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 49664
n,d = map(int, input().split())
L = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n):
  for k in range(i+1,n):
    dist = 0
    for v in range(d):
      dist += (L[i][v]-L[k][v])**2
    if (dist**0.5).is_integer():
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <stdio.h> 
#include <stdlib.h> 

int main(void){ 

  int i,j,k; 
  int count1,count2;  
  int str[10000]; 
  int ans[100]; 
  int max=0; 
  int min=0; 

  scanf("%d", &i); 
  for(count1=0; count1<i; count1++){ 
    scanf("%d",&j); 

    for(count2=0; count2<j; count2++){ 
      scanf("%d",&str[count2]);   
      if(count2>0){ 
 ans[count2-1]=str[count2]-str[count2-1]; 
      } 
    } 
     
    for(k=0; k<j-1; k++){ 
      if(ans[k]>max){ 
 max=ans[k]; 
      } 
      if(ans[k]<min){ 
 min=ans[k]; 
      } 
    } 
     
    printf("%d %d\n",max,abs(min)); 
    max=0; 
    min=0; 
  } 
  return 0; 
}


Measured memory_bytes: 2600
import numpy as np
N, L = map(int, input().split())
A = [L + i for i in range(N)]
v = min(np.abs(A))
b = 0
for j in range(N):
    b += A[j]
if A.count(v) >= 1:
    print(b-v)
else:
    print(b+v)

Measured memory_bytes: 12428
N = int(input())
N_1 = N + 1
hs = [0] + [int(h) for h in input().split()]

dp = [0] * N_1
dp[2] = abs(hs[1] - hs[2])

for i in range(3, N_1):
    cost_1 = dp[i - 1] + abs(hs[i] - hs[i - 1])
    cost_2 = dp[i - 2] + abs(hs[i] - hs[i - 2])
    dp[i] = min(cost_1, cost_2)

print(dp[-1])


Measured memory_bytes: 52208
fun main(args: Array<String>) {
    val aArray = LongArray(readLine()!!.toInt()) {
        readLine()!!.toLong()
    }

    val maxVal = aArray.max()
    val tempList = aArray.toMutableList()
    tempList.remove(maxVal)
    val secondVal = tempList.max()
    repeat(aArray.size) { i ->
        if (aArray[i] == maxVal) println(secondVal) else println(maxVal)
    }
}


Measured memory_bytes: 57968
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        char op = scanner.next().charAt(0);
        int b = scanner.nextInt();

        switch (op) {
            case '+':
                System.out.println(a + b);
                break;
            case '-':
                System.out.println(a - b);
                break;
        }
    }
}

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

using namespace std;
typedef unsigned long long int ll;
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}

int main()
{
    int n;
    cin>>n;
    int  total =0;
    for(int  i=1;i<=(1e7);i++)
    {
        total = (total*10 + 7)%n;
        if(total==0)
        {
            cout<<i;
            return 0;
        }
    }
    cout<<"-1";
    return 0;


}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+110;
const long long mod = 998244353;
typedef long long ll;

int n;
ll a[maxn];
ll _abs(ll x)
{
    if(x<0)return -x;
    return x;
}

int main()
{
    scanf("%d", &n);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld", &a[i]);
    }
    sort(a+1, a+n+1);
    if(n==2)
    {
        printf("%lld\n" , a[2]-a[1]);
        return 0;
    }
    int l=2, r=n-2;
    ll sum=a[n]-a[1]+a[n-1]-a[1];
    ll left=a[n-1];
    ll right=a[n];
    int cnt=0;
    while(l<=r)
    {
        if(cnt==1)
        {
            sum += _abs(left-a[l]);
            left=a[l];
            ++cnt;
            ++l;
        }
        else if(cnt==0)
        {
            sum += _abs(right-a[l]);
            right = a[l];
            ++l;
            ++cnt;
        }
        else if(cnt==3)
        {
            sum += _abs(left-a[r]);
            left=a[r];
            --r;
            ++cnt;
        }
        else if(cnt==2)
        {
            sum += _abs(right-a[r]);
            right=a[r];
            --r;
            ++cnt;
        }
        cnt%=4;
    }
    ll ans = 0;
    left=a[n], right=a[n];
    l=1, r=n-1;
    cnt=0;
    while(l<=r)
    {
        if(cnt==0)
        {
            ans += _abs(right-a[l]);
            right=a[l];
            l++;
            cnt++;
        }
        else if(cnt==1)
        {
            ans += _abs(left-a[l]);
            left=a[l];
            l++;
            cnt++;
        }
        else if(cnt==2)
        {
            ans += _abs(right-a[r]);
            right=a[r];
            --r;
            cnt++;
        }
        else if(cnt==3)
        {
            ans += _abs(left-a[r]);
            left=a[r];
            --r;
            cnt++;
        }
        cnt%=4;
    }
    printf("%lld\n", max(sum , ans));
    return 0;

}


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

public class Main {

    public static void main(String[] args) {

        // 入力データの取得
        Scanner scanner = new Scanner(System.in);
        StringBuilder inputStringData = new StringBuilder(scanner.nextLine());
        int repeatNum = scanner.nextInt();
        boolean reverseFlag = false;
        int frontCount = 0;
        int backCount = 0;
        ArrayList<String> addFrontList = new ArrayList<>();
        ArrayList<String> addBackList = new ArrayList<>();
        for (int count = 0; count < repeatNum; count++) {
            if (scanner.nextInt() == 1) {
                reverseFlag = !reverseFlag;
            } else {
                int judgmentNum = scanner.nextInt();
                if (!reverseFlag) {
                    if (judgmentNum == 1) {
                        addFrontList.add(scanner.next());
                        frontCount++;
                    } else {
                        addBackList.add(scanner.next());
                        backCount++;
                    }
                } else {
                    if (judgmentNum == 1) {
                        addBackList.add(scanner.next());
                        backCount++;
                    } else {
                        addFrontList.add(scanner.next());
                        frontCount++;
                    }
                }
            }
        }
        scanner.close();

        // 結果の処理
        StringBuilder displayStringBuilder = new StringBuilder();
        if (reverseFlag) {
            for (int index = backCount - 1; index >= 0; index--) {
                displayStringBuilder.append(addBackList.get(index));
            }
            displayStringBuilder.append(inputStringData.reverse().toString());
            for (int index = 0; index < addFrontList.size(); index++) {
                displayStringBuilder.append(addFrontList.get(index));
            }
        } else {
            for (int index = frontCount - 1; index >= 0; index--) {
                displayStringBuilder.append(addFrontList.get(index));
            }
            displayStringBuilder.append(inputStringData.toString());
            for (int index = 0; index < addBackList.size(); index++) {
                displayStringBuilder.append(addBackList.get(index));
            }
        }

        // 結果の出力
        System.out.println(displayStringBuilder.toString());

    }

}

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

int main()
{
  int n, m;
  cin >> n;
  int i, j;
  vector<string> s(n);
  for(i = 0; i < n; i++)
  {
    cin >> s.at(i);
  }
  cin >> m;
  vector<string> t(n+m);
  for(i = 0; i < n+m; i++)
  {
    if(i < n)
    {
      t.at(i) = s.at(i);
    }
    else
    {
      cin >> t.at(i);
    }
  }
  int max = 0;
  int value = 0;
  for(i = 0; i < n+m; i++)
  {
    for(j = 0; j < n+m; j++)
    {
      if(t.at(i) == t.at(j) && i!= j)
      {
        if(j < n) value++;
        else value--;
      }
    }
    if(i < n) value++;
    else value--;
    if(value > max) max = value;
    value = 0;
  }
  cout << max << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;
	int n, m;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			n = sc.nextInt(); m = sc.nextInt();
			if( (n|m) == 0) break;
			
			int[][] cost, time;
			cost = new int[m][m]; time = new int[m][m];
			for(int[] a: cost) fill(a, INF);
			for(int[] a: time) fill(a, INF);
			
			
			for(int i=0;i<n;i++) {
				int x = sc.nextInt()-1, y = sc.nextInt() -1,
					c = sc.nextInt(), t = sc.nextInt();
				cost[x][y] = cost[y][x] = min(cost[x][y], c);
				time[x][y] = time[y][x] = min(time[x][y], t);
			}
			
			int k = sc.nextInt();
			for(int i=0;i<k;i++) {
				int p = sc.nextInt()-1, q = sc.nextInt()-1, r = sc.nextInt();
				if(r == 0) 
					System.out.println(dijkstra(p, cost)[q]);
				else 
					System.out.println(dijkstra(p, time)[q]);
			}
		}
	}
	
	int[] dijkstra(int s, int[][] data ) {
		int d[] = new int[m];
		fill(d, INF); d[s] = 0;
		boolean[] used = new boolean[m];
		for(;;) {
			int v = -1;
			for(int i=0;i<m;i++) if(!used[i] && ( v==-1 || d[i] < d[v] )) {
				v = i;
			}
			
			if(v == -1) break;
			used[v] = true;
			
			for(int u=0;u<m;u++) {
				d[u] = min(d[u], d[v] + data[v][u]);
			}
		}
		return d;
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

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

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> T;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        T[A[i]]++;
    }
    sort(A.rbegin(), A.rend());

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if (!T[A[i]]) continue;
        ll j = 1;
        for(; j <= A[i]; j *= 2) {}
        if (A[i] != j - A[i] && T[j - A[i]] > 0) {
            T[j - A[i]]--;
            T[A[i]]--;
            ans++;
        } else if (A[i] == j - A[i] && T[A[i]] >= 2) {
            T[A[i]] -= 2;
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 26880
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var xy = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var result = 0;

        if (xy[0] < xy[1])
        {
            if (Abs(xy[0]) >= Abs(xy[1])) result += xy[1]<=0?xy[1]-xy[0]:1-xy[1] - xy[0];
            else result += xy[0]>=0?xy[1]-xy[0]:1+xy[1] - Abs(xy[0]);
        }
        else
        {
            if (Abs(xy[0]) <= Abs(xy[1])) result += xy[0] < 0 ? 2 - xy[1] + xy[0] : -xy[1] - xy[0] + 1;
            else result += xy[1] <= 0 ? 1 + xy[1] + xy[0] : 2 + xy[0] - xy[1];
        }
        WriteLine(result);
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
 
using namespace std;
 
#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
 
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int N = 1e5 + 10;
int main()
{
    fast_cin();
    string s, t;
    int n;
    cin>>n;
    cin>>s>>t;
    for(int i=0;i<s.size();i++) {
        cout<<s[i]<<t[i];
    }


} 

Measured memory_bytes: 256
//https://atcoder.jp/contests/abc055/tasks/arc069_b
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
#if LOCAL&0
    std::ifstream in("./test/sample-1.in"); //input.txt
    std::cin.rdbuf(in.rdbuf());
#else
    cin.tie(0);
    ios::sync_with_stdio(false);
#endif
    ll N; cin>>N;
    string s; cin>>s;
    vector<bool> sw(N+1); //trueだと狼
	auto sheep = [&](ll p)->bool {
        ll prev = p-1;
        if(prev<0) prev += N;
		if(s.at(p) == 'o') {
            return sw.at(prev);
		} else {
            return !sw.at(prev);
		}
	};
	auto get_next = [&](ll p)->bool {
        return sw.at(p)==false ? sheep(p) : !sheep(p);
	};
    //fillsw
    auto fill_sw = [&](){
        for(ll i=1;i<N;++i){
            sw.at(i+1) = get_next(i);
        }
    };

    auto check_and_ans = [&](){
        fill_sw();
        if (sw.at(0)==sw.at(N) && get_next(0)==sw[1]){
            REP(i,N){
                cout<<(sw.at(i)?"W":"S");
            }
            cout<<endl;
            exit(0);
        }
    };

    sw[0]=true; sw[1]=false;
    check_and_ans();
    sw[0]=true; sw[1]=true;
    check_and_ans();

    sw[0]=false; sw[1]=false;
    check_and_ans();
    sw[0]=false; sw[1]=true;
    check_and_ans();

    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 592
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

d,n = LI()
ans = n*100**d
if n % 100 == 0:
    ans += 100**d
print(ans)

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    string S, T;
    cin >> S >> T;

    bool ok = false;
    for (ll i = 0; i < (ll)S.size(); i++) {
        ok |= S == T;
        rotate(T.begin(), T.begin() + 1, T.end());
    }

    cout << (ok ? "Yes\n" : "No\n");
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}

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

int main(){
    int i;
    int o = 0;
    string s,t;
    cin>>s>>t;
    for (i=0;i<s.size();i++){
        if (s[i]!=t[i]){
            o++;
        }
    }
    cout<<o<<endl;
}


Measured memory_bytes: 3908
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#define INT long long
#define oo 99999987654321LL
using namespace std;

INT n, a[200020];
struct JK{ INT v, cnt; };
stack<JK> st;
INT ans, sum;

int main()
{
    cin>>n;
    for(int i = 0 ; i < n ; i++ )
        scanf("%lld", &a[i]);
    for(int i = n-1 ; i >= 0 ; i-- )
    {
        INT cnt = 1;
        while( !st.empty() && a[i] < st.top().v ) cnt+=st.top().cnt, sum -= (st.top().v*st.top().cnt), st.pop();
        st.push((JK){a[i], cnt}), sum += a[i]*cnt;
        ans += sum;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main() {
  int n, m, i, maxl = 0, minr = 100000;
  cin >> n >> m;
  
  vector<int> l(m), r(m);
  for(i = 0; i < m; i++){
    cin >> l.at(i) >> r.at(i);
    maxl = max(maxl, l.at(i));
    minr = min(minr, r.at(i));
  }
  
  if(maxl > minr){
    cout << 0 << endl;
  }
  else{
    cout << minr - maxl + 1 << endl;
  }
}


Measured memory_bytes: 1024
w,h,n=map(int,input().split())
x=y=0
for i in range(n):
  xi,yi,a=map(int,input().split())
  if a==1:
    x=max(x,xi)
  elif a==2:
    w=min(w,xi)
  elif a==3:
    y=max(y,yi)
  elif a==4:
    h=min(h,yi)    
print(0 if x>=w or y>=h else (w-x)*(h-y))


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

typedef long long ll;

typedef pair<ll, int> p;

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

    int x, y, a = 0, b = 0;
    cin >> x >> y;

    if(x != 2) {
        if(x == 4 || x == 6 || x == 9 || x == 11) a++;
        else b++;
    }
    if(y != 2) {
        if(y == 4 || y == 6 || y == 9 || y == 11) a++;
        else b++;
    }

    if(a == 2 || b == 2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
// Bismillah .Ya Allah...
#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
typedef pair<int,int> PII;
const int mod = 1e9+7,INF = 1e9;
const int mx = 2e5+5;
int a[mx],b[mx];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    ll k, ans =0;
    for(int i=1;i<=n;i++)
    {
        k = n/i;
        k = k*(k+1)/2;
        ans+= i*k;
    }
     cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
//constexpr ll MOD = 998244353;
//constexpr ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
constexpr ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

int main()
{
  ll N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;

  vector<vector<ll>> dist(N, vector<ll>(N, INF));

  for (ll s = 0; s < N; s++)
  {
    vector<bool> visited(N, false);
    visited.at(s) = true;
    queue<pair<ll, ll>> que;
    que.push(make_pair(s, 0));
    while (!que.empty())
    {
      ll v = que.front().first, d = que.front().second;
      que.pop();

      chmin(dist.at(s).at(v), d);
      chmin(dist.at(v).at(s), d);

      if (v == X && !visited.at(Y))
      {
        que.push(make_pair(Y, d + 1));
        visited.at(Y) = true;
      }
      if (v == Y && !visited.at(X))
      {
        que.push(make_pair(X, d + 1));
        visited.at(X) = true;
      }
      if (v != 0 && !visited.at(v - 1))
      {
        que.push(make_pair(v - 1, d + 1));
        visited.at(v - 1) = true;
      }
      if (v != N - 1 && !visited.at(v + 1))
      {
        que.push(make_pair(v + 1, d + 1));
        visited.at(v + 1) = true;
      }
    }
  }

  vector<ll> ans(N, 0);
  for (ll i = 0; i < N; i++)
  {
    for (ll j = i + 1; j < N; j++)
    {
      ans.at(dist.at(i).at(j))++;
    }
  }
  
  for (ll i = 1; i <= N - 1; i++)
  {
    cout << ans.at(i) << endl;
  }

  /*
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < N; j++)
    {
      cerr << dist.at(i).at(j) << " ";
    }
    cerr << endl;
  }
  //*/
}

Measured memory_bytes: 31616
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
    long long X;
    long long ans = 0;
    // freopen("in.in", "r", stdin);
    scanf("%lld", &X);
    while (ans * (ans + 1) < 2 * X) {
        ++ans;
    }
    printf("%lld", ans);
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
int C[101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>K;
	FOR(i,K) {
		cin>>x;
		FOR(j,x) {
			cin>>y;
			C[y-1]++;
		}
	}
	int ret=0;
	FOR(i,N) if(C[i]==0) ret++;
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3636
N = int(input())
a_list = list(map(int, input().split()))

ans_list = [0]*N

not1_list = [ a_list[i] for i in range(1, N, 2) ]
ans_list[0] = sum(a_list) - 2 * sum(not1_list)
for i in range(1,N):
  ans_list[i] = a_list[i-1] * 2 - ans_list[i-1]
print(*ans_list)

Measured memory_bytes: 14104
def d(pair, a, b)
  f = pair[0]
  s = pair[1]
  ma = (s - f) * a
  ma < b ? ma : b
end

i = gets.chomp.split(' ')
N = i[0].to_i
A = i[1].to_i
B = i[2].to_i

xs = gets.chomp.split(' ').map(&:to_i)

t = 0
xs.each_cons(2) do |pair|
  t += d(pair, A, B)
end

puts t


Measured memory_bytes: 12044
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define pb push_back
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

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

  ll n;
  string s;
  cin >> n >> s;

  ll r = 0, g = 0, b = 0;
  for(ll i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
    if(s[i] == 'B') b++;
  }
  ll sum = r * g * b;
  //cout << sum << endl;

  for(ll i = 0; i < n-2; i++){
    for(ll j = i+1; j < n-1; j++){
      if(j+j-i < n && s[i] != s[j] && s[j] != s[j+j-i] && s[j+j-i] != s[i]) sum--;
    }
  }
  cout << sum << endl;
  return 0;
}

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

int main() {
    string s;
    cin >> s;
    if(s[0]=='7'){
        cout << "Yes" << endl;
        return 0;
    }
    if(s[1]=='7'){
        cout << "Yes" << endl;
     return 0;
    }
    if(s[2]=='7'){
        cout << "Yes" << endl;
     return 0;
    }
    cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 3620
x1, y1, x2, y2 = map(int, input().split())
x = x2 - x1
y = y2 - y1
x3 = x2 - y
y3 = y2 + x
x4 = x3 - x
y4 = y3 - y
print(x3, y3, x4, y4)

Measured memory_bytes: 3060
N, T = map(int, input().split())
ct = [list(map(int, input().split())) for _ in range(N)]
ans = []
for c, t in ct:
    if t <= T:
        ans.append(c)
if len(ans) > 0:
    print(min(ans))
else:
    print('TLE')
    

Measured memory_bytes: 2940
# include <bits/stdc++.h>
# define sz(x) (int)((x).size())
# define F first
# define S second
# define pb push_back
# define ub upper_bound
# define lb lower_bound
# define end(x) prev(x.end());
# define all(x) x.begin(), x.end()
# define rall(x) x.rbegin(), x.rend()
# define pqueue priority_queue
# define mset multiset
# define umap unordered_map
# define Speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
# define rep(i,n) for(int i=0;i<n;++i)
# define forn(i,n) for(int i=1;i<=n;++i)
# define lr(i,l,r) for(int i=l;(l>r?i>=r:i<=r);(l>r?--i:++i))

using namespace std;

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

const int MOD = 1e9+7;
const int N = 2e5+5;

void solve(){
	int n;
	cin>>n;
	vector<int>a(n);
	rep(i,n)cin>>a[i];
	ll ans=0;
	for(int i=1;i<n;++i){
		if(a[i]<a[i-1]){
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	cout<<ans;
}

int main(){
	Speed();
	int T=1; 
	//cin>>T;	
	while(T--)
		solve();
	return 0;
}

Measured memory_bytes: 3912
#include <iostream>
#include <string>
#include <typeinfo>
#include <cctype>
#include <algorithm>

using namespace std;

int main(){
  string n;
  int a;
  int b;
  string c;
  string d;

  cin >> a;
  cin >> b;
  cin >> n;

  c = n[a];
  if (c=="-"){
    d=n.erase(a,1);
    if(all_of(d.cbegin(),d.cend(),::isdigit))
      {
       	cout << "Yes" << endl;
      }
    else {
      cout << "No" << endl;
    }
  }
  else {
    cout << "No" << endl;
    }
  return(0);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cassert>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define mp make_pair
#define fi first
#define se second
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

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

    int n, k;

    cin >> n >> k;

    if (k * 2 - 1 <= n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 
#define int long long

int n;
const int N=1e5+5;
int a[N],b[N],c[N];

int dp[N][3];

int f(int i,int prev){

    if(i>=n)
        return 0;

    if(dp[i][prev])
        return dp[i][prev];

    if(prev==0)
        dp[i][prev]=max(b[i]+f(i+1,1),c[i]+f(i+1,2));
    else if(prev==1)
        dp[i][prev]=max(a[i]+f(i+1,0),c[i]+f(i+1,2));
    else
        dp[i][prev]=max(a[i]+f(i+1,0),b[i]+f(i+1,1));

    return dp[i][prev];
}

int32_t main(){
 
    IOS;
    
    cin>>n;

    for(int i=0;i<n;i++)
        cin>>a[i]>>b[i]>>c[i];
    
    int ans=max({f(0,0),f(0,1),f(0,2)});

    cout<<ans;

}

Measured memory_bytes: 9600
#include <iostream>
#include <set>

using namespace std;

int main(void){
  set<int> A{ 1, 3, 5, 7, 8, 10, 12, -1};
  set<int> B = {4, 6, 9, 11, -1};
  set<int> C = {2, -1};
  int x, y;
  cin >> x >> y;

  if(A.find(x) != A.end() &&  A.find(y) != A.end())
    cout << "Yes" << endl;
  else if(B.find(x) != B.end() &&  B.find(y) != B.end())
    cout << "Yes" << endl;
  else if(C.find(x) != C.end() &&  C.find(y) != C.end())
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  contest
//
//  Created by TmpGuest on 2020/4/18.
//  Copyright © 2020 TmpGuest. All rights reserved.
//

#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
int main() {
ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    while(true) {
        c-=b;
        if(c<=0)
        {
            cout<<"Yes\n";
            break;
        }
        a-=d;
        if(a<=0) {
            cout<<"No\n";
            break;
        }
    }
        
    
    return 0;
}


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

int main() {
   int N;
   cin >> N;
   int A[N];
   for (int i=0; i<N; i++) {
       cin >> A[i];
   }
   sort(A,A+N);
   int count=0;
   for (int i=0; i<N; i++) {
       if (i==0) {
           if (A[0]==1 && A[1]>1) {
               cout << 1 << endl;break;
           }
           if (A[0]==1 && A[1]==1) {
               cout << 0 << endl;break;
           }
       }
       if (i!=0 && A[i]==A[i-1]) count++;
       else if (i!=N-1 && A[i]==A[i+1]) count++; 
       else {
           for (int j=2; j<=sqrt(A[i]); j++) {
               if (A[i]%j==0) {
                   if (j==*lower_bound(A,A+i,j) || A[i]/j==*lower_bound(A,A+i,A[i]/j)) {
                       count++;break;
                   }
               }
           }
       }
       if (i==N-1) cout << N-count << endl;
   }
}

Measured memory_bytes: 4400
#include <stdio.h>

#define N 100

int main(void){
    int dx[] = {0,1,0,-1};
    int dy[] = {-1,0,1,0};
    int map[N+2][N+2];
    int datas,d,dd,n;
    int x,y;
    
    scanf("%d", &datas);
    for (int i=0; i<datas; i++){
        // get size
        scanf("%d", &n);
        // reset map
        for (int xx=0; xx<n+2; xx++){
            for (int yy=0; yy<n+2; yy++){
                if (xx==0 || xx==n+1 || yy==0 || yy==n+1){
                    map[xx][yy]=-1;
                }else {
                    map[xx][yy]=0;
                }
            }
        }
        x=1; y=n; d=0; dd=1;
        // set spiral
        while(1){
            map[x][y]=1;
            if (map[x+dx[d]][y+dy[d]]==0){
                map[x+dx[dd]][y+dy[dd]]=-1;
            } else{
                if (map[x+dx[dd]][y+dy[dd]]==-1){
                    break;
                }else{
                    d = (d+1)%4;
                    dd = (dd+1)%4;
                }
            }
            x += dx[d];
            y += dy[d];
        }
        // output
        for (int yy=1; yy<=n; yy++){
            for (int xx=1; xx<=n; xx++){
                printf(map[xx][yy]==1?"#":" ");
            }
            printf("\n");
        }
        if (i<datas-1) printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 1052
#include<iostream>
int main () {
int a , b;
std::cin >> a >> b;
if(a<b){
std::cout<<"a < b"<<std::endl;
}
else if (a>b){
std::cout<<"a > b"<<std::endl;
}
else{
std::cout<<"a == b"<<std::endl;
}
return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int n; cin >> n;
	map<int, int> M;
	int num;
	for(int i=0; i<n; i++){
		cin >> num;
		M[num]++;
	}
	auto it = M.begin();
	int cont = 0;
	for(; it != M.end(); it++){
		if((*it).first < (*it).second)
			cont += (*it).second - (*it).first;
		else if ((*it).first > (*it).second)
			cont += (*it).second;
	}
	cout << cont;
	
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define FO(i,a,b) for (int i = (a); i < (b); i++)

int H, W;
int am[30];
int amsyms[5];
int main() {
    scanf ("%d %d", &H, &W);
    FO (i,0,H) FO(j,0,W) {
        char ch;
        scanf (" %c", &ch);
        am[ch-'a']++;
    }
    FO (i,0,H) {
        if (i*2 > H-1) continue;
        FO (j,0,W) {
            if (j*2 > W-1) continue;
            int syms = 1;
            if (i*2 != H-1) syms *= 2;
            if (j*2 != W-1) syms *= 2;
            amsyms[syms]++;
        }
    }
    FO (i,0,26) {
        for (int m = 4; m >= 1; m--) {
            while (am[i] >= m && amsyms[m]) {
                amsyms[m]--;
                am[i] -= m;
            }
        }
    }
    FO (i,1,5) {
        if (amsyms[i]) {
            printf ("No\n");
            return 0;
        }
    }
    printf ("Yes\n");
    return 0;
}


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

public class Main {

	static int n;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[n];
		for(int i = 0 ; i < n ; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			b[i] = sc.nextInt();
		}
		for(int i = 0 ; i < n ; i++) {
			c[i] = sc.nextInt();
		}
		long ans = 0;
		Arrays.sort(a);
		Arrays.sort(c);
		for(int i  = 0 ; i < n ; i++) {
			ans += 1L * binary_search(a, b[i]) * binary_search2(b[i], c);
		}
		System.out.println(ans);
	}

	public static int binary_search(int[] a, int x) {
		int l = 0;
		int r = n;
		while(r - l >= 1) {
			int i = (l + r) / 2;
			if(x <= a[i]) r = i;
			else l = i + 1;
		}
		return l;
	}

	public static int binary_search2(int x, int[] c) {
		int l = 0;
		int r = n;
		while(r - l >= 1) {
			int i = (l + r) / 2;
			if(x >= c[i]) l = i + 1;
			else r = i;
		}
		return n - l;
	}
}


Measured memory_bytes: 94200
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

const ll INF = 1LL << 50;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    vector<ll> X(N);
    for (auto& x : X) {
        cin >> x;
    }
    ll ans = INF;
    rep(i, 0, N) {
        if (i + K - 1 < N) {
            chmin(ans, abs(X[i]) + abs(X[i + K - 1] - X[i]));
        }
        if (i - K + 1 >= 0) {
            chmin(ans, abs(X[i]) + abs(X[i] - X[i - K + 1]));
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n, b[52],c[52] = {0};
    char a[52];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    for (int i = 0; i < n; i++){
        switch (a[i]){
            case 'S':
            c[b[i]-1] = 1;
            break;
            case 'H':
            c[12 + b[i]] = 1;
            break;
            case 'C':
            c[25 + b[i]] = 1;
            break;
            case 'D':
            c[38 + b[i]] = 1;
            break;
        }
    }
    for (int i = 0; i < 52; i++){
        if ( i < 13){
            if( c[i] == 0){
                cout << "S " << i + 1 << endl;
            }
        }else if (i < 26){
            if( c[i] == 0){
                cout << "H " << i - 12 << endl;
            }
        }else if (i < 39){
             if( c[i] == 0){
                cout << "C " << i - 25 << endl;
            }
        }else {
            if( c[i] == 0){
                cout << "D " << i - 38 << endl;
            }
        }
    }
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	int bob = 0;
	int alice =0;
	
	rep(i, n){
		cin >> a.at(i);
		bob += a.at(i);
	}

	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	for(int i = 0; i < n; i+=2){
		alice += a.at(i);
	}
	
	bob -= alice;
	cout << alice - bob << endl;
}

Measured memory_bytes: 256
import sys
n=int(input())
ans=False
if n%7==0 or n%4==0:
        ans=True
        print('Yes' if ans else 'No')
        sys.exit()

for i in range(n//4+1):
    total=0
    for j in range(n//7+1):
       total=4*i+7*j
       if total==n:
           ans=True
           break
print('Yes' if ans else 'No')

Measured memory_bytes: 3060
N, K = map(int, input().split())
p = list(map(int, input().split()))

S = sum(p[0:K])
max_S = S
for i in range(N - K):
    S += p[i + K] - p[i]
    max_S = max(S, max_S)
print((max_S + K) / 2)


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

int main(){
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int MAX = 0;
  if(A >= K)
    MAX += K;
  else{
    MAX += A;
    if(B >= K - A)
      MAX += 0;
    else
      MAX -= K - A - B;
  }
  cout << MAX << endl;
}

Measured memory_bytes: 3636
n = int(input())
p = list(map(int, input().split()))
count = 0
for i in range(n):
    if n-i >=3:
        a = []
        a.append(p[i])
        a.append(p[i+1])
        a.append(p[i+2])
        a = sorted(a)
        if a[1] == p[i+1]:
            count = count + 1
print(count)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
 
int main() {
	int num[10000] = {};
	int sa = 0;
	std::cin >> num[0] >> num[1] >> num[2];
	std::sort(num, num + 3);
	sa = (num[2] - num[1]) + (num[2] - num[0]);
	if (sa % 2 == 0) {
		std::cout << sa / 2 << std::endl;
	}
	else {
		std::cout << (sa + 3) / 2 << std::endl;
	}
}

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

namespace _0105
{
    class Program
    {
        static void Main(string[] args)
        {
            SortedDictionary<string,List<int>> dic = new SortedDictionary<string,List<int>>();
            while (true)
            {
                string s = Console.ReadLine();
                if (string.IsNullOrEmpty(s)) break;
                string[] x = s.Split();
                if (!dic.ContainsKey(x[0])) dic[x[0]] = new List<int>();
                dic[x[0]].Add(int.Parse(x[1]));
            }
            foreach (var i in dic)
            {
                Console.WriteLine(i.Key);
                var x = i.Value.ToArray();
                Array.Sort(x);
                Console.Write(x[0]);
                for (int j = 1; j < x.Count(); j++) Console.Write(" " + x[j]);
                Console.WriteLine();
            }
        }
    }
}


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<vector<char>> table(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> table.at(i).at(j);
    }
  }
/*
1.行整理。
#があったらbreak
・空白行だったら、Hcカウント
・#があったらHc-と交換
2.列整理。*/
  //1.
  int Hc=0;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(Hc==0){//空白を見つけていない
        if(table.at(i).at(j)=='#'){
          break;}
        if(j==W-1){//すべて'.'を検出
          Hc++;
        }
      }
      else{//Hc>=1 1回でも空白行を検出したあと
        //もし#があれば交換。なければHcをカウント。
        if(table.at(i).at(j)=='#'){
          for(int j=0; j<W; j++){
            table.at(i-Hc).at(j)=table.at(i).at(j);
            table.at(i).at(j)='.';
          }
          break;
        }
        else if(j==W-1){//空白行だった場合
          Hc++;
        }
      }
    }
  }
  //2.列整理、Hc行は検出しなくてOK
  int Wc=0;
  for(int i=0; i<W; i++){//列固定
    for(int j=0; j<H-Hc; j++){//行探索
      if(Wc==0){//空白を見つけていない
        if(table.at(j).at(i)=='#'){
          break;}
        if(j==H-1-Hc){//すべて'.'を検出
          Wc++;
        }
      }
      else{//Wc>=1 1回でも空白行を検出したあと
        //もし#があれば交換。なければHcをカウント。
        if(table.at(j).at(i)=='#'){
          for(int j=0; j<H-Hc; j++){
            table.at(j).at(i-Wc)=table.at(j).at(i);
            table.at(j).at(i)='.';
          }
          break;
        }
        else if(j==H-1-Hc){//空白列だった場合
          Wc++;
        }
      }
    }
  }
  
  //出力
  for(int i=0; i<H-Hc; i++){
    for(int j=0; j<W-Wc; j++){
        cout << table.at(i).at(j);
        if(j==W-1-Wc){
          cout << endl;
        }
    }
  }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace abc64
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int r = int.Parse(str[0]);
            int g = int.Parse(str[1]);
            int b = int.Parse(str[2]);
            int x = r * 100 + g * 10 + b;
            if (x % 4 == 0)
            {
                Console.WriteLine("YES");
            }else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++ i) cin >> a[i];
	int r = 0;
	for (int i = 0; i <= N; ++ i) {
		int s = 0;
		for (int j = 0; j < N; ++ j) if (j != i) s += a[j];
		if (s % 10) r = max(r, s);
	}
	cout << r << endl;
}


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

using namespace std;

int main(void) {
	int num, i, j, a, ok, ans = 0;
	cin >> num;
	vector<string> s(num);
	for (i = 0; i < num; i++) {
		cin >> s[i];
		s[i] += s[i];
	}
	for (a = 0; a < num; a++) {
		ok = true;
		for (i = 0; i < num; i++) {
			for (j = i + 1; j < num; j++) {
				if (s[i][j + a] != s[j][i + a]) {
					ok = false;
					break;
				}
			}
		}
		if (ok)
			ans++;
	}
	cout << ans * num << "\n";
	return 0;
}

Measured memory_bytes: 512
#56 ABC136E
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)

res=[]
for d in range(1,int(s**0.5)+1):
	if s%d==0:
		res.append(d)
		res.append(s//d)
ans=[]
for d in res:
	r1=[t%d for t in a]
	r1.sort()
	r2=[(d-t)%d for t in r1]
	r2=r2[::-1]
	x=[r1[0]]
	_=[x.append(x[-1]+r1[i]) for i in range(1,n)]
	y=[r2[0]]
	_=[y.append(y[-1]+r2[i]) for i in range(1,n)]
	#print(r1,r2,d,x,y)
	for i in range(n-1):
		#print(x[i],y[-i-2])
		if x[i]==y[-i-2] and x[i]<=k:
			ans.append(d)
			break
print(max(ans))

Measured memory_bytes: 42844
/* Doctor's Memorable Code */

#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cmath>
#include<cctype>

using namespace std;

string sbits(unsigned int x, int n){
  string ret;
  for(int i = 0; i < n; i++){
    ret += (x & 1) + '0';
    x >>= 1;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}

string DoctorTableAD(char c){
  string ret;
  if( isupper(c) ){
    ret = sbits(c - 'A', 5);
  }else{
    const char symb[] = " .,-'\?";
    for(int i = 0; i < sizeof(symb)/sizeof(*symb); i++){
      if( c == symb[i] ){
	ret = sbits(i+26, 5);
	break;
      }
    }
  }
  return ret;
}

string DoctorTableDA(string &s){
  unsigned int pos = 0;
  string ret;
  const char ctable[] = " ',-.\?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  const char table[][16] =
  {"101","000000","000011","10010001","010001","000001","100101","10011010","0101","0001","110","01001","10011011","010000","0111","10011000","0110","00100","10011001","10011110","00101","111","10011111","1000","00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
  
  while( true ){
    bool bFound = false;
    for(int i = 0; i < sizeof(table)/sizeof(*table); i++){
      if( pos == s.find(table[i], pos) ){
	ret += ctable[i];
	pos += strlen(table[i]);
	bFound = true;
	break;
      }
    }
    if( bFound == false ) break;
  }
  return ret;
}

string DoctorLovedDecode(string &raw){
  string s;
  for(unsigned int i = 0; i < raw.length(); i++){
    s += DoctorTableAD(raw[i]);
  }
  return DoctorTableDA( s );
}

int main(void){
  while(true){
    string s;
    
    getline(cin,s);
    if( cin.eof() ) break;
    
    cout << DoctorLovedDecode( s ) << "\n";
  }
  return 0;
}

Measured memory_bytes: 900
#include<stdio.h>
#define M 60000
int main(){
  int n,i,j;
  char p[M]={1,1};
  for(i=2;i*i<M;i++){
    if(p[i])continue;
    for(j=i*i;j<M;j+=i)p[j]=1;
  }
  while(scanf("%d",&n)!=EOF){
    for(i=n-1;p[i];i--);
    for(j=n+1;p[j];j++);
    printf("%d %d\n",i,j);
  }
  return 0;
}

Measured memory_bytes: 664
a,b = list(map(int,input().split()))
cnt = 0
for m in range(1,a+1):
    if m == a:
        last = b
    else:
        last = 31
    for d in range(1,last+1):
        if m == d :
            cnt += 1
            #print(m,d)

print(cnt)

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 1005;

intt f (int n) {
	return 1LL * n * n * n * n * n;
}

int main() {

	FAST;

	int x;
	cin >> x;
	for (int i = 200; i >= -200; i --) {
		for (int j = 200; j >= -200; j --) {
			if (f(i) - f(j) == x) {
				cout << i << ' ' << j << '\n';
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3468
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
int main() {
    int N; cin >> N;
    unordered_map<string, long long int> Map(N);
    vector<string> S(N, "");
    for (int i = 0; i < N; ++i) cin >> S[i];
    long long int cnt = 0;
    for (int i = 0; i < N; ++i) {
        sort(S[i].begin(), S[i].end());
        Map[S[i]]++;
        cnt += Map[S[i]] - 1;
    }
    cout << cnt << endl;
}


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

using namespace std;
using ll=long long;

// when range [l, r), has property notP~P, want first P.
// when return r, means not found.
template <typename T>
T bs_first(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return r;
}

void solve() {
    int n; ll K;
    cin >> n >> K;
    vector<ll> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    
    auto ck = [&](ll ta){
        ll cnt = 0;
        for (int i = 1; i < n; i++) {
            ll x = a[i];
            if (x > 0) {
                int k = bs_first<int>(0, i, [&](int k){
                        return a[k]*x > ta;
                        });
                cnt += k;
            } else {
                int k = bs_first<int>(0, i, [&](int k){
                        return a[k]*x <= ta;
                        });
                cnt += i-k;
            }
        }
        return cnt >= K;
    };
    ll res = bs_first<ll>(-1e18-10, 1e18+10, ck);
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
	string a,b,c;
	cin>>a>>b;
	int s1,s2;
	cin>>s1>>s2;
	cin>>c;
	if(c==a)cout<<s1-1<<' '<<s2;
	else cout<<s1<<' '<<s2-1;
	return 0;
} 

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val max = sc.nextInt() match {
    case 1 => 1
    case x =>
      val powers = for {
        i <- LazyList.from(2).takeWhile(_ <= x)
        j <- LazyList.from(2).takeWhile(_ <= x)
      } yield {
        math.pow(i, j).toInt
      }
      powers.filter(_ <= x).max
  }
  println(max)
}


Measured memory_bytes: 142396
#include <stdio.h>
#define def -1

int fibonacci(int);

int F[100];

int main(void){
  int i,n;
  scanf("%d", &n);
  for(i = 0; i < 100; i++)
    F[i] = def;
  printf("%d\n", fibonacci(n));
  return 0;
}

int fibonacci(int n){
  if(n == 0 || n == 1){
    F[n] = 1;
  } else if(F[n] != def){

  } else {
    F[n] = fibonacci(n-2) + fibonacci(n-1);
  }
  return F[n];
}

Measured memory_bytes: 596
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define y1 y11
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
//#define mp make_pair
#define pb push_back
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define pdi pair<double, int>
#define pdd pair<double, double>
#define mem(a, b) memset(a, b, sizeof(a))
#define debug(x) cerr << #x << " = " << x << "\n";
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//head

const int N = 1e5 + 5;
LL dp[N][2];
int a[N], n;
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i) {
		if(i == 1) dp[i][0] = dp[i][1] = a[1];
		else if(i == 2) {
			dp[i][0] = a[1] + a[2];
			dp[i][1] = -a[1] - a[2]; 
		}
		else {
			dp[i][0] = max(dp[i-1][0], dp[i-1][1]) + a[i];
			dp[i][1] = max(dp[i-1][0]-2*a[i-1]-a[i], dp[i-1][1]+2*a[i-1]-a[i]);
		}
	}		
	printf("%lld\n", max(dp[n][0], dp[n][1]));
	return 0;
}

Measured memory_bytes: 2176