akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

struct edge {
    int from, to, cost;
};

int d[2501];
int V, E;

bool shortest_path(int s, int v, vector<edge> &es) {
    for (int i = 0; i < V; i++) {
        d[i] = INF;
    }
    d[s] = 0;
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < es.size(); j++) {
            edge e = es[j];
            if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (i == v - 1) {
                    return false;
                }
            }
        }
    }
    return true;
}

signed main() {
    cin >> V >> E >> P;
    vvi g(V);
    vector<edge> esf(E);
    vector<edge> es;
    for (int i = 0; i < E; i++) {
        cin >> esf[i].from >> esf[i].to >> esf[i].cost;
        esf[i].from--, esf[i].to--;
        esf[i].cost -= P;
        esf[i].cost *= -1;
        g[esf[i].to].push_back(esf[i].from);
    }
    set<int> set;
    vi used(V, 0);
    queue<int> q;
    q.push(V - 1);
    set.insert(V - 1);
    used[V - 1] = 1;
    while (!q.empty()) {
        int now = q.front();
        dump(now);
        q.pop();
        for (auto adj : g[now]) {
            set.insert(adj);
            if (used[adj])
                continue;
            q.push(adj);
            used[adj] = 1;
        }
    }
    dump(set);
    for (int i = 0; i < E; i++) {
        if (set.count(esf[i].from) && set.count(esf[i].to)) {
            es.push_back(esf[i]);
        }
    }
    if (shortest_path(0, set.size(), es)) {
        cout << max(-d[V - 1], 0LL) << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 964
<?php
	$pattern = str_repeat( '#.', 151 );
	$output = array();
    while( true ) {
        fscanf( STDIN, "%d%d", $H, $W );
        if( 0 == $H && 0 == $W ) { break; }
        
		for( $i=0; $i<$H; $i++ ) {
			array_push( $output, substr( $pattern, ($i&1)?1:0, $W ).PHP_EOL );
		}
		array_push( $output, PHP_EOL );
    }
    print implode( '', $output );
	
	return;
?>

Measured memory_bytes: 6796
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    long long int ans=0;
    int x,z;
    cin >>x>>z;
    int c[10][10];
    vector<int> in,l(10,-1);
    in.push_back(1);
    l[1]=0;
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
            cin >> c[i][j];
        }
    }
    for(int i=1;i<10;i++){
        vector<int> tmp(10,-1);
        for(int j=0;j<10;j++){
            if(l[j]<0){
                for(int k:in){
                    if(tmp[j]>l[k]+c[j][k]||tmp[j]<0){
                        tmp[j]=l[k]+c[j][k];
                    }
                }
            }
        }
        int min=-1,itr;
        for(int j=0;j<10;j++){
            if(tmp[j]!=-1&&(min==-1||min>tmp[j])){
                min=tmp[j];
                itr=j;
            }
        }
        l[itr]=tmp[itr];
        in.push_back(itr);
    }
    while(cin >> x){
        if(x!=-1){
            ans+=l[x];
        }
    }
    cout << ans;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1e8;
typedef long long ll;
ll mod = 1e9+7;
long long fast_exp(long long a, long long b)
{
    if(b == 0)
	   return 1;
    else
    {
	   long long res = 1;
	   res = fast_exp(a,b/2);
	   res = (res*res)%mod;
	   if(b%2 == 1)
		  res = (res*a)%mod;
	   return res;
 
    }
}
const ll N = 1e5;

 

 
int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i = 0; i<2*n ; i++)
		if(i % 2 == 0)
			cout<<s[i/2];
		else
			cout<<t[i/2];
	cout<<endl;
	return 0;
	
}

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

void	put_cards(vector<pair<char, int>> C, int n)
{
	rep(i, n)
	{
		if (i)
			cout << ' ';
		cout << C.at(i).first << C.at(i).second;
	}
	cout << endl;
}

void	bubble_sort(vector<pair<char, int>> &C, int n)
{
	for (int i = 0; i < n - 1; i++)	
	{
		bool	flag;

		flag = 1;
		for (int j = n - 1; j > i; j--)
		{
			flag = 0;
			if (C.at(j).second < C.at(j - 1).second)
			{
				swap(C.at(j), C.at(j - 1));
				flag = 1;
			}
		}
	}
}

void	selection_sort(vector<pair<char, int>> &C, int n)
{
	for (int i = 0; i < n - 1; i++)	
	{
		int minj;

		minj = i;
		for (int j = i + 1; j < n; j++)
		{
			if (C.at(j).second < C.at(minj).second)
				minj = j;
		}
		if (minj != i)
			swap(C.at(i), C.at(minj));
	}
}

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

	vector<pair<char, int>>	A(n);
	rep(i, n)
		cin >> A.at(i).first >> A.at(i).second; 

	vector<pair<char, int>>	B(n);

	B = A;
	bubble_sort(A, n);
	selection_sort(B, n);
	put_cards(A, n);
	cout << "Stable" << endl;
	put_cards(B, n);
	if (B == A)
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;
}



Measured memory_bytes: 3104
#include<stdio.h>
int main () {
    int n,i,a[100];
    scanf ("%d",&n);
    for (int i=0;i<n;i++) {
        scanf ("%d",&a[i]);
    }
    for (i=0;i<n;i++) {
        printf ("%d",a[n-1-i]);
        if (i!=n-1) {
            putchar(' ');
        }
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <vector>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

long long dp[100][2];

int main() {
    int N;
    long long K;
    cin >> N >> K;
    vector<long long> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];

    for (int i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1;
    dp[45][0] = 0;
    for (int d = 44; d >= 0; --d) {
        long long mask = 1LL<<d;
        int num = 0;
        for (int i = 0; i < N; ++i) if (A[i] & mask) ++num;

        if (dp[d+1][1] >= 0) chmax(dp[d][1], dp[d+1][1] + mask * max(num, N-num));
        if (dp[d+1][0] >= 0) {
            if (K & (1LL<<d)) {
                chmax(dp[d][1], dp[d+1][0] + mask * num);
                chmax(dp[d][0], dp[d+1][0] + mask * (N-num));
            }
            else {
                chmax(dp[d][0], dp[d+1][0] + mask * num);
            }
        }
    }
    cout << max(dp[0][0], dp[0][1]) << endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 2e5+100;






string s;
int n;

int nxt[maxn][26];

int dp[maxn];
int dpl[maxn];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    
    cin>>s;
    n = s.length();

    
    for (int j=0;j<26;j++) {
	nxt[n][j] = n;
	for (int i=n-1; i>=0; i--) {	    
	    nxt[i][j] = nxt[i+1][j];
	    if (s[i]-'a' == j) {
		nxt[i][j] = i;
	    }
	}
    }



    dp[n+1]=0;
    //start at n to represent last 'a' to append to make it not a subseq
    
    for (int i=n; i>=0; i--) {
	dp[i] = 1e9;
	dpl[i] = -1;

	for (int j=0;j<26;j++) {
	    if (1+dp[nxt[i][j]+1] < dp[i]) {
		dp[i] = 1+dp[nxt[i][j]+1];
		dpl[i] = j;
	    }
	}
    }

    string res;
    int x=0;
    while (x<n) {
	res += char(dpl[x]+'a');
	x = nxt[x][dpl[x]]+1;
    }


    cout<<res<<endl; 
    return 0;
}


Measured memory_bytes: 22420
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

#define            ll              long long
#define            pb              push_back
#define            mp              make_pair
#define            loop(i,a,n)     for(int i=a;i<n;++i)
#define            clr(x)          memset(x,0,sizeof x)
#define            min3(a,b,c)     min(a,min(b,c))
#define            max3(a,b,c)     max(a,max(b,c))
#define            min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define            max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define            fast            ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define            pii             pair<int,int>
#define            pll             pair<ll,ll>
#define            pli             pair<ll,int>
#define            pil             pair<int,ll>
#define            FF              first
#define            SS              second
#define            PI              acos(-1.0)
#define            bug             cout<<"ok"<<endl;

using namespace std;
using namespace __gnu_pbds;

typedef tree<int , null_type,less<int>,
       rb_tree_tag, tree_order_statistics_node_update> anik;

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


ll dp[100009][3];
ll a[100009],b[100009],c[100009];
ll fun(ll n,ll idx)
{
    if(n==0)return 0;
    if(dp[n][idx]!=-1)return dp[n][idx];
    else
    {
        ll t0=a[n]+fun(n-1,0);
        ll t1=b[n]+fun(n-1,1);
        ll t2=c[n]+fun(n-1,2);
        dp[n][0]=max(t1,t2);
        dp[n][1]=max(t0,t2);
        dp[n][2]=max(t1,t0);
        return dp[n][idx];
    }
}

main()
{
   for(int i=0;i<100009;++i)
    for(int j=0;j<3;++j)
    dp[i][j]=-1;
   int n;
   cin>>n;
   loop(i,1,n+1)
      cin>>a[i]>>b[i]>>c[i];
    dp[0][0]=0;
    dp[0][1]=0;
    dp[0][2]=0;
    dp[n][0]=fun(n,0);
    dp[n][1]=fun(n,1);
    dp[n][2]=fun(n,2);

    cout<<max3(dp[n][0],dp[n][1],dp[n][2])<<endl;

}


Measured memory_bytes: 11136
##入力は以下の形式で標準入力から与えられる.
##N
##a1 a2 a3 ... aN
n =   gets.chomp.to_i

##N枚のカードがあります. i枚目のカードには, aiという数が書かれています.
##Alice と Bob は, これらのカードを使ってゲームを行います.
##ゲームでは, Alice と Bob が交互に 1 枚ずつカードを取っていきます.
##Alice が先にカードを取ります.
a_a = gets.chomp.split(" ").map(&:to_i).sort.reverse
# p a_a

alice, bob = 0, 0
a_a.each_index do |idx|
  if idx % 2 == 0
    alice += a_a[idx]
  else
    bob   += a_a[idx]
  end
end

##2 人がすべてのカードを取ったときゲームは終了し, 
##取ったカードの数の合計がその人の得点になります.

##両者が最適な戦略を取った時, AliceはBobより何点多く取るかを出力してください.
# p alice
# p bob
p (alice-bob)

Measured memory_bytes: 1788
#include "bits/stdc++.h"
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    char last = s[0];
    for(int i = 1; i < n; i++){
        if(last != s[i]){
            ans++;
            last = s[i];
        }
    }
    ans++;
    cout << ans << endl;
}

Measured memory_bytes: 512
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as BS

main = do
  [n,y] :: [Int] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  let result = [ (man,gosen,sen)
               -- man >= 0, gosen >= 0, sen >= 0
               -- n = man + gosen + sen
               -- y == 10000*man + 5000*gosen + 1000*sen
               -- <=> y == 10000*man + 5000*gosen + 1000*(n - man - gosen)
               -- <=> y == 9000*man + 4000*gosen + 1000*n
               -- <=> (y - 9000*man - 1000*n) `quotRem` 4000 == (gosen, 0)
               | man <- [max 0 (((y + 5000 - 1) `quot` 5000) - n) .. ((y - 1000*n) `quot` 9000)]
               -- man >= 0: OK
               , (gosen, 0) <- return ((y - 9000*man - 1000*n) `quotRem` 4000)
               -- gosen >= 0
               -- <=> y - 9000*man - 1000*n >= 0
               -- <=> y - 1000*n >= 9000*man
               -- <=> (y - 1000*n) `quot` 9000 >= man
               , let sen = n - man - gosen
               -- sen >= 0
               -- <=> n - man - gosen >= 0
               -- <=> n - man - ((y - 9000*man - 1000*n) `quot` 4000) >= 0
               -- <=> 4000*n - 4000*man - y + 9000*man + 1000*n >= 0
               -- <=> 5000*n + 5000*man - y >= 0
               -- <=> man >= ((y + 5000 - 1) `quot` 5000) - n
               ]
      check (man,gosen,sen) = man >= 0 && gosen >= 0 && sen >= 0 && n == man + gosen + sen && y == 10000*man + 5000*gosen + 1000*sen
  -- if not (all check result)
  --  then putStrLn "error"
  --  else return ()
  putStrLn $ unwords $ map show $ case result of
    (man,gosen,sen):_ -> [man,gosen,sen]
    [] -> [-1,-1,-1]


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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    cin >> S;
    ll answer = 1e10;
    for(int i = 0; i < S.size() - 2; i++)
    {
        ll num = 0;
        for(int j = 0; j < 3; j++)
        {
            num *= 10;
            num += S.at(i + j) - '0';
        }
        answer = min(answer, abs(num - 753));
    }
    cout << answer << endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
bunretsu = sum(A) - 1
zanretsu = 1
souwa = 0
for i in range(N+1):
    souwa += zanretsu
    if A[i] <= zanretsu:
        zanretsu -= A[i]
    else:
        souwa = -1
        break
    if bunretsu >= 1 and bunretsu <= zanretsu:
        zanretsu += bunretsu
        bunretsu = 0
    elif bunretsu >= 1 and bunretsu > zanretsu:
        bunretsu -= zanretsu
        zanretsu *= 2
print(souwa)

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver2 {
 public:
  int n, a, b;

  void solve() {
    cin >> n >> a >> b;
    cout << min(a, b) << ' ' << max(0, (a + b) - n) << endl;
  }
};
}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);

  Problem::Solver2 sol;
  sol.solve();
  return 0;
}


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


int main(void)
{
    
    int a, b, t;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &t);

    int sum = 0;
    int time = 0;
    while(1){
        time += a;
        if(t < time)
            break;
        sum += b;
    }

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





    return 0;
} 



Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
int main(){
	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
			cout<<i<<'x'<<j<<'='<<i*j<<endl;
		}
	}
}

Measured memory_bytes: 1116
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iomanip>


#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;


// <<fixed<<setprecision(6)<<


int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}


int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}


int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}


int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}


int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}


int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}


int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  while(a>0&&c>0){
    c-=b;
    if(c>0){
      a-=d;
    }
  }
  if(a>0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
	
int main(){
	string s;
	int t;
	cin>>t>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]+t>'Z') s[i]=s[i]+t-'Z'-1+'A';
		else s[i]+=t;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
typedef unsigned long long ull ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define rrep(i , n) for ( int i = n-1; i >=0 ; i--)

#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

class UnionFind {
private:
	ull size_; 
	std::vector<ull> par, rank, count;

public:
	UnionFind() : size_(0), par(std::vector<ull>()), rank(std::vector<ull>()), count(std::vector<ull>()) {};
	UnionFind(ull size__) : size_(size__) {
		par.resize(size_); rank.resize(size_); count.resize(size__);
		for (ull i = 0; i < size_; i++) par[i] = i, rank[i] = 0, count[i] = 1;
	}
	ull size() { return size_; }
	// ull root(ull x) { return par[x] == x ? x : par[x] = root(par[x]); }
	
	ull root(ull x)
	{
		while(par[x] != x)
		{
			par[x] = par[par[x]];
			x = par[x];
		}
		return x;
	}
	
	bool same(ull x, ull y) { return root(x) == root(y); }

	void unite(ull x, ull y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] < rank[y]) par[x] = y, count[y]+=count[x], count[x]=0;
		else if (rank[x] == rank[y]) par[y] = x, rank[x]++, count[x]+=count[y], count[y]=0;
		else par[y] = x, count[x] += count[y], count[y] = 0;
	}

	ull size__(ull x)
	{
		return count[root(x)];
	}

	bool operator==(const UnionFind &u) { return par == u.par; }
	bool operator!=(const UnionFind &u) { return par != u.par; }
};
/*
maybe sth wrong 
got wa in one problem
*/
ll modpow(ll a, ll b)
{
	if (b == 0)
	{
		return 1;
	}

	if (b % 2)
	{
		return a * modpow(a, b-1) % MOD;
	}
	else
	{
		ll halfB = b / 2;
		ll half = modpow(a, halfB);
		return half * half % MOD;
	}
}

ll calcComb(ll n, ll m)
{
	if (m > n-m)
	{
		return calcComb(n, n-m);
	}

	ll ansMul = 1;
	ll ansDiv = 1;

	rep(i, m)
	{
		ansMul *= (n-i);
		ansDiv *= (i+1);
		ansMul %= MOD;
		ansDiv %= MOD;
	}

	return ansMul * modpow(ansDiv, MOD - 2) % MOD;
}

__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}


int main()
{
	int N;
	
	cin >> N;
	int a[N];
	
	int ans[N];
	memset(ans, 0, sizeof(ans));
	rep(i, N)
	{
		cin >> a[i];	
	}

	int total = 0;
	for(int i = N; i >= 1; i--)
	{
		int sum = 0;
		for(int j = i*2; j <= N; j+= i)
		{
			sum += ans[j-1];
		}
		int ret = sum % 2;
		if (ret != a[i-1])
		{	
			ans[i-1] = 1;
			total++;
		}
		
	}

	cout << total << endl;

	if (total)
	{
		rep(i, N)
		{
			if(ans[i])
			{
				cout << i + 1 << endl;
			}
		}
	}
	
	
	return 0;
}


Measured memory_bytes: 2560
stock = [1]+[0] * 100005
item = [100, 101, 102, 103, 104, 105]
for x in range(100001):
    for y in item:
        if stock[x - y]:
            stock[x] = 1

n = int(input())
if stock[n]:
    print(1)
else:
    print(0)

Measured memory_bytes: 10332
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n;
  cin>>n;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<n;i++){
    int u,k;
    cin>>u>>k;
    for(int j=0;j<k;j++){
      int v,c;
      cin>>v>>c;
      G[u].push_back(P(v,c));
    }
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;
  d[0]=0;

  priority_queue<P,vector<P>,greater<P> > q;
  d[0]=0;
  q.push(P(0,0));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++) cout<<i<<" "<<d[i]<<endl;
  return 0;
}

Measured memory_bytes: 11840
import sys
INPUT = sys.stdin.readline
#入力関数
def SORO_INT(): return int(INPUT())
def MULT_INT_LIST(): return list(map(int, INPUT().split()))
def MULT_INT_MAP(): return map(int, INPUT().split())
def SORO_STRING(): return INPUT()
def MULT_STRING(): return INPUT().split()

A,B = MULT_INT_LIST()
new = []
C = A+B 
D = A-B
E = A*B
new.append(C)
new.append(D)
new.append(E)
print(max(new))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  ll point = 0;
  rep(i, sz(t)){
    if(i>=k){
      if(t[i]==t[i-k]){
        t[i] = 'a';
        continue;
      }
    }
    if(t[i]=='r'){
      point += p;
    }
    else if(t[i]=='s'){
      point += r;
    }
    else{
      point += s;
    }
  }
  print(point);
}

Measured memory_bytes: 3756
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from collections import defaultdict



N = int(input())
Rn = []
for i in range(N):
  s,p = map(str, input().split())
  Rn.append([str(i+1), s, p])

Rn = sorted(Rn, key=lambda x:-int(x[2]))
Rn = sorted(Rn, key=lambda x:x[1])
for i in range(N):
  print(Rn[i][0])

Measured memory_bytes: 38512
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#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 <climits>
#include <complex>
using namespace std;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0

typedef complex<double> P;

int n,m;
int edge[128][128],redge[128][128];
struct Sikaku{
	P v[4];
} sikaku[110];



double cross(P a, P b){
	return a.real()*b.imag() - a.imag()*b.real();
}
double dot(P a, P b){
	return a.real()*b.real() + a.imag()*b.imag();
}

int ccw(P p0, P p1, P p2){
	P a(p1-p0), b(p2-p0);
	if( cross(a,b)>EPS ) return 1;
	if( cross(a,b)<-EPS ) return -1;
	if( dot(a,b)<-EPS ) return 2;
	if( abs(a) < abs(b) ) return -2;
	return 0;
}

bool isintersected(P a1, P a2, P b1, P b2){
	return ( ccw(a1,a2,b1)*ccw(a1,a2,b2)<=0 &&
			 ccw(b1,b2,a1)*ccw(b1,b2,a2)<=0 );
}


bool ok(int a, int b){
	rep(i,4)rep(j,4){
		if( isintersected(sikaku[a].v[i],sikaku[a].v[(i+1)%4],
						  sikaku[b].v[j],sikaku[b].v[(j+1)%4]) ){
			return true;
		}
	}
	bool f = true;
	rep(i,4)rep(j,4){
		if( ccw(sikaku[a].v[j], sikaku[a].v[(j+1)%4], sikaku[b].v[i])!=-1 ){
			f = false; break;
		}
	}
	if( f ) return true;

	f = true;
	rep(i,4)rep(j,4){
		if( ccw(sikaku[b].v[j], sikaku[b].v[(j+1)%4], sikaku[a].v[i])!=-1 ){
			f = false; break;
		}
	}
	if( f ) return true;
	
	return false;
}


int num[128],visi[128],cnt;
void dfs(int node){
	rep(i,m)if( !visi[i] && edge[node][i]>0 ){
		visi[i] = 1;
		dfs(i);
	}
	num[cnt++] = node;
}

vector<set<int> > vst;

int redfs(int node, set<int>& st){
	st.insert(node);
	rep(i,m)if( !visi[i] && redge[node][i]>0 ){
		visi[i] = 1;
		redfs(i,st);
	}
}

int main(){
	//cout << ccw(P(100,100), P(100,200), P(0,0)) << endl;
	
	while(scanf("%d",&n),n){
		rep(i,n){
			vst.clear();
			rep(i,128)rep(j,128)edge[i][j]=redge[i][j]=0;
			
			scanf("%d",&m);
			rep(j,m){
				int x[4],y[4];
				scanf("%d%d%d%d%d%d%d%d",x,y,x+1,y+1,x+2,y+2,x+3,y+3);
				rep(k,4){
					sikaku[j].v[k].real() = (double)x[k];
					sikaku[j].v[k].imag() = (double)y[k];
				}
			}
			rep(j,m)rep(k,m)if( j!=k ){
				if( ok(j,k) ){
					edge[j][k] = 1;
					redge[k][j] = 1;
				}
			}

			memset(visi,0,sizeof(visi));
			cnt = 0;
			rep(i,m)if( !visi[i] ){
				visi[i] = 1;
				dfs(i);
			}

#if DEB
			rep(i,m){
				rep(j,m){
					printf("%d ",edge[i][j]);
				}
				puts("");
			}
			puts("num");
			rep(i,m){
				printf("num[%d]:%d\n",i,num[i]);
			}
#endif			

			set<int> ss;
			memset(visi,0,sizeof(visi));
			for(int j=cnt-1; j>=0; j--)if( !visi[num[j]] ){
				ss.clear();
				visi[num[j]] = 1;
				redfs(num[j],ss);
				vst.push_back(ss);
			}

			cout << vst.size() << endl;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 1096
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;


signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n, d, a; cin >> n >> d >> a;
	vector<pair<ll, ll>> kek(n);

	for (ll i = 0; i < n; i++) {
		cin >> kek[i].X >> kek[i].Y;
	}
	sort(all(kek));
	d *= 2;
	multiset<pair<ll, ll>> rofl;
	for (auto p : kek) rofl.insert(p);
	ll sm = 0;
	ll ans = 0;
	while (!rofl.empty()) {
		auto p = *rofl.begin();
		rofl.erase(rofl.begin());
		ll x = p.X;
		ll y = p.Y;
		if (y > 0) {
			if (sm < y) {
				ll k = (y - sm + a - 1) / a;
				ans += k;
				sm += k * a;
				rofl.insert({ x + d + 1, -k });
			}
		} else {
			y = -y;
			sm -= y * a;
		}
	}
	cout << ans << endl;

	return 0;
}

/*
3
0 1
3 0
1 0
*/

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


int main(){
    int64_t h,w ;
    cin >> h >> w ;
    if (h == 1 || w == 1)
    {
        cout << 1 << endl ;
        return 0 ;
    }
    
    int64_t ans = h*(w/2) ;

    if (w % 2 == 1)
    {
        ans += (h+1)/2 ;
    }
    cout << ans << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int h,w;
  cin >> h >> w;
  
  vector<string> v(h);
  
  rep(i,h) cin >> v[i];
  
  rep(i,h){
    rep(j,w){
      
      if(v[i][j] == '.') continue;
      
      int count1 = 4;
      int count2 = 0;
      
      if(i-1 < 0) count1--;
      else if(v[i-1][j] == '.') count2++;
      
      if(i+1 >= h) count1--;
      else if(v[i+1][j] == '.') count2++;
      
      if(j-1 < 0) count1--;
      else if(v[i][j-1] == '.') count2++;
      
      if(j+1 >= w) count1--;
      else if(v[i][j+1] == '.') count2++;
      
      if(count1 == count2){
        cout << "No";
        return 0;
      }
    }
  }
  
  cout << "Yes";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
 #include <vector>
 #include <algorithm>
#include <map>
 #include <set>
 #include <cmath>
 #include <cstring>
 #include <iomanip>
 #include <random>
 #include <chrono>
 #include <queue>
 #include <math.h>
 using namespace std;

int main(){
  long n,m,c;
  cin >>n >> m>>c;
  long b[m+10];
  for (int i=0;i<m;i++) cin >>b[i];
  int ans=0;
  long a[m+10];
  for (int i=0;i<n;i++){
    long check=0;
    for (int j=0;j<m;j++){
      cin >>a[j];
      check+=a[j]*b[j];
    }
    check+=c;
    if(check>0) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;

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

	int n, m, k;
	cin >> n >> m >> k;

	int ans = INF;
	
	string arr[n];
	for(int i = 0; i < n; i++) cin >> arr[i];

	for(int mask = 0; mask < (1 << (n - 1)); mask++){
		vector<vector<int> > A;
		vector<int> temp(m, 0);
		for(int i = 0; i < n - 1; i++){
			for(int j = 0; j < m; j++) if(arr[i][j] == '1') temp[j]++;
			if(mask & (1 << i)){
				A.pb(temp);
				temp = vector<int> (m, 0);
			}
		}
		for(int j = 0; j < m; j++) if(arr[n - 1][j] == '1') temp[j]++;
		A.pb(temp);

		int val = __builtin_popcount(mask);

		vector<int> sum(sz(A), 0);
		for(int i = 0; i < m; i++){
			for(int j = 0; j < sz(A); j++){
				if(A[j][i] > k) val += 1e9;
				if(sum[j] + A[j][i] > k){
					for(int l = 0; l < sz(A); l++) sum[l] = A[l][i];
					val++;
					break;
				}
				sum[j] += A[j][i];
			}
		}

		ans = min(ans, val);
	}
	cout << ans;
	
}

Measured memory_bytes: 384
b[9999];m,i;c(int*x){i=*x-*1[&x];}main(a){for(;scanf("%*d%d%d",&m,&a)*m;printf("%d\n",a)){for(i=m*=3;i;scanf("%d%d%d",b+i,b-~i,b+i+2))i-=3;for(qsort(b,m/3,12,c);m;a=a-b[m+1]?a-b[m+2]?a:b[m+1]:b[m+2])m-=3;}}

Measured memory_bytes: 0
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N, K;
    cin >> N >> K;
    int x = 1;
    while (x < K && N > 0)
    {
        x *= 2;
        N--;
    }
    while (N > 0)
    {
        x += K;
        N--;
    }
    cout << x << endl;
    return 0;
}


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

int main(){
	using ll = long long;
	ll n;
	cin >> n;
	priority_queue<ll, vector<ll>, greater<ll>> left;
	priority_queue<ll> right;
	ll left_sum = 0, right_sum = 0, mid[n];
	for(int i = 0; i < n; i++){
		ll a;
		cin >> a;
		left.push(a);
		left_sum += a;
	}
	for(int i = 0; i < n; i++) cin >> mid[i];
	for(int i = 0; i < n; i++){
		ll a;
		cin >> a;
		right.push(a);
		right_sum += a;
	}
	ll left_arr[n + 1], right_arr[n + 1];
	left_arr[0] = left_sum;
	right_arr[0] = right_sum;
	for(int i = 1; i < n + 1; i++){
		left.push(mid[i - 1]);
		left_sum += mid[i - 1];
		left_sum -= left.top();
		left.pop();
		left_arr[i] = left_sum;
	}
	for(int i = 1; i < n + 1; i++){
		right.push(mid[n - i]);
		right_sum += mid[n - i];
		right_sum -= right.top();
		right.pop();
		right_arr[i] = right_sum;
	}
	ll ans = -(1ll << 60);
	for(int i = 0; i < n + 1; i++) ans = max(ans, left_arr[i] - right_arr[n - i]);
	cout << ans << endl;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0; i<(int)(n); i++)
int main(){
int K, N; string S, ans=""; cin >> K >> S; N=S.size();
if(N<=K){ ans=S; }else{ REP(i, K){ ans+=S[i]; } ans+="..."; }
cout << ans << "\n";
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,t,m=100000,c,y;
  cin>>n>>t;
  for(int i=0;i<n;i++){
    cin>>c>>y;
    if(y<=t)
      m=min(m,c);
  }
  if(m==100000){
    cout<<"TLE";
    return 0;
  }
  cout<<m;
}

Measured memory_bytes: 768
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cstdlib>  // abs() for integer
#include <math.h>     // math.h をインクルードする！
#include <iomanip> // 小数点以下のやつ
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int factorial(int n) {
    if (n == 1) return 1;

    n *= factorial(n - 1);
    return n;
}

int main() {
    int n;
    cin >> n;
    vector<vector<long double> > t(n, vector<long double> (2));
    rep (i, n) {
        rep (j, 2) cin >> t[i][j];
    }
    long double sum = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += sqrt(pow(t[i][0] - t[j][0], 2) + pow(t[i][1] - t[j][1], 2)) * factorial(n - 1) * 2;
        }
    }
    cout << fixed << setprecision(10) << sum / factorial(n) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int max(int x,int y){ return x>y?x:y; }
void reverse(char *s,int n){
  int i;
  for(i=0;i<n/2;i++){
    *(s+i)^=*(s+n-i-1);
    *(s+n-i-1)^=*(s+i);
    *(s+i)^=*(s+n-i-1);
  }
}
char res[256];
char a[256],b[256];
main(){
  int n;
  int len,i,j,al,bl;
  char tmp,atai;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",a);
    al=strlen(a);
    scanf("%s",b);
    bl=strlen(b);
    len=max(al,bl);
    reverse(a,al);
    reverse(b,bl);
    tmp=0;
    for(j=0;j<len;j++){
      if(j>=al) a[j]='0';
      if(j>=bl) b[j]='0';
      atai=tmp+a[j]+b[j]-'0'-'0';
      tmp=atai/10;
      atai=atai%10+'0';
      res[j]=atai;
    }
    if(tmp>0){
      res[j]=tmp+'0';
      len++;
    }
    res[len]='\0';
    if(len>80) printf("overflow\n");
    else{ 
      reverse(res,len);
      printf("%s\n",res);
    }
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

static int h;
static int w;

std::pair<int, int> paint(boost::multi_array<int, 2>& ss, int y, int x) {
  auto ret = std::pair<int, int>(0, 0);
  int const currentColor = ss[y][x];
  assert(currentColor == 0 || currentColor == 1);
  ss[y][x] = -1;
  if (currentColor == 0) {
    ret.first++;
  } else {
    ret.second++;
  }
  int const alternativeColor = 1 - currentColor;
  if (x < w - 1 && ss[y][x + 1] == alternativeColor) {
    auto painted = paint(ss, y, x + 1);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (y < h - 1 && ss[y + 1][x] == alternativeColor) {
    auto painted = paint(ss, y + 1, x);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (x > 0 && ss[y][x - 1] == alternativeColor) {
    auto painted = paint(ss, y, x - 1);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  if (y > 0 && ss[y - 1][x] == alternativeColor) {
    auto painted = paint(ss, y - 1, x);
    ret.first += painted.first;
    ret.second += painted.second;
  }
  return ret;
}

int64_t solve(boost::multi_array<int, 2>& ss) {
  int64_t ret = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (ss[i][j] < 0) {
        continue;
      }
      auto painted = paint(ss, i, j);
      ret += static_cast<int64_t>(painted.first) * static_cast<int64_t>(painted.second);
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  std::cin >> h;
  std::cin >> w;
  boost::multi_array<int, 2> ss(boost::extents[h][w]);
  for (int i = 0; i < h; i++) {
    std::string s;
    std::cin >> s;
    for (int j = 0; j < w; j++) {
      ss[i][j] = static_cast<int>(s[j] == '#');
    }
  }
  auto const res = solve(ss);
  std::cout << res << std::endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S;
    cin >> S;
    ll ans = 0;
    ll N = S.size();
    rep(i, N) {
        rep2(j, i + 1, N + 1) {
            string T = "";
            rep2(k, i, j) {
                T += S[k];
            }
            bool ok = true;
            rep(t, T.size()) {
                if (T[t] == 'A' || T[t] == 'G' || T[t] == 'C' || T[t] == 'T') {
                    continue;
                } else {
                    ok = false;
                }
            }
            if (ok) {
                ans = max(ans, (ll) T.size());
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.BufferedWriter
import java.util.*
import kotlin.math.ceil
import kotlin.math.floor

fun main() = Case().exec(::solve)
//fun main() = TestExecutor.assert(testCase) { Case(it.r, it.w).exec(::solve) }

/** https://atcoder.jp/contests/abc174/tasks/abc174_e **/
fun solve(c: Case) {
    val (n, k) = c.intList()
    val aList = c.longList()

    val queue = PriorityQueue<Item>(11, compareBy { it.len.toDouble() / (it.div + 1) * -1 })

    val aSum = aList.sum()
    var divided = 0
    aList.forEach { a ->
        val div = floor(k * a.toDouble() / aSum).toInt()
        queue.add(Item(a, div.toLong()))
        divided += div
    }

    while (divided++ < k) {
        val item = queue.remove()
        queue.add(Item(item.len, item.div + 1))
    }

    c.println(ceil(queue.first().let { it.len.toDouble() / (it.div + 1) }).toInt().toString())
}

data class Item(val len: Long, val div: Long)

class Case(
    private val input: BufferedReader = System.`in`.bufferedReader(),
    private val out: BufferedWriter = System.out.bufferedWriter()
) {
    fun exec(fn: (Case) -> Unit) = input.use { out.use { execInThread(fn) } }
    private fun execInThread(fn: (Case) -> Unit) =
        Thread(null, { fn(this) }, "solve", 64 * 1024 * 1024)
            .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
            .apply { start() }.join()

    fun println(c: CharSequence?) = out.appendln(c)
    fun string(): String = input.readLine().trimEnd()
    fun long(): Long = input.readLine().toLong()
    fun intList(): List<Int> = input.readLine().split(" ").map { it.toInt() }
    fun longList(): List<Long> = input.readLine().split(" ").map { it.toLong() }
}

Measured memory_bytes: 76100
#include <iostream>

#define MAX 1000000007LL

using namespace std;

typedef long long ll;

int main(void) {
    
    int N;
    int M;
    ll nNum = 1;
    ll mNum = 1;
    
    cin >> N >> M;
    
    for (int i = 0; i < N; ++i) {
     
        nNum *= (N - i);
        nNum %= MAX;
        
    }
    
    for (int i = 0; i < M; ++i) {
        
        mNum *= (M - i);
        mNum %= MAX;
        
    }
    
    
    
    if (N == M) {
        
        cout << nNum * mNum * 2 % MAX << endl;
        
    }
    else if (N - M == 1 || M - N == 1) {
        
        cout << nNum * mNum % MAX << endl;
        
    }
    else {
        
        cout << 0 << endl;
        
    }
    
    return 0;
    
}
























Measured memory_bytes: 256
/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld             long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    #endif
    ll t = 1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll N = 1e6+5;
        ll sieve[N],chk[N];
        for(ll i=0;i<N;i++)
            sieve[i] = 0;
        ll x;
        vector<ll> v;
        memset(chk,0,sizeof(chk));
        ll ans = 1;
        ll g = 0;
        for(ll i=0;i<n;i++)
        {
            cin>>x;
            v.push_back(x);
            chk[x]++;
            if(chk[x]>1 and x!=1)
                ans = 0;
            g = __gcd(x,g);
        }
        ll val = 0;
        
        for(ll i=2;i<N;i++)
        {
            if(sieve[i])
                continue;
            val = chk[i];
            for(ll j=2*i;j<N;j+=i)
            {
                sieve[j] = i;
                val += chk[j];
            }
            if(val>1)
                ans = 0;
        }
        if(ans==1)
        {
            cout<<"pairwise coprime\n";
        }
        else if(g!=1)
        {
            cout<<"not coprime\n";
            return 0;
        }
        else
        {
            cout<<"setwise coprime\n";
        }
              
    }

    
    time
    return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    int mx = -1, my = -1;
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        if (mx < x) {
            mx = x;
            my = y;
        }
    }
    printf("%d", (mx + my));
    return 0;
} 

Measured memory_bytes: 384
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N; cin >> N;
  int a[N];
  FOR(i,0,N) cin >> a[i];
  sort(a, a + N);
  reverse(a, a + N);
  int ans = 0;
  FOR(i,0,N) {
    if(i % 2 == 0) ans += a[i];
    else ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

long long N, M, S;
vector<vector<tuple<long long, long long, long long>>> G;
vector<pair<long long, long long>> CD;
long long dp[50][2555];

int main(){
    cin >> N >> M >> S;
    S = min(S, 2500LL);
    G.resize(N);
    CD.resize(N);
    REP(i, M){
        long long U, V, A, B;
        cin >> U >> V >> A >> B;
        U--; V--;
        G[U].push_back(make_tuple(V, A, B));
        G[V].push_back(make_tuple(U, A, B));
    }
    REP(i, N){
        long long C, D;
        cin >> C >> D;
        CD[i] = make_pair(C, D);
    }
    REP(i, 50) REP(j, 2555) dp[i][j] = 1LL<<60;
    dp[0][S] = 0;

    priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>> pq;
    pq.push(make_tuple(0, 0, S));

    while(!pq.empty()){
        long long d, cur, s;
        tie(d, cur, s) = pq.top();
        //cerr << d << " " << cur << " " << s << endl;
        pq.pop();
        for(auto x : G[cur]){
            long long nxt, a, b;
            tie(nxt, a, b) = x;
            if(a <= s){
                if(dp[cur][s]+b < dp[nxt][s-a]){
                    dp[nxt][s-a] = dp[cur][s] + b;
                    pq.push(make_tuple(dp[nxt][s-a], nxt, s-a));
                }
            }
        }
        long long cc = CD[cur].first, dd = CD[cur].second;
        long long ss = s + cc;
        ss = min(ss, 2500LL);
        if(dp[cur][s]+dd < dp[cur][ss]){
            dp[cur][ss] = dp[cur][s]+dd;
            pq.push(make_tuple(dp[cur][ss], cur, ss));
        }
    }
    for(int i=1; i<N; i++){
        long long ans = 1LL<<60;
        for(int j=0; j<=2500; j++)
            ans = min(ans, dp[i][j]);
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 7204
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(void)
{
  string s;
  cin>>s;
  string ret="";

  rep(i,s.size()){
    char c=s[i];
    if(c=='0'||c=='1')
    ret.push_back(c);
    else{
      if(ret=="")
      continue;
      ret.pop_back();
    }
  }
  cout<<ret<<endl;
}


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

#define ll long long

using namespace std;

ll N;
ll ans = 0;

ll dfs(ll num, bool c3, bool c5, bool c7) {
  if (c3 && c5 && c7)
    ans++;

  if (num * 10 + 3 <= N) {
    dfs(num * 10 + 3, true, c5, c7);
  }
  if (num * 10 + 5 <= N) {
    dfs(num * 10 + 5, c3, true, c7);
  }
  if (num * 10 + 7 <= N) {
    dfs(num * 10 + 7, c3, c5, true);
  }
}

int main() {
  cin >> N;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
}


Measured memory_bytes: 256
a,b,c=map(int,input().split())

l=[a,b,c]
l.sort(reverse=True)
x_max=l[0]
x_mid=l[1]
x_min=l[2]
count=0
count+=l[0]-l[1]
dif=l[0]-(l[2]+count)
if dif%2==0:
    count+=dif//2
else:
    count+=dif//2+2
print(count)

Measured memory_bytes: 3064
// author: Saman Mahdanian
#include <iostream>
#include <cstring>

#define int long long

using namespace std;
const int N = 1e5 + 10;

int n, a[N], _cnt[2 * N];
long long get_le (int);

int32_t main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];

	long long g  = 2e9;
	long long le = 0;

	while (g - le > 1) {
		int med = (g + le) / 2;
		if (get_le(med) * 2 > (n * (n + 1)) / 2)
			g = med;
		else
			le = med;
	}

	cout << g << endl;
}

long long get_le (int x) { 
	memset (_cnt, 0, sizeof _cnt);
	int* cnt = &_cnt[N];
	cnt[0] = 1;
	int cur = 0, p = 0;
	long long res = 0;

	for (int i = 0; i < n; i++) {
		int val = a[i] <= x? +1 : -1;
		if (val == 1)
			cur += cnt[p];
		else
			cur -= cnt[p - 1];

		cur = max(cur, 0LL);
		res += cur;
		p += val;
		cnt[p]++;
	}
	return res;
} 

// SamMHD :: 05/12/2018 15:52:56 :: Another Nemidoonam-Che-Kooftie...

Measured memory_bytes: 2560
import java.util.*;
public class Main {
    public static void main(String[] args) throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        int datanum=scan.nextInt();
        while(datanum!=0){
        	int n= scan.nextInt();
        	int [] step =new int[n];
        	for(int i=0;i<n;i++)step[i] =scan.nextInt();
        	int upmax=0;
        	int downmax =0;
        	for(int i=0;i<n-1;i++){
        		if(step[i]<=step[i+1])
        			upmax=Math.max(upmax,step[i+1]-step[i]);
        		else downmax=Math.max(downmax,step[i]-step[i+1]);
        }
        	System.out.println(upmax+" "+downmax);
        	datanum--;
        }
    }
}

Measured memory_bytes: 12000