akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

int main(void) {
  int a, b, c, k;
  cin >> a >> b >> k;
  rep(i, k) {
    if (a > b) {
      break;
    }
    cout << a << endl;
    a++;
  }
  c = b - k + 1;
  if (c < a) {
    c = a;
  }
  rep(i, k) {
    if (c > b) {
      break;
    }
    cout << c << endl;
    c++;
  }
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
int solve(int,int);
int n1,a[20];
int main(){
  int n2,b[200],i;
  scanf("%d",&n1);
 
  for(i=0;i<n1;i++) scanf("%d",&a[i]);
 
  scanf("%d",&n2);
 
  for(i=0;i<n2;i++) scanf("%d",&b[i]);

  for(i=0;i<n2;i++){
    if(solve(0,b[i])>=1)  
      printf("yes\n");
    else 
      printf("no\n");
  }return 0;
}

int solve(int i,int m){
  int res;  
  if (m==0)return 1;
  if(i>=n1)return 0;

  res=solve(i+1,m)+solve(i+1,m-a[i]);
  return res;


}

Measured memory_bytes: 580
#include<iostream>
#include<vector>
#include<string>
#include<queue>

const int NOTPARENT = -1;
const int NOTSEARHCH = 0;
const int SEARCHING = 1;
const int SEARCHED = 2;
const int INF = static_cast<int>(1e8);

struct Edge{
    int ToNode;
    int weight;
    Edge(int t, int w) : ToNode(t), weight(w){}
};

bool operator>(const Edge &A, const Edge &B){
    return A.weight > B.weight;
}

std::vector<std::vector<Edge>> graph;


void shortestPath(){
    std::size_t n = graph.size();
    std::vector<int> shortestPathWeight(n, INF);
    std::vector<int> shortestPathParent(n);
    std::vector<int> nodeState(n, NOTSEARHCH);
    std::priority_queue<Edge, std::vector<Edge>, std::greater<Edge>> pq;
    shortestPathWeight[0] = 0;
    pq.push(Edge{0, 0});
    shortestPathParent[0] = NOTPARENT;

    int minWeight;
    int nextNode;
    while(!pq.empty()){
        nextNode = pq.top().ToNode;
        minWeight = pq.top().weight;
        pq.pop();

        nodeState[nextNode] = SEARCHED;
        if(shortestPathWeight[nextNode] < minWeight) continue;

        for(int i = 0; i < graph[nextNode].size(); i++){
            int adjacentNode = graph[nextNode][i].ToNode;
            int adjacentWeight = graph[nextNode][i].weight;
            if(nodeState[adjacentNode] != SEARCHED){
                if(shortestPathWeight[nextNode] + adjacentWeight < shortestPathWeight[adjacentNode]){
                    shortestPathWeight[adjacentNode] = shortestPathWeight[nextNode] + adjacentWeight;
                    nodeState[adjacentNode] = SEARCHING;
                    shortestPathParent[adjacentNode] = nextNode;
                    pq.push(Edge{adjacentNode, shortestPathWeight[adjacentNode]});
                }
            }
        }
    }

    // output
    std::cout << "Yes" << std::endl;
    for(int i = 1; i < n; i++){
        printf("%d\n", shortestPathParent[i] + 1);
    }
}

int main(){
    int n, m;
    std::cin >> n >> m;
    graph.resize(n);
    for(int i = 0; i < m; i++){
        int a, b;
        std::cin >> a >> b;
        a--; b--;
        graph[a].emplace_back(b, 1);
        graph[b].emplace_back(a, 1);
    }

    shortestPath();
    return 0;
}


Measured memory_bytes: 13744
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from copy import deepcopy
def compare(A,B):
    tot_a = sum(A)
    tot_b = sum(B)
    if tot_a > tot_b:
        return A
    if tot_b > tot_a:
        return B
    for i in range(9,0,-1):
        if A[i] > B[i]:
            return A
        elif A[i] < B[i]:
            return B

def main():
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    match = (-1,2,5,5,4,5,6,3,7,6)

    dp = [[0]*10 for _ in range(1 + N)]
    changed = [0] * (N + 1)
    changed[0] = 1
    for i in range(N):
        for j in A:
            if i + 1 - match[j] >= 0 and changed[i + 1 - match[j]]:
                B = deepcopy(dp[i + 1 - match[j]])
                B[j] += 1
                if compare(dp[i + 1],B) == B:
                    dp[i + 1] = B
                    changed[i + 1] = 1
    ans = ''
    for i in range(9,0,-1):
        ans += str(i) * dp[-1][i] 
    print(ans)    
if __name__ == '__main__':
    main()

Measured memory_bytes: 5956
import sys

inp = [int(x) for x in sys.stdin.read().split()]; ii = 0
shift = int(10**9 + 1)
rows, cols, k = inp[ii:ii+3]; ii += 3
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	r, c, v = inp[ii:ii+3]; ii += 3
	items[r].append(c*shift+v)
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for X in Row:
		c, v = X//shift, X%shift
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = v1
		if V < v2:
			V = v2
		if V < v3:
			V = v3
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		c = Row[j]//shift
		if best[c] < dp[j]:
			best[c] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)


Measured memory_bytes: 128724
# frozen_string_literal: true

a, b, k = gets.split.map(&:to_i)
count = 0
100.downto(1) do |i|
#  puts "#{i} #{a % i.to_f} #{b % i.to_f}"
  count += 1 if a % i == 0 && b % i == 0
  if count == k
    puts i
    exit
  end
end


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

#define REP(i, m, n) for (int i = (m); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define reps(i, n) for (int i = 0; i <= (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
typedef long long ll;
typedef pair<int, int> P;
const int inf = INT_MAX;
const ll INF = 1LL << 60;
const ll mod = 1e9 + 7;
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; }

int dp[101010];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    fill(dp, dp+N, inf);
    dp[0] = 0;
    vector<int> h(N);
    rep(i, N) cin >> h[i];
    rep(i, N) {
        chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
        chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define ll long long int
#define PI 3.141592653589793
using namespace std;

int main() {
    int N, L;

    cin >> N >> L;
    vector<string> S(N);
    REP(i,N) cin >> S[i];
    sort(ALL(S));

    REP(i,N) cout << S[i];
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
A,B,C=map(int,input().split())
K=int(input())

for i in range(0,K+1):
    for j in range(0,K+1-i):
        for k in range(0,K+1-i-j):
            #print('{},{},{}'.format(i,j,k))
            if(A*(2**i) < B*(2**j) and B*(2**j) < C*(2**k)):

                print('Yes')
                exit()

print('No')


Measured memory_bytes: 61864
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();

        if (x < 1200) {
            System.out.println("ABC");
        } else {
            System.out.println("ARC");
        }


    }
}

Measured memory_bytes: 9680
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int n = Integer.parseInt(sc.next());
    int d = Integer.parseInt(sc.next());
    
    int x[][] = new int[n][d];
    int dis = 0;
    int ans = 0;
    
    for (int i=0; i<n; i++){
      for (int j=0; j<d; j++){
        x[i][j] = Integer.parseInt(sc.next());
      }
    }

    for (int i=0; i<n; i++){
      for (int j=i+1; j<n; j++){
        dis = 0;
          
        for (int k=0; k<d; k++){
          dis += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
        }
        for (int a=1; a<=Math.sqrt(dis); a++) {
       	  if (dis == a*a) ans++;
        }
        
      }
    }
    
    System.out.println(ans);

  }
}


Measured memory_bytes: 21588
fun main(args: Array<String>) {
    val (n, k) = readLine()?.split(" ")?.map(String::toLong) ?: return
    val a = readLine()?.split(" ")?.map(String::toInt) ?: return
    val m = (1e9.toLong() + 7L)
    var t = 0L
    val k1 = ((k + 1) * ((k) / 2) + if (((k) % 2L) == 0L) {
        0
    } else {
        (k + 1) / 2
    }) % m
    val k2 = ((k) * ((k - 1) / 2) + if (((k - 1) % 2L) == 0L) {
        0
    } else {
        k / 2
    }) % m

    0.until(n.toInt()).forEach { i ->
        var f = 0L
        var s = 0L
        0.until(n.toInt()).forEach { j ->
            if (a[i] > a[j]) {
                if (i > j) {
                    s++
                } else {
                    f++
                }
            }
        }
        t = (t + (f * k1)) % m
        t = (t + (s * k2)) % m
    }
    println(t.toString())
}


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

//________
typedef long long ll;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
typedef vector<Pii> Vp;
#define pb push_back
#define fi first
#define se second
#define mkp make_pair
#define All(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define show(x) cerr << #x << ':' << x << endl
#define outl(x) cout << x << '\n';

#define INF (1 << 29)

#define FAST cin.tie(0), ios::sync_with_stdio(false)
inline int chmax(int &a, int b){return b>a ? a=b,1 : 0;}
inline int chmin(int &a, int b){return b<a ? a=b,1 : 0;}
//________


int a[6];
int add[5];


main(){
	char s[6];
	scanf("%s",s);
	for(int i=0; i<4; ++i){
		a[i] = s[i]-'0';
	}
	int p;

	bool t[8][3] = { {1,1,1}, {1,1,0}, {1,0,1}, {1,0,0},
		{0,1,1}, {0,1,0}, {0,0,1}, {0,0,0}};

	if     (a[0] + a[1] + a[2] + a[3] == 7)p = 0;
	else if(a[0] + a[1] + a[2] - a[3] == 7)p = 1;

	else if(a[0] + a[1] - a[2] + a[3] == 7)p = 2;
	else if(a[0] + a[1] - a[2] - a[3] == 7)p = 3;

	else if(a[0] - a[1] + a[2] + a[3] == 7)p = 4;
	else if(a[0] - a[1] + a[2] - a[3] == 7)p = 5;

	else if(a[0] - a[1] - a[2] + a[3] == 7)p = 6;
	else if(a[0] - a[1] - a[2] - a[3] == 7)p = 7;

	rep(i,3){
		printf("%d%c", a[i], t[p][i] ? '+' :'-');
	}
	printf("%d=7\n", a[3]);
}


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

namespace AtCoder
{
    class Program
    {
        static char[,] a;
        static char[,] b;

        static void Main(string[] args)
        {
            //[summary]B - Template Matching
            var line = ReadLine();
            int n = line[0];
            int m = line[1];

            a = GetPicture(n);
            b = GetPicture(m);

            for(int i = 0; i <= n - m; i++)
            {
                for(int j = 0; j <= n - m; j++)
                {
                    if (IsMatch(i, j))
                    {
                        Console.WriteLine("Yes");
                        return;
                    }
                }
            }

            Console.WriteLine("No");
        }

        static bool IsMatch(int y, int x)
        {
            int m = b.GetLength(0);

            for(int i = 0; i < m; i++)
            {
                for(int j = 0; j < m; j++)
                {
                    if (a[y + i, x + j] != b[i, j])
                    {
                        return false;
                    }
                }
            }

            return true;
        }

        static char[,] GetPicture(int n)
        {
            var picture = new char[n, n];

            for(int i = 0; i < n; i++)
            {
                var s = Console.ReadLine();

                for(int j = 0; j < n; j++)
                {
                    picture[i, j] = s[j];
                }
            }

            return picture;
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int left;
    if(a > b && a > c){
      left = a;
      if(left == b+c){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
    else if(b > a && b > c){
      left = b;
      if(left == a+c){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
    else{
      left = c;
      if(left == a+b){
        System.out.println("Yes");
      }
      else{
        System.out.println("No");
      }
    }
  }
}


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
int main(){
  int s;
  cin>>s;
  int a=s/100;
  int b=s%100;
  bool c,d;
  c=a>0&&a<=12;
  d=b>0&&b<=12;
  if(c&&d)cout<<"AMBIGUOUS"<<endl;
  if(c&&!d)cout<<"MMYY"<<endl;
  if(!c&&d)cout<<"YYMM"<<endl;
  if(!c&&!d)cout<<"NA"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    string s; cin >> s;

    vector<int> sum(n);

    int cnt = 0;
    sum[0] = 0;

    rep(i,n-1){
        if(s[i] == 'A' && s[i+1] == 'C'){
            cnt++;
        }
        sum[i+1] = cnt;
    }

    rep(i,q){
        int l, r; cin >> l >> r;
        l--; r--;

        cout << sum[r] - sum[l] << endl;

    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18L+5;
int main(){
    int N,W;
    scanf("%d%d",&N,&W);
    vector<int> w(N+1),v(N+1);
    int sum_value=0;
    for(int i=1;i<=N;++i){
        scanf("%d%d",&w[i],&v[i]);
        sum_value+=v[i];
    }
    vector<ll> dp(sum_value+1,INF);
    dp[0]=0;
    for(int i=1;i<=N;++i){
        for(int value=sum_value;value>=v[i];value--){
            dp[value]=min(dp[value],dp[value-v[i]]+w[i]);
        }
    }
    int ans;
    for(int i=1;i<=sum_value;++i){
        if(dp[i]<=W)
            ans=i;
    }
    printf("%d\n",ans);
    // while(1);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int x[200][200];
int ans=0;
int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<b;j++)
		{
			cin>>x[i][j];
		}
	}
	for(int i=1;i<=a;i++)
	{
		int y=0;
		int z=0;
		int res=0;
		for(int j=0;j<b;j++)
		{
			res=res+x[i][j]*x[y][z];
			z++;
		}
		if(res+c>0)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
  ll a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if(not(e-a>k))cout<<"Yay!"<<endl;
  else cout<<":("<<endl;
    return 0;
}



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

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int X,Y,Z; cin >> X >> Y >> Z;
    int ans = 0;

    X -= 2 * Z;
    if(X>=Y){
        ans++;
        X-=Y;
    }

    if(X> 0) ans += X/(Y+Z);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
p = list(map(int, input().split()))
e = lambda x: 0.5*(x+1)
if k == 1:
    res = e(max(p))
else:
    s = [0]
    s[0] = sum(p[:k])
    for i in range(1, n-k+1):
        s.append(s[i-1] - p[i-1] + p[i+k-1])
    idx = s.index(max(s))
    res = sum([e(p[i]) for i in range(idx, idx+k)])
print(res)

Measured memory_bytes: 32008
#include <cstdio>
#include <array>
#include <algorithm>

int main()
{
    int n;
    std::array<int, 200005> a;
    std::array<int, 200005> b;

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

    std::copy(a.begin(), a.begin()+n, b.begin());
    std::sort(b.begin(), b.begin()+n);

    int mid = n / 2 - 1;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] <= b[mid])
        {
            printf("%d\n", b[mid+1]);
        }
        else
        {
            printf("%d\n", b[mid]);
        }
    }
    return 0;
}

Measured memory_bytes: 3712
/*
 * Lang  : C++ 17
 * Author: little_angel
 * Date  : 04-07-2020 10:40 04
 */

#include<bits/stdc++.h>

using namespace std;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int n;
    string s;
    cin >> n;
    map<string, int> m;
    while (n--) {
        cin >> s;
        m[s]++;
    }


    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3672
#include<bits/stdc++.h>
#include<iomanip>
#include<numeric>

using namespace std;
using ll = long long;
constexpr int mo = 1000000007;
constexpr int  mod = mo;
constexpr ll inf = 1ll<<62;

int main(){
    int n,m;
    cin>>n>>m;
    vector<int> s(n),t(m);
    for(auto &a : s) cin>>a;
    for(auto & a : t) cin>>a;
    vector<vector<ll>> dp(n+1,vector<ll>(m+1));
    vector<vector<ll>> sum(n+1,vector<ll>(m+1));
    for(int i=0;i<n;++i)for(int j=0;j<m;++j)if(i == 0 or j ==0)sum[i][j] = 1ll;
    ll ret = 1ll;
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            if(s[i] == t[j]){
                dp[i+1][j+1] = (sum[i][j])%mo;
                (ret += dp[i+1][j+1])%=mo;
            }
            sum[i+1][j+1] = (sum[i][j+1] + sum[i+1][j] +mo - sum[i][j] + dp[i+1][j+1])%mo;
        }
    }
    cout << ret << endl;
    return 0;
}



Measured memory_bytes: 62976
#include <bits/stdc++.h>
#define N 20006
#define fi first
#define se second
using namespace std;
typedef pair<int,int> qwq;
struct arr{int i,flag,x;}b[N];
bool operator<(arr x,arr y)
{
	return x.x<y.x;
}
int n,h,t,ans,cnt,fx[N],q[N],id[N][2];qwq a[N];bool ok;
void judge(int p,int d,int flag)
{
	h=0;t=1;q[t]=p;fx[p]=flag;
	while(h<t){
		int x=q[++h],y=id[x][fx[x]];
		for(int i=y-1;i;i--){
			
			if(b[i].x<=b[y].x-d)break;
			int z=b[i].i;
			if(fx[z]==-1){
				fx[z]=b[i].flag^1;
				q[++t]=z; 
			}else if(fx[z]==b[i].flag){
				ok=0;return;
			}
		}
		for(int i=y+1;i<=cnt;i++){
			if(b[i].x>=b[y].x+d)break;
			int z=b[i].i;
			if(fx[z]==-1){
				fx[z]=b[i].flag^1;
				q[++t]=z;
			}else if(fx[z]==b[i].flag){
				ok=0;return;
			}
		}
	}
}
inline bool pd(int w)
{
	int d=0,tot=0;
	for(int i=1;i<=cnt;i++)
		if(b[i].x>=d)d=b[i].x+w,tot++;
	if(tot<n)return 0;
	memset(fx,-1,sizeof fx);
	for(int i=1;i<=n;i++)if(fx[i]==-1){
		ok=1;judge(i,w,0);
		if(!ok){
			for(int j=1;j<=t;j++)fx[q[j]]=-1;
			ok=1,judge(i,w,1);
			if(!ok)return 0;
		}
	}
	return 1;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&a[i].fi,&a[i].se);
		if(a[i].fi>a[i].se)swap(a[i].fi,a[i].se);
		b[++cnt]=arr{i,0,a[i].fi};
		b[++cnt]=arr{i,1,a[i].se};
	}
	sort(b+1,b+cnt+1);
	for(int i=1;i<=cnt;i++)id[b[i].i][b[i].flag]=i;
	int l=0,r=1000000000;
	while(l<=r){
		int mid=(l+r)>>1;
		if(pd(mid))ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%d",ans);
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int acs(const void *a, const void *b) { 
  return *(int*)a - *(int*)b;
} /* 1,2,3,4.. */
int des(const void *a, const void *b) {
  return *(int*)b - *(int*)a;
} /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { 
  return *(char*)a - *(char*)b;
} /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) {
  return strcmp(*(const char **)a, *(const char **)b);
} /* aaa,aab.. */
#define min(a,b) (a < b ? a : b)
#define max(a,b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007
#define INF 1000000009
typedef long long int lli;

int main(void) {
  int x;
  scanf("%d", &x);

  int ans = x / 500 * 1000;
  ans += (x % 500) / 5 * 5;
  printf("%d\n", ans);
  return 0;
}


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

int main() {
  int n, y;
  cin >> n >> y;
  int max = y / 1000;

  if(max < n) {
    cout << -1 << " " << -1 << " " << -1 << endl;
  } else {
    int tenThou = -1;
    int fiveThou = -1;
    int thou = -1;
    for(int i=0;max-9*i-n>=0&&i<=n;i++) {
      int remainder = (max-9*i-n) % 4;
      int j = (max-9*i-n) / 4;
      if(remainder==0&&n-i-j>=0) {
        tenThou = i;
        fiveThou = j;
        thou = n-i-j;
      }
    }
    cout << tenThou << " " << fiveThou << " " << thou << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAX=702;
int N,M,conn[MAX][MAX],chk[MAX],c[MAX];
vector<int> val;
bitset<2*MAX> dp;
int f(int x,int y){
    int t=1;
    if(chk[x]==0){
        chk[x]=y; c[y]++;
        for(int i=1;i<=N;i++) if(!conn[x][i]&&x!=i) t=t&f(i,3-y);
        return t;
    }
    if(chk[x]==y) return 1;
    return 0;
}
int main(){
    scanf("%d%d",&N,&M);
    for(int i=0;i<M;i++){
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        conn[t1][t2]=1; conn[t2][t1]=1;
    }
    for(int i=1;i<=N;i++) if(chk[i]==0){
        c[1]=0,c[2]=0;
        if(!f(i,1)){
            printf("-1\n");
            return 0;
        }
        val.push_back(abs(c[1]-c[2]));
    }
    dp[N]=1;
    for(int i=0;i<val.size();i++){
        dp=(dp<<val[i])|(dp>>val[i]);
    }
    for(int i=0;;i++){
        if(dp[i+N]){
            printf("%d\n",((N-i)/2)*((N-i)/2-1)/2+((N+i)/2)*((N+i)/2-1)/2);
            return 0;
        }
    }
}


Measured memory_bytes: 2176
N, M = map(int, input().split())
dict = [0 for _ in range(N + 1)]
for _ in range(M):
    a, b = map(int, input().split())
    dict[a] += 1
    dict[b] += 1

ans = 'YES'
for i in range(1, N + 1):
    if dict[i] % 2 == 1:
        ans = 'NO'
        break
print(ans)

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

using namespace std;

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

    if(a + b > c + d)
        printf("Left\n");
    else if (a + b < c +d)
        printf("Right\n");
    else
        printf("Balanced\n");

    return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1ll<<60;
struct grid{ll to; ll cost;};

using Graph = vector<vector<grid>>;
using P = pair<ll, ll>;

int main(int argc, char **argv)
{
	ll V, E, start; cin >> V >> E >> start;

	Graph G(V);
	for (ll i = 0; i < E; ++i)
	{
		ll s, t, d; cin >> s >> t >> d;
		G[s].push_back(grid{t, d});
	}

	priority_queue<P, vector<P>, greater<P>> que;
	que.push(P(0, start));
	vector<ll> dist(V, INF);
	dist[start] = 0;

	while (!que.empty())
	{
		P p = que.top(); que.pop();
		ll now = p.second;
		if (dist[now] < p.first) continue;

		for (auto &nv : G[now])
		{
			if (dist[nv.to] > dist[now] + nv.cost)
			{
				dist[nv.to] = dist[now] + nv.cost;
				que.push(P(dist[nv.to], nv.to));
			}
		}
			
	}
	for (auto &nv : dist)
	{
		if (nv == INF)
			std::cout << "INF" << std::endl;
		else
			std::cout << nv << std::endl;
	}
}


Measured memory_bytes: 19412
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;
using ull = unsigned long long;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int ans = 0;
    for (int a = 0; a <= A; ++a) {
        for (int b = 0; b <= B; ++b) {
            for (int c = 0; c <= C; ++c) {
                if (500 * a + 100 * b + 50 * c == X) {
                    ++ans;
                }
            }
        }
    }
    cout << ans << endl;
}


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

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[3 * n];
		for (int i = 0; i < array.length; i++) array[i] = sc.nextInt();
		Arrays.sort(array);
		int head = array.length - 2;
		long res = 0;
		for (int i = 0; i < n; i++) {
			res += array[head];
			head -= 2;
		}
		System.out.println(res);
	}

}


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


int main()
{
	int d,i;
	long sum;
	while( cin >> d ) {
		sum = 0;
		for( i = 0; i < 600; i += d ) {		
			sum += d * i * i;
		}
		printf("%d\n",sum);

	}
		

	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int MN = 1e5+3;
bool insub[MN];
int lca[MN], d[MN],t;
vector<int> adj[MN];
int ans=0;
void ree (int cur, int p = -1) {
	for (int i : adj[cur]) if (i != p) {
		d[i] = d[cur] + 1;
		ree(i,cur);
		insub[cur] |= insub[i];
	}
}
void dfs (int cur, int p = -1, int l = -1) {
	bool leaf = 1;
	for (int i : adj[cur]) if (i != p) {
		leaf = 0;
		if (insub[i]) dfs(i,cur);
		else dfs(i,cur,~l?l:cur);  
	}
	if (cur == t) l = t;
	if (leaf && d[t]-d[l] < d[l]) {
		int arrival = d[t]+d[cur]-(d[l]<<1);
		ans = max(ans,d[cur]-1);
	}
}
int main () {
	int n,a;
	scanf ("%d %d %d",&n,&t,&a);
	for (int i = 1; i < n; i++) {
		int b,c;
		scanf ("%d %d",&b,&c);
		adj[b].push_back(c);
		adj[c].push_back(b);
	}
	insub[t] = 1;
	ree(a);
	dfs(a);
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 12672
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    string s;
    while(getline(cin, s)){
        vector<int> v{0};
        for (auto &&i : s) {
            if(i == ' ') v.emplace_back(0);
            else v.back() = v.back()*10+i-'0';
        }
        int W = v.front();
        int n = v.size()-1;
        vector<int> A(v.begin()+1,v.end());
        auto dp = make_v(n, 1 << n, 1e12);
        for (int i = 0; i < n; ++i) {
            dp[i][1 << i] = A[i];
        }
        for (int j = 0; j < (1 << n); ++j) {
            for (int i = 0; i < n; ++i) {
                for (int k = 0; k < n; ++k) {
                    if(!(j & (1 << k))){
                        chmin(dp[k][j^(1 << k)], dp[i][j]+2*sqrt(A[i]*A[k]));
                    }
                }
            }
        }
        int ok = 0;
        for (int i = 0; i < n; ++i) {
            if(dp[i].back()+A[i] <= W+1e-10) ok = 1;
        }
        puts(ok ? "OK" : "NA");
    }
    return 0;
}


Measured memory_bytes: 3384
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

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

    int n, m;
    cin >> n >> m;
    vector<vs32> g(3 * n);
    int s, t;
    rep (i, m)
    {
        cin >> s >> t;
        --s; --t;
        g[s].push_back(t + n);
        g[s + n].push_back(t + 2 * n);
        g[s + 2 * n].push_back(t);
    }

    cin >> s >> t;
    --s; --t;
    vs32 d(3 * n, 1e9);
    queue<int> q;
    q.push(s);
    d[s] = 0;
    while (!q.empty())
    {
        int u = q.front(); q.pop();
        for (auto v : g[u])
        {
            if (d[v] > d[u] + 1)
            {
                d[v] = d[u] + 1;
                q.push(v);
            }
        }
    }


    int ans = (d[t] == 1e9 ? -1 : d[t] / 3);

    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 17920
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long
#define pb push_back
map<ll,ll>mp;

int main(){
    fast;
    ll t,s,i,e,o=0,n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;
//using static System.Globalization.CultureInfo;

class Program
{
    static void Main(string[] args)
    {
        var nx = Add.ar;
        var xs = Add.ar;
        xs = xs.Select(v => Abs(v - nx[1])).ToArray();
        var gcd = xs[0];
        for (var i = 1; i < nx[0]; i++)
            gcd = Calculation.GCD(gcd, xs[i]);
        WriteLine(gcd);
    }
}

public class Add
{
    public static string read => ReadLine();
    public  static int[] ar => Array.ConvertAll(read.Split(' '), int.Parse);
    public  static int num => ToInt32(read);
    public  static long[] arL => Array.ConvertAll(read.Split(' '), long.Parse);
    public  static long numL => ToInt64(read);
    public  const string Alfa = "abcdefghijklmnopqrstuvwxyz";
    public  const int MOD = 1000000007;
}

public class Calculation
{
    public static int LCM(int num1, int num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static long LCM(long num1, long num2)
    {
        return num1 / GCD(num1, num2) * num2;
    }

    public static int GCD(int num1, int num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }

    public static long GCD(long num1, long num2)
    {
        return num1 < num2 ? GCD(num2, num1) :
            num2 > 0 ? GCD(num2, num1 % num2) : num1;
    }
}


Measured memory_bytes: 20064
using namespace std;
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <bitset>
#include <iterator>
#include <set> 
#include <unordered_set>
#include <string>
#include <functional>
#include <limits.h>
//#include <bits/stdc++.h> 
//#include <list>
#include <stack>
#include <stdio.h>
typedef signed long long ll; //watch out ll= int*int will not become ll, rather (ll)ini*int casting will work
#include <queue>
#include <math.h>
#include <deque>
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
//typedef long float lf;
#include <cmath>
#include <iomanip>
#include <numeric>
#include <stdio.h>
const long double PI = 3.141592653589793238L;
/*struct CustomCompare
{
	bool operator()(pii& p1, pii& p2)
	{
		if (p1.second - p1.first == p2.second - p2.first)
			return p1.first > p2.first;

		return p1.second - p1.first < p2.second - p2.first;
	}
};*/
int tt, n, k, inp, a, b, x,m;
void pv(vector<int> a) {
	for (auto i : a)
		cout << i<< ' ';
	cout << '\n';
}
void pp (vector<pair<int, int>> a) {
	for (auto i : a)
		cout << i.first << ' ' << i.second<<'\n';
}
double solve(tuple<int, int, int> s,
	map <tuple <int, int, int>, double> &memo) {
	//cout << get<0>(s) << ' '<< get<1>(s) << ' '<< get<2>(s);
	//cout << endl;
	if (memo.find(s) == memo.end()) {
		int i = get<0>(s);
		int j = get<1>(s);
		int k = get<2>(s);
		
		//cout << "FIRST";
		double ans = 0;
		if (k>0)
		ans +=(double) k / n * (1 + solve({ i,j + 1,k-1 }, memo));
		
		
		//cout << "SECOND";
		if (j>0)
		ans += (double)  j / n * (1 + solve({ i + 1,j-1,k }, memo));
		
		
		//cout << "THIRD";
		if (i>0)
		ans += (double)     i / n * (1 + solve({ i-1,j,k }, memo));
		
		//cout << "FOURTH";
		ans = (double) n / ((double)i + j + k) * (ans + (double)((double)n - i - j - k) / n);
		
		//cout << "ANS " << ans << '\n';
		memo.insert({ s, ans });
		return ans;
	}
	else
		return memo.find(s)->second;

}
int main() {
	//vector<int> x = { 2,1,0 };
	cin >> n; cin >> k;
	vector<int> a(n); int minn = 999999;
	for (int i = 0; i < n; i++) {
		cin >> a[i]; minn = min(a[i], minn);
	}
	//cout << minn;
	vector<int> dp(k+1, 0);
	for (int i = 0; i < minn; i++) {
		dp[i] = 0;
	}
	//cout << "YY";
	int cur = 0;
	//pv(dp);
	while (cur < k + 1) {
		for (auto i : a) {
			if (cur + i < k + 1 && dp[cur+i]!=1)
				dp[cur + i] = !dp[cur];
		}
		//pv(dp);
		cur++;}
	if (dp[cur-1] == 1)
		cout << "First";
	else
		cout << "Second";

}


/*
tuple <int, int, int> s = {0,0,0};
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] == 1)
			get<0>(s)++;
		else if (a[i]==2)
			get<1>(s)++;
		else if (a[i] == 3)
			get<2>(s)++;

	}
	map <tuple <int, int, int>, double> memo;
	memo.insert({ {0,0,0},0.0 });
	cout << std::setprecision(11)<<solve(s, memo);
}*/

Measured memory_bytes: 3764
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
 
typedef struct{
    long long int code;
    int steps;
} puzz;
 
int q[1000000][14],size[500000];
long long int FR,TO,SW;
puzz* hash[500000][5];
 
void swap (int* x,int* y){
    int z;
    z=*x;
    *x=*y;
    *y=z;
}
 
long long int convert(int a[]){
    long long int ret=0;
    int i;
    for(i=0;i<13;i++)ret=ret*13+a[i];
    return ret;
}
 
void hashadd(long long int code,int step){
    int ccc=code%499999;
    puzz* ppp=(puzz*)malloc(sizeof(puzz));
    ppp->code=code;
    ppp->steps=step;
    if(size[ccc]>4){fprintf(stderr,"SIZE OVER!! (%d)\n",ccc);return;}
    hash[ccc][size[ccc]]=ppp;
    size[ccc]++;
}
 
int hashsearch(long long int code){
    int ccc=code%499999;
    int i=size[ccc]-1;
    for(;i>=0;i--){
        if(hash[ccc][i]->code==code)return hash[ccc][i]->steps;
    }
    return -1;
}
 
void mark(int x,int y){
    int k;
    long long int cd;
 
    swap(&q[FR][x],&q[FR][y]);
    cd=convert(q[FR]);
 
    if(SW==1 || hashsearch(cd)<0){
        for(k=0;k<14;k++){q[TO][k]=q[FR][k];}
        q[TO][13]++;
        if(SW==0)hashadd(cd,q[TO][13]);
        TO++;
    }
 
    swap(&q[FR][x],&q[FR][y]);
 
}
 
void check(){
    if(q[FR][0]==0){mark(0,2);}
    if(q[FR][1]==0){mark(1,2);mark(1,5);}
    if(q[FR][2]==0){mark(2,0);mark(2,1);mark(2,3);mark(2,6);}
    if(q[FR][3]==0){mark(3,2);mark(3,7);}
    if(q[FR][4]==0){mark(4,5);}
    if(q[FR][5]==0){mark(5,1);mark(5,4);mark(5,6);mark(5,9);}
    if(q[FR][6]==0){mark(6,2);mark(6,5);mark(6,7);mark(6,10);}
    if(q[FR][7]==0){mark(7,3);mark(7,6);mark(7,8);mark(7,11);}
    if(q[FR][8]==0){mark(8,7);}
    if(q[FR][9]==0){mark(9,5);mark(9,10);}
    if(q[FR][10]==0){mark(10,6);mark(10,9);mark(10,11);mark(10,12);}
    if(q[FR][11]==0){mark(11,7);mark(11,10);}
    if(q[FR][12]==0){mark(12,10);}
}
 
 
int main(){
    int i,ans;
    long long int cd;
 
    for(i=1;i<12;i++)q[0][i]=i;
    q[0][0]=0;q[0][12]=0;q[0][13]=0;
    hashadd(convert(q[0]),0);
 
    FR=0;TO=1;SW=0;
 
    while(FR<TO && q[FR][13]<=13){
        check();
        FR++;
    }

    while(scanf("%d",&q[0][0])*q[0][0]>=0){
        for(i=1;i<13;i++)scanf("%d",&q[0][i]);
        q[0][13]=0;FR=0;TO=1;SW=1;ans=9999;
 
        while(FR<TO){
            cd=hashsearch(convert(q[FR]));
            if(cd>=0){
                ans=(int)cd+q[FR][13];
                break;
            }
            if(q[FR][13]<6)check();
            FR++;
        }
 
        if(ans>20)printf("NA\n"); else printf("%d\n",ans);
    }
 
    return 0;
}

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

using namespace std;

const long long MOD = 1000000007LL;
const int MSTATE = 1 << 21;
int n, adj[21];
long long dp[MSTATE];

long long helper(int pos, int state){

    if(pos == n)
        return 1;

    if(dp[state] != -1)
        return dp[state];

    long long tot = 0;

    int possible = (state ^ adj[pos]) & adj[pos];
    for(;possible; possible &= possible - 1)
        tot = (tot + helper(pos + 1, state | (possible & -possible))) % MOD;

    dp[state] = tot;

    return tot;

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;

    for(int i = (1 << n) - 1; i >= 0; --i)
        dp[i] = -1;

    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j){
            int k; cin >> k;
            if(k == 0) continue;
            adj[i] |= 1 << j;
        }
    }

    cout << helper(0, 0) << "\n";

    return 0;
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long n,res = 0;
  cin>>n;
  for(int i=1;i<=n;i++)
  {
    if((i%3 && i%5))
    {
      
      res+=i;
    }
  }
  cout<<res;
  
  return 0;
}

Measured memory_bytes: 3632
#!/usr/bin/env python
N = raw_input()
A =raw_input().split()
print ' '.join(map(str, A)) 
A = map(int, A)

for i in range(1,len(A)):
    v = A[i]
    j = i - 1 
    while j >= 0 and A[j] > v:
        A[j + 1] =A[j]
        j = j - 1 
    A[j+1] = v 
    print ' '.join(map(str,A))

Measured memory_bytes: 6448
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    int sum = 0;
    rep(i, n) {
        if (h[i] >= k) {
            sum += 1;
        }
    }
    put(sum)
    
    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

ll xor_under_n_odd(ll n) { return (n + 1) / 2 % 2; }
ll xor_under_n(ll n) {
  if (n % 2 == 1) {
    return xor_under_n_odd(n);
  } else {
    return xor_under_n_odd(n + 1) ^ (n + 1);
  }
}

int main() {
  ll a, b;
  cin >> a >> b;
  cout << (xor_under_n(a - 1) ^ xor_under_n(b)) << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int K = 20;
const int KM = 1 << (K - 1);
int dat[1 << K];
int laz[1 << K];
int zero = 2e9;

void eval(int A, int l, int r) {
	if (laz[A] == zero) return;
	if (A * 2 < 1 << K) {
		laz[A * 2] = min(laz[A * 2], laz[A]);
		laz[A * 2 + 1] = min(laz[A * 2 + 1] , laz[A]);
	}
	dat[A] = min(dat[A], laz[A]);
	laz[A] = zero;
}

int update(int L, int R, int X, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return dat[A];
	if (L <= l && r <= R) {
		laz[A] = min(laz[A], X);
		return min(dat[A], laz[A]);
	}
	dat[A] = min(update(L, R, X, A * 2, l, (l + r) / 2), update(L, R, X, A * 2 + 1, (l + r) / 2, r));
	return dat[A];
}

void add(int L, int R, int X) {
	update(L, R, X, 1, 0, KM);
}

int check(int L, int R, int A, int l, int r) {
	eval(A, l, r);
	if (r <= L || R <= l) return zero;
	if (L <= l && r <= R) return dat[A];
	return min(check(L, R, A * 2, l, (l + r) / 2), check(L, R, A * 2 + 1, (l + r) / 2, r));
}

int query(int L, int R) {
	return check(L, R, 1, 0, KM);
}

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


	int N, Q;
	cin >> N >> Q;
	pair<int, pair<int, int>> XST[200000];
	rep(i, N) {
		int S, T, X;
		cin >> S >> T >> X;
		XST[i] = mp(X, mp(S, T));
	}
	sort(XST, XST + N);
	int D[200002];
	D[0] = 0;
	D[Q + 1] = zero;
	rep1(i, Q) cin >> D[i];
	rep(i, 1 << K) {
		dat[i] = zero;
		laz[i] = zero;
	}

	rep(i, N) {

		int L = 0, R = Q + 1;
		while (L + 1 < R) {
			int H = (L + R) / 2;
			if (D[H] + XST[i].first >= XST[i].second.first) R = H;
			else L = H;
		}
		int L2 = 0, R2 = Q + 1;
		while (L2 + 1 < R2) {
			int H = (L2 + R2) / 2;
			if (D[H] + XST[i].first >= XST[i].second.second) R2 = H;
			else L2 = H;
		}

		if (R <= L2) {
			add(R, L2 + 1, XST[i].first);
		}

	}

	rep1(i, Q) {
		int kari = query(i, i + 1);
		if (kari == zero) co(-1);
		else co(kari);
	}

	Would you please return 0;
}

Measured memory_bytes: 13184
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int n;
Vl va, ans;

void init()
{
	cin >> n;
	va.resize(n);
	ans.resize(n, 0);
	REP(i, n)
		cin >> va[i];
}


int main()
{
	init();

	ll all = 0;
	REP(i, n)
		all += va[i];
	
	ll exceptLast = 0;
	for (int i = 0; i < n / 2; ++i)
		exceptLast += va[i * 2];
	exceptLast *= 2;

	ans[n - 1] = all - exceptLast;

	for (int i = n - 2; i >= 0; --i)
		ans[i] = (va[i] - ans[i + 1] / 2) * 2;

	REP(i, n)
		cout << ans[i] << " ";
	cout << endl;

}


Measured memory_bytes: 2944
S = input().rstrip()
if int(S[:4]) >=2020:
    print("TBD")
    exit()
elif int(S[:4]) ==2019:
    if int(S[5:7]) >= 5:
        print("TBD")
        exit()
    elif int(S[5:7]) >= 4:
        if int(S[8:]) >= 31:
            print("TBD")
            exit()
print("Heisei")

Measured memory_bytes: 61768
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<29 //使いやすい無限

int main(){
  int N;cin>>N;
  vector<int>wsum(N);
  cin>>wsum[0];
  for(int i=1; i<N; i++){
    int w;cin>>w;
    wsum[i] = wsum[i-1] + w;
  }
  int ans = INF;
  for(int i=0; i<N; i++){
    ans = min(ans, abs(wsum[N-1]-wsum[i]-wsum[i]));
  }

  cout<<ans<<endl;
}

Measured memory_bytes: 256
S = input()
g = []
k = []
for i in range(len(S)):
  if i%2 == 0:
    k.append(S[i]) # 奇数個め
  else:
    g.append(S[i]) # 偶数個め

print(min(k.count('0') + g.count('1'), g.count('0') + k.count('1')))

Measured memory_bytes: 47216
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

vector<int> v[200010];
ll ans[200010];
int sum[200010];
int n,q;
bool seen[200020];

void dfs(int now,int from){
  seen[now]=true;
  if(from>=0)ans[now]=ans[from];
  ans[now]+=sum[now];
  rep(i,v[now].size()){
    if(!seen[v[now][i]])dfs(v[now][i],now);
  }
}



int main(){
  cin >> n >> q;
  rep(i,n-1){
    int x,y;
    cin >> x >> y;
    x--,y--;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  rep(i,q){
    int x,y;
    cin >> x >> y;
    x--;
    sum[x]+=y;
  }
  dfs(0,-1);
  rep(i,n)cout << ans[i] << ' ';
  cout << endl;
return 0;}

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

int main(){
    int a,b,cnt = 0,outlet = 1;
    cin >> a >> b;
    if(b == 1){
        cout << 0 << endl;
        exit(0);
        }
    while(outlet <= b){
        cnt++;
        if(cnt == 1)outlet += a;
        else{
            outlet += a-1;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
 
N, Q = map(int, input().split())
graph = [[] for i in range(N)]
cnt = [0]*N

# 入力しながらグラフを作成
for i in range(N-1):
  a, b = map(int, input().split())
  a, b = a-1, b-1
  graph[a].append(b)
  graph[b].append(a)

# 初期値を設定
for i in range(Q):
  p, x = map(int, input().split())
  cnt[p-1] += x

v = [False]*N

# stack=[]
def dfs(n,prv):
  # stack.append(n)
  if v[n]: return
  cnt[n] += prv
  v[n] = True
  for nv in graph[n]:
    dfs(nv, cnt[n])
   
dfs(0,0)
print(*cnt)
# print(stack)

Measured memory_bytes: 223584
import sys
import fractions
input=sys.stdin.readline

a = list(map(int, input().split()))

k = 0
while True:
    if a[0] == a[1] == a[2]:
        break
    a.sort()
    if a[1] == a[2]:
        a[0] += 2
        k += 1
    else:
        a[0] += 1
        a[1] += 1
        k += 1
print(k)

Measured memory_bytes: 5304
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    string s;cin>>s;
    int n=s.size();
    vector<int> v[26];
    rep(i,0,n){
        v[s[i]-'a'].push_back(i);
    }
    rep(i,0,26){
        if(v[i].size()<=1)continue;
        rep(j,1,v[i].size()){
            if(v[i][j]-v[i][j-1]<=2){
                cout<<v[i][j-1]+1<<" "<<v[i][j]+1<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<endl;
}


Measured memory_bytes: 1104