akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
const ll INF = 1LL<<60;
const int INT_INF = 1e9;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::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; }
using namespace std;

int dp[50];

int main() {
    int n; cin >> n;
    dp[0] = dp[1] = 1;

    // DP
    for (int i = 0; i < n; i++) {
        dp[i+2] = dp[i] + dp[i+1];
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
int dist1[200009],dist2[200009],n,a,b;
vector<int>x[200009];
void dfs1(int pos,int depth)
{
    
    if(dist1[pos]!=-1) return;
    dist1[pos]=depth;
    for(int i=0; i<x[pos].size(); i++) dfs1(x[pos][i],depth+1);
}
void dfs2(int pos,int depth)
{
    
    if(dist2[pos]!=-1) return;
    dist2[pos]=depth;
    for(int i=0; i<x[pos].size(); i++) dfs2(x[pos][i],depth+1);
}
int main()
{
    cin>>n;
    for(int i=0; i<n-1; i++)
    {
        cin>>a>>b;
        x[a].push_back(b);
        x[b].push_back(a);
    }
    for(int i=0; i<200009; i++)
    {
        dist1[i]=-1;
        dist2[i]=-1;
    }
    dfs1(1,0);
    dfs2(n,0);
    int cnt1=0,cnt2=0;
    for(int i=1; i<=n; i++)
    {
        if(dist1[i]<=dist2[i]) cnt1++;
        else cnt2++;
    }
    if(cnt1>cnt2) cout<<"Fennec"<<endl;
    else cout<<"Snuke"<<endl;
    
    return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
int check(int x){
    int tmp = (s[x]-'0')*100+(s[x+1]-'0')*10+s[x+2]-'0';
    return abs(tmp-753);
}
int main() {
    ios::sync_with_stdio(false);
    cin>>s;
    int ans = 1e9;
    for(int i=0;i<s.length()-2;i++){
        ans = min(ans,check(i));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
A=sorted(list(map(int, input().split())))
amax=max(A)
half=amax/2

ans=0
now=amax
for a in A:
  if abs(a-half)<=now and a<amax:
    now=abs(a-half)
    ans=a
print(amax, ans)

Measured memory_bytes: 14052
import scala.collection.immutable.Queue

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val H, W = sc.nextInt(); sc.nextLine()
    val S: Array[Array[Char]] = Array.fill(H)(sc.nextLine().toCharArray)

    // 開始時点ではマス(1,1)にキャラクターがいる
    // プレイヤーは白いマスだけを通って, H, Wにたどり着けばゲームクリア
    // ゲームを開始する前に, いくつかの白いマスを黒に変えることができる
    // ただし, マス1,1とH,Wの色を変えることはできず、ゲーム開始前に全ての色の更新を
    // 行わなければならない
    // ゲームをクリアしたとき, ゲームの開始前にマスの色を変えた回数がスコアになる
    // その時, 取る可能性のある最大スコア
    // ただし, どのようにマス目の色を変えても, H,Wにたどり着くことができない時 -1になる
    // つまり, 最短距離が, ゴールする際の最小マスなので,
    // 通るときに使うマス以外は黒くすることができる.
    // つまり, 初期状態の白いマスの数 - 最短距離のマスの数 で, たどり着くことができない場合は -1となる

    def solve(H: Int, W: Int, S: Array[Array[Char]]): Int = {
      val vector = List((0, 1), (1, 0), (0, -1), (-1, 0))
      val dist = Array.fill(H, W)(-1)
      def bfs(queue: Queue[(Int, Int)]): Unit =
        if (queue.nonEmpty) {
          val (x, y) = queue.head
          val candidates = vector
            .map { case (dx, dy) => (x + dx, y + dy) }
            .filter { case (x, y) =>
              x >= 0 && x < W && y >= 0 && y < H &&
              dist(y)(x) < 0 && S(y)(x) == '.'
            }
          candidates foreach { case (nx, ny) => dist(ny)(nx) = dist(y)(x) + 1 }
          bfs(queue.tail.enqueue(candidates))
        }
      dist(0)(0) = 1
      bfs(Queue((0, 0)))
      val d = dist(H - 1)(W - 1)
      if (d == -1) d
      else {
        val white = S.foldLeft(0)((c, arr) => arr.foldLeft(c)((c, m) => if (m == '.') c + 1 else c))
        white - d
      }
    }

    val r = solve(H, W, S)
    println(r)
  }

}


Measured memory_bytes: 55848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n;
    cin >> n;
    vector<ll> nums(n);
    vector<ll> packet(1e5 + 1);
    ll ans = 0;
    for(int i = 0; i < n; i++) {cin >> nums[i]; ans += nums[i]; packet[nums[i]]++;}
    int q;
    cin >> q;
    vector<ll> out;
    for(int i = 0; i < q; i++){
        ll b, c;
        cin >> b >> c;
        ll from = packet[b];
        ans += (c - b) * from;
        packet[c] += from;
        packet[b] = 0;
        out.push_back(ans);
    }
    for(int i = 0; i < out.size(); i++){
        cout << out[i] << "\n";
    }
}

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

int main() {
  
  double W,H,x,y;
  cin>>W>>H>>x>>y;
  // 小数点以下10桁まで
  cout << fixed << setprecision(6);

  cout<<(double)W*H/2;
  
  
  if(x==W/2&&y==H/2){
    cout<<" "<<"1"<<endl;
  }else{
    cout<<" "<<"0"<<endl;
  }
  
}


  
  
  

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

N = I()
A = [I() for _ in range(N)]

d = defaultdict(int)
for i in range(N):
    if d[A[i]]==0:
        d[A[i]] = 1
    else:
        d[A[i]] = 0

ans = 0
for k in d.keys():
    if d[k] != 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 54492
def dfs(root):
    visited = [False] * n
    queue = [(0, root)]
    longest = (-1, -1)

    while queue:
        total_weight, node = queue.pop()
        if visited[node]:
            continue
        visited[node] = True
        longest = max(longest, (total_weight, node))
        for w, t in edges[node]:
            if not visited[t]:
                queue.append((total_weight + w, t))

    return longest


n = int(input())

edges = [set() for _ in range(n)]

for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].add((w, t))
    edges[t].add((w, s))

_, ln = dfs(0)
ld, _ = dfs(ln)
print(ld)

Measured memory_bytes: 52868
//include----------------------------------------------------------------------------------------------------------------------
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cctype>
#include <string>
#include <vector>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <bitset>
#include <map>
#include <algorithm>
#include <memory>


//using namespace--------------------------------------------------------------------------------------------------------------
using namespace std;

//define,const-----------------------------------------------------------------------------------------------------------------
#define rep(i, n) for(int i = 0; i < n; i++)
const int INF = 1 << 25;
#define MAX 1000

//global-----------------------------------------------------------------------------------------------------------------------
int start_x, start_y, n;
vector<int> wator_x(100);
vector<int> wator_y(100);
int jump_x[12] = { -2, -2, -2, -1, 0, 1, 2, 2, 2, -1, 0, 1};
int jump_y[12] = { -1, 0, 1, -2, -2, -2, -1, 0, 1, 2, 2, 2};
int ok_zone_x[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
int ok_zone_y[9] = { 1, 1, 1, 0, 0, 0, -1, -1, -1 };
//function---------------------------------------------------------------------------------------------------------------------
bool solve(int x, int y, int i){
	if (x < 0 || y < 0 || x > 9 || y > 9)
		return false;
	if (i == n)
		return true;
	for (int j = 0; j < 12; j++){
		for (int k = 0; k < 9; k++){
			if (x + jump_x[j] == wator_x[i] + ok_zone_x[k] && y + jump_y[j] == wator_y[i] + ok_zone_y[k])
				if (solve(x + jump_x[j], y + jump_y[j], i + 1))
					return true;
		}
	}
	return false;
}

int main(){
	while (scanf("%d %d", &start_x, &start_y)){
		if (start_x == 0 && start_y == 0)
			return 0;
		scanf("%d", &n);
		rep(i, n)
			scanf("%d %d", &wator_x[i], &wator_y[i]);
		if (solve(start_x, start_y, 0))
			printf("OK\n");
		else
			printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1016
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <bitset>
using namespace std;
int main() {
	int n, k;
	int a[100010];
	int ans = 0;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	ans += (n - 1) / (k - 1);
	if ((n - 1) % (k - 1) != 0) {
		ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>

long long cost[50][50];
long long minutes[50][50];
long long ans[50][50 * 100 + 2];
long long exchange[50];
long long minutes_exchange[50];

int main() {
    int n, m; long long s; std::cin >> n >> m >> s;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cost[i][j] = -1;
    for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) minutes[i][j] = -1;
    long long sum = 0;
    for (int i = 0; i < m; i++) {
        long long a, b, c, d; std::cin >> a >> b >> c >> d;
        a--; b--;
        cost[a][b] = cost[b][a] = c;
        minutes[a][b] = minutes[b][a] = d;
        sum += c;
    }
    if (sum <= s) s = sum;

    constexpr long long INIT = 1e18;
    for (int i = 0; i < n; i++) {
        std::cin >> exchange[i] >> minutes_exchange[i];
    }
    using Node = std::pair<long long, std::pair<long long, long long>>;
    std::priority_queue<Node, std::vector<Node>, std::greater<Node>> que;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < sum + 2; j++) {
            ans[i][j] = INIT;
        }
    }
    que.push({ 0, { 0, s } });
    while (!que.empty()) {
        auto node = move(que.top());
        que.pop();
        long long dist = node.first;
        long long pos = node.second.first;
        long long coin = node.second.second;
        if (ans[pos][coin] != INIT) continue;
        ans[pos][coin] = dist;

        for (int i = 0; i < n; i++) {
            if (cost[pos][i] == -1) continue;
            long long nxtcoin = coin - cost[pos][i];
            if (nxtcoin < 0) continue;
            if (ans[i][nxtcoin] != INIT) continue;
            que.push({ dist + minutes[pos][i], { i, nxtcoin } });
        }

        if (coin < sum) {
            long long nxtcoin = std::min(sum, coin + exchange[pos]);
            long long nxtdist = dist + minutes_exchange[pos];
            if (ans[pos][nxtcoin] != INIT) continue;
            que.push({ nxtdist, {pos, nxtcoin} });
        }
     }
    for (int i = 1; i < n; i++) {
        std::cout << *std::min_element(ans[i], ans[i] + sum + 1) << std::endl;
    }
    return 0;
}


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

constexpr long long INF = 1LL << 61;

// cost:=全頂点対の最短経路長がここに書き込まれる
// 負閉路が存在する場合はfalse, それ以外の場合はtrueを返す
bool warshall_floyd(vector< vector<long long> >& cost){
    const int v = (int)cost.size();
 
    for(int k = 0 ; k < v ; ++k){
        for(int i = 0 ; i < v ; ++i){
            for(int j = 0 ; j < v ; ++j){
                if(cost[i][k] < INF && cost[k][j] < INF){
                    cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
                }
            }
        }
    }

    for(int i = 0 ; i < v ; ++i){
        if(cost[i][i] < 0LL){
            return false;
        }
    }

    return true;
}

int main(){
    int v, e;
    cin >> v >> e;

    vector< vector<long long> > cost(v, vector<long long>(v, INF));
    for(int i = 0 ; i < v ; ++i){
        cost[i][i] = 0;
    }

    for(int i = 0 ; i < e ; ++i){
        int s, t;
        long long d;
        cin >> s >> t >> d;
        cost[s][t] = min(cost[s][t], d);
    }

    if(warshall_floyd(cost)){
        for(int i = 0 ; i < v ; ++i){
            for(int j = 0 ; j < v ; ++j){
                if(j) cout << ' ';
                if(cost[i][j] < INF){
                    cout << cost[i][j];
                }else{
                    cout << "INF";
                }
            }
            cout << endl;
        }
    }else{
        cout << "NEGATIVE CYCLE" << endl;
    }

    return 0;
}


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

int main(void)
{
	int N, T;
	cin >> N >> T;

	long long total = 0;
	long long from = 0;
	long long to = 0;
	for (int i = 1; i <= N; i++) {
		int t;
		cin >> t;
		if (t > to) {
			total += (to - from);
			from = t;
		}
		to = t+T;
	}
	total += (to - from);

	cout << total << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int 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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){
    int a,b;
    cin >> a >> b;
    int x = a/b;
    int y = a % b;
    double z = (double)a / b;
    cout << x << " " << y << " " << fixed <<setprecision(8) << z <<endl;
}
/* //別解
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;

int main() {
	int a, b; cin >> a >> b;
	cout << a / b << ' ' << a%b << ' ';
	printf("%.7lf\n", (double)a / b);
} */



Measured memory_bytes: 3288
/*
*
*	AUTHOR :- @soham01
*		// "WORK HARD AND NEVER GIVE UP" //
*
*/
#include "bits/stdc++.h"

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //find_by_order(), order_of_key()
#define pb push_back
#define mp make_pair
#define vi vector<long long int >
#define vb vector<bool>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<long long int> >
#define vp vector<pair<long long int , long long int > >
#define seti set<long long int >
#define setc set<char>
#define setd set<double>
#define mod 1000000009
#define endl '\n'
typedef long long int lli;

// ITS MY REQUEST TO PLEASE PLEASE DO LOOK AT THE CONSTRAINS GIVEN CAREFULLY
// DO CHECK FOR CORNER CASES

/*-------LET THE GAME BEGIN-----------*/

void solve()
{
	lli n, i, j, c = 0, mn = 0;
	cin >> n;
	vi v(n);
	for (i = 0; i < n; i++)
	{
		cin >> v[i];
	}
	mn = v[0];
	for (i = 0; i < n; i++)
	{
		if (v[i] <= mn)
		{
			c += mn - v[i];
		}
		else if (v[i] > mn)
		{
			mn = v[i];
		}
	}
	cout << c << endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	solve();
	return 0;
}


Measured memory_bytes: 4780
import sys
n=int(input())
a=list(map(int,input().split()))
A=[]
for i in range(len(a)):
    if a[i]%2==0:
        A.append(a[i])
B=[]
for i in range(len(A)):
    if A[i]%3!=0:
        B.append(A[i])
C=[]
for i in range(len(B)):
    if B[i]%5!=0:
        C.append(B[i])
if len(C)>=1:
    print("DENIED")
else:
    print("APPROVED")

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 50001
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;
    vector<bool>Primecheck(MAX+1,true);
    vector<int>Primenumber(MAX+1,0); //Primearray
    int Primecounter =0;//Primearray counter;
    Primecheck[1]=false;
    Primecheck[0]=false;
    for(int i = 2; i<MAX+1;i++){
        if(Primecheck[i]){
            for(int j = 2;i*j<MAX;j++)
                Primecheck[i*j] = false;//?´???°??????Primearray???????´??????????????????°?????¨???false???
            Primenumber[Primecounter] = i;
            Primecounter++;
        }
    }
    while(cin>>n,n){
        ll ans=0;
        rep(i,Primecounter){
            if(Primenumber[i]>n/2)break;
            if(Primecheck[n-Primenumber[i]])ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <unordered_map>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <memory>
#include <iomanip>
#include <type_traits>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//constexpr long long MOD = 1e9 + 7;
//constexpr long long MAX = 1000000;

//long long MOD = 998244353;
constexpr ll INF = 1e17;
constexpr double PI = 3.141592653589793;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

ll h, w;
vector<ll> dx = { -1, 0, 1, 0 };
vector<ll> dy = { 0, -1, 0, 1 };


bool isInField(ll x, ll y) {
    bool f = x >= 0 && x < w && y >= 0 && y < h;
    return f;
}

bool compare_first(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.first != y.first) {
        return x.first < y.first;
    }
    else {
        return x.second < y.second;
    }
}

bool compare_second(pair<ll, ll> x, pair<ll, ll> y)
{
    if (x.second != y.second) {
        return x.second < y.second;
    }
    else {
        return x.first < y.first;
    }
}

struct {
    bool operator()(pair<string, int> x, pair<string, int> y) const
    {
        return x.second <= y.second && x.first < y.first;
    }
} compare_map;

const ll MAX = 500000000;
const ll MOD = 1000000007;


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

    //int h, w, k, a, b, c;

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }

    int l = 0;
    int r = n;

    int border = sum / (4 * m);
    if (sum % 2 == 1) {
        border++;
    }

    int count = 0;
    for (auto e : a) {
        if (e >= border) {
            count++;
        }
    }

    if (count >= m) {
        cout << "Yes" << "\n";
    }
    else {
        cout << "No" << "\n";
    }
    //sort(a.begin(), a.end());

    //while (l < r) {
    //    int mid = (l + r) / 2;
    //    if (a[mid] <= target) {
    //        l = mid + 1;
    //    }
    //    else {
    //        r = mid;
    //    }
    //}

    //if (n - l >= m) {
    //    cout << "Yes" << "\n";
    //}
    //else {
    //    cout << "No" << "\n";
    //}

    return 0;
}



Measured memory_bytes: 256
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => {

  var num = input.split(' ');

  var a = parseInt(num[0]);
  var b = parseInt(num[1]);
  var c = parseInt(num[2]);

  var d = [a, b, c];
  var result = d.sort();
  console.log(result[0] + ' ' + result[1] + ' ' + result[2]);
})



Measured memory_bytes: 15296
/*!enjoy karo yaar!*/

//CF,CC,AtC,SPOJ: hp1999
//HE: hemant269
//HR: hemant2132

#include<bits/stdc++.h>
using namespace std;

#define     int             long long int
#define     fast()          ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     all(x)          begin(x),end(x)
#define     rz(x)           resize(x)
#define     asn(x,y)        assign(x,y)
#define     mem(a,b)        memset(a,b,sizeof(a))
#define     sz(x)           ((int)(x.size()))
#define     eb              emplace_back
#define     pb              push_back
#define     pf              push_front
#define     pob             pop_back
#define     pof             pop_front
#define     ins             insert
#define     vi              vector<int>
#define     pii             pair<int,int>
#define     mii             map<int,int>
#define     F               first
#define     S               second
#define     makep           make_pair
#define     maket           make_tuple
#define     remax(a,b)      a=max(a,b)
#define     remin(a,b)      a=min(a,b)
#define     bitcount(x)     __builtin_popcountll(x)
#define     iceil(n,x)      (((n)+(x)-1)/(x))
#define     gcd(a,b)        (__gcd((a),(b)))
#define     lcm(a,b)        (((a)*(b))/gcd((a),(b)))
#define     dbug(x)         cout<<#x<<": "<<(x)<<"\n"
#define     flush           fflush(stdout)
#define     show(x)         for(auto zz:x)cout<<zz<<" ";cout<<"\n";
#define     show2(x)        for(auto zz:x)cout<<zz.F<<" "<<zz.S<<"\n";

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

const ld pi=acos(-1);
const ll inf=1e18,M=1e9+7;
const int N=52;

vi adj[N];
pii mat[N][N];

void solve()
{
    int n,m,s;
    cin>>n>>m>>s;

    int tot=0;
    int u,v,a,b;
    for(int i=0;i<m;++i)
    {
        cin>>u>>v>>a>>b;
        mat[u][v]={a,b};
        mat[v][u]={a,b};

        adj[u].pb(v);
        adj[v].pb(u);

        tot+=a;
    }

    vector<pii> val(n+1);
    int c,d;
    for(int i=1;i<=n;++i)
    {
        cin>>c>>d;
        val[i]={c,d};
    }

    priority_queue<tuple<int,int,int>> pq;           // (-time, coins, node)
    vector<vi> tim(n+1,vi(tot+1,inf));

    tim[1][0]=0;
    pq.push(maket(0,min(s,tot+1),1));

    int cur,coins,x;
    int req;
    while(!pq.empty())
    {
        tie(cur,coins,x)=pq.top();
        pq.pop();

        cur*=-1;

        for(auto c:adj[x])
        {
            req=mat[x][c].F;

            if(req>coins)
                continue;

            if(coins-req<=tot && tim[c][coins-req]>cur+mat[x][c].S)
            {
                tim[c][coins-req]=cur+mat[x][c].S;
                pq.push(maket(-tim[c][coins-req],coins-req,c));
            }
        }

        if(coins+val[x].F<=tot && tim[x][coins+val[x].F]>cur+val[x].S)
        {
            tim[x][coins+val[x].F]=cur+val[x].S;
            pq.push(maket(-tim[x][coins+val[x].F],coins+val[x].F,x));
        }
    }

    for(int i=2;i<=n;++i)
        cout<<*min_element(all(tim[i]))<<"\n";
}

int32_t main()
{
    fast();

    int t=1;
    //cin>>t;
    for(int z=1;z<=t;++z)
    {
        solve();
        //cout<<"\n";
    }

    return 0;
}



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

int main() {
	string s,ans;
	cin>>s;
	for(int i=0;i<s.size();++i){
		if(s.at(i)=='B'){
			if(ans.size())ans.pop_back();
		}
		else ans+=s.at(i);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;
    cin >> S;
    int mx = 0;
    int sum = 0;
    set<char>  acgt {'A','C','G','T'};
    for (int i=0;i<S.size();i++){
        if (acgt.count(S[i])){
            sum++;
            mx = max(mx,sum);
        }else{
            sum = 0;
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0;i<int(n);++i)
using namespace std;
template<class A>void pr(A a){cout << a << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;p(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;p(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;p(b,c,d);}
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
int INF=numeric_limits<int>::max();
// for(int j=0;j<N;++j) {}

int main(void) {
  int n;cin>>n;
  double res=0.0;
  REP(i,n) {
    double a;
    cin>>a;
    res+=1/a;
  }
  printf("%.10f",1/res);
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.stream.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        List<Cake> list = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            list.add(new Cake(in.nextLong(), in.nextLong(), in.nextLong()));
        }

        Calculate[] calcs = {
            c ->   c.getX() + c.getY() + c.getZ(),
            c ->   c.getX() + c.getY() - c.getZ(),
            c ->   c.getX() - c.getY() + c.getZ(),
            c ->   c.getX() - c.getY() - c.getZ(),
            c -> - c.getX() + c.getY() + c.getZ(),
            c -> - c.getX() + c.getY() - c.getZ(),
            c -> - c.getX() - c.getY() + c.getZ(),
            c -> - c.getX() - c.getY() - c.getZ()
        };
        long ans = 0;
        for(Calculate calc : calcs) {
            list.sort((c1, c2) -> calc.calc(c1) > calc.calc(c2) ? 1 : -1);
            long x = 0, y = 0, z = 0;
            for(Cake c : list.subList(0, m)) {
                x += c.getX(); y += c.getY(); z += c.getZ();
            }
            ans = Math.max(ans, Math.abs(x) + Math.abs(y) + Math.abs(z));
        }
        System.out.println(ans);
    }
}

class Cake {
    long x, y, z;
    public Cake(long x, long y, long z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
    public long getX() { return x; }
    public long getY() { return y; }
    public long getZ() { return z; }
    public long getSum() { return x + y + z; }
}

@FunctionalInterface
interface Calculate {
    public long calc(Cake cake);
}

Measured memory_bytes: 31228
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC";
  } else if (r < 2800) {
    cout << "ARC";
  } else {
    cout << "AGC";
  }

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	int sum = 0;
	int n,a,b;
	cin >> n >> a >> b;
	for(int i = 1;i<=n;i++){
		bool ans = false;
		int c = i,pos = 0;
		while(c>0){
			pos+=c%10;
			c/=10;
		}
		if(pos<=b&&pos>=a) ans = true;
		if(ans) sum += i;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
  if((double)a.first/(double)a.second!=(double)b.first/(double)b.second){
    return (double)a.first/(double)a.second < (double)b.first/(double)b.second;
  }else{
    if(a.first!=b.first){
      return a.first>b.first;
    }
    else return a.second > b.second;
  }
}
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0;
  string s,t,u;
  std::cin >> s>>t;
  std::cin >> x>>y;
  std::cin >> u;
  if(u==s)x--;
  if(u==t)y--;
  std::cout << x<<" "<<y << '\n';
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 998244353
int r,g,b,rg,rb,bg,no;
signed main()
{
	int n;
	scanf("%d",&n);
	int ans=1;
	for(int i=1;i<=3*n;i++)
	{
		char c;
		cin>>c;
		if(c=='R')
		{
			if(bg)
			{
				ans=1ll*ans*bg%mod;
				bg--;
			}
			else if(b)
			{
				ans=1ll*ans*b%mod;
				b--;
				rb++;
			}
			else if(g)
			{
				ans=1ll*ans*g%mod;
				g--;
				rg++;
			}
			else
				r++;
		}
		else if(c=='B')
		{
			if(rg)
			{
				ans=1ll*ans*rg%mod;
				rg--;
			}
			else if(r)
			{
				ans=1ll*ans*r%mod;
				r--;
				rb++;
			}
			else if(g)
			{
				ans=1ll*ans*g%mod;
				g--;
				bg++;
			}
			else
				b++;
		}
		else
		{
			if(rb)
			{
				ans=1ll*ans*rb%mod;
				rb--;
			}
			else if(r)
			{
				ans=1ll*ans*r%mod;
				r--;
				rg++;
			}
			else if(b)
			{
				ans=1ll*ans*b%mod;
				b--;
				bg++;
			}
			else
				g++;			
		}
	}
	for(int i=1;i<=n;i++)
		ans=1ll*i*ans%mod;
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
# A - ABC Swap
X,Y,Z = list(map(int, input().split()))
A=X
B=Y
C=Z

#箱Aと箱Bの中身を入れ替える
T=A
A=B
B=T

#箱Aと箱 Cの中身を入れ替える
T=A
A=C
C=T

print(A,B,C)

Measured memory_bytes: 3060
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>

const int INF = 1e9;

// code
// ------------------------------------------------
int main() {

  char a,b;
  cin >> a >> b;

  if( a == b)
    cout << 'H';
  else
  {
    cout << 'D';
  }
  

  // if(a == 'H')
  // {
  //   if(b == 'H')
  //   {
  //     cout << 'H';
  //   }
  //   else
  //   {
  //     cout << 'D';
  //   }
  // }
  // else
  // {
  //   if(b == 'D')
  //     cout << 'H';
  //   else
  //   {
  //     cout << 'D';
  //   }
    
  // }


  return 0;
}

// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=1e5+10;
int n,m,H[M];
vector<int>g[M];
bool cv[M],mark[M];
int dfs(int v,int par,int h)
{
  int up=h,cnt=0;
  mark[v]=true;
  H[v]=h;
  if(g[v].size()==1 && v!=1)return h;
  for(auto u:g[v])
    if(!mark[u])
      {
	cnt++;
	int d=dfs(u,v,h+1);
	up=min(up,d);
	if(d>=h)cv[v]=true;
      }
    else if(u!=par)
      up=min(up,H[u]);
  if(v==1)
    if(cnt>1)cv[v]=true;
    else cv[v]=false;
  return up;
}
int main()
{
  cin>>n>>m;
  for(int i=0;i<m;i++)
    {
      int u,v;
      cin>>u>>v;u++;v++;
      g[u].push_back(v);
      g[v].push_back(u);
    }
  dfs(1,1,0);
  for(int i=1;i<=n;i++)
    if(cv[i])cout<<i-1<<endl;
  return 0;
}

Measured memory_bytes: 6956
#include <iostream>
using namespace std;
int main(){
        int N;
        cin>>N;
        int K,P;
        for(int i=0;i<N;i++){
                cin>>K>>P;
                if(K>=P){
                        if(K%P==0){
                                cout<<P<<endl;
                        }
                        else{
                                cout<<K%P<<endl;
                }
                }
                else{
                        cout<<K%P<<endl;
                }
        }
        return 0;
}

Measured memory_bytes: 1160
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($s) = explode(" ", trim(fgets(STDIN)));
  $w = [];
  $w[0] = 0;
  $wc = 0;
  for ($i=0; $i<$n; $i++) {
    if($s[$i] == 'W'){
      $wc++;
    }
    $w[$wc]=$i;
  }

  if(count($w) == 1){
    echo "0";
    exit;
  }

  if($wc == $n){
    echo "0";
    exit;
  }

  //var_dump($w);

  $r = [];
  $rc = 0;
  for ($i=$n-1; $i>=0; $i--) {
    if($s[$i] == 'R'){
      $rc++;
    }
    //echo $i." ".$rc.PHP_EOL;
    if(!isset($w[$rc])){
      continue;
    }
    if($w[$rc] >= $i){
      if($w[$rc-1] == $i){
        echo --$rc;
      }else{
        echo $rc;
      }
      exit;
    }
  }
  echo "0";

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

template<typename T>
vector<T> eratosthenes(T n) {
	vector<T> ret;
	vector<bool> v;
	v.reserve(n + 1);
	for (T i = 0; i < n + 1; ++i)v.push_back(true);
	ret.push_back(2);
	for (T i = 2; i <= n; i += 2) v[i] = false;
	for (T i = 3; i <= n; ++i) {
		if (v[i]) {
			ret.push_back(i);
			for (T j = i; j <= n; j += i) v[j] = false;
		}
	}
	return ret;
}

template<typename T>
map<T, T> prime_fact(T n) {
	map<T, T> ret;
	for (T prime : eratosthenes<T>(sqrt(n))) {
		while (n % prime == 0) {
			n /= prime;
			++ret[prime];
		}
	}
	if (n != 1)++ret[n];
	return ret;
}

int main() {
	ll n;
	cin >> n;
	ll ans = 0;
	map<ll, ll> pf = prime_fact<ll>(n);
	for (auto p : pf) {
		ll a = p.second;
		for (ll i = 1;; ++i) {
			if (a < i)break;
			else {
				++ans;
				a -= i;
			}
		}
	}
	cout << ans << endl;
}


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

int main() {
    
    int N,M;
    cin >> N >> M;
    map<int,bool> red;
    map<int,int> cont;
    
    for(int i = 0; i < N;i++){
        red[i] = false;
        cont[i]++;
    }
    red[0]=true;
    int x,y;
    for(int i = 0; i < M;i++){
        cin >> x >> y;
        x--,y--;
        if(red[x]&&cont[x]-1!=0){
            cont[x]--;
            cont[y]++;
            red[y] = true;
        }else if(red[x]&&cont[x]-1==0){
            cont[x]--;
            cont[y]++;
            red[x] = false;
            red[y] = true;
        }else{
            cont[x]--;
            cont[y]++;            
        }
    }
    
    int ans = 0;
    for(int i = 0; i < N;i++){
        if(red[i])ans++;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v.at(i).first.first>>v.at(i).first.second;
        v.at(i).first.second=100-v.at(i).first.second;
        v.at(i).second=i;
    }
    sort(v.begin(),v.end());
    for(int i=0;i<n;i++)
    {
        cout<<v.at(i).second+1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int N;
int ans;
vector<int> h(N);
int main()
{
	cin >> N;
	h.resize(N, 0);
	REP(i, N) cin >> h[i];
	int prev = 0;
	REP(i, N) {
		if (prev < h[i]) {
			ans += (h[i] - prev);
		}
		prev = h[i];
	}
	cout << ans << 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;

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

int main() {
  int N;
  cin >> N;
  int sum = 0;
  rep(i,N) {
    rep(j,N) {
      rep(k,N) {
        sum += gcd(i+1, gcd(j+1,k+1));
      }
    }
  }
  cout << sum <<endl;
}

Measured memory_bytes: 3636
n = int(input())
sl = []
tl = []
cn = 0
tnp = 0

for i in range(n):
    s, t = map(str, input().split())
    t = int(t)
    sl.append(s)
    tl.append(t)

x = str(input())

for j in range(n):
    if sl[j] == x:
        cn = j

print(sum(tl) - sum(tl[:cn+1]))

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n, x;
    cin >> n >> x;
    vi a(n);
    rep(i, n) cin >> a[i];
    VSORT(a);
    int ans = 0;
    ll sum = 0;
    rep(i, n) {
        sum += a[i];
        if (sum <= x) ++ans;
    }
    if (sum < x) --ans;
    cout << ans << endl;
    return 0;
}


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

int T[105][10005];

int main(){
    int N, W;
    scanf("%d %d",&N,&W);
    int v[105],w[105];
    for(int i=1;i<=N;++i){
        scanf("%d %d",&v[i],&w[i]);
    }
    for(int i=0;i<=N;++i){
        T[i][0] = 0;
    }
    for(int j=0;j<=W;++j){
        T[0][j] = 0;
    }
    for(int i=1;i<=N;++i){
        for(int j=1;j<=W;++j){
            if(w[i]<=j){
                T[i][j] = max(T[i-1][j],T[i-1][j-w[i]]+v[i]);
            }
            else{
                T[i][j] = T[i-1][j];
            }
        }
    }
    printf("%d\n",T[N][W]);
}



Measured memory_bytes: 7168
while (line = gets)
  n = line.chop.to_i
  if (n == 0)
    break
  end

  max = nil
  subseq = Array.new

  n.times do
    a = gets.chop.to_i

    for i in (0...subseq.length)
      subseq[i] += a
    end
    subseq.push a

    cmax = subseq.max

    if (max.nil? || max < cmax)
      max = cmax
    end
  end

  puts max
end

Measured memory_bytes: 6112
ans = 0
N,M=map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]

List.sort()

for i in range(M-1):
  a = List[i][0]
  b = List[i+1][0]  
  if a == b:
    if List[i][1] != List[i+1][1]:
      ans = -1
ans3 = 0
ans2 = 0
ans1 = 0
cnt3 = 0
cnt2 = 0
      
for i in range(M):
  a = List[i][0]
  if a == 1:
    ans3 = List[i][1] * (10 ** (N-1))
    cnt3 = 1
  if a == 2:
    ans2 = List[i][1] * (10 ** (N-2))
    cnt2 = 1
    if N-2<0:
      ans = -1
  if a == 3:
    ans1 = List[i][1] * (10 ** (N-3))
    if N-3<0:
      ans = -1

if cnt3 == 0 and N >= 2:
  ans3 = 10 ** (N-1)
      
if ans == -1:
  print(-1)
else:
  a = int(ans1+ans2+ans3)
  if len(list(str(a))) == N:
    print(a)
  else:
    print(-1)

Measured memory_bytes: 38512
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
template<typename T>
void max_self(T &a,T b){
    a=max(a,b);
}
template<typename T>
void min_self(T &a,T b){
    a=min(a,b);
}
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=5e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    string s;
    cin>>s;
    ll sum=0;
    for(auto x:s){
        sum+=(x-'0');
    }
    cout<<(sum%9==0?"Yes":"No")<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

using namespace std;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a,b,c;
	cin>>a>>b>>c;
	if((a+b)>=c){
		cout<<"Yes";
	}
	else{
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(A: int, B: int):
    def count(n):
        ret = 1
        i = 2
        while i * i <= n:
            if n % i == 0:
                ret += 1
                while n % i == 0:
                    n //= i
            i += 1
        if n > 1:
            ret += 1
        return ret
    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a % b)
    g = gcd(A, B)
    #print(g)
    ret = count(g)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,a[111];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n;
	fo(i,0,n)cin>>a[i];
	int ans=10291;
	fo(i,1,n){
		int x=0,y=0;
		fo(j,0,n){
			if(j<i)x+=a[j];
			else y+=a[j];
		}
		ans=min(ans,abs(x-y));
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
fn main() {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("error!");
    let mut iter = line.split_whitespace();

    let a: i32 = iter.next().expect("error!")
        .parse().expect("error!");

    let b: i32 = iter.next().expect("error!")
        .parse().expect("error!");

    if a < b && (b - a) & 1 == 0 {
        let d = (b - a) / 2;
        println!("{}", a + d);
    } else if (a - b) & 1 == 0 { // a > b
        let d = (a - b) / 2;
        println!("{}", a - d);
    } else {
        println!("IMPOSSIBLE");
    }
}


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

using namespace std;

const int MAX_V = 1e5+10;

vector<vector<int> > g(MAX_V);
vector<int> ap;
int n;
bool visited[MAX_V];
int ord[MAX_V], low[MAX_V], timer;

void dfs(int v, int p){
	ord[v] = low[v] = timer++;
	visited[v] = true;
	int children = 0;
	for (int i = 0; i < g[v].size(); ++i)
	{
		int to = g[v][i];
		if (to == p) continue;
		if (visited[to]) low[v] = min(low[v], ord[to]);
		else {
			dfs(to, v);
			low[v] = min(low[v], low[to]);
			if (ord[v] <= low[to] && p!=-1) ap.push_back(v);
			children++;
		}
	}
	if (p == -1 && children > 1) ap.push_back(v);
}

void find_ap(){
	for (int i = 0; i < n; ++i) visited[i] = false;

	timer = 0;
    dfs(0,-1);
    sort(ap.begin(), ap.end());
	ap.erase(unique(ap.begin(), ap.end()), ap.end());
}

int main(int argc, char const *argv[])
{
	int m;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		int s, t;
		cin >> s >> t;
		g[s].push_back(t);
		g[t].push_back(s);
	}
	find_ap();

	for (int i = 0; i < ap.size(); ++i) cout << ap[i] << endl;
	return 0;
}


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

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		string ans = "EQUAL";
		string A = Console.ReadLine();
		string B = Console.ReadLine();
		if (A.Length > B.Length)
		{
			ans = "GREATER";

		}
        else if (A.Length < B.Length)
		{
			ans = "LESS";
		}
		else
		{

            for(int i = 0; i < A.Length; i++)
			{
				int a = A[i] - '0';
				int b = B[i] - '0';
				if (a > b)
				{
					ans = "GREATER";
					break;
				}
                else if (a < b)
				{
					ans = "LESS";
					break;
				}
				
			}
		}

		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main(void){
	int i, j;
	while (cin >> i >> j){
		int tmp = i+j;
		stringstream ss;
		ss << tmp;
		string c = ss.str();
		cout << c.length() << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int[] n = new int[3];
        for (int i = 0; i < 3; i++) {
            n[i] = sc.nextInt();
        }
        Arrays.sort(n);
        System.out.println(n[2]-n[0]);
    }
}

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


void solve(long long x, long long a, long long b){
    if(abs(x-a)>abs(x-b)) cout << "B" << endl;
    else cout << "A" << endl;
}

int main(){
    long long x;
    scanf("%lld",&x);
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(x, a, b);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a < b & b < c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2688