akhauriyash/Code-Regression huggingface dataset:
from sys import stdin, stdout, stderr

while 1:
    n, m = map(int, stdin.readline().split())

    if n + m == 0:
        break

    taro = [int(stdin.readline()) for i in range(n)]
    hana = [int(stdin.readline()) for i in range(m)]

    tsum = sum(taro)
    hsum = sum(hana)

    if (tsum - hsum) % 2:
        print(-1)
        continue

    smin = 10000
    ans1, ans2 = -1, -1

    for i in range(n):
        for j in range(m):
            dif = taro[i] - hana[j]

            if tsum - dif == hsum + dif and taro[i] + hana[j] < smin:
                ans1, ans2 = taro[i], hana[j]
                smin = taro[i] + hana[j]

    if ans1 + ans2 >= 0:
        print(ans1, ans2)
    else:
        print(-1)

Measured memory_bytes: 7644
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N,K; cin>>N>>K;
  vector<int>A(K);
  int ans=0;
  rep(i,K){
    cin>>A[i];
    ans+=A[i];
  }
  cout<<(ans>N? -1:N-ans)<<endl;
}

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

int main() {
  int N; cin >> N;
  string s; cin >> s;
  int r = 0;
  
  for(int c=1;c<N-1;c++){
    map<char,int> mp;
    for(int i='a';i<'z'+1;i++){mp[char(i)]=0;}
    string x = s.substr(0,c);
    string y = s.substr(c,N-c);
    int x_size = x.size();
    int y_size = y.size();
    
    for(int i=0;i<x_size;i++){
      for(int j=0;j<y_size;j++){
        if(x[i]==y[j]){
          mp[x[i]]=1;
        }
      }
    }
    int temp = 0;
    for(int i='a';i<'z'+1;i++){temp+=mp[char(i)];}
    if(temp>r){
      r = temp;
    }
  }
  
  
  cout << r << endl;
  
}

Measured memory_bytes: 256
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
string s;
void PrintStack(stack<char> s) 
{ 
    // If stack is empty then return 
    if (s.empty())  
        return; 
      
  
    char x = s.top(); 
  
    // Pop the top element of the stack 
    s.pop(); 
  
    // Recursively call the function PrintStack 
    PrintStack(s); 
  
    // Print the stack element starting 
    // from the bottom 
    cout << x ; 
  
    // Push the same element onto the stack 
    // to preserve the order 
    s.push(x); 
} 
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	stack<char> st;
	cin>>s;
	for(char ch: s)
	{
	    if(ch!='B')
	    st.push(ch);
	    else if(!st.empty())
	    st.pop();
	}
	PrintStack(st);
	return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <queue>
#include <string>
#include <map>
#include <fstream>
#include <cassert>
#include <stack>
#include <climits>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#include <functional>
#include <cfloat>
#include <numeric>

#include <atcoder/maxflow>
struct Coordinate {
	int x, y;
	std::vector<Coordinate> neighbor() const {
		return { Coordinate{x + 1, y}, Coordinate{x - 1, y}, Coordinate{x, y + 1}, Coordinate{x, y - 1} };
	}
};
int main() {
	int n, m; std::cin >> n >> m;
	std::vector<std::string> state(n);
	for (auto& line : state) std::cin >> line;
	atcoder::mf_graph<int> graph(n * m + 2);
	for (auto i = 0; i < n; ++i) {
		for (auto j = 0; j < m; ++j) {
			if (state[i][j] == '#') continue;
			if (((i ^ j) & 1) == 0) {
				graph.add_edge(n * m, i * m + j, 1);
				for (const auto neighbor : Coordinate{ i, j }.neighbor()) {
					if (neighbor.x < 0 || n <= neighbor.x) continue;
					if (neighbor.y < 0 || m <= neighbor.y) continue;
					if (state[neighbor.x][neighbor.y] == '#') continue;
					graph.add_edge(i * m + j, neighbor.x * m + neighbor.y, 1);
				}
			}
			else {
				graph.add_edge(i * m + j, n * m + 1, 1);
			}
		}
	}
	const auto flow = graph.flow(n * m, n * m + 1);
	auto result = state;
	for (const auto e : graph.edges()) {
		if (e.from >= n * m || e.to >= n * m) continue;
		const auto sx = e.from / m;
		const auto sy = e.from % m;
		if (e.flow == 0 || ((sx ^ sy) & 1) != 0) continue;
		const auto tx = e.to / m;
		const auto ty = e.to % m;
		if (sx < tx) {
			result[sx][sy] = 'v';
			result[tx][ty] = '^';
		}
		else if (tx < sx) {
			result[sx][sy] = '^';
			result[tx][ty] = 'v';
		}
		else if (sy < ty) {
			result[sx][sy] = '>';
			result[tx][ty] = '<';
		}
		else if (ty < sy) {
			result[sx][sy] = '<';
			result[tx][ty] = '>';
		}
		else {
			throw 0;
		}
	}
	std::cout << flow << '\n';
	for (const auto& line : result) std::cout << line << '\n';
}


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

int main(){
  int n, i, elm;
  int isFirst;

  while(cin>>n){
    elm=1; isFirst=1;
    for(i=0; i<10; i++){
      if(n%2==1){
        if(!isFirst) printf(" ");
        isFirst=0;
        printf("%d", elm);
      }
      n=n>>1; elm=elm<<1;
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>

using namespace std;

std::vector<int> Create_input_vector() {

   std::vector<int> vector;
   int size;

   cin >> size;
   vector.reserve(size);

   while (size--) {
      int value;
      cin >> value;
      vector.emplace_back(value);
   }

   return std::move(vector);

}

bool Exist_element(const std::vector<int>& list, int value) {

   if (value < list.front() || list.back() < value) {
      return false;
   }

   int begin = 0;
   int end = list.size() - 1;
   int now;
   while (now = (begin + end) / 2, begin != end) {
      int element = list.at(now);
      if (begin + 1 == end) {
         if (value == list.at(begin) || value == list.at(end)) {
            return true;
         }
         return false;
      }
      if (element < value) {
         begin = now;
         continue;
      }
      if (element > value) {
         end = now;
         continue;
      }
      return true;
   }

   return false;

}

int Count_same_element(const std::vector<int>& base, const std::vector<int>& other) {

   int count = 0;
   for (const auto element : base) {
      if (Exist_element(other, element)) {
         ++count;
      }
   }

   return count;

}

int main() {

   std::vector<int> S{ Create_input_vector() };
   std::vector<int> T{ Create_input_vector() };

   cout << Count_same_element(T, S) << endl;

   return 0;

}

Measured memory_bytes: 3340
import java.util.*;

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

        int N = sc.nextInt();
        long [] s = new long [N + 1];

        for (int i = 1; i <= N; i++) {
            s[i] = sc.nextInt(); 
            s[i] += s[i-1]; 
        }

        Arrays.sort(s);
        long cnt = 1;
        long total = 0;
        long prev = s[0];
        for (int i = 1; i <= N; i++){
            if (prev == s[i]) {
                cnt++;
            } else {
                prev = s[i];
                total += cnt * (cnt - 1) / 2;
                cnt = 1;
            }
        }
        total += cnt * (cnt - 1) / 2;
       System.out.println(total);
    }
}

Measured memory_bytes: 84080
x, n = map(int,input().split())
p = list(map(int,input().split()))

lst = [0]*102

for i in p:
    lst[i] = 1
    
if lst[x] == 0:
    print(x)
elif lst[x] == 1:
    for i in range(1, 102):
        if lst[x-i] == 0:
            print(x-i)
            exit()
        elif lst[x+i] == 0:
            print(x+i)
            exit()

Measured memory_bytes: 9176
using System;
class Program
{
    static void Main(string[] args)
    {
        string q01 = Console.ReadLine();
        int i01 = Convert.ToInt32(q01);
        string[] qAry = new string[3];
        qAry[0] = Console.ReadLine();
        qAry[1] = Console.ReadLine();
        qAry[2] = Console.ReadLine();
        int cnt = 0;
        for (int i = 0; i < i01; i++)
        {
            char datA = qAry[0][i];
            char datB = qAry[1][i];
            char datC = qAry[2][i];
            if (datA == datB)
            {
                if (datA != datC) cnt++;
            }
            else if (datA == datC || datB == datC)
            {
                cnt++;
            }
            else
            {
                cnt += 2;
            }
        }
        Console.WriteLine(cnt);
    }
}

Measured memory_bytes: 11220
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    foreach(s;stdin.byLine())
    {
        auto a = s.split(",").map!(to!real).array();
        immutable n = a.length, n2=n/2;
        auto v = iota(n2).map!"a*2"().map!(i=>[a[(i+2)%n]-a[i],a[(i+3)%n]-a[i+1]]).array();
        auto c = zip(v,cycle(v).drop(1).take(n2)).map!"a[0][0]*a[1][1]-a[1][0]*a[0][1]"().array();
        writeln((c.all!"a>0"() || c.all!"a<0")?"YES":"NO");
    }
}

Measured memory_bytes: 1144
#include<stdio.h>
int main(){
  int k,x;
  scanf("%d %d",&k,&x);
  int i;
  for(i=x-k+1;i<x+k;i++){
    if((i<=1000000)&&(i>=-1000000))printf("%d ",i);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3;
const lli INF = 1e18;
const lli MOD = 1e9+7;

vi m;
vi primes(1,2);
vector<vector<ld>>nk;
void sieve(){
	m = vi(N+1,0);
	for(int i = 4; i<N; i+=2)m[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!m[i])for(int j = i*i; j<N; j+=i)m[j]=1;
	for(int i = 3; i<N; i+=2)if(!m[i])primes.pb(i);
}

void pascal(){
	nk =vector<vector<ld>>(N,vector<ld>(N,0.0));
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7

void solve(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	ld h = 2*acos(-1)*(c*60+d)/720.0;
	ld mi = 2*acos(-1)*d/60.0; 
	cout<<fixed<<setprecision(10)<<sqrtl((a*a + b*b)- 2*a*b*cosl(h-mi))<<ENDL;
}

int main(){_
	//int t; cin>>t; while(t--)
	solve();
}


Measured memory_bytes: 4084
//
//  main.cpp
//  usaco
//
//  Created by 김현수 on 2020/08/30.
//  Copyright © 2020 김현수. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <string>
int main()
{
    int a, b, c, sum=0;
    scanf("%d %d %d", &a, &b, &c);
    if(a!=b)
    {
        sum++;
    }
    if(b!=c)
    {
        sum++;
    }
    if(c!=a)
    {
        sum++;
    }
    if(a==b and b==c and c==a)
    {
        printf("%d", 1);
    }
    else
    {
        printf("%d", sum);
    }
}


Measured memory_bytes: 3652
#include <stdio.h>
int calculate (int , int);
int main()
{
  int a,b;
  scanf("%d%d",&a,&b);
  printf("%d\n",calculate(a,b));
  return 0;
}

int calculate (int x, int y)
{
 int l;
  
  l=x%y;
  if(y>0&&l!=0)
    {
      x=y;
      y=l;
    }
  if(l==0) return y;
  else calculate(x,y);
}

Measured memory_bytes: 592
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	string s;cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


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

int main() {
	int k;
	cin >> k;
	int sm = 0;
	for(int a=1;a<=k;a++)
	{
		for(int b=1;b<=k;b++)
		{
			for(int c=1;c<=k;c++)
			{
				sm += gcd(a,gcd(b,c));
			}
		}
	}
	cout << sm << endl;
	return 0;
}


Measured memory_bytes: 3652
from collections import Counter
S = input()[::-1]
N = len(S)
l = [0]*N
for i in range(N):
    l[i] = (l[i-1]+int(S[i])*pow(10,i,2019))%2019
c = Counter(l)
c[0] += 1
ans = 0
for i in c.values():
    ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 16512
n = int(input())

if n >= 10 and n <= 99:
    print(9)
elif n >= 1000 and n <= 9999:
    print(909)
elif n == 100000:
    print(90909)
elif n < 10:
    print(n)
elif n >= 100 and n <= 999:
    print(9 + n - 99)
elif n >= 10000 and n <= 99999:
    print(909 + n - 9999)

Measured memory_bytes: 3060
class Dice(object):

    def __init__(self, n):
        self.n = n
    def move(self, to):
        if to == 'N':
            self.n[0], self.n[1], self.n[4], self.n[5] = self.n[1], self.n[5], self.n[0], self.n[4]
        elif to == 'E':
            self.n[0], self.n[2], self.n[3], self.n[5] = self.n[3], self.n[0], self.n[5], self.n[2]
        elif to == 'S':
            self.n[0], self.n[1], self.n[4], self.n[5] = self.n[4], self.n[0], self.n[5], self.n[1]
        elif to == 'W':
            self.n[0], self.n[2], self.n[3], self.n[5] = self.n[2], self.n[5], self.n[0], self.n[3]
    def top(self):
        return self.n[0]

dice = Dice([int(i) for i in input().split()])
move = input()
for m in move:
    dice.move(m)
print(dice.top())



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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define ALL(x) x.begin(),x.end()
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

inline bool LT(double a,double b) { return !equals(a,b) && a < b; }
inline bool LTE(double a,double b) { return equals(a,b) || a < b; }

const ll mod = 1000000007LL;

long long extgcd(long long a,long long b,long long& x,long long& y) {
  long long d = a;
  if(b != 0) {
    d = extgcd(b,a%b,y,x);
    y -= (a/b)*x;
  }
  else
    x = 1,y = 0;
  return d;
}

long long mod_inv(long long a,long long m) {
  long long x,y;
  extgcd(a,m,x,y);
  return (m+x%m)%m;
}


ll H,W,A,B;
#define MAX 10010000
ll fact[MAX];

void compute() {

}

int main() {
  fact[0] = 1;
  REP(i,1,MAX) fact[i] = ( fact[i-1] * (ll)i ) % mod;
  cin >> H >> W >> A >> B;
  ll ans = 0;
  ll x = B-1;
  for(ll y=0;y<H-A;++y) {
    ll v1 = 0;
    v1 = fact[x + y];
    v1 = ( v1 * mod_inv(fact[x],mod) ) % mod;
    v1 = ( v1 * mod_inv(fact[y],mod) ) % mod;
    //if( x <= 0 || y <= 0 ) v1 = 1;
    ll v2 = 0;
    ll rx = W - ( x + 1 ) - 1;
    ll ry = H - y - 1;
    v2 = fact[rx+ry];
    if( rx ) v2 = ( v2 * mod_inv(fact[rx],mod) ) % mod;
    if( ry ) v2 = ( v2 * mod_inv(fact[ry],mod) ) % mod;
    //if( rx <= 0 || ry <= 0 ) v2 = 1;
    ( ans += ( v1 * v2 ) % mod ) %= mod;
  }
  cout << ans % mod << endl;
  compute();
  return 0;
}


Measured memory_bytes: 78464
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        
        Scanner scanner = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        while (true) {
            int H = scanner.nextInt();
            int W = scanner.nextInt();
            
            if (H==0 && W==0) { break; }
            
            String[] mark = {"#", "."};
            int idx = 0;
            
            for (int i=0; i<H; i++) {
                for (int j=0; j<W; j++) {
                    idx = (i+j) % 2;
                    sb.append(mark[idx]);
                }
                sb.append("\n");
            }
            sb.append("\n");
            
        }
        
        System.out.print(sb.toString());
    }
}


Measured memory_bytes: 27352
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

// -------------------------------------------------------

int n;
vector<int> vec, rev, ansvec;

int main() {
  cin >> n;
  repe(i, 1, n) {
    int a;
    cin >> a;
    if (i % 2 == 1) {
      rev.push_back(a);
    } else {
      vec.push_back(a);
    }
  }

  reverse(rev.begin(), rev.end());

  for (auto e : rev) {
    ansvec.push_back(e);
  }

  for (auto e : vec) {
    ansvec.push_back(e);
  }

  if (n % 2 == 0) {
    reverse(ansvec.begin(), ansvec.end());
  }

  for (auto e : ansvec) {
    cout << e << " ";
  }
}

Measured memory_bytes: 5052
import java.util.*;

//update 2020/1/1 23:01

public class Main{

  static Scanner sc = new Scanner(System.in);
  static StringBuilder sb = new StringBuilder();

  public static void main(String[] args) {

    long X = nextLong();

    int a = (int)Math.sqrt((int)Math.sqrt(X));
    //System.out.println(a);


    for(int i=-1*a;i<=a;i++){
      for(int j=-1*a;j<=i;j++){
        double ans = Math.pow(i,5) - Math.pow(j,5);
        if((long)ans==X){
          System.out.println(i+" "+j);
          X = 0;
          break;
        }
      }
      if(X==0){
        break;
      }
    }




  }

  static int lcm(int a,int b){
    return a*b*gcd(a,b);
  }

  static int gcd(int a,int b){
    if(a%b!=0){
      return gcd(b,a%b);
    }
    else{
      return b;
    }
  }

  /*
    static String toSmall(String s){
      char c = s.charAt(0);
      //if(Character.isUpperCase(c)){
      if(c<=90){
        c += 32;
      }
      return String.valueOf(c);
    }
    static String toBig(String s){
      char c = s.charAt(0);
      //if(Character.isLowerCase(c)){
      if(c>=97){
        c -= 32;
      }
      return String.valueOf(c);
    }
  */

  static String toSmall(String s){
    return s.toLowerCase();
  }

  static String toBig(String s){
    return s.toUpperCase();
  }

  static String next(){
    return sc.next();
  }

  static int nextInt(){
    return Integer.parseInt(sc.next());
  }

  static long nextLong(){
    return Long.parseLong(sc.next());
  }

  static double nextDouble(){
    return Double.parseDouble(sc.next());
  }

  static String[] splitString(String s){
    return s.split("");
  }

  static char[] splitChar(String s){
    return s.toCharArray();
  }

  static int charToInt(char a){
    return a - 48;
  }

////////////////////////////////////////////
  public static int max(int[] a){
    int lng = a.length;
    int max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
  public static long max(long[] a){
    int lng = a.length;
    long max = a[0];
    for(int i=1;i<lng;i++){
      max = Math.max(max,a[i]);
    }
    return max;
  }
////////////////////////////////////////////

////////////////////////////////////////////
  public static int min(int[] a){
    int lng = a.length;
    int min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
  public static long min(long[] a){
    int lng = a.length;
    long min = a[0];
    for(int i=1;i<lng;i++){
      min = Math.min(min,a[i]);
    }
    return min;
  }
////////////////////////////////////////////

}


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

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

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}

int main(){
  string N;
  cin >> N;
  string ans = "ABC" + N;
  cout << ans << endl;
 
 }

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>
#include <map>

class UnionFind {
  std::vector<intmax_t> tree;

public:
  UnionFind(size_t n): tree(n, -1) {}

  size_t find(size_t v) {
    if (tree[v] < 0)
      return v;

    return (tree[v] = find(tree[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v)
      return false;

    if (-tree[u] >= -tree[v])
      std::swap(u, v);

    tree[v] += tree[u];
    tree[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) {
    return (find(u) == find(v));
  }

  size_t size(size_t v) {
    return -tree[find(v)];
  }
};

using Edge = std::pair<size_t, size_t>;

struct Query {
  size_t t, u, v;
  Query(size_t t, size_t u, size_t v): t(t), u(u), v(v) {}
};

void resolve(
    size_t n, std::set<Edge>& e, std::set<Edge>& s, std::vector<Query>& q) {

  std::map<size_t, size_t> vb;
  for (size_t i=0; i<q.size(); ++i) {
    for (size_t v: {q[i].u, q[i].v}) {
      auto it=vb.lower_bound(v);
      if (it != vb.end() && it->first == v) continue;
      vb.emplace_hint(it, v, vb.size());
    }
  }

  UnionFind uf(n);
  std::set<Edge> eh;
  for (const auto& ei: e) {
    size_t u=ei.first, v=ei.second;
    if (s.count({u, v})) {
      eh.emplace(u, v);
    } else {
      uf.unite(u, v);
    }
  }

  UnionFind uf_mini(vb.size());
  for (const auto& s: vb) {
    for (const auto& d: vb) {
      if (!uf.connected(s.first, d.first)) continue;
      uf_mini.unite(s.second, d.second);
    }
  }

  for (size_t i=0; i<q.size(); ++i) {
    size_t t=q[i].t, u=q[i].u, v=q[i].v;
    if (t == 1) {
      e.emplace(u, v);
      eh.emplace(u, v);
    } else if (t == 2) {
      e.erase({u, v});
      eh.erase({u, v});
    } else if (t == 3) {
      UnionFind tmp=uf_mini;
      for (const auto& s: eh) {
        size_t u0=vb.at(s.first), v0=vb.at(s.second);
        tmp.unite(u0, v0);
      }
      printf("%s\n", tmp.connected(vb.at(u), vb.at(v))? "YES":"NO");
    }
  }

  s.clear();
  q.clear();
}

int main() {
  size_t n, k;
  scanf("%zu %zu", &n, &k);

  std::set<Edge> e, s;
  std::vector<Query> q;
  for (size_t i=0; i<k; ++i) {
    size_t t, u, v;
    scanf("%zu %zu %zu", &t, &u, &v);

    q.emplace_back(t, u, v);
    if (t == 2) {
      s.emplace(u, v);
    }

    if ((i+1) % 256 == 0 || i+1 == k) {
      resolve(n, e, s, q);
    }
  }
}



Measured memory_bytes: 5092
/*
  ∧,,∧
( 'ω' )つ ＜WA,またお前か！！　
（m9 ＼ 　　
　 ＼　 ＼
　 　 ) ) ＼
　 ／／ ＼ ＼
　 (＿） 　 (＿)
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    cout << r * r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
#include <iomanip>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n,m;
	cin >> n >> m;
	
	int submit = 1900*m + 100*(n-m);
	REP(i,m) submit*=2;
	
	cout << submit << endl;
	
	return 0;
}

Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int l = sc.nextInt();
        
        String[] s = new String[n];
        
        for(int i = 0; i < n; i++) s[i] = sc.next();
        
        Arrays.sort(s);
        
        for(int i = 0; i < n; i++) System.out.print(s[i]);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,a,b;	cin >> k >> a >> b;
  for(int i=a;i<b+1;i++){
    if(i%k==0){
      cout << "OK";
      return 0;
    }
  }
  cout << "NG";
}

Measured memory_bytes: 3568
# -*- coding: utf-8 -*-
import sys
inf = sys.maxsize

n, k = map(int,input().split())
h = [int(i) for i in input().split()]

"""
dp = [0] * n
dp[0] = 0
for i in range(1,n):
    if i < k:
        dp[i] = inf
        for j in range(1, i + 1):
            if dp[i - j] + abs(h[i] - h[i - j]) < dp[i]:
                dp[i] = dp[i - j] + abs(h[i] - h[i - j])
    elif i >= k:
        dp[i] = inf
        for j in range(1, k + 1):
            if dp[i - j] + abs(h[i] - h[i - j]) < dp[i]:
                dp[i] = dp[i - j] + abs(h[i] - h[i - j])
print(dp[n - 1])
"""

dp = [0] * n
dp[0] = 0
for i in range(1,n):
    dp[i] = inf
    for j in range(1, min(i, k) + 1):
        if dp[i - j] + abs(h[i] - h[i - j]) < dp[i]:
            dp[i] = dp[i - j] + abs(h[i] - h[i - j])
print(dp[n - 1])


Measured memory_bytes: 52728
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main()
{
    int k;
    int u;
    int ci=0;
    char a[100];
    scanf("%s",a);
    int len=strlen(a);
    int i;
    int j;
    for(i=0;i<len;i++)
        for(j=i;j<len;j++)
    {
        for(u=0,k=i;k<=j;k++)
        {
            if(a[k]!='A'&&a[k]!='T'&&a[k]!='C'&&a[k]!='G')
            {u=1;break;}
        }
        if(u==0)
        if(j-i+1>ci)
            ci=j-i+1;
    }
    printf("%d\n",ci);

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  string S;
  cin >> N;
  cin >> S;
  
  //色ごとの数を数える
  long long R = 0;
  long long G = 0;
  long long B = 0;
  for (long long i = 0; i < N; i++){
    if (S.at(i) == 'R'){
      R++;
    }
    else if (S.at(i) == 'G'){
      G++;
    }
    else {
      B++;
    }
  }
  long long count = R * G * B;//各色の数の積=三色になる(i,j,k)の数
  
  //三色になる(i-j,i,i+j)の数を引く
  for (long long i = 1; i < N - 1; i++){
    for (long long j = 1; j <= min(i, N - 1 - i) ; j++){
      if (S.at(i - j) != S.at(i) && S.at(i) != S.at(i + j) && S.at(i - j) != S.at(i + j)){
        count--;
      }
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3612
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	var grid [3][3]int
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			grid[i][j] = nextInt()
		}
	}
	c := grid[0][0] + grid[1][1] + grid[2][2]
	if c != grid[0][1]+grid[1][2]+grid[2][0] || c != grid[0][2]+grid[1][0]+grid[2][1] {
		fmt.Printf("No")
		return
	}
	fmt.Printf("Yes")
	return
}


Measured memory_bytes: 640
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())
        S = input().rstrip()

        ans = ''
        for c in S:
            ans += chr(((ord(c) - 65) + N) % 26 + 65)
        print(ans)


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 41324
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  int N;
  cin >> N;
  int A[N], B[N];
  rep(i, N)
    cin >> A[i];
  rep(i, N)  
    cin >> B[i];
  // 入力終了

  // 現在の準備と必要な準備度の差分
  int sub[N];
  rep(i, N)
    sub[i] = A[i] - B[i];
  
  sort(sub, sub+N);

  int ans = 0;
  
  // 足りない準備度の和 (マイナスだったら足せばOK)
  long long sum = 0;
  rep(i, N){
    // 準備度が足りない
    if(sub[i] < 0){
      sum += sub[i];
      // 準備度が足りないなら変更しないといけない
      ans++;
    }
    // 準備度が足りてるならそれ以降は見なくてOK
    else
      break;
  }

  // 正のほうが計算しやすい
  sum = -sum;
  
  // 余剰の準備度から分配していく
  for(int i=N-1; i>=0; i--){
    // 分配し終わった
    if(sum <= 0)
      break;
    // 途中でsub[i]<0になったら100％ムリ
    if(sub[i] < 0){
      cout << -1 << endl;
      return 0;
    }

    // 余剰分を引いていく
    sum -= sub[i];
    ans++;
  }

  // 解答
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4740
import math
n = int(input())
ans = float('inf')
i = 1
while i <= math.sqrt(n):
    if n % i == 0:
        a = int(len(str(i)))
        b = int(len(str(n // i)))
        ans = min(ans,max(a,b))
    i += 1
print(ans)

Measured memory_bytes: 9092
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9

int n,m;
int a[1000],b[1000],c[1000],dist[1000][1000];

int main(){

  cin>>n>>m;

  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--,b[i]--;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i==j) dist[i][j]=0;
      else dist[i][j]=inf;
    }
  }

  for(int i=0;i<m;i++){
    dist[a[i]][b[i]] = min(dist[a[i]][b[i]],c[i]);
    dist[b[i]][a[i]] = min(dist[b[i]][a[i]],c[i]);
  }

  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++)
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
    }
  }

  int ans = m;
  for(int i=0;i<m;i++){
    bool s = false;
    for(int j=0;j<n;j++)
      if(dist[j][a[i]]+c[i]==dist[j][b[i]]) s = true;
    if(s) ans--;
  }

  cout<<ans<<endl;

  return 0;
}




Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <cinttypes>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;

    gc(N);

    vector<int> A;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        gc(tmp);
        A.push_back(tmp);
    }

    sort(A.begin(), A.end(), greater<int>());

    int bk = -1;
    int64_t first = -1;
    int64_t second = -1;
    for (int i = 0; i < N; i++)
    {
        if (bk != A[i]) bk = A[i];
        else
        {
            if (first == -1)
            {
                first = bk;
                bk = -1;
            }
            else if(second == -1)
            {
                second = bk;
                break;
            }
        }
    }

    printf("%" PRId64 "\n",
        (first == -1) || (second == -1) ? 0 : first * second);
    return 0;
}


Measured memory_bytes: 892
#include<stdio.h>
int main()
{
	int i,j,a,b,c,t=0;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){t=b;b=a;a=t;}
	if(a>c){t=c;c=a;a=t;}
	if(b>c){t=c;c=b;b=a;}
	printf("%d\n",c-a);
	return 0;
}

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

int main(){
  int x,y;

  scanf(" %d %d",&x,&y);

  int t=x;
  x=max(x,y);
  y=min(t,y);



  int ans=x;

  while(x%y!=0){
    ans=x%y;
    x=y;
    y=ans;
  }


  cout << ans << endl;

  return 0;

}

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

using namespace std;

int main()
{
  ll a, b;
  cin >> a >> b;
  ll sum = a + b;
  if(sum & 1)
    puts("IMPOSSIBLE");
  else
    cout << sum / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
def gcd (a,b):
    if b == 0:
        return a
        
    return gcd(b, a % b)

inp = input().split()
inp = [int(x) for x in inp]

p = input().split()
p = [int(x) for x in p]

ans = gcd(abs(inp[1]-p[0]), abs(inp[1]-p[0]))
for i in range(len(p)):
    ans = gcd(ans, abs(inp[1]-p[i]))

print(ans)


Measured memory_bytes: 14252
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
    public static void main (String[] args)
    {
        // your code goes here
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] h = new int[n];
        long sum = 0;
        for(int j=0; j<n; j++)
            h[j] = s.nextInt();

        for(int j=1; j<n; j++)
        {
            if(h[j-1]>h[j])
            {
                sum+=h[j-1]-h[j];
                h[j] = h[j-1];
            }
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 60820
import java.util.Scanner;

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

        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (Math.abs(x - a) > Math.abs(x - b))
            System.out.println("B");
        else
            System.out.println("A");
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

//void C_116()
int main()
{
  int N;
  cin >> N;
  
  vector<int> h(N);
  for (int i = 0; i < N; ++i) cin >> h[i];

  int active = 0;
  int ans = 0;

  for (int i = 0; i < N; ++i)
  {
    if (active >= h[i])
    {
      active = h[i];
    }
    else
    {
      ans += h[i] - active;
      active = h[i];
    }
  }

  cout << ans << endl;
}

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

void solve(int a,int b){
    int c=a*a+b*b;
    bool s=false;
    while(1){
        for(int i=1;i<=150;i++){
            for(int j=i+1;j<=150;j++){
                if((s||i>a)&&i*i+j*j==c){
                    cout<<i<<" "<<j<<endl;
                    return;
                }
            }
        }
        c++;
        s=true;
    }
}


int main(void){
    int a,b;
    while(cin>>a>>b,a){
        solve(a,b);
    }
}



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

int main(){
    using namespace std;
    unsigned long a, b, x;
    cin >> a >> b >> x;
    cout << setprecision(15);
    if(a * a * b <= x * 2){
        cout << atan2(static_cast<long double>(2 * (a * a * b - x)), static_cast<long double>(a * a * a)) * 180 / 3.1415926535897932384626433 << endl;
    }else{
        cout << static_cast<long double>(90) - atan2(static_cast<long double>(2 * x), static_cast<long double>(a * b * b)) * 180 / 3.1415926535897932384626433 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define INF 1LL << 60;
 
int main() {
  
  int N;
  cin >> N;
  int K;
  cin >> K;
  
  int h[N+K];
  ll dp[N+K];
  
  for(int i=0; i<N+K; i++){
    cin >> h[i];
  }
  
  for(int i=0; i<N+K; i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int i=0; i < N; i++){
    for(int j=1; j <= K; j++){
      dp[i+j] = min(dp[i+j], dp[i]+abs(h[i+j]-h[i]));
    }
    
  }
  
  cout << dp[N-1] <<endl;
  
}

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

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

template <class T>
struct Kruskal {
  struct UnionFind {
    int N;
    vector<int> sz_tree, parent;
    UnionFind() {}
    UnionFind(int N) : N(N), sz_tree(N, 1), parent(N) {
      iota(parent.begin(), parent.end(), 0);
    }
    int root(int x) {
      return parent[x] == x ? x : parent[x] = root(parent[x]);
    }
    void merge(int x, int y) {
      if ((x = root(x)) == (y = root(y))) return;
      if (sz_tree[x] < sz_tree[y]) swap(x, y);
      sz_tree[x] += sz_tree[y];
      parent[y] = x;
    }
    bool same(int x, int y) {
      return root(x) == root(y);
    }
    int size(int x) {
      return sz_tree[root(x)];
    }
  };
  struct edge {
    int from, to; T cost;
    edge() {}
    edge(int f, int t, T c) : from(f), to(t), cost(c) {}
  };
 
  int N;
  vector<edge> es;
  Kruskal() {}
  Kruskal(int N) : N(N) {}
 
  void add_edge(int from, int to, T cost) {
    es.emplace_back(from, to, cost);
  }
  T mst() {
    T res = 0;
    UnionFind uf(N);
    sort(es.begin(), es.end(), [&](edge a, edge b) {
      return a.cost < b.cost;
    });
    for (auto &e : es) {
      if (uf.same(e.from, e.to)) continue;
      uf.merge(e.from, e.to);
      res += e.cost;
    }
    return res;
  }
};

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, m;
  while (cin >> n >> m, n) {
    Kruskal<int> K(n);
    for (int i = 0; i < m; i++) {
      int a, b, cost;
      cin >> a >> b >> cost;
      K.add_edge(a, b, cost);
      K.add_edge(b, a, cost);
    }
    cout << K.mst() << endl;
  }

  return 0;
}


Measured memory_bytes: 3168
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int n;
  cin >> n;
  int c = 0;
  rep(i, n) {
    string s;
    cin >> s;
    c += (s == "A") - (s == "Un");
    if (c < 0) {
      cout << "NO" << endl;
      return;
    }
  }
  cout << (c ? "NO" : "YES") << endl;
}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define INF 999999999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(30) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 5100000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  lli A,B,C,D,E,F,N,M,K,L,R,X,Y,Z,H,W,sum=0,num=0,flag=0;string S,T;
  cin >> N >> M;
  DV(P,lli,8,N,0);
  rep(i,0,N){
    cin >> A >> B >> C;
    P[0][i]=A+B+C;
    P[1][i]=A+B-C;
    P[2][i]=A-B+C;
    P[3][i]=A-B-C;
    P[4][i]=-A+B+C;
    P[5][i]=-A+B-C;
    P[6][i]=-A-B+C;
    P[7][i]=-A-B-C;
  }
  rep(i,0,8){
    Sort(P[i]);
    Rev(P[i]);
  }
  rep(i,0,8){
    sum=0;
    rep(j,0,M)sum+=P[i][j];
    sum=abs(sum);
    chmax(num,sum);
  }
  Out(num);
}


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

namespace AtTest.C_Challenge
{
    class ABC_072
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int n = ReadInt();
            int[] array = ReadInts();
            var cnts = new int[100000 + 2];// -1 ~ 100000
            for (int i = 0; i < n; i++)
            {
                cnts[array[i] - 1 + 1]++;
                cnts[array[i] + 1]++;
                cnts[array[i] + 1 + 1]++;
            }
            int maxIndex = 0;
            for(int i = 1; i < cnts.Length; i++)
            {
                if (cnts[maxIndex] < cnts[i])
                {
                    maxIndex = i;
                }
            }
            Console.WriteLine(cnts[maxIndex]);
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 19168
A, B = map(str, input().split())
A = int(A)
B1, B2, B3 = int(B[0]), int(B[2]), int(B[3])
ans = A*B1*100 + A*B2*10 + A*B3
ans = str(ans)
if len(ans)>2:
    print(int(ans[:-2]))
else:
    print(0)


Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define req(i,a,b) for(ll i=(a);i>=(b);--i)
#define name "a"
#define pb push_back
#define sz size()
#define ff first
#define ss second
#define xd '\n'
#define dc " "
#define Truong_Thanh_Minh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair < ll , ll > ii;
const ll maxn = 1e5+7, oo = 1e18, base = 311, mod = 1e9+7;
const double PI = 3.141592654;
ll t, n, d, s;
int main()
{
    Truong_Thanh_Minh
    //freopen(name".inp","r",stdin);
    //freopen(name".out","w",stdout);
    cin >> d >> t >> s;
    if (d <= s*t)
        cout << "Yes\n";
    else cout << "No\n";
}


Measured memory_bytes: 3652
#include <cstdio>
#include <cstring>
#include <cmath>

#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <set>
#include <map>

using namespace::std;

#define ls t<<1
#define rs (t<<1)|1
#define sqr(x) ((x)*(x))

const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int maxn = 500 + 10;
const int maxm = 1e4 + 10;
const int mod = 1e9 + 7;
int n;
double d[maxn], r[maxn];

int main()
{
	while (~scanf("%d", &n))
	{
		for (int i = 0; i < n; i++)
			scanf("%lf", &r[i]);
		memset(d, 0, sizeof(d));
		d[0] = r[0];
		for (int i = 1; i < n; i++)
		{
			for (int j = i - 1; j >= 0; j--)
				d[i] = max(d[j] + 2 * sqrt(r[i] * r[j]), d[i]);
			d[i] = max(r[i], d[i]);
		}
		double ans = 0;
		for (int i = 0; i < n; i++)
			ans = max(ans, r[i] + d[i]);
		printf("%.8lf\n", ans);
	}
}

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

using namespace std;

int n;
long long a[3000], x[3000][3000], y[3000][3000];

void dfs(int left, int right, int turn) { 
    if(left + 1 <= right && x[left+1][right] == 0 && y[left+1][right] == 0) dfs(left+1, right, 1-turn);
    if(left <= right - 1 && x[left][right-1] == 0 && y[left][right-1] == 0) dfs(left, right-1, 1-turn);
    if(turn) {
        if(x[left+1][right]+a[left]-y[left+1][right] > x[left][right-1]+a[right]-y[left][right-1]) {
            x[left][right] = x[left+1][right] + a[left];
            y[left][right] = y[left+1][right];
        } else {
            x[left][right] = x[left][right-1] + a[right];
            y[left][right] = y[left][right-1];
        }
    } else {
        if(x[left+1][right]-y[left+1][right]-a[left] < x[left][right-1]-y[left][right-1]-a[right]) {
            y[left][right] = y[left+1][right] + a[left];
            x[left][right] = x[left+1][right];
        } else {
            y[left][right] = y[left][right-1] + a[right];
            x[left][right] = x[left][right-1];
        }
    }
}

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

    dfs(0, n-1, 1);

    cout << x[0][n-1]-y[0][n-1] << "\n";
}

Measured memory_bytes: 139904
n,k = map(int,input().split())
trees = []
for _ in range(n):
    trees.append(int(input()))
trees.sort()
ans = 10**9
for i in range(n):
    if i+k -1 ==n:
        break
    ans = min(ans,trees[i+k-1] -trees[i])
print(ans)

Measured memory_bytes: 7384
let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n

let () = print_endline @@ match n mod 10 with
  | 2 | 4 | 5 | 7 | 9 -> "hon"
  | 0 | 1 | 6 | 8 -> "pon"
  | _ -> "bon"


Measured memory_bytes: 3732
#include<stdio.h>

int i;
int j;
int k;


int main(void)
{
    int n, y;
    int ansa = -1;
    int ansb = -1;
    int ansc = -1;
    int frag;
    scanf("%d %d", &n, &y);
    

    for(i=0;i<=n;i++){
        for(j=0;j<=(y-10000*i)/5000;j++){
            k = n-i-j;
        
            if(10000*i+5000*j+1000*k==y){
                ansa=i;
                ansb=j;
                ansc=k;
                
            }
        }
    }

    printf("%d %d %d\n",ansa, ansb, ansc);

}

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

int main(){
    int a,b;
    char op;
    while(cin>>a>>op>>b&&op!='?'){
        if(op=='+') cout<<a+b<<endl;
        else if(op=='*') cout<<a*b<<endl;
        else if(op=='/') cout<<a/b<<endl;
        else if(op=='%') cout<<a%b<<endl;
        else if(op=='-') cout<<a-b<<endl;
    }
}


Measured memory_bytes: 3092
#include<iostream>
using namespace std;
int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		int a[9];
		for(int i=0;i<9;i++){
			cin>>a[i];
			n-=a[i];
		}
		cout<<n<<endl;
	}
}			



Measured memory_bytes: 2980