akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <algorithm>
using namespace std;

int w;
int h;
int n;
int ans;
int x[1000];
int y[1000];

int main() {
    scanf("%d%d%d", &w, &h, &n);
    scanf("%d%d", &x[0], &y[0]);
    for (int i=1; i<n; i++) {
        int dx, dy;

        scanf("%d%d", &x[i], &y[i]);
        dx = x[i]-x[i-1];
        dy = y[i]-y[i-1];
        if ((long long int)dx * (long long int)dy >= 0) {
            ans += max(abs(dx), abs(dy));
        } else {
            ans += abs(dx) + abs(dy);
        }
    }

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

Measured memory_bytes: 1032
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}

int main() {
	int N,M;
    cin>>N>>M;
    int L[M],R[M];
    rep(i,M) cin>>L[i]>>R[i];
    int gate[N+1]={};
    rep(i,M){
        gate[L[i]-1]++;
        gate[R[i]]--;
    }
    rep(i,N+1){
        if(0<i) gate[i]+=gate[i-1];
    }
    ll ans=0;
    rep(i,N+1) if(gate[i]==M) ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
n = int(input())
a = list(map(int,input().split()))
c = 0
for i in range(n):
  if a[i] < 0:
    c += 1
    a[i] = -a[i]
s = 0
m = 10**9
for i in range(n):
  s += a[i]
if c % 2 == 1:
  for i in range(n):
    m = min(m,a[i])
  s -= 2*m
print(s)

Measured memory_bytes: 14332
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

H,W=get_i
s=array(H)
H.times do|i|
    s[i]=get_nsp
end
ans=array(W,0,H)
Dir_=[[1,0],[1,1],[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1]]
H.times do|i|
    W.times do|j|
      Dir_.each do|x,y|
          next unless (j+x).between?(0,W-1) and (i+y).between?(0,H-1)
          ans[i][j]+=1 if s[i+y][j+x]=="#"
      end
    end
end
H.times do|i|
    W.times do|j|
        if s[i][j]=="#"
            print"#"
        else
            print ans[i][j]
        end
    end
    print "\n"
end

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;

    bool flagX, flagY;
    if(x-r>=0 && x+r<=W) {flagX=1;
    }
    else {flagX=0;
    }
    if(y-r>=0 && y+r<=H) {flagY=1;
    }
    else {flagY=0;
    }

    if(flagX && flagY) {cout << "Yes" << endl;
    }
    else {cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.La;
		if(s[1]%2==s[2]%2){
			Console.WriteLine("{0}",(s[2]-s[1])/2);
			return;
		}
		long ans=0;
		if(s[1]-1<s[0]-s[2]){
			ans+=s[1];
			s[2]-=s[1];
			s[1]=1;
		}
		else{
			ans+=s[0]-s[2]+1;
			s[1]+=s[0]-s[2]+1;
			s[2]=s[0];
		}
		Console.WriteLine("{0}",ans+((s[2]-s[1])/2));
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  ll N;
  cin>>N;
  cout<<N/3<<endl;
  return 0;
}

Measured memory_bytes: 256
import math

h = int(input())

dp = dict()
dp[1] = 1
def rec(parent):
    child = math.floor(parent / 2)
    if parent == 1:
        return 1
    elif child in dp:
        return 2 * dp[child] + 1
    else:
        return 2 * rec(child) + 1

print(rec(h))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	long long i = 0;
	long long n,a,b;
	cin>>n>>a>>b;
	if(n<a+b)
	{
		if(n>=a)cout<<a<<endl;
		else cout<<n<<endl;
		return 0;
	}
	long long k=0;
	i = n/(a+b)*a;
	k = n-((a+b)*(n/(a+b)));
	if(k>=a)cout<<i+a<<endl;
	else if(k<a)cout<<i+k<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  Int a,b,c;
  cin>>a>>b>>c;

  Int odd=0,even=0;
  if(a&1) odd++;else even++;
  if(b&1) odd++;else even++;
  if(c&1) odd++;else even++;

  if(even==3) drop("Tem");
  if(even==2) drop("Tem");
  if(even==1) drop("Hom");
  if(even==0) drop("Hom");

  assert(0);
  return 0;
}



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

// #undef DEBUG
// #define DEBUG
/// {{{ DEBUG --- ///
#ifdef DEBUG
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { o << "{"; for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? ", " : ""); o << "}"; return o; }
#ifdef USE_COUT
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cout<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#else
#define dump(...) [&](){auto __debug_tap=make_tuple(__VA_ARGS__);cerr<<"["<<__LINE__<< "] "<<#__VA_ARGS__<<" = "<<__debug_tap<<"\n";}()
#endif
template<class T> inline void dump2D(T &d, size_t sizey, size_t sizex) { ostream&o=
#ifdef USE_COUT
  cout;
#else
  cerr;
#endif
  for(size_t i = 0; i < sizey; i++) { for(size_t j = 0; j < sizex; j++) o << d[i][j] << " "; o << endl; }
}
#else
template <typename T> ostream &operator<<(ostream &o, const vector<T> &v) { for(size_t i = 0; i < v.size(); i++) o << v[i] << (i + 1 != v.size() ? " " : ""); return o; }
#define dump(...) (42)
#define dump2D(...) (42)
#endif
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":", ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream &o, tuple<T...> const &t){ o << "("; _ot<0>(o, t); o << ")"; return o; }
template<class T, class U> ostream & operator<<(ostream &o, pair<T, U> const &p) { o << "(" << p.first << ", " << p.second << ")"; return o; }
/// }}}--- ///


int a[112345];
map<int, int> mp;
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  mp[0]++;
  for(int i = 0; i < n; i++) cin >> a[i], a[i] %= m, a[i] += i ? a[i-1]: 0, a[i]%=m, ans+=mp[a[i]],  mp[a[i]]++, dump(a[i]);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3584
import sys
m=10**6;a=[1]*m;a[0:2]=0,0
for i in range(2,999):
 if a[i]>0:
  for j in range(i*2,m,i):a[j]=0
for i in range(m):a[i]+=a[i-1]
for e in sys.stdin:print(a[int(e)])


Measured memory_bytes: 44852
#include<stdio.h>

int main(){
	
	int n,i,h,k,numb,cards[4][13];
	for(i=0;i<4;i++){
		for(h=0;h<13;h++){
			cards[i][h]=0;
		}
	}
	char kind;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%c",&kind);
		scanf("%c %d",&kind,&numb);
		if(kind=='S')k=0;
		if(kind=='H')k=1;
		if(kind=='C')k=2;
		if(kind=='D')k=3;
		cards[k][numb-1]=1;
	}
	
	for(i=0;i<4;i++){
		for(h=0;h<13;h++){
			if(cards[i][h]==0){
				if(i==0)printf("S");
				if(i==1)printf("H");
				if(i==2)printf("C");
				if(i==3)printf("D");
				printf(" %d\n",h+1);
			}
		}
	}
	
	
	return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    int n;
    cin >> n;
    map<int, int> m;
    REP(i, n){
        m[i+1] = 0;
    }
    REP(i, n-1){
        int a;
        cin >> a;
        m[a]++;
    }
    for(map<int, int>::iterator i = m.begin(); i != m.end(); ++i) cout << i->second << endl;
}


Measured memory_bytes: 13016
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    vector<int> is_prime(100005,1);
    is_prime[0] = 0, is_prime[1] = 0;
    for (int i = 2; i < 100005; i++) {
        if (!is_prime[i]) continue;
        for (int j = i*2; j < 100005; j+=i) is_prime[j] = 0;
    }
    vector<int> a(100005, 0);
    for (int i = 0; i < 100005; i++) {
        if (i % 2 == 0) continue;
        if (is_prime[i] && is_prime[(i+1)/2]) a[i] = 1;
    }
    vector<int> s(100006, 0);
    for (int i = 0; i < 100005; i++) s[i+1] = s[i] + a[i];
    int Q; 
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int l, r;
        cin >> l >> r;
        cout << s[r+1]-s[l] << endl;
    }
}

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

int main(void)
{
  int i, n, j, k, v;
  cin >> n;
  int A[n];
  for (i = 0; i < n; i++) cin >> A[i];
  for (i = 0; i < n - 1; i++) cout << A[i] << " ";
  cout << A[n - 1] << endl;
  for (i = 1; i < n; i++) {
    v = A[i];
    j = i - 1;
    while (j >= 0 && A[j] > v) {
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = v;
    for (k = 0; k < n - 1; k++) cout << A[k] << " ";
    cout << A[n - 1] << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W, A, B;
  cin >> H >> W >> A >> B;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if ((i < B && j < A) || (i >= B && j >= A)) {
        cout << 0;
      } else {
        cout << 1;
      }
    }
    cout << '\n';
  }
  return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long n, m;
  std::vector<std::array<long, 2>> xs;
  Solver() {
    S002 reader;
    reader >= n >= m >m>= xs;
  }
  void solve() {
    std::vector<long> ys(n, 0);
    for(auto x : xs) {
      ys[x[0]-1] += 1;
      ys[x[1]-1] += 1;
    }
    for(auto y : ys) {
      printf("%ld\n", y);
    }
  }
  ~Solver() { fprintf(stderr, "--end--\n"); }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}



Measured memory_bytes: 256
def main():
    A, B, C = map(int, input().split())
    ans = 'NO'
    Atmp = A
    for i in range(pow(10,5)):
        if Atmp%B==C:
            ans = 'YES'
            break
        Atmp += A
    print(ans)

if __name__ == "__main__":
    main()


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

#define ll long long
using namespace std;

#define MAXN 1000000

int solve(vector<int> &A)
{
	if(A.size() == 1)
		return A[0];

	int l = A.size();
	int m = 1;
	while(m*2 <= l)
		m*=2;
	
	vector<int> B;
	int s = 0;
	for(int i=0; i<m; ++i)
		s+=A[i];
	s%=2;
	B.push_back(s);
	for(int i=m; i<l; ++i)
	{
		s+=(A[i]-A[i-m]+2);
		s%=2;
		B.push_back(s);
	}
	return solve(B);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int N;
	cin>>N;
	vector<int> A(N);
	int m = 2;
	for(int i=0; i<N; ++i)
	{
		char a;
		cin>>a;
		A[i] = a-'1';
		if(A[i] == 1)
			m = 1;
	}
	//cerr<<"--1--"<<endl;
	//cerr<<"--1--"<<endl;
	if(m == 2)
	{
		for(int i=0; i<N; ++i)
			A[i]/=2;
	}
	else
	{
		for(int i=0; i<N; ++i)
			A[i]%=2;
	}
	
	int ans = solve(A);
	
	cout<<ans*m<<endl;	
	return 0;
}


Measured memory_bytes: 7920
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)













ll POW(ll n, ll m, ll p){
    ll res = 1, x = n;
    for(ll i = m; i > 0; i >>= 1){
        if(i & 1){
            res *= x;
            res %= p;
        }
        x *= x;
        x %= p;
    }
    return res;
}

ll Fermat(ll a, ll x, ll p){
    return POW(a, p - 1 - x, p);
}

int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    REP(i, n){
        cin >> a[i];
    }
    ll cnt = 0;
    REP(i, n){
        for(ll j = n - 1; j > 0; j--){
            if(a[j - 1] > a[j]){
                swap(a[j - 1], a[j]);
                cnt++;
            }
        }
    }
    vector<ll> b = a;
    REP(i, n) b.push_back(a[i]);
    ll cnt2 = 0;
    REP(i, 2 * n){
        for(ll j = 2 * n - 1; j > 0; j--){
            if(b[j - 1] > b[j]){
                swap(b[j - 1], b[j]);
                cnt2++;
            }
        }
    }
    cout << ((((cnt * k % MOD) + ((cnt2 * k % MOD) * (k - 1) % MOD) * Fermat(2, 1, MOD)))) % MOD << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int iinf = 1 << 28;
const long long llinf = 1ll << 60;
const double PI = 3.14159265;


int main() {
    int n; cin>>n;
    vector<int> l(n);
    for (int i = 0; i < n; ++i) cin>>l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    for (int i = n - 1; i >= 2; --i) {
        for (int j = i - 1; j >= 1; --j) {
            vector<int>::iterator it = upper_bound(l.begin(), l.end(), l[i] - l[j]);
            int pos_c = it - l.begin();
            ans += max(0, j - pos_c);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
from itertools import accumulate #list(accumulate(A))

N = ii()
S = [sorted(li()) for _ in range(3)]
rec = [[0]*N for i in range(3)]

for i in range(N):
    #for j in range(2):
    #rec[0][i] = bisect.bisect_right(S[1], S[0][i])
    rec[1][i] = N - bisect.bisect_right(S[2], S[1][i])

acc = list(accumulate(rec[1]))
#acc_1 = [0] * N
#for i in range(N):
    #ind = bisect.bisect_right(S[2], acc_

ans = 0
for i in range(N):
    #for j in range(rec[0][i], N):
    ind = bisect.bisect_right(S[1], S[0][i])
    if ind == 0:
        ans += acc[-1]
    else:
        ans += acc[-1] - acc[ind-1]

print(ans)

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

using namespace std;

ll n, k, zero;
vector <ll> pos;
vector <ll> neg;

bool Check(ll x)
{
    ll Res = 0;

    if (x >= 0) {
        Res += zero * (zero - 1) / 2;
        Res += zero * (pos.size() + neg.size());
    }

    for (int L = 0, R = pos.size() - 1; L < pos.size(); L++) {
        R = max(R, L);
        while (R > L && pos[L] * pos[R] > x)
            R--;
        Res += R - L;
    }

    for (int L = 0, R = neg.size() - 1; L < neg.size(); L++) {
        R = max(R, L);
        while (R > L && neg[L] * neg[R] > x)
            R--;
        Res += R - L;
    }

    for (int L = pos.size() - 1, R = 0; L >= 0; L--) {
        while (R < neg.size() && pos[L] * neg[R] > x)
            R++;
        Res += (neg.size() - R);
    }

    return Res >= k;
}

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int x;  scanf("%d", &x);

        if (x > 0) pos.push_back(x);
        else if (x < 0) neg.push_back(x);
        else zero++;
    }

    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());

    ll Ans = 0;
    ll Start = -1e18, End = 1e18;
    while (Start <= End) {
        ll Mid = Start + (End - Start) / 2;

        if (Check(Mid)) {
            Ans = Mid;
            End = Mid - 1;
        } else Start = Mid + 1;
    }

    printf("%lld\n", Ans);
    return 0;
}


Measured memory_bytes: 2420
n = gets.to_i
h = gets.chomp.split(" ").map(&:to_i)

# DP配列を初期化
dp = Array.new(n, 0)

(1...n).each do |index|
  if index == 1
    dp[index] = dp[index - 1] + (h[index] - h[index - 1]).abs
  else
    step_one = dp[index - 1] + (h[index] - h[index - 1]).abs
    step_two = dp[index - 2] + (h[index] - h[index - 2]).abs
    dp[index] = [step_one, step_two].min
  end
end

puts dp[n - 1]


Measured memory_bytes: 11788
package main

import "fmt"

func main(){
    var w, h, x, y, r int
    fmt.Scanf("%d %d %d %d %d", &w, &h, &x, &y, &r)
    if x < r || y < r || x + r > w || y + r > h {
        fmt.Println("No")
    }else{
        fmt.Println("Yes")
    }
}


Measured memory_bytes: 1172
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout<< #x" " << x << endl;
#define ll long long
int main()
{
    //ios_base::sync_with_stdio(false);
    ll n;
    ll a;
    ll ans=0;
    cin >> n;
    for(int i=0;i<n;i++)
        cin >> a,ans+=(a-1);
    cout<< ans;
    return 0;
}


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

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
template<class T>void sort(vec<T> &v){sort(v.begin(),v.end());}
template<class T>void rsort(vec<T> &v){sort(v.rbegin(),v.rend());}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n; cin >> n;
    vec<ll> p(n); rep(i,n)cin >> p[i];
    ll ans = 0;
    rep(i,n-2){
        if(p[i] < p[i+1] && p[i+1] < p[i+2])ans++;
        else if(p[i] > p[i+1] && p[i+1] > p[i+2])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

double x[100];
double y[100];
double a[100];

int main()
{
	int n;
	double ans;

	cin >> n;
	rep(i, n) cin >> x[i];
	rep(i, n) cin >> y[i];
	rep(i, n) a[i] = abs(x[i] - y[i]);

	ans = 0.0;
	rep(i, n) ans += a[i];
	printf("%.10lf\n", ans);

	ans = 0.0;
	rep(i, n) ans += a[i] * a[i];
	ans = sqrt(ans);
	printf("%.10lf\n", ans);

	ans = 0.0;
	rep(i, n) ans += a[i] * a[i] * a[i];
	ans = cbrt(ans);
	printf("%.10lf\n", ans);

	ans = 0.0;
	rep(i, n) ans = max(ans, a[i]);
	printf("%.10lf\n", ans);

	return 0;
}



Measured memory_bytes: 3412
mojiretsu = input()
mojiretsu_len = len(mojiretsu)
moji_list = []
hanntei = 0

for i in range(mojiretsu_len):
    moji_list.append(mojiretsu[i])

for j in range(mojiretsu_len):
    count_moji = moji_list.count(moji_list[j])
    kisuu_hanntei = count_moji%2
    if kisuu_hanntei==1:
        print("No")
        hanntei = 1
        break

if not hanntei==1:
    print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
int mod = 1000000007;
const int INF = 1001001001;

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main() {
  int n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  mod = p;

  ll ans = 0;

  if (10 % p == 0) {
    vector<int> cnt(p);
    rep(i, n) {
      int c = s[i] - '0';
      if (c % p == 0) {
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  vector<mint> sum(n + 1);
  reverse(s.begin(), s.end());
  mint ten = 1;
  rep(i, n) {
    mint now = ten * (s[i] - '0'); 
    sum[i + 1] = sum[i] + now;
    ten *= 10;
  }
  
  vector<ll> cnt(p); 
  rep(i, n + 1) cnt[sum[i].x]++;

  rep(i, p) {
    ll c = cnt[i];
    ans += c * (c - 1) / 2;
  }

  cout << ans << endl;
}

Measured memory_bytes: 5244
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Main {
  private static int solve1(int W, List<Integer> values, List<Integer> weights, List<Integer> numbers) {
    int[] dp = new int[W + 1];
    for (int i = 1; i <= values.size(); ++i) {
      for (int j = W; j >=0; --j) {
        int v = values.get(i - 1);
        int w = weights.get(i - 1);
        int c = numbers.get(i - 1);
        for (int k = 1; k <= c; ++k) {
          if (j - k * w >= 0) {
            dp[j] = Math.max(dp[j], dp[j - k * w] + k * v);
          }
        }
      }
    }
    return dp[W];
  }

  private static int solve2(int W, List<Integer> values, List<Integer> weights, List<Integer> numbers) {
    List<Integer> newValues = new ArrayList<>();
    List<Integer> newWeights = new ArrayList<>();
    for (int i = 0; i < numbers.size(); ++i) {
      List<Integer> newNums = decompose(numbers.get(i));
      for (int num : newNums) {
        newValues.add(num * values.get(i));
        newWeights.add(num * weights.get(i));
      }
    }
    int[] dp = new int[W + 1];
    for (int i = 1; i <= newValues.size(); ++i) {
      for (int j = W; j >= 0; --j) {
        int v = newValues.get(i - 1);
        int w = newWeights.get(i - 1);
        if (j - w >= 0) {
          dp[j] = Math.max(dp[j], dp[j - w] + v);
        }
      }
    }
    return dp[W];
  }

  private static List<Integer> decompose(int num) {
    List<Integer> res = new ArrayList<>();
    int ele = 1;
    while (num - ele + 1 > 0) {
      res.add(ele);
      ele <<= 1;
    }
    int last = res.get(res.size() - 1);
    res.set(res.size() - 1, num - last + 1);
    return res;
  }

  private static final Pattern SPLIT = Pattern.compile("\\s");
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    List<Integer> weights = new ArrayList<>();
    List<Integer> values = new ArrayList<>();
    List<Integer> numbers = new ArrayList<>();
    List<Integer> NW = Stream.of(SPLIT.split(scanner.nextLine())).map(Integer::valueOf)
        .collect(Collectors.toList());
    final int N = NW.get(0);
    final int W = NW.get(1);
    for (int i = 0; i < N; ++i) {
      List<Integer> collect = Stream.of(SPLIT.split(scanner.nextLine())).map(Integer::valueOf)
          .collect(Collectors.toList());
      values.add(collect.get(0));
      weights.add(collect.get(1));
      numbers.add(collect.get(2));
    }
    System.out.println(solve2(W, values, weights, numbers));
  }
}

Measured memory_bytes: 33076
#include <bits/stdc++.h>
using namespace std;
long long n,ans=0,b=0,c=0;
int main(){
  cin >> n;
  long long a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b+=abs(c-a[i]);    
    if(i==n-1){
      b+=abs(a[i]);
    }
    c=a[i];
  }
  if((a[0]>=0&&a[1]>=a[0])||(a[0]<=0&&a[1]<=a[0])){
    cout << b << endl;    
  }else{
    if((a[0]>=0&&a[1]<=0)||(a[0]<=0&&a[1]>=0)){
      cout << b-abs(a[0])*2 << endl;
    }else{
      cout << b-abs(a[0]-a[1])*2 << endl;
    }
  }
  for(int i=1;i<n-1;i++){
    if((a[i-1]<=a[i]&&a[i]<=a[i+1])||(a[i-1]>=a[i]&&a[i]>=a[i+1])||(a[i]==a[i-1]||a[i]==a[i+1])){
      cout << b << endl;
    }else{
      cout << b-min(abs(a[i]-a[i-1]),abs(a[i]-a[i+1]))*2 << endl;
    }
  }
  if((a[n-2]<=a[n-1]&&a[n-1]<=0)||(a[n-2]>=a[n-1]&&a[n-1]>=0)){
    cout << b << endl;
  }else{
    if((a[n-1]>=0&&a[n-2]<=0)||(a[n-1]<=0&&a[n-2]>=0)){
      cout << b-abs(a[n-1])*2 << endl;
    }else{
      cout << b-abs(a[n-1]-a[n-2])*2 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2048
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
typedef long long ll;
#include <cmath>
#include<cstdio>
#include<iomanip>

int main(int argc, char *argv[])
{
	int n;


	cin>>n;
	vector<int> a(n,0);


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

	}
	for (int i=0;i<n;i++)
	{
		cout<<a[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 4048
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
    int n;
    cin >> n;
    vector<ll> dp = {2, 1};
    for(int i = 2; i <= n; i++) {
        int last = dp.size();
        dp.push_back(dp[last-1]+dp[last-2]);
        // cout << dp.back() << " " << endl;
    }
    cout << dp[n] << endl;
    return 0;
}




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

const int MOD = 1e9 + 7;
const int iINF = 1e9;
const long long int llINF = 1e18;
const double PI = acos(-1.0);
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, init, n) for (int i = init; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using edge = struct
{
    int to;
    int cost;
};

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

const int MAX = 7368800;

int main()
{
    int M, N;
    bool flag[MAX];

    while (cin >> M >> N, M)
    {
        rep(i, MAX) flag[i] = false;

        for (int i = M;; i++)
        {
            if (flag[i])
                continue;

            if (N == 0)
            {
                cout << i << endl;
                break;
            }
            else
            {
                N--;
                for (int j = i * 2; j <= MAX; j += i)
                    flag[j] = true;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 10300
fn getline() -> String{
    let mut __ret = String::new();
    std::io::stdin().read_line(&mut __ret).ok();
    return __ret;
}

fn main() {
    let s = getline();
    let a:Vec<_> = s.trim().split(' ').collect();
    let (a,b,c):(i32,i32,i32) = (a[0].parse().unwrap(),a[1].parse().unwrap(), a[2].parse().unwrap());

    if a <= c && c <= b {
        println!("Yes");
    }else{ 
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
   ll n;
   cin>>n;
   ll arr[n];
   for(ll i=0;i<n;++i){
       cin>>arr[i];
   }
   ll ans =0;
   for(int i=1;i<n;++i){
       if(arr[i]<arr[i-1]){
            ans += (arr[i-1] - arr[i]);
            arr[i] = arr[i-1];
       }
   }
   cout<<ans<<endl;
}

Measured memory_bytes: 5168
#include<bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d",&x);
#define scs(x) scanf("%s",x);
#define scl(x) scanf("%lld",&x);
#define rep(i,s,e) for(int i=s; i<=e; ++i)
#define dep(i,s,e) for(int i=s; i>=e; --i)
typedef long long ll;
using namespace std;
const ll mod=998244353;
const int Max=2e5+5;
int a[Max];
int main()
{
	int n;
	sc(n);
	rep(i,1,n-1){
		int u;sc(u);a[u]++;
	}rep(i,1,n)pf("%d\n",a[i]);
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    int h[n];
    REP(i,n)cin >> h[i];

    int count = 0;
    while(1){
        if(*max_element(h,h+n)==0)break;
        int i = 0;
        while(i<n){
            if(h[i]==0)i++;
            else{
                ++count;
                while(i<n&&h[i]!=0){
                    h[i]--;
                    ++i;
                }
            }
        }
    }
    COUT(count);
    return 0;
} 


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 

int n , a[N] , x;



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

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

    int s1 = 0 , s2 = 0 , mn = OO; 

    for(int t = 1 ; t <= n ; ++t){
        
        s1 = a[t] - a[0];
        s2 = a[n] - a[t];
        //cout << s1 << " " << s2 << "\n";
        mn = min(mn , abs(s1-s2));
    }
    cout << mn << "\n";

 
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	private void solve() {
		Scanner in = new Scanner(System.in);
		int N = in.nextInt();
		int current = in.nextInt();
		int total = current; //1st
		int prev = current;
		for (int i = 1; i < N-1; i++) {
			current = in.nextInt();
			total += Math.min(prev, current);
			prev = current;
		}
		total += prev; //last
		System.out.println(total);
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}


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

int main() {
    int N; cin >> N;
    int64_t H = 1, W = 0;
    while(H * W < N * 2) H++, W++;
    if(H * W != N * 2) {
        cout << "No" << '\n';
        return 0;
    }
    vector<vector<int>> ans(H, vector<int>(W));
    int n = 1;
    for(int b = 0; b < W; ++b) {
        for(int i = 0; i + b < W; ++i) {
            ans[i][i + b] = n;
            ans[i + b + 1][i] = n;
            n++;
        }
    }
    cout << "Yes" << '\n';
    cout << H << '\n';
    for(int i = 0; i < H; ++i) {
        cout << W << " ";
        for(int j = 0; j < W; ++j) cout << ans[i][j] << " ";
        cout << '\n';
    }
    return 0;
}


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

int main(){
    long int n, k, q, sub;

    std::cin >> n >> k >> q;
    std::vector<long int> vec(n , 0);

    for(int i = 0; i < q; i++){
        std::cin >> sub;
        vec.at(sub - 1) += 1;
    }

    for(int i = 0; i < n; i++){
       if(k - (q - vec.at(i)) > 0){
           std::cout << "Yes" << std::endl;
       }else{
           std::cout << "No" << std::endl;
       }
    }

    return 0;
}


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

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

        Scanner sc = new Scanner(System.in);

        int varieties = Integer.parseInt(sc.next());
        int buyCount = Integer.parseInt(sc.next());
        int[] prices = new int[varieties];
        for (int i = 0; i < varieties; i++) {
            prices[i] = Integer.parseInt(sc.next());
        }

        Arrays.sort(prices);

        int sum = 0;
        for (int i = 0; i < buyCount; i++) {
            sum += prices[i];
        }

        System.out.println(sum);
        sc.close();
    }
}


Measured memory_bytes: 38236
#include<iostream>
#include<iomanip>
#include<stdio.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<functional>
#include<math.h>
#include<unordered_set>
using namespace std;

int main() {
	int N;
	string s;
	int ans = 0;

	cin >> N >> s;

	for (int i = 0; i < N - 1; i++) {
		int cnt = 0;
		bool table[26] = { false };

		for (int j = 0; j <= i; j++) {
			table[s[j] - 'a'] = true;
		}

		for (int j = i + 1; j < N; j++) {
			if (table[s[j] - 'a']) {
				cnt++;
				table[s[j] - 'a'] = false;
			}
		}
		ans = max(cnt, ans);
	}

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

Measured memory_bytes: 256
import java.util.Scanner;

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

		if(input.toCharArray()[0] != 'A') {
			System.out.print("WA");
			return;
		}
		if(input.toCharArray()[1] == 'C') {
			System.out.print("WA");
			return;
		}
		if(input.toCharArray()[input.length() - 1] == 'C') {
			System.out.print("WA");
			return;
		}
		if(input.replaceAll("C","").length() == input.length()) {
			System.out.print("WA");
			return;
		}
		if(input.replaceAll("C","").length() < input.length() - 1) {
			System.out.print("WA");
			return;
		}
		if(!input.toLowerCase().equals(input.replaceAll("A","a").replaceAll("C","c"))) {
			System.out.print("WA");
			return;
		}
		System.out.print("AC");
	}
	
}

Measured memory_bytes: 21844
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,a,b,c;
vector<int> v;

int dfs(int num,int aa,int bb,int cc){
    int ret;
    int u,r,y,s;
    
    if(num==n){
        if(aa==0||bb==0||cc==0){
            return 100000000;
        }else{
            ret=abs(a-aa)+abs(b-bb)+abs(c-cc);}
    }else{
        if(aa==0){ u=dfs(num+1,aa+v[num],bb,cc);        }else{ u=dfs(num+1,aa+v[num],bb,cc)+10;        }
        if(bb==0){
            r=dfs(num+1,aa,bb+v[num],cc);        }else{
            r=dfs(num+1,aa,bb+v[num],cc)+10;        }
        if(cc==0){
            y=dfs(num+1,aa,bb,cc+v[num]);
        }else{
            y=dfs(num+1,aa,bb,cc+v[num])+10;
            
        }
        
        s=dfs(num+1,aa,bb,cc);
        ret=min({u,r,y,s});
    }
    
    return ret;
}



int main(){
    cin>>n>>a>>b>>c;
    rep(i,n){
        int x;cin>>x;
        v.push_back(x);
    }
    cout<<dfs(0,0,0,0)<<endl;
    
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, i, j, t, c, num[100];
	
	while (scanf("%d", &n), n != 0){
		for (i = 0; i < n; i++){
			scanf("%d", &num[i]);
		}
		c = 0;
		for (i = 1; i < n; i++){
			for(j = 1; j < n; j++){
				if (num[j - 1] > num[j]){
					t = num[j - 1];
					num[j - 1] = num[j];
					num[j] = t;
					c++;
				}
			}
		}
		
		printf("%d\n", c);
	}
	
	return (0);
}

Measured memory_bytes: 600
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: Write and Erase
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

typedef map<int,int> mii;

/* global variables */

mii amap;

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);
    amap[ai]++;
  }

  int cnt = 0;
  for (mii::iterator mit = amap.begin(); mit != amap.end(); mit++)
    if (mit->second & 1) cnt++;

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


Measured memory_bytes: 4992
#include <iostream>

int main(){
    long long A, B, N;
    long long ans = 0;

    std::cin >> A >> B >> N;

    ans = ((A * std::min(N, B-1)) / B) - (A * (std::min(N, B-1)/B));

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

Measured memory_bytes: 3596
<?php
list($n) = ints();
list($s) = strs();
$cnt['('] = 0;
$c = 0;
for ($i = 0; $i < $n; ++$i) {
    if ($s[$i] === '(') $c++;
    else $c--;
    if ($c < 0) {
        $cnt['(']++;
        $c = 0;
    }
}
$cnt[')'] = 0;
$c = 0;
for ($i = $n - 1; $i >= 0; --$i) {
    if ($s[$i] === ')') $c++;
    else $c--;
    if ($c < 0) {
        $cnt[')']++;
        $c = 0;
    }
}
echo str_repeat('(', $cnt['(']) . $s . str_repeat(')', $cnt[')']);
function strs()
{
    return explode(' ', trim(fgets(STDIN)));
}
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>


#define fs first
#define sc second

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

int N, M, Q;
int main(){
    cin >> N >> M >> Q;

    int x[500][500];
    for(int i = 0; i < 500; i++){
        fill(x[i], x[i]+500, 0);
    }

    for(int i = 0; i < M; i++){
        int l, r;
        cin >> l >> r;
        l--; r--;
        x[l][r]++;
    }
    for(int i = 0; i < 500; i++){
        for(int j = 1; j < 500; j++){
            x[i][j] += x[i][j-1];
        }
    }
    for(int j = 0; j < 500; j++){
        for(int i = 499; i > 0; i--){
            x[i-1][j] += x[i][j];
        }
    }

    for(int i = 0; i < Q; i++){
        int p, q;
        cin >> p >> q;
        p--; q--;
        cout << x[p][q] << endl;
    }




    return 0;

}


Measured memory_bytes: 1920
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


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

	ull res = 0;
	for (ll i = 1; i <= n; i++)
	{
		if (!(i % 3 == 0 || i % 5 == 0))
		{
			res += i;
		}
	}

	println(res);
}

Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>
  
using namespace std;
  
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

bool cc(char a){
	return a=='.' || a==',';
}

int main(){
	string str;
	bool ok = false;
	while(cin>>str){
		if(cc(str[str.size()-1])){
			str.erase(str.begin()+str.size()-1);
		}
		
		if(str.size()>=3 && str.size()<=6){
			if(ok)cout<<" ";
			ok=true;
			cout<<str;
		}
	}
	cout<<endl;
}

Measured memory_bytes: 1172
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;
 
int main(void){
    lint N;
    cin >> N;
    lint lim=sqrt(N);
    lint ans=LINF;
    for(int i=1;i<=lim;i++){
        if(N%i==0){
            lint K=N/i;
            ans=min(ans,K+i-2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256