akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        // 値段、個数
        Map<Integer, Integer> map = new TreeMap<>();
        
        for(int i = 0; i < N; i ++){
            int A = sc.nextInt();
            int B = sc.nextInt();
            
            Integer BB = map.get(A);
            if ( BB == null ){
                map.put(A, B);
            } else {
                map.put(A, BB + B);
            }
        }
        
        long ans = 0;
        for(int nedan : map.keySet()){
            int kosuu = map.get(nedan);
            if( kosuu < M ){
                ans += (long)nedan * kosuu;
                M -= kosuu;
            } else {
                ans += (long)nedan * M;
                break;
            }
        }
        
        System.out.println(ans);

    }
}


Measured memory_bytes: 89668
N = int(input())
A = [[0] for i in range(N)]
for i in range(N):
    A[i] = list(map(int, input().split()))

#for i in range(N):
#    A[i][i] = float("INF")

f = 0
r = [[1] * N for i in range(N)]

for k in range(N):
    for i in range(N):
        for j in range(N):
            if A[i][j] > A[i][k] + A[k][j]:
                f = 1
            elif A[i][j] == A[i][k] + A[k][j] and i != k and j != k:
                r[i][j] = 0

if f == 1:
    print("-1")
else:
    #print(r)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            ans += A[i][j] * r[i][j]

    print(ans)

Measured memory_bytes: 75824
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

int main() {
  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  rep(i, H) {
    cin >> s[i];
  }

  rep(i, H) {
    cout << s[i] << endl;
    cout << s[i] << endl;
  }
  
  return 0;
}


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

using namespace std;
using ll=long long;

const int N = 52; 
const int C = 2555; 
ll d[N][C+1];

struct State {
    ll dis;
    int i, t;
    State() {}
    State(ll _dis, int _i, int _t) : dis(_dis), i(_i), t(_t) {}
    bool operator<(const State& _oth) const {
        return dis > _oth.dis;
    }
};
void solve() {
    int n,m,S;
    cin >> n >> m >> S;
    vector<vector<tuple<int,int,int>>> g(n);
    for (int _ = 0; _ < m; _++) {
        int x,y,a,b;
        cin >> x >> y >> a >> b;
        --x,--y;
        g[x].emplace_back(y, a, b);
        g[y].emplace_back(x, a, b);
    }
    vector<pair<int,int>> charge(n);
    for (auto& x: charge) {
        cin >> x.first >> x.second;
    }

    memset(d, 0x3f, sizeof d);
    S = min(S, C);
    d[0][S] = 0;
    priority_queue<State> pq;
    pq.emplace(0,0,S);
    while (!pq.empty()) {
        auto _ = pq.top(); pq.pop();
        ll dis = _.dis;int i = _.i, t = _.t;
        if (dis > d[i][t]) continue;
        for (auto [j,a,b]: g[i]) if (a<=t){
            if (d[j][t-a] > dis + b) {
                d[j][t-a] = dis + b;
                pq.emplace(d[j][t-a], j, t-a);
            }
        }
        if (t < C) {
            int tt = min(C, t+charge[i].first);
            if (d[i][tt] > dis + charge[i].second) {
                d[i][tt] = dis + charge[i].second;
                pq.emplace(d[i][tt], i, tt);
            }
        }
    }
    for (int i = 1; i < n; i++) {
        ll res = *min_element(d[i], d[i]+C+1);
        cout << res << "\n";
    }
}

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


Measured memory_bytes: 6216
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct P {
	LL x, y;
};
P operator + (P a, P b) {
	return (P) {a.x + b.x, a.y + b.y};
}
P operator - (P a, P b) {
	return (P) {a.x - b.x, a.y - b.y};
}
P a[105];
LL dot(P a, P b) { return a.x * b.x + a.y * b.y; }
LL det(P a, P b) { return a.x * b.y - a.y * b.x; }
int quad(P a) {
	return a.y > 0 || (a.y == 0 && a.x > 0);
}
bool cmp(pair<P, int> a, pair<P, int> b) {
	if (quad(a.first) != quad(b.first)) return quad(a.first) > quad(b.first);
	return det(a.first, b.first) > 0;
}
bool cmp2(int i, int j) {
	if (a[i].x != a[j].x) return a[i].x < a[j].x;
	return a[i].y < a[j].y;
}
double ans[105];
int main() {
	int n;
	scanf("%d", &n);
	vector<int> tmp;
	for (int i = 0; i < n; ++ i) {
		scanf("%lld%lld", &a[i].x, &a[i].y);
		tmp.push_back(i);
	}
	vector<pair<P, int>> b;
	sort(tmp.begin(), tmp.end(), cmp2);
	for (int i = 0; i < n; ++ i) {
		int u = tmp[i];
		while (b.size() >= 2 && det(a[u] - a[b[b.size() - 2].second], a[b.back().second] - a[b[b.size() - 2].second]) < 0) b.pop_back();
		b.push_back({a[u], u});
	}
	int sz = b.size() - 1;
	for (int i = n - 2; i >= 0; -- i) {
		int u = tmp[i];
		while (b.size() - sz >= 2 && det(a[u] - a[b[b.size() - 2].second], a[b.back().second] - a[b[b.size() - 2].second]) < 0) b.pop_back();
		b.push_back({a[u], u});
	}
	b.pop_back();
	//for (auto p : b) printf("%lld %lld   %d\n", p.first.x, p.first.y, p.second);
	//sort(b.begin(), b.end(), cmp);
	if (b.size() == 1) {
		ans[b[0].second] = 1;
	} else if (b.size() == 2) {
		ans[b[0].second] = ans[b[1].second] = 0.5;
	} else
	for (int i = 0; i < (int) b.size(); ++ i) {
		P prv = b[(i + b.size() - 1) % b.size()].first;
		P nxt = b[(i + 1) % b.size()].first;
		P ll = b[i].first - prv, rr = nxt - b[i].first;
		P l = (P) {-ll.y, ll.x};
		P r = (P) {-rr.y, rr.x};
		//printf("l = %lld %lld  r = %lld %lld\n", l.x, l.y, r.x, r.y);
		double res = acos(1.0L * dot(r, l) / sqrt(1.0L * dot(l, l) * dot(r, r)));
		ans[b[i].second] = res / (2 * acos(-1.));
	}
	for (int i = 0; i < n; ++ i) printf("%.10f\n", ans[i]);
}



Measured memory_bytes: 256
// // Hail god Yato
 
// #include <bits/stdc++.h> 
// using namespace std;
 
// #define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// typedef long long ll;
// const ll MOD = 1000000007;
// const ll INF = 1e18;
// const ll MAX = 100001;
// //
// //
// void solve(){
//     string str;
//     cin>>str;
//     string front, back;
//     int cur = 1;
//     int q;
//     cin>>q;
//     while(q--){
//         int type;
//         cin>>type;
//         if(type == 1)
//             cur = cur*-1;
//         else{
//             char ch;
//             cin>>type>>ch;
//             if(type == 1){
//                 if(cur == 1)
//                     front.push_back(ch);
//                 else
//                     back.push_back(ch);
//             }
//             else
//                 if(cur == 1)
//                     back.push_back(ch);
//                 else
//                     front.push_back(ch);
//         }
//     }
//     if(cur == -1)
//         swap(front, back);
//     cout<<front<<str<<back;
// }
// int main(){ 
//         hs;
//         ll t;
//         t=1;
//         // cin>>t;
//         for (int i=1; i<=t; i++){
//                 //cout<<"Case #"<<i<<": ";
//                 solve();
//          }
//         return 0; 
// }


// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
void solve(){
    string str;
    int q;
    cin>>str>>q;
    deque<char> store;
    for(char ch : str)
        store.push_back(ch);
    int cur = 1;
    while(q--){
        int type;
        cin>>type;
        if(type == 1)
            cur *= -1;
        else{
            char ch;
            cin>>type>>ch;
            if(cur == -1)
                type = type^3;
            if(type == 1)
                store.push_front(ch);
            else
                store.push_back(ch);
        }
    }
    if(cur == -1)
        reverse(store.begin(), store.end());
    for(char ch : store)
        cout<<ch;
}
int main(){ 
        hs;
        ll t;
        t=1;
        // cin>>t;
        for (int i=1; i<=t; i++){
                //cout<<"Case #"<<i<<": ";
                solve();
         }
        return 0; 
}

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class ENonTriangularTriplets {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n, k; cin >> n >> k;
      vector<int> a(n), b(n), c(n);
      rep(i, n) {
        a[i] = k+i;
        b[i] = k+n+i;
        c[i] = k+(n*2)+i;
      }

      if (a[n/2]+b[n/2] > c[n/2]) {
        cout << -1 << endl;
        return;
      }
      int now = 0;
      if (n%2 == 0) {
        cout << a[0] << ' ' << b[0] << ' ' << c[0] << '\n';
        now = 1;
      }
      int p = (n-now)/2;
      int q = p+1;
      int cnt = now;
      for(int i=now; i+q<n; i++) {
        cout << a[i] << ' ' << b[i+p] << ' ' << c[cnt] << '\n';
        cnt++;
        cout << a[i+q] << ' ' << b[i] << ' ' << c[cnt] << '\n';
        cnt++;
      }
      cout << a[n-1-p] << ' ' << b[n-1] << ' ' << c[n-1] << '\n';
    }
};

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

Measured memory_bytes: 3456
// ABC143A.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
using namespace std;
int main()
{
	int A, B; // A窓の幅、Bカーテンの幅、カーテンは２枚ある
	cin >> A >> B;
	int ans; // 答えを入れる変数

	ans = A - 2 * B;
	if (ans<0)
	{
		ans = 0;
	}
	cout << ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
p = 0
mn = 1000
for i in range(N):
    H[i] = abs(A - (T - H[i] * 0.006))
    if H[i] < mn:
        mn = H[i]
        p = i

print(p + 1)


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Practice
{
    class Program
    {

        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
        }


        static void SolveA(string[] args)
        {
            string sz = (Console.ReadLine());
            int num = 0;
            for(int i=0;i<sz.Length;++i)
            {
                char c = sz[i];
                if( c == '+')
                {
                    num++;
                }else
                {
                    num--;
                }
            }
            Console.WriteLine(num);
        }
        static void SolveB(string[] args)
        {
            string sz = Console.ReadLine();
            long n = long.Parse(sz);
            int sn = 0;
            for (int i = 0; i < sz.Length; ++i)
            {
                int tmp = int.Parse(sz[i].ToString());
                sn += tmp;
            }
            if( n % sn == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }



    }

}


Measured memory_bytes: 11092
/** @Date    : 2017-05-30 19:19:37
  * @FileName: A.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;


int main()
{
	LL n, a, b;
	while(cin >> n >> a >> b)
	{
		if(a > b || (n == 1 && a != b))
		{
			printf("0\n");
			continue;
		}
		LL ans = (n - 2) * (b - a) + 1;
		if(ans < 0)
			ans = 0;
		printf("%lld\n", ans);
	}
    return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<i32>();
    let b = read::<i32>();
    let c = read::<i32>();
    println!("{}", if b - a == c - b { "YES" } else { "NO" });
}


Measured memory_bytes: 4352
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <stack>
#include <string>
#include <vector>
#include <iomanip>
 
using namespace std;
typedef long long ll;
using gra = vector<vector<ll>>;
using gram = vector<unordered_map<ll,ll>>;
 
typedef unsigned long long ull;
 
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
 
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template <class T> T dup(T a, T b) { return (a + b - 1) / b; }
template <class T> T modpow(T x, T p, T m) { T a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
// template <class T> void prim(T a) { for(ll i=0;i<a.size();++i) { cout << a[i]; } cout << "\n"; }
//template< typename T >
//T mod_pow(T x, T n, const T &p) {
//  T ret = 1;
//  while(n > 0) {
//    if(n & 1) (ret *= x) %= p;
//    (x *= x) %= p;
//    n >>= 1;
//  }
//  return ret;
//}
 
#define mod 1000000007LL
#define INF 10000000000000000LL
 
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep1(i, n) for (ll i = 1; i <= n; ++i)
#define rrep(i, n) for (int i = (n - 1); i >= 0; --i)
#define rrep1(i, n) for (int i = n; i > 0; --i)
 
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
//#define modpow(x, p, m) { ll a=1; while(p){ if(p%2)a =a*x%m; x = x+x%m; p/=2; } return a; }
 
#define m0(h) memset(h, 0, sizeof(h))
#define m1(h) memset(h, 1, sizeof(h))
#define m(h, n) memset(h, (n), sizeof(h))
#define all(n) (n).begin(),(n).end()
#define bit(n) (1LL << (n))
#define pb push_back
#define mp make_pair
 
//#ifdef LOCAL
//
//#define dpri(...) fprintf(stderr, __VA_ARGS__)
//#define pria(g) rep(i,g.size()){ cout << i << "{"; rep(j,g[i].size()) cout << g[i][j] << " "; cout << "}" << "\n"; }
//#else
//#define dpri(...) 42
//#define pria(g) 42
//#endif
//
//
//
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ---------------------
  // コーディング開始
  // ---------------------
  ll n,m,x;
  cin >> n >> m >> x;
  ll a;
  ll co = 0;
  rep(i,m){
    cin >> a;
    if(a<x)co++;
  }
  pri(min(co,m-co));
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1000000000000000000;
int main() {
	int a, b, tester=0;
	cin >> a >> b;
	for (long long i = a; i < inf; i+=a) {
		if (i%b != 0) {
			cout << i << endl;
			break;
		}
		else {
			tester++;
			if (tester == 2) {
				cout << -1 << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  int memo[n + 1];
  memo[0] = 0; memo[1] = 1;
  FOR(i, 2, n + 1) {
    memo[i] = memo[i - 1] * i;
  }

  vector<int> d;
  for(int i = n; i>0; i--) {
    d.push_back(i);
  }

  int qp = 1;
  REP(i, n) {
    int q;
    cin >> q;
    REP(j, d.size()) {
      if(d[j] == q) {
        qp += (d.size() - (j + 1)) * memo[n - (i + 1)];
        d.erase(d.begin() + j);
        break;
      }
    }
  }

  vector<int> dd;
  for(int i = n; i>0; i--) {
    dd.push_back(i);
  }

  int rp = 1;
  REP(i, n) {
    int q;
    cin >> q;
    REP(j, dd.size()) {
      if(dd[j] == q) {
        rp += (dd.size() - (j + 1)) * memo[n - (i + 1)];
        dd.erase(dd.begin() + j);
        break;
      }
    }
  }



  cout << abs(rp - qp) << endl;  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a;
    char op;
    int b;
    cin >> a >> op >> b;
    if (op == '+')
        cout << a+b;
    else
        cout << a-b;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int a[4],s[2],d,f,g,h,i,j;
	for(i=0;i<4;i++){
		scanf("%d",&a[i]);
		if(i>0&&a[i]>a[i-1]){
			d=a[i-1];
			a[i-1]=a[i];
			a[i]=d;
		}
	}
	for(i=0;i<2;i++){
		scanf("%d",&s[i]);
		if(i>0&&s[i-1]<s[i]){
			s[i-1]=s[i];

		}
	}
		printf("%d\n",a[0]+a[1]+a[2]+s[0]);
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};

int main() {
  int N,K;
  cin >> N >> K;
  UnionFind uf(N-K+1);
  int P[N];
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  if (N == K) {
    cout << 1 << endl;
    return 0;
  }
  set<int> Set;
  for (int i = 0; i <= K; i++) {
    Set.insert(P[i]);
  }
  int ans = 0;
  for (int i = 0; i < N - K; i++) {
    auto itr = Set.begin();
    auto itr2 = prev(Set.end(),1);

    if (*itr == P[i] && *itr2 == P[K+i]) {
      uf.unite(i,i+1);
    }
    if (i != N-K-1) {
      Set.erase(P[i]);
      Set.insert(P[K+i+1]);
    }
  }
  int R[N];
  R[0] = 0;
  vector<int> sam;
  for (int i = 1; i < N; i++) {
    if (P[i-1] > P[i]) {
      R[i] = R[i-1] + 1;
    } else {
      R[i] = R[i-1];
    }
  }
  for (int i = 0; i <= N-K; i++) {
    if (R[i] == R[i+K-1]) {
      sam.push_back(i);
    }
  }
  for (int i = 1; i < (int)sam.size(); i++) {
    uf.unite(sam[i],sam[i-1]);
  }
  
  for (int i = 0; i <= N-K; i++) {
    if (uf.find(i) == i) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14432
#include<iostream>
using namespace std;
int main(){
int a,b;
for(;;){
cin>>a>>b;
if(a==0||b==0){
break;
}
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
cout<<"#";
}
cout<<endl;
}
cout<<endl;
}
}

Measured memory_bytes: 3024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define N 200020
typedef long long ll;
//#define int ll
inline ll read(){
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,an,bn;
ll k,a[N],b[N],l,r,ans;
inline ll check(ll x){
	ll tot=0;
	int l=0,r=0;
	if(x>0){
		tot=1LL*an*bn;
		r=bn;
		for(l=1;l<=bn;l++){
			while(l<r&&b[l]*b[r]>=x){
				--r;
			}
			if(l==r)break;
			tot+=r-l;
		}
		l=1;
		for(r=an;r>=1;--r){
			while(l<r&&a[l]*a[r]>=x){
				++l;
			}
			if(l==r)break;
			tot+=r-l;
		}
	}
	else{
		r=1;
		for(l=1;l<=an;++l){
			while(r<=bn&&a[l]*b[r]>=x){
				++r;
			}
			if(r>bn)break;
			tot+=bn-r+1;
		}
	}
	return tot;
}
int main(){
	//freopen("1.in","r",stdin);
	n=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	} 
	sort(a+1,a+n+1);
	while(an<n&&a[an+1]<0){
		++an;
	}
	for(int i=an+1;i<=n;i++){
		b[++bn]=a[i];
	}
	l=-1e18-1,r=1e18+1;
	while(l<r){
		ll mid=(l+r)>>1;
		if(check(mid)<k){
			ans=mid,l=mid+1;
		}
		else{
			r=mid;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, u, v;
    cin >> N >> u >> v;
    --u;--v;
    vector<vector<unsigned long>> edge(N);
    vector<unsigned long> distu(N), distv(N);
    for(unsigned long i{1}, A, B; i < N; ++i){
        cin >> A >> B;
        --A;--B;
        edge[A].push_back(B);
        edge[B].push_back(A);
    }
    [dfs = [&edge, &distu, &v](auto f, unsigned long n, unsigned long prev, unsigned long d) -> void{
        distu[n] = d;
        for(const auto& i : edge[n])if(i != prev)f(f, i, n, d + 1);
    }](unsigned long n){dfs(dfs, n, n, 0);}(u);
    [dfs = [&edge, &distv, &v](auto f, unsigned long n, unsigned long prev, unsigned long d) -> void{
        distv[n] = d;
        for(const auto& i : edge[n])if(i != prev)f(f, i, n, d + 1);
    }](unsigned long n){dfs(dfs, n, n, 0);}(v);
    unsigned long ans{0};
    for(unsigned long i{0}; i < N; ++i)if(distu[i] < distv[i])ans = max(ans, distv[i] - 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
int gcd2(int p,int q){
    if (q == 0){
        return p;
    }
    return gcd2(q, p%q);
}
int gcd3(int a,int b,int c){
    return gcd2(gcd2(a, b),c);
}
int main()
{
    int k;
    cin >> k;
    long sum=0;
    for(int a=1;a<=k;a++){
        for(int b=1;b<=k;b++){
            for(int c=1;c<=k;c++){
               sum+=gcd3(a,b,c); 
            }
        }
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
//#define DEBUG
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template <class T>
void print_vect(std::vector<T> v){
    for(int i = 0 ; i < v .size(); i++) cout << v[i] << " ";
    cout << endl;
}

int cal_cost(vi& a , int p){
    int ans = 0;
    for(const auto & num : a){
        ans += (num - p) * ( num - p);
    }
    return ans;
}

void solve(){
    int N;
    cin >> N;
    vi X(N);
    for(int i = 0 ; i< N ; i++){
        cin >> X[i];
    }
    int min_cost = 100 * 100 * 100;
    for(int p = 1 ; p <= 100 ; p++){
        int cost = cal_cost(X, p);
        if( cost < min_cost){
            min_cost = cost;
        }
    }
    cout << min_cost << endl;
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/

    #ifdef DEBUG
    int TEST_CASES = 2;
    while(TEST_CASES--){
    #endif // DEBBUG

    solve();

    #ifdef DEBUG
    }
    #endif // DEBUG
    
    return 0;
}



Measured memory_bytes: 3656
#include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int inf=1<<29;

int main(){
	int n,m,x;
	scanf("%d %d",&n,&m);
	x=n+m;
	if(x%2==0) printf("%d",x/2);
	else printf("%d",x/2+1);
}

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

using namespace std;
priority_queue<int> q;
int main()
{
  int n, m; scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i)
  {
    int x; scanf("%d", &x);
    q.push(x);
  }
  long long ans = 0;
  for (int i = 1; i <= m; ++i)
  {
    int now = q.top(); q.pop();
    q.push(now / 2);
  }
  while (!q.empty()) ans += q.top(), q.pop();
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 892
import java.util.*;


public class Main {

    static void solve() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int h = sc.nextInt();

        ArrayList<Integer> a = new ArrayList<Integer>();
        ArrayList<Integer> b = new ArrayList<Integer>();

        int maxA = 0;
        for(int i = 0; i < n; i++) {
            int newA = sc.nextInt();
            int newB = sc.nextInt();
            a.add(newA);
            b.add(newB);
            if(newA > maxA){
                maxA = newA;
            }
        }

        for(int i = n-1; i >= 0; i--){
            if(b.get(i) < maxA){
                a.remove(i);
                b.remove(i);
            }
        }

        int sumB = 0;
        for(int i = b.size()-1; i >= 0; i--){
            sumB += b.get(i);
        }

        int count = 0;
        if(h > sumB){
            h -= sumB;
            count += h/maxA;
            h = h%maxA;
            if(h > 0){
                h -= maxA;
                count++;
            }
            h += sumB;
        }
        Collections.sort(b);
        for(int i = b.size()-1; i >= 0; i--){
            if(h <= 0){
                break;
            }
            h -= b.get(i);
            b.remove(i);
            count++;
        }

        System.out.println(count);
    }

    public static void main(String[] args) {
        solve();
    }
}


Measured memory_bytes: 91632
'use strict'

function main(input){
    const N = Number(input[0]);
    const P = input[1].split(' ').map(Number);
    let ans = 0;
    for(let i=0;i<N-2;i++){
        if((P[i+1]-P[i])*(P[i+2]-P[i+1])>0) ans++;
    }
    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split('\n'))

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<tuple>

#define DIV 1000000007
using namespace std;
using ll = long long;
using ldb = long double;

ll pm(vector<ll>& a, ll M, ll K) {
	int N = a.size();
	vector<ll> b(N);
	ll srm = 0;
	for (int i = 0; i < N; i++) {
		b[i] = a[i] % M;
		srm += b[i];
	}

	sort(b.begin(), b.end(), greater<ll>());
	ll inc = 0;
	for (int i = 0; i < srm / M; i++) {
		inc += (M - b[i]);
	}

	if (inc <= K)return M;
	else return 0;
}

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> a(N);
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}

	ll d = 1;
	for (ll i = 2; i <= sqrt(sum); i++) {
		if (sum % i == 0) {
			d = max(d, pm(a, i, K));
			d = max(d, pm(a, sum / i, K));
		}
	}

	if (sum >= 2) d = max(d, pm(a, sum, K));
	cout << d << endl;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int N=2005;
int n,l,r,a[N];

signed main(){
	read(n);read(l);read(r);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++){
			int dis;
			if(j<=l||i>=r) dis=j-i;
			else if(i<=l&&j>=r) dis=j-r+l-i+1;
			else if(i<=l) dis=min(j-i,r-j+1+l-i);
			else if(j>=r) dis=min(j-i,i-l+1+j-r);
			else dis=min(j-i,r-j+i-l+1);
			a[dis]++;
		}
	for(int i=1;i<n;i++) write(a[i]),puts("");
}


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

const int INF=1e18;
const int SIZE=2510;
struct edge{int from,to,cost;};

vector<edge> edges;
vector<vector<int>> G,revG;
bool visited[SIZE];
bool ng[SIZE];

int N,M,P;

void dfs(int v)
{
    visited[v]=true;
    for(int u:G[v]){
        if(!visited[u]) dfs(u);
    }
}

void revdfs(int v)
{
    visited[v]=true;
    for(int u:revG[v]){
        if(!visited[u]) revdfs(u);
    }
}

signed main()
{
    cin>>N>>M>>P;
    G.resize(N);
    revG.resize(N);
    for(int i=0;i<M;i++){
        int a,b,c; cin>>a>>b>>c;
        a--; b--;
        edges.push_back({a,b,P-c});
        G[a].push_back(b);
        revG[b].push_back(a);
    }

    for(int i=0;i<N;i++) visited[i]=false;
    dfs(0);
    for(int i=0;i<N;i++) if(!visited[i]) ng[i]=true;

    for(int i=0;i<N;i++) visited[i]=false;
    revdfs(N-1);
    for(int i=0;i<N;i++) if(!visited[i]) ng[i]=true;
    
    vector<int> dist(N,INF);
    dist[0]=0;
    for(int i=0;i<N;i++){
        for(edge e:edges){
            if(ng[e.from] or ng[e.to]) continue;
            if(dist[e.from]!=INF and dist[e.to]>dist[e.from]+e.cost){
                dist[e.to]=dist[e.from]+e.cost;
                if(i==N-1){
                    cout<<-1<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<max(0LL,-dist[N-1])<<endl;
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define dis distance
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define pub push_back
#define sec second
#define fir first

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	map<char,bool> M;
	
	REP(i,SZ(s)){
		M[s[i]] = true;
	}
	
	bool ans = true;
	if((M['N']&&(!M['S']))||(M['S']&&(!M['N']))||(M['E']&&(!M['W']))||(M['W']&&(!M['E']))){
		cout << "No" << endl;
	}else{
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

/*
 * AtCoder Beginner Contest 101 C
 */
public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int K = scanner.nextInt();

		int[] A = new int[N];
		int minNumIndex = 0;
		for (int i = 0; i < N; i++) {
			A[i] = scanner.nextInt();
			if (A[i] == 1) {
				minNumIndex = i + 1;
			}
		}

		
		int count = (N - K) / (K - 1) + 1;
		int remain = (N - K) % (K - 1);
		if (remain != 0) {
			count++;
		}

		System.out.println(count);

	}

}


Measured memory_bytes: 50200
a, b = [int(x) for x in input().split()]
 
if (b < a):
    tmp = b
    b = a
    a = tmp
 
 
x = 1
while True:
    if (int(x*0.08) == a and int(x*0.1) == b):
        print(x)
        break
    else:
        if (x > 1500):
            print(-1)
            break
        else:
            x += 1

Measured memory_bytes: 3064
n, x = input().split()
n, x = int(n), int(x)
arr = [int(x) for x in input().split()]

pf = [arr[0] for i in range(n)]

for i in range(1, n):
    pf[i] = pf[i-1] + arr[i]

c = 0
for i in pf:
    c += (i <= x)

print(c+1)

Measured memory_bytes: 3064
import numpy as np
N,W = map(int, input().split())
# np.maximum https://www.sejuku.net/blog/69175
# 第一引数と第二引数の大小関係を要素ごとに比較して、大きい方を格納した配列を返す
dp = np.zeros(W+1, dtype=np.int64)
# その重さでの最大valueが保存されている
for _ in range(N):
    w,v = map(int,input().split())
    # w以下ならvを足したもの、w以上ならそのままの値で、最大値を求める
    # 出力はw以上の配列として返す(それ以下は重さwなので関与しない)
    # 足す場合が前者、足さない場合が後者
    np.maximum(dp[:W-w+1]+v,dp[w:],out=dp[w:]) 

print(dp[-1])


Measured memory_bytes: 15828
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

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

// 素集合データ構造 UnionFind T(N); で構築
struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<ll> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<ll> sizes;

  UnionFind(ll n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  ll find(ll x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(ll x, ll y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(ll x, ll y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  ll size(ll x) {
    return sizes[find(x)];
  }
};

int main() {
    ll N, M;
    cin >> N >> M;
    vector<P> path;
    rep(i, M) {
        ll A, B;
        cin >> A >> B;
        path.pb(make_pair(A, B));
    }

    reverse(all(path));
    vector<ll> results;
    UnionFind T(N);
    ll res = (N * (N -1) / 2);
    rep (i, M) {
        // 答えを追加
        results.pb(res);

        // 次の答えを作成
        P p = path[i];
        ll a = p._1 - 1;
        ll b = p._2 - 1;

        // パスの両端の連結成分が違うなら、その両端の数を掛けたものを前より引く
        if (T.find(a) != T.find(b)) {
            res = res - (T.size(a) * T.size(b));
        }

        // 結合する
        T.unite(a, b);
    }

    reverse(all(results));

    rep (i, M) {
        cout << results[i] << endl;
    }
}

Measured memory_bytes: 4596
//
//
//
//
//
//
//

#include <iostream>
#include <complex>

using namespace std;
typedef complex<double> xy_t;

double cross_product(complex<double> a, complex<double> b)
{
  return (conj(a) * b).imag();
}

int main()
{
  int n; //??????????????°
  cin >> n;
  while (n > 0) {
    complex<double> a, b, c, d, e, f;
    double real[4], imag[4];
    for (int i = 0; i < 4; i++)
      cin >> real[i] >> imag[i];
    
    a = xy_t(real[0], imag[0]);
    b = xy_t(real[1], imag[1]);
    c = xy_t(real[2], imag[2]);
    d = xy_t(real[3], imag[3]);
    
    e = a - b;
    f = c - d;
    double judge = cross_product(e, f);
    if (abs(judge) < 1e-11)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    n--;
  }
}

/*
complex?????????????§????????????§???????????????????????????????????§?????????????????°??¢????????¨???????????????
double????????£??????????????¨????????£???????????????????????¨????°???\?????????????????¶??????????????????????????????
????????????????????¬????¬????????????????????????????
????????\????????????????????????????????????????????¨???????????????
*/

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

using namespace std;


int main() {
    string s;
    cin >> s;
    vector<int> v;
    long long ans = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'W') {
            v.push_back(i);
        }
    }
    for(int i = 0; i < v.size(); i++) {
        ans += (v[i] - i);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int N, M;
	cin >> N >> M;
	
	int s[5], c[5];
	REP(i, M) cin >> s[i] >> c[i];
	REP(i, 10000) {
		string S = to_string(i);
		if (S.size() != N) continue;
		
		bool ok = true;
		REP(j, M) if (S[s[j]-1] != c[j] + '0') ok = false;
		
		if (ok) {
			cout << S << endl;
			return 0;
		}
	}
	
	puts("-1");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <map>
#include <string>
#include <math.h>
using namespace std;
typedef long long ll;


int main() {

    string s;
    cin >> s;
    int a=0;
    int b=0;
    for(int i=0;i<3;i++){
        if('A'==s[i]){
            a++;
        }else if('B'==s[i]){
            b++;
        }
    }
    if(a==3||b==3){
        cout << "No" << endl;
        return 0;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int p=0;
    if(n<10)
        cout<<n<<endl;
    else{
        int a[10][10];
        for(int i=1;i<10;i++){
            for(int j=1;j<10;j++){
                a[i][j]=0;
            }
        }
        for(int i=1;i<=n;i++){
            string s=to_string(i);
            int l=s.size();
            if(s[l-1]!='0'){
                int x=s[0]-'0';
                int y=s[l-1]-'0';
                //swap(s[0],s[l-1]);
                a[x][y]++;
            }
        }
        for(int i=1;i<10;i++){
            for(int j=1;j<10;j++){
                p+=a[i][j]*a[j][i];
            }
        }
        cout<<p<<endl;

    }
}


Measured memory_bytes: 3772
import math

a,b,x = map(int,input().split())

if x == (a**2)*b:
    ans = 90
elif x == (a**2)*b/2:
    ans = 45
elif x < (a**2)*b/2:
    rad = math.atan(2*x/(a*b**2))
    ans = math.degrees(rad)
else:
    rad = math.atan(a**3/(2*a**2*b - 2*x))
    ans = math.degrees(rad)
print(90-ans)

Measured memory_bytes: 3060
def gcd(N,M):
    while True:
        if min(N,M)==0:
            return max(N,M)
        elif N>=M:
            N%=M
        elif M>N:
            M%=N
def lcm(N,M):
    return N*M//gcd(N,M)

N,M=list(map(int,input().split()))
S=input()
T=input()

L=lcm(N,M)

for i in range((N*M)//L):
    if S[i*L//M]!=T[i*L//N]:
        L=-1
        break
print(L)

Measured memory_bytes: 3316
#include<stdio.h>
#include<stdlib.h>
#define N_MAX 105
#define INF 30000000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define NIL -1

int n, M[N_MAX][N_MAX];

void dijkstra(int n)
{
  int minv;
  int d[N_MAX], color[N_MAX];
  int i, v, u;

  for(i=0; i<n; i++){
    d[i] = INF;
    color[i] = WHITE;
  }
  
  d[0] = 0;
  color[0] = GRAY;
  while(1){
    //  printf("FUCK\n");
    u=NIL;
    minv = INF;
    for(i=0; i<n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u=i;
	minv = d[i];
      }
    }

    if(u == NIL){
      break;
    }

    color[u] = BLACK;
    for(v=0; v<n; v++){
      if(color[v] != BLACK && M[u][v] != INF){
	if(d[v] > d[u] + M[u][v]){
	  d[v] = d[u] + M[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }
  
  for(i=0; i<n; i++){
    printf("%d %d\n", i, d[i]);
  }
}

int main()
{
  int i, j;
  int u, k, v, c;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    for(j=0; j<n; j++){
      M[i][j] = INF;
    }
  }

  for(i=0; i<n; i++){
    scanf("%d%d", &u, &k);
    for(j=0; j<k; j++){
      scanf("%d%d", &v, &c);
      M[u][v] = c;
    }
  }

  dijkstra(n);

  return 0;
}

Measured memory_bytes: 636
#include <iostream>

using namespace std;

int n, q;
bool v[100010], used[100010];

void magic(int i)
{
	if (v[i] && !used[i])
	{
		//v[i] = 0;

		if (i - 1 >= 1)
		{
			v[i - 1] = 1;
			used[i - 1] = 1;
		}

		if (i + 1 <= n)
		{
			v[i + 1] = 1;
			used[i + 1] = 1;
		}
	}
}

int main()
{
	v[1] = 1;
	cin >> n >> q;
	int ballpos = 1;
	for (int i = 1; i <= q; i++)
	{
		magic(ballpos);
		int a, b;
		cin >> a >> b;
		if (a == ballpos)
			ballpos = b;
		else if (b == ballpos)
			ballpos = a;
		swap(v[a], v[b]);
		swap(used[a], used[b]);
		magic(ballpos);
	}

	int nr = 0;
	for (int i = 1; i <= n; i++)
		nr += v[i];

	cout << nr;

	return 0;
}

Measured memory_bytes: 384
N = int(input())
X = []
U = []
total = 0
for i in range(N):
    a,b = map(str, input().split())
    X.append(a)
    U.append(b)

for i in range(len(X)):
    if U[i] == "JPY":
        total += int(X[i])
    else:
        n = float(X[i]) * 380000
        total += n
print(total)



Measured memory_bytes: 3060
#include <iostream>
using namespace std;
unsigned long long dp[17][17];
bool able[17][17];

int main(void){
  int n, m;
  while(cin >> n >> m, n && m){
    for(int i = 0; i < 17; i++)
      for(int j = 0; j < 17; j++){
	dp[i][j] = 0;
	able[i][j] = true;
      }
    int c;
    cin >> c;
    while(c--){
      int i, j;
      cin >> i >> j;
      able[i][j] = false;
    }

    dp[1][1] = 1;
    able[1][1] = false;

    for(int i = 1; i <= n; i++)
      for(int j = 1; j <= m; j++)
	if(able[i][j])
	  dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
    
    cout << dp[n][m] << endl;
  }
  return 0;
}

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

int main() {
	ll n, x, m; cin >> n >> x >> m;
	vector<ll> cnt;
	ll rem = x;
	ll tmp = m;
	while (tmp--) {
		cnt.push_back(rem);
		rem = (ll)pow(rem, 2) % m;
		if (find(cnt.begin(), cnt.end(), rem) != cnt.end())
			break ;
	}
	ll mae = distance(cnt.begin(), find(cnt.begin(), cnt.end(), rem));
	ll maeSUM = accumulate(cnt.begin(), cnt.begin() + mae, 0LL);
	ll loop = cnt.size() - mae;
	ll loopSUM = accumulate(cnt.begin() + mae, cnt.end(), 0LL);
	ll res = 0;
	if (n <= cnt.size()) {
		REP(i, n)
			res += cnt[i];
	}
	else if (n > cnt.size()) {
		res += maeSUM;
		n -= mae;
		ll div = n / loop;
		ll mod = n % loop;
		res += loopSUM * div;
		res += accumulate(cnt.begin() + mae, cnt.begin() + mae + mod, 0LL);
	}
	cout << res << '\n';
    return 0;
}


Measured memory_bytes: 3908
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int dp[1010][1010];
int main(){
    //cout<<"Yes"<<endl;
    int n;
    cin>>n;
    rep(k,n){
        //cout<<"aaa"<<endl;
        string s,t;
        cin>>s>>t;
        rep(i,1010) rep(j,1010) dp[i][j]=0;
        for(int i=0;i<s.size();i++){
            for(int j=0;j<t.size();j++){
                if(s[i]==t[j]) dp[i+1][j+1]=dp[i][j]+1;
                else{
                    dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
                }
            }
        }
        cout<<dp[s.size()][t.size()]<<endl;
    }
    return 0;
}


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

int main(){
    int h,w,cnt=0; cin>>h >>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            char a; cin>>a;
            if(a=='#')cnt++;
        }
    }
    if(cnt==h+w-1){
        cout<<"Possible"<<endl;
    }else{
        cout<<"Impossible"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main()
{
	int n, m, k, i, j, c = 0;

	scanf("%d %d %d", &n, &m, &k);

	for (i = 0; i <= n; i++) {
		for (j = 0; j <= m; j++) {
			if (i * (m - j) + (n - i) * j == k) {
				c = 1;
			}
		}
	}

	if (c == 1) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  int N;
  cin>>N;
  int a[2][N];
  for(int i=0;i<N;i++)scanf("%d",&a[0][i]);
  for(int i=0;i<N;i++)scanf("%d",&a[1][i]);
  int maxn=0,cnt;
  for(int i=0;i<N;i++){
    cnt=0;
    for(int j=0;j<=i;j++){
      cnt+=a[0][j];
    }
    for(int j=i;j<N;j++){
      cnt+=a[1][j];
    }
    maxn=max(maxn,cnt);
  }
  cout<<maxn<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void printArray(int *as, int n)
{
  int i;
  for (i = 0; i < n - 1; i++) {
    printf("%d ", as[i]);
  }
  printf("%d\n", as[n - 1]);
}

void bubbleSort(int *as, int n)
{
  int i, j;
  int x, y;
  int count = 0;

  for (i = 0; i < n; i++) {
    for (j = n - 1; j > i; j--) {
      x = as[j];
      y = as[j - 1];
      if (x < y) {
        as[j] = y;
        as[j - 1] = x;
        count++;
      }
    }
  }
  printArray(as, n);
  printf("%d\n", count);
}

int main(int argc, char *argv[])
{
  char row[4];
  int n = atoi(fgets(row, sizeof(row), stdin));
  int as[n];
  int i;

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

  bubbleSort(as, n);

  return 0;
}

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

const int MAXN = 100010;
int xs[MAXN], D, n, Q;
int R[MAXN][20];
int main() {
	std::ios_base::sync_with_stdio(false), std::cin.tie(0);
	std::cin >> n;
	for (int i = 1; i <= n; ++i) std::cin >> xs[i];
	std::cin >> D >> Q;
	for (int i = 1; i <= n; ++i)
		R[i][0] = std::upper_bound(xs + 1, xs + 1 + n, xs[i] + D) - xs - 1;
	for (int i = 1; i < 20; ++i)
		for (int j = 1; j <= n; ++j)
			R[j][i] = R[R[j][i - 1]][i - 1];
	while (Q --> 0) {
		int x, y, t = 0; std::cin >> x >> y; if (x > y) std::swap(x, y);
		for (int i = 19; ~i; --i) if (R[x][i] < y) t += 1 << i, x = R[x][i];
		std::cout << t + 1 << '\n';
	}
	return 0;
}


Measured memory_bytes: 9088
#include<iostream>
int main(){
  long long a,s,d,f,ans=0ll;
  std::cin>>a>>s>>d;
  if (d>s){ans=d-s;d=s;}
  for (int i=0;i<a-1;i++){
    std::cin>>f;
    if (d+f>s){ans+=d+f-s;d=s-d;}else{d=f;}}
  std::cout<<ans<<std::endl;}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, w = map(int, input().split())
items = [tuple(map(int, input().split())) for _ in range(n)]

dp = [[0] * (w + 1) for _ in range(n + 1)]

for i, (wi, vi) in enumerate(items):
    for j in range(w + 1):
        if j >= wi:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wi] + vi)
        else:
            dp[i + 1][j] = dp[i][j]

print(dp[n][w])


Measured memory_bytes: 148740
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
	double a,temp;
	double sum;
	while(scanf("%lf",&a)!=EOF){
		temp=a;
		sum=a;
		for(int i=2;i<=10;i++){
			if(i%2==0)
			temp=temp*2;
			else
			temp=temp/3;
			sum+=temp;
		}
		printf("%.8f\n",sum);
	}
}

Measured memory_bytes: 3164
import std;
enum inf(T)()if(__traits(isArithmetic,T)){return T.max/4;}
T scan(T=long)(){return readln.chomp.to!T;}
void scan(T...)(ref T args){auto input=readln.chomp.split;foreach(i,t;T)args[i]=input[i].to!t;}
T[] scanarr(T=long)(){return readln.chomp.split.to!(T[]);}
//END OF TEMPLATE

void main(){
    long a,b,c,k;
    scan(a,b,c,k);
    if(k<=a){
        k.writeln;
    }else if(k<=a+b){
        a.writeln;
    }else{
        (a-(k-a-b)).writeln;
    }   
}


Measured memory_bytes: 3672