akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iostream>
#include <deque>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    string S;
    cin >> S;
    int Q;
    cin >> Q;

    deque<char> deq;
    for (int i = 0; i < (int) S.size(); i++) {
        deq.push_back(S[i]);
    }

    int direction = 1;

    for (int i = 0; i < Q; i++) {
        int t;
        cin >> t;
        if (t == 1) {
            direction *= -1;
        } else {
            int f;
            char c;
            cin >> f >> c;
            if (direction == 1) {
                if (f == 1) {
                    // add top
                    deq.push_front(c);
                } else {
                    // add back
                    deq.push_back(c);
                }
            } else {
                if (f == 1) {
                    // add top
                    deq.push_back(c);
                } else {
                    // add back
                    deq.push_front(c);
                }
            }
        }
    }

    if (direction > 0) {
        for (int i = 0; i < (int) deq.size(); i++) {
            printf("%c", deq[i]);
        }
    } else {
        for (int i = deq.size() - 1; i >= 0; i--) {
            printf("%c", deq[i]);
        }
    }
    printf("\n");

    return 0;
}


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

using namespace std;

long long int solve(string n, long long int p, unsigned int q) {
	if (q == n.size())return p + n[q-1]-'0';
	int u = n[q - 1] - '0';
	long long int w = (p  + u)*10;
	int y = n.size() - q - 1;
	if (y == -1)y = 0;
	return solve(n, w, q + 1) + solve(n, 0, q + 1)+(p+u)*pow(2,y);
}
int main() {
	string s;
	cin >> s;
	
	cout << solve(s, 0, 1);
}

Measured memory_bytes: 256
import sys
n, m = map(int, input().split())

a = []
b = []

for i in range(n):
    a.append(input())
    
for i in range(m):
    b.append(input())

for i in range(n - m + 1):
    for j in range(n - m + 1):
        flg = False
        for k in range(m):
            if flg:
                break
            for l in range(m):
                if b[k][l] != a[i + k][j + l]:
                    flg = True
                    break
        
        if flg:
            pass
        else:
            print('Yes')
            sys.exit()

print('No')

Measured memory_bytes: 3064
#include<cstdio>
using namespace std;

int a[10010],map[110][110];
int dx[4]={0,-1,0,1};
int dy[4]={1,0,-1,0};
int X,Y,now,h,w;

void dfs(int x,int y,int cnt){
    if(cnt==0){
        X=x;Y=y;
        return;
    }
    map[x][y]=now;
    for(int i=0;i<4;i++){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>=1&&nx<=h&&ny>=1&&ny<=w)
            if(map[nx][ny]==0){
                dfs(nx,ny,cnt-1);
                break;
            }
    }
}

int main(void){
    int x,y;
    scanf("%d %d",&h,&w);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    X=1;Y=1;
    for(int i=1;i<=n;i++){
        x=X;y=Y;
        now=i;
        dfs(x,y,a[i]);
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++)
            printf("%d ",map[i][j]);
        printf("\n");
    }
    return 0;
}


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

int main(){
	int R, n, i, max_gain, min;
	cin >> n;
	cin >> R;
	min = R;
	cin >> R;
	max_gain = R-min;
	if(min > R)
		min = R;
	for(i=2;i<n;i++){
		cin >> R;
		if(max_gain < R-min)
			max_gain = R-min;
		if(min > R)
			min = R;
	}
	cout << max_gain << endl;
	return 0;
}

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] d = new int[n];
        for (int i=0; i<n; i++) {
            d[i] = sc.nextInt();
        }
        int sum_delicious = 0;
      	int check = 0;
        int cnt = 0;
        boolean TF = true;
        while(TF) {
            for(int i=cnt+1; i<n; i++) {
                sum_delicious += d[cnt]*d[i];
            }
            cnt++;
            if(cnt == n) TF = false;
        }
        System.out.println(sum_delicious);
    }
}

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

pub 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 gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        let ai = read();
        a.push(ai);
    }

    let mut max_gcd = a[0];

    for i in 0..a.len() {
        let ai = a[i];
        max_gcd = gcd(ai, max_gcd)
    }
    let mut ans = 0;

    while max_gcd % 2 == 0 {
        max_gcd /= 2;
        ans += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 500;
const int MAX_H = 10000000;
const int MAX_BITS = 1 << 24;
const int MAX_E2 = 1 << 25;

/* typedef */

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

struct BIT {
  int n;
  int bits[MAX_BITS];

  BIT() {}
  BIT(int _n) { init(_n); }
  
  void init(int _n) { n = _n; }

  int sum(int x) {
    int s = 0;
    while (x > 0) {
      s += bits[x];
      x -= (x & -x);
    }
    return s;
  }

  void add(int x, int v) {
    while (x <= n) {
      bits[x] += v;
      x += (x & -x);
    }
  }

  void print(int m) {
    for (int i = 1; i <= m; i++) cout << sum(i) << ' ';
    cout << endl;
  }
};

/* global variables */

int hs[MAX_N], nums[MAX_H + 1];
BIT bit;

/* main */

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

  int max_h = 0;
  for (int i = 0; i < n; i++) {
    cin >> hs[i];
    nums[hs[i]]++;
    if (max_h < hs[i]) max_h = hs[i];
  }

  bit.init(max_h);
  for (int i = 0; i < n; i++) bit.add(max_h + 1 - hs[i], 1);
  //bit.print(max_h);

  int h0 = 0, h1 = max_h + 1;

  while (h0 + 1 < h1) {
    int h = (h0 + h1) / 2;
    if (bit.sum(max_h + 1 - h) < 4 * h) h1 = h;
    else h0 = h;
  }
  //cout << h1 << endl;

  ll count = 1LL + 2LL * h1 * (h1 - 1);

  ll sumh = bit.sum(max_h + 1 - h1);
  for (int h = h1; h <= max_h; h++) {
    count += sumh;
    sumh -= nums[h];
  }

  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 62640
#include<bits/stdc++.h>
using namespace std;
struct edge {int u, v, w;};
vector<edge>G;
inline void add(int u, int v, int w) {
  G.push_back((edge) {u , v , w});
}
int main() {
  int L, t;
  cin >> L;
  for (int i = 0; i < 21; ++i) if (L & (1 << i)) t = i;
  for (int i = 1; i <= t - 1; i++) add(i, i+1, 1 << i-1), add(i, i+1, 0);
  add(t, 20, 0);
  add(t, 20, 1 << t-1);
  int g = 1 << t;
  while (g < L) {
    for(int i = 0; i < 21; ++i) if ((1 << i) & (L - g)) t = i; 
    add(t+1, 20 , g), g |= 1 << t;
  }
  cout << "20 " << G.size() << endl;
  for (auto it = G.begin(); it != G.end(); ++it) cout << it->u << ' ' << it->v << ' ' << it->w << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	if(a+b==15)
		printf("+");
	else if(a*b==15)
		printf("*");
	else
		printf("x");
	return 0;	
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<string>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define mp(x,y) make_pair(x,y)
#define r(x) read(x)
#define rrr(x,y,z) read(x);read(y);read(z)
#define FOR(i,l,r) for(int i=l;i<=r;i++)
using namespace std;
typedef long long LL;
typedef pair<int,int> pt;
const int N=1e6+5;
const int M=2e3+5;
const int INF=0x7fffffff;
const int mod=1e9+7;
const int bb=18;
const double eps=1e-10;
const double pi=acos(-1);
int n,m;
char str[N];
int f[N];
template<class T>
inline void read(T &x)
{
    char c; x=1;
    while((c=getchar())<'0'||c>'9') if(c=='-') x=-1;
    T res=c-'0';
    while((c=getchar())>='0'&&c<='9') res=res*10+c-'0';
    x*=res;
}
int main()
{
    int a,b,c;
    rrr(a,b,c);
    if((a==b&&b!=c)||(a==c&&b!=c)||(b==c&&a!=b)){
            cout<<"Yes\n";
    }
    else cout<<"No\n";
    return 0;
}


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

//for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

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

//constant
const int INF = 1<<30;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet**************************************
ifelse, isprime, torad, todeg, lcm, bfs
************************************************/

//adjacency list
vector<int> to[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n; cin >> n;
    vector<ll> h(100006);
    rep(i,0,n) cin >> h[i];
    vector<ll> cost(1000006);
    rep(i,1,n){
        if(i==1) cost[i]=abs(h[i]-h[i-1]);
        else if(cost[i-1]+abs(h[i]-h[i-1])>cost[i-2]+abs(h[i]-h[i-2])){
            cost[i]=cost[i-2]+abs(h[i]-h[i-2]);
        }else{
            cost[i]=cost[i-1]+abs(h[i]-h[i-1]);
        }
        //cout << cost[i] << ": " << i ENDL;
    }

    cout << cost[n-1] ENDL;



    
    return 0;
}

Measured memory_bytes: 14292
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
   int k=0,i,n;
   char s[101];
   cin.getline(s,101); ///citirea unui sir de caractere
   n=strlen(s); ///retin lungimea sirului de caractere
   for(i=0;i<=n/2-1;i++){
     ///  cout<<s[i]<<" "<<s[n-i-1]<<endl;
       if(s[i]!=s[n-i-1]){
           
           k++;
       }
   }  
   cout<<k;
   
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
 
using namespace std;
using namespace boost;

int64_t exec(const vector<vector<int>>& children, const vector<int64_t>& x, int root) {
  if (children[root].empty()) {
    return 0L;
  }

  constexpr auto kMax = 1000 * 5000;
  unordered_set<int64_t> nums;
  nums.insert(0);
  int64_t total = 0;
  for (auto c : children[root]) {
    auto p = exec(children, x, c);
    if (p < 0) {
      return p;
    }
    unordered_set<int64_t> next;
    for (auto n : nums) {
      next.insert(n + x[c]);
      next.insert(n + p);
    }
    nums.swap(next);
    total += x[c] + p;
  }
  
  for (int64_t i = x[root]; i >= 0; --i) {
    if (nums.count(i) > 0) {
      return total - i;
    }
  }
  
  return -1;
}

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

  vector<vector<int>> children(n);
  for (auto i : irange(1, n)) {
    int parent;
    cin >> parent;
    children[parent - 1].push_back(i);
  }
  
  vector<int64_t> x(n);
  for (auto&& xx : x) {
    cin >> xx;
  }
  
  if (exec(children, x, 0) >= 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 4704
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int lli;

int main(){
	lli n,a,b;
	cin >> n >> a >> b;
	lli ans = 0;
	ans += n/(a+b) *a;
	n %= a+b;
	ans += min(n, a);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n int
	fmt.Scan(&n)

	d := make([]int, n)
	for i := 0; i <n; i++ {
		fmt.Scan(&d[i])
	}
	sort.Ints(d)
	fmt.Println(d[n/2]-d[n/2-1])

}


Measured memory_bytes: 6324
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
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; }

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(){
    int n, m; cin >> n >> m;
    vector<ll> A(n); rep(i, n) cin >> A[i], A[i]--;
    UnionFind uf(n);
    rep(i, m){
        int x, y; cin >> x >> y; x--, y--;
        uf.merge(x, y);
    }
    ll res = 0;
    rep(i, n){
        if(uf.issame(i, A[i]))res++;
    }
    cout << res << ln;
}


Measured memory_bytes: 4556
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll d, t, s;
    cin >> d >> t >> s;
    if (s*t >= d) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3648
import sys
sys.setrecursionlimit(1000000)
N, M = map(int, input().split())
X = [0] * M
Y = [0] * M
Z = [0] * M 
for i in range(M):
  X[i], Y[i], Z[i] = map(int, input().split())

reach = [[] for _ in range(N)]

for i in range(M) :
    reach[Y[i]-1].append(X[i])
    reach[X[i]-1].append(Y[i])

approach = [False for _ in range(N)]

def change(reach, s):       
    approach[s-1] = True
    for i in reach[s-1]:
        if not approach[i-1] :
            change(reach, i)

ans = 0
for i in range(N) :
    if not approach[i]:
        change(reach, i+1)
        ans += 1

print(ans)

Measured memory_bytes: 112688
#include <bits/stdc++.h>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define BIT(t) (1ll << t)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll, ll>
#define SIZE(v) ll(v.size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
//        ios::sync_with_stdio(false);
//        cin.tie(nullptr);

int main(){
        string s;
        cin >> s;
        if(s.size() % 2 == 1){
                cout << "No" << endl;
                return 0;
        }
        for(int i=0;i<s.size();i+=2){
                if(s[i] != 'h' || s[i+1] != 'i'){
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;
}

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

using namespace std;

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

	int N;
	cin >> N;

	vector<int> arr(N + 1, 0);

	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= N; j += i)
			arr[j]++;
	}

	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += (i * (long long)arr[i]);
	}

	cout << ans;
}


Measured memory_bytes: 42236
a, b, k = gets.chomp.split(' ').map(&:to_i)


k.times do |i|
  if i % 2 == 0
    a -= 1 if a.odd?
    a /= 2
    b += a
  else
    b -= 1 if b.odd?
    b /= 2
    a += b
  end
end
puts "#{a} #{b}"


Measured memory_bytes: 1788
N, A, B = map(int, input().split())
S = input()
count = 0
count_foreign = 0
for s in S:
    if s == 'c':
        print('No')
    elif s == 'a':
        if count < A + B:
            print('Yes')
            count += 1
        else:
            print('No')
    else:
        if count < A + B and count_foreign < B:
            print('Yes')
            count_foreign += 1
            count += 1
        else:
            print('No')
    



Measured memory_bytes: 4016
# include "bits/stdc++.h"
using namespace std;
using LL = long long;
using ULL = unsigned long long;
const double PI = acos(-1);
template<class T>constexpr T INF() { return ::std::numeric_limits<T>::max(); }
template<class T>constexpr T HINF() { return INF<T>() / 2; }
template <typename T_char>T_char TL(T_char cX) { return tolower(cX); };
template <typename T_char>T_char TU(T_char cX) { return toupper(cX); };
const int vy[] = { -1, -1, -1, 0, 1, 1, 1, 0 }, vx[] = { -1, 0, 1, 1, 1, 0, -1, -1 };
const int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++)if ((n >> i) & 1)cnt++; return cnt; }
int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; }return ret; }
int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; }return ret; }
LL gcd(LL a, LL b) { if (b == 0)return a; return gcd(b, a%b); };
LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g*b; };
# define ALL(qpqpq)           (qpqpq).begin(),(qpqpq).end()
# define UNIQUE(wpwpw)        sort(ALL((wpwpw)));(wpwpw).erase(unique(ALL((wpwpw))),(wpwpw).end())
# define LOWER(epepe)         transform(ALL((epepe)),(epepe).begin(),TL<char>)
# define UPPER(rprpr)         transform(ALL((rprpr)),(rprpr).begin(),TU<char>)
# define FOR(i,tptpt,ypypy)   for(LL i=(tptpt);i<(ypypy);i++)
# define REP(i,upupu)         FOR(i,0,upupu)

struct INIT{
    INIT(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(0);
        cout << fixed << setprecision(13);
    }
}INIT;

int n, k;
LL a[202020], rui[202020];
map<LL, int> mp;
int main(){
    cin >> n >> k;
    REP(i, n)cin >> a[i];
    REP(i, n)rui[i + 1] = (rui[i] + a[i] - 1 + k) % k;
    LL ans = 0;
    REP(i, n + 1){
        ans += mp[rui[i]];
        mp[rui[i]]++;
        int t = i - k + 1;
        if(t >= 0)mp[rui[t]]--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main{
    
	// returns array of distances from first vertex to each other vertex
	static int[] bfs(int[][] v, int totalVertex) {
		
		// implement queue with linked list
    	Queue<Integer> Q = new LinkedList<Integer>();
    	int[] dist = new int[totalVertex];
    	
    	// starting from index 1
    	Q.add(1);
    	dist[1] = 0;
    	
    	while(!Q.isEmpty()) {
    		int cur = Q.remove();
    		for(int i = 2; i < totalVertex; i++) {
    			// if a distance has not been set yet and current vertex and ith vertex connect
    			if(dist[i] == 0 && v[cur][i] == 1) {
    				dist[i] = dist[cur] + 1;
    				// only add into queue if a new node distance is updated
    				Q.add(i);
    			}
    		}
    	}
    	return dist;
    }
	
	public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int totalVertex=in.nextInt() + 1; // arrays will have +1 offset
        
        // stores graph as 2D array
        // I know we've been using adjList but I can manipulate and visualize this so much better :/
        int[][] v=new int [totalVertex][totalVertex];
        
        for(int i = 1; i < totalVertex; i++) {
        	int vertex = in.nextInt();
        	int neighbors = in.nextInt();
        	// if vertex connects to neighbor, sets [vertex][neighbor] to 1, else will be 0
        	for(int j = 0; j < neighbors; j++) {
        		int connect = in.nextInt();
        		v[vertex][connect] = 1;
        	}
        }
        in.close();
        
        // easy enough fix to allow bfs to start from any index if necessary
        
        // create distance array
        int bfsdist[] = bfs(v, totalVertex);
        
        for(int i = 1; i < totalVertex; i++) {
        	// if no path from start to vertex
        	if(i != 1 && bfsdist[i] == 0) {
        		System.out.println(i + " -1");
        	}
        	else System.out.println(i + " " + bfsdist[i]);
        }      
	}
}


Measured memory_bytes: 28776
import java.util.*;

public class Main{
	public static void main(String[] args){

    Scanner scanner = new Scanner(System.in);

    int a = scanner.nextInt();
    int b = scanner.nextInt();

    String result = String.valueOf(a) + String.valueOf(b);
    int resultInt = Integer.parseInt(result);
    double resultSqrt = Math.sqrt(resultInt) ;

    if(resultSqrt==Math.floor(resultSqrt)) {System.out.println("Yes");}
    else{System.out.println("No");}



    }
}

Measured memory_bytes: 21716
#include <cstdio>
using namespace std;

#define sqr(x) ((x) * (x))

int main() {
	double x1, x2, y1, y2, xq, yq;

	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf", &x1, &y1, &x2, &y2, &xq, &yq) != EOF) {
		double x, y;
		double tmp_x, tmp_y;

		tmp_x = x1 - x2;
		tmp_y = y1 - y2;

		x = (2 * tmp_x * tmp_y * (yq - y1) - sqr(tmp_y) * (xq - 2 * x1) + sqr(tmp_x) * xq)
			/ (sqr(tmp_x) + sqr(tmp_y));
		y = (2 * tmp_x * tmp_y * (xq - x1) - sqr(tmp_x) * (yq - 2 * y1) + sqr(tmp_y) * yq)
			/ (sqr(tmp_x) + sqr(tmp_y));

		printf("%f %f\n", x, y);
	}

	return 0;
}

Measured memory_bytes: 1080
#1000 8
#1 3 4 5 6 7 8 9
n,k = map(int, raw_input().split())
s = set(map(int, raw_input().split()))
letters = [u for u in range(10) if u not in s]
def dfs(u,n,letters):
	if u >= n:
		return u
	return min([dfs(u*10 +l,n,letters) for l in letters if u or l])

print dfs(0,n,letters)

Measured memory_bytes: 85040
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<unordered_map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;

ll N;
P task[100010];
int main(){
    cin>>N;
    for(ll i=0;i<N;i++){
      ll x,l;
      cin>>x>>l;
      task[i]=P(x+l,max(0ll,x-l));
    }
    sort(task,task+N);
    ll now=0;
    ll ans=0;
    for(ll i=0;i<N;i++){
      if(now<=task[i].second){
        ans++;
        now=task[i].first;
        //cout<<now<<endl;
      }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using pint=pair<int,int>;
int N;
vector<vector<pint>> v;
bool judge(int bit){
    for(int i=0;i<N;++i){
        if(!(bit&(1<<i))) continue;
        for(pint xy:v[i]){
            int x=xy.first;
            int y=xy.second;
            if(y==1&&!(bit&(1<<x))) return false;
            if(y==0&&(bit&(1<<x))) return false;
        }
    }
    return true;
}
int main(void){
    cin >> N;
    v.resize(N);
    for(int i=0;i<N;i++){
        int A; cin >> A;
        v[i].resize(A);
        for(int j=0;j<A;j++){
            cin >> v[i][j].first >> v[i][j].second;
            v[i][j].first--;
        }
    }
    int res=0;
    for(int bit=0;bit<(1<<N);bit++){
        if(judge(bit)){
            int count=0;
            for(int i=0;i<N;i++){
                if(bit&(1<<i)) count++;
            }
            res=max(res,count);
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3600
# include <iostream>
# include <stdint.h>
# include <stdio.h>
# include <math.h>
#include <cstdlib>
# include <algorithm>
# include <string>
using namespace std;
int main(){
    long long x,y,a,max,min,b;
    cin >>x>>y;
    if(x >y){  max =x; min =y;  }
    else {max =y; min =x;}
    a =max%min;
    b =min;
    if(a !=0){
        while(1){
            if(min%a ==0)  break;
            else{
                b =a; a= min%a; min =b;
            }
        }
    }
    else a=min;
    cout <<a<<"\n";

	return 0;
}



Measured memory_bytes: 3092
$n=<>;$h[$|--]{$_}--for glob<>;($u,$x,$v,$y)=map$h[$i++/2]{$_},@a=map{(sort{$$_{$a}-$$_{$b}}keys%$_)[0,1]}@h;print$n+$u+("@a"-$a[2]?$v:$y-($-=$u+$y-$v-$x))

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  vsort(a);
  
  ll ans=0;
  rep(i,n){
    for(ll j=i+1; j<n; j++){
      ll idx=(lower_bound(all(a), a[i]+a[j])-a.begin())-1;
      ans+=idx-j;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include<iostream>
int main(void){
	int a, b;
	std::cin >> a >> b ;
	if (a<b){
		std::cout <<"a < b"<< std::endl;
	}
	else if (a > b){
		std::cout <<"a > b"<< std::endl;
	}
	else if(a == b){
		std::cout <<"a == b"<< std::endl;
	}

	
	return 0;
}

Measured memory_bytes: 1156
#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 whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    double t, x;
    cin >> t >> x;
    double ans = t/x;
    
    printf("%.10f", ans);
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <climits>
#include <memory>
#include <sstream>
#include <iomanip>

using namespace std;


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int a, b;

	cin >> a >> b;

	int ans;
	if (b % a == 0)ans = a + b;
	else ans = b - a;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

 

using namespace std;

 

 

 

int main()
{
    int i, ans, a, b, c;
    
    cin >> a >> b >> c;
    ans = 0;
    while(a<=b)
    {
        if(c%a==0)
        {
            ans++;
        }
        a++;
    }
    cout << ans << endl;
}


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

N, K = map(int, input().split())
MX = 2*K
A = [[0]*MX for _ in range(MX)]
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == "W":
        y += K
    A[y%MX][x%MX] += 1
S = [[0]*(MX+1) for _ in range(MX+1)]
for y in range(MX):
    for x in range(MX):
        S[y+1][x+1] = S[y+1][x] + S[y][x+1] - S[y][x] + A[y][x]
ans = 0
for y in range(K, MX+1):
    for x in range(K, MX+1):
        s = S[y][x] - S[y-K][x] - S[y][x-K] + S[y-K][x-K]
        s += S[y-K][x-K]
        s += S[MX][x-K] - S[y][x-K]
        s += S[y-K][MX] - S[y-K][x]
        s += S[MX][MX] - S[y][MX] - S[MX][x] + S[y][x]
        ans = max(ans, s, N-s)
print(ans)


Measured memory_bytes: 136588
#include<stdio.h>
#define MAX 1000000

typedef struct{

  int x,y,z;

}Tree;


Tree a[MAX];

int Depth(int);

int main(){

  int i,j,n,num,d,c,k=0;


  scanf("%d",&n);

  for(i = 0; i < n ;i++){

    a[i].x = -1;
    a[i].y = -1;
    a[i].z = -1;
  }


  for(i = 0; i < n ;i++){

    scanf("%d%d",&num,&d);

    for(j = 0; j < d; j++){

      scanf("%d",&c);

      if(j == 0)a[num].y = c;

      else a[k].z = c;

      k = c;
      a[c].x = num;

    }
  }


  for(i = 0; i < n; i++){

    printf("node %d: parent = %d, depth = %d,",i,a[i].x,Depth(i));

    if(Depth(i) == 0) printf(" root, [");

    else if(a[i].y == -1) printf(" leaf, [");

    else printf(" internal node, [");

    j = a[i].y;

    while(j != -1){

      printf("%d",j);

      j = a[j].z;

      if(j != -1){

	printf(", ");
      }
    }

    printf("]\n");
  }

  return 0;
}



int Depth(int num){

  int dep = 0;

  while(a[num].x != -1){

    num = a[num].x;
    dep++;
  }

  return dep;
}
      
	  
	



Measured memory_bytes: 2896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
	int m1, m2, d1, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (d2 == 1) { cout << 1 << endl; }
	else { cout << 0 << endl; }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(j, m) for (int j = 0; j < (int)(m); j++)
#define rep2(i, l, n) for (int i = l; i < (int)(n); i++)

bool guumojiretu(string A) {
    int flag = 0;
    rep(i,A.size()/2) {
        if (A[i] != A[i + A.size()/2]) {
            flag++;
        }
    }
    if (flag == 0) {
        return true;
    }
    else {
        return false;
    }
}

int main() {
    string S;
    cin >> S;
    while(true) {
        S.pop_back();
        S.pop_back();
        if (guumojiretu(S)) {
            cout << S.size() << endl;
            break;
        }
        
    }
}



Measured memory_bytes: 3628
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 8080
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD=1e9+7;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

int main(){
	double n,m,d;
	cin>>n>>m>>d;
	double ans=(m-1)/n * (n + max((double)0,n-2*d))/n;
	if(d==0) ans=(m-1)/n;
	printf("%.11f\n",ans);
}

Measured memory_bytes: 256
(declaim (optimize (speed 0) (safety 3) (debug 3)))
#+sbcl (declaim (sb-ext:unmuffle-conditions sb-ext:compiler-note))
;;(declaim (optimize (speed 3) (safety 0) (debug 0)))

(defvar *t-health* (read))
(defvar *t-attack* (read))
(defvar *a-health* (read))
(defvar *a-attack* (read))

(let ((n-t-die (ceiling *t-health* *a-attack*))
      ;; 青木君に何回攻撃されると高橋君は死ぬか 
      (n-a-die (ceiling *a-health* *t-attack*)))
  ;; 高橋君に何回攻撃されると青木君は死ぬか
  (format t "~:[No~;Yes~]" (<= n-a-die n-t-die)))
;; 高橋君が先制攻撃するので死ぬまでの回数が同じなら高橋君の勝ち 


Measured memory_bytes: 23720
H,W,M = gets.split.map &:to_i
HW = M.times.map{ gets.split.map{_1.to_i - 1}}

count_h = [0]*H
count_w = [0]*W
targets = Array.new(H){[]}
HW.each do |h,w|
    count_h[h] += 1
    count_w[w] += 1
    targets[h] << w
end

h_max = count_h.max
max_idxs_h = count_h.map.with_index{|c,i| c==h_max ? i : nil}.compact
w_max = count_w.max
max_idxs_w = count_w.map.with_index{|c,i| c==w_max ? i : nil}.compact

no_cross = max_idxs_h.any? do |h|
    max_idxs_w.difference(targets[h]).any?
end

ans = h_max + w_max
ans -= (no_cross) ? 0 : 1

p ans

Measured memory_bytes: 69996
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	tyoku := make([]int, N-1)
	buka := make([]int, N)
	for i := 0; i < N-1; i++ {
		fmt.Scan(&tyoku[i])
		buka[tyoku[i]-1]++
	}
	for i := 0; i < N; i++ {
		fmt.Println(buka[i])
	}

}


Measured memory_bytes: 8552
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		sc.useDelimiter("\\D+");
		int ans=0;
		while(sc.hasNext()){
			ans+=sc.nextInt();
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 17260
import bisect

N, X = map(int, input().split())
l = list(map(int, input().split()))
d = [-1]*(N+1) #0-index #バウンドする位置を格納するリスト
d[0] = 0 #バウンドする初期値は0

for i in range(1, N+1):
    d[i] = d[i-1] + l[i-1]

#print(d)
#print('left:', bisect.bisect_left(d, X))
#print('right:', bisect.bisect_right(d, X))
print(bisect.bisect_right(d, X))

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

#define endl '\n'
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

////////////////////////////////////////////////////////////////////

const int N = 2e5 + 5;

bool M[N];
int L[N], R[N], D[N], H[N];
vector<pii> G[N];

void DFS(int v, int w = 0) {
	H[v] = w, M[v] = true;
	for (pii e : G[v]) if (!M[e.first]) DFS(e.first, w + e.second);
}

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> L[i] >> R[i] >> D[i];
		G[L[i]].push_back(make_pair(R[i], D[i]));
		G[R[i]].push_back(make_pair(L[i], -D[i]));
	}
	for (int i = 1; i <= n; i++) if (!M[i]) DFS(i);
	bool flag = true;
	for (int i = 0; i < m; i++) flag &= (H[R[i]] - H[L[i]] == D[i]);
	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 16256
l,r  = map(int,input().split())
a = l % 2019
b = r % 2019
if r - l >= 2019:
    print(0)
else:
    if a > b:
        print(0)
    else:
        ml = []
        for i in range(a,b):
            for j in range(i+1,b+1):
                ml.append((i*j)%2019)
        print(min(ml))

Measured memory_bytes: 75412
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <queue>

using namespace std;

using PII = pair<int, int>;

const long long inf = 1e18;

vector<vector<PII>> edges;
vector<long long> dist;

void dfs(int pos, long long d) {
	if (dist[pos] != inf) {
		return;
	}

	dist[pos] = d;

	for (auto p: edges[pos]) {
		dfs(p.first, d + p.second);
	}
}

int main() {
	int n, q, k;
	cin >> n;

	edges.assign(n, {});
	int a, b, c;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b >> c;
		a--;
		b--;

		edges[a].emplace_back(make_pair(b, c));
		edges[b].emplace_back(make_pair(a, c));
	}
	cin >> q >> k;
	k--;
	vector<int> x(q), y(q);
	for (int i = 0; i < q; i++) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}

	dist.assign(n, inf);
	dfs(k, 0);

	for (int i = 0; i < q; i++) {
		cout << dist[x[i]] + dist[y[i]] << endl;
	}

	// for (int i = 0; i < dist.size(); i++) {
	// 	printf("dist[%2d]: %3lld\n", i, dist[i]);
	// }

	return 0;
}


Measured memory_bytes: 11904
#if defined(__GNUC__)
#include <bits/stdc++.h>
#define __int32 __int32_t
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<decltype(x)::value_type>())
#define RSORT2(x, T) sort(ALL(x), greater<T>())
#define REVERSE(x) reverce(ALL(x))
#define ACM(x, y) accumulate(ALL(x), y)

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)
#define FCT(x) [](int a) -> int {int r = 1; REP(i, a){r *= i;} return r;}(x)

// デバッグ用
#define PUT_LIST(x, y) std::copy(ALL(x), ostream_iterator<decltype(x)::value_type>(cout, y))

const int kMod = 1e9 + 7;

itn main() {
	ios::sync_with_stdio(false);

	int n, m;

	cin >> n >> m;

	int res = n * (n - 1) / 2;
	res += m * (m - 1) / 2;

	cout << res;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define double long double
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
signed main() {
	int a,b;
	cin>>a>>b;
	if(b%a==0)cout<<a+b<<endl;
	else cout<<b-a<<endl;
}


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

int dp[1<<12][1<<12];
pair<int, int> pre[1<<12][1<<12];

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

  string s, t; cin >> s >> t;
  memset(dp, 0, sizeof(dp));

  int n = s.size(), m = t.size();

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      dp[i + 1][j + 1] = max({dp[i][j] + int(s[i] == t[j]),
                              dp[i][j + 1],
                              dp[i + 1][j]});
      if (dp[i + 1][j + 1] == dp[i][j + 1]) {
        pre[i + 1][j + 1] = {i, j + 1};
      }
      else if (dp[i + 1][j + 1] == dp[i + 1][j]) {
        pre[i + 1][j + 1] = {i + 1, j};
      }
      else if (dp[i + 1][j + 1] == dp[i][j] + int(s[i] == t[j])) {
        pre[i + 1][j + 1] = {i, j};
      }
      else assert(0);
    }
  }

  pair<int, int> cur = {n, m};
  string ans;

  while (cur != make_pair(0, 0)) {
    int i, j, ni, nj;
    tie(i, j) = cur;
    tie(ni, nj) = pre[i][j];
    if (ni + 1 == i and nj + 1 == j) {
      ans.push_back(s[ni]);
      assert(s[ni] == t[nj]);
    }
    cur = {ni, nj};
  }

  reverse(ans.begin(), ans.end());
  cout << ans << '\n';
}



Measured memory_bytes: 161792
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
ll dp[1000002];
int main(){
  ll a,b,c=0,ans=0;cin>>a;
  rep(i,a){
    cin>>b;
    c=max(b,c);
    ans+=c-b;
  }
  cout<<ans;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
string s;
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n>>s;
    m=s.size();
    if(m<=n)
    {
        cout<<s<<"\n";
    }
    else
    {
        for(i=0;i<n;i++)
        {
            cout<<s[i];
        }
        cout<<"...\n";
    }
    return 0;
}



Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int main()
{
    int n,p;
    scanf("%d%d",&n,&p);
    printf("%d\n",(n*3+p)/2);
    return 0;
}


Measured memory_bytes: 256
#include <map>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

LL a[200010], c[200010], b[200010];

int main(){
//	freopen("in.txt", "r", stdin);
	int n; 
	cin >> n;
	LL po = 0, ne = 0;
	for (int i = 1; i <= n; i ++){
		scanf("%lld", &b[i]);
	}
	for (int i = 1; i <= n; i ++){
		scanf("%lld", &c[i]);
	}
	for (int i = 1; i <= n; i ++){
		a[i] = b[i] - c[i];
		if (a[i] > 0) po += a[i];
		if (a[i] < 0) ne -= a[i] / 2; 
	}
//	cout << po << " " << ne << endl;
	if (po > ne) puts("No");
	else puts("Yes");
	return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}
ll dp1[101][4];
ll dp2[101][4];
int main() {
    int K;
    string N;
    cin >> N >> K;
    // cout << "wo" << endl;
    int keta = N.length();
    // cout << keta << endl;
    // vector<vector<ll>> dp1(keta, vector<ll>(K + 1, 0LL));
    // vector<vector<ll>> dp2(keta, vector<ll>(K + 1, 0LL));
    // cout << "memory allocated" << endl;
    // dp1 inactive
    // dp2 active
    dp1[0][0] = 1LL;
    // cout << "e" << endl;
    dp1[0][1] = N[0] - '0' - 1;
    // cout << dp1[0][1] << endl;
    dp2[0][1] = 1;
    dp2[0][0] = 0;
    for(int i = 1; i < keta; i++) {
        for(int j = 0; j <= K; j++) {
            // jは0出ない数
            if(j == 0) {
                dp1[i][j] = dp1[i - 1][j];
            } else {
                dp1[i][j] = 9 * dp1[i - 1][j - 1] + dp1[i - 1][j];
                if(N[i] != '0') {
                    dp1[i][j] +=
                        (N[i] - '0' - 1) * dp2[i - 1][j - 1] + dp2[i - 1][j];
                }
                if(j != 0) {
                    if(N[i] == '0') {
                        dp2[i][j] = dp2[i - 1][j];
                    } else {
                        dp2[i][j] = dp2[i - 1][j - 1];
                    }
                }
            }
        }
    }
    // cout << dp2[keta - 1][K] << " : " << dp1[keta - 1][K] << endl;
    cout << dp2[keta - 1][K] + dp1[keta - 1][K] << endl;
    return 0;
}

Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function () { return this.index < this.max },
        "next": function () { if (!this.hasNext()) { throw "ArrayIndexOutOfBoundsException"; } else { return this.list[this.index++]; } }
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)
const Main = () => {
    const [N, M] = nextIntArray()
    const x = nextIntArray()
    x.sort((a, b) => a - b)
    let diff = []
    for (let i = 1; i < M; i++) {
        diff.push(x[i] - x[i - 1])
    }
    diff.sort((a, b) => a - b)
    let ans = 0
    for (let i = 0; i < M - N; i++) {
        ans += diff[i]
    }
    console.log(ans)

}
Main()


Measured memory_bytes: 43844
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nm = readints;
    int n = nm[0], m = nm[1];

    auto xs = readints;
    auto uf = new UnionFind(n + 1);
    for (int i = 0; i < m; i++) {
        auto xy = readints;
        uf.unite(xs[xy[0] - 1], xs[xy[1] - 1]);
    }

    int ans = 0;
    foreach (i; 1 .. n + 1) {
        if (uf.isSame(xs[i - 1], i)) {
            ans++;
        }
    }

    writeln(ans);
}

class UnionFind {
    private int[] _data;
    private int[] _nexts; // 次の要素。なければ -1
    private int[] _tails; // 末尾の要素

    this(int n) {
        _data  = new int[](n + 1);
        _nexts = new int[](n + 1);
        _tails = new int[](n + 1);

        _data[] = -1;
        _nexts[] = -1;
        for (int i = 0; i < _tails.length; i++)
            _tails[i] = i;
    }

    int root(int a) {
        if (_data[a] < 0) return a;
        return _data[a] = root(_data[a]);
    }

    bool unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) return false;
        // ra に rb を繋げる
        _data[ra] += _data[rb];
        _data[rb] = ra;

        // ra の末尾の後ろに rb を繋げる
        _nexts[_tails[ra]] = rb;
        // ra の末尾が rb の末尾になる
        _tails[ra] = _tails[rb];
        return true;
    }

    bool isSame(int a, int b) {
        return root(a) == root(b);
    }

    /// a が属する集合のサイズ
    int groupSize(int a) {
        return -_data[root(a)];
    }

    /// a が属する集合の要素全て
    void doEach(int a, void delegate(int) fn) {
        auto node = root(a);
        while (node != -1) {
            fn(node);
            node = _nexts[node];
        }
    }
}


Measured memory_bytes: 5180
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef vector<vector<int>> MX;

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

map<ll,ll>M;
priority_queue<ll>Q;

int main()
{
	ll N;
	cin>>N;
	for(int i=0;i<N;i++)
	{
		int p;
		cin>>p;
		M[p]++;
	}
	for(auto p:M)
	{
		Q.push(p.second);
	}
	cout<<(Q.size()%2?Q.size():Q.size()-1)<<endl;
}


Measured memory_bytes: 10400
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> w(n);
    int all = 0;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
        all += w[i];
    }

    int sum = 0;
    int diff = all;
    for (int i = 0; i < n; i++) {
        sum += w[i];

        if (abs(all - 2 * sum) < diff) {
            diff = abs(all - 2 * sum);
        }
    }

    cout << diff;
}

Measured memory_bytes: 256