akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f40;
const long long mod=1e9+7;
const long double PI = acos(0);
// }}} End Header
int main() {
	ll n, ans = 0, sum = 0;
	cin >> n;
	vector<ll> a(n);
	rep(i,n){
		cin >> a[i];
		sum+=a[i];
	}
	rep(i,n-1){
		sum-=a[i];
		ll t = ((a[i]%mod)*(sum%mod));
		ans+=t;
		ans%=mod;
	}
	cout << ans << endl;
	//cout << sum << endl;
	return 0;
}

Measured memory_bytes: 4812
n,m=map(int,input().split())
AC=[0]*n
WA=[0]*n
ACs=set()
for _ in range(m):
    p,c=input().split(); p=int(p)
    if p in ACs:continue
    if c=='AC':
        AC[p-1]+=1
        ACs.add(p)
    else:
        WA[p-1]+=1
for i in range(n):
    if i+1 not in ACs:
        WA[i]=0
print(sum(AC),sum(WA))

Measured memory_bytes: 13504
import qualified Data.ByteString.Char8 as BS
import Data.Char
import Data.List
import Control.Monad

main = do
  li <- BS.getLine
  let [h,w] = unfoldr (BS.readInt . BS.dropWhile isSpace) li
  ass <- forM [1..h] (\_ -> do
    li <- BS.getLine
    let as = unfoldr (BS.readInt . BS.dropWhile isSpace) li
    return as
    )
  let ans = compute  h w ass
  print $ length ans
  putStrLn $ unlines $ map (unwords . map show) ans

compute :: Int -> Int -> [[Int]] -> [[Int]]
compute h w ass = vcmds ++ hcmds
  where
    bss = map (map odd) ass
    cs = map (foldl1 (/=)) bss
    hcmds = [[x,y,x,succ y] | (x,bs) <- zip [1..] bss, y <- sub bs]
    vcmds = [[x,w,succ x,w] | x <- sub cs]

sub cs = map fst $ filter snd $ zip [1..] $ init $ scanl1 (/=) cs

{-
まずそれぞれの行の中で考えて最大化し、奇数は一番右に寄せる。
最後に一番右の列を縦に最適化する。最後は寄せる必要はない。
で、最適と要求されなければできるはず。

手順は、奇数から次の奇数あるいは末尾までをずっとひっくり返す、というだけ。
-}

Measured memory_bytes: 38488
N,M,Q = gets.chomp.split.map &:to_i
inputs = Q.times.map{gets.chomp.split.map &:to_i}

#p "in: #{inputs}"
com = (1..M).to_a.repeated_combination(N)
#p "co: #{com}"

ans = 0
com.each do |co|
  point = 0
  inputs.each do |a,b,c,d|
#    p "co: #{co}"
    point += d if co[b-1] - co[a-1] == c
  end
  ans = [ans, point].max
end

p ans
    
    

Measured memory_bytes: 14548
from operator import itemgetter
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
lis=[]
for i in range(m-1):
  lis.append([x[i+1]-x[i],i])
lis.sort(reverse=True)
if n>=m:
  print(0)
else:
  if n==1:
    print(max(x)-min(x))
  else:
    cnt=x[lis[0][1]]-x[0]+x[m-1]-x[lis[n-2][1]+1]
    for i in range(1,n-1):
      cnt+=x[lis[i][1]]-x[lis[i-1][1]+1]
    print(cnt)

Measured memory_bytes: 20772
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>G[2000];
string s;
int N;
long ans=9e18;
long nowret;
bool vis[2000];
pair<int,pair<int,int> >dfs(int u,int p)
{
	int ct=s[u]=='1';
	if(G[u].size()==1&&G[u][0]==p)
	{
		return make_pair(ct,make_pair(0,0));
	}
	vector<pair<int,int> >A;
	for(int v:G[u])
	{
		if(v!=p)
		{
			pair<int,pair<int,int> >p=dfs(v,u);
			ct+=p.first;
			A.push_back(make_pair(p.first+p.second.first,p.first+p.second.second));
		}
	}
	sort(A.begin(),A.end());
	int sum=0,mv=0;
	for(int i=0;i+1<A.size();i++)sum+=A[i].second;
	mv=A.back().first;
	if(mv<=sum)
	{
		int now=sum+A.back().second;
		return make_pair(ct,make_pair(now%2,now));
	}
	else
	{
		return make_pair(ct,make_pair(mv-sum,sum+A.back().second));
	}
}
main()
{
	cin>>N>>s;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(int i=0;i<N;i++)
	{
		nowret=0;
		pair<int,pair<int,int> >now=dfs(i,-1);
		if(now.second.first==0&&now.second.second%2==0)ans=min(ans,1L*now.second.second/2);
	}
	if(ans<9e18)cout<<ans<<endl;
	else cout<<-1<<endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int n,k;
    cin >> n >> k;

    int d[k];

    vector<vector<int>> A(k);

    for(int i=0;i<k;i++){
        cin >> d[i];
        for(int j=0;j<d[i];j++){
            int a;
            cin >>a;
            A[i].push_back(a);
        }
    }

    int s[n]={};

    for(int i=0;i<k;i++){
        for(int j=0;j<d[i];j++){
            s[A[i][j]-1]++;
        }
    }

    int c=0;

    for(int i=0;i<n;i++){
        if(s[i]==0)c++;
    }

    cout << c << endl;

}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {

  int N,M;
  cin >> N >> M;

  vector<vector<bool>> G(N,vector<bool>(N,false));
  vector<int> num(N,false);

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

  for(int i = 0;i < N;i++) {
    num.at(i) = i;
  }

  int res = 0;
  do {
    if(num.at(0) != 0) break;
    bool ok = true;
    for(int i = 0;i < N-1;i++) {
      int from = num.at(i),to = num.at(i+1);
      if(!G.at(from).at(to)) ok = false;
    }

    if(ok) res++;

  }while(next_permutation(num.begin(),num.end()));

  cout << res << endl;
}



Measured memory_bytes: 256
// AOJ Volume 0 Problem 0076

#include <stdio.h>
#include <math.h>

#define PI	(3.141592653589794246)

#define TO_RAD(a)	((a) * PI / 180)
#define TO_DEG(a)	((a) * 180 / PI)

int main(void)
{
	int n;
	int i;
	double r;
	int ll;
	

	while (1){
		scanf("%d", &n);
		if (n == -1){
			break;
		}

		ll = 1;
		r  = 0.0;
		for (i = 1; i < n; i++){
			r += atan(1 / sqrt((double)ll));			
			ll++;
		}
		
		printf("%.02lf\n%.02lf\n", cos(r) * sqrt(ll), sin(r) * sqrt(ll));
	}
	
	return (0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long int
#define __ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi acos(-1)
using namespace std;


int main ()
{
__

ll a,b,c,d,lcm,ans=0;

cin >> a >> b >> c >>d;

lcm =(c*d)/ __gcd(c,d);

ans = (b+1-a) - ((b/c + b/d - b/lcm)-((a-1)/c + (a-1)/d - (a-1)/lcm ));

cout << ans << "\n";

return 0;
}


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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
};

int N, K;
vec a;
bool dp[5010][5010];

bool C(const int &m) {
  m0(dp);
  dp[0][0] = true;
  vector<int> b;

  for (int i = 0; i < N; i++) {
    if (i != m) b.push_back(a[i]);
  }

  for (int i = 0; i < N - 1; i++) {
    for (int k = 0; k <= K; k++) {
      if (!dp[i][k]) continue;
      dp[i + 1][k] = true;
      if (k + b[i] <= K) dp[i + 1][k + b[i]] = true;
    }
  }

  int tmp = 0;
  for (int i = 0; i <= K; i++) {
    if (dp[N - 1][i]) {
      tmp = a[m] + i;
      if (tmp >= K) break;
    }
  }
  return (tmp < K) || (K <= tmp - a[m]);
}

signed main() {
  cin >> N >> K;
  a.resize(N);

  for (int i = 0; i < N; i++) {
    int tmp;
    cin >> tmp;
    a[i] = min(tmp, K);
  }

  sort(ALL(a));

  int ok = -1, ng = N + 1;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (C(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  cout << min(ng, N) << endl;
  return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int n,a,ans;
map<pair<int,int>,int> m;

signed main() {
    cin >> n;
    rep1(i,n) cin >> a,m[mp(min(a,i), max(a,i))]++;
    for(auto i : m) if (i.se == 2) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define L 128
using namespace std;
char g[100];
string ans;
int ng=0,n[100],su,sum;
string d(string x){
	string y="";
	for (int i=1;i<x.length();i++)y+=x[i];
	return y;
}
int get(string s){
	cout<<'?'<<' '<<s<<endl;
	int x;cin>>x;return x;
}
string work(int l,int r){
	if (l==r){string s="";while (n[l]--)s+=g[l];return s;}
	string s1=work(l,(l+r)/2),s2=work((l+r)/2+1,r),an="";
	while(s1.length()&&s2.length()){
		if (get(an+s1[0]+s2)==su-(an+s2).length()-1){an+=s1[0];s1=d(s1);}
		else {an+=s2[0];s2=d(s2);}
	}
	return an+s1+s2;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
	for (int i=0;i<26;i++)g[++ng]='a'+i;
	for (int i=0;i<26;i++)g[++ng]='A'+i;
	for (int i=0;i<10;i++)g[++ng]='0'+i;
	for (int i=1;i<=ng;i++){
		string s="";for (int j=1;j<=L;j++)s=s+g[i];
		n[i]=L-get(s);su+=n[i];
	}
	string ans=work(1,ng);
	cout<<'!'<<' '<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3776
s = input()
l = list({s[i] for i in range(len(s))})
a = [False] * 26
for c in l:
    a[ord(c) - ord("a")] = True
ans = "None"
for i in range(len(a)):
    if a[i] == False:
        ans = chr(ord("a") + i)
        break
print(ans)


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

Measured memory_bytes: 1156
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

lld fac[200001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=200000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


long long int gcd(lld b,lld a)
{
    if(a<b) return gcd(a,b);
    if(a%b==0) return b;
    return gcd(a%b , b);
}

//vector< vector <lld > > v(100001);
lld p1=1000000007,p2=998244353;
lld l,r,mid,ans;
lld n,m,i,j,k;
lld x,y,n1,a,b,n2,h,z,c;
queue<lld> q;
lld d,p=1000000000;

void solve()
{
    cin>>n;
    vector<lld> v,w,w2;
    cin>>x>>y>>z;
    v.pb(x);
    w.pb(y);
    w2.pb(z);
    for(i=1;i<n;i++)
    {
        cin>>x>>y>>z;
        v.pb(max(w[i-1],w2[i-1])+x);
        w.pb(max(v[i-1],w2[i-1])+y);
        w2.pb(max(w[i-1],v[i-1])+z);
    }
    //cout<<"!";
    cout<<max(max(v[n-1],w[n-1]),w2[n-1]);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
    //getfac(p2);
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
            solve();
        cout<<"\n";
    }

    return 0;
}

Measured memory_bytes: 2912
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	int D, G, dummy;
	dummy = scanf("%d %d", &D, &G);

	vector<int> p;
	vector<int> c;

	int tmp1, tmp2;
	//TA.reserve(N);
	for (int i = 0; i < D; i++) {
		dummy = scanf("%d %d", &tmp1, &tmp2);
		p.push_back(tmp1);
		c.push_back(tmp2);
	}
	
	int ans = 1000;
	int max = 1 << D;
	for (int i = 0; i < max; i++) {
		char* str = new char[D];
		int tmpBit = 1;
		int tmpPoint = 0;
		int tmpCount = 0;
		for (int b = 0; b < D; b++) {
			str[b] = (i & tmpBit) ? 1 : 0;
			tmpBit <<= 1;
			if (str[b]) {
				tmpPoint += p[b] * (b+1) * 100 + c[b];
				tmpCount += p[b];
				str[b] = p[b];
			}
		}
		while (tmpPoint < G) {
			int b;
			for (b = D-1; b >= 0; b--) {
				if (str[b] + 1 < p[b]) {
					tmpPoint += (b+1) * 100;
					tmpCount++;
					str[b]++;
					break;
				}
			}
			if (b < 0) {
				tmpCount = 1000;
				break;
			}
		}
		ans = min(ans, tmpCount);
	}

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


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

#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

using i64 = long long;
using d64 = long double;
using pi = pair<int, int>;
using pli = pair<i64, i64>;
using ti = tuple<int, int, int>;
using tli = tuple<i64, i64, i64>;

#define iterall(cont) cont.begin(), cont.end()
#define prec(n) setprecision(n) << fixed

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

    int N, K;
    cin >> N >> K;

    vector<int> P(N);
    vector<i64> C(N);
    for (int i = 0; i < N; i++) cin >> P[i], P[i]--;
    for (int i = 0; i < N; i++) cin >> C[i];

    vector<bool> vst(N);
    i64 ans = numeric_limits<i64>::min();
    for (int i = 0; i < N; i++) {
        if (vst[i]) continue;

        vector<int> tr = {i};
        vector<i64> trw(1);

        while (P[tr.back()] != tr[0]) tr.emplace_back(P[tr.back()]);
        for(auto el:tr) vst[el] = true;
        int T = tr.size();
        for (int j = 1; j <= T; j++) {
            trw.emplace_back(C[tr[j - 1]]);
            trw[j] += trw[j - 1];
        }
        // for(auto el:trw) cout<<el<<" ";
        // cout<<endl;

        auto ivM = min(T, K);
        vector<i64> ivMax(ivM, numeric_limits<i64>::min());
        for (int iv = 0; iv < ivM; iv++) {
            for (int j = 0; j < T; j++) {
                int s = j;
                int e = (j + iv) % T;

                if (s <= e) ivMax[iv] = max(ivMax[iv], trw[e+1] - trw[s]);
                else ivMax[iv] = max(ivMax[iv], trw[e+1] - trw[s] + trw.back());
            }
        }

        if(trw.back() < 0) ans = max(ans, *max_element(iterall(ivMax)));
        else {
            if(K/T >= 1) ans = max(ans, trw.back() * (K/T-1) + (*max_element(iterall(ivMax))));
            ans = max(ans, trw.back() * (K / T) + (K%T?*max_element(ivMax.begin(), ivMax.begin() + K%T):0));
        }
    }

    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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;
}

string Func(const string& str) {
    string s = str;
    sort(s.begin(), s.end());
    return s;
}
int main() {
    string s, t;
    cin >> s >> t;

    s = Func(s);
    t = Func(t);
    reverse(t.begin(), t.end());

#ifdef SOURCE_TEST
    cout << s << endl;
    cout << t << endl;

#endif

    bool isOk = true;
    for (ll i = 0; i <= s.size(); ++i) {
        if (i == s.size()) {
            if (t.size() <= i) {
                isOk = false;
            }
            break;
        }
        if (t.size() <= i) {
            isOk = false;
            break;
        }
        if (s[i] < t[i]) {
            break;
        } else if (s[i] > t[i]) {
            isOk = false;
            break;
        }
    }

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

    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
using namespace std;
int a[1000006];
int main(){
	int n, k;
	cin >> n >> k;
	for (int i = 1; i <= n; ++ i)
		cin >> a[i];
	a[++ n] = 0;
	sort(a + 1, a + 1 + n);
	++ k;
	int zero = 0;
	for (int i = 1; i <= n; ++ i)
		if (a[i] == 0){
			zero = i;
			break;
		}
	int ans = 1000000000;
	for (int i = 0; i <= min(zero - 1, k); ++ i)
		if (zero + k - i - 1 <= n){
			int l = -a[zero - i], r = a[zero + k - i - 1];
			ans = min(ans, min(2 * l + r, l + 2 * r));
		}
	cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <functional>

const int MAX = 100000;
int t, n, k;
int x[MAX];

int main(){
    std::cin >> t;
    for(int a = 0; a < t; ++a){
        std::cin >> n >> k;
        std::vector<int> sub;
        int s, g;
        int in1, in2;
        for(int i = 0; i < n; ++i){
            std::cin >> in1;
            if(i == 0)
                s = in2 = in1;
            if(i == n - 1)
                g = in1;
            sub.push_back(in1 - in2);
            in2 = in1;
        }
        std::sort(sub.begin(), sub.end(), std::greater<int>());
        int l = g - s;
        // std::cout << "l : " << l << std::endl;
        // std::cout << "s : " << s << std::endl;
        // std::cout << "g : " << g << std::endl;
        for(int i = 0; i < k - 1; ++i){
            if(i == n - 1)
                break;
            // std::cout << "sub i : " << sub[i] << std::endl;
            l -= sub[i];
        }
        std::cout << l << std::endl;
    }
    return 0;
}

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


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

  int min = x-k + 1;
  int max = x+k -1;
  for(int i = min; i <= max; i++) cout << i << " ";
}


/*





















*/


Measured memory_bytes: 384
from collections import deque

N,M = map(int,input().split())
U = input()
A = list(map(int,input().split()))
src = [tuple(map(int,input().split())) for i in range(M)]

edges = {}
for s,t,b in src:
    s,t = s-1,t-1
    if s>t: s,t = t,s
    if (s,t) in edges:
        edges[(s,t)] += b
    else:
        edges[(s,t)] = b

P = N+2
es = [[] for i in range(P)] # [[to1,cap1,rev1], ...]

def add_edge(fr,to,cap):
    es[fr].append([to,cap,len(es[to])])
    es[to].append([fr,0,len(es[fr])-1])

for i,(u,a) in enumerate(zip(U,A)):
    if u == 'L':
        add_edge(0,i+2,a)
        add_edge(i+2,1,0)
    else:
        add_edge(0,i+2,0)
        add_edge(i+2,1,a)
for (s,t),b in edges.items():
    add_edge(t+2,s+2,b)

INF = float('inf')
level = [0] * P
iters = [0] * P

def dinic_max_flow(s,t):
    global iters

    def _bfs(s):
        global level
        level = [-1] * P
        level[s] = 0
        q = deque([s])
        while q:
            v = q.popleft()
            for to,cap,rev in es[v]:
                if cap > 0 and level[to] < 0:
                    level[to] = level[v] + 1
                    q.append(to)

    def _dfs(v,t,f):
        if v == t: return f
        for i in range(iters[v],len(es[v])):
            iters[v] += 1
            to,cap,rev = es[v][i]
            if es[v][i][1] > 0 and level[v] < level[to]:
                d = _dfs(to,t,min(f,es[v][i][1]))
                if d > 0:
                    es[v][i][1] -= d #cap
                    es[to][rev][1] += d
                    return d
        return 0

    flow = 0
    while True:
        _bfs(s)
        if level[t] < 0: return flow
        iters = [0] * P
        f = 0
        while True:
            f = _dfs(s,t,INF)
            if f <= 0: break
            flow += f

print(dinic_max_flow(0,1))


Measured memory_bytes: 6588
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  cin>>n;
  vs s(n);
  rep(i,n)cin>>s[i];
  int m;
  cin>>m;
  vs t(m);
  rep(i,m)cin>>t[i];
  int ans=0;
  rep(i,n){
    int tmp=0;
    rep(j,n)if(s[i] == s[j])tmp++;
    rep(j,m)if(s[i] == t[j])tmp--;
    ans=max(ans,tmp);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int i, j, height[10], tmp;
	for(i = 0; i < 10; i++) {
		scanf("%d", &height[i]);
	}
	for(i = 0; i < 10; i++) {
		for(j = 0; j < 9; j++) {
			if(height[j] <= height[j + 1]) {
				tmp = height[j + 1];
				height[j + 1] = height[j];
				height[j] = tmp;
			}
		}
	}
	for(i = 0; i < 3; i++) {
		printf("%d\n", height[i]);
	}
	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<math.h>
#include<iomanip>
using namespace std;


int main(){
	string s;
	cin>>s;
	int N=s.size();

	long long ans=0;

	for(int bit=0;bit<(1<<(N-1));bit++){
		long long sum=0;

		for(int j=0;j<N-1;j++){
			sum *=10;
			sum +=s.at(j)-'0';

			if(bit &(1<<j)){
				ans+=sum;
				sum=0;
			}
		}

		sum *= 10;
		sum += s.back()-'0';
		ans += sum;
	}
	cout << ans <<endl;

	return 0;

}

Measured memory_bytes: 3580
/*--------------------------"SABUJ-JANA"------"JADAVPUR UNIVERSITY"--------*/
/*-------------------------------@greenindia-----------------------------------*/
//
//		  _____       _           _        _
//		 / ____|     | |         (_)      | |
//		| (___   __ _| |__  _   _ _       | | __ _ _ __   __ _
//		 \___ \ / _` | '_ \| | | | |  _   | |/ _` | '_ \ / _` |
//		 ____) | (_| | |_) | |_| | | | |__| | (_| | | | | (_| |
//		|_____/ \__,_|_.__/ \__,_| |  \____/ \__,_|_| |_|\__,_|
//		                        _/ |
//		                       |__/
/*---------------------- Magic. Do not touch.-----------------------------*/
/*------------------------------God is Great/\---------------------------------*/
#include <bits/stdc++.h>
using namespace std;
#define crap ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
//cout<<fixed<<showpoint<<setprecision(12)<<ans<<endl;
#define int long long int
#define double long double
#define PI acos(-1)
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
#define endl "\n"

void print1d(const vector<int>& vec) {for (auto val : vec) {cout << val << " ";} cout << endl;}

void print2d(const vector<vector<int>>& vec) {for (auto row : vec) {for (auto val : row) {cout << val << " ";} cout << endl;}}

signed main() {
	crap;

	int x, n;
	cin >> x >> n;

	if (n == 0) {
		cout << x << endl;
		return 0;
	}

	vi arr(n);

	map<int, int> mp;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		mp[arr[i]]++;
	}

	int nix = INT_MAX;
	int val;
	bool flag = false;
	for (int i = -1; i <= 101; i++) {
		if (mp[i] == 0) {
			if (abs(x - i) < nix) {
				nix = abs(x - i);
				val = i;
				flag = true;
			}
		}
	}

	if (flag)
		cout << val << endl;

	return 0;
}

Measured memory_bytes: 3600
from sys import exit

X = int(input())

if X <= 599:
    print(8)
    exit()

if X <= 799:
    print(7)
    exit()

if X <= 999:
    print(6)
    exit()

if X <= 1199:
    print(5)
    exit()

if X <= 1399:
    print(4)
    exit()

if X <= 1599:
    print(3)
    exit()

if X <= 1799:
    print(2)
    exit()

print(1)


Measured memory_bytes: 9192
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

l=lmp()
for i in range(3):
    if l.count(l[i])==1:
        print(l[i])

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

using namespace std;

typedef long long ll;

ll n, m;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> m;
	if (n == 1 && m == 1)
		cout << 1 << endl;
	else if (n == 1)
		cout << m - 2 << endl;
	else if (m == 1)
		cout << n - 2 << endl;
	else
		cout << (n - 2) * (m - 2) << endl;
	return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

count=0
ans=[]
hako=[0]*N
for i in range(N)[::-1]:
    all=0
    for j in range(i,N)[::i+1]:
        if i==j:
            continue
        all^=hako[j]
    if all==1:
        if A[i]==1:
            continue
        else:
            hako[i]=1
            count+=1
            ans.append(i+1)
    else:
        if A[i]==1:
            hako[i]=1
            count+=1
            ans.append(i+1)
        else:
            continue
ans.sort()
print(count)
print(*ans)
#print(hako)
            



Measured memory_bytes: 14044
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		int N = nextInt();

		String res = "No";

		for(int i=9;i>0;i--) {
			if(N % i == 0 && N / i < 10) {
				res = "Yes";
				break;
			}
		}

		out.println(res);
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}
}

Measured memory_bytes: 23252
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> order;
    order.pb(0);
    rep(i, N) order.pb(A[i]);
    order.pb(0);
    ll sum = 0;
    rep(i, order.size() - 1) { sum += abs(order[i] - order[i + 1]); }
    for(int i = 1; i < order.size() - 1; i++) {
        cout << sum - abs(order[i] - order[i + 1]) -
                    abs(order[i - 1] - order[i]) +
                    abs(order[i - 1] - order[i + 1])
             << endl;
    }
    return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
long long N,a[150],as1,as2;
bool cmp(long long x,long long y)
{
	return x>y;
}
int main()
{
    cin>>N;
	for(int i=0;i<N;i++)cin>>a[i];
	sort(a,a+N,cmp);
	for(int i=0;i<N;i++)
	{
		if(i%2==0)as1+=a[i];
		else as2+=a[i];
	}
	cout<<as1-as2<<endl;
    return 0;
}

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


typedef long long           ll;
typedef unsigned long long  ull;

#define sf                  scanf
#define pf                  printf
#define si(n)               scanf("%d",&n)
#define sii(x,y)            scanf("%d %d",&x,&y)
#define siii(x,y,z)         scanf("%d %d %d",&x,&y,&z)
#define sl(n)               scanf("%lld",&n)
#define sll(x,y)            scanf("%lld %lld",&x,&y)
#define slll(x,y,z)         scanf("%lld %lld %lld",&x,&y,&z)
#define yes                 printf("YES\n")
#define no                 printf("NO\n")
#define FOR(i,x,y)          for(int i=x;i<y;i++)
#define RFOR(i,x,y)         for(int i=x;i>=y;i--)
#define MAXN                100005
#define MOD                 1000000007
#define PI                  acos(-1)


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

    cout<<a*b<<endl;

    return 0;
}




Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define REP(i,x,n) for(int i=x;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define sp(p) cout<<setprecision(16)<<fixed<<p<<endl;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define UNIQ(a) unique(all(a))
#define UNIQNUM(a) UNIQ(a)-a.begin()
#define UNIQIT(a) a.erase(UNIQ(a), a.end());
#define VOUT(v,i) rep(i,v.size())cout<<v[i]<<(i==v.size()-1?"\n":" ");
#define vout(v) VOUT(v,z);
#define vdbg(v,i) cout<<#v<<": ";for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}cout<<"\n";
#define vmin(v) *min_element(all(v))
#define vmax(v) *max_element(all(v))
#define vsum(v) accumulate(all(v), 0LL)
#define MOUT(m,r,c) rep(i,r){rep(j,c){cout<<m[i][j]<<" ";}cout<<endl;}
#define mout(m) MOUT(m,m.size(),m[0].size())
#define debg(a) cout<<#a<<": "<<a<<endl;
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define digit(a) to_string(a).length();
template<class T>inline int out(const T &t){ print(t); putchar('\n'); return 0; }
template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
bool is_palindrome(string s){return s == string(s.rbegin(),s.rend());}
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef vector<ll> V;
typedef vector<vector<ll>> VV;
// const long long MOD=1000000007;
const long long INF = 1e18;
#define EPS (1e-7)
#define PI (acos(-1))
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) { a = b; return true; }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) { a = b; return true; }
    return false;
}

const string YES = "Yes";
const string NO = "No";
#define judge(f) cout<<(f?YES:NO)<<"\n";

void solve(long long N){
    string s=to_string(N);
    bool f=false;
    for (long long i = 0; i < s.length(); i++) {
        if(s[i]=='7') f=true;
    }
    judge(f);
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n),num(200010);
    int cnt=0,ans=0;
    rep(i,n){
        cin>>a[i];
        if(num[a[i]]==0) cnt++;
        num[a[i]]++;
    }
    if(cnt<=k) cout<<0;
    else{
        sort(all(num));
        reverse(all(num));
        while(cnt>k){
            ans+=num[cnt-1];
            cnt--;
        }
        cout<<ans;
    }
}

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

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

	int n, m, x;
	cin >> n >> m >> x;
	vector<vector<int> >a(n, vector<int>(m));
	vector<int> c(n);

	for (int i = 0; i < n; i++) { // take the input
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}

	// since n is comparable small we can brute force through every solution and find the correct answer
	int all = 1 << n; // total number of subsets
	int ans = 12345678;
	for (int mask = 0; mask < all; mask++) {
		vector<int> level(m); // all the knowledge
		int cost = 0; // intial ability
		for (int i = 0; i < n; i++) {
			if ((mask >> i) & 1) {
				cost += c[i]; // add the cost of the book
				for (int j = 0; j < m; j++) {
					level[j] += a[i][j]; // add the knowledge
				}
			}
		}

		bool ok = true;

		for (int j = 0; j < m; j++) {
			if (level[j] < x) ok = false; // not acceptable
		}
		if (ok) ans = min(ans, cost);
	}
	if (ans == 12345678)
		cout << -1 << "\n";
	else
		cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3628
N = int(input())
h_list = list(map(int,input().split()))
dp = [0] * N
dp[0] = 0
dp[1] = abs(h_list[1] - h_list[0])
for i in range(2,N):
    dp[i] = min(dp[i-2] + abs(h_list[i] - h_list[i-2]), (dp[i-1] + abs(h_list[i-1] - h_list[i])))
#print(dp)
print(dp[N-1])

Measured memory_bytes: 13980
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

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 x;
  cin >> x;
  int c500 = x/500;
  x -= c500*500;
  int c5 = x/5;
  int ans = c500*1000 + c5*5;
  cout << ans << endl;

  return 0;
}

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

const int INF = 1000000;
int h,w;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int bfs(field &maze, int sx, int sy) {
  queue<P> que;
  vector<vector<int>> dist(h, vector<int>(w,INF));
  que.push(P(sx, sy));
  dist[sx][sy] = 0;
  while(que.size() != 0) {
    P p = que.front(); que.pop();
    rep(i,0,4) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
      if (maze[nx][ny] == "#") continue;
      if (dist[nx][ny] == INF) {
        que.push(P(nx, ny));
        dist[nx][ny] = dist[p.first][p.second] + 1;
      }
    }
  }

  int rtn = 0;
  rep(i,0,h) rep(j,0,w) {
    if (dist[i][j] == INF) continue;
    rtn = max(rtn, dist[i][j]);
  }
  return rtn;
}

int main() {
  cin >> h >> w;
  field maze(h,vector<string>(w));
  rep(i,0,h) {
    string s;
    cin >> s;
    rep(j,0,w) {
      maze[i][j] = s.substr(j,1);
    }
  }
  int ans = 0;
  rep(i,0,h) rep(j,0,w) {
    if (maze[i][j] == "#") continue;
    ans = max(ans, bfs(maze,i,j));
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
    int res = 0;
    string s = "";
    cin >> s;
    for(int i = 0; i < 4; i++){
        if(s[i] == '-')
            res--;
        else
            res++;
    }
    cout << res << "\n";
    return 0;
}

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

using namespace std;

const int MAXN = 1000;
const int MAXX = 5000;
vector<int> adjList[MAXN + 1];
int x[MAXN + 1];
int weights[MAXN + 1][2];
bool dp[MAXX + 1];

bool solve(int v, int p)
{
    for (int adj : adjList[v])
        if (adj != p)
            if (!solve(adj, v))
                return false;
    int totalSum = 0;
    fill(dp, dp + x[v] + 1, false);
    dp[0] = true;
    for (int adj : adjList[v])
    {
        if (adj != p)
        {
            totalSum += weights[adj][0] + weights[adj][1];
            for (int i = x[v]; i >= 0; i--)
            {
                if (dp[i])
                {
                    dp[i] = false;
                    for (int j = 0; j < 2; j++)
                    {
                        if (i + weights[adj][j] <= x[v])
                        {
                            dp[i + weights[adj][j]] = true;
                        }
                    }
                }
            }
        }
    }
    int best = -1;
    for (int i = 0; i <= x[v]; i++)
    {
        if (dp[i])
            best = i;
    }
    if (best == -1)
        return false;
    weights[v][0] = x[v];
    weights[v][1] = totalSum - best;
    if (weights[v][0] > weights[v][1])
        swap(weights[v][0], weights[v][1]);
    return true;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 2; i <= n; i++)
    {
        int p;
        cin >> p;
        adjList[i].push_back(p);
        adjList[p].push_back(i);
    }
    for (int i = 1; i <= n; i++)
        cin >> x[i];
    if (solve(1, 1))
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    //for (int i = 1; i <= n; i++)
      //  cout << i << " " << weights[i][0] << " " << weights[i][1] << endl;
    return 0;
}


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


using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin >> a >> b;
    cout<< a/b << " " << a%b << " " << setprecision(9) << fixed << double(a) / double(b) << '\n';
    return 0;


}



Measured memory_bytes: 3280
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		char[] c = new char[1200];
		
		String line = br.readLine();
		for(int i = 0; i < line.length(); i++){
			c[i] = line.charAt(i);
			if(Character.isUpperCase(c[i])){
				c[i] = Character.toLowerCase(c[i]);
			}else{
				c[i] = Character.toUpperCase(c[i]);
			}
		}
		
		for(int j = 0; j < line.length(); j++){
			System.out.print(c[j]);
			if(j == line.length() - 1){
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 25276
import java.util.*;
public class Main {
    
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        if(N%2==1){
            for (int l=1, r=N-1; l <= M ; l++, r--) {
                System.out.println(String.format("%d %d", l,r));
            }
        }else{
            for (int l = 1, r=N; l <= M ; l++, r--) {
                if(l<=N/4){
                    System.out.println(String.format("%d %d", l, r));
                }else{
                    System.out.println(String.format("%d %d", l+1, r));
                }
            }
        }
    }
}

Measured memory_bytes: 105832
n,k=map(int,input().split())
A=list(map(int,input().split()))

ans=float("inf")
for i in range(1,2**n):
    num=format(i,"b").zfill(n)
    point=0
    if num.count("1")!=k:continue
    highest=A[0]
    for j in range(1,n):
        if num[j]=="1":
            point +=max(0,highest-A[j]+1)
            highest=max(highest+1,A[j])
        highest=max(highest,A[j])
    ans=min(ans,point)

print(ans)

Measured memory_bytes: 41840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

	    @SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);

	    int A = scan.nextInt();
	    int B = scan.nextInt();
	    int C = scan.nextInt();
	    int D = scan.nextInt();
	    
	    int X = A*B;
	    int Y = C*D;
	    
	    if(X ==Y){
	    	System.out.println(X);
	    } else if(X>Y){
	    	System.out.println(X);
	    } else if(X<Y){
	    	System.out.println(Y);
	    }
	    
		}

	}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int mod = 1e9+7;

int i,k,n;
int fac[2000026];
int res;

int mul(int a,int b) {
	return a*(ll)b % mod;
}

int pow(int a, int b) {
	int rs=1;
	while(b) {
		if(b%2) 
			rs = mul(rs, a);
		a = mul(a,a);
		b/=2;
	}
	return rs;
}

int dv(int a ,int b) {
	return mul(a, pow(b,mod-2));
}

int comb(int a,int b) {
	return dv(fac[a], mul(fac[a-b],fac[b]));
}

int add(int a,int b) {
	a+=b;
	if(a>=mod)
		a-=mod;
	if(a<0)
		a+=mod;
	return a;
}

int32_t main() {
	string s;
	cin>>k>>s;
	n=s.length();
	k+=n;
	fac[0]=1;
	fac[1]=1;
	for(i=2;i<=2000020;i++) {
		fac[i] = mul(fac[i-1], i);
	}
	res=0;
	for(i=n;i<=k;i++) {
		int temp = comb(i-1, n-1);
		temp = mul(temp, pow(25, i-n));
		temp = mul(temp, pow(26, k-i));
		res = add(res,temp);
		// cout<<res<<" "<<temp<<"\n";
	}

	cout<<res;
}

Measured memory_bytes: 12160
use std::i64;
use std::cmp;

// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main(){
    input! {
        s: chars,
        t: chars,
    }

    let mut dp = vec![vec![0;t.len()+1]; s.len()+1];
    for i in 1 .. s.len()+1 {
        for j in 1 .. t.len()+1 {
            if s[i-1] == t[j-1] {
                dp[i][j] = dp[i-1][j-1] + 1;
            } else {
                dp[i][j] = cmp::max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    let mut ans = String::new();
    let mut i = s.len();
    let mut j = t.len();
    while i > 0 && j > 0 {
        if s[i-1] == t[j-1] {
            ans.push(s[i-1]);
            i -= 1;
            j -= 1;
        } else {
            if dp[i][j] == dp[i-1][j] {
                i -= 1;
            } else {
                j -= 1;
            }
        }
    }

    println!("{}", ans.chars().rev().collect::<String>());
}




Measured memory_bytes: 41212
#include<bits/stdc++.h>
#define ll long long
#define sort(a) sort(a.begin(), a.end())
#define loop(n) for(ll i = 0; i<n; i++)
using namespace std;
 
int main(){
    ll n; int k;
    cin>>n>>k;
    cout<<int((log10(n)/log10(k))+1)<<"\n";
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main()
{
    int n;
    scanf("%d", &n);
    vvll a(n, vll(3));
    vvll dp(n, vll(3, 0));
    for (int i = 0; i < n; i++){
        scanf("%lld%lld%lld", &a[i][0], &a[i][1], &a[i][2]);
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 0; i < n - 1; i++){
        for (int j = 0; j < 3; j++){
            dp[i + 1][j] = max({dp[i + 1][j], dp[i][(j + 1) % 3] + a[i + 1][j], dp[i][(j + 2) % 3] + a[i + 1][j]});
            // cout << dp[i + 1][j] << " ";
        }
        // cout << endl;
    }
    printf("%lld", max({dp[n - 1][0], dp[n - 1][1], dp[n - 1][2]}));
    return 0;
}

Measured memory_bytes: 14312
#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
#include <cstdlib> 
#include <math.h>
#include<cstdio>
#include<cmath>
#include<cstring>
#define dbg(x) cout << #x << " = " << x << endl
#define dbg2(x,y) cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define dbg3(x,y,z) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl
#define dbg4(x,y,z,q) cout << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << ", " << #q << " = " << q << endl
//_builtin_popcount
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)

#define gap cout<<endl;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fo(i,n) for(int i=0;i<n;i++)
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()


ll n,k;
std::vector<ll> a(200005);
 std::vector<ll> f(200005);
bool check(ll val){
	ll tmp=k;
	fo(i,n){
		//dbg(a[i]*f[i]);
		if(a[i]*f[i]<=val) ;
		else{
			tmp=tmp-(a[i]-(ll)val/f[i]);
		}
		if(tmp<0) return false;
		//dbg(tmp);
	}
	return true;

}

int main(){
	cin>>n>>k;
	a.resize(n);
	f.resize(n);
	fo(i,n) cin>>a[i];
	fo(i,n) cin>>f[i];
	ll lo=0;
	ll hi=1e13;
	ll mid;
	sort(all(a));
	reverse(all(a));
	sort(all(f));
	while(lo<hi){
		mid=(lo+hi)/2;
		if(check(mid)) hi=mid;
		else lo=mid+1;
	    //dbg2(lo,hi);
	}
	cout<<lo<<endl;
}

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

int main () {

    int N, M;
    scanf("%d %d", &N, &M);

    int L[M], R[M];
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &L[i], &R[i]);
    }

    vector<int> number_of_openable_gate(N + 2, 0);
    for (int i = 0; i < M; i++) {
        number_of_openable_gate[L[i]]++;
        number_of_openable_gate[R[i]+1]--;
    }

    for (int i = 1; i <= N; i++) {
        number_of_openable_gate[i] += number_of_openable_gate[i-1];
    }

    int ans = 0;

    for (int i = 0; i < N + 2; i++) {
        if (number_of_openable_gate[i] == M) {
            ans++;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1408