akhauriyash/Code-Regression huggingface dataset:
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18;
const double PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

void solve(){
	int N,K;
	cin >> N >> K;
	vector<LL> A(N);
	for(int i=0;i<N;++i){
		cin >> A[i];
	}
	vector<LL> sum(N);
	sum[0] = A[0];
	for(int i=1;i<N;++i){
		sum[i] = sum[i-1] + A[i];
	}
	vector<LL> B(N,0);
	for(int i=0;i<N;++i){
		if( i ){
			B[i] += B[i-1];
		}
		if( A[i] > 0 ){
			B[i] += A[i];
		}
	}
	LL ans = 0;
	for(int i=0;i<=N-K;++i){
		LL res = 0;
		//[i,i+K-1]
		res = B[N-1] - B[i+K-1];//右
		if( i ){
			res += B[i-1];//左
		}
		LL cen = 0;
		cen = sum[i+K-1];
		if( i ){
			cen -= sum[i-1];
		}
		if( cen > 0 ){
			res += cen;
		}
		ans = max(ans, res);
	}
	cout << ans << endl;
}
#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	
	
	solve();
}
#pragma endregion //main()


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

int main(){
  string S;
  int long long K;
  cin>>S>>K;
  int len = S.size();
  int x;
  int long long ans=0;
  if(len==1){
    cout<<K/2<<endl;
    exit(0);
  }
  if(len==2){
    if(S.at(0)==S.at(1)){
      cout<<K<<endl;
      exit(0);
    }
    else{
      cout<<0<<endl;
      exit(0);
    }
  }
  if(K==1){
    int long long a=0;
    int n=0;
    for(int i=1;i<len;i++){
      if(S.at(i)==S.at(i-1))
        n++;
      else{
        a+=((n+1)/2);
        n=0;
      }
    }
    a+=(n+1)/2;
    cout<<a<<endl;
    exit(0);
  }
  if(S.at(0)==S.at(len-1))
    x=1;
  else
    x=0;
  int num=0;
  if(x==0){
    for(int i=1;i<len;i++){
      if(S.at(i)==S.at(i-1))
        num++;
      else{
        ans+=((num+1)/2)*K;
        num=0;
      }
    }
    ans+=((num+1)/2)*K;
    cout<<ans<<endl;
  }
  int rnum=0;
  int s=0;
  int e=0;
  if(x==1){
    for(int i=1;i<len-1;i++){
      if(S.at(i)==S.at(0))
        rnum++;
      else{
        s=i;
        break;
      }
    }
    if(rnum==len-2){
      ans=(len*K)/2;
      cout<<ans<<endl;
    }
    else{
      for(int i=len-2;i>s-1;i--){
        if(S.at(i)==S.at(len-1))
          rnum++;
        else{
          e=i;
          break;
        }
      }
      for(int i=s;i<e+2;i++){
        if(S.at(i)==S.at(i-1))
          num++;
        else{
          ans+=((num+1)/2)*K;
          num=0;
        }
      }
      rnum+=2;
      ans+=(rnum/2)*(K-1);
      ans+=(s/2);
      ans+=((len-1-e)/2);
      cout<<ans<<endl;
    }
  }
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.array;
import std.conv;
import std.string;
import std.uni;
import std.range;
import std.algorithm;
import std.math;

void main()
{
    auto k = readln.strip.split(" ").map!(to!double).array;
    writefln("%.10000000f", sqrt((k[2] - k[0]) * (k[2] - k[0]) + (k[3] - k[1]) * (k[3] - k[1])));
}


Measured memory_bytes: 51336
N,M = map(int,input().split())
ab_ = [list(map(int,input().split())) for i in range(N)]
ab_.sort(key=lambda x:x[0])
buy = 0
money = 0
for i in range(N):
  if buy+ab_[i][1] > M:
    money += (M-buy)*ab_[i][0]
    break
  else:
    money += ab_[i][0]*ab_[i][1]
    buy += ab_[i][1]

print(money)

Measured memory_bytes: 29024
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=a;i<=b;i++){
        if(c%i==0){
            ans++;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3112
#include<iostream>
#include<vector>
using namespace std;
#include<algorithm>

int main(){
	long long int n,a,b;
	cin>>n>>a>>b;
	vector<int> h(n);
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	
	long long int hp=0;
	
	sort(h.begin(),h.end(),greater<int>());
	
	long long int l=0;
	long long int r=h[0];
	
	long long int mid=h[0]/2;
	
	for(int i = 0;i<100;i++){
		hp=mid*b;
		long long int hh=0;
		for(int j=0;j<n;j++){
			if((h[j]-hp)>0){
				hh+=(h[j]-hp)/(a-b);
				if((h[j]-hp)%(a-b)!=0)hh+=1;
			}
		}
		if(hh<=mid){
			r=mid;
			mid=(l+r)/2;
		}else{
			l=mid;
			mid=(l+r)/2;
		}
		if((l+r)%2!=0)mid++;
	}
	
	cout<<mid<<endl;
	return 0;
}

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

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a,b;
  cin >> a >> b;
  (a == b) ? cout << "Yes\n" : cout << "No\n";
return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "string.h"
using namespace std;
bool visit[1000000];
int prime[1000000];

void isPrime()
{
    int j=0;
    for(int i=2;i<1000000;i++)
    {
        if(visit[i])
            prime[j++]=i;
        for(int t=0;t<j&&i*prime[t]<1000000;t++)
        {
            visit[i*prime[t]]=false;
            if(i%prime[t]==0)
                break;
        }
    }
}

int main()
{
    int N=30;
    int n;
    memset(visit,true,1000000);
    visit[0]=visit[1]=false;
    isPrime();
    while(cin>>n)
    {
        int cnt=0;
        for(int i=2;i<=n;i++)
            if(visit[i])
            cnt++;
        cout<<cnt<<endl;
    }
    return 0;
}

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

using namespace std;

using ll = long long;

vector<ll> g[200001], garbo;
queue<ll> q;
vector<bool> used(200001);
vector<int> d(200001), p(200001);
ll ans = 0;

int main(){
    ll n, m;
    cin >> n >> m;
    for(ll i = 1; i <= m; ++i){
        ll u, v; cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    q.push(1);
    used[1] = true;
    p[1] = -1;
    while (!q.empty()){
        ll v = q.front();
        q.pop();
        for (auto u : g[v]) {
            if (!used[u]) {
                used[u] = true;
                q.push(u);
                d[u] = d[v] + 1;
                p[u] = v;
                if(u == n && d[u] == 2){
                    cout << "POSSIBLE";
                    return 0;
                }
            }
        }
    }
    cout << "IMPOSSIBLE";

    return 0;
}


Measured memory_bytes: 15208
#include <bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
int dp[100005];
int fun(int idx)
{
    int &ret=dp[idx];
    if(~ret) return ret;
    ret=0;
    for(int i=0;i<adj[idx].size();i++)
    {
        ret=max(ret,1+fun(adj[idx][i]));
    }
    return ret;
}
int main()
{
    memset(dp,-1,sizeof dp);
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
    }
    int ans=1;
    for(int i=1;i<=n;i++)
        ans=max(ans,fun(i));
    cout<<ans<<endl;
}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define forx(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define caseout(i, x) cout << "Case #" << i << ": " << x << endl;

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

    int n;
    cin >> n;
    vector<int> c;
    vector<int> s(200010);
    c.push_back(0);
    rep(i, n){
        int x;
        cin >> x;
            if (x != c.back())
                c.push_back(x);
    }
    n = c.size()-1;
    vector<ll> dp(n+1);
    dp[0] = 1;
    ll mod = 1e9 + 7;

    forx(i,1,n+1){
        dp[i] = dp[i-1];

        if(s[c[i]]!=0)dp[i] += dp[s[c[i]]];

        s[c[i]] = i;

        dp[i] %= mod;
    }

    cout << dp[n] << endl;

    return 0;
}


Measured memory_bytes: 3572
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
int h[100010]; // shuugo 
int dp[100010]; // cost at i --> dp[i]
int  INF = INT_MAX;
#define  min(a,b) (a>b? b:a)
int sa(int a, int b){return a>b? a-b:b-a;}
int 
chmin(int  *a, int b) 
{
	 if (*a > b){
		 *a = b; //	printf("%ld\n",*a);
		 return 1; 
	 }
	 return 0;
}
int 
main(){
	int N,i;
	scanf("%d",&N);
	
	
	for(i=0;i<N;i++){
		scanf("%d",&h[i]); //d[i]=100010;
	}
	for(i=0;i<N;i++){
		dp[i] =INF;
	}
	dp[0]=0; // cost at 1 // default
	for(i=0;i<N;i++){
		dp[i+1] = min(dp[i+1],dp[i]+ abs(h[i+1]-h[i]));				
		dp[i+2] = min(dp[i+2],dp[i]+ abs(h[i+2]-h[i]));
		//chmin(&dp[i+1],dp[i]+ abs(h[i+1]-h[i]));				
		//chmin(&dp[i+2],dp[i]+ abs(h[i+2]-h[i]));
	}
	printf("%d\n",dp[N-1]);
 return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define C 0.5772156649
#define pi acos(-1.0)
#define ll long long
#define mod 1000000007
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1

using namespace std;

const double g=10.0,eps=1e-7;
const int N=1000+10,maxn=60000+10,inf=0x3f3f3f;

map<int,int>ma;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<=n;i++)
        for(int j=0;j<=m;j++)
            ma[i*m+j*n-2*i*j]=1;
    if(k%n==0||k%m==0||ma[k])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}
/********************

********************/


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

int main(void){
    string s;
    string t;
    cin>>s;
    cin>>t;
    map<char, vector<int> > mp;
    rep(i, s.size()){
        mp[s[i]].push_back(i);
        mp[s[i]].push_back(i+s.size());
    }
    for(char i ='a'; i <='z'; i++){
        if(mp[i].empty()) continue;
        sort(mp[i].begin(), mp[i].end());
    }
    
    ll ans=0;
    ll bef=-1;
    rep(i, t.size()){
        if(mp[t[i]].empty()){
            cout<<-1<<endl;
            return 0;
        }
        auto p=upper_bound(mp[t[i]].begin(), mp[t[i]].end(), bef);
        ll idx=(ll)*p;
        ans+=(idx-bef);
        bef=idx;
        if(idx>=s.size()) bef-=(ll)(s.size());
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1728
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

int a[10][10];
int rem, n;
bool big(int x, int y, int r){
    bool res = true;
    if(x - 2 < 0 || x + 2 >= 10 || y - 2 < 0 || y + 2 >= 10)return false;
    for(int i = x - 2;i <= x + 2;i++)
	for(int j = y - 2;j <= y + 2;j++)
	    if(abs(x - i) + abs(y - j) <= 2){		
		a[i][j] += r;
		rem += r;
		if(a[i][j] < 0)res = false;
	    }
    if(!res)big(x, y, -r);
    return res;
}

bool small(int x, int y, int r){
    bool res = true;
    if(x - 1 < 0 || x + 1 >= 10 || y - 1 < 0 || y + 1 >= 10)return false;
    for(int i = x - 1;i <= x + 1;i++)
	for(int j = y - 1;j <= y + 1;j++)
	    if(abs(x - i) + abs(y - j) <= 1){
		a[i][j] += r;
		rem += r;
		if(a[i][j] < 0)res = false;
	    }
    if(!res)small(x, y, -r);
    return res;
}

bool middle(int x, int y, int r){
    bool res = true;
    if(x - 1 < 0 || x + 1 >= 10 || y - 1 < 0 || y + 1 >= 10)return false;
    for(int i = x - 1;i <= x + 1;i++)
	for(int j = y - 1;j <= y + 1;j++){
	    a[i][j] += r;
	    rem += r;
	    if(a[i][j] < 0)res = false;
	}
    if(!res)middle(x, y, -r);
    return res;
}

typedef pair<int, int> P;
typedef pair<P, int> T;

vector<T> ans;

bool solve(int n,int p = 0, int q = 0){
    if(rem > 13 * n)return false;
    if(p - 2 >= 0 && q - 1 >= 0 && a[p - 2][q - 1])return false;
//    if(p - 1 >= 0 && q - 2 >= 0 && a[p - 1][q - 2])return false;
    for(int i = 0;i < 10;i++){
	for(int j = 0;j < 10;j++){
	    if(a[i][j] > n)return false;
	}
    }
    for(int i = p;i < 10;i++){
	for(int j = 0;j < 10;j++){
	    if(a[i][j] == 0)continue;
	    if(big(i, j, -1)){
		ans.push_back(T(P(i, j), 3));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		big(i, j, 1);
	    }
	    if(middle(i, j, -1)){
		ans.push_back(T(P(i, j), 2));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		middle(i, j, 1);
	    }
	    if(small(i, j, -1)){
		ans.push_back(T(P(i, j), 1));
		if(solve(n - 1, i, j))return true;
		ans.pop_back();
		small(i, j, 1);
	    }
	}
    }
    return (n == 0);
}

int main(){
    cin >> n;
    for(int i = 0;i < 10;i++)
	for(int j = 0;j < 10;j++){
	    cin >> a[i][j];
	    rem += a[i][j];
	}
    
    solve(n);
    for(int i = 0;i < ans.size();i++){
	cout << ans[i].first.second << " "<< ans[i].first.first << " "<<ans[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <ctime>
#include <cassert>
#include <unordered_map>
#include <fstream>
#include <random>
#include <cstring>
#include <bitset>
#include <functional>
#include <tuple>
#include <complex>
#include <chrono>
#include <climits>

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef unsigned int uint;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
// default_random_engine generator;
// mt19937 rnd(1);

const int SIGMA = 26;
const int P = 1e9 + 7;

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

    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> cnt(SIGMA);
    for (int i = 0; i < n; ++i) {
        ++cnt[s[i] - 'a'];
    }

    ll res = 1;

    for (int i = 0; i < SIGMA; ++i) {
        res *= cnt[i] + 1;
        res %= P;
    }
    res -= 1;
    if (res == -1) {
        res = P - 1;
    }

    cout << res << endl;

}


Measured memory_bytes: 512
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{
	// a b c
	// a d e
	// f b d
	// f c e
	// (a,f) (b) , (c,d) (e)	
	// (1,2) (1,3) (1,4)
	// (1,2) (2,3) (2,4)
	// (3,4) (1,3) (2,3)
	// (3,4) (1,4) (2,4)
	static int solve(int[][] A){
		int N = A.length;
		int day = 0;
		int current[] = new int[N];
		int totalRound = N * (N -1) / 2;
		int currentRound = 0;
		Set<Integer> checkUser = new HashSet<Integer>();
		for(int i = 0 ; i < N ; ++i){
			checkUser.add(i);
		}
		while(currentRound < totalRound){
			int r = 0;
			Set<Integer> moveUser = new HashSet<Integer>();
			for(int i : checkUser){
				if(current[i] >= N - 1){
					continue;
				}
				int nj = A[i][current[i]];				
				if(A[nj][current[nj]] == i){
					++r;
					moveUser.add(i);
					moveUser.add(nj);
				}
			}
			r = r / 2;
//			System.out.println(moveUser);
			Set<Integer> nextCheckUser = new HashSet<Integer>();
			for(int i : moveUser){				
				current[i]++;
				if(current[i] < N -1){
					nextCheckUser.add(i);
					nextCheckUser.add(A[i][current[i]]);					
				}
			}
			checkUser = nextCheckUser;
//			System.out.println(checkUser);
			currentRound += r;
			if(r == 0){
				return -1;
			}
			++day;
		}
		return day;
	}
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[][] = new int[N][N - 1];
		for(int i = 0 ; i < N ; ++i){
			for(int j = 0 ; j < N - 1; ++j){
				A[i][j] = sc.nextInt() - 1;
			}
		}
		int day = solve(A);
		System.out.println(day);
	}
}


Measured memory_bytes: 281944
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, x, y;
long long d;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> d;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		if (x * 1LL * x + y * 1LL * y <= d * d) cnt++;
	}
	cout << cnt << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3668
import bisect

def main():
  N,D,A=map(int,input().split())
  m=sorted([int(j) for j in input().split()] for i in range(N))

  x=[m[i][0] for i in range(N)]
  es=[0]*(N+1)
  a,c=0,0
  for i in range(N):
    c-=es[i]
    if m[i][1]>A*c:
      t=(m[i][1]-A*c+A-1)//A
      a+=t
      c+=t
      es[bisect.bisect_right(x,x[i]+2*D)]+=t
  print(a)

main()

Measured memory_bytes: 49712
local A, B, C = io.read("*n", "*n", "*n")
local price = io.read("*n")
local count = 0

for a = 0, A do
    for b = 0, B do
        for c = 0, C do
            if 500*a + 100*b + 50*c == price then
                count = count + 1
            end
        end
    end
end
print(count)

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

namespace ABC
{
    class ProgramB
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            var s1 = int.Parse(s.Substring(0, 2));
            var s2 = int.Parse(s.Substring(2, 2));

            var r1 = 0 < s1 && s1 <= 12;
            var r2 = 0 < s2 && s2 <= 12;

            if (r1 && r2)
            {
                Console.WriteLine("AMBIGUOUS");
            }
            else if (r1)
            {
                Console.WriteLine("MMYY");
            }
            else if (r2)
            {
                Console.WriteLine("YYMM");
            }
            else
            {
                Console.WriteLine("NA");
            }
        }
    }
}


Measured memory_bytes: 27488
import kotlin.comparisons.compareBy
data class XY(var x: Int, var y: Int) {
    constructor(xy: List<Int>): this(xy[0], xy[1])
}
fun main(args: Array<String>) {
    val N = nextInt()
    val R = Array(N) { XY(listOfInt()) }.sortedWith(compareBy({ -it.y }, { -it.x }))
    val B = Array(N) { XY(listOfInt()) }.sortedWith(compareBy({  it.x }, {  it.y }))
    var ans = 0
    for (b in 0 until N) {
        for (r in 0 until N) {
            if (R[r].x == -1) continue
            if (R[r].x < B[b].x && R[r].y < B[b].y) {
                R[r].x = -1
                ans += 1
                break
            }
        }
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt(d: Int = 0) = listOfString().map { it.toInt() + d }
fun listOfLong(d: Long = 0) = listOfString().map { it.toLong() + d }




Measured memory_bytes: 37932
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<tuple>


#define MOD 1000000007
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back

typedef long long ll;

using namespace std;

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

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

    int A[100001];
    char prev=S[0];
    int j=0;
    rep(i,0,N){
        if(prev==S[i])A[j]++;
        else{
            j++;
            A[j]++;
            prev=S[i];
        }
    }
    j++;
    int b=max(1,j-2*K);
    cout<<N-b;


    return 0;
}

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

#define st              first
#define nd              second
#define pb              push_back
#define lwb             lower_bound
#define upb             upper_bound
#define all(a)          (a).begin(), (a).end()
#define Reset(s, n)     memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       (a).resize(unique(all(a)) - (a).begin())
#define bit(n, i)       (((n) >> (i)) & 1)
#define cntbit(n)       __builtin_popcountll(n)

using namespace std;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const ld PI = acos((ld) -1);
const ld EPS = 1e-12;
inline bool isPrime (ll x){ if(x <= 1) return 0; if(x <= 3) return 1; if (!(x % 2) || !(x % 3)) return 0; ll s = sqrt(1.0 * x) + EPS; for(ll i = 5; i <= s; i += 6){if (!(x % i) || !(x % (i + 2))) return 0;}return 1;}
inline ll fpow(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = r * n % p; n = n * n % p;} return r;}
inline int inv(int a, ll p = MOD) {return fpow(a, p - 2, p);}
inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline void onbit(ll &a, int i){a |= 1LL << i;}
inline void offbit(ll &a, int i){onbit(a, i), a -= (1LL << i);}

const int N = 1e6 + 5;

ll n, m, k;
ll a[N], b[N];

void solve(){
   cin >> n;
   cout << 2 * PI * n;

}

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   cout << fixed << setprecision(10);
   //    freopen("input.txt", "r", stdin);
   //    freopen("output.txt", "w", stdout);
   int query = 1;
   // cin >> query;
   int start = 1000 * clock() / CLOCKS_PER_SEC;
   while(query--) solve();
   cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC  - start << "ms\n";
}


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

void Main()
{
  int N;
  cin >> N;
  vector<ll> a(N);
  ll maxnum = 0;
  rep(i,N) {cin >> a[i]; maxnum += a[i]-1;}
  cout << maxnum << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
long long b[100010];
vector<pair<long long,long long> > v;
int main(){
	long long n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		v.push_back(make_pair(a[i],b[i]));
	}
	sort(v.begin(),v.end());
	long long cnt=0;
	for(int i=0;i<v.size();i++){
		if(m<v[i].second){
			cnt+=v[i].first*m;
			m=0;
			break;
		}
		else if(m>=v[i].second){
			cnt+=v[i].first*v[i].second;
			m-=v[i].second;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


int main(){

  int n;
  cin >> n;
  
  if(n/10 == 9 || n % 10 == 9) cout << "Yes" << endl;
  else cout << "No" << endl;

 return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    int n = input();
    int r = n%10;
    if(r == 2 or r == 4 or r == 5 or r == 7 or r == 9) cout << "hon";
    else if(r == 0 or r == 1 or r == 6 or r == 8) cout << "pon";
    else cout << "bon";
}

Measured memory_bytes: 3652
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>
#include <numeric>
#include <math.h>

#define LOOP(N) for(int i=0; i<(N); ++i)
#define REP(i, N) for(int i=0; i<(N); ++i)
#define FOR(i, start, end) for(int i=(start); i<(end); ++i)

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using Graph = vector< vector<int> >;


int main() {
    int a; cin >> a;
    if (a < 3200) {
        cout << "red";
    } else {
        string s;
        cin >> s;
        cout << s;
    }
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t; using i64 = int64_t; using f64 = double_t; using str = string;
template <typename T> using vec = vector<T>;
template <typename T> using heap = priority_queue<T, vec<T>, greater<T>>;
#define times(n, i) for (i32 i = 0; i < (n); ++i)
#define range(a, b, i) for (i32 i = (a); i < (b); ++i)
#define upto(a, b, i) for (i32 i = (a); i <= (b); ++i)
#define downto(a, b, i) for (i32 i = (a); i >= (b); --i)
#define stepup(a, b, s, i) for (i32 i = (a); i <= (b); i+=(s))
#define stepdown(a, b, s, i) for (i32 i = (a); i >= (b); i-=(s))
#define foreach(xs, x) for (auto &x : (xs))
#define all(xs) (xs).begin(), (xs).end()
#define sortall(xs) sort(all(xs))
#define reverseall(xs) reverse(all(xs))
#define uniqueall(xs) (xs).erase(unique(all(xs)), (xs).end())
#define maximum(xs) (*max_element(all(xs)))
#define minimum(xs) (*min_element(all(xs)))
#define even(x) (((x) & 1) == 0)
#define odd(x) (((x) & 1) == 1)
#define append emplace_back
const i64 MOD = 1000000007;

i64 n,m;

i32 main()
{
    cin >> n >> m;
    i64 ans = min(n, m/2);
    ans += max(i64(0), (m - ans*2)/4);

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

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

using namespace std;

int main(){
	int t,l;
	cin>>t>>l;
	string a[t];
	for(int i=0;i<t;i++){
		cin>>a[i];
	}
	sort(a,a+t);
	for(int i=0;i<t;i++){
		cout<<a[i];
	}
}



Measured memory_bytes: 3648
n = int(input())
l = []
for i in range(n):
    l.append(int(input()))
sorted_l = sorted(l)  # nlogn (n=2e5)
mmm = sorted_l[-1]
only = mmm != sorted_l[-2]
for p in l:
    if not only or p != mmm:
        print(mmm)
    else:
        print(sorted_l[-2])


Measured memory_bytes: 70104
x,y=[int(j) for j in input().split()]
if x==1 and y==1:
    print(1000000)
    exit()
ans=0
if x==1:
    ans+=300000
elif x==2:
    ans+=200000
elif x==3:
    ans+=100000
if y==1:
    ans+=300000
elif y==2:
    ans+=200000
elif y==3:
    ans+=100000
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[100003];
        for (int i = 0; i < n; i++) {
            int m = sc.nextInt();
            a[m]++;
            a[m + 1]++;
            a[m + 2]++;
        }
        int ans = 0;
        for (int i = 0; i < 100003; i++) {
            ans = Math.max(ans, a[i]);
        }
        System.out.println(ans);

    }
}

Measured memory_bytes: 48688
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <deque>
#include <bitset>
#include <regex>
#include <cassert>
#include <set>
#include <map>
using namespace std;
#define inf 2000000000
#define mod 1000000007
int gcd(int a, int b){
	if(b == 0) return a;
	return gcd(b, a%b);
}
int ans;
int main() {
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				ans += gcd(gcd(i,j),k);
			}
		}
	cout << ans;
}

Measured memory_bytes: 3680
#include <stdio.h>
#define N 100
#define INF 100000000

int G[N+1][N+1], vis[N+1], n, size[N+1];

void dfs(int p, int t){
  int i;
  vis[p] = t;
  for(i=1;i<=size[p];i++) if(t + 1 < vis[G[p][i]]) dfs(G[p][i], t + 1);
}

main(){
  int i, j, u;
  scanf("%d", &n);
  for(i=1;i<=n;i++){
    vis[i] = INF;
    scanf("%d", &u);
    scanf("%d", &size[u]);
    for(j=1;j<=size[u];j++) scanf("%d", &G[u][j]);
  }
  dfs(1, 0);
  for(i=1;i<=n;i++) printf("%d %d\n", i, (vis[i] == INF) ? -1 : vis[i]);
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>
#include<iomanip>

using namespace std;

struct Point{double x,y;};

void koch(int n,Point a,Point b){
  if(n==0) return;
  Point s,t,u;
  double th=M_PI*60.0/180.0;
  s.x=(2.0*a.x+1.0*b.x)/3.0;
  s.y=(2.0*a.y+1.0*b.y)/3.0;
  t.x=(1.0*a.x+2.0*b.x)/3.0;
  t.y=(1.0*a.y+2.0*b.y)/3.0;
  u.x=(t.x-s.x)*cos(th)-(t.y-s.y)*sin(th)+s.x;
  u.y=(t.x-s.x)*sin(th)+(t.y-s.y)*cos(th)+s.y;

  koch(n-1,a,s);
  cout << s.x << " " << s.y << endl;
  koch(n-1,s,u);
  cout << u.x << " " << u.y << endl;
  koch(n-1,u,t);
  cout << t.x << " " << t.y << endl;
  koch(n-1,t,b);
}

int main(){
  cout << fixed << setprecision(10);
  Point p1,p2;p1.x=0;p1.y=0;p2.x=100;p2.y=0;
  int n;cin >> n;
  cout << p1.x << " " << p1.y << endl;
  koch(n,p1,p2);
  cout << p2.x << " " << p2.y << endl;
}



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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int N; cin >> N;
  vector<int> ans(N+1,0);
  for (int x = 1; x * x < N; x++) {
    for (int y = 1; y * y < N; y++) {
      for (int z = 1; z * z < N; z++) {
        int buf = x*x + y*y + z*z + x*y + y*z + z*x;
        if(buf <= N) ans[buf]++; 
      }
    }
  }
  rep(i, N+1) {
    if(i==0) continue;
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
 
using namespace std;
 
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define f first
#define s second
#define getunique(v) {sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end());}
typedef long long ll;
typedef long double lld;
typedef unsigned long long ull;
 
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v);
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
	cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
template<typename A, typename B> istream& operator>>(istream& cin, pair<A, B> &p) {
	cin >> p.first;
	return cin >> p.second;
}
 
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
// mt19937 rng(61378913);
/* usage - just do rng() */
 
void usaco(string filename) {
  // #pragma message("be careful, freopen may be wrong")
	freopen((filename + ".in").c_str(), "r", stdin);
	freopen((filename + ".out").c_str(), "w", stdout);
}
 
const lld pi = 3.14159265358979323846;
const ll mod = 1000000007;
// const ll mod = 998244353;
// ll mod;
 
 
 
ll n, m, k, q, l, r, x, y, z;
const ll template_array_size = 1e6 + 1389;
ll a[template_array_size];
ll b[template_array_size];
ll c[template_array_size];
string s, t;
ll ans = 0;
 

 
void solve(int tc = 0) {
	cin >> n;
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (ll i = 0; i < n; i++) {
		cin >> b[i];
	}
	
	reverse(b, b + n);
	
	ll lpt = 0, rpt = n - 1;
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			if (b[lpt] != b[i] && a[lpt] != b[i]) {
				swap(b[i], b[lpt]);
				++lpt;
			} else if (b[rpt] != b[i] && a[rpt] != b[i]) {
				swap(b[i], b[rpt]);
				--rpt;
			} else {
				cout << "No\n";
				return;
			}
		}
	}
	
	for (ll i = 0; i < n; i++) {
		if (a[i] == b[i]) {
			cout << "No\n";
			return;
		}
	}
	
	cout << "Yes\n";
	for (ll i = 0; i < n; i++) {
		cout << b[i] << " ";
	}
	cout << '\n';
}
 
int main() {
	#ifdef galen_colin_local
		auto begin = std::chrono::high_resolution_clock::now();
	#endif
	
	send help
 
	#ifndef galen_colin_local
		// usaco("moop");
	#endif
	
	// usaco("cowland");
	
	// freopen("tc.cpp", "r", stdin);
 
	int tc = 1;
	// cin >> tc;
	for (int t = 0; t < tc; t++) solve(t);
	
	#ifdef galen_colin_local
		auto end = std::chrono::high_resolution_clock::now();
		cout << setprecision(4) << fixed;
		// cout << "Execution time: " << std::chrono::duration_cast<std::chrono::duration<double>>(end - begin).count() << " seconds" << endl;
	#endif
} 

Measured memory_bytes: 6736
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
const int INF = 1001001001;


int main(){
    int n, c;
    cin >> n >> c;
    vector<vector<int>> d(c, vector<int>(c));
    vector<vector<int>> col(n, vector<int>(n));
    
    rep(i, c) rep(j, c) cin >> d[i][j];
    rep(i, n) rep(j, n) {
        cin >> col[i][j];
        col[i][j]--;
    }
    

    vector<vector<int>> num(c, vector<int>(3));
    rep(i, n) rep(j, n) {
        num[col[i][j]][(i+j)%3]++;
    }
    

    vector<vector<int>> diff(c, vector<int>(3));

    rep(i, c) rep(j, 3) {
        rep(k, c) {
            diff[i][j] += num[k][j] * d[k][i];
        }
    }

    int ans = INF;

    rep(i, c) rep(j, c) rep(k, c) {
        if (i==j || j==k || i==k) continue;
        chmin(ans, diff[i][0]+diff[j][1]+diff[k][2]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1280
import itertools as it

N = int(input())
A = [int(i) for i in range(1,N+1)]
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

V = it.permutations(A)
i = 0
for v in V:
  if v == P:
    a = i
  if v == Q:
    b = i
  i += 1
print(abs(a-b))

Measured memory_bytes: 3064
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;



int main(int argc, char* argv[])
{
    long n;
    scanf("%ld", &n);

    vector<long> a(n);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &a[i]);
    }

    for(i=n-1; i>=0; i-=2) {
        printf("%ld ", a[i]);
    }
    for(i=n%2; i<n; i+=2) {
        printf("%ld ", a[i]);
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 3712
#include<iostream>

using namespace std;

int main(){
    int a,b,c;
    //cout << "Please input numbers a,b,c" << endl;
    cin >> a >> b >> c;
    if(a < b && b < c){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
     }
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

ll gcd(ll a, ll b)
{
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int main()
{
    ll N, X;
    cin >> N >> X;
    vec x(N);
    REP(i,0,N) cin >> x[i];

    ASC(x);
    ll s = lower_bound(ALL(x), X) - x.begin() - 1;
    ll d;
    if(s >= 0) d = abs(X - x[s]);
    else d = abs(X - x[0]);
    for(ll i=s; i>=1; --i) d = gcd(d, abs(x[i]-x[i-1]));
    if(s+1<N) {
        d = gcd(d, abs(x[s+1]-x[0]));
        REP(i,s+1,N-1) d = gcd(d, abs(x[i+1]-x[i]));
    }
    PR(d);

    return 0;
}

/*



*/

Measured memory_bytes: 3920
# coding: utf-8
# Your code here!

nums=list(map(int,input().split()))
k = nums[0]
s = nums[1]

sm = 0
upper = 0
lower = 0
left = max(s-k*2, 0)
right = min(s, k)

for x in range(left, right + 1):
    upper = min(s-x, k)
    lower = max(s-k-x, 0)
    sm += upper - lower + 1
    
print(sm)














Measured memory_bytes: 39152
/*
AizuOJ ALDS1_11_C

???;BFS;????´¢;?????????;?¨????
*/
#include <queue>
#include <cstring>
#include <cstdio>
using namespace std;

const int MAXN=110, MAXM=110*110, INF=0x3f3f3f3f;
int n;
int adj[MAXN]; // 1 .. n
int to[MAXM], enext[MAXM]; // 1 .. m
int d[MAXN];

int s, v;
void bfs(int start) {
    queue<int> q;
    q.push(start);
    while (!q.empty()) {
        s=q.front();
        q.pop();
        for (int e=adj[s]; e!=0; e=enext[e]) {
            v=to[e];
            if (d[v]>d[s]+1) {
                d[v]=d[s]+1;
                q.push(v); // ?????????????????? !visited
            }
        }
    }
}

void add_edge(int no, int u, int v) {
    to[no]=v;
    enext[no]=adj[u];
    adj[u]=no;
}

int m=0, k, tmp;
//int v;
int main() {
    memset(d, INF, sizeof(d));
    d[1]=0;
    scanf("%d", &n);
    for (int u=1; u<=n; u++) {
        scanf("%d%d", &tmp, &k);
        while (k--) {
            scanf("%d", &v);
            add_edge(++m, u, v);
        }
    }
    bfs(1);
    for (int u=1; u<=n; u++) {
        printf("%d %d\n", u, d[u]==INF ? -1 : d[u]);
    }
    return 0;
}

Measured memory_bytes: 2768
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = double;
const ld eps = 1e-9;

#define Seg_Max_N (1<<19) 

using Value = long long int;
const Value ini =-1e18;
struct segtree {
	int N;
	vector<Value>dat;

	segtree() {}
	segtree(int n) :dat(2 * Seg_Max_N) {
		N = 1;
		while (N < n) N *= 2;
		for (int i = 0; i < 2 * N - 1; i++) {
			dat[i] = ini;
		}
	}
	Value connect(const Value&l, const Value&r) {
		return max(l,r);
	}
	// update k th element
	void update(int k, Value a) {
		k += N - 1;
		dat[k] = a;

		while (k > 0) {
			k = (k - 1) / 2;
			const Value al(dat[k * 2 + 1]);
			const Value ar(dat[k * 2 + 2]);
			dat[k] = connect(al, ar);
		}
	}
	// min [a, b)
	Value  query(int a, int b) { return query(a, b, 0, 0, N); }
	Value  query(int a, int b, int k, int l, int r) {
		if (r <= a or b <= l) return ini;
		if (a <= l and r <= b) return dat[k];
		const int m = (l + r) / 2;
		const Value al(query(a, b, k * 2 + 1, l, m));
		const Value ar(query(a, b, k * 2 + 2, m, r));
		return connect(al, ar);
	}
};

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

	//size,value
	vector<pair<long long int,long long int>>ps;
	vector<long long int>v;
	for (int i = 0; i < N; ++i) {
		long long int a,b;scanf("%lld %lld",&a,&b);
		ps.emplace_back(a,b);
		v.push_back(a);
	}
	sort(v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	map<long long int,int>mp;
	vector<long long int>revmp(v.size());
	for (int i = 0; i < v.size(); ++i) {
		mp[v[i]]=i;
		revmp[i]=v[i];
	}
	for (auto &p : ps) {
		p.first=mp[p.first];
	}

	vector<long long int>sas(v.size()-1);
	for (int i = 0; i < v.size()-1; ++i) {
		sas[i]=revmp[i+1]-revmp[i];
	}
	vector<long long int>arts(v.size());
	for (auto& p : ps) {
		arts[p.first]+=p.second;
	}

	segtree seg(v.size());
	seg.update(0,0);
	vector<long long int>as(N);
	for (int i = 0; i < v.size()-1; ++i) {
		long long int x= seg.query(i, i + 1) + arts[i + 1] - sas[i];
		seg.update(i+1,x);
		as[i+1]=x;
	}

	long long int ans=0;
	for (int i = 0; i < v.size(); ++i) {
		ans=max(ans,arts[i]+seg.query(i,v.size())-as[i]);
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 69876
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount



string t;


int32_t main(){
INIT
cin>>t;

for(int i=0; i<t.length(); i++){
    if(t[i]=='?'){
        if(i==0){
            t[i]='D';}
            else{

            if(t[i-1]=='P'){
                t[i]='D'; continue;
            }else{
            t[i]='D';}

            }

        if(i==t.length()-1){
            t[i]='D';
        }
        else{
            if( (t[i+1])=='D' ){
                t[i]='P';
            }
        }
    }
}

cout<<t;

return 0;
}


Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int ans = (n-1)/2;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    string s,t,n;
    cin>>s>>t;
    n="";
    for(int i=0;i<t.size()-1;i++){
        n=n+t[i];
    }
    if(s==n){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
}



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

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


    int A, B;

    cin >> A >> B;

    if ((A - 2 * B) <= 0)
    {
        cout << 0;
    }
    else
    {
        cout << (A - 2 * B);
    }

    return 0;
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

int main() {
  int D,E;
  while( cin >> D >> E, D | E ) {
    double mini = DBL_MAX;
    rep(x,D+1) {
      int y = D - x;
      double cost = fabs(sqrt(x*x+y*y)-(double)E);
      if( !equals(cost,mini) && mini > cost ) mini = cost;
    }
    printf("%.10f\n",mini);
  }
  return 0;
}

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

int main() {
    
    char x;
    cin >> x;
    
    if (x == 'a' || x == 'i' || x == 'u' || x == 'e' || x == 'o'){
        cout << "vowel" << endl;
    }
    else{
        cout << "consonant" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cstdlib>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;
const int MOD = 1000000007;

long long mod(long long val, long long m) {
  long long res = val % m;
  if (res < 0) res += m;
  return res;
}

bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
  int N,ans;
  cin >> N;
  ans = pow(N,3);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 4072
// C++ program of a space optimized DP solution for 
// 0-1 knapsack problem. 
#include<bits/stdc++.h> 
#define ll long long int
using namespace std; 

ll max(ll a,ll b){
return a>b?a:b;
}

ll min(ll a,ll b){
return a>b?b:a;
}

// Driver program to test the cases 
int main() 
{ 
	ll n,W,i,j;
    cin>> n >> W;
    ll val[n+1],wt[n+1];
    for(i=0;i<n;i++) 
    cin >> wt[i] >> val[i];
    
    ll sum=0;
	for(int i=0;i<n;i++)
	sum+=val[i];
	
	ll dp[sum+1]; // min total weight of items having this value. 
	// since weight dimensions is large. consider array of value. exactly opposite to  -https://www.geeksforgeeks.org/space-optimized-dp-solution-0-1-knapsack-problem/
	
	for(ll i=0;i<=sum;i++)
	dp[i] = INT_MAX;
	
	dp[0] = 0;

	// iterate through all items 
	for(ll i=0; i < n; i++) {
		//traverse dp array from right to left backwards bcoz, suppose to calculate dp[8] for 2nd coins(having value 4) we need result of dp[4] of 1st coin. if we go forward, we will get result of 2nd coin itself. 
		for(ll j=sum; j>=val[i]; j--)  
			dp[j] = min(dp[j], wt[i] + dp[j-val[i]]);
	}

	ll ans=0;
	for(ll i=0;i<=sum;i++) {
	    if(dp[i]<=W)  {
	    ans=max(ans,i);
	    }
	}
	cout << ans; 
    
    
} 


Measured memory_bytes: 1024
from itertools import permutations

N = int(input())

R = set()
G = set()
B = set()
for i, s in enumerate(input(), start=1):
    if s == 'R':
        R.add(i)
    if s == 'G':
        G.add(i)
    if s == 'B':
        B.add(i)

ans = len(R) * len(G) * len(B)

def calc(A, B, C):
    ret = 0
    for a in A:
        for b in B:
            c = 2 * a - b
            if c in C:
                ret += 1
    return ret

ans -= calc(R, G, B)
ans -= calc(G, B, R)
ans -= calc(B, R, G)

print(ans)


Measured memory_bytes: 73740