akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n,m,x,y = map(int, input().split())
xl=list(map(int, input().split()))
yl=list(map(int, input().split()))

xl.sort()
yl.sort()

yr=min(yl[0],y)

if xl[-1]<yr and x<yr:
  print('No War')
else:
  print('War')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <cstdlib>
#include <cmath>
#include <functional>

#define INF 1000000000000000000
using namespace std;
typedef long long ll;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c - b == b - a)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
 
if sum(A) < sum(B):
    print(-1)
    exit(0)
 
t = 0
m = 0
L = []
for k in range(N):
    if A[k] > B[k]:
        L.append(A[k]-B[k])
    else:
        m += B[k] - A[k]
        t += 1
 
if m == 0:
    print(0)
    exit(0)
 
L = (sorted(L))[::-1]
for e in L:
    m -= e
    t += 1
    if m <= 0:
        break
print(t)

Measured memory_bytes: 82224
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& e : A) cin >> e;
  long long ans = 0, sum = 0;
  for (int i = 0; i < N; ++i) {
    if(A[i] != 0)sum += A[i];
    else {
      ans += sum / 2;
      sum = 0;
    }
  }
  ans += sum / 2;
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <queue>
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int map_max;
int map[110][110];
int rows;
int cols[110];
int howfar[110];
int far;
int visited[110];

void get_map();
void print_map();
int search(int node);
void print_result();
void check_result();

int main()
{

  get_map();
  //print_map();
  for(int i=0;i<map_max;i++)
    {
      visited[i]=1000;
    }
  search(1);
  check_result();
  print_result();
  return 0;
}

void check_result()
{
  for(int i=1;i<map_max;i++)
    {
      if(visited[i]==1000)
	{
	  visited[i]=-1;
	}
    }
}

void print_result()
{
  for(int i=0;i<map_max;i++)
    {
      std::cout << i+1 << " " << visited[i] << std::endl;
    }
}

void get_map()
{

  int k;
  scanf("%d", &map_max);//<100

  for(int i=0;i<map_max;i++)
    {
      scanf("%d", &k);
      scanf("%d", &cols[i]);
      for(int j=0;j<cols[i];j++)
	{
	  map[i][j]=0;
	  scanf("%d", &map[i][j]);
	}
    }

  
  return ;
}

void print_map()
{
  for(int i=0;i<map_max;i++)
    {
      for(int j=0;j<cols[i];j++)
	{
	  printf("%d", map[i][j]);
	}
      puts("");
    }
  return ;
}


int search(int node)
{
  far =1;
  int next =1, now,buf;
  visited[node-1]=0;
  
  queue<int> q;//push root node
  for(int i=0;i<cols[node-1];i++)
    {
      now = map[node-1][i];
      q.push(now);//
      visited[now-1]=visited[node-1]+1;
      
    }

  while(!q.empty())
  {
    next = q.front();
    q.pop();
    for(int i=0;i<cols[next-1];i++)
      {
	now = map[next-1][i];
	if(visited[now-1]==1000)
	  {
	    q.push(now);
	    visited[now-1]=min(visited[next-1]+1, visited[now-1]);
	  }
      }
  }

  return 0;
}

/*
  int search(int node, int far)
  {
  int now = node-1;
  if(visited[now] == 1)//searched
  {
  if(howfar[now]>far)
  {
  howfar[now]=far;
  }
  //return -1;
  }
  else
  {
  howfar[now]=far;
  visited[now]=1;

  //for(int i=0;i<cols[node-1];i++)
  //{
  //  //if(map[node-1][i]!=0)
  //  {
  //  search(map[node-1][i], far+1);
  //  }
  //}
  //return -1;
  }

  for(int i=0;i<cols[now];i++)
  {
  //if(map[now][i]!=0)
  {
  search(map[now][i], far+1);
  }
  }
    

  return -1;
  }
*/

Measured memory_bytes: 1260
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

struct UnionFind{
  vector<ll> par;
  vector<ll> rank;
  vector<ll> sz;

  UnionFind(ll n){init(n);}

  void init(ll n){
    par.resize(n), rank.resize(n), sz.resize(n);
    REP(i,n){par[i] = i, rank[i] = 0; sz[i] = 1;}
  }

  ll find(ll x){
    if(par[x] == x){return x;}else{return par[x] = find(par[x]);}
  }

  void unite(ll x, ll y){
    x = find(x), y = find(y);
    if(x==y) return;
    if(rank[x]<rank[y]){par[x] = y; sz[y] += sz[x];
    }else{
      par[y] = x;
      sz[x] += sz[y];
      if(rank[x]==rank[y]) rank[x]++;
    }
  }

  bool same(ll x, ll y){return find(x)==find(y);}

  ll size(ll x){return sz[find(x)];}
};

int main(){
  ll n,m;
  cin >> n >> m;
  UnionFind uf(n);
  int a[m], b[m];
  REP(i,m){
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
  }
  reverse(a,a+m);
  reverse(b,b+m);
  ll ans[m];
  ans[0] = n*(n-1)/2;
  REP(i,m-1){
    if(uf.same(a[i],b[i])){
      ans[i+1] = ans[i];
    }else{
      ans[i+1] = ans[i] - uf.size(a[i])*uf.size(b[i]);
      uf.unite(a[i],b[i]);
    }
  }
  reverse(ans,ans+m);
  REP(i,m) cout << ans[i] << endl;
  return 0;
}


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

using namespace std;

typedef long long int lli;

int n, mini = 100, match[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string table[8] = {"", "", "", "", "", "", "", ""};
vector<string> dp(10001, "");

string rec(int rem) {
    if (rem == 0 || dp[rem] != "") return dp[rem];
    
    string res = "";
    for (auto c : table) {
        if (c == "") continue;
        int rem_next = rem - match[c[0]-'0'];
        if (rem_next < 0 || (0 < rem_next && rem_next < mini)) continue;
        string tmp = c + rec(rem-match[c[0]-'0']);
        sort(tmp.begin(), tmp.end(), greater<char>());
        res = (res.size() == tmp.size()) ? max(res, tmp) : 
                (res.size() > tmp.size()) ? res : tmp;
    }

    return dp[rem] = res;
}

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

    int m;
    string a;
    cin >> n >> m;

    for (int i=0; i<m; i++) {
        cin >> a;
        table[match[a[0]-'0']] = max(table[match[a[0]-'0']], a);
        mini = min(mini, match[a[0]-'0']);
    }

    cout << rec(n) << endl;

    return 0;
}


Measured memory_bytes: 26752
#一回の交換をするための関数
def exchangeOne(x,y,z):
    return(((y+z)//2,(z+x)//2,(x+y)//2))
#全部偶数であるときにTrueを返す
def isAllEven(x,y,z):
    return(x%2==0 and y%2==0 and z%2==0)
A,B,C=map(int,input().split())
appeared=set() #一度現れた組み合わせを記録しておくための集合
appeared.add((A,B,C))
ans = 0
while isAllEven(A,B,C):
    A,B,C = exchangeOne(A,B,C)
    #ループを検出したら-1にしてシミュレーション終了
    if (A,B,C) in appeared:
        ans = -1
        break
    appeared.add((A,B,C))
    ans += 1
print(ans)

Measured memory_bytes: 3064
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(s: String);

    let char_vec: Vec<char> = s.chars().collect();
    for i in 0..s.len() - 1 {
        if char_vec[i] == char_vec[i + 1] {
            println!("{}", "Bad");
            return;
        }
    }
    println!("{}", "Good");
}


Measured memory_bytes: 2124
// #include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <complex>
#include <cstring>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;
const int INF = (int)2e9 + 1;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, temp;
  cin >> N;

  vector<int> seq;
  vector<int> slime;

  int n2 = 1 << N;
  for (int i = 0; i < n2; i++) {
    cin >> temp;
    seq.push_back(temp);
  }
  sort(seq.begin(), seq.end());
  slime.push_back(seq.back());
  seq.back() = -INF;
  int cnt;

  for (int i = 0; i < N; i++) {
    vector<int> pre = slime;
    sort(pre.begin(), pre.end());
    cnt = n2 - 1;
    while (pre.size() > 0 && cnt >= 0) {
      if (seq[cnt] != -INF) {
        if (seq[cnt] < pre.back()) {
          slime.push_back(seq[cnt]);
          pre.pop_back();
          seq[cnt] = -INF;
        }
      }
      cnt--;
    }
    if (pre.size() > 0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<string>
#include<list>
#include<vector>
#include<algorithm>
#include <numeric>
#include<queue>
#include <climits>

using namespace std;
/*
int main(int argc, char const *argv[])
{
	/*
	cin>>x;
	cout<<x<<endl;

	int a,b,c,i,j,n,m,ans=0;

	cin>>n>>m;
	vector<int> x(n);
	vector<pair<int,int>> y;
	for(i=0;i<n;i++){
		cin>>x[i];
	}
	for(i=0;i<m;i++){
		cin>>b>>c;
		v[i].

	}

}*/


int main(int argc, char const *argv[])
{
	/*
	cin>>x;
	cout<<x<<endl;
	*/
	int a,b,c=1,d,i,j,n,m,ans=0;

	cin>>n>>m;
	d=n;

	for(i=0;i<m;i++){
		cin>>a>>b;
		if(a>c){
			c=a;
		}
		if(b<d){
			d=b;
		}
	}
	ans=(d-c)+1;
	if(ans<0){
		ans=0;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int cnt[202020] = {0};

ll mlpow(ll x, ll p, ll mod) { //x^p(long long)%MOD
    ll tmp = 1;
    if(p == 0) return 1;
    //繰り返し二乗法
    while(p != 0) {
        if(p & 1) tmp = tmp*x % mod;
        x = x*x % mod;
        p = p >> 1;
    }
    return tmp;
}

int main() {
    int N; cin >> N;
    string X; cin >> X;
    queue<ll> ans;

    cnt[0] = 0; cnt[1] = 1;
    int pcnt = 0;
    ll ssum = 0, dsum = 0;
    rep(i, N-1) cnt[i+2] = cnt[(i+2)%__builtin_popcount(i+2)]+1;
    rep(i, N) if(X[i] == '1') pcnt++;

    if(pcnt == 0){
        rep(i,N) ans.push(1);
    }else if(pcnt == 1){
        rep(i,N) if(X[i] == '1') ssum = mlpow(2, N-1-i, 2);
        rep(i,N){
            if(X[i] == '1') ans.push(0);
            else{
                ans.push(cnt[(ssum+mlpow(2, N-1-i, 2))%2]+1);
            }
        }
    }else{
        rep(i,N){
            if(X[i] == '1') {
                ssum += mlpow(2, N-1-i, pcnt+1);
                ssum %= pcnt+1;
                dsum += mlpow(2, N-1-i, pcnt-1);
                dsum %= pcnt-1;
            }     
        }
        rep(i,N){
            if(X[i] == '1'){
                ans.push(cnt[(dsum-mlpow(2, N-1-i, pcnt-1)+pcnt-1)%(pcnt-1)]+1);
            }else{
                ans.push(cnt[(ssum+mlpow(2, N-1-i, pcnt+1))%(pcnt+1)]+1);
            }
        }
    }

    while(!ans.empty()) {
        cout << ans.front() << "\n";
        ans.pop();
    }
    return 0;
}


Measured memory_bytes: 6028
#include <iostream>
#include <vector>
#include <algorithm>

int a[100010], b[100010];

std::vector<unsigned long long> vec;

int main(){
    int n;
    std::cin >> n;
    unsigned long long t1 = 0, t2 = 0;
    for(int i = 0; i < n; i++){
        std::cin >> a[i];
        t1 += a[i];
    }
    int count = 0;
    long long delta = 0;
    for(int i = 0; i < n; i++) {
        std::cin >> b[i];
        t2 += b[i];
        if(a[i] < b[i]){
            count++;
            delta += (b[i] - a[i]);
        }else{
            vec.push_back(a[i]-b[i]);
        }
    }
    if(t1 < t2){
        std::cout << -1 << std::endl;
        return 0;
    }
    std::sort(vec.begin(), vec.end(), std::greater<unsigned long long>());
    int i = 0;
    while(1){
        if(delta <= 0){
            std::cout << count + i << std::endl;
            break;
        }
        delta -= vec[i];
        i++;
    }

}


Measured memory_bytes: 2040
N = int(input())
w=[]
for i in range(N):
    w.append(input())

def first_name(x):
    x = x[0]
    return x
w_first = list(map(first_name, w))
import collections
w_c=collections.Counter(w_first)
import itertools
from functools import reduce
march_list = ['M', 'A', 'R', 'C', 'H']
march_combinations = list(itertools.combinations(march_list,3))
ans = 0
for march_com in march_combinations:
    march_c = []
    for march in march_com:
        if not w_c.get(march) == None:
            march_c.append(w_c.get(march))
            ans_plus = reduce(lambda x, y: x * y, march_c)
    if len(march_c) == 3:
        ans += ans_plus
print(ans)
    




Measured memory_bytes: 11108
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
/* DSU 
int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}
void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}
*/ 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
 
using namespace std;

int main()
{
	fast;
	string s; cin>>s;
	int c = s[0];
	if(c >= 97 && c <= 122) cout << "a" << endl;
	else cout << "A" << endl;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long int ll;
typedef vector<pair<ll,ll> > Q;
typedef pair<int,int> P;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
const ll inf=1e9+7;
ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); }
ll lcm(ll a, ll b) { return a / (gcd(a, b)) * b; }

int main(){
  int b[101];
  int ans[101];

  int n;
  cin>>n;
  rep(i,0,n-1) cin>>b[i];

  ans[0]=b[0],ans[n-1]=b[n-2];
  rep(i,1,n-1) ans[i]=min(b[i],b[i-1]);

  int answer=0;
  rep(i,0,n) answer+=ans[i];

  cout<<answer<<endl;
  //rep(i,0,n) cout<<ans[i]<<endl;

}

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

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

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

    cout << ans;
    return 0;
}

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

#define MAX 100000

int head = 0;
int tail = 0;

pair<string, int> queue[100000];

void enqueue(pair<string, int> val) {
  queue[tail] = val;
  if(tail >= MAX - 1) {
    tail = 0;
  }
  else {
    tail++;
  }
}

bool isEmpty() {
  return head == tail;
}

pair<string, int> dequeue() {
  pair<string, int> val = queue[head];
  if(head >= MAX - 1) {
    head = 0;
  }
  else {
    head++;
  }
  return val;
}

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

  int time;
  cin >> time;

  char input[10];
  int data;
  for(int i = 0; i < n; i++) {
    pair<string, int> tmp;
    scanf("%s", input);
    scanf("%d", &data);

    tmp.first = input;
    tmp.second = data;
    enqueue(tmp);
  }

  int passedTime = 0;

  while(!isEmpty()) {
    pair<string, int> tmp = dequeue();
    if(tmp.second > time) {
      tmp.second -= time;
      passedTime += time;
      enqueue(tmp);
    }
    else {
      passedTime += tmp.second;
      tmp.second = 0;
      cout << tmp.first << " " << passedTime << endl;
    }
  }

  return 0;
}

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

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

    if (k * 500 >= x)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 29);
const ll LINF = 1e18;
const double PI = acos(-1);

template<typename T>vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value != 0>::type
fill_v(U& u, const V... v) { u = U(v...); }
template<typename T, typename U, typename... V>
typename enable_if<is_same<T, U>::value == 0>::type
fill_v(U& u, const V... v) { for (auto& e : u) fill_v<T>(e, v...); }
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 (a > b) { a = b; return 1; } return 0; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int S;
	cin >> S;
	int a = S / 100;
	int b = S % 100;
	bool ba = a == 0 || a > 12;
	bool bb = b == 0 || b > 12;
	if (ba & bb) {
		cout << "NA" << endl;
	}
	else if (ba) {
		cout << "YYMM" << endl;
	}
	else if (bb) {
		cout << "MMYY" << endl;
	}
	else {
		cout << "AMBIGUOUS" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
<?php
    $num = trim(fgets(STDIN));
     
    $number = strval($num);
     
    $check = 0;
    for($i = 0;$i < strlen($num);$i++ ){
    	if($number[$i] == $number[strlen($number)- 1 -$i]){
    		$check = 1;
    	}else{
    		$check = 0;
    		break;
    	}
    }
     
    if($check == 1){
    	echo 'Yes';
    }else{
    	echo 'No';
    }
    ?>
 

Measured memory_bytes: 3700
#include<iostream>
#include<math.h>

using namespace std;

int main(){
    double a, b, n;
    cin >> a >> b >> n;
    int ans;
    if (n < b - 1)
    {
        ans = floor((a * n) / b) - a * floor(n / b);
    }
    else
    {
        ans = floor(a * (b - 1) / b) - a*floor((b - 1) / b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N, A, B;
    cin >> N >> A >> B;

    int X[N];
    for(int i=0; i<N; i++) cin >> X[i];

    sort(X, X+N);

    int now = X[0];
    ll ans = 0;
    for(int i=0; i<N; i++){
        ll w = (ll)A*(X[i] - now);
        ll t = B;
        ans = ans + min(w, t);
        now = X[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 640
N, M = list(map(int, input().split()))
g = [[] for _ in range(N + 1)]  # 部屋mにつながっている部屋一覧
for m in range(M):
    a, b = list(map(int, input().split()))
    if a <= N and b <= N:
        g[a].append(b)
        g[b].append(a)

queue = [1]
d = [None] * (N + 1)
d[0] = 0
# d[1] = 0
while queue:
    v = queue.pop(0)
    for i in g[v]:
        # print('g[v]',g[v])
        if d[i] is None:
            d[i] = v
            queue.append(i)
        # print('d[i]',d[i],'queue',queue)
for i in range(N + 1):
    if d[i] is None:
        print('No')
        exit()
print('Yes')
for i in range(2, N + 1):
    print(d[i])


Measured memory_bytes: 33780
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H>>W;
  int i=0;
  while(i<W+2){
    cout<<"#";
    i++;
  }
   cout<<endl;
  for(int i=0;i<H;i++){
    string a;
    cin>>a;
    cout<<"#"<<a<<"#"<<endl;
  }
  i=0;
  while(i<W+2){
    cout<<"#";
    i++;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
vi d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << min(a, b) + min(c, d) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
int d[200];
int main(){
   int n;
   scanf("%d",&n);
   for(int i=0;i<n+n;i++)scanf("%d",d+i);
   sort(d,d+n+n);
   int ans=0;
   for(int i=1;i<n+n;i+=2){
      ans+=min(d[i],d[i-1]);
   }
   printf("%d\n",ans);
   return 0;
}


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};


signed main()
{   
  gearup;
  int n; cin >> n;
  map<int,int> mp;
  rep(i,n){
      int a; cin >> a;
      mp[a]++;
  }
  int even = 0,odd = 0;
  for(auto a:mp){
      if(a.second & 1)odd++;
      else even++;
  }
  int not_n = n - (odd+even); //余剰枚数
  int res =(odd + even) - ((not_n % 2 == 0)?0:1);
  out(res);
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cfloat>
#include <algorithm>
#include <set>
#include <memory>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double l_double;

#define vtr vector
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define st_ct static_cast // <>
#define TEST uint _ {}; cin >> _; while (_--)
#define PI (3.1415926535897932384626433832795)
#define MOD st_ct<int>(1e9 + 7)
#define EPS 1e-9
#define deb1(x) cerr << #x << " -> " << x << endl;
#define deb2(x,y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ")" << endl;
#define deb3(x,y,z) cerr << "(" << #x << ", " << #y << ", " << #z << ") -> (" << x << ", " << y << ", " << z << ")" << endl;
#define debVV(V) cerr << #V << ":\n" << V << endl; // 2D

// 1D
template<typename T>
istream& operator>>(istream &is, vector<T> &A) {
    for (T &v: A)
        is >> v;
    return is;
}

template <typename T>
ostream& operator<<(ostream &os, const vector<T> &A) {
    for (T const &v: A)
        os << v << " ";
    return os;
}

template<typename T>
void vtrV(const vector<T> &A)
{ for (T const &val: A) cout << val << endl; }

// 2D
template<typename T>
istream& operator>>(istream &is, vector<vector<T>> &A) {
    for (vector<T> &i: A)
        for (T &j: i)
            is >> j;
    return is;
}

template <typename T>
ostream& operator<<(ostream &os, const vector<vector<T>> &A) {
    for (vector<T> const &i: A) {
        for (T const &j: i)
            os << j << " ";
        os << endl;
    }
    return os;
}

template<typename T>
void vvtrNS(const vector<vector<T>> &A) {
    for (vector<T> const &i: A) {
        for (T const &j: i)
            cout << j;
        cout << endl;
    }
}

template<typename T>
T cntDigits(const T &N) { return (floor(log10(N)) + 1); }

template<typename T>
bool isPowOfTwo(const T &N) { return (N && (!(N&(N-1)))); }

template<typename T>
T lcm(T a, T b) { return ((a*b)/gcd(a, b)); }
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // cout.setf(std::ios::boolalpha);
    cout<<std::fixed;
    cout<<std::setprecision(6); // default
    /* -------------------------------- */

    int n {};
    cin >> n;
    set<string> arr {};
    while (n--) {
    	string s {};
    	cin >> s;
    	arr.insert(s);
    }
    cout << arr.size() << endl;
    return 0;
}

Measured memory_bytes: 19244
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ff first
#define ss second
#define eb emplace_back
#define MP make_pair
#define pb push_back
#define pf push_front
#define ins insert
#define endl '\n'
#define all(v) (v).begin(), (v).end()
#define mset(m,v) memset(m,v,sizeof(m))
#define tr(c,it) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n) for(lli i=0;i<(n);i++)
#define inc(i,a,b) for(lli i=a;i<=b;i++)
#define dec(i,a,b) for(lli i=a;i>=b;i--)
#define fr2(i,n) for(int i=0;i<(n);i++)
#define inc2(i,a,b) for(int i=a;i<=b;i++)
#define dec2(i,a,b) for(int i=a;i>=b;i--)
#define ymin(a,b)  (a=min((a),(b)))
#define ymax(a,b)  (a=max((a),(b)))
#define sz(x) (lli)(x).size()
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr<< *it << " = " << a << endl;
	err(++it, args...);
}

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<lli,lli> plli;
typedef vector<lli> vlli;
typedef vector<int> vi;
//typedef  vector<vector<lli> >ncr(1001,vector<lli>(1001,0))
typedef vector<plli> vplli;
long long MOD=1000000009;
#define addm(x,y) (x+y>=MOD? (x+y-MOD):(x+y))
int n;
lli dp[1<<16];
lli a[16][16];
// lli solve(lli mask)
// {
// 	cout<<mask<<endl;
// 	cout<<dp[mask]<<" yp"<<endl;
// 	if(mask>=(1<<n))
// 		return 0 ;
// 	if(dp[mask]!=-MOD)
// 	{
// 		cout<<"hi";
// 		return dp[mask];
// 	}
// 	vector<lli>temp;
// 	for(lli i=0;i<n;i++)
// 	{
// 		if(mask&(1<<i))
// 			temp.eb(i);

// 	}
// 	dp[mask]=0;
// 	for(lli p=0;p<temp.size();p++)
// 	{
// 		for(lli k=p+1;k<temp.size();k++)
// 				dp[mask]+=a[temp[p]][temp[k]];
// 	}
// 	cout<<dp[mask]<<endl;
// 	for(lli s=mask;s;s=(s-1)&mask)
// 	{
// 		dp[mask]=max(dp[mask],solve(s)+solve(s^mask));
// 	}
// 	return dp[mask];
// }
int main()
{
	// 	#ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS
	// clock_t start,end;
	// start=clock();
	// int t;
	// cin>>t;
	// for(int i=1;i<=t;i++)
	// {
	// 	cout<<"Case #"<<i<<": ";
	// 	solve();

	// }
	
	
	// end=clock();
	
	// double time_taken=double(end-start)/double(CLOCKS_PER_SEC);
	// cout<<fixed<<setprecision(10)<<time_taken<<" sec"<<endl;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
			cin>>a[i][j];
	}
	//mset(dp,-MOD);
	for(lli i=0;i<(1<<n);i++)
	{
		vector<lli>temp;
		for(lli j=0;j<n;j++)
		{
			if(i&(1<<j))
				temp.eb(j);
		}
		dp[i]=0;
		for(lli p=0;p<temp.size();p++)
		{
			for(lli k=p+1;k<temp.size();k++)
				dp[i]+=a[temp[p]][temp[k]];
		}
		//cout<<dp[i]<<" "<<i<<endl;
	}
	for(lli i=0;i<(1<<n);i++)
	{
		for(lli j=i;j>0;j=(j-1)&i)
			dp[i]=max(dp[i],dp[j]+dp[j^i]);
	}
	//cout<<solve(0)<<endl;
	cout<<dp[(1<<n)-1]<<endl;
}


Measured memory_bytes: 4152
n = int(input())
a = sorted(list(map(int,input().split())))
x = a.pop()
y = a[0]
m = abs(x/2 - a[0])
for i in range(1,n-1):
    if abs(x/2-a[i]) < m:
        y = a[i]
        m = abs(x/2-a[i])
print(x,y)
    

Measured memory_bytes: 14064
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author toshibablack
 */

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <fstream>
#include <functional>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define ll long long int
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) for(int i=0;i<n;++i)
#define FOREACH(x, a) for(auto& (x) : (a))
#define ALL(a) (a).begin(),(a).end()
#define COUT(x) out << (x) << endl;

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

using namespace std;


class DMegalomania {
public:
    int N;
    vector<pair<ll, ll>> P;

    void solve(std::istream& in, std::ostream& out) {
        in >> N;
        REP(i, N) {
            ll a, b;
            in >> a >> b;
            P.push_back(make_pair(b, a));
        }
        sort(ALL(P));
        ll sum = 0;
        REP(i, N) {
            sum += P[i].second;
            if (sum > P[i].first) { COUT("No"); return; }
        }
        COUT("Yes");
    }
};


int main() {
    DMegalomania solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 6128
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>
#include <cmath>
#include <stack>
#include <random>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

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

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

constexpr ll mod = 1e9+7;
const double PI = acos(-1.0);
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

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

  int h, w; cin >> h >> w;
  bool mat[h][w], mat1[h][w], mat2[h][w];
  rep(i, h) {
    rep(j, w) {
      char c; cin >> c;
      mat[i][j] = (c == '#');
      if (j==0) {
        mat1[i][j] = true;
      } else if (j==w-1) {
        mat1[i][j] = false;
      } else if (i&1) {
        mat1[i][j] = true;
      } else {
        mat1[i][j] = false;
      }
      mat2[i][j] = !mat1[i][j];
    }
  }

  rep(i, h) {
    rep(j, w) {
      if (mat[i][j]) {
        mat1[i][j] = mat2[i][j] = true;
      }
    }
  }

  rep(i, h) {
    rep(j, w) {
      if (mat1[i][j]) {
        cout << '#';
      } else {
        cout << '.';
      }
    }
    cout << '\n';
  }
  cout << '\n';
  rep(i, h) {
    rep(j, w) {
      if (mat2[i][j]) {
        cout << '#';
      } else {
        cout << '.';
      }
    }
    cout << '\n';
  }
}


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

int main() {
  int H, W;
  cin >> H >> W;
  Graph c(10, vector<int>(10));
  rep(i,10) rep(j,10) cin >> c[i][j];
  Graph A(H, vector<int>(W));
  rep(i,H) rep(j,W) cin >> A[i][j];

  // Warshall-Floyd
  rep(i,10) {
    rep(j,10) {
      rep(k,10) {
        if (c[j][k] > c[j][i] + c[i][k]) {
          c[j][k] = c[j][i] + c[i][k];
        }
      }
    }
  }

  int sum = 0;
  rep(i,H) {
    rep(j,W) {
      if (A[i][j] != -1) {
        sum += c[A[i][j]][1];
      }
    }
  }

  cout << sum << endl;
  return 0;
}


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

int main() {
	string s;
	cin >> s;
	int n = s.size();
	int res = n;
	for (char c = 'a'; c <= 'z'; c++) {
		int cur = 0, ans = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == c) {
				ans = max(ans, cur);
				cur = 0;
			} else {
				cur++;
			}
		}
		ans = max(ans, cur);
		res = min(res, ans);
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
if K < 32:
    print(list[K-1])
else:
    print(list[31])

Measured memory_bytes: 3064
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Possible")
#define p_no() p("Impossible")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

struct Point{
    ll x;
    ll y;
    Point(ll x, ll y): x(x), y(y) {}

    string ToString(){
        stringstream ss;
        ss << "[point] " << x << " " << y;
        return ss.str();
    }
};

bool inside(int x, int y, int W, int H){
    if(0<=x && x < W && 0<=y && y<H){
        return true;
    }else{
        return false;
    }
}

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

    // input
    ll H, W;
    cin >> H >> W;

    ll sharp_num = 0;
    FOR(i, 0, H){
        string s;
        cin >> s;

        for(char c : s){
            if(c=='#'){
                sharp_num++;
            }
        }
    }

    if(sharp_num == W + H - 1){
        p_yes();
    }else{
        p_no();
    }
    
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall, csgraph_to_dense
from scipy.sparse import issparse
sys.setrecursionlimit(10**7)

n, m, l = [int(i) for i in sys.stdin.readline().split()]
graph = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a, b, c = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a][b] = c
    graph[b][a] = c

res = floyd_warshall(csgraph_from_dense(graph))
if issparse(res):
    res = csgraph_to_dense(res)
res = np.where(res <= l, 1, 0)
new_res = floyd_warshall(res)
new_res[new_res == np.inf] = 0
q = int(input())
for j in range(q):
    s, t = [int(i) for i in sys.stdin.readline().split()]
    s -= 1
    t -= 1
    dis = new_res[s, t]
    print(int(dis) - 1)

Measured memory_bytes: 21056
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
int ary[40][40] = {-1};

int main() {
    int n,m;
    cin >> n >> m;
    for(int i=1; i<=n; i++) {
        int k;
        cin >> k;
        for(int j=0; j<k; j++) {
            int a;
            cin >> a;
            ary[i][a] = 1;
        }
    }
// for(int i=1; i<=n; i++) {
//     for(int j=1; j<=m; j++) {
//         cout << ary[i][j];
//     }
//     cout << endl;
// }

    int v = 0;
    for(int i=1; i<=m; i++) {
        int flag = 1;
        for(int j=1; j<=n; j++) {
            if(ary[j][i] != 1) {
                flag = 0;
                break;
            }
        }
        if(flag) v++;
    }
    cout << v << endl;
}


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

bool comp(string a, string b){
    bool flag = false;
    for(int i = 0 ; i < a.length();i++){
        if(a[i] == b[i]){
            continue;
        }else if(a[i] > b[i]){
            flag = false;
            break;
        }else if(b[i] > a[i]){
            flag = true;
            break;
        }
    }
    return flag;
}
int main(){
    int N,L;
    cin >> N >>L;

    vector<string> S(N);

    for(int i = 0 ; i < S.size() ; i++){
        cin >> S[i];
    }
    sort(S.begin(),S.end(),comp);

    for(int i = 0 ; i < S.size(); i++){
        cout << S[i];
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    int N = S.size();
    int ans = N;
    for(int i=0;i<N-1;i++) if(S[i]!=S[i+1]){
        ans = min(ans,max(i+1,N-i-1));
    }
    cout << ans << "\n";
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<time.h>
using namespace std;

int main() {
	long long n, m, ans = 1;
	cin >> n >> m;
	if (abs(n - m) > 1) {
		ans = 0;
	}
	else {
		if (n == m) {
			for (int i = 1; i <= n; ++i) {
				ans = (((ans*i) % 1000000007)*i) % 1000000007;
			}
			ans = (ans * 2) % 1000000007;
		}
		else {
			for (int i = 1; i <= min(n, m); ++i) {
				ans = (((ans*i) % 1000000007)*i) % 1000000007;
			}
			ans = (ans*max(m, n)) % 1000000007;
		}
	}
	cout << ans << endl;
}

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

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

using namespace std;

int main(){
	for(int W,Q;scanf("%d%d",&W,&Q),W||Q;){
		int wall[100];
		memset(wall,-1,sizeof(wall));
		rep(i,Q){
			char c;	scanf(" %c",&c);
			if(c=='s'){
				int id,a;	scanf("%d%d",&id,&a);
				int pos=-1;
				rep(i,W)if(wall[i]==-1){
					bool ok=true;
					rep(j,a)if(i+j==W || wall[i+j]!=-1){ ok=false; break; }
					if(ok){
						rep(j,a)	wall[i+j]=id;
						pos=i;
						break;
					}
				}
				if(~pos)	printf("%d\n",pos);
				else		puts("impossible");
			}
			else{
				int id;	scanf("%d",&id);
				rep(i,W)if(wall[i]==id)	wall[i]=-1;
			}
		}
		puts("END");
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=100005;
int n,m,x[N],a[N];
int b[N],vis[N],tmp[N],t;
int ans[N];
LL K;
int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	scanf("%d%lld",&m,&K);
	for (int i=1;i<n;i++)
		b[i]=i;
	for (int i=1;i<=m;i++){
		scanf("%d",&a[i]);
		swap(b[a[i]-1],b[a[i]]);
	}
	memset(vis,0,sizeof vis);
	for (int i=1;i<n;i++){
		if (vis[i])
			continue;
		vis[i]=1;
		tmp[t=1]=i;
		for (int j=b[i];j!=i;j=b[j])
			vis[tmp[++t]=j]=1;
		int d=K%t;
		for (int j=1;j<=t;j++)
			ans[tmp[j]]=tmp[(j-1+d)%t+1];
	}
	LL tot=x[1];
	printf("%lld\n",tot);
	for (int i=1;i<n;i++)
		printf("%lld\n",tot+=x[ans[i]+1]-x[ans[i]]);
	return 0;
}

Measured memory_bytes: 3584
import numpy as np
C = []
for i in range(3):
  C.append(list(map(int,input().split())))

frag = True
c = np.zeros((3,3))
for a1 in range(0,C[0][0] + 1):
  b1 = C[0][0] - a1
  b2 = C[1][0] - a1
  b3 = C[2][0] - a1
  a2 = C[0][1] - b1
  a3 = C[0][2] - b1
  c[:,0] += a1
  c[:,1] += a2
  c[:,2] += a3
  c[0,:] += b1
  c[1,:] += b2
  c[2,:] += b3
  
  frag = True
  for i in range(3):
    for j in range(3):
      if C[i][j] != c[i][j]:
        frag = False
  
  if frag:
    print("Yes")
    break
if frag == False:
  print("No")

Measured memory_bytes: 14552
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
const int MOD = 1e9 + 7;
int fat[MAX];

int modify(int x) {
    x %= MOD;
    if (x < 0) x += MOD;
    return x;
}

inline int add(int a, int b) {
    a = modify(a);
    b = modify(b);
    a += b;
    if (a >= MOD) a -= MOD;
    return a;
}

inline int sub(int a, int b) {
    a = modify(a);
    b = modify(b);
    return (a - b + MOD) % MOD;
}

inline int mult(int a, int b) {
    a = modify(a);
    b = modify(b);
    return (1LL * a * b) % MOD;
}

int f_exp(int x, int e) {
    if (e == 0) return 1;
    if (e & 1) return mult(x, f_exp(x, e - 1));
    return f_exp(mult(x, x), e / 2);
}

inline int inv(int x) {
    return f_exp(x, MOD - 2);
}

inline int comb(int n, int k) {
    if (k > n) return 0;
    return mult(fat[n], mult(inv(fat[n - k]), inv(fat[k])));
}

void preprocess() {
    fat[0] = 1;
    fori (i, 1, MAX) {
        fat[i] = mult(fat[i - 1], i);
    }
}

void solve() {
    preprocess();
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    fori (i, 0, n) cin >> v[i];
    sort(begin(v), end(v));
    int ans = 0;
    fori (i, 0, n) {
        {
            int ways = comb(i, k - 1);
            int cur = mult(v[i], ways);
            ans = add(ans, cur);
        }

        {
            int ways = comb(n - i - 1, k - 1);
            int cur = mult(v[i], ways);
            ans = sub(ans, cur);
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, K, p[1000];
    cin >> N >> K;
    REP(i, N) cin >> p[i];
    sort(p, p + N);
    ll ans = 0;
    REP(i, K) ans += p[i];
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bits/stdc++.h>
#include<queue>
#include <numeric>
#include<stdio.h>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    int A,B,C,D; 
    cin >> A >> B >> C >> D;
    int sta=max(A,C);
    int fin=min(B,D);
    if(fin-sta<=0){
        cout << 0;
    }
    else{
        cout << fin-sta;
    }
    }

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		WriteLine(F * 0 + G.Aggregate(GCD));
	}
	public static int GCD(int n, int m)
	{
		while (m > 0) { var c = n % m; n = m; m = c; }
		return n;
	}
}


Measured memory_bytes: 21728
mod = 10**9 + 7


def comb(n, k):
    x, y = 1, 1
    k = min(k, n - k)
    for i in range(k):
        x *= n - i
        x %= mod
        y *= i + 1
        y %= mod
    return x * pow(y, mod - 2, mod) % mod


def solve(string):
    n, m, k = map(int, string.split())
    base = n * m * ((n + 1) * (m + 1) * (n + m - 2) - n**2 - m**2 + 2) // 6 % mod
    return str(base * comb(n * m - 2, k - 2) % mod)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 3064