akhauriyash/Code-Regression huggingface dataset:
# import itertools
# import math

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)

mod = 10**9+7

# print(list(itertools.combinations(range(6), 3)))
# A = range(6)
# N = 6
# K = 3

# 二項係数を素数で割った余り
def combMod(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p
fact = [-1 for _ in range(N+1)]
fact[0] = 1
fact[1] = 1
inv = [-1 for _ in range(N+1)]
inv[0] = 0
inv[1] = 1
factinv = [-1 for _ in range(N+1)]
factinv[0] = 1
factinv[1] = 1
# fact = [1, 1]
# factinv = [1, 1]
# inv = [0, 1]
p = mod
    
for i in range(2, N + 1):
    fact[i] = ((fact[i-1] * i) % p)
    inv[i] = ((-inv[p % i] * (p // i)) % p)
    factinv[i] = ((factinv[i-1] * inv[i]) % p)
    # fact.append((fact[-1] * i) % p)
    # inv.append((-inv[p % i] * (p // i)) % p)
    # factinv.append((factinv[-1] * inv[-1]) % p)




ans = 0
for i in range(N):
    num = combMod(i, K-1, mod) % mod
    ans += num * A[i] % mod
    ans -= num * A[N-i-1] % mod
    ans %= mod

print(ans)

Measured memory_bytes: 18908
import math
t = 10 ** 9 + 7
n, m = map(int, input().split())
if (abs(n-m) >= 2):
    ans = 0
else:
    if n != m:
        ans = ((math.factorial(n) % t)*(math.factorial(m) % t))%t
    else:
        ans = ((math.factorial(n) % t)*(math.factorial(m) % t)*2)%t
print(ans)

Measured memory_bytes: 4096
N=int(input())
A=list(map(int,input().split(' ')))
A_short = [A[0]]
tmp = A[0]
ans = 1
cnt = 0
for i in A[1:]:
    if tmp != i:
        A_short.append(i)
    tmp = i
while cnt < len(A_short)-2:
    if A_short[cnt] >= A_short[cnt+1] and A_short[cnt+1] <A_short[cnt+2]:
        cnt += 1
        ans += 1
    elif A_short[cnt] <= A_short[cnt+1] and A_short[cnt+1] > A_short[cnt+2]:
        cnt += 1
        ans += 1
    cnt += 1
print(ans)

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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int A[N];
    int tmp = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        if (A[i] == 1) {
            tmp = i;
        }
    }
    int left = tmp;
    int ans = 0;
    ans += (left + (K - 1) - 1) / (K - 1);
    tmp = ans * (K - 1);
    int right = N - tmp - 1;
    ans += (right + (K - 1) - 1) / (K - 1);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    vector<int> nums(n);
    int end = n;
    while(end){
        int idx = end / 2;
        printde(end, idx);
        for(int i = idx; i < end; i++){
            int acc = 0;
            for(int j = i + 1; j <= n; j += (i + 1)){
                acc ^= nums[j - 1];
            }
            if(acc != as[i]){
                nums[i] = 1;
            }
        }
        end = idx;
        printde(nums);
    }
    cout << accumulate(nums.begin(), nums.end(), 0ll) << '\n';
    for(int i = 0; i < n; i++){
        if(nums[i]){
            cout << i + 1 << ' ';
        }
    }
}


Measured memory_bytes: 2432
n,k=map(int,input().split())
h=[int(input()) for i in range(n)]
h.sort()
ans=h[k-1]-h[0]
res=float("INF")
for i in range(n-k+1):
    res=h[i+k-1]-h[i]
    if ans>res:
        ans=res
print(ans)


Measured memory_bytes: 13156
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
using namespace std;

string solve(string s1, string s2) {
	int cnt = 0;
	int l = 1, r = 0;

	int s1n=-1;
	string ls1, rs1;
	for (int i = 1; i < s1.size() - 1; i++) {
		if (s1[i] == '(')cnt++;
		else if (s1[i] == ')')cnt--;

		if (cnt == 0 && l == 1) {
			r = i;
			ls1 = s1.substr(l, r - l + 1);

			i += 2;

			int l2 = i;
			while (1) {
				i++;
				if (s1[i] == ']') {
					s1n = stoi(s1.substr(l2, i - l2).data());
					i++;
					break;
				}
			}

			l = r = i;
			i--;
		}
		else if (cnt == 0){
			r = i;
			rs1 = s1.substr(l, r - l + 1);
		}
	}


	l = 1, r = 0;

	int s2n=-1;
	string ls2, rs2;
	for (int i = 1; i < s2.size() - 1; i++) {
		if (s2[i] == '(')cnt++;
		else if (s2[i] == ')')cnt--;

		if (cnt == 0 && l == 1) {
			r = i;
			ls2 = s2.substr(l, r - l + 1);

			i += 2;

			int l2 = i;
			while (1) {
				i++;
				if (s2[i] == ']') {
					s2n = stoi(s2.substr(l2, i - l2).data());
					i++;
					break;
				}
			}

			l = r = i;
			i--;
		}
		else if (cnt == 0) {
			r = i;
			rs2 = s2.substr(l, r - l + 1);
		}
	}

	if (s1n == -1 || s2n == -1)return "";

	return "(" + solve(ls1,ls2) + ")" + "[" + to_string(s1n + s2n) + "]" + "(" + solve(rs1, rs2) + ")";
}

int main()
{
	string s1, s2;
	cin >> s1 >> s2;

	s1.insert(s1.begin(), '(');
	s1.push_back(')');
	s2.insert(s2.begin(), '(');
	s2.push_back(')');
	
	cout << solve(s1, s2) << endl;

    return 0;
}

Measured memory_bytes: 3476
#include <iostream>
#include <algorithm>
#include <cstdlib>

using namespace std;

int main(){
  long long INF=1LL<<35;
  int N, K;
  int h[100010];
  cin >> N >> K;
  for(int i=0; i<N; i++) cin >> h[i];
  long long dp[100010];
  for(int i=0; i<N; i++) dp[i]=INF;
  dp[0]=0;
  for(int i=1; i<N; i++){
    for(int j=1; j<=min(i,K); j++){
      dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));     
    }
  }
  cout << dp[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1408
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = list(map(int, readline().split()))
    x = list(map(int, readline().split()))

    ans = INF
    if 0 in x:
        start = x.index(0)
        leftlim = max(0, start - k + 1)
        rightlim = min(start + k - 1, n - 1)
        for i in range(leftlim, start + 1):
            left = i
            right = left + k - 1
            if right > rightlim:
                break
            if x[left] * x[right] < 0:
                temp = min(2 * abs(x[left]) + abs(x[right]), abs(x[left]) + 2 * abs(x[right]))
            else:
                if x[left] < 0:
                    temp = abs(x[left])
                else:
                    temp = abs(x[right])
            ans = min(ans, temp)
    else:
        start = bisect.bisect_left(x, 0)

        leftlim = max(0, start - k)
        rightlim = min(start + k - 1, n - 1)

        for i in range(leftlim, start + 1):
            left = i
            right = left + k - 1
            if right > rightlim:
                break

            if x[left] * x[right] < 0:
                temp = min(2 * abs(x[left]) + abs(x[right]), abs(x[left]) + 2 * abs(x[right]))
            else:
                if x[left] < 0:
                    temp = abs(x[left])
                else:
                    temp = abs(x[right])
            ans = min(ans, temp)

    print(ans)

if __name__ == '__main__':
    main()


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

void sort(int ,int*);

int main(void) {
	int N,K;
	scanf("%d %d",&N,&K);
	int p[N];
	int i;
	for(i=0;i<N;i++){
		scanf("%d",&p[i]);
	}
	sort(N,p);
	int j,sum=0;
	for(j=0;j<K;j++){
		sum += p[j];
	}
	printf("%d",sum);
   return 0;
}

void sort(int n,int array[]){
	int k,i,j,max;

	for(k=n-1; k>0; k--){
		max = 0;
		for(i=0; i<=k; i++){
			if(max < array[i]){
				max = array[i];
				j = i;

		    }
		}
			array[j] = array[k];
			array[k] = max;
    }
}


Measured memory_bytes: 1696
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;

int N;
ll h[112345];
ll dp[112345]; //i番目までの最小コスト
signed main(){
    cin>>N;
    rep(i,N)cin>>h[i];

    dp[1]=abs(h[1]-h[0]);
    rep(i,N-2){
        dp[i+2]=min(dp[i]+abs(h[i+2]-h[i]),dp[i+1]+abs(h[i+2]-h[i+1]));
    }
    dp[N-1]=min(dp[N-1],dp[N-2]+abs(h[N-1]-h[N-2]));

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


 
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#define llint long long

using namespace std;

llint x, y;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> x >> y;
	
	if(abs(x-y) <= 1) cout << "Brown" << endl;
	else cout << "Alice" << endl;
	
	return 0;
}

Measured memory_bytes: 256
let cnt = ref 0

let merge a l m r =
  let ni = m - l in
  let ai = Array.make (ni + 1) max_int in
  for i = 0 to ni - 1 do
    ai.(i) <- a.(l + i)
  done;
  let aj = Array.make (r - m + 1) max_int in
  for i = 0 to r - m - 1 do
    aj.(i) <- a.(m + i)
  done;
  let i = ref 0 in
  let j = ref 0 in
  for k = l to r - 1 do
    if ai.(!i) <= aj.(!j) then begin
      a.(k) <- ai.(!i);
      incr i;
    end else begin
      a.(k) <- aj.(!j);
      cnt := !cnt + (ni - !i);
      incr j;
    end
  done

let merge_sort a l r =
  let rec doit l r =
    if (l + 1) < r then begin
      let m = (l + r) / 2 in
      doit l m;
      doit m r;
      merge a l m r
    end in
  doit l r

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  Printf.printf "%d\n" !cnt

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b){ if (a > b) { a = b; } }

int main() {
    int x, y;
    cin >> x >> y;
    int a = 2 * x - y / 2;
    int b = y / 2 - x;
    if (y % 2 || a < 0 || b < 0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3636
//* AuThOr GaRyMr *//
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define KEEP while(1)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
typedef pair<mp,mp> superpair;
int main(){
	int a;string s;
	cin>>a>>s;
	if(a>=3200){
		cout<<s<<endl;
	}
	else{
		cout<<"red"<<endl;
	}
	return 0;
}

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

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> cs(n);
    for (auto& c : cs) {
        std::cin >> c;
        --c;
    }

    Graph<> graph(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
    }

    std::vector<lint> sz(n);
    std::vector<std::vector<int>> nxts(n), roots(n);

    {
        std::vector<int> pars(n, -1);
        std::function<void(int, int)>
            dfs = [&](int v, int p) -> void {
            sz[v] = 1;

            if (pars[cs[v]] == -1) {
                roots[cs[v]].push_back(v);
            } else {
                nxts[pars[cs[v]]].push_back(v);
            }

            for (auto e : graph[v]) {
                int u = e.dst;
                if (u == p) continue;

                int pp = pars[cs[v]];
                pars[cs[v]] = u;

                dfs(u, v);
                sz[v] += sz[u];

                pars[cs[v]] = pp;
            }
        };
        dfs(0, -1);
    }

    lint ans = 0;

    std::function<void(int)>
        dfs = [&](int v) -> void {
        for (auto e : graph[v]) {
            auto u = e.dst;
            if (sz[u] > sz[v]) continue;

            lint s = sz[u];
            for (auto w : nxts[u]) {
                s -= sz[w];
                dfs(w);
            }

            ans -= s * (s + 1) / 2;
        }
    };

    for (int c = 0; c < n; ++c) {
        ans = lint(n) * (n + 1) / 2;

        lint s = n;
        for (auto r : roots[c]) {
            dfs(r);
            s -= sz[r];
        }

        ans -= s * (s + 1) / 2;

        std::cout << ans << std::endl;
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 54592
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;
};

Node *nil;

Node* listSearch(int key) {
  Node *cur=nil->next;
  while (cur!=nil&&cur->key!=key) {
    cur=cur->next;
  }
  return cur;
}

void init() {
  nil=(Node *)malloc(sizeof(Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList() {
  Node *cur=nil->next;
  int isf=0;
  while (1) {
    if (cur==nil) break;
    if (isf++>0) printf(" ");
    printf("%d", cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if (t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x=(Node *)malloc(sizeof(Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main() {
  int n, key;
  int size=0;
  char com[20];
  int np=0;
  int nd=0;
  scanf("%d", &n);
  init();
  for (int i=0; i<n; i++) {
    scanf("%s %d", com, &key);
    if (com[0]=='i') {
      insert(key);
      np++;
      size++;
    }
    else if (com[0]=='d') {
      if (strlen(com)>6) {
        if (com[6]=='F') deleteFirst();
        else if (com[6]=='L') deleteLast();
      } else  {
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();

  return 0;
}


Measured memory_bytes: 33868
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 2003,MaxA = 2003,INF=0x3fffffff;
int n,a[MaxN],s;
bitset<MaxN*MaxA> dp;
int main() {
    scanf("%d",&n);
    for (int i=1;i<=n;++i) scanf("%d",a+i),s+=a[i];
    dp[0]=1;
    for (int i=1;i<=n;++i) dp|=dp<<a[i];
    for (int i=(s+1)/2;i<=s;++i) if (dp[i]) return printf("%d\n",i),0;
    return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N,H[101010];
ll i,j,ans;
int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &H[i]);
    }
    H[0]--;
    fornum(i,1,N){
        if(H[i-1]<=H[i]){
            H[i] -= H[i - 1] == H[i] ? 0 : 1;
        }else{
            break;
        }
    }
    if(i==N){
        printf("Yes");
    }else{
        printf("No");
    }
    
    return 0;
}

Measured memory_bytes: 1024
using System;
class Min2019{
	static void Main(string[] args){
		string[] LR = Console.ReadLine().Split(' ');
		int L = int.Parse(LR[0]);
		int R = int.Parse(LR[1]);
		int MinAns = 2232;
		for(int i = L;i <= Math.Min(L + 2018,R - 1);i++){
			for(int j = i + 1;j <= Math.Min(i + 2019,R);j ++){
				int MAns = ((i % 2019) * (j % 2019)) % 2019;
				if(MAns < MinAns)MinAns = MAns;
			}
		}
		Console.WriteLine(MinAns);
	}
}

Measured memory_bytes: 11092
int main(){
   int N=0,L=0;
   int aji[210];
   int sum=0,sum2=0,s=10000,s_tmp=0;
   int aji_res=0;
   scanf("%d %d",&N,&L);
   for(int i=1;i<=N;i++){
      aji[i]=L+i-1;
      sum += aji[i];
   }
   for(int i=1;i<=N;i++){
      sum2 -= aji[i];
      for(int j=1;j<=N;j++){
         sum2 += aji[j];
      }
      if(sum>sum2) s_tmp=sum-sum2;
      if(sum2>=sum) s_tmp=sum2-sum;
      if(s_tmp<s){
         s=s_tmp;
         aji_res=sum2;
      }
      sum2=0;
      s_tmp=0;
   }
   printf("%d\n",aji_res);
   return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = sc.nextInt();
		a[1] = sc.nextInt();
		a[2] = sc.nextInt();
		Arrays.sort(a);
		System.out.println(a[0] + a[1] + a[2]*10);
	}
}

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  REP(i,1,N){
    int K=i*108/100;
    if(K==N){
      cout<<i<<endl;
      break;
    }
    if(K>N){
      cout<<":("<<endl;
      break;
    }
  }
  }


Measured memory_bytes: 256
import java.io.PrintWriter

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}


fun solve(out: PrintWriter) {
    val n = readInteger()
    val aList = readIntegerList()
//    j - i == ai + aj
//    ai + i == j - aj
    val iList = aList.mapIndexed { index, i -> i + index + 1 }
    val jList = aList.mapIndexed { index, i -> index + 1 - i }

    val jCountMap = elementCountMap(jList)
    var ans = 0L
    for (i in iList) {
        ans += jCountMap[i] ?: 0
    }
    println(ans)
}

/**
 * O(n)
 */
fun <T>elementCountMap(list: List<T>): Map<T, Int> {
    val countMap = mutableMapOf<T, Int>()
    for (e in list) {
        countMap[e] = (countMap[e] ?: 0) + 1
    }
    return countMap
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)


Measured memory_bytes: 79148
import scipy.sparse.csgraph as c,numpy
_,*s=open(0)
s=numpy.int32([list(t[:-1])for t in s])
m=c.floyd_warshall(s)
i=m[0]%2<1
j=i^True
print(s[i][:,i].any()|s[j][:,j].any()and-1or-~int(m.max()))

Measured memory_bytes: 14748
n = int(input())
ls =list(map(int, input().split()))
t = len(ls)
a=[]
b=[]
for i in range(1,101):
    for j in range(t):
        p = (ls[j]-i)**2
        a.append(p)
    b.append(sum(a))
    a=[]
b.sort()
print(b[0])


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int max = Math.max(a + b, a -b);
		max = Math.max(max, a * b);
		System.out.println(max);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
using namespace std;

int main()
{
	string a,b;
	int x;
	int zh(string s);
	
	cin>>a>>b;
	
	x=zh(a+b);
	
	if(int(sqrt(x))==sqrt(x))
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	return 0;
}

int zh(string s)
{
	int tmp=0;
	for(int i=0;i<s.size();i++)
	tmp=tmp*10+(s[i]-'0');
	
	return tmp;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int N = 5e5+7;
int n,m,d[N],kt[N];
vector <int> a[N];
void nhap()
{
    scanf("%d %d",&n,&m);
    for (int i=1; i<=m; i++)
    {
        int u,v;
        scanf("%d %d ",&u,&v);
        a[u].pb(v);
        a[v].pb(u);
    }
}
void solve()
{
    queue <int> q;
    kt[1] = 1;
    d[1] = 0;
    q.push(1);
    while (q.size()>0)
    {
        int u = q.front();
        q.pop();
        for (int i=0; i<a[u].size(); i++)
        {
            int v = a[u][i];
            if (kt[v]==0)
            {
                d[v] = d[u]+1;
                if (v==n)
                {
                    if (d[v]==2) {cout<<"POSSIBLE";}
                    else {cout<<"IMPOSSIBLE";}
                    return;
                }
                kt[v] = 1;
                q.push(v);
            }
        }
    }
    cout<<"IMPOSSIBLE";
}
int main()
{
    nhap();
    solve();
}


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

int main() {
  int A,B,X;
  cin >> A >> B >> X;
  int M =A+B;
  if(A>X){
    cout << "NO" << endl;
  }
  else if(M<X){
  cout << "NO" << endl;
  }
  else if(M>X-1 && X-A>B){
  cout << "NO" << endl;
  }
  else{
  cout << "YES" << endl;
  }
  
  
}





Measured memory_bytes: 256
import math

def a():
    s = input()
    if s == 'RRR':
        print(3)
    elif 'RR' in s:
        print(2)
    elif 'R' in s:
        print(1)
    else:
        print(0)


def b():
    n = int(input())
    l = list(map(int, input().split()))
    l.sort()
    count = 0
    for i, li in enumerate(l):
        for j, lj in enumerate(l[i + 1:],i + 1):
            for lk in l[j + 1:]:
                if lk < li + lj and li != lj and lj != lk:
                    # print(li,lj,lk)
                    count += 1
    print(count)




def c():
    pass



def d():
    pass


# a()
b()
# c()
# d()

Measured memory_bytes: 9200
/** Seek God..Trust God..Praise God..**/

#include<bits/stdc++.h>
using namespace std;


#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define endl            "\n";

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////



/*
long long  Prime[3000000],nPrime;
long long  mark[10000002];

void seive(long long int n)
{
	long long int i,j,limit=sqrt(n*1.0)+2;
	mark[1]=1;
	for(i=4; i<=n ;i+=2)
	mark[i]=1;
	Prime[nPrime++]=2;
	for(i=3; i<=n; i+=2)
	{
		if(!mark[i])
		{
			Prime[nPrime++]=i;
			if(i<=limit)
			{
				for(j=i*i; j<=n ;j+=i*2)
				{
					mark[j]=1;
				}
			}
		}
	}
}
*/




int main()
{
    FASTIO;

    ll n;

    cin >> n;

    ll MOD = 1e9+7;



    ll sum = 0 , ans = 0;


    ll sum1 = 0;


    for(ll i=0; i<n; i++)
    {
        ll a;

       cin >> a;

       ans += (sum*a);

       ans %= MOD;

       sum += a;

       sum %= MOD;

    }

    cout << ans << endl;





    return 0;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define SIZE 10000
using namespace std;
vector<pair<double, double> > vertex;
void koch_curve(const pair<double, double> &p1, const pair<double, double> &p2, int n)
{
    if (n == 0)
    {
        return;
    }
    double ax = p1.first * 2 / 3 + p2.first / 3, ay = p1.second * 2 / 3 + p2.second / 3;
    double bx = p1.first / 3 + p2.first * 2 / 3, by = p1.second / 3 + p2.second * 2 / 3;
    double x = bx - ax, y = by - ay;
    double cx = ax + x * cos(M_PI / 3) - y * sin(M_PI / 3), cy = ay + x * sin(M_PI / 3) + y * cos(M_PI / 3);
    pair<double, double> a1 = make_pair(ax, ay), a2 = make_pair(cx, cy), a3 = make_pair(bx, by);
    koch_curve(p1, a1, n - 1);
    vertex.push_back(a1);
    koch_curve(a1, a2, n - 1);
    vertex.push_back(a2);
    koch_curve(a2, a3, n - 1);
    vertex.push_back(a3);
    koch_curve(a3, p2, n - 1);
}
int main()
{
    int n;
    cin >> n;
    vertex.push_back(make_pair(0, 0));
    koch_curve(make_pair(0, 0), make_pair(100, 0), n);
    vertex.push_back(make_pair(100, 0));
    for (int i = 0; i < vertex.size(); ++i)
        printf("%.8f %.8f\n", vertex[i].first, vertex[i].second);
}


Measured memory_bytes: 3180
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 3000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100000],b[100000];
  int ans=INF;
  rep(i,n){
    cin>>a[i]>>b[i];
    ans=min(ans,a[i]+b[i]);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<tuple<string, int, int>> sp(n);
  for (int i = 0; i < n; i++){
    cin >> get<0>(sp.at(i)) >> get<1>(sp.at(i));
    get<2>(sp.at(i)) = i + 1;
    get<1>(sp.at(i)) *= -1;
  }

  sort(sp.begin(), sp.end());
  for (int i = 0; i < n; i++){
    cout << get<2>(sp.at(i)) << endl;
  }
}

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

using ll = long long int;
using bigint = int64_t;

#define pll pair<ll, ll>
#define vll vector<ll>
#define vpll vector<pll>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define bitcount __builtin_popcount
#define endl "\n"
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define deb(x) cout << #x << " = " << x << endl;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(ll i = a; i <= b; i++)
#define ffo(i, a, b) for(ll i = a; i >= b; i--)
#define ffi(i,a,b,c) for(ll i = a ; i <= b ; i += c)
#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int MOD = 1000000007;

void io_set(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

void solve(){
    ll n, k;
    cin >> n >> k;
    long double a[n], x;
    rep(i, n){
    	cin >> x;
    	a[i] = (x+1)/2;
    }
    long double s = 0, ans = -1;
    fo(i, 0, k-1){
    	s += a[i];
    }
    ans = s;
    fo(i, k, n-1){
    	s += (a[i] - a[i-k]);
    	ans = max(ans, s);
    }
    cout << fixed << setprecision(10) << ans << endl;
}

int main(){
    IOS;
    //io_set();
    ll tt = 1;
    //cin >> tt;
    while(tt--){
        solve();
    }
    return 0;
} 

Measured memory_bytes: 3456
n, k = map(int, input().split())
s = input()

score = 0
paired = 0
for i in range(1, n):
    if s[i - 1] == s[i]:
        score += 1
    if s[i - 1] == s[0] and s[i] != s[0]:
        paired += 1

if k < paired:
    print(score + 2 * k)
else:
    print(n - 1)

Measured memory_bytes: 3316
/*
ID: Aman Raj
LANG: C++
TASK: prefix
*/
//#include<iostream>
#include <stdio.h>
//#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#include<math.h>
typedef  long long int ll;
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
//#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
//#define mod 13
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
//#define flush fflush(stdout)
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#include <fstream>
// find_by_order()  // order_of_key
typedef tree<
	int,
	null_type,
	less<int>,
	rb_tree_tag,
	tree_order_statistics_node_update>
	ordered_set;


   int main()
{    //ll a,b;cin>>a>>b;

        ll k,x;cin>>k>>x;
        ll l=-1*1000000,ul=1000000;
        ll a=max(l,x-k+1);
         ll b=min(ul,x+k-1);
         for(ll i=a;i<=b;i++)cout<<i<<" ";
   return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	long long n;
	cin >> n;
	long long ans = n / 11 * 2;
	if (n % 11 > 6) {
		ans += 2;
	}
	else if(n%11!=0){
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    priority_queue<double, vector<double>, greater<double>> a;
    double ans = 0.0;
    REP(i, n)
    {
        double tmp;
        cin >> tmp;
        a.push(tmp);
    }
    REP(i, n - 1)
    {
        double v1, v2;
        v1 = a.top();
        a.pop();
        v2 = a.top();
        a.pop();
        a.push((v1 + v2) / 2.0);
    }
    printf("%.16lf\n", a.top());
}

Measured memory_bytes: 256
type card = { id : int; ch : char; num : int }

let quick_sort (a : card array) cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let rec exchange = function
      | (i, j) when j = r -> swap i r; i
      | (i, j) when cmp a.(j) a.(r) <= 0 -> swap i j; exchange (i + 1, j + 1)
      | (i, j) -> exchange (i, j + 1) in
    exchange (p, p) in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit 0 (Array.length a - 1)

let stable_p (a : card array) n =
  let rec doit i =
    if i = n then true
    else if (fun a b -> a.num = b.num && a.id > b.id) a.(i-1) a.(i) then false
    else doit (i + 1) in
  doit 1

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let () =
  let n = read_int () in
  let read i =
    match split (read_line ()) ' ' with
    | [c; d] -> { id = i; ch = c.[0]; num = int_of_string d }
    | _ -> exit 1 in
  let a = Array.init n read in
  quick_sort a (fun a b -> a.num - b.num);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun e -> Printf.printf "%c %d\n" e.ch e.num) a

Measured memory_bytes: 8776
import java.util.*;
import java.lang.*;


public class Main {
    static void possible(){
        System.out.println(1);
        System.exit(0);
    }
    static void impossible(){
        System.out.println("0");
        System.exit(0);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        for(int amount = X/100; amount>=X/105; amount--){
            int penny = X - amount*100;
            if(0<=penny && penny<=5*amount) possible();
        }
        impossible();
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <utility>
#include <tuple>
#include <queue>
using namespace std;

const int infty = (int) 1e7;

int main() {
  int N, M, L, K, A, H;
  while (scanf("%d%d%d%d%d%d", &N, &M, &L, &K, &A, &H) != EOF && N) {
    bool freeze[110];
    fill(freeze, freeze+110, false);
    for (auto i=0; i<L; i++) {
      int l;
      scanf("%d", &l);
      freeze[l] = true;
    }
    freeze[A] = true;
    freeze[H] = true;
    vector <pair <int, int> > V[110];
    for (auto i=0; i<K; i++) {
      int X, Y, T;
      scanf("%d%d%d", &X, &Y, &T);
      V[X].push_back(make_pair(Y, T));
      V[Y].push_back(make_pair(X, T));
    }
    priority_queue< tuple<int, int, int> > Q; // -1*cost, town, time
    bool visited[110][110];
    int mincost[110][110];
    fill(&visited[0][0], &visited[0][0]+110*110, false);
    fill(&mincost[0][0], &mincost[0][0]+110*110, infty);
    Q.push(make_tuple(0, A, M));
    while (!Q.empty()) {
      int cost = -1 * get<0>(Q.top());
      int town = get<1>(Q.top());
      int time = get<2>(Q.top());
      Q.pop();
      /*cerr << "cost = " << cost << ", town = " 
	<< town << ", time = " << time << endl; */
      if (!visited[town][time]) {
	visited[town][time] = true;
	mincost[town][time] = cost;
	if (visited[H][M]) break;
	for (auto i=0; i<V[town].size(); i++) {
	  int dst = V[town][i].first;
	  int c = V[town][i].second;
	  int x;
	  if ((x = time - c) >= 0 && !visited[dst][x]) {
	    if (freeze[dst]) {
	      Q.push(make_tuple(-1 * (cost + c), dst, M));
	    } else {
	      Q.push(make_tuple(-1 * (cost + c), dst, x));
	    }
	  }
	}
      }
    }
    if (mincost[H][M] == infty) {
      printf("Help!\n");
    } else {
      int ans = mincost[H][M];
      if (M > ans) {
	printf("%d\n", ans);
      } else {
	printf("%d\n", 2*ans-M);
      }
    }
  }
}

Measured memory_bytes: 1468
#include <bits/stdc++.h>
using namespace std;
//マクロ
const int inf { int (1e9) } ;//int ans {inf} ;と使う
int N,M;
int main(){
  cin >> N >> M;
  for(int i=M/N;i>0;i--){
    if(M%i==0){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<cstring>
#define INF 1000000000
using namespace std;
set<string> gacha;
int n;
string x;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        gacha.insert(x);
    }
    cout<<gacha.size();
    
    
}

Measured memory_bytes: 19116
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

ll N, M;
ll a[1001000];
ll dp[1001000];
int main() {

    cin >> N >> M;
    rep(i, 0, M) {
        cin >> a[i];
    }
    bool b[1001000];
    for (int j = 0; j < M; ++j) {
        int v = a[j];
        b[v] = true;
    }
    dp[0] = 1;
    for (int i = 0; i < 1001000; ++i) {
        if (b[i]) {
            continue;
        }
        dp[i + 1] += dp[i];
        dp[i + 1] %= MOD;
        dp[i + 2] += dp[i];
        dp[i + 2] %= MOD;
    }

    cout << dp[N] % MOD << endl;
    return 0;
}

Measured memory_bytes: 10624
from fractions import gcd
def factor(n):
    res = []
    for i in range(2,int(n**0.5)+1):
        while n % i == 0:
            res.append(i)
            n //= i
    if n > 1:
        res.append(n)
    return res

a,b = map(int,input().split())
c = gcd(a,b)
print(len(set(factor(c)))+1)

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

#define rep(i,n) for (int i = 0; i< (n); i++)
using namespace std;
 
int main() {
  int N, M;
  string judge = "No";
  //vector<int> p(N); 
  vector<int> a(3);
  vector<int> b(3);
  vector<vector<int>> c(3, vector<int>(3));
  for(int i = 0; i<3; i++){
  	for(int j = 0; j<3; j++){
    	cin>>c[i][j];
    }
  }
  
  for(int i = 0; i<=c[0][0]; i++){
  	for(int j = 0; j<=c[0][1]; j++){
      for(int k = 0; k<=c[0][2]; k++){
        a[0] = i;
        a[1] = j;
        a[2] = k;
        
      	b[0] = c[0][0] - a[0];
        b[1] = c[1][0] - a[0];
        b[2] = c[2][0] - a[0];
        
        if (a[1]+b[1] == c[1][1] && a[2]+b[1] == c[1][2] && a[1]+b[2]==c[2][1] && a[2]+b[2]==c[2][2]){
          if(a[0]+b[0]==c[0][0]&&a[0]+b[1]==c[1][0]&&a[0]+b[2]==c[2][0]&&a[1]+b[0]==c[0][1]&&a[2]+b[0]==c[0][2]){
            judge = "Yes";
          } 
        }
      }
    }
  }
  cout<<judge<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int H,W;
unsigned long long calc=0;
int c[10][10];
int main (void){
	int A;
	cin>>H>>W;
	for (int i=0;i<=9;++i)
		for (int j=0;j<=9;++j) cin>>c[i][j];
	for (int k=0;k<=9;++k)
		for (int i=0;i<=9;++i)
			for (int j=0;j<=9;++j)
				if (c[i][j]>c[i][k]+c[k][j]) c[i][j]=c[i][k]+c[k][j];
	for (int i=0;i<H;++i)
		for (int j=0;j<W;++j){
			cin>>A;
			if (A!=-1) calc+=c[A][1];
		}
	cout<<calc<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())


int main(){
  string s;
	cin>>s;
  rep(i,s.size()){
  if(s[i]=='1'){s[i]='9';}
  else if(s[i]=='9'){s[i]='1';}
  }
  cout << stoi(s) << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
class Main{
    public static void main(String[] args)
    {
        String n;
        char station = ' ';
        int result = 0;
        Scanner scanner = new Scanner(System.in);
        n = scanner.next();

        for(int i = 0; i < n.length(); i++){
            if(i == 0){
                station = n.charAt(i); 
            }else if(station != n.charAt(i)){
                result = 1;
                break;
            }
        }
        if(result == 1){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 55;
const int md = (int) 1e9 + 7;

ll dp[N];

int main() {
  int n;
  string s[2];
  cin >> n >> s[0] >> s[1];
  vector <int> v;
  for (int i = 0; i < n; i++) {
    if (s[0][i] == s[1][i]) v.push_back(1);
    else v.push_back(2), i++;
  }
  n = v.size();
  dp[0] = 6;
  if (v[0] == 1) dp[0] = 3;
  for (int i = 1; i < n; i++) {
    if (v[i - 1] == 1 && v[i] == 1) dp[i] = 2 * dp[i - 1] % md;
    if (v[i - 1] == 2 && v[i] == 1) dp[i] = dp[i - 1];
    if (v[i - 1] == 1 && v[i] == 2) dp[i] = 2 * dp[i - 1] % md;
    if (v[i - 1] == 2 && v[i] == 2) dp[i] = 3 * dp[i - 1] % md;
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = [int(input()) for i in range(n)]

for k in range(m):
    for i in range(n-1):
        if a[i] % (k+1) > a[i+1] % (k+1):
            a[i],a[i+1] = a[i+1],a[i]

for i in range(n):
    print(a[i])


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,s=0; cin>>n;
    for(int i=1;i<=n;i++)
        if(i%3!=0 && i%5!=0)
            s+=i;
    cout<<s;
    return 0;
}


Measured memory_bytes: 3648
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int d[10];

int main() {
    memset(d, 0, sizeof(d));
    for (int i = 0; i < 4; i++)
        d[gi()] = 1;
    printf(d[1] && d[4] && d[7] && d[9] ? "YES\n" : "NO\n");

    return 0;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

#include <bits/stdc++.h>
using namespace std;

const ll mod = 1e9 + 7;

const ll INF = 1e15;

ll mpow(ll x, ll n) {
	ll ans = 1; x %= mod;
	while (n != 0) {
		if (n & 1) ans = ans * x % mod;
		x = x * x % mod;
		n = n >> 1;
	}
	return ans;
}

ll inv_mod(ll a) { return mpow(a, mod - 2); }

class Factorial {
private:
	vector<ll> fac;
	vector<ll> ifac;
public:

	Factorial(ll N) {
		fac.push_back(1);
		for (int i = 0; i < N; i++) fac.push_back(fac[i] * (i + 1) % mod);
		ifac.resize(N + 1);
		ifac[N] = inv_mod(fac[N]);
		for (int i = 0; i < N; i++) ifac[N - 1 - i] = (ifac[N - i] * (N - i)) % mod;
	}

	ll fact(ll a) { return fac[a]; }
	ll ifact(ll a) { return ifac[a]; }

	ll cmb(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		ll tmp = ifact(a - b) * ifact(b) % mod;
		return tmp * fac[a] % mod;
	}
	ll per(ll a, ll b) {
		if (a == 0 && b == 0) return 1;
		if (a < b || a < 0 || b < 0) return 0;
		return fac[a] * ifac[a - b] % mod;
	}
};

int main() {
	ll n;
	cin >> n;
	vector<ll> as(n), bs(n);
	rep(i, n) cin >> as[i];
	rep(i, n) cin >> bs[i];

	vector<P> cs;
	rep(i, n) {
		cs.emplace_back(as[i], 0);
		cs.emplace_back(bs[i], 1);
	}
	sort(cs.begin(), cs.end());
	int counts[2] = { 0,0 };
	ll sum = 1;
	Factorial f(n);
	rep(i, 2 * n) {
		auto p = cs[i];
		auto other = (p.second + 1) % 2;
		if (counts[other]) {
			sum *= counts[other];
			sum %= mod;
			counts[other]--;
		}
		else {
			counts[p.second]++;
		}
	}
	cout << sum << endl;
	return 0;
}


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

int main()
{
	int x;
	cin >> x;
	int num = x / 100;
	int sheng = x % 100;
	if(sheng <= num * 5)
		printf("1\n");
	else
		printf("0\n");
	return 0;
}


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

using namespace std;

#define int long long
#define mem(v , val) memset(v , val , sizeof val)
#define endl '\n'



void solve()
{
    int n;
    cin >> n;
    map <int , int> m;

    int sum = 0 , x;
    for(int i = 0 ; i < n;  i++)
    {
        cin >> x;
        sum += x;
        m[x]++;
    }

    int q;
    cin >> q;
    int l , r;
    while(q--)
    {
        cin >> l >> r;
        int temp = m[l];
        sum += m[l] * (r - l);
        m[l] = 0;
        m[r] += temp;
        cout << sum << endl;
    }
    return;
}


int32_t main()
{
    int t = 1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 9440
fun main(array: Array<String>) {
    val n = readLine()!!.toInt()
    val arr = readLine()!!.split(" ").map { it.toInt() }
    var cnt = 0
    var max = 0
    for(i in 0 until n-1) {
        if(arr[i] >= arr[i+1]) {
            cnt++
        }
        else {
            cnt = 0
        }
        if(max < cnt) {
            max = cnt
        }
    }
    print(max)
}

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

int main() {
    long long N, x;
    long long a[100] = {};
    cin >> N >> x;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(a, a + N);
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i == N - 1 && x > a[i]) {
            // 配り切る
            cout << ans << endl;
            return 0;
        }
        x -= a[i];
        if (x < 0) {
            cout << ans << endl;
            return 0;
        } else {
            ans++;
        }
    }
    cout << ans << endl;

    return 0;
}


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

const double PI=acos(-1.0);

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    //rep(i, n) cout << a[i] << " ";

    
    int cnt = 0;
    int next = 0;
    bool can = false;
    while(cnt < n) {
        cnt++;
        if(a[next] == 1) {
            can = true;
            break;
        }
        next = a[next];
    }

    cout << (can ? cnt : -1) << endl;
    

    return 0;
}

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

using namespace std;
using ll = long long;
using IP = pair<int, int>;

const ll INF = 1LL << 62;
#define atcoder(int)1e9+7
#define Endl endl
#define mp make_pair
#define all(v) v.begin(),v.end()
#define pb push_back

ll gcd(ll a, ll b) {//最大公約数
	if (a%b == 0)return b;
	else gcd(b, a%b);
}

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

int main() {
	
	int n;
	int mina = 1000, maxa = -1000;
	cin >> n;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		maxa = max(a, maxa);
		mina = min(a, mina);
	}
	cout << maxa - mina << Endl;

	return 0;
}

Measured memory_bytes: 256