akhauriyash/Code-Regression huggingface dataset:
# 选择排序
def showList(list1):
  for i in range(len(list1)):
    if(i<len(list1)-1):
      print(list1[i],end=' ')
    else:
      print(list1[i])
      
def selectionSort(seq):
  swapCount = 0
  for i in range(len(seq)):
    minIndex = i
    for j in range(i+1,len(seq)):
      if seq[minIndex]>seq[j]:
        minIndex = j
    if i!=minIndex:
      seq[i],seq[minIndex] = seq[minIndex],seq[i]
      swapCount+=1
  return swapCount

n = input()
list1 = list(map(int,input().split()))

count = selectionSort(list1)
showList(list1)
print(count)


Measured memory_bytes: 5608
var par = [];
function init(n) {
    for (var i = 0; i < n; i++) {
        par[i] = i;
    }
}
function find(x) {
    if (par[x] == x) return x;
    return par[x] = find(par[x]);
}
function isSame(x, y) {
    return find(x) == find(y);
}
function union(x, y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    par[x] = y;
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim();
var lines = input.split('\n');

var n = +lines.shift();

var es = [];
for (var y = 0; y < n; y++) {
    var xs = lines.shift().trim().split(' ').map(function(n){return +n;});
    for (var x = y + 1; x < n; x++) {
        var cost = xs[x];
        if (cost == -1) continue;
        es.push({cost: cost, v1: x, v2: y});
    }
}
es.sort(function(a, b){return a.cost - b.cost;});

init(n);
var costs = 0;
var e;
while (e = es.shift()) {
    if (!isSame(e.v1, e.v2)) {
        costs += e.cost;
        union(e.v1, e.v2);
    }
}
console.log(costs);

Measured memory_bytes: 10192
#include <stdio.h>

int main( void ){
	int one,two,three,num;
	int i;

	one = two = three = num = 0;

	for( i = 0; i < 10; i++ ){
		scanf( "%d", &num );

		if( num >= one ){
			three = two;
			two = one;
			one = num;
		}
		else if( num >= two ){
			three = two;
			two = num;
		}
		else if( num >= three ){
			three = num;
		}
	}

	printf("%d\n%d\n%d\n", one, two, three ); 

	return 0;

}



Measured memory_bytes: 2036
// #define DEBUGGING
#include <bits/stdc++.h>
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()
template <typename T> using V = std::vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = std::int64_t;
using ull = std::uint64_t;
using PLL = std::pair<ll, ll>;
using TLL = std::tuple<ll, ll, ll>;
template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return std::min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return std::max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return std::max(low, std::min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { return t = clamp(t, low, high); }
namespace init__ { struct InitIO { InitIO() { std::cin.tie(nullptr); std::ios_base::sync_with_stdio(false); std::cout << std::fixed << std::setprecision(30); } } init_io; }
#define mv_rec make_v(init, tail...)
template <typename T> T make_v(T init) { return init; }
template <typename T, typename... Tail> auto make_v(T init, size_t s, Tail... tail) { return V<decltype(mv_rec)>(s, mv_rec); }
#undef mv_rec
using namespace std;
#ifdef DEBUGGING
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

bool dp[1000][4];

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    dp[0][0] = 1;
    for(char c : S) {
        int n = c - '0';
        for(int j = 2; 0 <= j; j--) {
            for(int i = 0; i < 1000; i++) {
                if(!dp[i][j]) continue;
                int nxt = i * 10 + n;
                if(1000 <= nxt) continue;
                dp[nxt][j + 1] = true;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 1000; i++) ans += dp[i][3];
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) (vec).begin(),(vec).end()
typedef unsigned long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "\n"; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n; cin >> n;
  vector<int> a(1 << n);
  for (int &z : a) cin >> z;
  multiset<int> x(ALL(a));
  vector<int> b = {*max_element(ALL(a))};
  for (int len = 1; len < (1 << n); len <<= 1) {
    sort(ALL(b));
    reverse(ALL(b));
    vector<int> c = b;
    for (int z : b) {
      auto it = x.lower_bound(z);
      if (it == x.begin()) kek("No");
      --it;
      c.push_back(*it);
      x.erase(it);
    }
    swap(b, c);
  }
  kek("Yes");
}


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


using namespace std;

#ifdef CLION
ifstream ifs("/home/kyuridenamida/CLionProjects/project/input.txt");
#define cin ifs
#define scanf DONT_USE_SCANF
#endif

typedef long long ll;

int main() {
    string s;
    int k;
    cin >> s >> k;

    long long ans = 0;
    set<string> cands;
    if (k == 1) {
        for (int i = 0; i < s.size(); i++) {
            for (int j = 1; j < 10; j++) {
                string w = string(s.size(), '0');
                w[i] = '0' + j;

                cands.insert(w);
            }
        }
    } else if (k == 2) {
        for (int i = 0; i < s.size(); i++) {
            for (int i2 = i + 1; i2 < s.size(); i2++) {
                for (int j = 1; j < 10; j++) {
                    for (int j2 = 1; j2 < 10; j2++) {
                        string w = string(s.size(), '0');
                        w[i] = '0' + j;
                        w[i2] = '0' + j2;
                        cands.insert(w);
                    }
                }
            }
        }
    } else {
        for (int i = 0; i < s.size(); i++) {
            if (i == 0) {
                // special
                for (int i2 = i + 1; i2 < s.size(); i2++) {
                    for (int i3 = i2 + 1; i3 < s.size(); i3++) {
                        for (int j = 1; j < 10; j++) {
                            for (int j2 = 1; j2 < 10; j2++) {
                                for (int j3 = 1; j3 < 10; j3++) {
                                    string w = string(s.size(), '0');
                                    w[i] = '0' + j;
                                    w[i2] = '0' + j2;
                                    w[i3] = '0' + j3;
                                    if (w <= s) {
                                        ans++;
                                    }
                                }
                            }
                        }

                    }
                }
            } else {
                ans += 9ll * 9ll * 9 * (s.size() - i - 1) * (s.size() - i - 2) / 2;
            }
        }
    }

    for (auto c : cands) {
        if (s >= c) {
            ans++;
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 75392
#include <bits/stdc++.h>
using namespace std;
#define ll long long
 
void solve(){
    ll n; cin >> n;
    ll sum = 0, count = 0;
    
    for(ll i = 1;i <= n;i++){
        if(i%3 == 0 || i%5 == 0) continue;
        sum += i;
    }
    cout << sum << endl;
}

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


Measured memory_bytes: 3640
n = input()
a = map(int, raw_input().split())

mini = a[0]
maxi = a[0]
sum = 0
for x in a:
    sum += x
    if x < mini:
        mini = x
    if maxi < x:
        maxi = x

print('{} {} {}'.format(mini, maxi, sum))

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

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

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

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> S;
const int MAX_N = 110;
int main() {
  cin >> N;
  S.resize(N);
  for (auto &val : S){
    cin >> val;
  }
  sort(S.begin(), S.end());
  int sum = 0;
  for (int i = 0; i < N; i++){
    sum += S[i];
  }

  if (sum % 10 != 0){
    cout << sum << endl;
    return 0;
  }
  for (int i = 0; i < S.size(); i++){
    if ((sum - S[i]) % 10 != 0){
      cout << sum - S[i] << endl;
      return 0;
    }
  }
  cout << 0 << endl;

  return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = 10e15;
const ll MINF = -10e10;
const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)


//ifstream myfile("~/Downloads/02.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

vector<vector<ll>> dp;

// https://kamino.hatenablog.com/entry/cpp-permutation-combination
void foreach_permutation(int n, std::function<void(int *)> f) {
    int indexes[n];
    for (int i = 0; i < n; i++) indexes[i] = i;
    do {
        f(indexes);
    } while (std::next_permutation(indexes, indexes + n));
}

// https://qiita.com/okaryo/items/8e6cd73f8a676b7a5d75
void warshall_floyd(int n) {
    for (int k = 0; k < n; k++) {       // 経由する頂点
        for (int i = 0; i < n; i++) {    // 始点
            for (int j = 0; j < n; j++) {  // 終点
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
}

int main() {

    ll n, m, r;
    cin >> n >> m >> r;

    vector<ll> targets(r);
    rep(i, r) {
        ll t;
        cin >> t;
        t--;
        targets[i] = t;
    }

    dp = vector<vector<ll>>(n, vector<ll>(n, INF));
    rep(i, m) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dp[a][b] = c;
        dp[b][a] = c;
    }
    warshall_floyd(n);


    ll ans = INF;
    foreach_permutation(r, [&](int *indexes) {
        ll now = 0;
        for (ll k = 0; k < r - 1; k++) {
            ll from = targets[indexes[k]];
            ll to = targets[indexes[k + 1]];

            now += dp[from][to];
        }
        cmin(ans, now);
    });
    cout << ans << endl;

}

Measured memory_bytes: 512
'use strict';
console.log(function(args){
  const N = args.trim()|0;
  let count = 0;
  for ( let i = 1; i <= N; i++ ) {
    if ( (''+i).length % 2 === 1 ) count++;
  }
  return count.toString();
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 10828
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール

// 処理内容
int main() {
    
    ll n, k; cin >> n >> k;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];
    
    vector<ll> s(n+1, 0);
    REP(i, n) s[i+1] = s[i] + max(0LL, a[i]);
    vector<ll> t(n+1, 0);
    REP(i, n) t[i+1] = t[i] + a[i];

    ll ans = 0;
    RANGE(i, 0, n-k) {
        ll x = t[i+k] - t[i];
        ll y = s[i] + s[n] - s[i+k];
        chmax(ans, max(y, x + y));
    }
    cout << ans << endl;
    
}

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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20
#define INF 1e12+20

typedef long long ll;
using namespace std;

int n,m,b,j;
int main() {
    cin >> n;

    int a[n];
    rep(i,0,n){
        cin >> a[i];
    }
    cin >> m;
    int cnt = 0;
    rep(i,0,m){
        cin >> b;
        int left = 0, right = n,mid;
        while(left < right){
            mid = (left+right)/2;
            if(b == a[mid]){
                cnt++;
                break;
            }
            if(b > a[mid]) left = mid +1;
            else if(b < a[mid]) right = mid;
        }        
    }
    pout(cnt);
    return 0;
}


Measured memory_bytes: 3520
#include<iostream>
using namespace std;
string s="a";
int n;
void dfs(int step,char $){
    if(step==n){
        cout<<s<<endl;
        return;
    }
    string t=s;
    char i;
    for(i='a';i<=$+1;i++){ 
    	s=t+i;
    	dfs(step+1,max($,i)); 
	}
	s=t; 
}
int main(){
    cin>>n;
    dfs(1,'a');
    return 0;
}

Measured memory_bytes: 1536
#include<stdio.h>
typedef struct{
  char name[10];
  int time;
}Process;
int main(){
  int i,q,takenTime,n,head,tail;
  Process pc[100001];

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",pc[i].name,&pc[i].time);
  }

  head = 0;
  tail = n;
  takenTime = 0;

  while( head != tail ){
    if( pc[head].time - q > 0 ){
      takenTime += q;
      pc[head].time -= q;
      pc[tail] = pc[head];
      if( tail + 1 > n){
	tail = 0;
      }
      else {
	tail++;
      }
    }
    else{
      takenTime += pc[head].time;
      printf("%s %d\n",pc[head].name,takenTime);
    }

    if( head + 1 > n ){
      head = 0;
    }
    else {
      head++;
    }
  }
  return 0;
}
 

Measured memory_bytes: 1384
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<set>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;
typedef long long ll;

int main(){

   int m;
   cin >> m;

   cout << 24 + (24-m) << endl;


   return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = Integer.parseInt(sc.next());
		int S = Integer.parseInt(sc.next());
		int result = 0;
		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				int total = x + y;
				if (!(total > S) && (total+K) >= S) {
					result++;
				}
			}
		}
		System.out.println(result);
	}
}

Measured memory_bytes: 35676
#include <iostream>
  #include <string>
  #include <vector>
  #include <algorithm>
  #include <utility>
  #include <map>
  using namespace std;
  typedef long long ll;
  #define rep(i,n) for (int i=0;i < (int)(n);i++)


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

    return 0;
  }


Measured memory_bytes: 4796
#include<map>
#include<cstdio>
#include<queue>
#include<bitset>
#include<vector>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
# define Type template<typename T>
# define ll long long
# define ull unsigned ll
# define read read1<int>()
Type inline T read1(){
    T t=0;
    char k;
    bool fl=0;
    do k=getchar(),(k=='-')&&(fl=1);while('0'>k||k>'9');
    while('0'<=k&&k<='9')t=(t<<3)+(t<<1)+(k^'0'),k=getchar();
    return fl?-t:t;
}
int a[105],s,k;
int main(){
    s=read,k=read;
    while(k--)
        for(int T=read;T--;)
            a[read]=1;
    int ans=0;
    for(int i=1;i<=s;++i)
        ans+=!a[i];
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3764
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map.Entry;

public class Main {
  public static void main(String[] args) throws IOException {
    String ans = "Yes";
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String str = br.readLine();
    HashMap<Character, Integer> map = new HashMap<Character, Integer>();
    for (int i = 0; i < str.length(); i++) {
      if (map.containsKey(str.charAt(i))) {
        map.put(str.charAt(i), map.get(str.charAt(i)) + 1);
      } else {
        map.put(str.charAt(i), 1);
      }
    }
    for (Entry<Character, Integer> entry : map.entrySet()) {
      if (entry.getValue() % 2 == 1) {
        ans = "No";
        break;
      }
    }
    System.out.print(ans);
  }
}

Measured memory_bytes: 22484
#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int N, W;
  cin >> N >> W;
  vector<int> ans(N+2, 0);
  ans[0] = W;
  for(int i = 1; i <= W/2; ++i){
    ++ans[i+1];
  }
  for(int i = W/2+1; i < W; ++i){
    for(int j = 3; j*i <= N; ++j){
      ++ans[j*i-W+1];
      --ans[j*i-W+1+W-i];
    }
  }
  for(int i = 1; i <= N-W+2; ++i){
    ans[i] += ans[i-1];
  }
  cout << ans[1];
  for(int i = 2; i <= N-W+1; ++i) cout << " " << ans[i];
  cout << endl;
  return 0;
}



Measured memory_bytes: 3096
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def main():
    N, X, *xn = map(int, open(0).read().split())
    ans = None
    for x in xn:
        if ans is not None:
            ans = gcd(ans, abs(X - x))
        else:
            ans = abs(X - xn[0])
    print(ans)
    return


main()


Measured memory_bytes: 14052
def main():
    n, k = map(int, input().split(' '))
    result = 0
    for i in range(1, n+1):
        p = n//i
        result += p*max(0,i-k)
        result += max(0, n%i-k+1)
    if k == 0:
        result -= n
    print(result)
main()

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.rbegin(), a.rend());

  cout << a[0] * 10 + a[1] + a[2] << endl;
}


Measured memory_bytes: 256
import os, sys, re, math


def get_exp_value(number):
    if number == 0:
        return 0
    a = (number + 1) / number
    exp = a * (number // 2)
    if number % 2 != 0:
        exp += a / 2

    return exp


(N, K) = [int(n) for n in input().split()]
P = [int(n) for n in input().split()]

exps = [get_exp_value(i) for i in range(200001)]

s = sum(P[0:K])
max_sum = 0
max_pos = 0
for i in range(K, N):
    s = s - P[i - K] + P[i]
    if s > max_sum:
        max_sum = s
        max_pos = i

answer = 0
for i in range(max_pos - K, max_pos):
    answer += exps[P[i + 1]]

print(answer)


Measured memory_bytes: 33068
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <functional>
using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

VI a;
int N;

int main(){

	cin >> N;
	a.resize(N);
	int ma=-100000000;
	int mi=100000000;
	int mai=0,mii=0;
	REP(i,N){
		cin >> a[i];
		if(ma < a[i]){
			ma = a[i];
			mai = i+1;
		}
		if(mi > a[i]){
			mi = a[i];
			mii = i+1;
		}
	}
	cout << N*2-1 << endl;
	if(abs(ma)>abs(mi)) {
		REP(i,N) {
			cout << mai << " " << i+1 << endl;
		}
		FOR(i,1,N) {
			cout << i << " " << i+1 << endl;
		}
	} else {
		REP(i,N) {
			cout << mii << " " << i+1 << endl;
		}
		RFOR(i,0,N-1) {
			cout << i+2 << " " << i+1 << endl;
		}
	}
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

#define long long long

const int N = 1e5+2;
const long INF = 1e18;

int n;
long a[3*N], pref[3*N], suff[3*N]; 

void Solve()
{
    priority_queue<long, vector<long>, greater<long> > minheap;
    priority_queue<long, vector<long>, less<long> > maxheap;
    
    for (int i = 1; i <= n; ++i)
    {
        pref[i] = pref[i-1] + a[i];
        minheap.push(a[i]);
    }
    for (int i = n+1; i <= 3*n; ++i)
    {
        long top = minheap.top();
        long mx = max(a[i], top); minheap.pop();
        pref[i] = pref[i-1] - top + mx;
        minheap.push(mx);
    }
    
    for (int i = 3*n; i > 2*n; --i)
    {
        suff[i] = suff[i+1] + a[i];
        maxheap.push(a[i]);
    }
    for (int i = 2*n; i >= 1; --i)
    {
        long top = maxheap.top();
        long mn = min(a[i], top); maxheap.pop();
        suff[i] = suff[i+1] - top + mn;
        maxheap.push(mn);
    }
    
    long res = -INF;
    for (int i = n; i <= 2*n; ++i) res = max(res, pref[i] - suff[i+1]);
    printf("%lld",res);
}

int main()
{
    scanf("%d",&n);
    for (int i = 1; i <= 3*n; ++i) scanf("%lld",&a[i]);
    Solve();
    return 0;
}

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

int main() {
    int n;
    cin >> n;
    int m = n;
    int c = 0;
    
    while (m > 0) {
        c += m % 10;
        m /= 10;
    }
    
    if (n % c == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007
using namespace std;
int dp[300100][62];

ll pr(ll x , ll y)
{
    if(y==0) return 1;
    ll res=1;
    while(y>1)
    {
        if(y&1) res*=x;
        x*=x;
        y/=2;
        x%=hell;
        res%=hell;
    }
    res*=x;
    res%=hell;
    return res;
}
void solve()
{
 ll i,j=0,r=200,p,q,k,d,y=0,h,flag=0,m=0,n,a=hell,b=hell,id,h1,h2,a1,b1,a2,w,x,u,f,l,c,e,ans=0;
 cin>>n;
 vector < ll > v(n);
 rep(i,0,n) cin>>v[i];
 for(i=n-1;i>=0;i--)
 {
     k=v[i];
     c=0;
     if(i<n-1)
     for(j=0;j<=61;j++) dp[i][j]=dp[i+1][j];
     while(k>0)
     {
         if(k&1) dp[i][c]++;
         c++;
         k/=2;
     }
 }

 for(i=0;i<n-1;i++)
 {
     k=v[i];
     c=0;
     while(c<62)
     {
         if(k%2==0)
         {
             p=dp[i+1][c];
             if(p)
             y+=p*pr(2,c);
             y%=hell;
         }
         else
         {
             p=n-i-1-dp[i+1][c];
             if(p)
             y+=p*pr(2,c);
             y%=hell;
         }
         c++;
         k/=2;
         //cout<<y<<" "<<c<<endl;
     }
     //cout<<y<<endl;

 }
 cout<<y;
}



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


Measured memory_bytes: 75264
//
// Created by 10034 on 2020/7/29.
//

#include <iostream>
#include <cstring>
using namespace std;
const int mod=1e9+7,N=1000100;
char s[N];
#define int long long
typedef long long LL;
int qmi(int a,int b){
    int res=1;
    while(b){
        if(b&1) res=(LL)res*a%mod;
        b>>=1;
        a=(LL)a*a%mod;
    }
    return res;
}
int fac[N*2];
int C(int a,int b){
//    cout<<fac[a]<<" "<<qmi(fac[a-b],mod-2)<<" "<<qmi(fac[b],mod-2)<<endl;
    return (LL)fac[a]*qmi(fac[a-b],mod-2)%mod*qmi(fac[b],mod-2)%mod;
}
signed main(){
    fac[0]=1;
    for(int i=1;i<N*2;++i){
        fac[i]=(LL)fac[i-1]*i%mod;
    }
    int n,m;
    cin>>m;
    cin>>s;
    int res=0;
    n=strlen(s);
    for(int i=0;i<=m;++i){
        res=(LL)(res+(LL)qmi(26,i)*C(n+m-i-1,n-1)%mod*qmi(25,m-i)%mod)%mod;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 19760
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using db = double;
using ld = long double;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for(ll i = a; i < (ll)(n); ++i)
#define repr(i, a, n) for(ll i = n - 1; (ll)a <= i; --i)
#define ENDL '\n'
typedef pair<int, int> Pi;
typedef pair<ll, ll> PL;
constexpr ll mod = 1000000007;  // 998244353;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 + 99);
const ld PI = acos((ld)-1);
const vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U> inline bool chmin(T& t, const U& u) {
  if(t > u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T, typename U> inline bool chmax(T& t, const U& u) {
  if(t < u) {
    t = u;
    return 1;
  }
  return 0;
}
template <typename T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

template <typename T, typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(; n; n >>= 1) {
    if(n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template <typename T, typename Y>
ostream& operator<<(ostream& os, const pair<T, Y>& p) {
  return os << "{" << p.fs << "," << p.sc << "}";
}
template <typename T> ostream& operator<<(ostream& os, const V<T>& v) {
  os << "{";
  for(auto e : v) os << e << ",";
  return os << "}";
}
template <typename... Args> void debug(Args&... args) {
  for(auto const& x : {args...}) { cerr << x << ' '; }
  cerr << ENDL;
}

bool pc = true;
set<ll> prime;

template <typename T> vector<T> eratosthenes(T N) {
  vector<T> v(N + 1, 1);
  iota(all(v), 0);
  for(int i = 2; i * i < N + 1; i++) {
    for(int j = i * i; j < N + 1; j += i)  // i^2からスタートしてよい
    {
      if(v.at(j)==j)v.at(j) = i;
    }
  }
  return v;
}
//その数を割り切る(最小の)素数を入れる
// 1以外、1が入っているならば素数
//→素因数分解が対数時間で可能
// now→now/v[now]として1まで遷移していく

template <typename T> vector<T> factor(T n, const vector<T>& s) {
  V<T> ret(0);
  while(n > 1) {
    ret.eb(s.at(n));
    n /= s.at(n);
  }
  return ret;
}

signed main() {
  cin.tie(0);
  cerr.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n;
  cin >> n;

  V<ll> v(n), er = eratosthenes(1000010ll);
  rep(i, 0, n) cin >> v[i];
  ll g = v[0];
  rep(i, 1, n) g = gcd(g, v[i]);

  rep(i, 0, n) {
    V<ll> ps = factor(v[i], er);
    sort(all(ps));
    ps.erase(unique(all(ps)), ps.end());

    rep(j, 0, siz(ps)) {
      if(prime.count(ps[j]))
        pc = false;
      else
        prime.insert(ps[j]);
    }
  }

  if(pc)
    cout << "pairwise coprime" << ENDL;
  else if(g == 1)
    cout << "setwise coprime" << ENDL;
  else
    cout << "not coprime" << ENDL;
}
//! ( . _ . ) !
// CHECK overflow,vector_size,what to output?

Measured memory_bytes: 22352
#include<iostream>
#include<cmath>
#include<map>

using namespace std;

int main(){
  for(int N;cin>>N,N;){
    int X[51234],R[51234];
    for(int i=0;i<N;i++){
      cin>>X[i]>>R[i];
    }
    double l=0,h=1e9;
    for(int i=0;i<66;i++){
      double m=(l+h)/2;
      map<double,int> mp;
      for(int j=0;j<N;j++){
	double inr=1.*R[j]*R[j]-m*m;
	if(inr>=0){
	  mp[-sqrt(inr)+X[j]]++;
	  mp[sqrt(inr)+X[j]]--;
	}
      }
      int c=0;
      double start;
      bool f=false;
      for(auto e:mp){
	if(c==0){
	  start=e.first;
	}
	c+=e.second;
	if(c==0){
	  f|=e.first-start>=m*2;
	}
      }
      (f?l:h)=m;
    }
    cout<<fixed<<l*2<<endl;
  }
}

Measured memory_bytes: 7912
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1e18;

signed main(){
    int n,m;
    cin>>n>>m;
    V<ll> x(n),y(n),z(n);
    rep(i,n) cin>>x[i]>>y[i]>>z[i];
    ll ans=0;
    for(int i=0;i<8;i++){
        string t;
        for(int j=0;j<3;j++){
            if(i>>j&1) t+='+';
            else t+='-';
        }
        V<pair<ll,int>> p;
        for(int j=0;j<n;j++){
            ll cnt=0;
            for(int k=0;k<3;k++){
                if(k==0){
                    if(t[k]=='+') cnt+=x[j];
                    else cnt-=x[j];
                }else if(k==1){
                    if(t[k]=='+') cnt+=y[j];
                    else cnt-=y[j];
                }else{
                    if(t[k]=='+') cnt+=z[j];
                    else cnt-=z[j];
                }
            }
            p.push_back(make_pair(cnt,j));
        }
        sort(all(p),greater<pair<ll,int>>());
        ll a=0,b=0,c=0;
        for(int j=0;j<m;j++){
            a+=x[p[j].sc];
            b+=y[p[j].sc];
            c+=z[p[j].sc];
        }
        chmax(ans,abs(a)+abs(b)+abs(c));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>

using namespace std;

int prv[200010];
char str[200010];

int main ()
{
    fgets (str + 1, 200010, stdin);

    int n = strlen (str + 1) - 1;
    for (int i = 1; i <= n; ++i)
        prv[i] = i - 1;

    int lg = n;
    for (int i = 1; i <= n; ++i)
    {
        for (; i <= n && str[i] == 'T' && str[prv[i]] == 'S';)
        {
            lg -= 2;
            prv[i + 1] = prv[prv[i]];
            ++i;
        }
    }

    printf ("%d\n", lg);

    return 0;
}


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

const int N=600;

struct NODE{
    int to,id;NODE *nxt;
    NODE(){}
    NODE(int _t,int _i,NODE *_n):to(_t),id(_i),nxt(_n){}
};
struct GRAPH{
    NODE pol[N*N],*head[N+3],*ncnt;
    int du[N+3];
    void Init(){
        ncnt=pol;
    }
    void AddEdge(int u,int v,int id){
        NODE *p=++ncnt;
        *p=NODE(v,id,head[u]);head[u]=p;du[u]++;
    }
}G;

int n,m,del;
int frm[N*N];
int seid[N+3];
double Te[N+3],Se[N+3];
bool vis[N+3];
double mngx[N+3];

double FirDP(int u){
    if(vis[u]) return Te[u];
    vis[u]=true;
    if(u==n) return Te[u]=0;
    mngx[u]=0;
    for(NODE *it=G.head[u];it;it=it->nxt){
        int v=it->to;
        double resu=FirDP(v);
        if(mngx[u]<resu){
            mngx[u]=resu;
            seid[u]=it->id;
        }
        Te[u]+=(resu+1)/G.du[u];
    }
    return Te[u];
}
double DP(int u){
    if(vis[u]) return Te[u];
    vis[u]=true;
    if(u==n) return Te[u]=0;
    mngx[u]=1e9;
    if(u==del){
        for(NODE *it=G.head[u];it;it=it->nxt){
            int v=it->to;
            if(it->id==seid[u]) continue;
            double resu=DP(v);
            Te[u]+=(resu+1)/(G.du[u]-1);
        }
    }
    else{
        for(NODE *it=G.head[u];it;it=it->nxt){
            int v=it->to;
            Te[u]+=(DP(v)+1)/G.du[u];
        }
    }
    return Te[u];
}
int main(){
    G.Init();
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;scanf("%d%d",&u,&v);
        G.AddEdge(u,v,i);
        frm[i]=u;
    }
    double ans=FirDP(1);
    for(int i=1;i<=n;i++){
        if(!seid[i] || G.du[i]==1) continue;
        for(int j=1;j<=n;j++) Te[j]=vis[j]=0;
        del=i;
        ans=min(ans,DP(1));
    }
    printf("%.7f\n",ans);
    return 0;
}


Measured memory_bytes: 5632
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

S = input()


def is_valid(s):
    if len(s) & 1:
        return False
    return s == (s[:len(s) // 2]) * 2


for i in range(len(S) - 1, -1, -1):
    if is_valid(S[:i]):
        print(i)
        exit()


Measured memory_bytes: 38256
while True:
    try:
        N, M = map(int, input().split())
        
        dp = [0]*(10**5+5)
        for i in range(M):
            L, R = map(int, input().split())
            dp[L-1] += 1
            dp[R] -= 1
        
        cnt = 0
        ans = 0
        for i in range(N):
            cnt += dp[i]
            if cnt == M:
                ans += 1
            
        print(ans)
    except:
        break

Measured memory_bytes: 3956
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <utility>
#include <functional>
#include <map>
#include <string>
#include <set>
#include <math.h>

using namespace std;

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

  string str;
  cin >> str;

  int ans = 700;
  for (auto s : str) {
    if (s == 'o') {
      ans += 100;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

int f(int x){
    return (x - 1) % 3;
}

bool valid(int l, int r){
    if(f(l) <= f(r)) return true;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    while(1){
        cin >> s;
        if(s == "#") break;
        //start from left foot
        int l = s[0] - '0';
        int r = 3;
        int cnt = 0;
        int turn = 1;
        rep(i, 1, s.size()){
            if(turn){//move right
                if(valid(l, s[i] - '0')){
                    r = s[i] - '0';
                    turn = 0;
                }else{
                    l = s[i] - '0';
                    turn = 1;
                    cnt++;
                }
            }else{//move left
                if(valid(s[i] - '0', r)){
                    l = s[i] - '0';
                    turn = 1;
                }else{
                    r = s[i] - '0';
                    turn = 0;
                    cnt++;
                }
            }
        }
        int ans = cnt;
        //start from right foot
        l = 1;
        r = s[0] - '0';
        cnt = 0;
        turn = 0;
        rep(i, 1, s.size()){
            if(turn){//move right
                if(valid(l, s[i] - '0')){
                    r = s[i] - '0';
                    turn = 0;
                }else{
                    l = s[i] - '0';
                    turn = 1;
                    cnt++;
                }
            }else{//move left
                if(valid(s[i] - '0', r)){
                    l = s[i] - '0';
                    turn = 1;
                }else{
                    r = s[i] - '0';
                    turn = 0;
                    cnt++;
                }
            }
        }
        cout << min(ans, cnt) << endl;
    }
}


Measured memory_bytes: 3244
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int[] bSort = new int[n];
			for(int i = 0;i < n;i++){
				bSort[i] = scan.nextInt();
			}
			int count = 0;
			for(int i = 0;i < n;i++){
				for(int j = n-1;j > i;j--){
					if(bSort[j] < bSort[j-1]){
						swap(bSort,j,j-1);
						count++;
					}
				}
			}
			PrintOut(bSort,n);
			System.out.println(count);
		}
	}
	
	public static void swap(int[] a,int i,int j){
		int t = a[j];a[j] = a[i];a[i] = t;
	}
	
	public static void PrintOut(int[] a,int n){
		for(int i = 0;i < n;i++){
			System.out.print(a[i] + ((i == n-1)?"\n":" "));
		}
	}
}

Measured memory_bytes: 19088
N=int(input())
A=[int(x) for x in input().split()]
if 0 in A:
    print(0)
else:
    ans = 1
    for i in range(N):
        ans*=A[i]
        if ans>10**18:
            print(-1)
            break
    if ans<=10**18:
        print(ans)

Measured memory_bytes: 21704
#19:36
n,k = map(int,input().split())
mod = 10 ** 9 + 7
peer = [[] for _ in range(n)]
for _ in range(n-1):
  a,b = map(int,input().split())
  a -= 1
  b -= 1
  peer[a].append(b)
  peer[b].append(a)
now = [0]
pst = [[] for _ in range(n)]
seen = [0 for _ in range(n)]
seen[0] = 1
while now:
  last = now
  now = []
  for x in last:
    for y in peer[x]:
      if seen[y] == 0:
        seen[y] = 1
        now.append(y)
        pst[x].append(y)
#print(pst)
for i in range(n):
  if i == 0:
    ans = k
    for j in range(len(pst[0])):
      ans *= k-1-j
      ans %= mod
    continue
  for j in range(len(pst[i])):
    ans *= k-2-j
    ans %= mod
print(ans)

Measured memory_bytes: 79392
#include <bits/stdc++.h>
#define MAX 10000007
#define INF 1000000000000000000
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int a,b;
    cin>>a>>b;

    if(b%a)
        cout<<b-a<<endl;
    else
        cout<<a+b<<endl;


    return 0;
}


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

int main()
{
    int N, M, C;

    std::cin >> N >> M >> C;

    std::vector<int> B(M);
    std::vector<std::vector<int> > A(N, std::vector<int>(M));

    for (int i = 0; i < M; ++i) {
        std::cin >> B.at(i);
    }

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < M; ++j) {
            std::cin >> A.at(i).at(j);
        }
    }

    int n_correct_codes = 0;

    for (int i = 0; i < N; ++i) {
        int score = 0;
        for (int j = 0; j < M; ++j) {
            score += A.at(i).at(j) * B.at(j);
        }
        score += C;

        if (score > 0) {
            ++n_correct_codes;
        }
    }

    std::cout << n_correct_codes << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
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++)
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;


void solve() {
	int n; cin >> n; int l; cin >> l;
	int sum = 0;
	vector<int> v;
	rep1(i, n)sum += l + i - 1,v.push_back(l+i-1);
	int mi = mod;
	int ans;
	rep(i, n) {
		int csum = 0;
		rep(j, n) {
			if (i == j)continue;
			csum += v[j];
		}
		if (abs(sum - csum) < mi) {
			mi = abs(sum - csum); ans = csum;
		}
	}
	cout << ans << endl;
}

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,sum=0;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
        sum+=a[i];
    }
    ll part=0,mini=sum;
    rep(i,n){
        part+=a[i];
        mini=min(mini,abs(part-(sum-part)));
    }
    cout<<mini;
}

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

int main(){
  int n;
  static int a[200005], b[200005];
  
  cin >> n;
  rep(i, n){
    cin >> a[i] >> b[i];
  }

  int ans = 0;

  sort(a, a+n);
  sort(b, b+n);
  if(n%2==1){
    int mid = (n+1)/2;
    ans = b[mid-1]-a[mid-1]+1;
  }else{
    int mid1 = n/2;
    int mid2 = mid1+1;

    ans = b[mid1-1]+b[mid2-1]-a[mid1-1]-a[mid2-1]+1;
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 5160
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        string[] input1 = Console.ReadLine().Split(' ');
        int H = int.Parse(input1[0]);
        int W = int.Parse(input1[1]);
        string[] input2 = Console.ReadLine().Split(' ');
        int h = int.Parse(input2[0]);
        int w = int.Parse(input2[1]);
        int answer = H * W - (h * W + H * w) + h * w;
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#define mod 1000000007
#define MOD(x) ((x)%mod)
#define pii pair<int,int>
#define mp(a,b) make_pair(a,b)
using namespace std;
char s1[3005],s2[3005];
int len1,len2;
int dp[3005][3005];
int maxl;
char c[3005];
int main()
{
	scanf(" %s %s",s1,s2);
	len1=strlen(s1);
	len2=strlen(s2);
	for(int i=1;i<=len1;i++)
	{
		for(int j=1;j<=len2;j++)
		{
			dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			if(s1[i-1]==s2[j-1]) dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
			maxl=max(maxl,dp[i][j]);
			//printf("%d ",dp[i][j]);
		}
		//printf("\n");
	}
	int a=len1;
	int b=len2;
	int now=maxl;
	while(a*b)
	{
		if (dp[a-1][b-1]==now) a--,b--;
		else if(dp[a-1][b]==now) a--;
		else if(dp[a][b-1]==now) b--;
		else
		{
			c[now]=s2[b-1];
			a--;
			b--;
			now--;
		}
	}
	//printf("%d\n",maxl);
	for(int i=1;i<=maxl;i++)
		printf("%c",c[i]);
	return 0;
}



Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
const ll mod = 1e9 + 7;
ll inf = 1e16;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)


int main()
{
   fastio;
	ll n,w;
	cin>>n>>w;
	ll weights[n],values[n];
	for(int i=0;i<n;++i){
		cin>>weights[i]>>values[i];
	}
	ll dp[n+1][w+1];
	for(int i=0;i<=n;++i){
		for(int j=0;j<=w;++j){
			if(i==0 || j==0){
				dp[i][j] = 0;
			}else{
				// either pick that or not pick
				dp[i][j]  = dp[i-1][j];
				if(j >= weights[i-1]){
					dp[i][j] = max(dp[i][j], values[i-1]+ dp[i-1][j-weights[i-1]]);
				}
			}
		}
	}
	cout<<dp[n][w]<<endl;
	return 0;
}



Measured memory_bytes: 82500