akhauriyash/Code-Regression huggingface dataset:
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

const ll INF = LONG_MAX;
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; }

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int n;
    cin >> n;

    map<int, int> m;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        m[tmp]++;
    }

    for (auto it = m.begin(); it != m.end(); it++) {
        if (it->second > 1) {
            cout << "NO";
            return 0;
        }
    }

    cout << "YES";

    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 9600
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	char c;
	int s;
	for(int i=1;i<=3;i++)
	{
		cin>>c;
		if(c=='a')
		{
			s+=1;
		}
		else if(c=='b')
		{
			s+=2;
		}
		else
		{
			s+=4;
		}
	}
	if(s==7)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

using namespace std;

int main()
{
  double a, b, c, d, e, f;
  while ( cin >> a >> b >> c >> d >> e >> f )
    {
      double det = a * e - b * d;
      double x = round(((c * e - b * f) / det) * 1000) / 1000;
      double y = round(((a * f - c * d) / det) * 1000) / 1000;
      if ( abs( x ) < 0.001 ) x = 0.0;
      if ( abs( y ) < 0.001 ) y = 0.0;
      cout << fixed << setprecision(3) << x << " " << y << endl;
    }
  return 0;
}

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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) ll(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<ll,ll>;
using Pl = pair<ll,ll>;
using vi = vector<ll>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const ll dx[] = {0,1,0,-1,1,1,-1,-1};
const ll dy[] = {1,0,-1,0,1,-1,-1,1};
const ll inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  ll d;
  cin >> d;
  ll k = 26;
  vi c(k);
  rep(i,k) cin >> c[i];
  vii s(d,vi(k));
  rep(i,d)rep(j,k) cin >> s[i][j];
  vi t(d);
  rep(i,d) cin >> t[i];
  vi p(k);
  vi lastday(k);
  rep(i,d) {
    ll today = t[i]-1;
    p[today] += s[i][today];
    lastday[today] = i+1;
    rep(j,k) {
      p[j] -= c[j] * (i+1 - lastday[j]);
    }
    ll ans = 0;
    rep(j,k) ans += p[j];
    cout << ans << endl;
  }
}

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

int W,H;
int vis[50][50][50][50] = {};
int dx[4] = {-1,1,0,0},dy[4] = {0,0,-1,1};
string F[2][50];
int s0x,s0y,s1x,s1y,g0x,g0y,g1x,g1y;
        
bool in(int x,int y,int c){
    return 0<=x && x<H && 0<=y && y<W && F[c][x][y]!='#';
}

bool goal(int x,int y,int c){
    if(c==0) return g0x==x && g0y==y;
    else return g1x==x && g1y==y;
}

struct state{
    int x0,y0,x1,y1;
};


int main(){
    while(cin >> W >> H && W>0){
        for(int i=0;i<H;i++) for(int j=0;j<W;j++) for(int k=0;k<H;k++) for(int l=0;l<W;l++) vis[i][j][k][l] = 0;
        for(int i=0;i<H;i++){
            cin >> F[0][i] >> F[1][i];
            for(int j=0;j<W;j++) if(F[0][i][j]=='L'){s0x = i; s0y = j;}
            for(int j=0;j<W;j++) if(F[1][i][j]=='R'){s1x = i; s1y = j;}
            for(int j=0;j<W;j++) if(F[0][i][j]=='%'){g0x = i; g0y = j;}
            for(int j=0;j<W;j++) if(F[1][i][j]=='%'){g1x = i; g1y = j;}            
        }
        queue<state> Q;
        Q.push({s0x,s0y,s1x,s1y});
        vis[s0x][s0y][s1x][s1y] = 1;
        while(!Q.empty()){
            state now = Q.front(); Q.pop();
            for(int i=0;i<4;i++){
                int n0x = now.x0+dx[i],n0y = now.y0+dy[i],
                n1x = now.x1+dx[i],n1y = now.y1-dy[i];
                if(!in(n0x,n0y,0) && in(n1x,n1y,1) && vis[now.x0][now.y0][n1x][n1y]==0){
                    if(goal(now.x0,now.y0,0) xor goal(n1x,n1y,1)) continue;
                    vis[now.x0][now.y0][n1x][n1y] = 1;
                    Q.push({now.x0,now.y0,n1x,n1y});
                }
                if(in(n0x,n0y,0) && !in(n1x,n1y,1) && vis[n0x][n0y][now.x1][now.y1]==0){
                    if(goal(n0x,n0y,0) xor goal(now.x1,now.y1,1)) continue;
                    vis[n0x][n0y][now.x1][now.y1] = 1;
                    Q.push({n0x,n0y,now.x1,now.y1});
                }
                if(in(n0x,n0y,0) && in(n1x,n1y,1) && vis[n0x][n0y][n1x][n1y]==0){
                    if(goal(n0x,n0y,0) xor goal(n1x,n1y,1)) continue;
                    vis[n0x][n0y][n1x][n1y] = 1;
                    Q.push({n0x,n0y,n1x,n1y});
                }
            }
        }
        cout << (vis[g0x][g0y][g1x][g1y]? "Yes":"No") << endl;
    }
}


Measured memory_bytes: 28300
import java.util.*;

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

    long a = sc.nextLong();
    long b = sc.nextLong();

    long d = a / b;
    long r = a % b;
    double f = (double)a / (double)b;

    System.out.println(d + " " + r + " " + String.format("%.8f", f));
  }
}



Measured memory_bytes: 26400
import sys
import numpy as np
N = int(sys.stdin.readline())
A = np.array(sys.stdin.readline().split(), dtype=np.int32)

"""
A = [10,4,8,7,3]
is_left_end = [1,0,1,0,0]
left_idx = [0,0,2,2,2]
というものを作る
"""
is_left_end = np.empty(N, dtype=np.bool)
is_left_end[0] = 1
is_left_end[1:] = (A[1:] > A[:-1])


left_idx = np.where(is_left_end, np.arange(N), 0) # [0,0,2,0,0]
np.maximum.accumulate(left_idx, out=left_idx) # [0,0,2,2,2]

answer = (np.arange(N) - left_idx).max()
print(answer)


Measured memory_bytes: 24312
import java.math.BigInteger;
import java.util.*;  

/*求最大公约数和最小公倍数*/  
public class Main {  
  
    public static void main(String[] args) {  
        Scanner cin = new Scanner(System.in);// 接收控制台输入的信息  
        int n;
        n = cin.nextInt();
        
        BigInteger ans = BigInteger.valueOf(1);
        for(int i=1 ;i<=n ;i++) {
        	BigInteger x;
        	x = cin.nextBigInteger();
        	BigInteger tem = ans.gcd(x);
        	ans = ans.multiply(x);
        	ans = ans.divide(tem);
        }
        System.out.println(ans);
    }  
}  

Measured memory_bytes: 22100
from itertools import accumulate
a=[]
for i in range(12):
    a.append(26**i)
b=list(accumulate(a))

alpha=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

N=int(input())

num=0
for i in range(12):
    if N < b[i] :
        num=i
        break

M=N-b[num-1]
r=M
for i in range(num):
    q=r//26**(num-i-1)
    r=r%26**(num-i-1)
    print(alpha[q],end='')

Measured memory_bytes: 62148
#include <bits/stdc++.h>
using namespace std;
int main()
{long long t,i,n,k,x,y,m,j;
string s;
cin>>s;x=0;
if(s[0]=='R')x=x+1;if(s[1]=='R')x=x+1;if(s[2]=='R')x=x+1;
if(x==2){if(s[1]=='S')cout<<1;else cout<<x;}
else cout<<x;
return 0;}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
#define Max(a) (*max_element(ALL(a)))
#define Min(a) (*min_element(ALL(a)))
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  vi A(n),B(n);
  for(int i=0;i<n;i++){
    cin>>A[i]>>B[i];
    if(n%2 == 0){
      A[i]*=2;B[i]*=2;
    }
  }
  sort(ALL(A));
  sort(ALL(B));
  if(n%2){
    cout<<B[n/2]-A[n/2]+1<<endl;
  }else{
    cout<<1+(B[n/2]+B[n/2-1])/2 - (A[n/2]+A[n/2-1])/2<<endl;
  }
  return 0;
}


Measured memory_bytes: 6368
import math
while True:
    n = int(input())
    if n==0:
        break
    si = [int(x) for x in input().split()]
    sum = 0
    m = 0
    for i in range(n):
        m += si[i]
    m = m/n
    for i in range(n):
        sum += (si[i]-m)**2
    print(math.sqrt(sum/n))
    


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

long long n,m,count_a;
vector<long long> nnum(1000010,0);
vector<vector<long long>> g(1000010);

void dfs(long long i) {
  for (auto x : g[i]) {
    if (nnum[x]==0) {
	  nnum[x]=1;
	  count_a++;
	  dfs(x);
	}
  }
}


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

  for (long long i=0;i<m;i++) {
    long long a,b;cin >> a >> b;
	g[a-1].push_back(b-1);
	g[b-1].push_back(a-1);
  }

  long long count=0;
  
  for (long long i=0;i<n;i++) {
    if (nnum[i]==0) {
	  count_a=0;
	  nnum[i]=1;
	  count_a++;
	  dfs(i);
	  if (count<count_a) {count=count_a;}
	}
	
  }
  cout << count << endl;
}

Measured memory_bytes: 46880
def main():
    from math import gcd

    K = int(input())

    result = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            t = gcd(a, b)
            for c in range(1, K + 1):
                result += gcd(t, c)
    print(result)


main()

Measured memory_bytes: 9180
// ------------------
// author: MatsuTaku
// date  : 19/02/2020
// ------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int N,K; cin>>N>>K;
  vector<int> H(N); for (auto& h : H) cin>>h;
  sort(H.rbegin(), H.rend());
  ll sum = 0;
  for (int i = K; i < N; i++) {
    sum += H[i];
  }
  cout << sum << endl;

  return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
  return b ? gcd(b, a % b) : a;
}

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

//実行部
void Main()
{
  ll R, G, B, N; cin >> R >> G >> B >> N;
  ll flag = 0;
  for(ll i = 0;i <= N / R;i++)
  {
    for(ll j = 0;j <= N / G;j++)
    {
      if((N - R * i - G * j) % B == 0&&(N - R * i - G * j) >= 0)
      {
        flag++;
      }
    }
  }
  fin(flag)
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
int main(){
    int n;
    long long a[300300];
    cin>>n;
    long long cnt[100];
    REP(i,61)cnt[i]=0;
    REP(i,n){
        cin>>a[i];
        for(int j=0;j<61;j++){
            long long aa=a[i]>>j;
            // cout<<aa<<endl;
            if(aa==0)break;
            cnt[j]+=aa&1;
        }
    }
    long long mod=1000000007;
    long long ans=0;
    // REP(i,60)cout<<cnt[i]<<" ";cout<<endl;
    for(long long i=0;i<61;i++){
        // cout<<"ok"<<endl;
        // cout<<(cnt[i]*(n-cnt[i])*(1LL<<i)%mod)<<endl;
        // cout<<(1<<i)<<endl;
        ans+=((cnt[i]*(n-cnt[i])%mod)*((1LL<<i)%mod));
        ans%=mod;
    }
    cout<<ans%mod<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

int DFS(int V,vector<vector<int> >&GRAPH , vector<int> & DP)
{
  if(DP[V] != -1)return DP[V];
  int res = 0;
  for (int i = 0; i < GRAPH[V].size(); i++)
  {
    chmax(res,DFS(GRAPH[V][i],GRAPH,DP)+1);
  }
  return DP[V] =res;
  
  
}
//SOLVE
void solve(void)
{
  int N,M;
  cin>>N>>M;
  vector<vector<int> > GRAPH (N);
  for (int i = 0; i < M; i++)
  {
    int A,B;
    cin>>A>>B;
    A--;B--;
    GRAPH[A].push_back(B);
  }
  vector<int> DP(N,-1);
  int ANS = 0;
  for (int i = 0; i < N; i++)
  {
    chmax(ANS,DFS(i,GRAPH,DP));
  }
  cout<<ANS<<endl;
  

  
  
  return;
}


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

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 9216
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
	string a,b;
	vector<int> ans;
	int n,tmp,carry,num;
	bool flag = true;
	cin >> n;
	
	for(int i=0; i<n; i++){
		ans.clear();
		cin >> a >> b;
		int ai = a.size()-1;
		int bi = b.size()-1;
		
		if(ai < 0 && bi < 0 && carry==0){
			cout << "overflow";
			flag = false;
		}
		carry = 0;
		while(ai >= 0 || bi >= 0){
			tmp=0;
			if(ai >= 0) tmp += (a[ai] - '0');
			if(bi >= 0) tmp += (b[bi] - '0');
			ans.push_back((tmp+carry)%10);
			carry = (tmp+carry)/10;
			ai--; bi--;
		}
		
		if(carry != 0) ans.push_back(carry);
		
		if(flag == true){
		
			if(ans.size() > 80){
				cout << "overflow";
				//flag = false;
			}
		
			else{
				for(int j=ans.size()-1; j>=0; j--)
					cout << ans[j];
			}
			
		}
		
	cout << endl;
	
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(void){
    while(1){
        int n; int jewel[21][21]={0};
        scanf("%d",&n); if(n==0) break;
        int x,y;
        for(int i=0;i<n;i++){
            scanf("%d%d",&x,&y);
            jewel[y][x]=1;
        }
        int m; x=10,y=10;
        int ans=0;
        scanf("%d",&m); getchar();
        for(int i=0;i<m;i++){
            char c; int len,d=0;
            scanf("%c%d",&c,&len); getchar();
            //printf("%c\n",c);
            switch(c){
                case 'N':d=0; break;
                case 'E':d=1; break;
                case 'S':d=2; break;
                case 'W':d=3; break;
            }
            for(int j=0;j<len;j++){
                x+=dx[d]; y+=dy[d];
                if(jewel[y][x]){
                    jewel[y][x]=0;
                    ans++;
                }
            }
        }
        if(ans==n) printf("Yes\n");
        else printf("No\n");
    }
}



Measured memory_bytes: 1976
K = int(input())
A = [int(a) for a in input().split()]
ma = mi = 2
while A:
    a = A.pop()
    mi = (mi+a-1) // a * a
    ma = (ma) // a * a + (a-1)
    if mi > ma:
        print(-1)
        exit()

print(mi, ma)

Measured memory_bytes: 14252
open Batteries

let () =
  let n, m = Scanf.scanf "%d %d" (fun x y -> x, y) in
  let cakes = Array.init n (fun i ->
    Scanf.scanf " %d %d %d" (fun x y z -> (i, x, y, z))) in
  (0--7) |> Enum.map (fun b ->
    let s = Array.init 3 (fun i -> if b land (1 lsl i) <> 0 then 1 else -1) in
    let sx, sy, sz = List.init n (fun i ->
      let _, x, y, z = cakes.(i) in
      (s.(0) * x + s.(1) * y + s.(2) * z, x, y, z))
    |> List.sort (fun x y -> compare y x)
    |> List.take m
    |> List.fold_left (fun (sx, sy, sz) (_,x,y,z) -> (sx+x, sy+y, sz+z)) (0, 0, 0)
    in
    abs sx + abs sy + abs sz)
  |> Enum.fold max 0 |> Printf.printf "%d\n"


Measured memory_bytes: 5248
#!/usr/bin/env python3
import sys


def solve_iter(N: int, X: "List[int]"):
    Y = sorted(X)
    m = sum(Y[N//2-1:N//2+1]) / 2
    for x in X:
        if x < m:
            yield Y[N//2]
        else:
            yield Y[N//2-1]


def solve(N: int, X: "List[int]"):
    if N == 2:
        return X[::-1]
    return list(solve_iter(N, X))

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(*solve(N, X), sep='\n')

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


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


int main()
{
    string S, T;
    cin >> S;
    cin >> T;

    if (S.size() < T.size()) {
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    
    int beginSubstring = -1;
    for( int i = 0; i <= S.size()-T.size(); ++i ){
        bool isMatch = true;
        for( int j = 0; j < T.size(); ++j ){
            if( S[i+j] != T[j] && S[i+j] != '?' ){
                isMatch = false;
                break;
            }
        }
        if( isMatch ) beginSubstring = i;
    }

    if( beginSubstring < 0 ) cout << "UNRESTORABLE" << endl;
    else{
        string ans;
        for( int i = 0; i < S.size(); ++i ){
            if( i == beginSubstring ){
                ans += T;
                i += T.size() - 1;
            }else if( S[i] == '?' ) ans += 'a';
            else ans += S[i];
        }
        cout << ans << endl;
    }
    
    return 0;
}

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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

ll pow_f(ll b, ll e) {
    ll ans = 1;
    b = b % M;
    while (e) {
        if (e&1) {
            ans = (ans * b) % M;
        }
        b = (b * b) % M;
        e >>= 1;
    }
    return ans;
}

ll nCr(ll n, ll r) {
    if (r > n || n < 0 || r < 0) { return 0; }
    if (n == r || r == 0) { return 1; }
    r = min(r, n-r);
    ll ans = 1;
    for (ll i = 1; i <= r; ++i) {
        ans = (ans * (n-i+1))/(i); 
    }
    return ans;
}

ll nCr(tuple<ll,ll> t) {
    auto n = get<0>(t);
    auto k = get<1>(t);
    return nCr(n+k-1, k);
}

template<typename T>
void print(T v) {
    cout << v << " ";
}

template<typename T>
void print(vector<T> v) {
    for (auto &i : v) {
        print(i);
    }
    cout << endl;
}

void solve() {
    ll L;
    cin >> L;
    long double d = L/3.0L;
    cout << fixed << setprecision(9) << d*d*d << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef D_LOCAL
        freopen("in.in", "r", stdin);
        freopen("out.out", "w", stdout);
    #endif

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> vec(n,0);
  rep(i,k){
    cin >> t1;
    rep(j,t1){
      cin >> t2;
      t2--;
      vec[t2]++;
    }
  }
  ll ans = 0;
  rep(i,n){
    if(vec[i] == 0){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,a,b) for(int i=a ; i<b ; i++)
const int max_n = 1e5;
const ll mod = 1e9+7;
const ll INF = 1LL<<60;
typedef long double ld;
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; }

int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
int main(){
  int h,n;  cin >> h >> n;
  vector<int> a(n),b(n);
  rep(i,0,n){
    cin >> a[i] >> b[i];
  }
  ll dp[h+1];
  rep(i,0,h+1){
    dp[i] = INF;
  }
  dp[0] = 0;
  rep(i,0,n){
    rep(j,0,h+1){
      chmin(dp[min(h,j+a[i])], dp[j]+b[i]);
    }
  }
  cout << dp[h] << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long int;

const LL MOD = 1000000007;

LL mpow(LL a, LL x) {
	if (x == 0)return 1;
	LL half = mpow(a, x / 2);
	half *= half;
	half %= MOD;
	if (x % 2) {
		half *= a;
		half %= MOD;
	}
	return half;
}


int N;
int par[222222];
vector<int>child[222222];
int vnum[222222];
int cnt[222222];
int dep[222222];

void dfs(int v, int cou) {
	dep[v] = cou;
	for (int ch : child[v]) {
		dfs(ch, cou + 1);
	}
}

struct node {
	LL nil, one;
	LL sum;
};

node operator+(const node&n1, const node&n2) {
	LL nil = (n1.nil * n2.nil) % MOD;
	LL one = (n1.nil * n2.one + n1.one * n2.nil) % MOD;
	return {
		nil,one,n1.sum + n2.sum
	};
}

void merge(vector<node> &prime, vector<node> &brnch) {
	assert(prime.size() >= brnch.size());
	int diff = prime.size() - brnch.size();
	for (int i = 0; i < brnch.size(); ++i) {
		node grow = prime[i + diff] + brnch[i];
		prime[i + diff] = grow;
	}
}

//yes,no
vector<node> dp(int v) {
	if (child[v].empty()) {
		return vector<node>(1, { 1,1,1 });
	}
	/*
	vector<node>res = dp(child[v][0]);

	for (int i = 1; i < child[v].size(); ++i) {
	vector<node>tmp = dp(child[v][i]);
	if (tmp.size() > res.size()) {
	merge(tmp, res);
	//res = move(tmp);
	swap(res, tmp);
	}
	else {
	merge(res, tmp);
	}
	}
	*/
	vector<pair<int, int>>srt;
	vector<vector<node>>tame;
	for (int ch : child[v]) {
		tame.emplace_back(dp(ch));
		srt.push_back({ tame.back().size(),tame.size() - 1 });
	}
	sort(srt.begin(), srt.end());
	//vector<node>&res = tame[srt[0].second];
	int las = 0;
	for (int i = 1; i < srt.size(); ++i) {
		//vector<node>&tmp = tame[srt[i].second];
		/*
		if (tmp.size() > res.size()) {
		merge(tmp, res);
		res = move(tmp);
		//swap(res, tmp);
		}
		else {
		merge(res, tmp);
		}
		*/
		merge(tame[srt[i].second], tame[srt[i - 1].second]);
		las = tame[srt[i - 1].second].size();
	}
	vector<node>&res = tame[srt[srt.size() - 1].second];
	int cnt = 0;
	for (auto itr = res.rbegin(); itr != res.rend(); ++itr) {
		if (cnt >= las)break;
		LL zero = mpow(2, itr->sum) + MOD;
		zero = (zero - itr->one) % MOD;
		itr->nil = zero;
		cnt++;
	}
	res.push_back({ 1,1,1 });
	return move(res);
}

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> par[1 + i];
		child[par[1 + i]].push_back(i + 1);
	}
	dfs(0, 0);
	vector<node> ans = dp(0);
	for (int i = 0; i <= N; ++i) {
		cnt[dep[i]]++;
	}
	LL answer = 0;
	for (int i = 0; i < ans.size(); ++i) {
		LL kis = N + 1 - cnt[ans.size() - 1 - i];
		kis = mpow(2, kis);
		kis *= ans[i].one;
		kis %= MOD;
		answer += kis;
		answer %= MOD;
	}
	cout << answer << endl;
	return 0;
}


Measured memory_bytes: 59504
<?php
fscanf(STDIN, '%d', $cnt);
$ans = array_fill(0, 10050, 0);
for ($i=1; $i <= 105; $i++) { 
    for ($j=1; $j <= 105; $j++) { 
        for ($k=1; $k <= 105; $k++) { 
            $calc = $i * $i + $j * $j + $k * $k + $i * $j + $j * $k + $i * $k;
            if ($calc < 10050) {
                $ans[$calc]+=1;
            }
        }
    }
}
for ($i=0; $i < $cnt; $i++) { 
    echo $ans[$i+1]."\n";
}


Measured memory_bytes: 16440
# -*- coding: utf-8 -*-
# abc136/abc136_a
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B, C = i2nn()
    r = C - (A - B)
    if r < 0:
        r = 0
    print(r)
    return

main()


Measured memory_bytes: 3064
package main

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

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

// Sort
type Val struct {
	id, num int
}
type ByNum []Val

func (a ByNum) Len() int           { return len(a) }
func (a ByNum) Less(i, j int) bool { return a[i].num < a[j].num }
func (a ByNum) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	K := sc.nextInt()
	if K%2 == 0 {
		fmt.Fprintln(wtr, (K/2)*K/2)
	} else {
		fmt.Fprintln(wtr, (K/2+1)*(K/2))
	}

	wtr.Flush()
}


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

int main(void){
  int i;
  string s;
  cin >> s;
  int count=s.size();
  vector<char> vec(s.size());
  for(i=0;i<s.size();i++){
    vec[i]=s[i];
  }
  for(i=1;i<s.size();i++){
    if(vec[i]==vec[i-1]){
      count--;
      i+=2;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 772
/*************************************************************************
  > File Name: d.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Tue Mar 17 19:12:42 2020
*************************************************************************/

#include <bits/stdc++.h>
using namespace std;
long long x;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> x;
    int cnt = 0;
    while (x) {
        cnt++;
        x >>= 1;
    }
    cout << (1LL << cnt) - 1 << '\n';
    return 0;
}


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

struct state{
	int node,dist,comp;
	bool operator<(const state& r)const{
		return dist>r.dist;
	}
};

struct edge{
	int to,comp;
};

int main(){
	int N,M,inf = 1e9;
	cin >> N >> M;
	vector<vector<edge>> v(N+1);
	map<int,int> dp[N+1];
	map<int,vector<int>> m[N+1];
	int id = N+1;
	int p,q,c;
	for(int i=0;i<M;i++){
		cin >> p >> q >> c;
		v[p].push_back({q,c});
		v[q].push_back({p,c});
		m[p][c].push_back(q);
		m[q][c].push_back(p);
	}
	priority_queue<state> Q;
	dp[1][0] = 0;
	Q.push({1,0,0});
	while(!Q.empty()){
		state now = Q.top(); Q.pop();
		if(dp[now.node][now.comp]<now.dist) continue;
		state ne = now;
		if(now.comp!=0){
			ne.comp = 0;
			if(!dp[ne.node].count(ne.comp) || dp[ne.node][ne.comp]>ne.dist){
				dp[ne.node][ne.comp] = ne.dist;
				Q.push(ne);
			}
		}
		if(now.comp!=0 && !m[now.node][now.comp].empty()){
			for(auto x:m[now.node][now.comp]){
				ne.node = x;
				ne.comp = now.comp;
				ne.dist = now.dist;
				if(!dp[ne.node].count(ne.comp) || dp[ne.node][ne.comp]>ne.dist){
					dp[ne.node][ne.comp] = ne.dist;
					Q.push(ne);
				}
			}
		}
		if(now.comp!=0) continue;
		for(auto x:v[now.node]){
			ne.node = x.to;
			ne.comp = x.comp;
			ne.dist = now.dist+1;
			if(!dp[ne.node].count(ne.comp) || dp[ne.node][ne.comp]>ne.dist){
				dp[ne.node][ne.comp] = ne.dist;
				Q.push(ne);
			}
		}
	}
	cout << (dp[N].count(0)? dp[N][0]:-1) << endl;
}

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

class D {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int M = sc.nextInt();
        final long[] x = new long[N];
        final long[] y = new long[N];
        final long[] z = new long[N];
        for (int i = 0; i < N; i++) {
            x[i] = sc.nextLong();
            y[i] = sc.nextLong();
            z[i] = sc.nextLong();
        }
        long max = 0;
        final long[] a = new long[N];
        for (int i = 1; i >= -1; i -= 2)
            for (int j = 1; j >= -1; j -= 2)
                for (int k = 1; k >= -1; k -= 2) {
                    for (int l = 0; l < N; l++)
                        a[l] = x[l] * i + y[l] * j + z[l] * k;
                    Arrays.sort(a);
                    long sum = 0;
                    for (int l = N - 1; l >= N - M; l--)
                        sum += a[l];
                    max = Math.max(max, sum);
                }
        System.out.println(max);
    }
}
public class Main {
    public static void main(String...args) {
        D.main();
    }
}

Measured memory_bytes: 29068
#include <iostream>
using namespace std;
int main(){
    int max1=0,max2=0,max3=0,h;
    
    for(int k=1;k<=10;k++){
    cin>>h;
        
        if(h>max1){
            max3=max2;
            max2=max1;
            max1=h;
        }
        else if(h>max2){
            max3=max2;
            max2=h;
        }
        
    else if(h>max3)
            max3=h;
    }
    
    cout<<max1<<endl;
    cout<<max2<<endl;
    cout<<max3<<endl;
    
    
}

Measured memory_bytes: 3104
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

int main(){
    int n,k;
    cin>>n>>k;
    long long c=0;
    if(k%2==0){
        long long a=((n+k/2)-(n+k/2)%k)/k;
        c=c+a*a*a;
    }
    long long b=(n-n%k)/k;
    c=c+b*b*b;
    cout<<c<<endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

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

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


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

	map<int, int> dic;
	rep(i, 0, N) {
		int A;
		cin >> A;
		for (auto x : getPrimeFactor(A)) {
			dic[x.first]++;
		}
	}

	int cnt = 1;
	for (auto x : dic) {
		cnt = max(cnt, x.second);
	}

	if (cnt == 1) {
		cout << "pairwise coprime" << endl;
	}
	else if (cnt < N) {
		cout << "setwise coprime" << endl;
	}
	else {
		cout << "not coprime" << endl;
	}
	return 0;
}


Measured memory_bytes: 7320
"use strict";

var main = function main(input) {
  var K = input.split(' ')[0];
  var S = input.split(' ')[1];
  var count = 0;

  for (var i = 0; i <= K; i++) {
    for (var j = 0; j <= K; j++) {
      var amari = S - i - j;

      if (amari <= K && amari >= 0) {
        count++;
      }
    }
  }

  console.log(count);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 7500
#include<stdio.h>
int main(void){
    double A,B;
    scanf("%lf\n%lf",&A,&B);
    if(A>B){
        printf("GREATER");
    }else if(A<B){
        printf("LESS");
    }else if(A==B){
        printf("EQUAL");
    }
    return 0;
}


Measured memory_bytes: 504
import numpy as np
H, W, K = list(map(int, input().split()))
cnt = 0
mtx = np.zeros((H, W), dtype = np.int)
for i in range(H):
    s = input()
    for j in range(W):
        if s[j] == '#':
            mtx[i][j] = 1

for i in range(2**H):
    mtx_1 = mtx.copy()
    for h in range(H):
        if i >> h & 1:
            mtx_1[h] = [0] * W
    
    for j in range(2**W):
        mtx_2 = mtx_1.copy()
        for w in range(W):
            if j >> w & 1:
                mtx_2[:, w] = [0] * H
        if np.sum(mtx_2) == K:
            cnt += 1
print(cnt)            
    

Measured memory_bytes: 27244
#include <bits/stdc++.h>
#define M_PI_2 1.57079632679489661923
#define ll long long int
#define endl '\n'
using namespace std;
 
vector<vector<int>> g;
vector<bool> visit;
vector<int> parent;
vector<int> dist;
template<typename T>
 
class graph
{
    unordered_map<T,list< pair<T,int> > > m;
 
    public:
 
    void addedge(T u,T v,int dist,bool bidir = true)
    {
        m[u].push_back(make_pair(v,dist));
        if(bidir)
        {
            m[v].push_back(make_pair(u,dist));
        }
    }
    void printAdj()
    {
        for(auto i:m)
        {
            cout<<i.first<<" -> ";
            for(auto j:i.second)
            {
                cout<<"( "<<j.first<<","<<j.second<<" )"<<" ";
            }
            cout<<endl;
        }
    }
 
    void dijkstra(T src)
    {
        unordered_map<T,int> dist;
        vector<int> par(m.size(),-1);
        for(auto j:m)
        {
            dist[j.first] = INT_MAX;
        }
        dist[src] = 0;
        set< pair<int,T> > s;
        s.insert({0,src});
 
        while(!s.empty())
        {
            auto p = *(s.begin());
            T node = p.second;
            int nodedist = p.first;
            s.erase(s.begin());
            for(auto child:m[node])
            {
                if((nodedist+child.second)<dist[child.first])
                {
                    auto k = s.find({dist[child.first],child.second});
                    if(k!=s.end())
                    {
                        s.erase(k);
                    }
                    s.insert({nodedist+child.second,child.first});
                    dist[child.first] = nodedist+child.second;
                    par[child.first] = node;
                }
            }
        }
        for(int i=1;i<m.size();i++)
        {
            if(par[i]==-1)
            {
                cout<<"No"<<endl;
                return;
            }
        }
        cout<<"Yes"<<endl;
        for(int i=1;i<m.size();i++)
        {
            cout<<par[i]+1<<endl;
        }
    }
};
 
void solve()
{
  int n,k;
  cin>>n>>k;
  int x,y;
  graph<int> g;
  for(int i=0;i<k;i++)
  {
    cin>>x>>y;
    x--;
    y--;
    g.addedge(x,y,1);
  }
 
  g.dijkstra(0);
}    
 
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 30572
package main


import (
  "fmt"
  "strings"
  "strconv"
)


func min(a int, b int) int {
  if a < b {
    return a
  } else {
    return b
  }
}


func main () {
  var s string
  fmt.Scanf("%s", &s)

  var as []string = strings.Split(s, "")

  var ans1 int = 0
  var ans2 int = 0

  for k := 0; k < len(s); k++ {
    var _k1 = strconv.Itoa(k%2)
    var _k2 = strconv.Itoa((k+1)%2)

    if as[k] != _k1 {
      ans1++
    }
    if as[k] != _k2 {
      ans2++
    }
  }

  fmt.Println(min(ans1, ans2))
}


Measured memory_bytes: 3200
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
const int maxn=200050;
struct point{
	ll x,y;
	point(ll x0=0,ll y0=0):x(x0),y(y0){}
};
point p[maxn],res[maxn];
int n;

int cmp(point a,point b){
	return a.y<b.y||(a.y==b.y&&a.x<b.x);
}
ll cross(point a,point b,point c){
	return (b.x-a.x)*(c.y-a.y)-(b.y-a.y)*(c.x-a.x);
}
ll dist(point a,point b){
	return abs(b.x-a.x)+abs(b.y-a.y);
}
int convex(int n){
	int now=1;
	for(int i=1;i<=n;i++){
		while(now>2&&(cross(res[now-2],p[i],res[now-1]))>=0)	now--;
		res[now++]=p[i];
	}
	int k=now;
	for(int i=n-1;i>=1;i--){
		while(now>k&&(cross(res[now-2],p[i],res[now-1]))>=0)	now--;
		res[now++]=p[i];
	}
	if(n>1)	now--;
	return now-1;
}
ll caliper(int now){
	int cnt=2;
	ll ans=0;
	for(int i=1;i<=now;i++){
		while((cross(res[i],res[i+1],res[cnt+1])-cross(res[i],res[i+1],res[cnt]))>0)	cnt=cnt%now+1;
		ll d1=dist(res[i],res[cnt]);
		ll d2=dist(res[i+1],res[cnt]);
		ans=max(ans,max(d1,d2));
	}
	return ans;
}

void solve(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)	scanf("%lld %lld",&p[i].x,&p[i].y);
	sort(p+1,p+n+1,cmp);
	int now=convex(n);
	printf("%lld\n",caliper(now));
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 7988
v = int(input())
h = int(input())

l = [i for i in range(1, v + 1)]
for i in range(h):
    n, m = input().split(',')
    n = int(n) - 1
    m = int(m) - 1
    l[n], l[m] = l[m], l[n]

for i in l:
    print(i)

Measured memory_bytes: 6724
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}


int main()
{
    string str;
    cin>>str;
    int len=str.size();
    if(str[len-1]=='s') cout<<str<<"es"<<endl;
    else cout<<str<<"s"<<endl;




	return 0;
}




Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

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

using namespace std;

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

    ll N, A, B;
    cin >> N >> A >> B;

    string ans;
    if (abs(A-B) % 2 == 0) {
        ans = "Alice";
    } else {ans = "Borys";}

    cout << ans << "\n";

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define p 1000003
#define Maxn 1000010
int Q;
long long fac[Maxn], inv[Maxn], Cap, x, d, n, Res, Nah, Remain;

long long Pow(long long y, long long x)
{
    long long tmp=1;
    for (; x; x>>=1)
    {
        if (x&1) tmp=(tmp*y)%p;
        y=(y*y)%p;
    }
    return tmp;
}

int main()
{
	fac[0]=1; for(int i=1; i<=p; i++) fac[i]=fac[i-1]*i%p;
    inv[1]=1; for(int i=2; i<p; i++) inv[i]=(p-p/i)*inv[p%i]%p;
    inv[0]=1; for(int i=1; i<p; i++) inv[i]=inv[i]*inv[i-1]%p;
	scanf("%d", &Q);
	while (Q--)
	{
		scanf("%lld%lld%lld", &x, &d, &n);
		if (d==0)
		{
			printf("%lld\n", Pow(x, n));
			continue;
		}
		Cap=x*Pow(d, p-2)%p; Remain = Cap + n - 1; Res = 1;
		if (Remain>=p) { puts("0"); continue; }
		else
		{
			Res = ((Res * (fac[Cap+n-1] * inv[Cap-1] % p) % p) * Pow(d, n)) % p;
		}
		if (Res<0) Res+=p; 
		printf("%lld\n", Res);
	}
}

Measured memory_bytes: 16512
N = int(input())
*A, = map(int,input().split())
*B, = map(int,input().split())

INF = N *100
ans = INF
for i in range(2**N):
    C = [((a,j,0) if (i>>j)&1 else (b,j,1)) for j,a,b in zip(range(N),A,B)]
    P = sum(p for c,j,p in C)
    if P%2: continue
    E = sum(p for c,j,p in C[::2])
    O = sum(p for c,j,p in C[1::2])
    if E!=O: continue
    C0 = []
    C1 = []
    for c,j,p in C:
        if (p+j)%2:
            C1.append((c,j,p))
        else:
            C0.append((c,j,p))
    C0.sort()
    C1.sort()
    D = []
    E = []
    for c0,c1 in zip(C0,C1):
        E.append(c0[0])
        E.append(c1[0])
        D.append(c0[1])
        D.append(c1[1])
    if N%2:
        D.append(C0[-1][1])
        E.append(C0[-1][0])
    contFlg = False
    for e,e2 in zip(E[:-1],E[1:]):
        if e>e2:
            contFlg = True
            break
    if contFlg: continue
    tmp = 0
    for i,d in enumerate(D):
        for j,d2 in enumerate(D[:i]):
            if d2 > d: tmp += 1
    ans = min(ans,tmp)
if ans == INF:
    ans = -1
print(ans)

Measured memory_bytes: 72668
import java.util.*;

class Main{
	public static void main(String[] $){
		//入力
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), m = sc.nextInt();

		HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();
		PriorityQueue<Integer> tasks = new PriorityQueue<>(Comparator.reverseOrder());

		for(int i = 0; i < n; i++){
			int a = sc.nextInt(), b = sc.nextInt();
			map.computeIfAbsent(a, o -> new ArrayList<>()).add(b);
		}

		sc.close();


		//処理
		long ans = 0;

		for(int i = 1; i <= m; i++){
			ArrayList<Integer> list = map.get(i);
			if(list != null){
				for(Integer item : list) tasks.add(item);
			}
			Integer task = tasks.poll();
			if(task != null) ans += task;
		}


		//出力
		System.out.println(ans);
	}
}


Measured memory_bytes: 104972