akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

using namespace std;
using LL = long long;

constexpr int N = 1e5 + 5;

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

    int n, t, a;
    cin >> n >> t >> a;

    double diff = 1e9;
    int ans = -1;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        double avg = t - x * 6.0 / 1000;
        if (diff > fabs(a - avg)) {
            diff = fabs(a - avg);
            ans = i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
    ll dp[3010][3010][4];
    //(i,j)まで見て、j行目のアイテムをk個持った時の最大値
    ll value[3010][3010];
int main(){
    ll r, c, k;
    cin >> r >> c >> k;
    vector<ll> x(k), y(k), v(k);
    for (ll i = 0; i < k; i++) cin >> x[i] >> y[i] >> v[i];

    for (ll i = 0; i < 3010;i++){
        for (ll j = 0; j < 3010;j++){
            value[i][j] = 0;
        }
    }
    for (ll i = 0; i < k;i++){
            value[x[i]][y[i]] = v[i];
    }
    for (ll i = 0; i < 3010;i++){
        for (ll j = 0; j < 3010;j++){
            for (ll k = 0; k < 4;k++){
                dp[i][j][k] = 0;
            }
        }
    }
    for (ll i = 0; i < r+1;i++){
        for (ll j = 0; j < c+1;j++){
            for (ll k = 0; k < 4;k++){
                //上
                if(i>0){
                    chmax(dp[i][j][0], dp[i-1][j][k]);
                    chmax(dp[i][j][1], dp[i-1][j][k] + value[i][j]);
                }
                //右
                if(j>0){
                    chmax(dp[i][j][k], dp[i][j-1][k]);
                    if (k > 0) chmax(dp[i][j][k], dp[i][j-1][k - 1] + value[i][j]);
                }
            }
        }
    }

    ll res=0;
    for (ll i = 0; i < 4; i++) chmax(res, dp[r][c][i]);
    cout << res << endl;
}

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

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

  vector<int> d(n);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }

  int ans = 0;
  for (int i = 0; i < n - 1; i++) {
    for (int j = i + 1; j < n; j++) {
      ans += (d[i] * d[j]);
    }
  }

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

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

#define INF 1e+9

struct Edge{
	  int s,t,w;
	  Edge(int si, int ti, int wi){
			s = si; t = ti; w = wi;
	  }
	  bool operator > (const Edge& e) const {
			return w > e.w;
	  }

};
typedef vector<vector<Edge> > AdjList;

struct state{
	  int v, w;
	  state(int vi, int wi){ v = vi; w = wi; }
	  bool operator > (const state& tgt) const {
			return w > tgt.w;
	  }
};

vector<int> dijk(int s, AdjList& G){
	  priority_queue<state,vector<state>, greater<state> > q;
	  vector<int> used(G.size(),INF);

	  q.push( state(s,0) );
	  while( q.size() ) {
			state corr = q.top(); q.pop();
			if(used[corr.v] != INF) continue;

			used[corr.v] = corr.w;
			// if(used[t] != -1) break;

			for(Edge e : G[corr.v]){
				  if(used[e.t] == INF)
						q.push( state(e.t, corr.w + e.w) );
			}
	  }
	  return used;

}

int main(){

	  int V,E,r; cin >> V >> E >> r;
	  
	  AdjList G(V);
	  for(int i=0; i<E; i++){
			int s,t,d; cin >> s >> t >> d;
			G[s].push_back(Edge(s,t,d));
	  }
	  vector<int> stlen = dijk(r,G);
	  for(int i=0; i<V; i++)
			if(stlen[i] != INF)
				  cout << stlen[i] << endl;
			else
				  cout << "INF" << endl;
			

}

Measured memory_bytes: 16500
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

S = gets.chomp

count = S.split('').count { |x| x == 'o' }

puts 700 + 100 * count


Measured memory_bytes: 14392
s = input()
s = int(s)
if s == 23:
    print("25")
elif s == 22:
    print("26")
elif s == 21:
    print("27")
elif s == 20:
     print("28")
elif s == 19:
     print("29")
elif s == 18:
     print("30")
elif s == 17:
     print("31")
elif s == 16:
     print("32")
elif s == 15:
     print("33")
elif s == 14:
     print("34")
elif s == 13:
     print("35")
elif s == 12:
     print("36")
elif s == 11:
     print("37")
elif s == 10:
     print("38")
elif s == 9:
     print("39")
elif s == 8:
     print("40")
elif s == 7:
     print("41")
elif s == 6:
     print("42")
elif s == 5:
     print("43")
elif s == 4:
     print("44")
elif s == 3:
     print("45")
elif s == 2:
     print("46")
else:
     print("47")

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

void solve(const int& n, const vector<int>& v) {
    double minH = 1e25;
    int bs, ba, bc;
    for (int s = 0; s <= 15; ++s) {
        for (int a = 0; a <= 15; ++a) {
            for (int c = 0; c <= 15; ++c) {
                int occ[256];
                fill(occ, occ + 256, 0);

                int r = s;
                for(int j = 0; j < n; ++j) {
                    r = (a * r + c) % 256;
                    ++occ[(r + v[j]) % 256];
                }

                double h = 0;
                for(int j = 0; j < 256; ++j) {
                    if(occ[j] != 0) {
                        h += -log((double)occ[j] / n) * occ[j] / n;
                    }
                }

                if(h + 1e-9 < minH) {
                    minH = h;
                    bs = s;
                    ba = a;
                    bc = c;
                }
            }
        }
    }

    cout << bs << ' ' << ba << ' ' << bc << endl;
}

int main() {
    int n;
    vector<int> a;
    while (true) {
        cin >> n;
        if(n == 0) break;
        a.resize(n);

        for (int i = 0; i < n; ++i) {
            cin >> a[i];
        }
        solve(n, a);
    }
    return 0;
}

Measured memory_bytes: 1256
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
using namespace std;
int A,B,C,now,chk;
int main(void)
{
    scanf("%d %d %d",&A,&B,&C);
    if((A+B)>=C) chk = 1;
    if(chk) printf("Yes");
    else printf("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <deque>

using ll = long long;
using namespace std;

int main() {
    string s;
    int prev;
    cin >> s;
    ll ans = stoll(s);
    int n = s.size()-1;
    for (int i = 0; i < (1 << n); ++i) {
        deque<int> S;
        prev = 0;
        for (int j = 0; j < n; ++j) {
            if (i & (1<<j)) S.emplace_back(j);
        }
        bool a = S.empty();
        while(!S.empty()) {
            int k = S.front(); S.pop_front();
            ans += stoll(s.substr(prev, k - prev + 1));
            prev = k+1;
        }
        if((prev != n+1) && !a){
            ans += stoll(s.substr(prev, n - prev + 2));
        }

    }
    cout << ans << "\n";

    return 0;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R PI = acos(-1.0L);
using P = complex<R>;

// Problem Specific Parameter:

int n;
int x[110], y[110];
R ans[110];

const R inf = 1e13;

inline R dist(int i, P q) {
	P p = P(x[i], y[i]);
	return norm(p - q);
}

int main(void) {
	const int limit = 400000;
	cin >> n;
	rep(i, n) cin >> x[i] >> y[i];

	rep(i, limit) {
		const R cur = 2.0 * PI / limit * i;
		P point = polar(inf, cur);

		R d = dist(0, point);
		int idx = 0;
		rep(j, n) if (chmin(d, dist(j, point))) idx = j;
		ans[idx] += 1.0;
	}

	cout.precision(20);
	rep(i, n) cout << fixed << 1.0 * ans[i] / limit << endl;

	return 0;
}


Measured memory_bytes: 256
#include <math.h>
#include <stdio.h>

#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int main() {
    const float t = 100000000;
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double res;

    res = (sqrt(pow(((x2 - x1)), 2) + pow(((y2 - y1)), 2)));

    printf("%.5f\n", res);
    return 0;
}


Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int64_t X, Y;
	cin >> X >> Y;

	int64_t cnt = 0;
	while (X <= Y) {
		cnt++;
		X *= 2;
	}

	cout << cnt << endl;
}

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

int main(){
    int N, A, B;
    cin >> N >> A >> B;
    int ans = 0;
    int a;
    for(int i = 1; i <= N; i++){
        a = (i / 10000) + ((i / 1000) % 10) + ((i / 100) % 10) + ((i / 10) % 10) + (i % 10);
        if(A <= a && a <= B){
            ans += i;
        }
    }
    cout << ans << endl;
}

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

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;//testcases
    cin>>n;
    long long sum =0;
    for(int i=1;i<=n;i++){
		bool fizzbuzz = i%3==0 && i%5==0;
		bool fizz = (!fizzbuzz && i%3==0);
		bool buzz = (!fizzbuzz && !fizz && i%5==0);
		if(!fizzbuzz && !fizz &&!buzz){
			sum+=i;
		}
	}
	cout << sum;
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
using namespace std;
const int N = 1e5 + 6 ;
int main()
{
    ll n , k ;
    cin >> n >> k ;
    if(k == 0){
        cout << n * n << endl ;
        return 0 ;
    }
    ll ans = 0 ;
    for (ll i = k + 1; i <= n; i++)
    {
        ans += (n / i) * (i - k);
        if (n % i >= k)
            ans += n % i - k + 1;
    }
   cout << ans << endl ;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
   int a,b;
   scanf("%d%d",&a,&b);
   if(a+b==15){
    printf("+\n");
   }
   else if(a*b==15){
    printf("*\n");
    }
    else{
    printf("x\n");
    }

    return 0;
}


Measured memory_bytes: 128
N = int(input())
abc = [list(map(int,input().split())) for _ in range(N)]

dp = [row for row in abc]
for i in range(1,N):
    for a in range(3):
        dp[i][a] = abc[i][a] + max(dp[i-1][:a]+dp[i-1][a+1:])
print(max(dp[-1]))

Measured memory_bytes: 31512
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const string YES = "YES";
const string NO = "NO";

struct UnionFind {
  vector< int > data;
 
  UnionFind(int sz) {
    data.assign(sz, -1);
  }
 
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return (false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }
 
  int find(int k) {
    if(data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }
 
  int size(int k) {
    return (-data[find(k)]);
  }
};


void solve(){
    int n,m;cin>>n>>m;
    UnionFind uf(n+m);
    set<int> s;
    rep(i,n){
        int k;cin>>k;
        rep(j,k){
            int l;cin>>l;l--;
            uf.unite(i,n+l);
            s.insert(l);
        }
    }
    cout<<(uf.size(0)==n+s.size()?YES:NO)<<endl;
}

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


Measured memory_bytes: 3584
// O - Matching --> Atcoder Educational Contest, Question Link-=>
// https://atcoder.jp/contests/dp/tasks/dp_o
// To find pairs of N men and N women-> for a given N and their Compatibility matrix

// IMPORTANT NOTE ->  Whenever in a question N is near to 21 (MAX_Value)...it would
// use Bit Masking

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

int n,mod =1e9+7;
// 2 to power n ==> 2^n ==> is 100000..00 with 1 at nth position
// from right so ...its 1 left shifted n times.... (1<<n)
long long dp[22][1<<21];
int a[21][21];

long long addself(long long a,long long b)
{
    if(a+b >= mod)
        return a+b-mod;
    return a+b;
}

long long calcpairs(int index,int prevmask)
{
    if(index==n)
        return (prevmask == (1<<n) -1);

    if(dp[index][prevmask]!=-1)
        return dp[index][prevmask];

    long long ans=0;    
    for(int i=0;i<n;i++)
    {
        if(a[index][i]==1 && !(prevmask & (1<<i)))
        {        
            ans= addself(ans, calcpairs(index+1,(prevmask + (1<<i))));
        }
    }
    return dp[index][prevmask]=ans;
}

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

    int i,j;
    cin>>n;
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            cin>>a[i][j];
        }
    }
    memset(dp,-1,sizeof(dp));

    long long res=calcpairs(0,0);

    

    cout<<res<<endl;
}

Measured memory_bytes: 360704
#include<stdio.h>
int main(void)
{
	int a,b,x,y;
	scanf("%d %d",&a,&b);
	x=a*b;
	y=x%2;
	if(y==0){
		printf("Even\n");
	}
	else{
		printf("Odd\n");
	}
	return 0;
}

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

using namespace std;

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

	string s;
	int k;
	cin >> s >> k;
	vector<string> str;
	set<string> se;
	int len = s.length();
	for(int i = 0; i < len; i++)
		for(int j = 1; len > i + j - 1 && j<6; j++)
		{
			if(se.count(s.substr(i, j)) == 0)
			{
				str.push_back(s.substr(i, j));
				se.insert(s.substr(i, j));
			}
		}
	sort(str.begin(), str.end());;
	cout << str[k - 1] << endl;

	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>

int n,A[100000];
int k,B[100000];

int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>=n){
    return 0;
  }
  res=solve(i+1,m)||solve(i+1,m-A[i]);
  return res;
}

int main(){
  int i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %d",&A[i]);
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&B[i]);
  }

  for(i=0;i<k;i++){
    if(solve(0,B[i])){
      printf("yes\n");
    }
    else{
      printf("no\n");
    }

  }
  return 0;
}



Measured memory_bytes: 2104
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

string S,T;
inline void solve(){
  IN2(S,T);
  reverse(ALL(T));
  OUT(S==T?"YES":"NO");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>
#include <queue>
#include <algorithm>

using namespace std;
using edge_set = unordered_set<int>;

int main() {

    int V, E;
    cin >> V >> E;

    int count = 0;
    pair<int, int> order[V];
    edge_set indeg[V], outdeg[V];

    for (int i = 0; i < V; i++) {
        order[i].second = i;
    }

    for (int i = 0; i < E; i++) {
        int s, t;
        cin >> s >> t;
        indeg[t].insert(s);
        outdeg[s].insert(t);
    }

    queue<int> que;

    for (int i = 0; i < V; i++) {
        if (indeg[i].empty()) {
            que.push(i);
        }
    }

    while (!que.empty()) {
        int u = que.front();
        que.pop();
        for (int v : outdeg[u]) {
            indeg[v].erase(u);
            if (indeg[v].empty()) {
                que.push(v);
            }
        }
        order[u].first = ++count;
    }

    //count < |V| なら閉路がある

    sort(order, order + V);

    for (int i = 0; i < V; i++) {
        cout << order[i].second << endl;
    }
}


Measured memory_bytes: 8280
# encoding:utf-8
def main():
	n = int(input())
	nums = list(map(int, input().split()))

	counter = 0
	for i in range(n - 1):
		if nums[i] == i + 1:
			nums[i], nums[i + 1] = nums[i + 1], nums[i]
			counter += 1

	if nums[n - 1] == n:
		counter += 1

	print(counter)

if __name__ == '__main__':
	main()

Measured memory_bytes: 14008
n,t = map(int,input().split())
st = list(map(int,input().split()))

st += [10**10]
t1 = 0
t2 = 0
ans = 0
for ti in st:
  if t2 < ti:
    ans += t2-t1
    t1 = ti
  t2 = ti+t
print(ans)

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

const ll MOD = 2019;

int main(){
  string s;cin >> s;
  reverse(s.begin(),s.end());
  ll n = s.size();

  vector<ll> cnt(MOD,0);
  ll total = 0;
  ll x = 1;
  ll ans = 0;
  rep(i,n){
    cnt.at(total)++;
    total += (s.at(i)-'0')*x;
    total %= MOD;
    x = x*10%MOD;
    ans += cnt.at(total);
  }
  cout << ans << endl;
  return 0;
}


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

vector<bool> seen;

int dfs(vector<vector<int>> &G, int i, int fn){
  seen[i] = true;
  fn += 1;
  for(auto v : G[i]){
    if(seen[v]) continue;
    fn = dfs(G,v,fn);
  }
  return fn;
}

int main(){
  int N,M;
  cin >> N >> M;
  vector<vector<int>> G(N);
  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    G[a-1].push_back(b-1);
    G[b-1].push_back(a-1);
  }
  seen.assign(N,false);
  int m = 0;
  for(int i = 0; i < N; i++){
    if(!seen[i]){
      m = max(m,dfs(G,i,0));
    }
  }
  cout << m << endl;
}


Measured memory_bytes: 23436
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define rep(i,n) for(int i = 0; i < (int)(n);i++)
typedef long long ll;
using namespace std;
int main() {
	int n, k;
	cin >> n >> k;
	int a[100000];
	rep(i, n) {
		cin >> a[i];
	}
	if ((n - 1) % (k - 1) == 0) {
		cout << (n - 1) / (k - 1) << endl;
	}
	else {
		cout << (n - 1) / (k - 1) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector

#define vvec(s) vector<vector
>
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Yes(x) cout<<(x?"Yes":"No")<<endl;
#define YES(x) cout<<(x?"YES":"NO")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " " 
#define INF 10000000000
#define LINF 9000000000000000000
#define all(s) s.begin(),s.end()
void vout(vi v){
    for(lli i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    cout << std::fixed << std::setprecision(10);
    lli n;
    map<lli, lli> ans;
    cin>>n;
    rep(i,n){
        lli a;
        cin>>a;
        ans[a]=i+1;
    }
    for(auto v:ans){ 
        cout<<v.second<<sp;
    }
}

Measured memory_bytes: 9784
#include<iostream>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
string S, T, U; queue<pair<string, int>>Q;
set<string>E;
int solve(string P, int n) {
	while (!Q.empty())Q.pop(); Q.push(make_pair(P, 0)); int CNT = 0; int maxn = 10;
	while (!Q.empty()) {
		string V = Q.front().first; int Z = Q.front().second; Q.pop(); int to = -1;
		for (int j = 0; j < n; j++)if (V[j] != '0') { to = j; break; }
		long long H = stoll(V);
		if (to == -1) { return Z; }
		int Y = (V[to] - '0'); int en = n - 1; CNT++;
		for (int j = to; j < n; j++)if (V[j] != V[to]) { en = j - 1; break; }

		for (int j = en; j < n; j++) {
			string W = V; int Y = (W[to] - '0');
			for (int k = to; k <= j; k++) {
				W[k] -= Y; if (W[k] < '0')W[k] += 10;
			}
			if (E.find(W) == E.end()) {
				Q.push(make_pair(W, Z + 1)); E.insert(W);
			}
		}
	}
}
int main() {
	while (true) {
		int n; cin >> n; E.clear(); if (n == 0)break; cin >> S >> T; U = "";
		for (int i = 0; i < n; i++) {
			int sa = T[i] - S[i]; if (sa < 0)sa += 10;
			U += (char)('0' + sa);
		}
		cout << solve(U, n) << endl;
	}
	return 0;
}

Measured memory_bytes: 4424
import java.util.*;
import java.util.Scanner;

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

        int N = sc.nextInt();
        int res = -1;

        for (int i = 111; i < 1000; i += 111) {
            if (i >= N) {
                res = i;
                break;
            }
        }

        System.out.println(res);
    }
}

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

using namespace std;

typedef long long ll;

ll n, b[200005];
pair <ll, ll> a[200005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin >> n;
    memset(b, 0, sizeof(b));
    for (ll i = 1; i < n; i++)
    {
        cin >> a[i].first;
        b[a[i].first]++;
        a[i].second = i;
    }
    for (ll i = 1; i <= n; i++)
    {
        cout << b[i] << endl;
    }
}

Measured memory_bytes: 8344
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int main(){
    int q; cin>>q;
    FOR(i,0,q){
        ll a,b; cin>>a>>b;
        ll k=sqrtl(a*b-1);
        ll ans=2*k-1;
        if(k*(k+1)>a*b-1) ans--;
        if(a==b) ans++;
        co(ans);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

typedef pair<ll,ll> P;

int main(){
  ll n, c; cin >> n >> c;
  //xr[i] =  原点から右へ歩き，i個取ったときに移動した距離
  //xl[i] =  原点から左へ歩き，i個取ったときに移動した距離
  //vsum[i] = v[1] + ... + v[i]
  //vr[i] =  vsum[i] - xr[i] 原点から右へ歩きi個とったときの実質スコア
  //vl[i] =  vsum[n]-vsum[n-i]-xl[i] 原点から左へ歩きi個とったときの実質スコア
  vector<ll> xr(n+2,0), xl(n+2,0), vsum(n+1,0), vr(n+2,0), vl(n+2,0);
  xr[n+1] = c; xl[n+1] = c; 
  REP(i,n) {
    ll v; cin >> xr[i+1] >> v;
    vsum[i+1] = vsum[i] + v;
    vr[i+1] = vsum[i+1] - xr[i+1];
  }
  REP(i,n){
    xl[i+1] = c - xr[n-i];
    vl[i+1] = vsum[n]-vsum[n-i-1]-xl[i+1];
  }
  
  ll ans = 0;
  set<P> stl, str;
  stl.insert(make_pair(0,0)); //左で往復
  str.insert(make_pair(0,0)); //右で往復
  IREP(l,n+1){
    ll e = 0;
    //左からl個とる
    e += vl[l];
    // i) 左で往復する場合
    e -= xl[l];
    // 右からとる
    auto it = prev(stl.end());
    e += it->first;
    ans = max(ans,e);
    // setに候補追加
    ll idx = n-l+1;
    stl.insert(make_pair(vr[idx],idx));

    // ii) 右で往復する場合
    //左からとる
    e = vl[l];
    //右からとる
    it = prev(str.end());
    e += it->first;
    ans = max(ans,e);
    //lが1個減るので，setに候補を追加
    str.insert(make_pair(vr[idx]-xr[idx],idx));
  } 
  cout << ans << endl;
}


Measured memory_bytes: 16640
#include<bits/stdc++.h>                                                   //---------------------------------------------------------------
                                                                    
# define ll long long   
# define ld long double                                               
# define mod 1000000007                                                   
# define MAX 100005
# define pi 3.141592653589793238                                                                                  //shortcut keys
                                                                                
# define pb push_back                                                                     
# define mp make_pair 
# define all(x) x.begin(),x.end()                                                      
                                                                  
# define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);        //---------------------------------------------------------------                                       
using namespace std;
int main()
{
    int n;
    cin>>n;
    int dp[n+1]={};
    for(int i=2;i<=n;i++){
    	int x;
    	cin>>x;
    	dp[x]++;
	}
	for(int i=1;i<=n;i++){
		cout<<dp[i]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 4356
def main():
    s = input()
    MOD = 2019
    r = [0]*MOD
    r[0] = 1
    z = 0
    t = 0
    for i in reversed(s):
        z = int(i) * pow(10,t,MOD) + z
        z %= MOD
        r[z] += 1
        t += 1
    print(sum(i*(i-1)//2 for i in r))


if __name__ == '__main__':
    main()


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

bool v[10][10];
int dx[] = {1, 0, -1, 0},
    dy[] = {0, 1, 0, -1};
string s[10];
int h, w;

bool dfs(int x,int y)
{
    v[y][x] = true;

    // for(int i=0;i<h;i++){for(int j=0;j<w;j++)cerr<<v[i][j];cerr<<endl;}cerr<<endl;

    if (x == w - 1 && y == h - 1) return true;

    for (int i = 0; i < 4; i++) {
        int nx = x + dx[i],
            ny = y + dy[i];
        if (true
            && nx >= 0
            && nx < w
            && ny >= 0
            && ny < h
            && s[ny][nx] == '#'
        ) {
            // cerr << y << " " << x << " " << dy[i] << " " << dx[i] << " " << v[ny][nx] << endl;
            if ((dx[i] < 0 || dy[i] < 0) && !v[ny][nx]) return false;
            else if (v[ny][nx]) continue;
            else return dfs(nx, ny);
        }
    }
    return false;
}
int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++) cin >> s[i];

    bool f = dfs(0, 0);

    int c = 0, cc = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            c += s[i][j] == '#';
            cc += v[i][j];
        }
    }

    cout << (f && c == cc ? "Possible" : "Impossible") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;
long long x[500010],a[500010],b[500010],c[500010];
int main(){
	long long i,n,d,q;
	cin >> n >> d;
	a[0] = d;
	for(i=1;i<=n;i++){
		cin >> x[i-1];
		d = min(d,abs(d-x[i-1]));
		a[i] = d;
	}
	cin >> q;
	for(i=0;i<q;i++){
		cin >> b[i];
	}
	
	if(a[n]!=0){
		for(i=0;i<q;i++){
			cout << "YES" << endl;
		}
		return 0;
	}
	
	c[n] = 1;
	for(i=n-1;i>0;i--){
		if(x[i]>=2*c[i+1]){
			c[i] = c[i+1];
		}else{
			c[i] = c[i+1]+x[i];
		}
	}
	
	for(i=0;i<q;i++){
		if(a[b[i]-1]>=c[b[i]]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 17536
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> mpll;
typedef unordered_map<char, ll> mpcl;
typedef unordered_map<string, ll> mpsl;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return (x);
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n = inl(), k = inl();
        double ans = 0;
        for (int i = 1; i <= n; ++i) {
            ll tmp = i;
            ll time = 0;
            while (tmp < k) tmp *= 2, time++;
            ans += pow(1.0 / 2, time) * 1.0 / n;
        }
        cout << fixed << setprecision(10) << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
import math
from functools import reduce

def getD(num):
    input_list = [2 if i % 2 == 0 else i for i in range(num+1)]
    input_list[0] = 0
    bool_list = [False if i % 2 == 0 else True for i in range(num+1)]
    sqrt = int(math.sqrt(num))
    
    for serial in range(3, sqrt + 1, 2):
        if bool_list[serial]:
            for s in range(serial ** 2, num+1, serial):
                if bool_list[s]:
                    input_list[s] = serial
                    bool_list[s] = False
    return input_list

N = int(input())
A = list(map(int, input().split()))

D = getD(max(A))
pairwise_coprime = True
use_divnum = set()
for k in A:
    while k != 1:
        if D[k] in use_divnum:
            pairwise_coprime = False
            break
        else:
            use_divnum.add(D[k])
        div = D[k]
        while k % div == 0 and k > 1:
            k = k // div

if pairwise_coprime:
    print('pairwise coprime')
    exit()

if reduce(math.gcd, A) == 1:
    print('setwise coprime')
else:
    print('not coprime')


Measured memory_bytes: 127588
#include<iostream>
#include<cmath>
#include<vector>
#include<climits>
#include<algorithm>
#include<numeric>
#include<iomanip>
#include<map>
#include<cassert>
using namespace std;
#define ll long long int
#define ld long double
const ll Mod = 1000000007;
ll CaseN=1;
const ld PI = 22/7.0;

bool mycmp(string s,string t)
{
if(s.size()<t.size())
{
return true;	
}		
return false;
}

void solve()
{
	ll ans=1;
	ll p = pow(10ll,18ll);
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++)
	{
	ll x;
	cin>>x;
	if(ans!=0  && ans !=-1 && x<=p/ans)
	ans = ans*x;
	else
	{
		if(ans!=0)
		ans = -1;}	
	
	if(x==0)
	{
	ans =0;	
	}
	
	}
	
	// cout<<"Case #"<<CaseN<<": ";
   CaseN++;
   cout<<ans<<endl;
   //printf("%llld",ans);
	// print your ans below;
return ;
}


signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();	
	}
}


Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int  j = Integer.parseInt(sc.nextLine());
        
        int box[] = new int[j];
        
        for(int i=1; i<=j;i++){
            box[j-i]=sc.nextInt();
        }
        for(int i=0; i<j; i++){
            if(i<j-1){
                System.out.print(box[i]+ " ");
            }else{
                System.out.println(box[i]);
            }
        }
        
        
    }
}



Measured memory_bytes: 26240
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,ll>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

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


vector<vector<P>>G;
vector<int>res;
void dfs(int v,int p){
    for(auto nv : G[v]){
        if(nv.first==p)continue;
        if(nv.second==0)res[nv.first] = res[v];
        else res[nv.first] = 1-res[v];
        dfs(nv.first,v);
    }
}

int main(){
    int n;cin>>n;
    G.assign(n,vector<P>());
    res.assign(n,0);
    rep(i,n-1){
        int a,b;
        ll c;cin>>a>>b>>c;
        a--;b--;
        c %= 2;
        G[a].emplace_back(b,c);
        G[b].emplace_back(a,c);
    }
    dfs(0,-1);
    rep(i,n)cout<<res[i]<<endl;
}



Measured memory_bytes: 10496
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int a, b, c, d, e, k;
    cin >> a >> b >> c >> d >> e >> k;
    int x = e - a;
    if (x > k) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    };

    return 0;
}

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

main(){
	int n;
	double k;
	cin>>n;
	k = n;
	
	if(n%2 == 1)
		cout<<fixed<<setprecision(20)<<(int(k/2)+1)/k<<endl;
	else
		cout<<(k/2)/k<<endl;
}

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

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;

  if(e-a > k){
    cout << ":(" << endl;
  }
  else{
    cout << "Yay!" << endl;
  }
}

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

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int d;
  while (cin >> d) {
    int s = 0;
    for (int x = d; x < 600; x += d) {
      s += x * x * d;
    }
    cout << s << endl;
  }
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N;
    cin >> N;

    string S;
    cin >> S;

    if (N%2 == 0) {
        string tmp1 = S.substr(0, N/2);
        string tmp2 = S.substr(N/2, N/2);
        if (tmp1 == tmp2) {
            Yes;
        } else {
            No;
        }
    } else {
        No;
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(void){
    char a[101],b[101];
    int al, bl;

    scanf("%s", a);
    scanf("%s", b);
    al = strlen(a);
    bl = strlen(b);

    if(al == bl){
        for(int i = 0; i < al; i++){
            if(a[i] != b[i]){
                printf(a[i] > b[i] ? "GREATER" : "LESS");
                break;
            }
            if(i == al - 1) printf("EQUAL");
        }
    }else if(al > bl){
        printf("GREATER");
    }else{
        printf("LESS");
    }


    return 0;
}

Measured memory_bytes: 1732
// #pragma GCC optimize ("O3")

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

#define sd(mark) scanf("%d",&mark)
#define s2d(mark,marx) scanf("%d%d",&mark,&marx)
#define s3d(mark,marx,marz) scanf("%d%d%d",&mark,&marx,&marz)
#define sf(mark) scanf("%f",&mark)
#define slf(mark) scanf("%lf",&mark)
#define sst(mark) scanf("%s",&mark)
#define sld(mark) scanf("%lld",&mark)
#define s2ld(mark,marx) scanf("%lld%lld",&mark,&marx)
#define s3ld(mark,marx,marz) scanf("%lld%lld%lld",&mark,&marx,&marz)
#define sline(mline) scanf("%[^\n]%*c",&mline)

#define pi(n) printf("%d\n",n)
#define pf(n) printf("%f\n",n)
#define plf(n) printf("%lf\n",n)
#define pst(n) printf("%s\n",n)
#define pl(n) printf("%lld\n",n)

#define pis(n) printf("%d ",n)
#define pfs(n) printf("%f ",n)
#define plfs(n) printf("%lf ",n)
#define pss(n) printf("%s ",n)
#define pls(n) printf("%lld ",n)

#define sff fflush(stdout)
#define decimal(n) cout.precision(n)
#define fix cout<<fixed
#define debug(mark) printf("check%d\n",mark)
#define in(a) cin>>a
#define out(a) cout<<a<<'\n'
#define clr(mark) memset(mark,0,sizeof(mark))
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long int
#define mod 1000000007ll
#define llu unsigned long long int
#define endl '\n'
#define INF 1123456789
#define eps 1e-9
#define fo(i,a,b) for(int i=a;i<b;++i)
#define foll(i,a,b) for(ll i=a;i<b;++i)
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)

#define UL 100000		//5
#define MAXN 1000000	//6
#define MAXL 10000000	//7

typedef vector< vector<int> > vvi;
typedef vector< vector<ll> > vvl;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< pair<ll,ll> > vll;
typedef pair<char,char> pcc;
typedef vector< pair<int, int> > vii;


// bool mark[MAXN+5];

// int sieve()
// {
// 	int ULL = MAXN;
// 	for(int i=0;i<=ULL;i++) mark[i]=true;
// 	for(int i=2;i*i<=ULL;i++) if(mark[i]) for(int j=i*i;j<=ULL;j+=i) mark[j]=false;
// 	for(int i=2;i<=ULL;i++) if(mark[i]) p.pb(i);
// 	return p.size();
// }


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

ll modexp(ll a,ll b)
{
	if(b==0) return 1;
	if(b==1) return a;
	ll temp = modexp(a,(b>>1));
	temp = (temp*temp);
	return (temp*modexp(a,b&1));
}

ll modexp(ll a,ll b, ll m)
{
	if(b==0) return 1;
	if(b==1) return a%m;
	ll temp = modexp(a,(b>>1),m);
	temp = (temp*temp)%m;
	return (temp*modexp(a,b&1,m))%m;
}

ll modinv(ll a, ll p)
{
	return modexp(a,p-2,p);
}

// int A[3*UL+5],B[3*UL+5];
// ll sA[3*UL+5],sB[3*UL+5];

// int solve(int l1,int l2,int r1,int r2)
// {
// 	if(l1>r1||l2>r2) return 0;
// 	int x = l1, y = l2;
// 	while((sA[x]-sA[l1-1])!=(sB[y]-sB[l2-1]))
// 	{
// 		if((sA[x]-sA[l1-1])<(sB[y]-sB[l2-1])) x++;
// 		else if((sA[x]-sA[l1-1])>(sB[y]-sB[l2-1])) y++;
// 	}
// 	return (1+solve(x+1,y+1,r1,r2));
// }

vi p,tt;
int main()
{
	int n,x; s2d(n,x);
	p.pb(x);
	fo(i,0,n) {sd(x);p.pb(x);}
	sort(p.begin(), p.end());
	fo(i,1,n+1) {tt.pb(p[i]-p[i-1]);}
	int g = tt[0];
	fo(i,0,tt.size()) {g= gcd(g,tt[i]);}
	pi(g);
}

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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl '\n'
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("lepus.in", "r", stdin); freopen("lepus.out", "w", stdout);
#define __lcm(a, b) a * b / __gcd(a, b)
#define up_b upper_bound
#define low_b lower_bound
#define pcnt(i) __builtin_popcount(i)

using namespace std;

const long long MXN = 1e6 + 1;
const long long MAXN = 1e3 + 7;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

inline void JUDGE(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,-1,0,0}; int dy[]= {0,0,1,-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[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, k, a[MXN];

int main() {

    JUDGE();

    cin >> n >> k;
  	for(int i = 1; i <= n; i++) {
    	cin >> a[i];
    }
  	sort(a + 1, a + 1 + n);
  	if(k >= n) cout << 0;
  	else {
      	long long sum = 0;
     	for(int i = 1; i <= n - k; i++) {
        	sum += a[i];
        }
      cout << sum;
    }

    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, n1, n2, n3;
  cin >> a;
  n3 = a/100;
  n2 = a/10-n3*10;
  n1 = a-n3*100-n2*10;
  cout << n1+n2+n3;
  // ここにプログラムを追記
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

x = 0
for i in range(H):
    ans = []
    for j in range(W):
        ans.append(x+1)
        A[x] -= 1
        if A[x] == 0:
            x += 1
    if i % 2 == 0:
        print(*ans)
    else:
        print(*ans[::-1])

Measured memory_bytes: 43504
import sys


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = self.__dot(node[i], c)
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


N, Q = map(int, input().split())
query = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]

flagH = [N - 1] * N
flagW = [N - 1] * N

stH = SegmentTree([N - 1] * N, min, N - 1)
stW = SegmentTree([N - 1] * N, min, N - 1)

cnt = 0
for t, x in query:
    if t == 1:
        stX, stY = stW, stH
    else:
        stX, stY = stH, stW

    cnt += max(0, stX.get(x - 1, N) - 1)
    # flagX[x - 1] = 0
    stY.update(stX.get(x - 1, N), x - 1)

print(pow(N - 2, 2) - cnt)


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
// #define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int n, m; cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 7696
require "bigdecimal"
require "bigdecimal/util"

def gi() gets.to_i end
def gs() gets.chomp end
def gmi() gets.split.map(&:to_i) end
def gms() gets.split.map(&:chomp) end
def YesNo1(bool, yes="Yes", no="No") puts (bool ? yes : no) end
def YESNO2(bool, yes="YES", no="NO") puts (bool ? yes : no) end


#####
n = gi
nums = gmi
negCount = 0
zeroCount = 0
nums.each do |num|
  if num < 0
    negCount += 1
  elsif num == 0
    zeroCount += 1
  end
end
res = 0
nums.map!(&:abs).sort!.reverse!
#print nums
res += nums[0..(n-1-negCount%2)].inject(:+)
res -= nums[(n-negCount%2)..-1].inject(:+) if negCount%2 != 0
puts res

Measured memory_bytes: 9504