akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define srt(x) sort((x).begin(), (x).end());
#define rsrt(x) sort((x).rbegin(), (x).rend());
#define deb(x) cout<<#x<<" = "<<(x)<<" (L"<<LINE<<")"<<endl;
#define vdeb(x) {cout<<#x<<" = { "; rep(i, x.size()) cout<<x[i]<<' '; cout <<'}'<<" (L"<<LINE<<")"<<endl;}
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vivi = vector<vi>;
using vll = vector<long long>;
using vllvll = vector<vll>;
using vs = vector<string>;
using um = unordered_map<long long, long long>;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;

vllvll dp(110, vll(11000, 0));
vll v(1000);
vll w(1000);

ll rec(ll x, ll wei)
{
    if (x == 0) return dp[x][wei];
    if (wei >= w[x]) {
        return dp[x][wei] = max(rec(x-1, wei-w[x-1]) + v[x-1], rec(x-1, wei));
    } else {
        return dp[x][wei] = rec(x-1, wei);
    }
}

int main()
{
    ll N, W;
    cin >> N >> W;
    rep(i, 0, N) {
        cin >> v[i] >> w[i];
    }   
    rep(i, 0, W+1) {
        dp[0][i] = 0;
    }
    rep(i, 0, N) {
        rep(j, 0, W+1) {
            if (j - w[i] >= 0) {
                dp[i+1][j] = max(dp[i+1][j-w[i]]+v[i], dp[i][j]);
            } else {
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    /*
    rep(i, 0, N+1) {
        rep(j, 0, W+1) {
            cout << dp[i][j] << ' ';
        }
        cout << endl;
    }
    */
   ll mx = -1;
   rep(i, 0, W+1) {
       mx = max(mx, dp[N][i]);
   }
   cout << mx << endl;   
}


Measured memory_bytes: 12228
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX / 2 + 2], R[MAX / 2 + 2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i, j, k;
    int n1 = mid - left;
    int n2 = right - mid;
    for(i = 0; i < n1; i++) L[i] = A[left + i];
    for(i = 0; i < n2; i++) R[i] = A[mid + i];

    L[n1].value = R[n2].value = SENTINEL;
    i = j =  0;
    for(k = left; k < right; k++){
        if(L[i].value <= R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[], int n, int left, int right){
    int mid;
    if(left + 1 < right){
        mid = (left + right) / 2;
        mergeSort(A, n, left, mid);
        mergeSort(A, n, mid, right);
        merge(A, n, left, mid, right);
    }
}

int partition(struct Card A[], int n, int p, int r){
    int i, j;
    struct Card t, x;
    x = A[r];
    i = p - 1;
    for(j = p; j < r; j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i + 1];
    A[i + 1] = A[r];
    A[r] = t;
    return i + 1;
}

void quickSort(struct Card A[], int n, int p, int r){
    int q;
    if(p < r){
        q = partition(A, n, p, r);
        quickSort(A, n, p, q - 1);
        quickSort(A, n, q + 1, r);
    }
}

int main(){
    int n, i, v;
    struct Card A[MAX], B[MAX];
    char S[10];
    int stable = 1;

    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%s %d", S, &v);
        A[i].suit = B[i].suit = S[0];
        A[i].value = B[i].value = v;
    }

    mergeSort(A, n, 0, n);
    quickSort(B, n, 0, n - 1);

    for(i = 0; i < n; i++){
        if(A[i].suit != B[i].suit) stable = 0;
    }

    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i = 0; i < n; i++){
        printf("%c %d\n", B[i].suit, B[i].value);
    }

}


Measured memory_bytes: 5056
Moves = [1,2,3]
MaxStep = 30

def solve
  dp = Array.new(MaxStep + 1, 0)
  dp[0] = 1
  for step in 1..MaxStep
    Moves.each do |m|
      break if step - m < 0
      dp[step] += dp[step - m]
    end
  end
  dp
end

result = solve

while (n = $stdin.gets.to_i) != 0
  printf "%d\n", (result[n].to_f / 3650.to_f).ceil
end

Measured memory_bytes: 6100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
int main()
{
  int n;
  cin >> n;
  int sum = 0;
  while (sum - n < 0)
  {
    sum += 1000;
  }
  cout << sum - n << endl;

  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define DBG(v) cerr << #v << " = " << (v) << endl;

struct DSU {
	vector<int> rank;
	vector<int> parent;

	DSU(int n) {
		rank.resize(n, 1);
		parent.resize(n);
		for (int i = 0; i < n; ++i)
			parent[i] = i;
	}

	int find(const int u) {
		return parent[u] == u ? u : (parent[u] = find(parent[u]));
	}

	bool merge(int u, int v) {
		if ((u = find(u)) == (v = find(v)))
			return false;
		if (rank[u] < rank[v])
			swap(u, v);
		rank[u] += rank[v];
		parent[v] = u;
		return true;
	}

	int size(int u) {
		return rank[find(u)];
	}
};


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

	int n, m;
	cin >> n >> m;

	DSU dsu(n);

	int ans = n;
	for (int i = 0; i < m; ++i) {
		int u, v, w;
		cin >> u >> v >> w;
		--u, --v;


		if(dsu.merge(u, v))
			ans--;
	}
cout <<ans;
	return 0;
}


Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var a int
	var b int
	fmt.Scanf("%d%d", &a, &b)
	if a < b {
		fmt.Println("a < b")
	} else if a == b {
		fmt.Println("a == b")
	} else {
		fmt.Println("a > b")
	}
}



Measured memory_bytes: 1120
n=3
c=[]

for i in range(n):
    c.append([int(i) for i in input().split()])

a=c[0][0]-c[0][1]
b=c[0][1]-c[0][2]
d=c[0][2]-c[0][0]

e=c[0][0]-c[1][0]
f=c[1][0]-c[2][0]
g=c[2][0]-c[0][0]

for i in range(n):
    if c[i][0]-c[i][1]==a and c[i][1]-c[i][2]==b and c[i][2]-c[i][0]==d:
        if c[0][i]-c[1][i]==e and c[1][i]-c[2][i]==f and c[2][i]-c[0][i]==g: 
            pass

    else:
              print("No")
              break  

else:
    print("Yes")

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

//繰り返し二乗法
long long int ex(int x,long long int n){
  if(n==0)return 1;
  long long int ans=ex(x,n/2)*ex(x,n/2);
  if(n%2==1)ans*=x;
  return ans;
}

int main(){
    long long int h;
    cin >> h;
    long long int cnt=0;
    long long int ans=1,tmp=1;
    while(true){
        h/=2;
        cnt++;
        if(h==0){
          cnt--;
          break;
        }
    }
    //cout << cnt << endl;
    ans=ex(2,cnt+1)-1;
    cout << ans << endl;
}



Measured memory_bytes: 256
S = str(input())
T = str(input()) 
S_rot = S+"A"
for i in range(len(S)):
    if i == 0:
        S_rot = S_rot.replace("A",S_rot[0])
        S_rot = S_rot[1:]
    else:
        S_rot = S_rot+"A"
        S_rot = S_rot.replace("A",S_rot[0])
        S_rot = S_rot[1:]

    if S_rot == T:
        print("Yes")
        exit()
    else:
        continue
print("No")

Measured memory_bytes: 3060
let max l =
	let rec max' l res els = 
		match l with
		|[] -> (res,els)
		|x::xs -> if x > res then max' xs x (res::els) else max' xs res (x::els)
	in
	match l with
	|[] -> (0,[])
	|x::xs -> max' xs x [];;

let sort l =
	let rec sort' l res =
		match l with
		|[] -> res
		|_ -> let (m,e) = max l in sort' e (m::res)
	in
	sort' l [];;

let rec print_list l =
	match l with
		|[] -> print_string "\n"
		|x::xs -> print_int x; if xs <> [] then print_string " "; print_list xs;;

let make_list a b c = a::(b::(c::[]));;

Scanf.sscanf(read_line()) "%d %d %d" (fun a b c -> print_list (sort (make_list a b c)));;



Measured memory_bytes: 2380
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
	{
		int a;
		scanf("%d", &a);
		if (a % 2 == 0)
		{
			if (a % 3 != 0 && a % 5 != 0)
			{
				puts("DENIED");
				return 0;
			}
		}
	}
	puts("APPROVED");
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
struct UnionFind{
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};
int main(){
    int V,E;
    cin>>V>>E;
    vp vec(E);
    REP(i,E){
        cin>>vec[i].fi>>vec[i].se;
        vec[i].fi--;
        vec[i].se--;
    }
    int ans=0;
    REP(i,E){
        UnionFind uf(V);
        REP(j,E){
            if(i==j){
                continue;
            }
            uf.unite(vec[j].fi,vec[j].se);
        }
        if(uf.size(0)!=V){
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		
		int []a = new int [n];
		boolean []b = new boolean [n];
		int m = Integer.parseInt(sc.next());
		
		boolean flag = true;
		
		for(int i = 0;i < m;i++) {
			int s = Integer.parseInt(sc.next());
			int t = Integer.parseInt(sc.next());
			if(!b[n-s]) {
				if(s == 1 && t == 0 && n >= 2) {
					flag = false;
					break;
				}
				a[n-s] = t; 
				b[n-s] = true;
			}
			else {
				if(a[n-s] != t) {
					flag = false;
					break;
				}
			}
		}
		
		if(flag) {
			int ans= 0;
			
			for(int i = 0 ; i < n ;i++) {
				if(i == n-1 && !b[i] && n >= 2) {
				ans += Math.pow(10, i);
				} 
				else {
				ans += a[i] * Math.pow(10, i);
			}
		}
			System.out.println(ans);
		}
		else {
			System.out.println(-1);
		}
	}

}


Measured memory_bytes: 21844
import java.math.BigInteger;
import java.util.Scanner;
import java.util.Vector;

public class Main {
	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scanner = new Scanner(System.in);

		int N = scanner.nextInt();

		int[] scannerArrayB = new int[N - 1];

		long ans = 0;

		for (int index = 0; index < N - 1; index++) {
			scannerArrayB[index] = scanner.nextInt();
		}

		ans = scannerArrayB[0];

		for(int i = 0; i < N-2; i++) {
			ans += Math.min(scannerArrayB[i], scannerArrayB[i+1]);
		}

		ans += scannerArrayB[N-2];


//		for(int index = 0; index < N - 1; index++) {
//			ans += scannerArrayB[index];
//		}

		log(ans);
	}

	private static void dfs(int[] treeArray,int parrent, int children) {
		Vector<Vector> aa = new Vector<>();
		Vector<Integer> bb = new Vector<>();
		bb.add(1);
		aa.add(bb);
	}


	/**
	 * バブルソートの交換数を算出
	 * ※転倒数
	 * @param array
	 * @return
	 */
	private static long countSwapBabbleSort(int[] array, int N) {
		long ans = 0;
		int[] binary = new int[N + 1];

		for (int index = 0; index < array.length; index++) {
			ans = ans + (index - sum(binary, array[index]));
			add(binary, array[index], 1);
		}
		return ans;
	}

    //add value at idx on bit O(logN)
	private static void add(int[] bit,int idx,int value) {
        for(int i=idx;i<bit.length;i=i+(i&-i)) {
        	bit[i] += value;
        }
    }

    //return sum [1,idx] O(logN)
	private static long sum(int[] bit,int idx) {
        long ret = 0;
        for(int i=idx;i>0;i-=(i&-i)) {
        	ret += bit[i];
        }
        return ret;
    }

	private static void log(String str) {
		System.out.println(str);
	}

	private static void log(int str) {
		System.out.println(str);
	}

	private static void log(long str) {
		System.out.println(str);
	}

	private static void log(double str) {
		System.out.println(str);
	}

	private static void log(BigInteger str) {
		System.out.println(str);
	}

}



Measured memory_bytes: 21716
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[2];
  for(int j=0;j<2;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
  bool f=false;
  
  
  for(int i=0;i<4;i++){
    d[1].roll('R');
    for(int j=0;j<4;j++){
      d[1].roll('N');
      if(same(d[0],d[1])) f=true;
    }
  }
  d[1].roll('E');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }

  d[1].roll('W');
  d[1].roll('W');
  for(int j=0;j<4;j++){
    d[1].roll('N');
    if(same(d[0],d[1])) f=true;
  }
  
  cout << (f?"Yes":"No") << endl;
  return 0;
}


Measured memory_bytes: 3096
#include <stdio.h>

int main(){

  int n,i,sum = 0,j,temp;
  int array[124] = {};

  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    scanf("%d",&array[i]);
  }
  
  for(i = 0;i < n;i++){
    for(j = n - 1; j > i ;j--){
      if(array[j - 1] > array[j]){
	temp = array[j];
	array[j] = array[j - 1];
	array[j - 1] = temp;
	sum += 1;
      }
    }
  }

  for(i = 0;i < n;i++){
    if(i != n - 1) printf("%d ",array[i]);
    else printf("%d",array[i]);
  }
  printf("\n");
  printf("%d\n",sum);

  return 0;
}

Measured memory_bytes: 2744
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> L){
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    for(ll i=1; i< N; i++){
        L[0]-= L[i];
    }
    if(L[0]<0)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
color=[]
for i in range(n):
    color+=[i+1]*a[i]
tmp=[]
tmp=[[0]*w for i in range(h)]

for i,aa in enumerate(color):
    tmp[i//w][i%w]=color[i]

ans=[]
for i,t in enumerate(tmp):
    if i%2==0:
        ans.append(t)
    else:
        t.sort(reverse=True)
        ans.append(t)

for aa in ans:
    print(*aa)



Measured memory_bytes: 3956
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    auto S = sread();
    writeln((S[0] == S[1] && S[1] == S[2]) ? "No" : "Yes");
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;//ベルマンとかはllにしよ
//ここ十分にしないとだめ
#define INF 1000000000000

struct Edge{
  ll to_Node;
  ll cost;
  Edge(ll t,ll c){to_Node=t;cost=c;}
};

//関係ないループを外す
bool bellmanford(vector< vector<Edge> >& Edges,vector<ll>& mincost,ll n){
  //(l1-1)(普通のbellman)+1(検出)
  for(ll i=0;i<n;i++){
    for(ll j=0;j<n;j++){
      if(mincost[j]!=INF){
        ll e=Edges[j].size();
        for(ll k=0;k<e;k++){
          ll new_mincost=mincost[j]+Edges[j][k].cost;
          if(mincost[Edges[j][k].to_Node]>new_mincost){
            mincost[Edges[j][k].to_Node]=new_mincost;
            if(i==n-1 and Edges[j][k].to_Node==n-1)return true;
          }
        }
      }
    }
  }
  return false;//負の閉路があればtrue
}

int main(){
  ll n,m;cin >> n >> m;
  vector<ll> mincost(n,INF);
  vector< vector<Edge> > Edges(n);
  //mincost0の更新だけしっかりやる
  mincost[0]=0;

  for(ll i=0;i<m;i++){
    ll a,b,c;cin >> a >> b >> c;
    Edges[a-1].push_back(Edge(b-1,-c));
  }
  //Nodesを更新
  if(bellmanford(Edges,mincost,n)){
    cout << "inf" << endl;
  }else{
    cout << -mincost[n-1] << endl;
  }

}


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

long long int N, x, a[111], ans;

int main(){
    scanf("%lld%lld", &N, &x);
    for(int i = 0; i < N; ++i){
        scanf("%lld", a + i);
    }
    sort(a, a + N);
    size_t i = 0;
    while(x >= a[i]){
        if(i == N){
            ans -= (x > 0);
            break;
        }
        x -= a[i];
        ++ans;
        ++i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int len = s.length();
  int m = 0;
  int last = 0; //0: m 1:e 2:w
  REP(i,len){
    if(i == 0){
      if(s[i] != 'm'){
        cout << "Rabbit\n";
        return 0;
      }
      m++;
      continue;
    }
    if(last == 0){
      if(s[i] == 'e'){
        last = 1;
      }else if(s[i] == 'm'){
        last = 0;
        m++;
      }else{
        cout << "Rabbit\n";
        return 0;
      }
    }else if(last == 1){
      if(s[i] == 'm'){
        last = 0;
        m++;
      }else if(s[i] == 'w'){
        last = 2;
        m--;
      }else{
        cout << "Rabbit\n";
        return 0;
      }
    }else{
      if(s[i] == 'e'){
        last = 1;
      }else if(s[i] == 'w'){
        last = 2;
        m--;
      }else{
        cout << "Rabbit\n";
        return 0;
      }
    }
  }

  if(m == 0){
    cout << "Cat\n";
  }else{
    cout << "Rabbit\n";
  }
  return 0;
}




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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n;cin >> n;
    vector<lint> a(n);
    map<lint, lint> mp;
    REP(i, n) {
        cin >> a[i];
        int tmp = mp[a[i]];
        mp[a[i]] = mp[a[i]] + 1;
    }
    lint c = 0;
    for(auto m:mp){
        lint x=m.first,y = m.second;
        c += y * (y - 1) / 2;
    }
    lint ans=0;
    REP(i,n){
        lint x = mp[a[i]];
        lint out = c - x * (x - 1) / 2 + (x - 1) * (x - 2) / 2;
        cout << out << "\n";
    }
    return 0;
}

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

using namespace std;

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

  vector<int> X(N);

  for (auto& v : X) {
    cin >> v;
  }

  int ans = 2000000000;
  for (int P = 1; P <= 100; ++P) {
    int tmp = 0;
    for (const auto v : X) {
      tmp += (v - P) * (v - P);
    }
    ans = min(tmp, ans);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3164
/*input
1000 1000 1000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

const ll third=mypow(3,MOD-2);

inline ll inv(ll n){return mypow(n,MOD-2);}

int main()
{
	IOS;
	int n,m,k;
	cin>>n>>m>>k;

	ll ans=0;

	ll C=1;
	ll ex=mypow(3,m+k);
	ll l=1,r=1;
	ll S=1;
	for(int sum=0;sum<=m+k;sum++){
		ans+=S*C%MOD*ex%MOD;
		// cout<<S<<' '<<C<<' '<<ex<<' '<<l<<' '<<r<<'\n';
		if(ans>=MOD) ans-=MOD;
		C=C*inv(sum+1)%MOD;
		C=C*(n-1+sum+1)%MOD;

		ex=ex*third%MOD;

		S<<=1;
		if(sum>=m) S-=l;
		if(sum>=k) S-=r;
		S=(S+MOD+MOD)%MOD;

		if(sum>=m){
			l=l*(sum+1)%MOD*inv(sum+1-m)%MOD;
		}
		if(sum>=k){
			r=r*(sum+1)%MOD*inv(sum+1-k)%MOD;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define endl "\n"
#define pb push_back
#define mod 1000000007
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int dx8[]={1,-1,0,0,1,1,-1,-1};
int dy8[]={0,0,1,-1,1,-1,1,-1};
ll binexp(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinvfermat(ll a, ll m)
{
	return binexp(a, m - 2, m);
}
void task(bool flag)
{
	if (flag)
		cout << "YES\n";
	else
		cout << "NO\n";
}
ll lcm(ll a, ll b)
{
	return ((1LL * a * b) / (__gcd(a, b)));
}



//ll a[]={6,8,4,2,6};

//ll tb=100;
void solve(){
	vector<int> v(5);
	ll ans=0;
	for(ll i=0;i<5;i++){
		cin>>v[i];
		if(v[i]==0)ans=i+1;

	}
	cout<<ans<<endl;

		



		
}



int main()
{  
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
    fast;
    ll t;
    t=1;
   // cin>>t;
    while(t--){
    	solve();
    }
    
   
  



#ifndef ONLINE_JUDGE
	cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
#endif
return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> V(10, vector<int>(10));
  for (int i = 1; i <= N; i++)
    V.at((int)(to_string(i).front()) - '0').at((int)(to_string(i).back()) - '0')++;

  int sum = 0;
  for (int i = 1; i <= N; i++)
    sum += V.at((int)(to_string(i).back()) - '0').at((int)(to_string(i).front()) - '0');

  cout << sum << "\n";
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long


#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

const int N=1e5+5;
const int mod=1e9+7;

int32_t main() {
IOS;
int m,n,Min,Max;
cin>>m>>n;
Min=min(m,n);
Max=max(m,n);
int ans=1,sz=Max+Min;
    for (int i = 0; i <sz; ++i) {
        if(i%2){

            ans=((ans)*(Min))%mod;
            Min--;
        }else {

            ans=(ans*Max)%mod;
            Max--;
        }
    }
    cout<<((m==n?2:1)*ans)%mod;
}

Measured memory_bytes: 256
x = int(input())
k = int(input())
*R, = map(int,input().split()+[1<<30])
Q = int(input())
ta = [tuple(map(int,input().split())) for _ in range(Q)]
def f(x,l): return(max(l[0],min(l[1],x+l[2])))
L = a,b,c = 0,x,0
idx = t0 = 0
g = -1
for r in R:
    while idx < Q and ta[idx][0] < r:
        print(f(f(ta[idx][1],L)+g*(ta[idx][0]-t0),(0,x,0)));idx += 1
    d,t0 = g*(r-t0),r
    L = a,b,c = f(a,(0,x,d)),f(b,(0,x,d)),c+d
    g *= -1

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

int main() {
	int n;
	int x[100];
	int d[100];

	for (int i = 0; i < 100; i++) {
		d[i] = 0;
		x[i] = 0;
	}

	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	int max = x[0];
	int min = x[0];

	for (int i = 0; i < n; i++) {
		if (x[i] > max) {
			max = x[i];
		}
		if (x[i] < min) {
			min = x[i];
		}
	}

	
	for (int i = min - 1; i < max; i++) {
		for (int j = 0; j < n; j++) {
			d[i] += (i + 1 - x[j]) * (i + 1 - x[j]);
		}
	}

	int result = d[min - 1];
	for (int i = min - 1; i < max; i++) {
		if (d[i] < result) {
			result = d[i];
		}
	}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define MINF INT_MIN
#define ll long long
#define PB push_back 
#define PF push_front
#define P_F pop_front
#define P_B pop_back
#define F front
#define B back
#define MP make_pair
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define forit(i, s) for(__typeof ((s).end ()) i = (s).begin (); i != (s).end (); ++i)
#define foritr(i, s) for(__typeof ((s).rend ()) i = (s).rbegin (); i != (s).rend (); ++i)
 
using namespace std;

int datos = 100000;
vector<int> all(datos+1);

int main() {
  int n, k, aux, peNe;
  cin >> n>> k; 
  vector<int> peso;
  vector< map<int, int> > grafo(n);
  for(int i=0; i<n; i++){
    cin>>aux;
    peso.PB(aux);
  }

  for(int i=0;i<n;i++){
    for(int j=i+1; j<=i+k and j<n; j++){
      peNe = abs(peso[i]-peso[j]);
      grafo[i][j] = peNe;
    }
  }

  int nodo;
  deque<int> dq;
  vector<int> seen(n, INF);
  dq.PB(0);
  seen[0] = 0;

  while(!dq.empty()){
    nodo = dq.F();
    dq.P_F();
    
    if(nodo != n-1){
      forit(x, grafo[nodo]){
        if(seen[x->first] == INF){
          seen[x->first] = x->second + seen[nodo];
          dq.PB(x->first);
        }else
          seen[x->first]= min(seen[x->first], seen[nodo] + x->second);
      }
    }
  }
  
  cout << seen[n-1] << "\n";

  return 0;
}

Measured memory_bytes: 476760
#include <iostream>
#include <vector>

using namespace std;

int n;
vector<int> p;


int main()
{
	cin >> n;

	int ans = 0;

	p = vector<int>(n);
	for (int i = 0; i < n; i++) {
		cin >> p.at(i);
	}

	bool current_more = p.at(0) < p.at(1);

	for (int i = 1; i < n-1 ; i++) {
		bool new_more = p.at(i) < p.at(i + 1);

		if (current_more == new_more) { ans++; }

		current_more = new_more;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n, x, y;
  cin >> n >> x >> y;
  vector<int> ans(n);
  for(int i = 1; i < n+1; i++){
    for(int j = i+1; j < n+1; j++){
      ans[min({abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(x-j)})]++;
    }
  }
  for(int i = 1; i < n; i++){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n = int(input())
k = int(input())
x = list(map(int, input().split())) #x[0->(n-1)]

sum = 0

for i in x:
    if i < k - i:
        sum = sum + i
    else:
        sum = sum + k - i

print(sum*2)

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdlib>

using namespace std;
using ll = long long;

ll solve(vector<int> a){
	const int n = a.size();
	sort(a.begin(), a.end());
	const int m = n / 2, k = n - m;
	vector<int> lo(a.begin(), a.begin() + k);
	vector<int> hi(a.begin() + k, a.end());
	ll answer = 0;
	for(const int x : hi){ answer += x * 2; }
	if(k == m){ answer -= hi[0]; }
	for(const int x : lo){ answer -= x * 2; }
	if(k == m){
		answer += lo[k - 1];
	}else{
		answer += lo[k - 1] + lo[k - 2];
	}
	return answer;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i){ cin >> a[i]; }
	const ll x = solve(a);
	for(int i = 0; i < n; ++i){ a[i] = -a[i]; }
	const ll y = solve(a);
	cout << max(x, y) << endl;
	return 0;
}



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

#define int long long
#define MOD 1000000007

int64_t pow_mod(int64_t a, int64_t b){
    if(b == -1) return 0;
    int64_t ret = 1;
    while(b){
        if(b & 1) ret = ret * a % MOD;
        a = a * a % MOD; b >>= 1;
    }
    return ret;
}


struct Combination{
    int64_t mod;
    vector<int64_t> f;
    vector<int64_t> rf;

    int64_t inv(int64_t a){
        int64_t ret = 1, b = mod-2;
        while(b){
            if(b & 1) ret = ret * a % mod;
            a = a * a % mod; b >>= 1;
        }
        return ret;
    }

    Combination(int ma, int64_t m): f(ma+1), rf(ma+1){
        mod = m;
        f[0] = rf[0] = 1;
        for(int i = 1;i <= ma;i++){
            f[i] = f[i-1] * i % mod;
            rf[i] = rf[i-1] * inv(i) % mod;
        }
    }

    int64_t get(int n, int r){
        if(n < r) return 0;
        return f[n] * rf[r] % mod * rf[n-r] % mod;
    }
};


Combination combi(200010, MOD);
int c[200010];

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

    for(int i = 0;i < n;i++) cin >> c[i];
    sort(c, c+n, greater<int>());

    int sum = 0;
    int ans = 0;

    for(int i = 0;i < n;i++){
        sum += pow_mod(2, n-i-1) * (pow_mod(2, i) % MOD + pow_mod(2, i-1)*i%MOD) % MOD * c[i] % MOD;
        sum %= MOD;
    }

    cout << sum * pow_mod(2, n) % MOD << endl;


    return 0;
}

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

int main(){
int N, K;
cin >> N >> K;
ll sum = 0;
for (long long i = K; i <= N + 1; i++)
{
    sum += i * (N - i + 1) + 1;
    sum %= (1000000000LL + 7);    
}


cout << sum << endl;

}


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


namespace ConsoleApplication2
{
    class Program
    {
        static void Main()
        {
            int[] a=new int [2];
            int i;
            for(i=0;i<2;i++)
            {

                
                    a[i] = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
                
            }
            if (a[0]<a[1])a[0]=a[1];
            Console.WriteLine(a[0]);
        }
    }
}

Measured memory_bytes: 5860
N, K = map(int, input().split())
S = input()

cnt = 0

if S[0] == "L":
    cnt += 1

ans = 0

for i in range(N - 1):
    if S[i:i + 2] == "RL":
        cnt += 1
    if S[i] == S[i + 1]:
        ans += 1

if cnt - K >= 1:
    ans += K * 2
else:
    ans = N - 1

print(ans)


Measured memory_bytes: 3316
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
constexpr ll mod = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v) {
  int sz = v.size();
  for (int i = 0; i < sz; i++) {
    cout << v[i] << " \n"[i == sz - 1];
  }
}

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

  int n;
  cin >> n;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      if (i * j == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	for(int n;cin>>n,n;){
		int res=0;
		for(int i=0;i<=n;i++)
			for(int j=2;j<=n;j++)
				if(n==i*j+j*(j+1)/2)
					res++;
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
while True:
    count=0
    n,x=map(int,input().split())
    if n==0:
        break
    for i in range(1,n):
        a=i
        for j in range(1,n):
            if a+j>n:
                break
            else:
                b=a+j
            for k in range(1,n):
                if b+k>n:
                    break
                else:
                    c=b+k
                if a+b+c==x:
                    count=count+1
    print(count)


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

int main(){
    int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  if(s[k-1]=='A')
    s[k-1]='a';
  else if(s[k-1]=='B')
    s[k-1]='b';
  else if(s[k-1]=='C')
    s[k-1]='c';
  cout<<s<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MAXN = 301;

int main(){
    vector<int> V = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int N; cin >> N; 
    cout << V[N-1] << endl;
}

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

int main(){
  int H,W;
  cin >> H >> W;
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0; i<H; i++){
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  for(int i=0; i<W+2; i++){
    cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
import sys
def sign(x):
    if x>0: s=1
    elif x<0: s=-1
    else: s=0
    return s

def f(p1,p2,p3):
    x1,y1 = p1
    s = sign((p3[1]-y1)*(p2[0]-x1)-(p2[1]-y1)*(p3[0]-x1))
    return s

for s in sys.stdin:
    D = map(float, s.split(","))
    p1 = D[0:2]; p2 = D[2:4]; p3 = D[4:6]; p4 = D[6:8]
    x = f(p1,p3,p2) != f(p1,p3,p4) and f(p2,p4,p1) != f(p2,p4,p3)
    print ["NO","YES"][x]

Measured memory_bytes: 4256
n,m=map(int,input().split())
ac=[0 for i in range(n)]
l=[0 for i in range(n)]
for i in range(m):
    p,s=input().split()
    p2=int(p)
    if s=="AC":
        ac[p2-1]=1
    elif ac[p2-1]==0:
        l[p2-1]+=1
ans1=sum(ac)
ans2=0
for i in range(n):
    if ac[i]>0:
        ans2+=l[i]
print(ans1,ans2)


Measured memory_bytes: 4760
N = int(input())

M = 0
A = 0
R = 0
C = 0
H = 0


for n in range(N):
  _ = input()
  if _[0] == 'M':
    M += 1
  elif _[0] == 'A':
    A += 1
  elif _[0] == 'R':
    R += 1
  elif _[0] == 'C':
    C += 1
  elif _[0] == 'H':
    H += 1
  else:
    pass

ans = M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + M*C*H
ans += A*R*C + A*R*H + A*C*H
ans += R*C*H
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[][] a=new int[s[0]][];
		for(int i=0;i<s[0];i++){a[i]=sc.Ia;}
		Array.Sort(a,(u,v)=>(u[1]-u[0])-(v[1]-v[0]));
		St2 st=new St2(1,s[1]);
		StringBuilder sb=new StringBuilder();
		for(int i=1,j=0;i<=s[1];i++){
			while(j<s[0]&&a[j][1]-a[j][0]<i){
				if(a[j][1]==a[j][0]){st.Ud(a[j][0],1);}
				else{st.Ud2(a[j][0],a[j][1],1);}
				j++;
			}
			long ans=s[0]-j;
			for(int k=0;k<=s[1];k+=i){ans+=st.Get(k,k);}
			sb.Append(ans+"\n");
		}
		Console.Write(sb);
	}
}
public class St2{
	private long[] dat,dat2;
	private int m=1,f,sr=1,count=0;
	public St2(int f,int n){
		this.f=f;
		n+=f^1;
		while(m<n){m*=2;sr+=sr;}
		count=m+n;
		dat=new long[count];
		dat2=new long[count];
	}
	public void Ud(int q,long b){
		q+=m-1-f;
		dat[q]+=b;
		while(q>0){
			dat[(q-1)/2]=dat[(q-1)/2]+b;
			q=(q-1)/2;
		}
	}
	private long Fdg(int a,int b,int k,int l,int r){
		if(dat2[k]!=0){
			dat[k]+=dat2[k];
			if(2*k+1<count){dat2[2*k+1]+=dat2[k]/2;}
			if(2*k+2<count){dat2[2*k+2]+=dat2[k]/2;}
			dat2[k]=0;
		}
		if(r<a||b<l){return 0;}
		if(a<=l&&r<=b){return dat[k];}
		else{return Fdg(a,b,k*2+1,l,(l+r)/2)+Fdg(a,b,k*2+2,(l+r+1)/2,r);}
	}
	public long Get(int a,int b){return Fdg(a,b,0,f,m-(f^1));}
	public void Ud2(int a,int b,long d){Hn(a,b,0,f,m-(f^1),d*sr);}
	private long Hn(int a,int b,int k,int l,int r,long d){
		if(a<=l&&r<=b){dat2[k]+=d;return d;}
		else if(r>=a&&b>=l){
			long q=Hn(a,b,k*2+1,l,(l+r)/2,d/2);
			q+=Hn(a,b,k*2+2,(l+r+1)/2,r,d/2);
			dat[k]+=q;
			return q;
		}
		return 0;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


Measured memory_bytes: 39432
from collections import deque
import heapq

N,M = map(int,input().split())
LRC2 = []

for i in range(M):
    
    L,R,C = map(int,input().split())
    L -= 1
    R -= 1
    LRC2.append([L,R,C])

LRC2.sort()

LRC = deque([])

for i in LRC2:
    LRC.append(i)

q = []

for i in range(N):

    while len(LRC) > 0 and LRC[0][0] == i:
        now = LRC.popleft()
        L = now[0]
        C = now[2]
        R = now[1]

        if L == 0:
            heapq.heappush(q,[C,R])
            continue

        while len(q) > 0 and q[0][1] < i:
            heapq.heappop(q)

        if len(q) > 0:
            heapq.heappush(q,[C + q[0][0] , R])

    #print (LRC,q)


while len(q) > 0 and q[0][1] < N-1:
    heapq.heappop(q)

#print (q)

if len(q) > 0:
    print (q[0][0])

else:
    print (-1)


Measured memory_bytes: 85080
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    ll S;
    cin >> N >> K >> S;
    rep(i, 0, K) {
        cout << S << ' ';
    }
    if (S == 2) {
        rep(i, 0, N - K) {
            cout << 1000000000 << ' ';
        }
    }
    else if (S == 1) {
        rep(i, 0, N - K) {
            cout << 2 << ' ';
        }
    }
    else {
        rep(i, 0, N - K) {
            cout << (i % 2 ? 2 : S - 1) << ' ';
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <stdio.h>

using namespace std;

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



int main()
{
    string s;
    cin >> s;
    bool hantei = false;
    rep(i,3) {
        if(s.at(i) == '7') {
            hantei = true;
        }
    }

    if(hantei) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3040
import sys
from operator import itemgetter

n,q = [ int(x) for x in sys.stdin.readline().strip().split() ]
edge= [ [] for _ in range(n-1) ]
for i in range(n-1):
    edge[i] = [ int(x)-1 for x in sys.stdin.readline().strip().split() ]
edge.sort( key=itemgetter(0) )
c= [ 0 for _ in range(n) ]
for i in range(q):
    p,x= [ int(x) for x in sys.stdin.readline().strip().split() ]
    c[p-1]+= x
#
for a,b in edge: c[b]+= c[a]

print( *c )

Measured memory_bytes: 54236
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<map>
#include<utility>
#define mod 998244353
#define pb push_back
using namespace std;
long long x[1009],y[1009],z[1009];
int xx[8]={1,1,1,1,-1,-1,-1,-1};
int yy[8]={1,1,-1,-1,1,1,-1,-1};
int zz[8]={1,-1,1,-1,1,-1,1,-1};
vector<long long> a;
int main(){
	int n,m;
	long long ans=0;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i]>>z[i];
	}
	for(int i=0;i<=7;i++){
		long long cur=0;
		a.clear();
		for(int j=0;j<n;j++){
			a.pb(x[j]*xx[i]+y[j]*yy[i]+z[j]*zz[i]);
		}
		sort(a.begin(),a.end());
		for(int j=0;j<m;j++){
			cur+=a[n-j-1];
		}
		if(ans<cur)ans=cur;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://arc080.contest.atcoder.jp/tasks/arc080_a>
問題文============================================================
 長さ N の数列 a=(a1,a2,…,aN) があります。 各 ai は正の整数です。
 
 すぬけ君の目標は、a の要素を自由に並べ替え、次の条件が成り立つようにすることです。
 
 各 1≤i≤N−1 について、ai と ai+1 の積は 4 の倍数である。
 すぬけ君が目標を達成できるか判定してください。

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N; cin >> N;
    vector<ll> a(N);
    for(auto & in:a) cin >> in;
    ll four = 0, two = 0;
    for(int i = 0; i < N;i++){
        if(a[i]%4 == 0) four++;
        if(a[i]%2 == 0) two++;
    }
    two -= four;
    if(four*2 + 1 >= N){
        cout << "Yes" << endl;
        return 0;
    }
    if(four*2 + two >= N){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
	return 0;
}


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



int main()
{
 ll a, b;
 cin>>a>>b;

ll x,y;

for(ll i=1;i<=1250;i++)
{
	x=(i*8)/100;
	y=(i*10)/100;
	if(x==a&&y==b)return cout<<i,0;
}
cout<<-1;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<long long, long long> pllll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector< pair<int, int> > vii;
typedef vector< pair<long long, long long> > vllll;
typedef map<int, int> mii;
typedef map<long long, long long> mllll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0ll)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
#define bitsum(x) __builtin_popcount(x)
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  // ex: n = 3, m = 14
  // a1 + a2 + a3 = 14
  // Let D is the greatest common divisor
  // D * b1 + D * b2 + D * b3 = 14
  // D * 3 + D * (b1 - 1 + b2 - 1 + b3 - 1) = 14
  // D * 3 + D * c = 14 (c >= 0)
  // D * (3 + c) = 14 (c >= 0)
  // So D <= 14 / 3
  // So find the greatest factor of 14 less or equeal to 14 / 3 (4) 
  // The answer is 2, and 2 * (3 + c) = 14 => c = 4
  ll ans = 1;
  ll n, m;
  cin >> n >> m;
  fi(1, sqrt(m) + 1) {
    if(m % i == 0) {
      if(i <= m / n)
        chmax(ans, (ll)i);
      if(m / i <= m / n)
        chmax(ans, m / i);
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
import heapq as hq

# adj list graph
def dijkstra(adj, costs, s):
  N = len(adj)
  q = [(0,s)]
  dist = [float('inf')]*N
  dist[s] = 0
  prev = [None]*N

  while q:
    c, u = hq.heappop(q)
    if c > dist[u]:
      continue

    for v in adj[u]:
      if dist[v] > dist[u] + costs[(u,v)]:
        dist[v] = dist[u] + costs[(u,v)]
        prev[v] = u
        hq.heappush(q, (dist[v], v))

  return prev, dist


n,m,s,t = map(int,input().split())
s,t = s-1,t-1

G = [list() for _ in range(n)]
Cs = dict()
Ct = dict()

for _ in range(m):
  u,v,a,b = map(int,input().split())
  u,v = u-1,v-1
  G[u].append(v)
  G[v].append(u)
  Cs[(u,v)] = a
  Cs[(v,u)] = a
  Ct[(u,v)] = b
  Ct[(v,u)] = b

Ds = dijkstra(G, Cs, s)[1]
Dt = dijkstra(G, Ct, t)[1]

D = sorted(((a+b, i) for i,(a,b) in enumerate(zip(Ds,Dt))), reverse=True)
for i in range(n):
  while D[-1][1] < i:
    D.pop()
  print(int(10**15 - D[-1][0]))

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

using namespace std;

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

	string s;

	cin >> s;

	if(s[2] == s[3] && s[4] == s[5]){
		cout << "Yes\n";
	}else{
		cout << "No\n";
	}

	return 0;

}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  string ans = "";
  rep(i, s.size()) {
    ans += 'x';
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=1e9+7;
vector<vector<pii> >G(100010);
ll d[100010];
void dfs(int i,int p,int w){
    d[i]=d[p]+w;
    for(auto e:G[i]){
        if(e.first==p)continue;
        dfs(e.first,i,e.second);
    }
}
int main(){
    int n;cin>>n;
    rep(i,n-1){
        int a,b,c;cin>>a>>b>>c;
        G[a].pb(make_pair(b,c));
        G[b].pb(make_pair(a,c));
    }
    int q,k;cin>>q>>k;
    dfs(k,0,0);
    rep(i,q){
        int x,y;cin>>x>>y;
        cout<<d[x]+d[y]<<endl;
    }
}

Measured memory_bytes: 12800