akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BDigitSums solver = new BDigitSums();
        solver.solve(1, in, out);
        out.close();
    }

    static class BDigitSums {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int sum = 0;
            int tmp = n;
            while (tmp > 0) {
                sum += tmp % 10;
                tmp /= 10;
            }

            out.println(n % sum == 0 ? "Yes" : "No");
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21460
#include <iostream> 
#include <stdlib.h> 
#include <string.h> 
#include <string> 
#include <sstream>
#include <cstring> 
#include<cmath>
using namespace std;
int main()
{
	long long x = 2, y = 1,z=0,w;
	cin >> w;
	if (w == 1) {
		cout << 1;
	}
	else {
		for (int i = 1; i < w; i++) {



			z = (x + y);

			x = y;
			y = z;
		}
		cout << z;
	}
    return 0;
}

Measured memory_bytes: 3620
#include <cassert>
#include <cstddef>
#include <utility>
#include <vector>


template <class Abelian> class PotentializedUnionFind {

public:
	using value_type = Abelian;
	using difference_type = std::ptrdiff_t;
	using container_type = std::vector<std::pair<difference_type, value_type>>;
	using const_reference = const value_type &;
	using size_type = typename container_type::size_type;

protected:
	container_type c;

private:
	value_type potential(size_type x) {
		value_type ret = {};
		while (c[x].first >= static_cast<difference_type>(0)) {
			if (c[static_cast<size_type>(c[x].first)].first >=
				static_cast<difference_type>(0)) {
				c[x].second =
					c[static_cast<size_type>(c[x].first)].second + c[x].second;
				c[x].first = c[static_cast<size_type>(c[x].first)].first;
			}
			ret = ret + c[x].second;
			x = static_cast<size_type>(c[x].first);
		}
		return std::move(ret);
	}

public:
	PotentializedUnionFind() : c() {}
	explicit PotentializedUnionFind(const size_type size)
		: c(size, std::make_pair(-1, value_type())) {}

	size_type size() const { return c.size(); }
	bool empty() const { return c.empty(); }

	size_type find(size_type x) {
		assert(x < size());
		while (c[x].first >= static_cast<difference_type>(0)) {
			if (c[static_cast<size_type>(c[x].first)].first >=
				static_cast<difference_type>(0)) {
				c[x].second =
					c[static_cast<size_type>(c[x].first)].second + c[x].second;
				c[x].first = c[static_cast<size_type>(c[x].first)].first;
			}
			x = static_cast<size_type>(c[x].first);
		}
		return x;
	}
	value_type diff(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return potential(y) + (-potential(x));
	}
	bool same(const size_type x, const size_type y) {
		assert(x < size());
		assert(y < size());
		return find(x) == find(y);
	}
	size_type size(const size_type x) {
		assert(x < size());
		return static_cast<size_type>(-c[find(x)].first);
	}

	bool unite(size_type x, size_type y, value_type d) {
		assert(x < size());
		assert(y < size());
		d = d + diff(y, x);
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (c[x].first > c[y].first)
			std::swap(x, y), d = -d;
		c[x].first += c[y].first;
		c[y] = std::make_pair(static_cast<difference_type &&>(x), std::move(d));
		return true;
	}
};

#include<cstdio>

int main() {
	using uint = unsigned int;
	uint n, m;
	scanf("%u%u", &n, &m);
	PotentializedUnionFind<int> T(n);
	while (m--) {
		uint l, r;
		int d;
		scanf("%u%u%d", &l, &r, &d);
		--l;--r;
		if (!T.unite(l, r, d)) {
			if (T.diff(l, r) != d) {
				puts("No");
				return 0;
			}
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 1792
N = int(input())
T, A = map(int, input().split())
for i in range(N-1):
  t, a = map(int, input().split())
  p = (T-1)//t + 1
  q = (A-1)//a + 1
  n = max(p, q)
  T = n*t
  A = n*a
print(T+A)

Measured memory_bytes: 3060
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
//#define double long double

using namespace std;

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

const int MOD = 1e9 + 7;
const ll INF = 1e17;
const int INT_INF = 1e9;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int N;
double X[101], Y[101];
double dist(double x, double y) {
	return sqrt(x*x + y * y);
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	REP(i, N) {
		cin >> X[i] >> Y[i];
	}
	double theta = 0;
	double ans = 0;
	while (theta <= 2 * pi) {
		double x = 0, y = 0;
		REP(i, N) {
			if (cos(theta)*X[i] + sin(theta)*Y[i] > 0) {
				x += X[i];
				y += Y[i];
			}
		}
		ans = max(ans, dist(x, y));
		theta += pi / 1000000.0;
	}
	cout << setprecision(12) << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n;
  cin>>n;
  int cnt=0,mi=1e9+1,sum=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    sum+=abs(a);
    mi=min(abs(a),mi);
    if(a<0)cnt++;
  }
  cout<<sum-(cnt%2)*mi*2<<endl;
  return 0;
}


Measured memory_bytes: 256
def resolve():
    import sys

    input = lambda: sys.stdin.readline().rstrip()

    a, b, c, k = map(int,input().split())
    
    if a >= k:
      print(k)
    elif a + b >= k:
      print(a)
    else:
      print(a-(k-(a+b)))
      
resolve()

Measured memory_bytes: 61764
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;

int main(){
  long long int n;
  cin>>n;
  long long int sum=0;
  vector<long long int> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  while(1){
    sort(a.begin(),a.end());
    if(a[n-1]==(n-1))break;
    long long int wl=a[n-1]/n;
    sum+=wl;
    for(int i=0;i<n-1;i++){
      a[i]+=wl;
    }
    a[n-1]-=wl*n;
  }

  cout<<sum<<endl;

  return 0;
}


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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  long long ans = a[0];
  for (int i = 1, j = n - 2; j > 0; ++i) {
    ans += min(2, j) * a[i];
    j -= min(2, j);
  }
  cout << ans;

  return 0;
}


Measured memory_bytes: 3976
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

L, R = gets_i_list
MOD = 2019

if L == R - 1
  puts L * R % MOD
else
  if R - L >= 2019
    puts 0
  else
    ans = (L..R).to_a.combination(2).map do |i, j|
      i * j % MOD
    end.sort
    puts ans.first
  end
end


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

void dfs(int N,int s,string r){
    if(N==s){
        cout << r<<endl;
        return;
    }
    char max=0;
    for(int i=0;i<s;i++){
        if(r[i]>max){
            max=r[i];
        }
    }
    for(char x='a';x<max+2;x++){
        dfs(N,s+1,r+x);
    }
}

int main(){
    int N;
    cin >> N;
    dfs(N,1,"a");
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<cstdio>
#include<sstream>
using namespace std;
string s;
long long cnt;
int a[20];
int to_num(string s)
{
	int a;
	stringstream ss(s);
	ss>>a;
	return a;
}
bool pls[20];
long long add()
{
	long long t=0;
	long long sum=0;
	for(int i=0;i<s.size()-1;i++)
	{
			t=t*10+a[i];
		if(pls[i])
		{
			sum+=t;
			t=0;
		}
	}
	t=t*10+a[s.size()-1];
	return t+sum;
}
void dfs(int x)
{
	if(x==s.size()-1)
	{
		cnt+=add();
		return;
	}
	pls[x]=0;
	dfs(x+1);
	pls[x]=1;
	dfs(x+1);
}
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		a[i]=s[i]-'0';
	}
	dfs(0);
	cout<<cnt;
    return 0;
}


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

using namespace std;

const int maxn = 1e5 + 10;
int x[maxn];
int main(){
    int n;
    cin >> n;
    memset(x, 0, sizeof(x));
    int r = 0;
    x[0] = 0;
    x[n + 1] = 0;
    for (int i = 1; i <= n; ++i) {
        cin >> x[i];
        if(i == 1)r += abs(x[i]);
        else r += abs(x[i] - x[i-1]);
    }
    r += abs(x[n]);
    for (int i = 1; i <= n; ++i) {
        cout << r - abs(x[i]-x[i-1]) - abs(x[i+1]-x[i]) + abs(x[i - 1] - x[i + 1]) << endl;
    }
    return 0;
}

Measured memory_bytes: 1664
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) >= 0 ? (a) : (-(a)))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) > *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static size_t countDivisors(const size_t n)
{
	size_t count = 1;

	for (size_t i = 2; i <= n; i++) {
		if (n%i == 0) {
			count++;
		}
	}

	return count;
}

static int32_t x[100000];

int main(void) {
	size_t N, K;

	scanf("%zu %zu\n", &N, &K);
	for (size_t idx = 0; idx < N; idx++) {
		scanf("%"PRId32, &x[idx]);
		if (idx < N - 1) {
			scanf(" ");
		}
	}

	size_t minTime = (size_t)UINT32_MAX;

	for (size_t beginIdx = 0; beginIdx <= N - K; beginIdx++) {
		const size_t endIdx = beginIdx + K - 1;
		{
			const size_t timeCost = ABSS(x[beginIdx], x[endIdx]) + ABS(x[beginIdx]);
			if (timeCost < minTime) {
				minTime = timeCost;
			}
		}
		{
			const size_t timeCost = ABSS(x[beginIdx], x[endIdx]) + ABS(x[endIdx]);
			if (timeCost < minTime) {
				minTime = timeCost;
			}
		}
	}

	printf("%zu\n", minTime);

	return 0;
}


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

int main() {
  ll n;
  cin >> n;
  vector<ll> a (n+1);
  vector<ll> b (n);
  for(ll i=0; i<n+1; i++){
    cin >> a.at(i);
  }
  for(ll i=0; i<n; i++){
    cin >> b.at(i);
  }
  ll ans = 0;
  for(ll i=0; i<n; i++){
    if(b.at(i) > a.at(i)){
      ans += a.at(i);
      b.at(i) = b.at(i) - a.at(i);
      if(a.at(i+1) <= b.at(i)){
        ans += a.at(i+1);
        a.at(i+1) = 0;
      }
      else{
        ans += b.at(i);
        a.at(i+1) = a.at(i+1) - b.at(i);
      }
    }
    else{
      ans += b.at(i);
      a.at(i) = a.at(i) - b.at(i);
    }
  }
  cout << ans << endl;
}

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

#define FOR(a,b,c) for (int a=(b);a<(c);++a)
#define REP(i,n) FOR(i,0,n)
#define ll long long
#define pii pair<int,int>
#define x first
#define y second
#define pb push_back
#define lf double

using namespace std;

const int MAX = (int)1e6 + 5;

int main(){
	int a;
	scanf ("%d",&a);
	printf (a>=30?"Yes":"No");
	
	
	return 0;
}


Measured memory_bytes: 3824
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
double EPS=1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

bool used[51][51][51][51];
int W,H;
char field[2][101][101];
int sy[2],sx[2],gy[2],gx[2];

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

typedef pair<pii,pii> ppi;

bool bfs(){
	queue<ppi> q;
	q.push(make_pair(pii(sy[0],sx[0]),pii(sy[1],sx[1])));
	used[sy[0]][sx[0]][sy[1]][sx[1]]=true;
	while(q.size()){
		ppi p=q.front();q.pop();
		int cy1=p.first.first;
		int cx1=p.first.second;
		int cy2=p.second.first;
		int cx2=p.second.second;
		//if(cy1>=0&&cx1>=0&&cy1<H&&cx1<W)
		for(int i=0;i<4;i++){
			if(i==0||i==2){
				int ny1=cy1+dy[i];
				int nx1=cx1+dx[i];
				if(!(ny1>=0&&nx1>=0&&ny1<H&&nx1<W)||field[0][ny1][nx1]=='#'){
					ny1=cy1;
					nx1=cx1;
				}
				int ny2=cy2+dy[i];
				int nx2=cx2+dx[i];
				if(!(ny2>=0&&nx2>=0&&ny2<H&&nx2<W)||field[1][ny2][nx2]=='#'){
					ny2=cy2;
					nx2=cx2;
				}
				if(!used[ny1][nx1][ny2][nx2]){
					if(!((ny2==gy[1]&&nx2==gx[1])^(ny1==gy[0]&&nx1==gx[0]))){
						used[ny1][nx1][ny2][nx2]=true;
						q.push(make_pair(pii(ny1,nx1),pii(ny2,nx2)));
					}
				}
			}
			else{
				int ny1=cy1+dy[i];
				int nx1=cx1+dx[i];
				if(!(ny1>=0&&nx1>=0&&ny1<H&&nx1<W)||field[0][ny1][nx1]=='#'){
					ny1=cy1;
					nx1=cx1;
				}
				int ny2=cy2-dy[i];
				int nx2=cx2-dx[i];
				if(!(ny2>=0&&nx2>=0&&ny2<H&&nx2<W)||field[1][ny2][nx2]=='#'){
					ny2=cy2;
					nx2=cx2;
				}
				if(!used[ny1][nx1][ny2][nx2]){
					if(!( (ny2==gy[1]&&nx2==gx[1])^(ny1==gy[0]&&nx1==gx[0]) )){
						used[ny1][nx1][ny2][nx2]=true;
						q.push(make_pair(pii(ny1,nx1),pii(ny2,nx2)));
					}
				}
			}
		}
	}
	return used[gy[0]][gx[0]][gy[1]][gx[1]];
}

void solve(){
	while(cin>>W>>H&&(H|W)){
		for(int i=0;i<H;i++){
			for(int j=0;j<2*W;j++){
				if(j<W){
					cin>>field[0][i][j];
					if(field[0][i][j]=='L'){
						field[0][i][j]='.';
						sy[0]=i;
						sx[0]=j;
					}
					else if(field[0][i][j]=='%'){
						gy[0]=i;
						gx[0]=j;
						field[0][i][j]='.';
					}
				}
				else{
					cin>>field[1][i][j%W];
					if(field[1][i][j%W]=='R'){
						field[1][i][j%W]='.';
						sy[1]=i;
						sx[1]=j%W;
					}
					else if(field[1][i][j%W]=='%'){
						gy[1]=i;
						gx[1]=j%W;
						field[1][i][j%W]='.';
					}
				}
			}
		}
		memset(used,0,sizeof(used));
		if(bfs()){
			cout<<"Yes"<<endl;
		}
		else cout<<"No"<<endl;
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 8416
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
string s;
int ans;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(i>=s.size()-1-i)
			break;
		if(s[i]!=s[s.size()-1-i])
			ans++;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 256
import numpy as np

N = int(input())
T = [[int(_) for _ in input().split()] for i in range(N)]


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n + 1)]
        self.rank = [0] * (n + 1)

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[x] = y
            else:
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


E = []
indices_x = np.argsort([x for x, y in T])
indices_y = np.argsort([y for x, y in T])

for i in range(N - 1):
    a, _ = T[indices_x[i]]
    c, _ = T[indices_x[i + 1]]
    E.append((indices_x[i], indices_x[i + 1], abs(a - c)))

    _, b = T[indices_y[i]]
    _, d = T[indices_y[i + 1]]
    E.append((indices_y[i], indices_y[i + 1], abs(b - d)))

uf = UnionFind(N)
ans = 0
for i, j, cost in sorted(E, key=lambda x: x[2]):
    if uf.same_check(i, j):
        continue

    uf.union(i, j)
    ans += cost

print(ans)


Measured memory_bytes: 76464
def calc_cost(h):
    if (len(h) == 0):
        return 0

    cost = [None] * len(h)
    cost[0] = 0
    for i in range(1, len(h)):
        cost[i] = cost[i-1] + abs(h[i] - h[i-1])
        if i>1:
            cost[i] = min(cost[i], cost[i-2] + abs(h[i] - h[i-2]))

    return cost[len(h)-1]

if __name__ == "__main__":
    n = int(input())
    h = list(map(int, input().split(" ")))
    res = calc_cost(h)
    print(res)

Measured memory_bytes: 13928
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#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 <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;

// 最大公約数求める関数
auto my_gcd(auto n , auto m){
  if(n < m){
    auto tmp = n;
    n = m;
    m = tmp;
  }
  auto l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
  ll A,B; cin >> A >> B;
  ll x = my_gcd(A,B);
  cout << A * B / x << endl;
  }


Measured memory_bytes: 256
def f():
  n=int(input())
  l=tuple(tuple(map(int,input().split())) for i in range(n-1))
  for i in range(n):
    now=0
    for a,s,d in l[i:]:
      now=a+s-(-max(0,now-s)//d)*d
    print(now)
if __name__=="__main__":
  f()

Measured memory_bytes: 3188
/*
读题不规范，爆零两行泪。
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
D P 顺序错，爆零两行泪。
大小少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int N=200000,LOG_N=20;
int n,m,qu;
int a[N+1];
int rit[N+1],lft[N+1];
int rit_to[N+1][LOG_N],rit_sum[N+1][LOG_N],lft_to[N+1][LOG_N],lft_sum[N+1][LOG_N];
int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	int now=1;
	for(int i=1;i<=n;i++){
		while(now<=n&&a[now]-a[i]<m)now++;
		rit[i]=now;
	}
	rit[n+1]=n+1;
	for(int i=n+1;i;i--){
		rit_to[i][0]=rit[i],rit_sum[i][0]=-rit[i]+1;
		for(int j=1;j<LOG_N;j++)
			rit_to[i][j]=rit_to[rit_to[i][j-1]][j-1],
			rit_sum[i][j]=rit_sum[i][j-1]+rit_sum[rit_to[i][j-1]][j-1];
	}
	now=n;
	for(int i=n;i;i--){
		while(now&&a[i]-a[now]<m)now--;
		lft[i]=now;
	}
	lft[0]=0;
	for(int i=0;i<=n;i++){
		lft_to[i][0]=lft[i],lft_sum[i][0]=lft[i];
		for(int j=1;j<LOG_N;j++)
			lft_to[i][j]=lft_to[lft_to[i][j-1]][j-1],
			lft_sum[i][j]=lft_sum[i][j-1]+lft_sum[lft_to[i][j-1]][j-1];
	}
	cin>>qu;
	while(qu--){
		int l,r;
		scanf("%d%d",&l,&r);
		int ans=0;
		now=l;
		ans+=-now+1;
		for(int i=LOG_N-1;~i;i--)if(rit_to[now][i]<=r)ans+=rit_sum[now][i],now=rit_to[now][i];
		now=r;
		ans+=now;
		for(int i=LOG_N-1;~i;i--)if(lft_to[now][i]>=l)ans+=lft_sum[now][i],now=lft_to[now][i];
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 68636
#include<iostream>
#include<cstdio>
using namespace std;
int n,a[100100],cnt[100100];
int main()
{
	int n,mx;scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),cnt[a[i]]++;
	for(int i=n;i>=1;i--)if(cnt[i]){mx=i;break;}
	mx++;
	if(mx&1)
	{
		if(cnt[mx>>1]!=1)return 0*puts("Impossible");
		for(int i=1;i<(mx>>1);i++)if(cnt[i]!=0)return 0*puts("Impossible");
		for(int i=(mx>>1)+1;i<mx;i++)if(cnt[i]<2)return 0*puts("Impossible");
		for(int i=mx;i<=n;i++)if(cnt[i]!=0)return 0*puts("Impossible");
	}
	else
	{
		if(cnt[mx>>1]!=2)return 0*puts("Impossible");
		for(int i=1;i<(mx>>1);i++)if(cnt[i]!=0)return 0*puts("Impossible");
		for(int i=(mx>>1)+1;i<mx;i++)if(cnt[i]<2)return 0*puts("Impossible");
		for(int i=mx;i<=n;i++)if(cnt[i]!=0)return 0*puts("Impossible");
	}
	return 0*puts("Possible");
}

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

using namespace std;

typedef long long int 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; }
 
typedef pair<int,int> pair;

int main(){
    int a,b,c; cin >> a >> b >> c;
    bool ans=false;

    if(a==7 && b==5 && c==5)
        ans=true;
    if(b==7 && a==5 && c==5)
        ans=true;
    if(c==7 && b==5 && a==5)
        ans=true;

    if(ans){
        cout << "YES" << endl;
    }else{
        puts("NO");
    }
}

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

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

    vector<int> es(N), ws(N);

    for (int i = 0; i < N; i++) {
        es[i] = (i == 0 ? 0 : es[i-1]) + (S[i] == 'W');
        ws[N-i-1] = (i == 0 ? 0 : ws[N-i]) + (S[N-i-1] == 'E');
    }

    int best = 1 << 30;

    for (int i = 0; i < N; i++) {
        int ec = (i == 0 ? 0 : es[i-1]);
        int wc = (i + 1 == N ? 0 : ws[i+1]);

        best = min(best, ec + wc);
    }

    cout << best << endl;
}


Measured memory_bytes: 3068
a, b = map(int, input().split())
c = input()
d = [0] * a
e = 0
for i in range(a):
    if c[i] == "C" and c[i-1] == "A":
        e += 1
    d[i] = e
for i in range(b):
    f, g = map(int, input().split())
    print(d[g-1] - d[f-1])


Measured memory_bytes: 6084
abc = list(map(int, input().split()))
a = abc[0]
b = abc[1]
k = abc[2]
kazu = []

if a > b:
    for i in range(b):
        if a % (i+1) == 0 and b % (i+1) == 0:
            kazu.append(i+1)
else:
    for i in range(a):
        if a % (i+1) == 0 and b % (i+1) == 0:
            kazu.append(i+1)

print(kazu[-k])

Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#define PB push_back
#define MP make_pair

using namespace std;
typedef long long ll;

int tpar[100000],par[100000];
int mark[100000];
int search(int a){
    if(mark[a]) return a;
    else return search(tpar[a]);
}
int find(int a){
    if(par[a]==a) return a;
    else return par[a]=find(par[a]);
}
void unite(int a,int b){
    par[find(a)]=find(b);
}
int main(){
    int N,Q;
    for(;;){
        scanf("%d %d\n",&N,&Q);
        if(N==0 && Q==0) break;
        tpar[0]=0;
        int p;
        for(int i=1;i<N;i++){
            scanf("%d\n",&p);
            tpar[i]=p-1;
        }
        fill(mark,mark+N,0);
        mark[0]=1;
        char q;
        int a;
        vector<pair<char,int>> query;
        for(int i=0;i<Q;i++){
            scanf("%c %d\n",&q,&a);
            a--;
            query.PB(MP(q,a));
            if(q=='M') mark[a]++;
        }
        for(int i=0;i<N;i++){
            par[i]=search(i);
        }
        ll ans=0;
        for(int i=Q-1;i>=0;i--){
            int now=query[i].second;
            if(query[i].first=='Q') ans+=find(now)+1;
            else if(!--mark[now]) unite(now,tpar[now]);
        }
        printf("%lld\n",ans);
    }
}

Measured memory_bytes: 3888
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto abc = readln.split.to!(int[]);
    auto A = abc[0];
    auto B = abc[1];
    auto C = abc[2];
    writeln(max(0, C - A + B));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int const NMAX = 1e5;
int v[1 + NMAX];

int main() {

  int n, pos = 1, p = 1e9, ans = 1e9;
  string bigG;
  cin >> bigG;
  for(int i = 0;i < bigG.size() - 2;i++){
    pos = (bigG[i] - '0') * 100 + (bigG[i + 1] - '0') * 10 + (bigG[i + 2] - '0');
    if(abs(pos - 753) < p){
      p = abs(pos - 753);
      ans = pos;
    }
  }
  cout << p;
  return 0;
}


Measured memory_bytes: 3568
/************************************************
 # @Author:      miniLCT
 # @DateTime:    2019-12-22 19:55:49
 # @Description: You build it.You run it
 # @More: If lots of AC,try BF,dfs,DP
 ***********************************************/
#include <bits/stdc++.h>

using namespace std;
#define eps 1e-8
#define close ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef long long ll;
const int maxn = 1e6;
const int INF = 1e9;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int main()
{
	int n ;
	string s, t;
	cin >> n >> s >> t;
	for(int i = 0; i < n;i++){
		cout << s[i] << t[i];
	}
	cout << endl;
}

/******************************************************
 stuff you should look for
  * int overflow, array bounds
  * special cases (n=1?), set tle
  * do smth instead of nothing and stay organized
*******************************************************/

Measured memory_bytes: 256
x=int(input())
input = list(map(int, input().split()))

for i in range(len(input)):
  if(input[i]==0):
    print(0)
    exit(0)

multi=1
for i in range(len(input)):    
  multi *= input[i]
  if(multi > (10 ** 18)):
    print(-1)
    exit(0)

print(multi)

Measured memory_bytes: 21368
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll INF=1e18;
int n;
ll a[20];
map<P, ll> memo[18][18];
ll solve(int l, int r, int x, int y){
	if(l>r) return 0;
	if(l==r) return a[l]*x;
	if(r-l==1) return a[l]*x+a[r]*y;
	if(memo[l][r].find({x, y})!=memo[l][r].end()){
		return memo[l][r][{x, y}];
	}
	ll ret=INF;
	for(int i=l+1; i<r; i++){
		ret=min(ret, solve(l, i, x, x+y)+solve(i, r, x+y, y)-a[i]*(x+y));
	}
	return memo[l][r][{x, y}]=ret;
}
int main()
{
	cin>>n;
	for(int i=0; i<n; i++) cin>>a[i];
	cout<<solve(0, n-1, 1, 1)<<endl;
	return 0;
}

Measured memory_bytes: 16512
split :: String -> String -> [String]
split _ "" = [""]
split t (s:sr)
  |t == [s] = [] : (split t sr)
  |otherwise = (s : (head (split t sr))) : (tail (split t sr))

data Date = Date {year :: Int, month :: Int, day :: Int}

instance Eq Date where
  a == b = (year a == year b) && (month a == month b) && (day a == day b)

instance Ord Date where
  compare a b = ((year a) * 365 + (month a) * 31 + (day a)) `compare` ((year b) * 365 + (month b) * 31 + (day b))

meiji = Date 1868 9 8
taisho = Date 1912 7 30
showa = Date 1926 12 25
heisei = Date 1989 1 8

gengo :: Date -> String
gengo d
  |d < meiji = "pre-meiji" ++ "\n"
  |d < taisho = "meiji " ++ (show ((year d) - (year meiji) + 1)) ++ " " ++ (show $ month d) ++ " " ++ (show $ day d) ++ "\n"
  |d < showa = "taisho " ++ (show ((year d) - (year taisho) + 1)) ++ " " ++ (show $ month d) ++ " " ++ (show $ day d) ++ "\n"
  |d < heisei = "showa " ++ (show ((year d) - (year showa) + 1)) ++ " " ++ (show $ month d) ++ " " ++ (show $ day d) ++ "\n"
  |otherwise = "heisei " ++ (show ((year d) - (year heisei) + 1)) ++ " " ++ (show $ month d) ++ " " ++ (show $ day d) ++ "\n"

main = do
  input <- getContents
  mapM_ putStr $ map gengo $ map (((\[y, m, d] -> Date (read y) (read m) (read d)) .) (split " ")) $ lines input

Measured memory_bytes: 3924
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = 1 << 30;
const ll INFll = 1ll << 60;

int main() {
  int a;
  cin >> a;
  cout << (3 * a * a) << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.ReadLine();
            var arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            MergeSort(arr, 0, arr.Length);
            Console.WriteLine(Count);
        }

        private static long Count { set; get; } = 0;

        public static void Merge(int[] array, int left, int mid, int right)
        {
            var nl = mid - left;
            var nr = right - mid;
            var lefts = new int[nl + 1];
            var rights = new int[nr + 1];
            Array.Copy(array, left, lefts, 0, nl);
            Array.Copy(array, mid, rights, 0, nr);
            lefts[nl] = int.MaxValue;
            rights[nr] = int.MaxValue;
            var i = 0; var k = 0;
            for (var m = left; m < right; ++m)
            {
                if (lefts[i] <= rights[k])
                {
                    array[m] = lefts[i];
                    ++i;
                }
                else
                {
                    array[m] = rights[k];
                    ++k; Count += nl - i;
                }
            }
        }

        public static void MergeSort(int[] array, int left, int right)
        {
            if (left + 1 < right)
            {
                var mid = (left + right) / 2;
                MergeSort(array, left, mid);
                MergeSort(array, mid, right);
                Merge(array, left, mid, right);
            }
        }
    }
}


Measured memory_bytes: 41732
#include <iostream>
#define ll long long
using namespace std;
void print(int , int);
int main() {
    int n ,k;
    cin >> n >> k;
    if ( k <= ((n-1)*(n-2))/2 ) {
        int m = ( ((n-1) * (n-2))/2 - k );
        print(n ,m);
    
    
    }else {

        cout << -1;
    }
    
    
}



void print (int n ,int m) {
    cout << m+n-1<< endl;
    for (int i= 1; i< n;i++ ){
        cout << i << " "<< n << endl; 
    }
    int s= 0;
    for (int i=1;i <n;i++ ) {
        for (int j = i+1;j < n;j++) {
            if (s < m) {
                cout << i<<" "<< j<< endl;
                s++;
            }
        }
    }
}


Measured memory_bytes: 256
#ライブラリインポート
from collections import defaultdict
import queue

#入力受け取り
def getlist():
	return list(map(int, input().split()))

INF = float("inf")

class Graph(object):
	def __init__(self):
		self.graph = defaultdict(list)

	def __len__(self):
		return len(self.graph)

	def add_edge(self, a, b):
		self.graph[a].append(b)

	def get_nodes(self):
		return self.graph.keys()

class BFS(object):
	def __init__(self, graph, s, N):
		self.g = graph.graph
		self.Q = queue.Queue()
		self.Q.put(s)
		self.color = defaultdict(int)
		self.precolor = [None] * N
		self.visit = ["No"] * N
		self.visit[s] = "Yes"
		while not self.Q.empty():
			v = self.Q.get()
			self.c = 0
			for i in self.g[v]:
				if self.visit[i] == "No":
					self.c += 1
					if self.c == self.precolor[v]:
						self.c += 1
					x, y = sorted([i, v])
					self.color[100000 * x + y] = self.c
					self.precolor[i] = self.c
					self.Q.put(i)
					self.visit[i] = "Yes"


#処理内容
def main():
	N = int(input())
	G = Graph()
	S = []
	for i in range(N - 1):
		a, b = getlist()
		a, b = sorted([a, b])
		G.add_edge(a - 1, b - 1)
		G.add_edge(b - 1, a - 1)
		S.append([a - 1, b - 1])
	BF = BFS(G, 0, N)
	D = BF.color
	#print(D)
	ans = []
	d = defaultdict(int)
	for i in range(N - 1):
		a = S[i][0]
		b = S[i][1]
		ans.append(D[100000 * a + b])
		d[D[100000 * a + b]] += 1
	print(len(d))
	for i in range(N - 1):
		print(ans[i])

if __name__ == '__main__':
	main()

Measured memory_bytes: 116436
#include <iostream>
using namespace std;
int main() {
  int a[3][3] = {};
  bool sign[101] = {};
  int n;
  for (int i = 0; i < 3; i++)
    for (int j = 0; j < 3; j++)
      cin >> a[i][j];
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    sign[a] = true;
  }
  bool ok = false;
  for (int i = 0; i < 3; i++) {
    bool o = true;
    for (int j = 0; j < 3; j++) {
      if (!sign[a[i][j]]) {
        o = false;
      }
    }
    if (o)
      ok = true;
  }
  for (int i = 0; i < 3; i++) {
    bool o = true;
    for (int j = 0; j < 3; j++) {
      if (!sign[a[j][i]]) {
        o = false;
      }
    }
    if (o)
      ok = true;
  }
  if (sign[a[0][0]] && sign[a[1][1]] && sign[a[2][2]])
    ok = true;
  if (sign[a[0][2]] && sign[a[1][1]] && sign[a[2][0]])
    ok = true;
  if (ok)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
using namespace std;

int main(){
    int D,G;cin>>D>>G;
    int p[20],c[20],comp[20],ans=100000;
    for(int i=0;i<D;i++){
        cin>>p[i]>>c[i];
        comp[i]=100*(i+1)*p[i]+c[i];
    }

    for(int bit=0;bit<(1<<D);bit++){
        int sum=0,solve=0;
        for(int d=0;d<D;d++){
            if(bit&(1<<d)){
                sum+=comp[d];
                solve+=p[d];
            }
        }
        
        if(sum>=G)ans=min(ans,solve);
        else{
        int bit0=(1<<D)-1-bit;
        for(int i=0;i<D;i++){
            if(bit0&(1<<i)){
                int so=0;
                int su=sum;
                while(su<G){
                    su+=100*(i+1);
                    so++;
                    if(so==p[i])goto lol;
                }
                ans=min(ans,so+solve);
                lol:
                bool b;
            }
        }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
as = gets.split.map(&:to_i)

ans = 1
if n == 1 || as[0] == as[1]
  increased = 0
else
  increased = as[0] < as[1] ? 1 : -1
end

1.upto(n - 1) do |i|
  l = as[i - 1]
  r = as[i]
  next if l == r

  if increased == 0
    increased = l < r ? 1 : -1
    next
  end

  if (r - l) * increased < 0
    ans += 1
    increased = 0
  end
end

puts ans


Measured memory_bytes: 8460
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<list>
#define MAX(x,y) ((x>y)? x:y)

using namespace std;

FILE *wfp=fopen("output.txt","w");
FILE *rfp=fopen("input.txt","r");

int W;
int N;

int kati[10000];
int omosa[10000];

int DP[1005][10005];//[i][j]i番目までにjより小さくなるような価値
int DP_W[10005];//そのときの重さ

int CASE=0;
int main()
{
	wfp=stdout;
	rfp=stdin;
	while(true)
	{
		CASE++;
		fill(DP_W,DP_W+10005,0);
		for(int i=0;i<10000;i++)DP[0][i]=0;
		for(int i=0;i<1000;i++)DP[i][0]=0;
		fscanf(rfp,"%d",&W);
		if(W==0)break;
		fscanf(rfp,"%d",&N);
		for(int i=0;i<N;i++)
		{
			fscanf(rfp,"%d,%d",&kati[i],&omosa[i]);
		}
		for(int i=0;i<N;i++)
		{
			for(int j=0;j<W;j++)
			{
				if(j+1-omosa[i]>=0)DP[i+1][j+1]=MAX(DP[i][j+1],DP[i][j+1-omosa[i]]+kati[i]);
				else DP[i+1][j+1]=DP[i][j+1];
			}
		}
		DP_W[0]=0;
		for(int i=1;i<=W;i++)
		{
			if(DP[N][i]==DP[N][i-1])DP_W[i]=DP_W[i-1];
			else DP_W[i]=i;
		}


		fprintf(wfp,"Case %d:\n",CASE);
		fprintf(wfp,"%d\n",DP[N][W]);
		fprintf(wfp,"%d\n",DP_W[W]);
	}
	fclose(rfp);
	fclose(wfp);
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

    int N;
    cin >> N;
    vector<pair<int, int>> A(N);
    REP(i, N) cin >> A[i].first >> A[i].second;
    vector<pair<ll, int>> sum(N);
    REP(i, N) {
        sum[i].first  = A[i].first + A[i].second;
        sum[i].second = i;
    }
    RSORT(sum);
    ll taka = 0, aoki = 0;
    REP(i, N) {
        if (i % 2 == 0)
            taka += A[sum[i].second].first;
        else
            aoki += A[sum[i].second].second;
    }
    ll ans = taka - aoki;
    std::cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

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

  int w,n;
  scanf("%d %d",&w,&n);
  int left[n];
  int right[n];
  int ans[w+1];
  for(int i=0;i<n;i++) {
    scanf("%d,%d",&left[i],&right[i]);
  }
  for(int i=1;i<=w;i++) {
    int state = i;
    int t = 0;
    while(t<n) {
      if(left[t] == state) {
        state = right[t];
      }
      else if(right[t] == state) {
        state = left[t];
      }
      t++;
    }
    ans[state] = i;
  }
  for(int i=1;i<=w;i++) {
    printf("%d\n",ans[i]);
  }
}

Measured memory_bytes: 1212
/*
Oh, can you tell me, can you tell me the way the story ends?
A monster in my heart
A ghost inside my chest
I'm broken down, the world around us
Surround my suffering
You smile and laugh at me
But you don't see a thing

Damaged and broken as I am
I'm trying not to breathe
Unraveled, I'm not unraveled by
The truth I finally see, freeze

I'm breakable, unbreakable
I'm shakeable, unshakeable
Unraveling since I found you

And now I'm turning to dust in a world that's twisted
Don't come searching when I go missing
Close your eyes or just try to look away
Don't want to hurt you
We live in a world someone else imagined
The ghost of what's left of me all but vanished
Remember my heart, how bright I used to shine

Entangled in the loneliness
The memory of innocence
It's stinging me, it's breaking me
The pain is spreading endlessly
I cannot move, I close my eyes
I try to breathe, I realize -
I'm paralyzed, I'm paralyzed
UNRAVEL THE WORLD

I'm not what I was then
Don't touch the infection
Entwined we will both die
So stay away, and stay alive
I'm breakable, unbreakable
I'm shakeable, unshakeable
Unraveling, I won't infect you!

Now I'm turning to dust in a world that's twisted
Don't come searching when I go missing
Close your eyes or just try to look away
Don't want to hurt you
We live in a world someone else imagined
The ghost of what's left of me all but vanished
Remember my heart, how bright I used to shine

Please, just don't forget me...
Just don't forget me
Just don't forget me
Just don't forget me
Don't forget me

We live in a world someone else imagined
The ghost of what's left of me all but vanished
Remember my heart, how bright I used to shine

Oh, can you tell me?
Oh, can you tell me?
A monster in my heart
And now there's nothing left
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define PI 3.14159265358979323846
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef long double ld;
typedef string st;
const ll MOD = 1e9 + 7 ;
const ll INF=1e14;
ll mpow(ll a,ll b,ll p=MOD){a=a%p;ll res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const ll N=500020;

int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
 
      ll cnt[5]={0};
      forn(i,3)
      {
        ll x,y;
        cin>>x>>y;
        cnt[x]++;
        cnt[y]++;
      }
      ll cntq[3]={0};
      for1(i,4){
        if(cnt[i]>2)
        {
          cout<<"NO";
          return 0;
        }
        cntq[cnt[i]]++;
      }
      if(cntq[1]==2&&cntq[2]==2)
      {
        cout<<"YES\n";
      }
      else cout<<"NO\n";

}


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

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

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

dd d;

bool f(dd x,dd y)
{
  if(sqrt(x*x+y*y)<=d)
    return 1;
  return 0;
}

int main()
{
   su;
   dd n,x,y;
   int cnt=0;
   cin>>n>>d;
   while(n--)
   {
     cin>>x>>y;
     if(f(x,y)==1)
      cnt++;
  }
  cout<<cnt<<nl;
   return 0;
}


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

int main() {
    int n, t;
    cin >> n >> t;
    int c, d;
    int a = 1001;
    for (int i = 0; i < n; i++) {
        cin >> c >> d;
        if (d <= t) {
            a = min(a, c);
        }
    }

    if (a == 1001) {
        cout << "TLE" << endl;
    } else {
        cout << a << endl;
    }

}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(void)
{
	int n,m,p,i,j,x[101],sum,cnt,ans;
	while(1)	{
		scanf("%d %d %d",&n,&m,&p);
		if(n==0 && m==0 && p==0)	break;
		sum=0;
		for(i=1;i<=n;i++)	{
			scanf("%d",&x[i]);
			sum+=x[i];
		}
		sum=sum*100*(100-p)/100;
		if(x[m]==0)	printf("0\n");
		else {
			ans=sum/x[m];
			printf("%d\n",ans);
		}
	}
	return 0;
}


Measured memory_bytes: 1040
import math
import numpy as np


def main():
    N = int(input())
    SP = [list(input().split()) + [i + 1] for i in range(N)]
    SP.sort(key=lambda x: (x[0], -int(x[1])))
    _SP = np.array(SP)
    for i in _SP[:, 2]:
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 12496
#include<iostream>
#include<queue>

using namespace std;

struct position{
  int x,y;
};

int w,h,ans=0;
bool building[102][102],pushed[102][102];
queue<position> wait;
/*wjx,hiy*/
int dx[2][6]={{-1,0,-1,1,-1,0},{0,1,-1,1,0,1}};
int dy[6]={-1,-1,0,0,1,1};

int solve(position now)
{
  int total=0;
  for(int i=0;i<6;i++){
    position next={now.x+dx[now.y%2][i],now.y+dy[i]};
    if(0<=next.x&&next.x<=w+1&&0<=next.y&&next.y<=h+1){
      if(building[next.x][next.y]){
	total++;
      }
      else if(!pushed[next.x][next.y]){
	pushed[next.x][next.y]=true;
	wait.push(next);
      }
    }
  }
  return total;
}

int main()
{
  cin>>w>>h;
  for(int i=0;i<=h+1;i++){
    for(int j=0;j<=w+1;j++){
      building[j][i]=false;
      pushed[j][i]=false;
    }
  }
  for(int i=1;i<=h;i++){
    for(int j=1;j<=w;j++){
      cin>>building[j][i];
    }
  }

  position start={0,0};
  wait.push(start);

  while(!wait.empty()){
    ans+=solve(wait.front());
    wait.pop();
  }

  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1240
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces

def main():
    n,m = na()
    a = na()
    ans = n - sum(a)
    if ans < 0:
        print(-1)
        return
    print(ans)
    return


if __name__ == '__main__':
    main()



Measured memory_bytes: 68168
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[] dp;
	int MONEY = 1000;
	void run() {
		Scanner sc = new Scanner(System.in);
		dp();
		for(;;) {
			int money = sc.nextInt();
			if(money == 0) break;
			System.out.println(dp[money]);
		}
	}
	
	void dp() {
		dp = new int[MONEY+1];
		int coin[] = {1, 5, 10, 50, 100, 500};
		fill(dp, INF);
		dp[MONEY] = 0;
		for(int i=MONEY;i>=0;i--) for(int j=0;j<coin.length;j++) {
			if( i-coin[j]>0 )
				dp[i-coin[j]] = min(dp[i-coin[j]], dp[i]+1);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
from time import time
from random import randrange
sTime = time()
D = int(input())
C = [int(a) for a in input().split()]
S = [[int(a) for a in input().split()] for _ in range(D)]
A = [0] * D

while time() - sTime < 1.7:
    d = randrange(D)
    i = A[d]
    j = i
    while j == i:
        j = randrange(26)
    t = S[d][j] - S[d][i]
    for k in range(d)[::-1]:
        if A[k] == i:
            prev = k
            break
    else:
        prev = -1
    for k in range(d)[::-1]:
        if A[k] == j:
            new = k
            break
    else:
        new = -1
    t += C[j] * (d - new) - C[i] * (d - prev)
    if t > 0:
        A[d] = j

print(*[a + 1 for a in A], sep = "\n")

Measured memory_bytes: 81636
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

typedef pair<int,int> pii;
typedef pair<int,pii> piii;
piii extgcd(int a,int b){
  int x=1,y=0,x1=0,y1=1,t;
  while(b!=0){
    int q=a/b;
    t=x,x=x1,x1=t-q*x1;
    t=y,y=y1,y1=t-q*y1;
    t=b,b=a-q*b,a=t;
  }
  return a>0?piii(a,pii(x,y)):piii(-a,pii(-x,-y));
}

int main(void){

  int a,b;

  cin >> a >> b;

  piii res=extgcd(a,b);
  cout << res.second.first << " " << res.second.second << endl;

  return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  if ((S.at(2) == S.at(3)) && (S.at(4) == S.at(5))){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <cctype>
#include <cstdio>
#include <vector>
using namespace std;

int main()
{
    int x,a,b;
    cin >> x >> a >> b;
    if(abs(x-a)<abs(x-b)){
        cout << 'A';
    }else{
        cout << 'B';
    }
    
    return 0;
}

Measured memory_bytes: 256