akhauriyash/Code-Regression huggingface dataset:
// D - Powerful Discount Tickets
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rp(i,n) for(int i=0;i<(n);i++)

int main(){
	int N,M; cin>>N>>M;

	vector<int> A(N);
	vector<pair<int,int>> B;
	rp(i, N){
		cin>>A[i];
		for(int a=A[i]; a>0; a>>=1) B.push_back(make_pair(a, i));
	}

	sort(B.rbegin(), B.rend());

	vector<int> C(N);
	rp(i, min(M, (int)B.size())) C[B[i].second]++;

	ll ans = 0;
	rp(i,N) ans += (ll)A[i]>>C[i];
	cout<< ans <<endl;
}

Measured memory_bytes: 34916
N,Q = map(int,input().split())
S = input()
T = [0] * N
for i in range(1,N):
    T[i] = T[i-1] + (1 if S[i-1:i+1] == 'AC' else 0)
for i in range(Q):
    l,r = map(int,input().split())
    print(T[r-1]-T[l-1])

Measured memory_bytes: 9412
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

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

		int d = 0;
		int r = 0;
		double f = 0;

		d = a / b;
		r = a % b;
		f = 1.0 * a / b;

		System.out.println(d);
		System.out.println(r);
		System.out.println(String.format("%.5f", f));
	}

}



Measured memory_bytes: 26604
package main

import "fmt"
import "math"

func max(lhs, rhs int) int {
	return int(math.Max(float64(lhs), float64(rhs)))
}

func main() {
	var (
		N, M int
	)
	fmt.Scanf("%d %d", &N, &M)
	values := make([]int, N)
	weights := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d %d", &weights[i], &values[i])
	}
	//fmt.Println(N, M)
	//fmt.Println(values, weights)
	dp := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		dp[i] = make([]int, M+1)
	}
	for i := 1; i <= N; i++ {
		for j := 0; j <= M; j++ {
			dp[i][j] = dp[i-1][j]
			if j >= weights[i-1] {
				dp[i][j] = max(dp[i][j], dp[i-1][j-weights[i-1]]+values[i-1])
			}
		}
	}
	fmt.Println(dp[N][M])
}


Measured memory_bytes: 81792
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
    
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int cnt0 = 0;
        int cnt1 = 0;
        for(int i = 0; i < S.length(); i++){
            if( S.charAt(i) == '0' ){
                cnt0++;
            } else {
                cnt1++;
            }
        }
        
        System.out.println( Math.min(cnt0, cnt1) * 2 );
        
    }
}


Measured memory_bytes: 24016
import sys

if sys.platform =='ios':
	sys.stdin=open('input_file.txt')
	
#+++++
n,k=list(map(int, input().split()))
aa={}
for _ in range(n):
	a,b = list(map(int, input().split()))
	t = aa.get(a,0)
	aa[a] = t+b

sa = sorted(aa.keys())
for a in sa:
	if k > aa[a]:
		k -= aa[a]
	else:
		print(a)
		break
		

Measured memory_bytes: 10584
package main

import "fmt"

func main() {
	var N int
	var S string
	fmt.Scan(&N, &S)
	max := 0
	for i := 1; i < N; i++ {
		fst, snd := S[:i], S[i:]
		fstchars, sndchars := make(map[rune]bool), make(map[rune]bool)
		for _, c := range fst {
			fstchars[c] = true
		}
		for _, c := range snd {
			sndchars[c] = true
		}
		count := 0
		for c := range fstchars {
			if fstchars[c] && sndchars[c] {
				count++
			}
		}
		if count > max {
			max = count
		}
	}
	fmt.Println(max)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int n;
	cin >> n;
	if (n < 1200) {
		cout << "ABC" << endl;
	}
	else if (n >=1200&&n<2800) {
		cout << "ARC" << endl;
	}
	else{
		cout << "AGC" << endl;
	}

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int A,B;cin >> A >> B;
    if(A == 1){
        if(B == 2)cout << 3 << endl;
        else cout << 2 << endl;
    }   
    else if(A == 2){
        if(B == 1)cout << 3 << endl;
        else cout << 1 << endl;
    }
    else{
        if(B == 1)cout << 2 << endl;
        else cout << 1<< endl;
    }
}

Measured memory_bytes: 256
<?php


fscanf(STDIN, "%d %d", $N, $M);
for ($i=0; $i < $N; $i++) { 
	fscanf(STDIN, "%d %d", $a, $b);
	$price[$i]=$a;
	$amount[$i]=$b;
}
asort($price);
$result=0;
$nowamount=0;
$flag = 0;
foreach ($price as $key => $value) {

	if ($nowamount+$amount[$key]>$M) {
		$getamount = $M-$nowamount;
		$flag = 1;
	}else{
		$getamount = $amount[$key];
	}
	$result += $value * $getamount;
	$nowamount += $getamount;

}

echo $result;


Measured memory_bytes: 18036
#include <stdio.h>
#include <sstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <limits>
#include <iomanip>
#include <ctype.h>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, char> pic;
#define bit(x,v) ((ll)x << v)

const ll INF = 1000000007;
const int MAX = 210000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}

ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {

	while (max_n >= x)
	{
		bit[x]++;
		x += x & -x;
	}
}
void sub(int x) {
	while (max_n >= x)
	{
		bit[x]--;
		x += x & -x;
	}
}


void solv() {
	
	string s;
	cin >> s;
	int n = s.size(); 

	int dep[40010];
	memset(dep, -1, sizeof(dep));
	int de = 20000;
	stack<pair<int,ll>> st;
	for (size_t i = 0; i < n; i++)
	{
		if (s[i] == '\\'){
			de++;
			dep[de] = i;
		}
		else if (s[i] == '/') {
			int fr = dep[de];
			if (fr == -1) continue;
			ll v = i - fr;
			while (!st.empty() && de < st.top().first) {
				pair<int, ll> p = st.top();
				st.pop();
				v += p.second;
			}
			st.push(make_pair(de, v));
			de--;
		}
	}
	
	ll sum = 0;
	vector<ll> t;
	while (!st.empty())
	{
		pair<int, ll> p = st.top();
		st.pop();
		sum += p.second;
		t.push_back(p.second);
	}


	cout << sum << endl;
	cout << t.size();
	reverse(t.begin(), t.end());
	for (auto v : t)
	{
		cout << " " << v;
	}
	cout << endl;
}
int main() {
	//	COMinit();
	solv();
	return 0;
}



Measured memory_bytes: 3440
n = int(input())
h_list = list(map(int, input().split()))

count = 0
max_count = 0
pre_height = -1

for height in h_list:
    if (pre_height < height):
        if (max_count < count):
            max_count = count
        count = 0
        pre_height = height
        
        continue
    
    count += 1
    pre_height = height

if (max_count < count):
    max_count = count

print(max_count)

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

int main(){
    int N, M, K;
    cin >> N >> M >> K;
    vector<int> A(M);
    for(int i=0; i<M; i++) cin >> A[i];
    
    int cost1=0, cost2=0;
    for(int i=K+1; i<=N; i++){
        for(int j=0; j<M; j++){
            if(i==A[j]) cost1++;
        }
    }
    
    for(int i=K-1; i>=0; i--){
        for(int j=0; j<M; j++){
            if(i==A[j]) cost2++;
        }
    }
    
    cout << min(cost1, cost2) << endl;
}


Measured memory_bytes: 256
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

using Matrix = vector< vector<int> >;

bool d(Matrix &mat, int K, Matrix &lmat, Matrix &rmat) {
    int H = mat.size(), W = mat[0].size();
    int ma = -1 , mi = INF;
    rep(i,0,H) rep(j,0,W) {
        if(ma < mat[i][j]) {
            ma = mat[i][j];
        }
        if(mi > mat[i][j]) {
            mi = mat[i][j];
        }
    }

    int idx = -1;
    rep(i,0,H) {
        int tmp = -1;
        rep(j,idx,W) {
            if(mi + K < mat[i][j]) chmax(tmp, j);
        }
        rep(j,0,max(idx,tmp) + 1) {
            if(ma - K > mat[i][j]) return false;
        }
        idx = max(idx, tmp);
    }
    return true;
}

pair<Matrix, Matrix> calc_mima(Matrix &mat) {
    int H = mat.size(), W = mat[0].size();
    Matrix lret(H, vector<int>(W));
    Matrix rret(H, vector<int>(W));

    // lret (min)
    rep(i,0,H) rep(j,0,W) {
        if(j == 0) lret[i][j] = mat[i][j];
        else lret[i][j] = min(mat[i][j], lret[i][j-1]);
    }

    // rret (max)
    rep(i,0,H) repr(j,W-1,0) {
        if(j == W-1) rret[i][j] = mat[i][j];
        else rret[i][j] = max(mat[i][j], rret[i][j+1]);
    }

    return make_pair(lret, rret);
}

int solve(Matrix &mat) {
    pair<Matrix, Matrix> mts = calc_mima(mat);
    Matrix lmat = mts.first, rmat = mts.second;

    int lb = 0, ub = INF;
    while(ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if(d(mat, mid, lmat, rmat)) ub = mid;
        else lb = mid;
    }
    return ub;
}

Matrix rotate(Matrix mat) {
    int H = mat.size(), W = mat[0].size();
    Matrix ret(W, vector<int>(H));

    rep(i,0,H) rep(j,0,W) {
        ret[j][H-i-1] = mat[i][j];
    }
    return ret;
}

signed main() {
    int H, W; cin >> H >> W;
    Matrix mat(H, vector<int>(W));
    rep(i,0,H) rep(j,0,W) cin >> mat[i][j];

    int ans = INF;
    rep(i,0,4) {
        chmin(ans, solve(mat));
        mat = rotate(mat);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 159560
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;
const ld PI = 3.14159265358979323846;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//






int main(void) {

    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;

    
    return 0;
}









Measured memory_bytes: 3628
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		double x1, y1, x2, y2;

		Scanner stdIn = new Scanner(System.in);

		x1 = stdIn.nextDouble();
		y1 = stdIn.nextDouble();
		x2 = stdIn.nextDouble();
		y2 = stdIn.nextDouble();

		System.out.println(Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2)));

		stdIn.close();
	}
}

Measured memory_bytes: 28088
s=list(input())
t=list(input())

s.reverse()
t.reverse()

snum=len(s)
tnum=len(t)
chk=False
for i in range(snum-tnum+1):
    #print(s[i:i+tnum])
    cnt=0
    for j in range(i,i+tnum):
        #print(s[j],t[j-i])
        if s[j]==t[j-i]:
            cnt+=1
        elif s[j] =="?":
            cnt+=1
        
    if cnt==tnum and chk==False:
        s[i:i+tnum]=t
        chk=True
    else:
        if s[i]=="?":
            s[i]="a"

for i in range(snum):
    if s[i]=="?":
        s[i]="a"

if chk==True:
    print("".join(reversed(s)))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 38384
import java.util.*;

public class Main{
	public static void main(String[] args) {
		String i,o;
		Scanner sc = new Scanner(System.in);
		i = sc.nextLine();
		o = "";
		sc.close();
		
		int j;
		for (j=0 ; j<i.length() ; j++) {
			char a;
			a = i.charAt(j);
			if (a>='A' && a<='Z') {
				a += 'a'-'A';
			}else if (a>='a' && a<='z') {
				a += 'A'-'a';
			}
			o = o+a;
		}
		System.out.println(o);
	}
}


Measured memory_bytes: 31008
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    int x; cin>>x;

    cout<<360 / __gcd(x, 360)<<endl;
}

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

int main() {
  
  int h,w,k;
  cin >> h >> w >> k;
  
  vector<string> c(h);
  for ( int i = 0; i < h; i++) cin >> c[i];
  
  int cnt, ans = 0;
  for ( int a = 0; a < ( 1 << h ); a++){
    for ( int b = 0; b < ( 1 << w ); b++){
      cnt = 0;
      for ( int i = 0; i < h; i++){
        for ( int j = 0; j < w; j++){
          if ( ( a >> i ) & 1 ) continue;
          if ( ( b >> j ) & 1 ) continue;
          if ( c[i][j] == '#' ) cnt++;
        }
      }
      if ( cnt == k ) ans++;
    }
  }
  
  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double llf;
#define ft first
#define sd second
int main(){
	int n;
	scanf("%d",&n);
	int x,y,t,px=0,py=0,pt=0;
	while(n--){
		scanf("%d%d%d",&t,&x,&y);
		if(((x^px^y^py^t^pt)&1)||abs(x-px)+abs(y-py)>abs(t-pt)){
			puts("No");
			return 0;
		}
		px=x,py=y,pt=t;
	}
	puts("Yes");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
	int a[4],d, e;
	scanf("%d %d %d", &a[0], &a[1], &a[2]);
	scanf("%d", &d);
	int j, i;
	for ( i = 0; i < 2; i++)
	{
		for ( j = 2; j>i; j--)
		{
			if (a[j] < a[j - 1])
			{
				int b;
				b = a[j];
				a[j] = a[j - 1];
				a[j - 1] = b;
			
			}
			
		}
	}

	e = pow(2,d)
;	
 
e = a[2]*e+a[1]+a[0];
printf("%d", e);
	return 0;
 
 
 
 
 
 
}

Measured memory_bytes: 128
n = int(input())
p = tuple(map(int, input().split()))
a = list(p)

ans = []
for i in range(1,n+1):
  ans.append(i)

  

for i in range(n):
  for j in range(n):
    a[i] = p[j]
    a[j] = p[i]
    if a == ans:
      print('YES')
      exit()
    else:
      a = list(p)
    
      
      
      
    
print('NO')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//値のついてるノードを根として，とりあえず偶奇の条件調べる
//値のついてないノードに関しては値の範囲を調べるようなdfsをする
//範囲が空なら死，でよさそう...

int n;
vector<vector<int>> g;
int k;
vector<ll> v;
vector<ll> v_min,v_max;
vector<ll> dep;
int root=-1;
vector<ll> ans;

void dfs_dep(int pre,int now){
    for(auto to:g[now])if(to!=pre){
        dep[to]=dep[now]+1;
        dfs_dep(now,to);
    }
}

bool f=true;
//min, maxを返す
pair<ll,ll> dfs(int pre,int now){
    ll l=-LINF,r=LINF;
    if(v[now]<0){
        for(auto to:g[now])if(to!=pre){
            auto re=dfs(now,to);
            chmax(l,re.first-1);
            chmin(r,re.second+1);
        }
    }
    else{
        for(auto to:g[now])if(to!=pre){
            auto re=dfs(now,to);
            if(re.first-1<=v[now] and v[now]<=re.second+1){}
            else f=false;
        }
        l=v[now];
        r=v[now];
    }
    v_min[now]=l;
    v_max[now]=r;
    return make_pair(l,r);
}

void dfs2(int pre,int now){
    if(v[now]<0){
        if(v_min[now]<=ans[pre]+1 and ans[pre]+1<=v_max[now]){
            ans[now]=ans[pre]+1;
        }
        else if(v_min[now]<=ans[pre]-1 and ans[pre]-1<=v_max[now]){
            ans[now]=ans[pre]-1;
        }
        else f=false;
    }else{
        ans[now]=v[now];
    }
    for(auto to:g[now])if(to!=pre){
        dfs2(now,to);
    }
}

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

    cin>>n;
    g.resize(n);v.resize(n,-1);dep.resize(n);ans.resize(n);
    v_min.resize(n,-LINF);v_max.resize(n,LINF);
    //v[i]=-1 -> iは値の無いノード
    rep(i,n-1){
        int a,b;cin>>a>>b;a--,b--;
        g[b].push_back(a);
        g[a].push_back(b);
    }
    cin>>k;
    rep(i,k){
        int u;ll p;
        cin>>u>>p;u--;
        v[u]=p;
        v_min[u]=p;v_max[u]=p;
        if(root<0) root=u;
    }
    dep[root]=0;
    dfs_dep(-1,root);

    //偶奇のチェック
    rep(i,n){
        if(v[i]<0) continue;
        if( (v[root]%2) != ((v[i]+dep[i])%2) ){
            cout<<"No"<<endl;
            return 0;
        }
    }


    //範囲をやる
    dfs(-1,root);
    if(f) dfs2(-1,root);
    
    if(f){
        cout<<"Yes"<<endl;
        rep(i,n){
            cout<<ans[i]<<endl;
        }
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  //配列宣言と流し込み
  vector<int> vec(N);
  for (int j = 0; j < N; j++){
    cin >> vec.at(j);
  }
    
  //ソート
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  //差があったら1段増える
  int dan;
  dan = 1;
  
  for (int i = 0; i < N-1; i++){
  	if (vec.at(i+1) - vec.at(i) != 0){
    dan = dan + 1;
    }
  }
  
  //出力
  cout << dan << endl;
  
}

Measured memory_bytes: 256
def dfs(linesdata,visitlist,point):
 visitlist.append(point)
 for line in linesdata:
  if point == line[0] and not line[1] in visitlist:
   dfs(linesdata,visitlist,line[1])
  elif point == line[1] and not line[0] in visitlist:
   dfs(linesdata,visitlist,line[0])
import copy
data=raw_input().split(' ')
points=int(data[0])
lines=int(data[1])
lineslist=[]
count=0
for x in range(lines):
 pts=raw_input().split(' ')
 lineslist.append((int(pts[0])-1,int(pts[1])-1))
for index in range(lines):
 newlines=copy.deepcopy(lineslist)
 newlines[index]=[-1,-1]
 vislist=[]
 dfs(newlines,vislist,0)
 if not sorted(vislist)==range(points):
  count+=1
print count

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  int s_size = s.size();
  for(int i=s_size/2;i>=0;i--){
    string a,b;
    a = s.substr(0,i);
    b = s.substr(i,i);
    if(a==b){
      if(i*2 < s_size){
     	cout << i*2 << endl;
      	break;
      }
    }
  }
  
}

Measured memory_bytes: 256
import Control.Monad
import qualified Data.ByteString.Char8 as BS
import Data.List
import Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getIntList = readIntList <$> BS.getLine

main = do
  getLine
  as <- getIntList
  mapM_ (print . snd) (sort $ zip as [1 ..])

Measured memory_bytes: 29264
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)

signed main() {
    int n; cin >> n;
    vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];

    int ans = 0;
    for(int i = 0; i < n; i++) {
        while(a[i] % 2 == 0) {
            a[i] /= 2;
            ans++;
        }
    }

    cout << ans << endl;
}


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

int main() {
    int N, M, C; cin >> N >> M >> C;
    int ans = 0;
    int B[M];
    for (int i = 0; i < M; i++) {
        cin >> B[i];
    }
    for (int i = 0; i < N; i++) {
        int A;
        int sum = 0;
        for (int j = 0; j < M; j++) {
            cin >> A;
            sum += A * B[j];
        }
        if (sum + C > 0) {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
long long n;
void solve()
{
    long long i,a[n],b[n];
    for (i=0;i<n;i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }
    sort(b,b+n);
    for (i=0;i<n;i++)
    {
        long long j=n-1;
        if (a[i]==b[j]) cout<<b[j-1];
        else cout<<b[j];
        cout<<endl;
    }
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 4736
#include<stdio.h>

#define INFTY 2000000000
#define MAX 500000

int n;
long long count=0;

long long merge(long int A[],long int n,long int left,long int mid,long int right)
{
	int n1=mid-left;
	int n2=right-mid;
	int L[MAX/2+2],R[MAX/2+2];
	int i,j;
	long long int cnt=0;
	
	for(i=0;i<n1;i++)
	{
		L[i]=A[left+i];
	}
	
	for(i=0;i<n2;i++)
	{
		R[i]=A[mid+i];
	}
	
	L[n1]=INFTY;
	R[n2]=INFTY;
	
	i=0;
	j=0;
	
	for(int k=left;k<right;k++)
	{
		if(L[i]<=R[j])
		{
			A[k]=L[i];
			i=i+1;
		}
		else
		{
			A[k]=R[j];
			j=j+1;
			cnt+=n1-i;
		}
	}
	
	return cnt;
}

long long mergeSort(long int A[],long int n,long int left,long int right)
{
	long int x1,x2,x3;
	
	if(left+1<right)
	{
		int mid=(left+right)/2;
		x1=mergeSort(A,n,left,mid);
		x2=mergeSort(A,n,mid,right);
		x3=merge(A,n,left,mid,right);
		return x1+x2+x3;
	}
	else
	{
		return 0;
	}
}

int main(void)
{
	scanf("%d",&n);
	
	long int A[n];
	long int i;
	
	for(i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
	}
	
	int left=0,right=n;
	
	count=mergeSort(A,n,left,right);
	
	printf("%lld\n",count);
	
	return 0;
}



Measured memory_bytes: 4136
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String s = sc.next();
    if (a<3200){
      System.out.println("red");
    }else{
      System.out.println(s);
    }
    sc.close();
  }
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int X; cin >> X;
  
  //main
  bool ans = 0;
  for(int i=(X/105); i<=(X/100); i++){
    if((X-100*i)<=5*i){ ans = 1; break; }
  }
  
  // output
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2,tune=native")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("trapv")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<ll>;
using vvi = vector<vi>;
using pi = pair<ll, ll>;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 69;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vi v;
ll solve() {
	if(v[0]) cout <<-1, exit(0);
	ll ans = 0;
	for(int i = 1; i < v.size(); i++) {
		if(v[i]-1==v[i-1])ans++;
		else if(v[i]<=v[i-1]) ans += v[i];
		else cout <<-1, exit(0);
	}
	return ans;
}
int main() { //DINIC ORZ
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, t;
	cin >> n;
	ll ans = 0;
	while(n--) {
		cin >> t;
		v.pb(t);
	}
	cout << solve();
}


Measured memory_bytes: 3444
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;

const int N_MAX = 2005;
int root[N_MAX][N_MAX];
int K[N_MAX];

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= n; j++){
            if (j != i)root[i][j] = N_MAX;
            else root[i][j] = 0;
        }
    }
    memset(K, 0, sizeof(K));

    for(int i = 1; i < n; i++){
        queue<int> Q;
        Q.push(i);
        while(!Q.empty()){
            int t = Q.front();
            Q.pop();
            if (i < t)K[root[i][t]]++;
            if (t == x && root[i][y] > root[i][x] + 1){
                Q.push(y);
                root[i][y] = root[i][x] + 1;
            }
            if (t == y && root[i][x] > root[i][y] + 1){
                Q.push(x);
                root[i][x] = root[i][y] + 1;
            }
            if (t-1 >= 0 && root[i][t-1] > root[i][t] + 1){
                Q.push(t-1);
                root[i][t-1] = root[i][t] + 1;
            }
            if (t+1 <= n && root[i][t+1] > root[i][t] + 1){
                Q.push(t+1);
                root[i][t+1] = root[i][t] + 1;
            }
        }
    }
    for(int i = 1; i < n; i++){
        cout << K[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 15872
import sys
input=sys.stdin.readline
n=int(input())
max1=0
max2=0
a=[int(input()) for i in range(n)]
for i in a:
    if i>=max1:
        max2=max1
        max1=i
    elif i>=max2:
        max2=i
if max2==0:
    for i in range(n):
        print(max1)
    exit()
for i in a:
    if i==max1:
        print(max2)
    else:
        print(max1)
    

Measured memory_bytes: 58832
#include <iostream>
#include<bits/stdc++.h>
#include <iomanip>
 
#define array_size(a) (sizeof(a)/sizeof(a[0]))
#define lpi(n) for(int i=0; i<n; i++)
#define lpiv(v,n) for(int i=v; i<n; i++)
#define lpj(n) for(int j=0; j<n; j++)
#define lpjv(v,n) for(int j=v; j<n; j++)
#define iii pair<int,pair<int,int>>
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int>>
#define pqig priority_queue<int>
#define pqil priority_queue<int, vector<int>, greater<int>>
#define filein(ff) freopen(ff, "r", stdin)
#define fileout(ff) freopen(ff, "w", stdout)
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); 
using namespace std;
 
typedef long long ll;
 
 
ll fastpow(ll nodess, ll num) {
    if (!num)
        return 1;
    if (num % 2)
        return nodess * fastpow(nodess, num - 1)/*%mod*/;
    ll p = fastpow(nodess, num / 2);
    // p %= mod;
    p *= p;
    // p %= mod;
    return p;
}
 
ll my_mod(ll num, ll mod) {
    ll reto = num % mod;
    while (reto < 0)
        reto += mod;
    return reto;
}
 
ll gcd(ll u, ll v) { return !u ? v : gcd(v % u, u); }
 
ll dist(pair<ll, ll> u, pair<ll, ll> v) {
    return abs(u.fi - v.fi)  + abs(u.se - v.se);
}

ll lcm(ll a, ll b){
    return a / __gcd(a, b) * b;
}

int main(int argc, const char * argv[]) {
 
    fastio;

    int h,w;
    cin >> h >> w;
    ll dp[h+1][w+1];
    char grid[h][w];
    ll cnt =0;

    for(int i =0; i < h; i++){
        for(int j =0; j < w; j++){
            cin >> grid[i][j];
        }
    }

    for(int i =0; i <= h; i++){
        for(int j =0; j <=w; j++){
            if(i==0||j==0){
                dp[i][j] = 0;
                continue;
            }
            if(grid[i-1][j-1]=='#'){
                dp[i][j]=0;
            } else {
                if(i==1&&j==1){
                    dp[i][j]=1;
                }
                else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%(1000000000+7);
            }
        }
    }

    cout << dp[h][w] << endl;

    return 0; 
}   

Measured memory_bytes: 9088
N, M = map(int,input().split())

ans = 0
if N == 1 and M == 1:
    ans = 1
elif N == 1:
    ans = M - 2
elif M == 1:
    ans = N - 2
elif N == 2 or M == 2:
    ans = 0
else:
    ans += (N-2)*(M-2)

print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

void call(int n){
    int i,
        x;
    for(i=1;i<=n;i++){
        x = i;
        if (x%3==0||x%10==3){
            printf(" %d", i);
        }else{
            while(x){
                x /= 10;
                if(x%10==3){
                    printf(" %d", i);
                    break;
                }
            }
        }
    }
    printf("\n");
}

int main(){
    int n = 0;
    scanf("%d", &n);
    call(n);
    return 0;
}

Measured memory_bytes: 1788
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define DCSB {printf("-1");exit(0);}
using namespace std;
struct edge{
    int v,next;
}a[500001];
int n,m,u,v,ans=0,els,huanu,huanv,tot=0,q[500001],head[500001],fa[500001],dep[500001],f[500001];
void add(int u,int v){
    a[++tot].v=v;
    a[tot].next=head[u];
    head[u]=tot;
}
void dfs(int u,int ff,int dpt){
    dep[u]=dpt;
    fa[u]=ff;
    f[u]=(dpt%2)?1:-1;
    for(int tmp=head[u];tmp!=-1;tmp=a[tmp].next){
        int v=a[tmp].v;
        if(v!=ff){
            if(dep[v]){
                huanu=u;
                huanv=v;
                continue;
            }
            dfs(v,u,dpt+1);
            f[u]+=f[v];
        }
    }
}
void gao_tree(){
    if(f[1]!=0)DCSB
    for(int i=1;i<=n;i++)ans+=abs(f[i]);
    printf("%d",ans);
}
void gao_jihuan(){
    if(f[1]%2!=0)DCSB
    els=-f[1]/2;
    ans=abs(els);
    for(;huanu;huanu=fa[huanu])f[huanu]+=els;
    for(;huanv;huanv=fa[huanv])f[huanv]+=els;
    for(int i=1;i<=n;i++)ans+=abs(f[i]);
    printf("%d",ans);
}
void gao_ouhuan(){
    int top,mid;
    top=0;
    if(f[1])DCSB
    for(;huanv!=huanu;huanv=fa[huanv]){
        q[++top]=f[huanv];
        dep[huanv]=0;
    }
    sort(q+1,q+top+1);
    mid=q[(top+1)/2];
    ans=abs(mid);
    for(int i=1;i<=n;i++)if(dep[i])ans+=abs(f[i]);
    for(int i=1;i<=top;i++)ans+=abs(q[i]-mid);
    printf("%d",ans);
}
int main(){
    memset(head,-1,sizeof(head));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    dfs(1,0,1);
    if(m==n-1)gao_tree();
    else if((dep[huanv]-dep[huanu])%2==0)gao_jihuan();
    else gao_ouhuan();
    return 0;
}

Measured memory_bytes: 17152
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
  int x, y, tmp;
  while(true)
  {
    cin >> x >> y;
    if(!x && !y)
      break;
    if(x < y)
    {
      tmp = y;
      y = x;
      x = tmp;
    }
    int i;
    for(i = 0; y; i++)
    {
      x = x % y;
      tmp = y;
      y = x;
      x = tmp;
    }
    printf("%d %d\n", x, i);
  }
}

Measured memory_bytes: 1144
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    // Your code here!
    //今から文字入力
    double r;
    cin>>r;
    cout<<fixed<<setprecision(6);
    cout<<r*r*3.141592653589<<" "<<2*3.141592653589*r<<endl;
    
   return 0;
}



Measured memory_bytes: 3288
from functools import lru_cache

N = int(input())

@lru_cache(maxsize=None)
def luca(N):
  if N>=2:
    return luca(N-2)+luca(N-1)
  if N==1:
    return 1
  if N==0:
    return 2
  
print(luca(N))


Measured memory_bytes: 38384
A = []
H, W = map(int, input().split())
while H != 0 or W != 0:
    A.append([H,W])
    H, W = map(int, input().split())
for i in range(len(A)):
    for j in range(A[i][0]):
        print('#' * A[i][1])
    print('')


Measured memory_bytes: 5624
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] s = new int[n];
    int sum = 0;

    for (int i = 0; i < n; i++) {
      s[i] = sc.nextInt();
      sum += s[i];
    }

    Arrays.sort(s);
    for (int i = 0; i < n; i++) {
      if ((sum % 10) != 0) {
        System.out.println(sum);
        return;
      } else {
        if ((s[i] % 10) != 0) {
          sum -= s[i];
        }
      }
    }

    System.out.println(0);

  }
}

Measured memory_bytes: 36044
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b=sc.nextInt();
        char[] s = sc.next().toCharArray();
        String ans = "Yes";
        for(int i = 0;i<s.length;i++){
            if(i!=a&&s[i]=='-'){
                ans = "No";
                break;
            } else if(i==a&&s[i]!='-'){
                ans = "No";
                break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
#include <iostream>
using namespace std;
#define LL long long
#define MXN 10000
#define MOD 10000007

ifstream f("data.in");
ofstream g("data.out");

void solve(){
    string i,j;
    cin>>i>>j;
    
    j = j.substr(0,j.size()-1);
    if(i==j)puts("Yes");
    else puts("No");
} 

int main() {
    solve();

    return 0;
}

Measured memory_bytes: 3632
def solve(a, m, sumA):
    if m < 0 or m > sumA:
        return False
    if m == 0:
        return True
    if len(a) == 0:
        return False
    return solve(a[1:], m - a[0], sumA) or solve(a[1:], m, sumA)

n = int(input())
tmp = input().split()
a = []
for i in range(n):
    a.append(int(tmp[i]))
q = int(input())
tmp = input().split()
m = []
for i in range(q):
    m.append(int(tmp[i]))

sumA = sum(a)

for i in range(q):
    if solve(a, m[i], sumA):
        print("yes")
    else:
        print("no")



Measured memory_bytes: 5620
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        StringBuilder sb = new StringBuilder();
        for (int i = 0 ; i < s.length() ; i ++) {
            if (i % 2 == 0) {
                sb.append(String.valueOf(s.charAt(i))) ;
            }
        }
        System.out.println(sb);
    }

}

Measured memory_bytes: 23888
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/


signed main() {
	int a, b; cin >> a >> b;
	cout << max({ a + b,a - b,a * b }) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    string s, t;
    cin >> s >> t;

    int ans = 0;
    rep(i, s.size()) {
        if (s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3916
def main():
	H, W, A, B = map(int, input().split())
	H, W= H-1, W-1
	DIV = 10**9+7
	size = H+W+1

	fact = [0]*size
	inverse = [0]*size
	inv_cal = [0]*size
	fact[:2] = [1, 1]
	inverse[:2] = [1, 1]
	inv_cal[:2] = [0, 1]

	for i in range(2, size):
		fact[i] = (fact[i-1]*i%DIV)
		inv_cal[i] = (-inv_cal[DIV%i]*(DIV//i))%DIV
		inverse[i] = inverse[i-1]*inv_cal[i]%DIV

	def C(n, r):
		ans = fact[n]*inverse[r]%DIV
		return ans*inverse[n-r]%DIV

	ans = 0
	for x in range(B, W+1):
		y = H-A
		tmp = (C(x+y, x)%DIV)*(C(H+W-x-y-1, W-x)%DIV)%DIV
		ans += tmp
		ans %= DIV

	print(ans)


if __name__ == '__main__':
	main()

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

int main() {
    string s;
    int a,b;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s.at(i)=='A'){
            a=i;
            break;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s.at(s.size()-1-i)=='Z'){
            b=s.size()-1-i;
            break;
        }
    }

    cout << b-a+1 << endl;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pi pair <int, int>

int n, x, y, dist[2100];
vector <int> G[2100];
queue <int> q;
map <int, int> mp;

int32_t main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> x >> y;
	G[x].pb(y);
	G[y].pb(x);
	for(int i = 1; i < n; ++i) {
		G[i].pb(i + 1);
		G[i + 1].pb(i);
	}
	for(int k = 1; k < n; ++k) {
		mp[k] = 0;
	}
	// bfs
	for(int i = 1; i <= n; ++i) {
		memset(dist, -1, sizeof(dist));
		int source = i;
		q.push(source);
		dist[source] = 0;
		while (q.size()) {
			int u = q.front();
			q.pop();
			for(int j = 0; j < G[u].size(); ++j) {
				int v = G[u][j];
				if (dist[v] == -1) {
					q.push(v);
					dist[v] = dist[u] + 1;
					++mp[dist[v]];
				}
			}
		}
	}
	for(auto it:mp) {
		cout << it.second/2 << '\n';
	}
}

Measured memory_bytes: 3808
N = int(input())
B = [int(i) for i in input().split()]
A = [float('inf')] * N

for i in range(N - 1) :
    A[i] = min(A[i], B[i])
    A[i+1] = min(A[i+1], B[i])
    
print(sum(A))

Measured memory_bytes: 38496
ny = input().split(' ')

n = int(ny[0])
y = int(ny[1])

ans = "-1 -1 -1"

for i in range(n+1):
    for j in range(n-i+1):
        if(10000*i+5000*j+1000*(n-i-j) == y):
            ans = str(i)+' '+str(j)+' '+str(n-i-j)
            break

print(ans)

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

int main(){
    int n, b, f, r, v, a[5][4][11];
    
    
    for (int i = 1; i <= 4; i++) {
        for (int j = 1; j <= 3; j++){
            for (int k = 1; k <= 10; k++){
                a[i][j][k] = 0;
            }
        }     
    }

    cin >> n;

    for (int i = 0; i < n; i++){ 
        cin >> b >> f >> r >> v;
        a[b][f][r] += v;  
    }

    for (int i = 1; i <= 4; i++) {
        if (i > 1) cout << "####################" << endl;
        for (int j = 1; j <= 3; j++){
            for (int k = 1; k <= 10; k++){
                cout << " " << a[i][j][k];
            }
            cout << endl;
        }     
    }
    
}



Measured memory_bytes: 3120
#include <iostream>
#include <algorithm>
#include <atcoder/dsu>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#define PI 3.14159265359
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pai;
typedef pair<ll, ll> pal;
const int MOD = 1e9+7;
const ll LLINF = 1e18;


int main(){
	int n, q;
	cin >> n >> q;
	dsu d(n);
	for (int i = 0; i < q; i++){
		int x, u, v;
		cin >> x >> u >> v;
		if (x == 0){
			d.merge(u, v);
		}else{
			if (d.same(u, v)){
				cout << 1 << endl;
			}else{
				cout << 0 << endl;
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3928
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
//const int MOD=998244353;
const int INF=1e9;
const long long LINF=1e18;
#define int long long
//template
template <typename T>
void fin(T a){
  cout<<a<<endl;
  exit(0);
}
/*
止まる駅はMlogMなので愚直にやっても間に合う？
駅の種類をいい感じに数えられない気がする
*/
/*
区間を短い順でsort
dを1から順番に見て行く
dでは現在の区間ストックの個数を足した後BITに入ってるものを各dの倍数で見る
dが上がるたびに区間長がd未満のものをBITに入れてあげる
*/
int N=1;

int bit0[1000000],bit1[1000000];
int sum(int *b,int i){
  int res=0;
  while(i){
    res+=b[i];
    i-=i&-i;
  }
  return res;
}
void add(int *b,int i,int v){
  while(i<=N){
    b[i]+=v;
    i+=i&-i;
  }
}
//main
signed main(){

  int n,m;cin>>n>>m;
  while(m>N)N*=2;
  memset(bit0,0,sizeof(bit0));
  memset(bit1,0,sizeof(bit1));
  std::vector<int> l(n),r(n);
  for(int i=0;i<n;i++)cin>>l[i]>>r[i];
  typedef pair<int,int> P;
  priority_queue<P,vector<P>,greater<P>> que;
  for(int i=0;i<n;i++)que.push(P(r[i]-l[i]+1,i));
  for(int d=1;d<=m;d++){
    while(que.size()&&que.top().first<d){
      P p=que.top();que.pop();
      int ql=l[p.second],qr=r[p.second];
      add(bit0,ql,-1*(ql-1));
      add(bit1,ql,1);
      add(bit0,qr+1,qr);
      add(bit1,qr+1,-1);
    }
    int res=que.size();
    for(int i=d;i<=m;i+=d){
      res+=sum(bit0,i)+sum(bit1,i)*i;
      res-=sum(bit0,i-1)+sum(bit1,i-1)*(i-1);
    }
    cout<<res<<endl;
  }
}


Measured memory_bytes: 30828
#include <bits/stdc++.h>
using namespace std;
int main(){
  
int n,m;
cin>>n>>m;
vector<int>r(n,0);

for(int i=0;i<2*m;i++){
  int a;
  cin>>a;
  r.at(a-1)++;
  }

for(int i=0;i<n;i++){
  cout<<r.at(i)<<endl;
  }

return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int[]po=new int[n];
        int minus=0;
        int zeros=0;
        for(int i=0;i<n;i++){
            po[i]=sc.nextInt();
            if(po[i]<0)minus++;
            else if(po[i]==0)zeros++;
            po[i]=Math.abs(po[i]);
        }
        if(minus%2==0||zeros!=0){
            long ans=0;
            for(int i=0;i<n;i++){
                ans+=po[i];
            }
            System.out.println(ans);
        }
        else{
            long ans=0;
            Arrays.sort(po);
            for(int i=1;i<n;i++){
                ans+=po[i];
            }
            System.out.println(ans-po[0]);
        }
    }
}

Measured memory_bytes: 50084
#include <bits/stdc++.h> 
using namespace std;
//関数
const long INF=1000000000000000;
const long MOD=1000000007;
bool check=false;


int main(void){
    long N,K;
    cin>>N>>K;
    vector<long> p(N);
    for(int i=0;i<N;i++){
        cin>>p.at(i);
    }
    
    long ans=-1;
    long sum=0;
    for(int i=0;i<K;i++){
        sum+=p.at(i);
    }
    
    ans=sum;
    
    for(int i=0;i+K<N;i++){
        sum+=p.at(i+K)-p.at(i);
        ans=max(ans,sum);
    }
    
    double Ans=((double) (ans+K))/2;
    
    cout<<setprecision(12)<<Ans<<endl;
}


Measured memory_bytes: 1792
n=*0...gets.to_i
g=$<.map{|l|l.split.map &:to_i}.select{|v|v[0]}.sort
r=n.-g.map{|v|v[1,2]}.reduce:+
x,y,*z=[],[]
w=->f,i{i<0&&next
x<<i
f[f,g[i][1]]
y<<i
f[f,g[i][2]]
z<<i}
w[w,r[0]]
s=" "
puts :Preorder,s+x*s,:Inorder,s+y*s,:Postorder,s+z*s

Measured memory_bytes: 6116
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<iomanip>
using namespace std;

int main() {
    const double PI = 3.1415926535;
    double a, b, x; cin >> a >> b >> x;
    double h;
    double L = a * a * b;
    double theta;
    if (x >= L / 2) {
        h = 2 * b - (2 * x) / (a * a);
        theta = atan(h / a);
        cout << setprecision(9) << (theta * 180 / PI) << endl;
    } else {
        h = (2 * x) / (a * b);
        theta = atan(h / b);
        cout << setprecision(9) << (90 - theta * 180 / PI) << endl;
    }
}


Measured memory_bytes: 512
n=int(input())
s=[None for i in range(n)]
l=[[] for i in range(n)]
for i in range(n-1):
  x,y,w=map(int,input().split())
  x-=1
  y-=1
  l[x]+=[[y,w%2]]
  l[y]+=[[x,w%2]]

s[0]=0
p=[0]
while p:
  q=p.pop()
  for t,w in l[q]:
    if s[t] == None:
      if w==1:
        s[t]=(s[q]+1)%2
      else:
        s[t]=s[q]
      p+=[t]
for i in s:
  print(i)

Measured memory_bytes: 41808