akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
      	int num = 1;
      	for(int i=0;i<9;i++){
          	if(N-111>0){
            	N -= 111;
            }else{
            	num += i;
              	break;
            }
        }
        System.out.println(num*111);
    }
}

Measured memory_bytes: 23380
#include<stdio.h>
int main(void){
  int Line,Column;
  int i,j,num;
  scanf("%d%d",&Line,&Column);
  int A[Line][Column],b[Column];
  for(i=0;i<Line;i++){
    for(j=0;j<Column;j++){
      scanf("%d",&A[i][j]);
    }
  }
  for(i=0;i<Column;i++){
    scanf("%d",&b[i]);
  }

  for(i=0;i<Line;i++){
    num=0;
    for(j=0;j<Column;j++){
      num+=A[i][j]*b[j];
    }
    printf("%d\n",num);
  }
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>

using namespace std;

int main(){
  //ifstream in("input.txt");
  //cin.rdbuf(in.rdbuf());

  string S;
  long long K;

  cin>>S;
  cin>>K;

  long long cou=0;

  if(K<=S.size()){
    for(long long i=0;i<K;i++){
      if(S.at(i)=='1'){
        cou++;
      }
    }
  }

  if(cou==K){
    cout<<1<<endl;
    return 0;
  }

  for(int i=0;i<S.size();i++){
    if(S.at(i)!='1'){
      cout<<S.at(i)<<endl;
      return 0;
    }
  }


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi        first
#define se        second
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long uLL;
typedef pair<int,int> Pii;
typedef pair<ll,ll>   Pll;
typedef pair<ll,int>  Pli;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int main()
{
	IOS();
	
	string s,t;
	cin>>s>>t;
	cout<<t<<s<<endl; 
	
	
	return 0;
}



Measured memory_bytes: 256
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

import           Control.Monad.Writer
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

main = do
  BS.getLine
  a <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  b <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve $ Cities (map MonsterCount a) (map SavePower b)

solve :: Cities -> Int
solve cities = getSum killResult
  where
    (_, KillResult killResult) = runWriter $ killThemAll cities

newtype MonsterCount =
  MonsterCount Int

newtype SavePower =
  SavePower Int

newtype KillResult =
  KillResult (Sum Int)
  deriving (Monoid)

data Cities =
  Cities
    { monsterCounts :: [MonsterCount]
    , saverPowers   :: [SavePower]
    }

killThemAll :: Cities -> Writer KillResult ()
killThemAll Cities {saverPowers = []} = writer ((), KillResult $ Sum 0)
killThemAll cities =
  firstSaverSaveFirstCity cities >>= firstSaverSaveSecondCity >>=
  killThemAll . restCities
  where
    firstSaverSaveFirstCity :: Cities -> Writer KillResult Cities
    firstSaverSaveFirstCity Cities {monsterCounts = m:ms, saverPowers = s:ss} =
      writer (Cities (mAfter : ms) (sAfter : ss), killCount)
      where
        (mAfter, sAfter, killCount) = kill m s
    firstSaverSaveSecondCity :: Cities -> Writer KillResult Cities
    firstSaverSaveSecondCity Cities { monsterCounts = m1:m2:ms
                                    , saverPowers = s:ss
                                    } =
      writer (Cities (m1 : m2After : ms) (sAfter : ss), killCount)
      where
        (m2After, sAfter, killCount) = kill m2 s
    kill :: MonsterCount -> SavePower -> (MonsterCount, SavePower, KillResult)
    kill (MonsterCount mc) (SavePower sp) =
      ( MonsterCount (mc - killCount)
      , SavePower (sp - killCount)
      , KillResult $ Sum killCount)
      where
        killCount :: Int
        killCount = min mc sp
    restCities :: Cities -> Cities
    restCities Cities {monsterCounts = m:ms, saverPowers = s:ss} = Cities ms ss


Measured memory_bytes: 12284
/*Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
vector<long long>v;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n;
    string s,ss;
    cin>>s>>ss;
    f=1;g=0;
    for(i=0; i<n; i++)
    {
        if(s[i]==ss[i]){
            if(i==0){
                f*=3;
            }
            else if(!g){
                f*=2;
            }
            g=0;
            f%=pi;
        }
        else{
            if(i==0){
                f*=2*3;
            }
            else if(!g){
                f*=2;
            }
            else f*=3;
            i++;
            g=1;
            f%=pi;
        }
    }
    cout<<f<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<long long int>arr(n);
long long int all(0);
for(int i=0; i<n; ++i)
{
cin>>arr[i];
all+=arr[i];
}
long long int sum(0),mn(1000000000000000000LL);
for(int i=0; i<n-1; ++i)
{
sum+=arr[i];
mn=min(mn,abs(sum-(all-sum)));
}
cout<<mn;
}

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

int main() {
  int n;cin>>n;
  int c=0;
  int a=n;
  while (a>0) {
    a/=10;
    c++;
  }
  if (c==1) cout<<n<<endl;
  else if (c==2) cout<<9<<endl;
  else if (c==3) cout<<n-90<<endl;
  else if (c==4) cout<<909<<endl;
  else if (c==5) cout<<n-9090<<endl;
  else if (c==6) cout<<90909<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>

int calculateMin(int amount){
  int A, B, C, maxA, maxB, maxC, minPrice=9000, price;
  maxA = (amount - amount%200)/200;
  maxB = (amount - amount%300)/300;
  maxC = (amount - amount%500)/500;
  for(A=0; A<=maxA; A++){
    for(B=0; B<=maxB; B++){
      for(C=0; C<=maxC; C++){
        if(200*A+300*B+500*C==amount){
          price = 380*((A/5)*5*0.80+A%5) + 550*((B/4)*4*0.85+B%4) + 850*((\
C/3)*3*0.88+C%3);
          if(price<=minPrice){
            minPrice = price;
          }
        }
      }
    }
  }
  return minPrice;
}
int main(){
  int amount;
  while(scanf("%d", &amount), amount){
    printf("%d\n", calculateMin(amount));
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define lcm(x, y) ((x) * (y) / __gcd((x), (y)))
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#include <iostream>

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1}; // trick to explore an implicit 2D grid
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1}; // S,SE,E,NE,N,NW,W,SW neighbors  //GO FOR EVEN FOR 4 moves

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
        }
        base = base * base;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n,i,j,k,t,temp,tc;
    string s[]={"AC","WA","TLE","RE"};
    string str="";
    cin>>n;
    LL cnt[4]={0};
    for(i=0;i<n;i++)
    {
        cin>>str;
        if(str[0]=='A')
        {
            cnt[0]++;
        }
        if(str[0]=='W')
        {
            cnt[1]++;
        }
        if(str[0]=='T')
        {
            cnt[2]++;
        }
        if(str[0]=='R')
        {
            cnt[3]++;
        }
    }

    for(i=0;i<4;i++)
    {
        cout<<s[i]<<" x "<<cnt[i]<<endl;
    }

    return 0;
}


Measured memory_bytes: 3668
# coding: utf-8
orders = list(input())
out_list = []
for od in orders:
  if od == "0":
    out_list.append("0")
  elif od == "1":
    out_list.append("1")
  elif od == "B":
    if len(out_list) != 0:
      out_list.pop(-1)
out_str = "".join(out_list)
print(out_str)

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

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    int res;
    for(int i=n;;i++){
        string s=to_string(i);
        if(s.substr(0,1)==s.substr(1,1) && s.substr(0,1)==s.substr(2,1)){
            res=i;
            break;
        }
    }
    p(res)
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int X, Y; cin >> X >> Y;
  bool flag = false;
  for (int a=0;a<=X;a++){
    int b = X-a;
    if (2*a+4*b==Y) flag = true;
  }
  cout << (flag ? "Yes" : "No") << endl;

  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 3636
#include <stdio.h>

#define MAX_NUMBER_OF_SEQUENCE	100000 /* 2 <= n <= 10^5 */

int main()
{
    int n;
    int sequence[MAX_NUMBER_OF_SEQUENCE];
    int sum;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
	scanf("%d", &sequence[i]);
    }

    sum = 0;
    for (int i = 0; i < n; i++)
    {
	sum = sum + sequence[i];
    }

    if ((sum % 2) == 0)
    {
	printf("YES\n");
    }
    else
    {
	printf("NO\n");
    }

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;

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


Measured memory_bytes: 3160
N = int(input())

div = set()
for i in range(1, N + 1) :
  if i * i > N : 
    break
    
  if N % i == 0 :
    div.add(i)
    if i != N // i :
      div.add(N // i)

N = N - 1
for i in range(1, N + 1) :
  if i * i > N : 
    break
    
  if N % i == 0 :
    div.add(i)
    if i != N // i :
      div.add(N // i)

def check(x) :
  n = N + 1
  while n >= x :
    if n % x == 0 :
      n //= x
    else :
      n %= x
      
  return n == 1

ret = 0
for x in list(div) :
  if x == 1 : continue
  if check(x) :
    ret += 1
      
print(ret)

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

using namespace std;

int var[105];

int main(){
  int n, m = 0;
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i){
    int x;
    scanf("%d", &x);
    x /= 400; 
    if(x >= 8){
      ++m;
    }
    else{
      ++var[x];
    }
  }
  int minVal = 0;
  for(int i = 0; i < 8; ++i){
    if(var[i]){
      ++minVal;
    }
  }
  int maxVal = minVal;
  maxVal += m;
  printf("%d %d\n", max(minVal, 1), maxVal);
  return 0;
}


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

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    int x[N], y[N];
    int l = 100001;
    int t[l + 1]{};
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        t[x[i]] = max(t[x[i]], y[i]);
    }

    int Y = 0;
    int ans = 2 * l;
    for (int i = l; i >= 0; i--) {
        ans = min(ans, i + Y);
        Y = max(Y, t[i]);
    }
    cout << ans << "\n";
    //
    // for (int i = 0; i < N; i++) {
    //     cout << d[i].x << " " << d[i].y << "\n";
    // }
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll a, b, c, ans = 0;
  cin >> a >> b >> c;

  if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0)
    cout << 0 << endl;
  else
    cout << min({a * b, b * c, a * c}) << endl;

  return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
typedef long long ll;
#define MAX_N (100010)
int a[MAX_N];
int N;
int main()
{
    scanf("%d", &N);
    for ( int i = 0; i < N; i++ ) {
	scanf("%d", &a[i]);
	a[i]--;
    }
    int ans = 0;
    for ( int i = 0; i < N; i++ ) {
	if ( i == a[a[i]] ) ans++;
    }

    printf("%d\n", (ans>>1));
    return 0;
}


Measured memory_bytes: 640
#include <cstdio>

const int MAXN = (int)1e5;

int a[MAXN];


int main() {
  int n, k, q;
  scanf("%d %d %d", &n, &k, &q);
  for (int i = 0, cur; i < q; ++i) {
    scanf("%d", &cur);
    ++a[cur];
  }
  for (int i = 1; i <= n; ++i) {
    if (k + a[i] - q > 0) puts("Yes");
    else puts("No");
  }
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int X, Y;
    cin >> X >> Y;

    bool ok = false;
    for (int kame = 0; !ok && kame <= X; ++kame) {
        ok = (kame*4+2*(X-kame) == Y);
    }

    cout << (ok ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 3644
#include <iostream>

using namespace std;

void selectionSort(int *,int);

int main(){
	int n;
	cin>>n;
	int *array;
	array=new int [n];
	if (array==NULL){
		cout<<"Error!"<<endl;
		return -1;
	}
	for (int i=0;i<n;i++){
		cin>>array[i];
	}
	selectionSort(array,n);
	delete [] array;
	return 0;
}

void selectionSort(int *a,int n){
	int cnt=0;
	for (int i=0;i<n;i++){
		int mini=i;
		for (int j=i;j<n;j++){
			if (a[j]<a[mini]){
				mini=j;
			}
		}
		if (i!=mini){
			int temp;
			temp=a[i];
			a[i]=a[mini];
			a[mini]=temp;
			cnt++;
		}
	}
	for (int i=0;i<n;i++){
		cout<<a[i];
		if (i!=n-1){
			cout<<" ";
		}
	}
	cout<<endl;
	cout<<cnt<<endl;
}

Measured memory_bytes: 1196
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	unsigned long long A;
	cin >> A;

	string B;
	cin >> B;

	unsigned long long nB = 0;
	for (char ch : B)
	{
		if (ch != '.')
		{
			nB *= 10;
			nB += (ch - '0');
		}
	}

	cout << (A * nB) / 100;

	return 0;
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

#define X real()
#define Y imag()

using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9 + 7;

const int dx[] = {0, 0,1,-1,1,-1, 1,-1};
const int dy[] = {1,-1,0, 0,1,-1,-1, 1};

const int N = 1e5 + 5;




void mul(long long &a,long long b){
        a = ((a % mod) * (b % mod))%mod;
}
long long fp(long long b, long long p){
        long long ret = 1;
        while(p){
                if(p&1)
                    mul(ret,b);
                mul(b,b);
                p >>= 1;
        }
        return ret;
}
long long inv(long long a){
        return fp(a , mod - 2);
}
void add(long long &a , long long b){
    a = ((a%mod) + (b%mod))%mod;

}
void sub(long long &a, long long b){
    a = ((a%mod)-(b%mod))%mod;
    if(a<=0)
        a+=mod;
}
long long n , arr[N],k;
long long ncr[N],f[N];;
void init(int n ,int r){
        for(int i = 0; i <= n; ++i)
                f[i] = 1,ncr[i]=1;

        for(int i = 1; i <= n; ++i)
            mul(f[i],((1ll * i%mod) * (f[i - 1]%mod))%mod);

        for(int i = n; i >= r; --i){
            mul(ncr[i],f[i]);
            mul(ncr[i],inv(f[r]));
            mul(ncr[i],inv(f[i-r]));
            ncr[i]%=mod;
        }


}
int main()
{



  //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  cin >> n >> k;
  init(n,k-1);
  long long ans = 0;
  for(int i = 1; i <= n; ++i)
        cin >>arr[i];
  sort(arr + 1,arr + n + 1);
  for(int i = n; i >= k ; --i){
        ll z = ncr[i - 1];
        mul(z,arr[i]);
        add(ans,z);
  }
  //error(ans);
  for(int i = 1; i <= n - k + 1; i++){
        ll z = ncr[n - i];
        mul(z,arr[i]);
        sub(ans,z);
  }
  cout << (ans+mod)%mod << '\n';

    return 0;
}


Measured memory_bytes: 2560
def nibun(a,x):
    return bisect.bisect_left(a, x) #場所返す

import bisect
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
N = I()
ans = int(0)
L = LI()

L.sort()
t = int(0)
for i in range(N):
    for j in range(i+1,N):
        t = L[i] + L[j]
        count =int(0)
        count += nibun(L,t) - (j+1)
        ans += max(count,0)
#        print(i,j,count)

print(ans)

Measured memory_bytes: 44208
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

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

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };


vector<int> sq;
int solve(int n, int num, int after)
{
	if (num == 1)
		return binary_search(sq.begin() + after, sq.end(), n) ? 1 : 0;

	int res = 0;
	for (int i = after; i < sq.size() && sq[i] < n; ++i)
		res += solve(n - sq[i], num - 1, i);
	return res;
}
int main()
{
	for (int i = 1; i * i <= 1 << 15; ++i)
		sq.push_back(i * i);

	int n;
	while (scanf("%d", &n), n)
	{
		int res = 0;
		for (int i = 1; i <= 4; ++i)
			res += solve(n, i, 0);
		printf("%d\n", res);
	}
}

Measured memory_bytes: 920
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n,k;
    cin>>n>>k;
    const int INF = 1e9;
    vector<int> h(n);
    for(int i =0; i<n; i++) 
        cin>>h[i];
    

    vector<vector<int> > dp(n, vector<int> (k, INF));
    vector<int> dp_min (n,INF);

    for(int i = 0; i< n; i++)
    {   
        int mini = INF;

        for(int j = 0; j<k; j++)
        {
            if(i==0)
                dp[i][j] = 0;
            
            else if(i - (j+1) >=0)
                dp[i][j] = dp_min[i - (j+1)] + abs(h[i] - h[i - (j+1)]);

            mini = min (mini , dp[i][j]);
        }
        dp_min[i] = mini;
    }
    
    cout<<dp_min[n-1]<<"\n";
}

Measured memory_bytes: 44032
#include "bits/stdc++.h"
//#include "ext/pb_ds/assoc_container.hpp" 
//#include "ext/pb_ds/tree_policy.hpp" 
using namespace std;
//using namespace __gnu_pbds;
#define ff first
#define ss second
#define ld long double
#define ll long long int
#define ull unsigned ll
#define ins insert
#define pb emplace_back
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define pii pair<int,int> 
#define pll pair<ll , ll>
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define fo(i,a,b) for(i=a; i<b; ++i)
#define foe(i,a,b) for(i=a; i<=b; ++i)
#define rep(i,n) for(i=0;i<n;i++)
#define rep1(i,n) for(i=1;i<=n;i++)
#define per(i,n) for(i=n-1;i>=0;i--)
#define per1(i,n) for(i=n;i>=1;i--)
#define mod 1000000007
#define pi 3.141592653589793238460
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0)
//#define pbds tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
        //use cerr if u want to display at the bottom
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif


int main(){
    fast;
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll t, i, j, k;
    t=1;
    while(t--){
        ll n, k;
        cin>>n;
        vll a(n), v;
        rep(i,n) cin>>a[i];
        ll ans = 0;
        for(i=0; i<n; i++){
        	for(j=i+1; j<n; j++){
        		for(k=j+1; k<n; k++){
        			v = {a[i], a[j], a[k]};
        			sort(all(v));
        			if(v[0]+v[1] > v[2] && v[0]!=v[1] && v[0]!=v[2] && v[1]!=v[2]) ans++;

        		}
        	}
        }
        cout<<ans<<'\n';
    }
    return 0;
}







Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

  vector<ll> a(n), s(n+1, 0);
  vector<vector<ll>> dp(n+1, vector<ll>(n+1, LLONG_MAX >> 10));
  REP(i, n){
    cin >> a[i];
    s[i+1] = s[i] + a[i];
    dp[i][i+1] = 0;
  }

  REP(w, n+1)REP(l, n){
    if(l + w > n) continue;
    FOR(i, l+1, l+w){
      dp[l][l+w] = min(dp[l][l+w], dp[l][i] + dp[i][l+w] + s[l+w]-s[l]); 
    }
  }

  cout << dp[0][n] << endl;

  return 0;
}


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


int main(){
    int a, b;
    cin >> a >> b;
    int x = a*b;
    int y = a+b;
    int z = a-b;
    vector <int> v;
    v.push_back(x);
    v.push_back(y);
    v.push_back(z);
    sort(v.begin(), v.end());
    cout << v[2];
    return 0;
}

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

using namespace std;

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if(abs(a-c) <= d){
		cout << "Yes";	
	} else {
		if(abs(a-b) <= d && abs(b-c) <= d){
			cout << "Yes";	
		} else {
			cout << "No";
		}
	}
	return 0;
}


Measured memory_bytes: 256
n,k,s = gets.split.map(&:to_i)

ans = []
mx = s == 10**9 ? 10**9-2 : 10**9
if k == 0
  ans = [mx]*n
elsif s == 1
  ans = [1]*k + [mx]*(n-k)
elsif n == k
  ans = [s] * n
else
  ans << 1
  k.times do 
    if ans[-1] == 1
      ans << s-1
    else
      ans << 1
    end
  end
  (n-k-1).times do
    ans << mx
  end
end
puts ans.join(" ")

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int h, w, k;

ll solve(int w, int h) {
    ll ans = 0;
    for (int a = 1; a < w; a++) {
        for (int cha = 0; cha < h; cha++) {
            int R = 2 * k - a * cha + __gcd(cha, w) - 2;
            if (R < 0)break;
            int low = min(h - cha - 1, R / w);
            ans += cha == 0 ? low : low * 2;
            low++;
            if (low + cha < h && w * low - __gcd(w - a, low + cha) - __gcd(a, low) <= R)
                ans += cha == 0 ? 1 : 2;
        }
    }
    return ans * 2;
}

int main() {
    scanf("%d%d%d", &w, &h, &k);
    printf("%lld\n", solve(w, h) + solve(h, w));
    return 0;
}

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

using namespace std;

int n,l,dp[100005],a[100005];

int func(int i){

  if(i>n)return 0;
  if(dp[i]>0)return dp[i];

  int res=0;
  if(a[i]<a[i-1])res=max(res,func(i-1));
  if(a[i]<a[i+1])res=max(res,func(i+1));

  return dp[i]=l-a[i]+res;
}

int main(void){
  int in;
  
  while(cin >> n >> l){
    
    for(int i=0;i<n+2;i++)dp[i]=0;

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

    a[0]=a[n+1]=0;

    int res=0;
    for(int i=1;i<n+1;i++)
      res=max(res,func(i));

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3120
calc = lambda op1, op2, op3, xyz: op1*xyz[0] + op2*xyz[1] + op3*xyz[2]

N, M = list(map(int, input().split()))
xyz = [list(map(int, input().split())) for i in range(N)]
ans = 0
ops = [[1,1,1], [1,1,-1], [1,-1,1], [1,-1,-1], [-1,1,1], [-1,1,-1], [-1,-1,1], [-1,-1,-1]]

for op1, op2, op3 in ops:
    nums = sorted([calc(op1, op2, op3, n) for n in xyz], reverse=True)
    ans = max(ans, sum(nums[:M]))
print(ans)

Measured memory_bytes: 3396
//#define _GLIBCXX_DEBUG
//#define _CRTDBG_MAP_ALLOC
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

typedef int64_t ll;
typedef uint64_t ull;

const ll LINF = 9187201950435737471;
const ll nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const ull ULINF = numeric_limits<ull>::max();
const int MAXN = 4000 + 15;
const ll MOD = 1e9 + 7;
int C = 700;
const double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd;

#define all(_v) _v.begin(), _v.end()
#define rall(v) v.rbegin(), v.rend()
#define sz(v) (int)(v.size())
#define sqr(_v) (_v * _v)
#define vi vector <int>
#define vii vector <pair <int, int> >
#define eb emplace_back


inline void IO() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif
}

template <typename T>
istream& operator >> (istream& in, vector<T>& a) {
    for (auto& i : a)
        in >> i;
    return in;
}

template <typename T>
ostream& operator << (ostream& out, const vector<T>& a) {
    for (auto& i : a) {
        out << i << " ";
    }
    return out;
}

template <typename T, typename D>
istream& operator >> (istream& in, pair<T, D>& a) {
    in >> a.first >> a.second;
    return in;
}

template <typename T, typename D>
ostream& operator << (ostream& out, const pair<T, D>& a) {
    out << a.first << " " << a.second;
    return out;
}

#define int int64_t

inline void solve() {
    int n, k;
    cin >> n >> k;
    int ans = 0;
    vector <int> a(n);
    cin >> a;
    sort(rall(a));
    for (auto u : a) {
        if (k != 0) {
            k--;
        }
        else {
            ans += u;
        }
    }
    cout << ans;
}

signed main() {
    IO();
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
 using namespace std;
  string s1,s2,t;
  int i,len;
  int main(){
      cin>>s1>>t;
      sort(s1.begin(),s1.end());
      sort(t.begin(),t.end());
      len=t.size();
      for(i=len-1;i>=0;i--) s2+=t[i];
      if(s1<s2) cout<<"Yes"<<endl;
           else cout<<"No"<<endl;
      return 0;
  }

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int a,b,op;
	
	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op == '?') break;
	if(op == '+'){
	printf("%d\n",a+b);
	}else if (op=='-'){
	printf("%d\n",a-b);	
	}else if(op=='*'){
	printf("%d\n",a*b);
	}else if(op=='/'){
	printf("%d\n",a/b);
	}
	}
	return 0;
}



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

ll n;
int ans = 0;

int dig(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

void dfs(int keta, ll a) {
  if(keta>10) return;
  if(a<=n && a>=357) {
    bool ok1 = false;
    bool ok2 = false;
    bool ok3 = false;
    int k = dig(a);
    string s = to_string(a);
    rep(i,k) if(s.at(i)=='3') ok1 = true;
    rep(i,k) if(s.at(i)=='5') ok2 = true;
    rep(i,k) if(s.at(i)=='7') ok3 = true;
    if(ok1&&ok2&&ok3) ans++;
  }
  dfs(keta+1, a+3*pow(10,keta));
  dfs(keta+1, a+5*pow(10,keta));
  dfs(keta+1, a+7*pow(10,keta)); 
}

int main() {
  cin >> n;
  dfs(0,0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}
vector<bool> seen;
void dfs(const Graph &G, int v){
    seen[v] = true; // vを訪問済みにする
    
    for(auto next_v: G[v]){
        if(seen[next_v]) continue; // next_vが探索済みならスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int main(){

    ll n, k;
    cin >> n >> k;

    ll tmp;
    ll ans = n;
    if(n < k){
        tmp = abs(n - k);
        if(ans > tmp) ans = tmp; 
    }
    else if(n % k == 0){
        ans = 0;
    }
    else{
        tmp = n / k;
        ll a,b;
        a = abs(n - (k * tmp));
        b = abs(n - (k * (tmp + 1)));
        if(a > b){
            ans = b;
        }
        else{
            ans = a;
        }
    }
    
    cout << ans << endl; 
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main(){
  long max_=-1000000,min_=1000000,sum=0,a;
  int n;
  cin >>n;
  for(int i=0;i<n;i++){
    cin >> a;
    max_ = max(max_,a);
    min_ = min(min_,a);
    sum+=a;
 }
  cout << min_ << " " <<max_ << " " << sum <<endl;
  return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    lint n, k; cin >> n >> k;
    out(min(n % k, k - (n % k)));
}

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

int ask(vector<int> a)
{
  cout << "?";
  for (int x : a)
    cout << ' ' << x + 1;
  cout << endl;
  cout.flush();
  string s;
  cin >> s;
  return s == "Blue";
}

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

  int n;
  cin >> n;
  vector<int> ans(n * 2, -1);

  vector<int> leftHalf;
  for (int i = 0; i < n; i++)
    leftHalf.push_back(i);

  // ask 1 -> n
  int leftHalfColor = ask(leftHalf);
  int rightHalfColor = leftHalfColor ^ 1;

  // find when left color turns to right color
  int res = 0, low = 1, high = n - 1;
  vector<int> save;
  for (int i = 0; i < n; i++)
    save.push_back(i + n);
  while (low <= high)
  {
    int mid = (low + high) / 2;
    vector<int> a;
    for (int i = 0; i < n; i++)
      if (i < mid) a.push_back(i);
      else a.push_back(i + n);
    if (ask(a) == rightHalfColor)
    {
      res = mid;
      low = mid + 1;
      save = a;
    }
    else high = mid - 1;
  }

  ans[res] = leftHalfColor;
  ans[res + n] = rightHalfColor;

  // a contains [0, res) and [res + n, 2n)
  vector<int> a = save;
  for (int i = res + 1; i < res + n; i++)
  {
    a[res] = i;
    if (ask(a) == rightHalfColor) ans[i] = rightHalfColor;
    else ans[i] = leftHalfColor;
  }

  // add n/2 0s and n/2 1s
  vector<int> b;
  int cnt[2] = {0};
  for (int i = res; i <= res + n; i++)
    if (cnt[ans[i]] < n / 2)
    {
      b.push_back(i);
      cnt[ans[i]]++;
    }

  b.push_back(-1);
  for (int i = 0; i < n * 2; i++)
    if (ans[i] < 0)
    {
      b.back() = i;
      ans[i] = ask(b);
    }

  cout << "! ";
  for (int i = 0; i < n * 2; i++)
    cout << (ans[i] ? 'B' : 'R');
  cout << endl;
  cout.flush();
}


Measured memory_bytes: 724
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    int c = a+b;
    int d = a-b;
    int e = a*b;

    int ans = Math.max(c,d);
    ans = Math.max(ans,e);

    System.out.println(ans);
  }
}


Measured memory_bytes: 23892
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long[] cnt = new long[n];
        for (int i = 0; i < n; i++) {
            long x = a[i];
            int j = 0;
            while (x != 0) {
                cnt[j] += x % 2;
                x /= 2;
                j++;
            }
        }
        // System.out.println(Arrays.toString(cnt));
        boolean ok = true;
        for (int i = 0; i < n; i++) {
            if (cnt[i] % 2 != 0) {
                ok = false;
                break;
            }

        }
        if (!ok) {
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

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


Measured memory_bytes: 24404
N = int(input())
AN = list(map(int, input().split()))
Q = int(input())
BCList = [input() for i in range(Q)]

ADic = {}

for A in AN:
    if A in ADic:
        ADic[A] += 1
    else:
        ADic[A] = 1

sum = 0
for key, value in ADic.items():
    sum += key * value

for BC in BCList:
    diff = 0
    B, C = map(int, BC.split())
    if B in ADic:
        diff = (C - B) * ADic[B]
        if C in ADic:
            ADic[C] += ADic[B]
            ADic[B] = 0
        else:
            ADic[C] = ADic[B]
            ADic[B] = 0
    sum += diff
    print(sum)


Measured memory_bytes: 24996
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			long N = scan.nextLong();//s
			long M = scan.nextLong();//c
			
			if(2*N>M) {//sを全部使い切るためのcの個数がない
				System.out.println(M/2);
			}else {
				long kosuu = N;
				M-=2*N;
				kosuu+=M/4;
				System.out.println(kosuu);
			}
			
		}
		
		
	}
		

}


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

int main() 
{ 
    int flag=0;
    int a[3];
  int  hash[10]={0};
    for(int i=0;i<3;i++){
        cin>>a[i];
       
    }
     for(int i=0;i<3;i++){
     hash[a[i]]++;
     }
    for(int i=1;i<10;i++){
        if(hash[i]==2){
           flag=1;
           break;
           
        }
        else{
            flag=0;
        }
    }
    if(flag==1){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using T = tuple<int,int,int>;
using P = pair<int,int>;

struct UnionFind{
  vector<int> d;
  UnionFind(int n){
    d.resize(n,-1);
  }
  int find(int x){
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    if(d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return;
  }
  int size(int x){return -d[find(x)];}
};

int main(){
  int n;
  cin >> n;
  UnionFind uf(n);
  vector<T> town(n);
  int xi, yi;
  for(int i=0; i<n; ++i){
    cin >> xi >> yi;
    town[i] = make_tuple(xi,yi,i);
  }
  sort(town.begin(),town.end());
  priority_queue<P,vector<P>,greater<P>> que;
  int minnum = get<1>(town[0]), townnum = get<2>(town[0]);
  que.push(P(minnum,townnum));
  for(int i=1; i<n; ++i){
    int nowy = get<1>(town[i]);
    int nowt = get<2>(town[i]);
    if(nowy < minnum){
      que.push(P(minnum,townnum));
      minnum = nowy;
      townnum = nowt;
    }else{
      uf.unite(nowt,townnum);
      while(!que.empty() && que.top().first < nowy){
        uf.unite(nowt, que.top().second);
        que.pop();
      }
      que.push(P(minnum,townnum));
    }
  }
  for(int i=0; i<n; ++i){
    printf("%d\n",uf.size(i));
  }
}

Measured memory_bytes: 6684
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  map<int, int> mpp;
  for(int i = 1; i <= n; i++){
    mpp[i-a[i-1]]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; i++){
    ans += mpp[i+a[i-1]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20968
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define FOR(i, first, last) for (int i = (first); i < (last); ++i)
#define REP(i, n) FOR(i, 0, n)
#define CLR(a) memset((a), 0, sizeof(a))
#define DUMP(x) std::cerr << #x << " = " << (x) << std::endl;
#define DUMPR(v) REP(_i,v.size()){std::cerr<< #v << "[" << _i << "] = " << (v[_i]) << std::endl;}
#define CIN_VEC(v,N) {v.clear(); v.reserve(N); REP(i,N){typename decltype(v)::value_type x; cin>>x; v.emplace_back(x);}};

inline int to_int(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string to_string(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

typedef unsigned long long ull;
typedef unsigned long ul;
typedef long long ll;

int N,M;
ll x[1001], y[1001], z[1001];

struct Vec {
  ll x,y,z;

  Vec(ll x, ll y, ll z) : x(x), y(y),z(z) {
  }

  ll abssum() const {
    return abs(x)+abs(y) +abs(z);
  }

  Vec operator+(const Vec& other) const {
    return Vec(x+other.x,y+other.y, z+other.z);
  }

  bool operator<(const Vec& o) const {
    return x < o.x && y<o.y && z<o.z;
  }

  void dump() const {
    cout<<x <<" "<<y<<" "<<z<<endl;
  }
};

template<class T>
T findmax(T first, T end, bool xp, bool yp, bool zp) {
  ll delta = LLONG_MIN;
  auto res = first;
  for(auto it=first; it!=end; ++it) {
    ll d = 0;
    d += xp ? it->x : -it->x;
    d += yp ? it->y : -it->y;
    d += zp ? it->z : -it->z;
    if (d > delta) {
      delta = d;
      res = it;
    }
  }
  return res;
}

ll cals(const multiset<Vec>& ss, bool xp, bool yp, bool zp) {
  multiset<Vec> s = ss;

  Vec sum(0,0,0);
  for(int i=0; i<M;i++) {
    auto it = findmax(s.begin(), s.end(), xp, yp, zp);
    Vec r = *it;

    sum = sum + r;

    s.erase(it);
  }
  return sum.abssum();
}

int main() {
  cin>>N>>M;
  multiset<Vec> s;
  REP(i,N) {
    cin>>x[i]>>y[i]>>z[i];
    // s.emplace(x[i],y[i],z[i]);
    Vec v(x[i],y[i],z[i]);
    s.insert(v);
    // v.dump();
  }

  vector<ll> anss;
  anss.push_back(cals(s, 0, 0, 0));
  anss.push_back(cals(s, 0, 0, 1));
  anss.push_back(cals(s, 0, 1, 0));
  anss.push_back(cals(s, 0, 1, 1));
  anss.push_back(cals(s, 1, 0, 0));
  anss.push_back(cals(s, 1, 0, 1));
  anss.push_back(cals(s, 1, 1, 0));
  anss.push_back(cals(s, 1, 1, 1));

  ll ans = 0;
  for(auto x : anss) {
    if(ans < x) ans = x;
  } 
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 384
function main()
    n, m, k = parse.(Int, split(readline()))
    a = parse.(Int, split(readline()))
    b = parse.(Int, split(readline()))

    t = sum(b)
    j = m
    ans = 0
    for i in 0:n
        while j > 0 && t > k
            j -= 1
            t -= b[j+1]
        end
        t > k && break
        ans = max(ans, i+j)
        i == n && break
        t += a[i+1]
    end
    println(ans)
end

function isOK(a, index, key)
    a[index] >= key 
end

function binary_search(a, key)
    left = 0
    right = length(a)+1
    while right - left > 1
        mid = (left + right) ÷ 2 
        if isOK(a, mid, key)
            right = mid
        else
            left = mid
        end
    end
    return right
end

main()

Measured memory_bytes: 206384
from collections import deque
n,m = map(int,input().split())
to = [[] for _ in range(n)]
e = []
for _ in range(m):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
    e.append((a,b))
ans = m
seen = [False]*n
q = deque()
for i in range(m):
    a,b = e[i]
    q.clear()
    q.append((a,-1))
    for j in range(n): seen[j] = False
    flag = True
    while q and flag:
        cur,prev = q.popleft()
        seen[cur] = True
        for nxt in to[cur]:
            if nxt == b:
                if cur == a: continue
                ans -= 1
                flag = False
                break
            if nxt == prev: continue
            if seen[nxt]: continue
            q.append((nxt,cur))
print(ans)

Measured memory_bytes: 3316
import sys
odd = 'RUD'
even = 'LUD'
step = input()
odd_step = step[0::2]
even_step = step[1::2]
for o in odd_step:
    if not o in odd:
        print('No')
        sys.exit(0)
for e in even_step:
    if not e in even:
        print('No')
        sys.exit(0)
print('Yes')

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

const int INF = 1e9;

int main() {
	int h, w;
	cin >> h >> w;
	int ch, cw, dh, dw;
	cin >> ch >> cw >> dh >> dw;
	ch--, cw--, dh--, dw--;
	vector<string> s(h);
	rep(i, h) cin >> s[i];
	deque<pii> q;
	q.push_front({ch, cw});
	vector<vector<int>> d(h, vector<int>(w, INF));
	d[ch][cw] = 0;
	while (!q.empty()) {
		pii p = q.front();
		q.pop_front();
		int x, y;
		tie(y, x) = p;
		vector<int> dx = {0, 1, 0, -1};
		vector<int> dy = {1, 0, -1, 0};
		rep(i, 4) {
			int nx = x + dx[i];
			int ny = y + dy[i];
			if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
			if (s[ny][nx] == '#') continue;
			if (d[ny][nx] <= d[y][x]) continue;
			d[ny][nx] = d[y][x];
			q.push_front({ny, nx});
		}
		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				int nx = x + j;
				int ny = y + i;
				if (nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
				if (s[ny][nx] == '#') continue;
				if (d[ny][nx] <= d[y][x] + 1) continue;
				d[ny][nx] = d[y][x] + 1;
				q.push_back({ny, nx});
			}
		}
	}
	int ans = d[dh][dw];
	if (ans != INF) cout << ans << endl;
	else cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n; cin >> n;
    vi a(n);
    ll cnt = 0;
    rep(i, n){
        cin >> a[i];
        if(i%2 == 0 && a[i]%2 == 1) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#define range(i,a,b) assert(a<=i && i<=b)
using namespace std;
int N, M, L;
vector<long long> K, S;
long long floorL(long long x){
	return (x / L)*L;
}
long long sumofS(int a, int b){
	long long sum = 0;
	for (int i = a; i < b + 1; i++){
		range(i, 0, M - 1);
		sum += S[i];
	}
	return sum;
}
long long solve(int n){
	if (n > 0){
		auto res = solve(n - 1);
		auto sum1 = sumofS(K[n - 1] + 1, K[n]);
		auto sum2 = sumofS(K[n - 1], K[n]);
		range(n, 1, N - 1);
		auto candi1 = floorL(res + sum1) + sum2;
		auto candi2 = res + sum1 + floorL(sum2);
		//cerr << candi1 << " " << candi2 << endl;
		return min(candi1,candi2);
	}
	else{
		range(K[0], 0, M - 1);
		//cerr << S[K[0]] << endl;
		return S[K[0]];
	}
}
int main(){
	cin >> N >> M >> L;
	K = vector<long long>(N);
	S = vector<long long>(M);
	for (int i = 0; i < N; i++){
		cin >> K[i];
		K[i]--;
	}
	for (int i = 0; i < M; i++)
		cin >> S[i];
	sort(K.begin(), K.end());
	auto ans = solve(N - 1) / L;
	cout << ans << endl;
}

Measured memory_bytes: 2056