akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N, max, k = 0, l = 1, sum = 0;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
    cin >> vec.at(i);
  for (int i = 0; i < N; i++){
    max = 0;
    for (int j = 0; j < N; j++){
      if (max < vec.at(j)){
        max = vec.at(j);
        k = j;
      }
    }
    sum += max * l;
    l *= -1;
    vec.at(k) = 0;
  }
  cout << sum << endl;
}
      
  

Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int N, M;
    cin >> N >> M;

    vector<pair<int, int> > A;

    for (int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        A.push_back(pair<int, int>(a, b));
    }

    sort(A.begin(), A.end());
    double m=0;
    for (pair<int, int> x : A) {
        int num = min(M, x.second);
        m += (double)x.first*num;
        M -= num;
        if (M==0){
            break;
        }
    }
    
    int d=log10(m);
    for (int i=d; i >= 0; --i) {
        int v = (m/pow(10,i));
        cout << v;
        m = m - (double)v*(double)(pow(10,i));
    }
    cout << endl;
    return 0;
}

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

// definitions
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define rep(i, l, r) for (long long i = (l); i < (long long)(r); i++)
#define repb(i, r, l) for (long long i = (r); i > (long long)(l); i--)
#define pb push_back
#define mod1 998244353
#define mod 1000000007
#define MAX_CHAR 256

using namespace std;
typedef vector<long long> vl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector< pair<long long, long long> > vp;
typedef vector<tuple<long long , long long , long long> > vtup;
typedef deque <long long> dq;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;


// standard functions
ll gcd(ll x, ll y) {
    if (x < y) return gcd(y, x);
    if (y == 0) return x;
    return gcd(y, x % y);
} 
 


ll modexp(ll x, ll ex, ll modp) {
    ll ans = 1ll;
    while (ex > 0) {
        if (ex & 1ll) ans = (ans * x)%modp;
        ex >>= 1ll;
        x = (x * x)%modp;
    }
    return ans;
} 
 
ll nCrModp(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (ll i = 1; i <= n; i++) 
    { 
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
}
 
bool isPrime(ll n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true;  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
 
vl countFreq(ll arr[], ll n) 
{ 
    unordered_map<ll, ll> mp; 
    vector <ll> v;
    
    for (ll i = 0; i < n; i++) 
        mp[arr[i]]++; 
   
    for (auto x : mp) 
        v.pb(x.second);
    
    return v;
}

ll binarySearch(ll arr[], ll l, ll r, ll x) 
{ 
    while (l <= r) 
    { 
        ll m = l + (r - l) / 2; 
        if (arr[m] == x) 
            return m; 
        if (arr[m] < x) 
            l = m + 1; 
        else
            r = m - 1; 
    }
    return -1; 
}

const ll MAXSIEVE=(1e3);
ll spf[MAXSIEVE];
void sieve() 
{ 
    spf[1] = 1; 
    for (ll i=2; i<MAXSIEVE; i++) 
        spf[i] = i; 

    for (ll i=4; i<MAXSIEVE; i+=2) 
        spf[i] = 2; 
  
    for (ll i=3; i*i<MAXSIEVE; i++) 
    { 
        if (spf[i] == i) 
        { 
            for (ll j=i*i; j<MAXSIEVE; j+=i) 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
}

// code beigns in main
int main()
{
    
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll t=1;
    // cin >> t;
    
    while(t--)
    {
        ll n;
        cin >> n;
        
        set <string> str;
        rep(i,0,n)
        {
            string s;
            cin >> s;
            str.insert(s);
        }
        cout << str.size() << endl;
    }
}


Measured memory_bytes: 19292
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long 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 {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint operator^(const ll& t)const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return 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 {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

///////////////////////////

int main() {
	
	ll K, T;
	cin >> K >> T;

	ll ans = 0;
	rep(i, T) {
		ll a;
		cin >> a;
		ans = max(ans, 2 * a - K - 1);
	}
	cout << ans;
	system("PAUSE");
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main() {
  vector<int> X(2);
  cin >> X[0] >> X[1];
  int cnt = 0;
  sort(X.begin(), X.end());
  cnt = X[1] + max(X[1]-1, X[0]);
  cout << cnt << endl;
}

Measured memory_bytes: 256
N = gets.to_i
A = gets.split.map(&:to_i).sort.insert(0, 0).push(9_000_000_000)
B = gets.split.map(&:to_i).sort
C = gets.split.map(&:to_i).sort.insert(0, 0).push(9_000_000_000)

ans = 0
i, j, k = 0, 0, 0
B.each do |b|
  a = A.bsearch_index {|x| x >= b}
  c = C.bsearch_index {|x| x > b }
  next if a == 1
  next if c > N
  ans += (a - 1) * (N + 1 - c)
end

puts ans


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

struct dice{
	int top;
	int front;
	int left;
	int right;
	int back;
	int bottom;
};

void ClockwiseTop(dice *X){
	int c = X->front;
	X->front  = X->right;
	X->right  = X->back;
	X->back   = X->left;
	X->left   = c;
}

void ClockwiseFront(dice *X){
	int c = X->top;
	X->top    = X->left;
	X->left   = X->bottom;
	X->bottom = X->right;
	X->right  = c;
}

void ClockwiseRight(dice *X){
	int c = X->top;
	X->top    = X->front;
	X->front  = X->bottom;
	X->bottom = X->back;
	X->back   = c;
}

void ClockwiseBottom(dice *X){
	ClockwiseTop(X);
	ClockwiseTop(X);
	ClockwiseTop(X);
}

void ClockwiseBack(dice *X){
	ClockwiseFront(X);
	ClockwiseFront(X);
	ClockwiseFront(X);
}

void ClockwiseLeft(dice *X){
	ClockwiseRight(X);
	ClockwiseRight(X);
	ClockwiseRight(X);
}

void TwiceClockwiseTop(dice *X){
	ClockwiseTop(X);
	ClockwiseTop(X);
}

void TwiceClockwiseRight(dice *X){
	ClockwiseRight(X);
	ClockwiseRight(X);
}

dice ArrengeTop(int a, dice B){
	if(B.front  == a) ClockwiseRight(&B);
	if(B.right  == a) ClockwiseBack(&B);
	if(B.left   == a) ClockwiseFront(&B);
	if(B.back   == a) ClockwiseLeft(&B);
	if(B.bottom == a) TwiceClockwiseRight(&B);
	return B;
}

dice ArrengeFront(int a, dice B){
	if(B.right  == a) ClockwiseTop(&B);
	if(B.left   == a) ClockwiseBottom(&B);
	if(B.back   == a) TwiceClockwiseTop(&B);
	return B;
}

bool Flag(dice A, dice B){
	if(B.top    != A.top   ) return false;
	if(B.front  != A.front ) return false;
	if(B.right  != A.right ) return false;
	if(B.left   != A.left  ) return false;
	if(B.back   != A.back  ) return false;
	if(B.bottom != A.bottom) return false;
	return true;
}

bool Judge(dice A, dice B){
	B = ArrengeTop(A.top, B);
	B = ArrengeFront(A.front, B);	
	return Flag(A, B);
}

dice Enter(dice X){
	cin >> X.top;
	cin >> X.front;
	cin >> X.right;
	cin >> X.left;
	cin >> X.back;
	cin >> X.bottom;
	return X;
}

int main(){
	//?????????????????????????????¢?????°????????\?????????
	dice A = Enter(A);
	dice B = Enter(B);
	//???????????????????????¨?????????
	if(Judge(A, B) == false) cout << "No"  << endl;
	if(Judge(A, B) == true ) cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
using namespace std;
typedef long long LL;
typedef double db;
//char buf[1<<24],*p1=buf,*p2=buf,obuf[1<<23],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
	if (x< 0) putchar('-'),x=-x;
	if (x>=10) print(x/10);
	putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
LL p[N];
void ins (LL a)
{
	for (int i=60; i>=0; i--)
		if ((a>>i)&1)
		{
			if (!p[i]) { p[i]=a; break; }
			else a^=p[i];
		}
}
LL query ()
{
	LL ans=0;
	for (int i=60; i>=0; i--)
		if (!((ans>>i)&1)&&p[i]) ans^=p[i];
	return ans;
}
LL a[N];
int main ()
{
	// freopen (".in","r",stdin);
	// freopen (".out","w",stdout);
	int n; sc(n);
	LL s=0;
	for (int i=1; i<=n; i++)
		sc(a[i]),s^=a[i];
	for (int i=0; i<=60; i++) if ((s>>i&1))
	{
		LL sb=1LL<<i;
		for (int j=1; j<=n; j++)
			if (a[j]>>i&1) a[j]-=sb;
	}
	for (int i=1; i<=n; i++)
		ins (a[i]);
	LL g=query ();
	pr((s^g)+g);
	return 0;
}


Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,a,b;
	cin>>n>>a>>b;
	ll pre=0,ans=0;
	rep(i,n){
		ll x;
		cin>>x;
		if(i==0){
			pre=x;
			continue;
		}
		ans+=min(b,(x-pre)*a);
		pre=x;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
/// Code By t_bone_289 (Tushar Singh)
/// An Immature Programmer.... I'm still developing !!
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pll pair<ll,ll>
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define endl '\n'
#define M 1000000007
#define error(x) cout << #x << " = " << x << endl;
#define pi 3.14159265358979323846
typedef long long ll;
typedef long double ld;
template <typename T>
void ContainerError(T &v){cout<<"{";for(auto &x:v){cout<<x<<',';}cout<<"}"<<endl;return;}
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
ll powmod(ll base,ll exp,ll MOD){ll res=1;while(exp>0){if(exp%2==1) res=(res*base)%MOD;base=(base*base)%MOD;exp/=2;}return (res%MOD);}
ll mpow(ll base,ll exp){ll res=1;while(exp>0){if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return (res);}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll> v(n+2,0);
    while(q--)
    {
        ll a;
        cin>>a;
        if(a==1)
        {
            v[2]--;
        }
        else if(a==n)
        {
            v[1]--;
            v[a]++;
        }
        else
        {
            v[1]--;
            v[a]++;
            v[a+1]--;
        }
    }
    for(ll i=1;i<=n;i++)
    {
        v[i] += v[i-1];
    }
    //  ContainerError(v);
    for(ll i=1;i<=n;i++)
    {
        if((k+v[i])>0)
        {
            cout<<"Yes\n";
        }
        else
        {
            cout<<"No\n";
        }
    }
    return 0;
}



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

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

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

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-10;
typedef long long ll;
typedef pair<int, int> pint;


int main()
{
	int n;
	while (scanf("%d", &n), n)
	{
		int x[3000], y[3000];
		for (int i = 0; i < n; ++i)
			scanf("%d%d", x + i, y + i);
		set<pint> memo;
		for (int i = 0; i < n; ++i)
			memo.insert(pint(x[i], y[i]));

		int res = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = i+1; j < n; ++j)
			{
				int vx = y[j]-y[i], vy = -(x[j]-x[i]);
#define ex(xx, yy) (memo.count(pint(xx, yy)) > 0)
				if (ex(x[i]+vx, y[i]+vy) && ex(x[j]+vx, y[j]+vy)
					|| ex(x[i]-vx, y[i]-vy) && ex(x[j]-vx, y[j]-vy))
				{
					int w = abs(vx), h = abs(vy);
					res = max(res, (w+h)*(w+h) - 2*w*h);
				}
			}
		}
		printf("%d\n", res);
	}
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

const ll MOD = 1000000007;

struct mint {
    ll x;
    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 {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t/2);
        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 {
        mint res(*this);
        return res /= a;
    }
};

ostream &operator<<(ostream &os, const mint &a) {
    return os << a.x;
}

int main() {
    ll N,K;
    cin >> N >> K;
    vec<ll> mn(N+2,0);
    vec<ll> mx(N+2,0);
    for(int k=1;k<=N+1;++k){
        mn[k] = mn[k-1] + k-1;
        mx[k] = mx[k-1] + N+1 - k;
    }
    
    mint ans = 0;
    for(int k=K;k<=N+1;++k){
        ans += (mx[k]-mn[k]+1);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6428
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD = 1000000007;
    int dp[5001][5001];
     signed main(){
         int n;string s;
         cin>>n>>s;
      fill(dp[0],dp[0]+n+1,0);
        dp[0][0]=1;
        for(int i=1;i<=n;i++)for(int j=0;j<=n;j++){
            dp[i][j]=0;
            if(j>0)dp[i][j]=dp[i-1][j-1];
            else dp[i][j]=dp[i-1][j];
            if(j<n)dp[i][j]=(dp[i][j]+dp[i-1][j+1]*2)%MOD;
        }
        cout<<dp[n][s.size()]<<endl;
        return 0;
        for(int i=0;i<=n;i++){
            for(int j=0;j<=n;j++){
                cerr<<dp[i][j]<<' ';
            }
            cerr<<endl;
        }
     }


 


 






    





      

        


Measured memory_bytes: 199000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int n;
  bool flag = true;
  cin >> n;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  rep(i,n-1) {
    if(h[i] < h[i+1]) {
      h[i+1]--;
    }
    if(h[i] > h[i+1]) {
      flag = false;
    }
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 640
N, M, K = map(int, input().split())

success = False
for x in range(M + 1):
    for y in range(N + 1):
        temp = (M - x) * y + (N - y) * x
        if temp == K:
            success = True

if success:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 40684
import sys

stdin = sys.stdin

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

n = ni()
a = nl()
print('YES' if len(set(a)) == len(a) else 'NO')


Measured memory_bytes: 25684
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int n = sc.nextInt();
            if (n == 0)
                break;
            int[] list=new int[n];
            int[] sum=new int[n+1];
            for(int i=0;i<n;i++) {
                list[i]=sc.nextInt();
                sum[i+1]=list[i];
            }
            sum[0]=0;
            for(int i=0;i<n;i++) {
                for(int j=i;j<n;j++) {
                    sum[j+1]=Math.max(sum[j]+list[j],sum[j+1]);
                }
            }
            int max=Integer.MIN_VALUE;
            sum[0]=max;
            for(int i:sum) {
                max=Math.max(max, i);
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 36748
N,M = map(int,input().split())
sts = [list(map(int, input().split())) for i in range(N)]
checkp = [[i+1]+list(map(int, input().split())) for i in range(M)]
rt = [None] * N
distances = [2*(10**8)] * N
for s in range(N):
  for c in checkp:
    dist = abs(sts[s][0]-c[1]) + abs(sts[s][1]-c[2])
    if rt[s] is None:
      rt[s] = c[0]
      distances[s] = dist
    else:
      if distances[s] > dist:
        rt[s] = c[0]
        distances[s] = dist
for i in rt:
  print(i)

Measured memory_bytes: 9056
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const int MAXN = 1234;
vector<int> G[MAXN];
bool visit[MAXN];
int dis[MAXN], from[MAXN];

int bfs(int x, int y) {
    memset(visit, 0, sizeof(visit));
    memset(dis, 0, sizeof(dis));
    queue<int> qu;
    dis[x] = 0;
    qu.push(x);
    while (!qu.empty()) {
          int tp = qu.front();
          qu.pop();
          visit[tp] = 1;
          if (tp == y) return dis[y];
          for (auto to : G[tp]) {
              if (!visit[to]) {
                 visit[to] = 1;
                 dis[to] = dis[tp] + 1;
                 from[to] = tp;
                 qu.push(to);
              }
          }
    }
    return MAXN;
}

int main() {
    int N, M;
    scanf("%d %d", &N, &M);
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        G[a].push_back(b);
    }
    int ans = MAXN, x = 0, y = 0;
    for (int i = 1; i <= N; i++) {
        for (int j : G[i]) {
            int cur_ans = bfs(j, i);
            if (cur_ans < ans) {
               ans = cur_ans;
               x = j, y = i;
            }
        }
    }
    if (ans == MAXN) puts("-1");
    else {
       memset(visit, 0, sizeof(visit));
       printf("%d\n", ans + 1);
       bfs(x, y);
       int cur = y;
       while (cur != x) {
             printf("%d\n", cur);
             cur = from[cur];
       }
       printf("%d\n", x);
    }
    return 0;
}


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

typedef signed long long ll;
typedef vector <int> vi; 
const int MX = 1e6 + 5;
int dis[MX];
vi G[MX];
ll h[MX];

ll solve(ll n) {
	if(n == 1LL) return 1LL;
	else {
		ll ans = solve(n / 2LL);
		return ans + 1;
	}
}

int main() {
	ll h;
	cin >> h;
	cout << (1LL << solve(h)) - 1 << endl;
    return 0;
}

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

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans1,ans2,ans3,ans4,ans;
  ans1 = a*c;
  ans2 = a*d;
  ans3 = b*c;
  ans4 = b*d;
  ans = max(ans1, ans2);
  ans = max(ans, ans3);
  ans = max(ans, ans4);
  cout << ans << endl;
  return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, Q;
    string S;
    vector<ll> ac;
    cin >> N >> Q;
    cin >> S;
    ac.resize(N);
    rep2(i, 1, N) {
        ac[i] = ac[i - 1];
        if(S[i - 1] == 'A' && S[i] == 'C') ac[i]++;
    }
    rep(i, Q) {
        ll l, r;
        cin >> l >> r;
        cout << ac[r - 1] - ac[l - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    edge = [[] for _ in range(n)]
    for _ in range(n - 1):
        a, b, c = ns()
        a -= 1
        b -= 1
        edge[a].append((b, c))
        edge[b].append((a, c))

    dist_table = [-1 for _ in range(n)]

    def dfs(node, dist):
        for t, cost in edge[node]:
            if dist_table[t] == -1:
                dist_table[t] = dist + cost
                dfs(t, dist_table[t])
        return

    q, k = ns()
    k -= 1
    dist_table[k] = 0
    dfs(k, 0)

    for _ in range(q):
        x, y = ns()
        print(dist_table[x - 1] + dist_table[y - 1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 152732
#include <iostream>
#include <queue>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	long long int a[100000];
	long long int b = 0;
	cin >> n;
	for(int i=0;i < n;i++)
	{
		cin >> a[i];
	}
	sort(a,a + n,greater<int>());
	for(int i=0;i < (n - 1);i++)
	{
		if(a[i] == a[i + 1])
		{
			if(b)
			{
				b*=a[i];
				cout << b << endl;
				return 0;
			}
			else
			{
				b = a[i];
				i++;
			}
		}
	}
	cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#define INF (1 << 28)

using namespace std;

int dp[1 << 16];

int main(void) {
	int N;
	while (cin >> N, N) {
		vector< vector<int> > t(N,vector<int>(N+1));
		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N+1; ++j) {
				cin >> t[i][j];
			}
		}
		for (int i = 1; i < (1 << N)+1; ++i) {
			dp[i] = INF;	
		}

		dp[0] = 0;
		for (int i = 0; i < (1 << N); ++i) {
			if (dp[i] < INF) {
				for (int j = 0; j < N; ++j) {
					if (!((i >> j)&1)) {
						dp[i+(1 << j)] = min(dp[i]+t[j][0],dp[i+(1 << j)]);
						for (int k = 0; k < N; ++k) {
							if ((i >> k)&1) {
								dp[i+(1 << j)] = min(dp[i]+t[j][k+1],dp[i+(1 << j)]);
							}
						}
					}
				}
			}
		}
		cout << dp[(1 << N)-1] << endl;
	}
	return 0;
}



Measured memory_bytes: 3372
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	ll n, m, i;
	ll tmpi;
	string tmps;
	ll sumac, sumwa;
	bool ac[100000];
	int wa[100000];

	cin >> n >> m;	
	
	sumac = sumwa = 0;
	for (i = 0; i < 100000; i++) {
		ac[i] = false;
		wa[i] = 0;
	}

	for (i = 0; i < m; i++) {
		cin >> tmpi >> tmps;
		if (ac[tmpi - 1])
			continue;
		else {
			if (tmps == "AC") 
				ac[tmpi - 1] = true;
			else 
				wa[tmpi - 1]++;
		}
	}
	for (i = 0; i < n; i++) {
		if (ac[i]) {
			sumac++;
			sumwa += wa[i];
		} 
	}
			

	cout << sumac << " " << sumwa << endl;
	
	return 0;
}


Measured memory_bytes: 768
n = int(input())
A = list(map(int,input().split()))
minus = 0
for a in A:
    if a < 0:
        minus += 1
absA = list(map(abs,A))
if minus%2 ==1:
    print(sum(absA)-min(absA)*2)
else:
    print(sum(absA))

Measured memory_bytes: 14224
#include <iostream>
#include <cstdio>
#include <map>
#include <algorithm>
#include <vector>

using namespace std;

int main()
{
    int n, m;
    
    while (1) {
        scanf("%d %d", &n, &m);
        if (!(n || m)) break;
        
        vector<pair<int, int> > scores(m, pair<int, int>(0, 0));
        
        for(int i = 0; i < n; ++i) {
            for(int j = 0; j < m; ++j) {
                int s; scanf("%d", &s);
                scores[j].first  -= s;
                scores[j].second =  j+1;
            }
        }
        
        sort(scores.begin(), scores.end());
        
        for(int i = 0; i < m; ++i) {
            cout << scores[i].second;
            if (i != m-1) {
                cout << " ";
            } else {
                cout << "\n";
            }
        }
    }
}

Measured memory_bytes: 1208
package main

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

func main() {
	H := readint()      // モンスターの体力
	N := readint()      // トキが使える魔法の種類
	A := make([]int, N) // 魔法攻撃力
	B := make([]int, N) // 消費魔力
	for i := 0; i < N; i++ {
		A[i] = readint()
		B[i] = readint()
	}

	// 残体力ごとにどの魔法を使うのがベストかを、残体力が小さい順に
	// 計算していって、今回のモンスターの体力だとどうなるかを求める

	// dp[体力] = 消費魔力の最小値
	// dp初期化(dp[0]=0、dp[1..]=MaxInt32)
	dp := make([]int, H+1)
	for i := 0; i < H; i++ {
		dp[i+1] = math.MaxInt32
	}

	// HN<=10^7なので全回しでも行ける
	for i := 0; i < N; i++ { // 魔法の種類分繰り返す
		for j := 1; j <= H; j++ { // 残り体力の取りうるパターン分繰り返す

			// 魔法攻撃後のモンスター残り体力(remaining hitpoint)
			rh := max(j-A[i], 0)

			// 攻撃後の残り体力を0にするのに要する最小魔力が未計算の場合
			// 一旦すっ飛ばす
			if dp[rh] == math.MaxInt32 {
				continue
			}

			// 攻撃時に消費した魔力　＋　攻撃後の残り体力を0にするのに要する最小魔力　が
			// 攻撃前の体力を0にするのに要する最小魔力（現行値）よりも小さい場合
			if B[i]+dp[rh] < dp[j] {
				// 攻撃前の体力を0にするのに要する最小魔力（現行値）を更新する
				dp[j] = B[i] + dp[rh]
			}
		}
	}
	fmt.Println(dp[H])
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func permutation(n int, k int) int {
	v := 1
	if 0 < k && k <= n {
		for i := 0; i < k; i++ {
			v *= (n - i)
		}
	} else if k > n {
		v = 0
	}
	return v
}

func factorial(n int) int {
	return permutation(n, n-1)
}

func combination(n int, k int) int {
	return permutation(n, k) / factorial(k)
}


Measured memory_bytes: 768
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <sstream>
#include <deque>

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

using namespace std;

int main() {
    int n;
    
    vector<int> open(30);
    open[0] = 1;
    open[1] = 2;
    open[2] = 4;

    for ( int i = 3; i < 30; i++ ) {
        open[i] = open[i-1] + open[i-2] + open[i-3];
        // cout << i << ":" << open[i] << endl;
    }

    while(cin >>n, n) {
        n -= 1; // 添字に合わせる

        cout << (open[n]/10/365)+1 << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1192
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	int N, M; cin >> N >> M;
	vector<map<int, long long int>>mps(N);
	while (1) {
		int s, t, e; cin >> s >> t >> e;
		if (!s)break;
		s--; t--;
		mps[s][t] += e;
	}
	int L; cin >> L;
	for (int i = 0; i < L; ++i) {
		vector<long long int>moneys;
		for (int j = 0; j < M; ++j) {
			int a; cin >> a;
			moneys.push_back(a);
		}
		for (int i = 0; i < N; ++i) {
			long long int salary = 0;
			for (auto w : mps[i]) {
				salary += moneys[w.first] * w.second;
			}
			cout << salary;
			if (i != N - 1)cout << " ";
			else cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 6780
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

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


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

using namespace std;
int main(){
	string a;
	cin>>a;
	char b = a.back();
	if(b =='2' || b == '4' || b == '5' || b == '7' || b=='9')
		cout<<"hon"<<endl;
	else if(b == '0' || b == '1' || b == '6' || b == '8')
		cout<<"pon"<<endl;
	else
	cout<<"bon"<<endl;
    return 0;
}


Measured memory_bytes: 3608
// https://atcoder.jp/contests/code-festival-2017-qualc/tasks/code_festival_2017_qualc_c
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define REP(i, n) for(size_t i = 0; i < (n); ++i)

int main()
{
    string s;
    cin >> s;
    deque<char> sdq;
    REP(i, s.size())
    {
        sdq.push_back(s[i]);
    }
    int ans = 0;
    // s が最終的に回文になる場合、
    // 先頭文字と末尾文字を削除しても回文となるので、
    // s の先頭文字と末尾文字に着目し、削除と挿入を行う
    while (!sdq.empty())
    {
        if (sdq.front() == sdq.back())
        {
            if (sdq.size() == 1) break;
            sdq.pop_front();
            sdq.pop_back();
        }
        else if (sdq.front() == 'x')
        {
            sdq.push_back('x');
            ++ans;
        }
        else if (sdq.back() == 'x')
        {
            sdq.push_front('x');
            ++ans;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }

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


Measured memory_bytes: 3828
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;

int n, s;

int cal(int a, int b, int c)
{


	if (a == 1 && b >= c && b < 10)
	{
		return 1;
	}
	if (a == 1)
	{
		return 0;
	}
	int hoge = 0;


	for (int i = c; i < 10 && i < b; i++)
	{
		hoge += cal(a - 1, b - i, i + 1);
	}

	return hoge;


}

int main(void)
{
	while (cin >> n >> s,1)
	{
		if (n==0&&s==0)
		{
			break;
		}

		cout << cal(n, s, 0) << endl;
	}

	return 0;
}




Measured memory_bytes: 2964
N, x = map(int, input().split())
if x == 1 or x == 2 * N - 1:
    print('No')
    exit()
if N == 2:
    print('Yes')
    for i in [1, 2, 3]:
        print(i)
    exit()


ans = [0] * (2 * N - 1)
ans[N - 2], ans[N - 1], ans[N] = x - 1, x, x + 1
d = 1
for i in range(2 * N - 1):
    if i in [N - 2, N - 1, N]:
        continue
    if d == x - 1:
        d = x + 2
    ans[i] = d
    d += 1

print('Yes')
for i in ans:
    print(i)

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

public class Main {

	static int n,y;
	static Bank bank[];
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N = cin.nextInt();
			if(N==0){
				break;
			}
			int y =cin.nextInt();
			bank=new Bank[N];
			for(int i = 0;i<N;i++){
				int a = cin.nextInt();
				double b = cin.nextDouble();
				int t = cin.nextInt();
				bank[i]=new Bank(a,b,t);
				bank[i].calc(y);
				//System.out.println(bank[i].money);
				
			}
			Arrays.sort(bank);
			System.out.println(bank[bank.length-1].b);
		}
		
	}

}
class Bank implements Comparable{
	double money;
	int b;
	double r;
	int type;
	public int compareTo(Object o){
		Bank b = (Bank)o;
		if(this.money>b.money){
			return 1;
		}
		else if(this.money==b.money){
			return 0;
		}
		else{
			return -1;
		}
	}
	Bank(int a,double d,int x){
		b=a;
		r=d;
		type=x;
	}
	void calc(int year){
		money=1;
		if(type==2){
			money = money*Math.pow((1.0+r/100),year);
		}
		else{
			money= money*(1.0+year*(r/100));
		}
	}
}

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

using namespace std;

int n;
int a[100001],b[100001],c[100001];
long long x[100001],y[100001],z[100001];


int main(){
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i] >> b[i] >> c[i];
	}
	x[1]=a[1];
	y[1]=b[1];
	z[1]=c[1];
	for (int i = 2; i <= n; i++)
	{
		x[i] = a[i] + max(y[i-1],z[i-1]);
		y[i] = b[i] + max(x[i-1],z[i-1]);
		z[i] = c[i] + max(x[i-1],y[i-1]);
	}
	cout  << max(max(x[n],y[n]),z[n]);
	return 0;
}


Measured memory_bytes: 3712
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    public static void Main()
    {
        int N = NextInt();
        int M = NextInt();
        int Q = NextInt();
        int[,] data = new int[N + 1, N + 1];

        for (int i = 0; i < M; i++)
        {
            int L = NextInt();
            int R = NextInt();
            data[L, R] += 1;
        }

        for (int i = 0; i <= N; i++)
            for (int j = 1; j <= N; j++)
                data[i, j] += data[i, j - 1];
        for (int i = 0; i <= N; i++)
            for (int j = N - 1; j > 0; j--)
                data[j, i] += data[j + 1, i];


        for (int i = 0; i < Q; i++)
        {
            int p = NextInt();
            int q = NextInt();
            Console.WriteLine(data[p, q]);
        }
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

Measured memory_bytes: 17584
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();

        if (n >= 3200) {
            System.out.println(s);
        } else {
            System.out.print("red");
        }
    }

}


Measured memory_bytes: 21844
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    int N;
    int[] A;
    private void Scan()
    {
        N = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    public void Solve()
    {
        Scan();
        Console.WriteLine(A.Max() - A.Min());
    }
}


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

int main() {
    int n;
    int *count = calloc(4,sizeof(int));
    scanf("%d",&n);
    char str[n][3];
    for (int i=0;i<n;i++) {
        scanf("%s",str[i]);
        if ( strcmp(str[i],"AC") == 0 )
           count[0]++;
        else if ( strcmp(str[i],"WA") == 0 )
           count[1]++;
        else if ( strcmp(str[i],"TLE") == 0 )
           count[2]++;
        else if ( strcmp(str[i],"RE") == 0 )    
           count[3]++;
    }
    printf("%s x %d\n%s x %d\n%s x %d\n%s x %d\n","AC",count[0],"WA",count[1],"TLE",count[2],"RE",count[3]);
    return 0;
}

Measured memory_bytes: 2020
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);

        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();
        int d = scan.nextInt();
        int ans=1;
        if(a==c){ans=0;}
        System.out.println(ans);
    }
}


Measured memory_bytes: 22612
import math
N, K = map(int, input().split())
A = list(map(int, input().split()))
'''
one_idx = A.index(1)
before = math.ceil(one_idx / (K - 1))
after = math.ceil((N - one_idx - 1) / (K - 1))
'''
print(math.ceil((N - 1) / (K - 1)))

Measured memory_bytes: 13812
#include <stdio.h>

int main(void)
{
        char n[2];
        scanf("%s",n);
        int i=0,x=0;
        for(i;i <= 1;i++)
                {
                if(n[i] == '9')
                {x=1;}
                }
        if(x == 1)
                {printf("Yes\n");}
        else
                {printf("No\n");}
        return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define i_love_u_Phuong ios_base::sync_with_stdio(0); cin.tie(0);
using ll = long long;
using namespace std;
using ld = long double;
typedef pair<int,int> ii;


int main()
{
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
#endif // ONLINE_JUDGE
    i_love_u_Phuong;
    int n;
    cin >> n;
    priority_queue<ld , vector<ld> , greater<ld>> pq;
    for(int i=0; i<n ; ++i)
        {
            ld k;
            cin >> k;
            pq.push(k);
        }
    while (pq.size()>1)
    {
        ld u = pq.top();
        pq.pop();
        ld v =pq.top();
        pq.pop();
        u+=v;
        u/=2;
        pq.push(u);
    }
    cout << setprecision(10) << fixed << pq.top();
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
	string a, b;
	int n;
	cin >> n;
	cin >> a >> b;
	int len = a.length();
	for (int i = 0; i < len; i++) {
		cout << a[i] << b[i];
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<tuple>
#include<numeric>
#include<map>
#include<cmath>
#define ll long long
#define rep(i,n) for(int i=0;i<(int) (n);i++)
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  swap(a,b);
  swap(a,c);
  cout<<a<<" "<<b<<" "<<c;

  return 0;
}


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

const int INF=1e9;
const ll INFF=1e17;
const double EPS=1e-9;
const ll MOD=1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k,sum=0;
	vector<int> a(100);
	cin >> n >> k;
	REP(i,n)cin >> a[i];
	sort(a.begin(),a.begin()+n);
	reverse(a.begin(),a.begin()+n);
	REP(i,k)sum+=a[i];
	cout << sum << '\n';
	return 0;
}


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

char c[55][55]; int H, W, cnt;

int main(){
    cin >> H >> W;
    for(int i = 1; i <= H; i++) {
        for(int j = 1; j <= W; j++) cin >> c[i][j];
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(c[i][j] == '#' && c[i][j - 1] != '#' && c[i -1][j] != '#' && c[i][j +1] != '#' && c[i +1][j] !='#') cnt++;
        }
    }
    if(cnt == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    
}


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

#define ll long long

using namespace std;

const int maxn = 1e7 + 5;

int n;
bool prime[maxn];
int d[maxn];

void sieve()
{
	for(int i = 2; i <= n; i++){
		if(prime[i]) continue;

		for(int j = i + i; j <= n; j += i) prime[j] = 1, d[j] = i;

		d[i] = i;
	}
}

ll prime_fact(int x)
{
    //cout << x << ' ';

	ll ans = 1;

	while(x != 1){
		int dd = d[x], cnt = 1;

		while(x % dd == 0) cnt++, x /= dd;

		ans *= cnt;
	}

	//cout << ans << endl;

	return ans;
}

int main()
{
//	#ifndef ONLINE_JUDGE
//		freopen("input.txt", "r", stdin);
//		freopen("output.txt", "w", stdout);
//	#endif

	cin >> n;

	sieve();

	//cout << prime_fact(4) << endl;

	ll ans = 1;

	for(int i = 2; i <= n; i++){
		if(prime[i] == 0) ans += (i * 2LL);
		else ans += (i * prime_fact(i));
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 52432
import sys

ri = lambda: int(sys.stdin.readline())
rl = lambda: list(map(int, sys.stdin.readline().split()))
mod = 10**9 + 7

n = ri()
a = rl()
s = sum(a)
ans = 0
for i in a:
    s -= i
    ans = (ans + s*i)%mod
print(ans)

Measured memory_bytes: 92068
#include <iostream>
#include <vector>
#include <map>
#include <tuple>
using namespace std;


int main(){

    int N;
    long K;

    cin >> N >> K;

    vector<int> A(N+1,0);
    vector<long> past(N+1,-1);
    //map<int, long> past{};

    for(int i=1;i<=N;i++){
        cin >> A[i];
    }
    int tmp = 1;
    long warp;
    past[tmp] = 0;
    long warped = 0;

    for(long i=1;i<=K;i++){
        tmp = A[tmp];

        if(past[tmp]>0){
            warp = (K-i)/(i-past[tmp]-warped)*(i-past[tmp]-warped);
            i += warp;
            warped += warp;
        }else{
            past[tmp]=i;
        }
    }
    cout << tmp << endl;

    return 0;
}


Measured memory_bytes: 5636