akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
  	/* memo
	L(N) を昇順に sort
	L[0] L[1] L[2] ... L[N-3] L[N-2] L[N-1]
	0 <= i < j <= N-2
	table[i][j] = L[i] + L[j]

	すべての (i,j) に対して 
	j < k 
	table[i][j] < L[k]
	なる k がいくつあるか？を数える. 

	2分探索. 
	l = j+1 // table[i][j] > L[l]; OK
	r = N-1 // table[i][j] <= L[r]; NG
	while(r-l>1){
		m = (l+r)/2;
		table[i][j] > L[m] -> l = m;
		table[i][j] <= L[m] -> r = m;
	}
	*/
  
  	int N;
  	cin >> N;
  	vector<int>L(N);
  	rep(i,N) cin >> L[i];
  		
  	sort(L.begin(),L.end());
  	
  	vector<vector<int>> table(N, vector<int>(N));
  	rep3(i,0,N-3){
  		rep3(j,i+1,N-2){
      		table[i][j] = L[i] + L[j];
        }
    }
  	
  	int l, r, m;
  	ll count = 0;
  	rep3(i,0,N-3){
		rep3(j,i+1,N-2){
     		l = j+1;
          	r = N-1;
          	if(table[i][j] <= L[l]){
            	;
            }
          	else if(table[i][j] > L[r]){
            	count += (N-j-1);
                //cout << "i = " << i << ", j = " << j;
            	//cout << ", l = " << l << ", r = " << r;
				//cout << ", l-j = " << N-j-1 << endl;
            }
			else{
              	while(r-l>1){
             		m = (l+r)/2;
            		if(table[i][j] > L[m]){ l = m; }
					else{ r = m; }		
            	}
          		count += (l-j);
          		//cout << "i = " << i << ", j = " << j;
            	//cout << ", l = " << l << ", r = " << r;
				//cout << ", l-j = " << l-j << endl;
            }
        }
    }
  	cout << count << endl;
  
	return;
}

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




Measured memory_bytes: 16000
class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]
        self.member_num = [1 for _ in range(size)]

    #representative
    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        m1=self.member_num[s1]
        m2=self.member_num[s2]
        if s1 != s2:
            if m1 != m2:
                if m1 < m2:
                    self.table[s1] = s2
                    self.member_num[s2]=m1+m2
                    return [m1,m2]
                else:
                    self.table[s2] = s1
                    self.member_num[s1]=m1+m2
                    return [m1,m2]
            else:
                self.table[s1] = -1
                self.table[s2] = s1
                self.member_num[s1] = m1+m2
                return [m1,m2]
        return [0,0]

N,M = list(map(int,input().split()))
uf = UnionFind(N)
count = 0
for i in range(M):
    A,B = list(map(int,input().split()))
    A,B = A-1,B-1
    if uf.find(A)!=uf.find(B):
        uf.union(A,B)
        count+=1

B = set()

for i in range(N):
    B.add(uf.find(i))

print(len(B)-1)

Measured memory_bytes: 82072
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

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

template<class T> inline bool chmin(T& a,T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if (a < b) {a = b; return true;} return false;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  ll N, K; cin >> N >> K;
  vector<P> array(N);
  rep(i, N){
    cin >> array[i].first >> array[i].second;
  }
  sort(array.begin(), array.end());

  ll ans = 0;
  ll tot = 0;
  rep(i, N){
    tot += array[i].second;
    if (tot >= K) {
      ans = array[i].first;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const ll N=5100,XJQ=1e9+7;
struct node{
	ll to,next;
}a[N*2];
ll n,tot,ls[N],siz[N],f[N][N],ans,g[N],fac[N];
void addl(ll x,ll y){
	a[++tot].to=y;
	a[tot].next=ls[x];
	ls[x]=tot;
}
void dp(ll x,ll fa){
	siz[x]=f[x][1]=1;
	for(ll i=ls[x];i;i=a[i].next){
		ll y=a[i].to;
		if(y==fa)continue;
		dp(y,x);
		for(ll i=1;i<=siz[x];i++)
			g[i]=f[x][i],f[x][i]=0;
		for(ll j=1;j<=siz[x];j++){
			for(ll k=1;k<=siz[y];k++){
				(f[x][j+k]+=f[y][k]*g[j]%XJQ)%=XJQ;
				if((k&1)==0)
					(f[x][j]+=XJQ-f[y][k]*g[j]%XJQ*fac[k-1]%XJQ)%=XJQ;
			}
		}
		siz[x]+=siz[y];
	}
	return;
}
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<n;i++){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		addl(x,y);addl(y,x);
	}
	fac[0]=fac[1]=1;
	for(ll i=2;i<=n;i++)
		fac[i]=fac[i-2]*i%XJQ;
	dp(1,1);
	for(ll i=2;i<=n;i++)
		ans=(ans+f[1][i]*fac[i-1]%XJQ)%XJQ;
	printf("%lld",ans);
}

Measured memory_bytes: 90632
import itertools
cards = []
player = ["a","b","c"]
for  _ in range(3):
    S = input()
    S = list(S)
    cards.append(S)
sute = "a"
turn = 0
while True:

    card = cards[turn]

    if len(card) == 0:
        print(player[turn].upper())
        break

    sute = card.pop(0)
    turn = player.index(sute)







Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<typename T> inline istream& operator>>(istream &i, vector<T> &v) {rep(j, size(v)) i >> v[j]; return i;}
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; }
template<class T> T gcd(T a, T b) {if(b==0)return a; else return gcd(b,a%b);}
template<class T> T lcm(T a, T b) {return a/gcd(a,b)*b;}
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c)) << endl;
}

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

import sys
from bisect import bisect_right

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
P = [p-1 for p in LIST()]
X = LIST()

nodes = [[] for i in range(N)]
for i, p in enumerate(P):
    nodes[p].append(i+1)

# W[(i, j)] := (自分を根とした木の自分側の色の重み, 反対側の色の重み)
W = [None] * N
def calc(u):
    # 葉はどうするか確定
    if not nodes[u]:
        return (X[u], 0)

    A = []
    total = 0
    for v in nodes[u]:
        A.append(W[v])
        total += W[v][0] + W[v][1]
    # 自分の子の色をどうするかは自由に決められるはずなので、
    # 部分和を列挙して、一番いい(親に戻す重みが少なくて済むような)値を使う
    n = len(A)
    dp = [set() for i in range(n+1)]
    dp[0].add(0)
    for i in range(n):
        a, b = A[i]
        for s in dp[i]:
            dp[i+1].add(s+a)
            dp[i+1].add(s+b)
    B = sorted(dp[n])
    idx = bisect_right(B, X[u]) - 1
    # 自分の予定量より大きい重みしかなければNG
    if idx == -1:
        print('IMPOSSIBLE')
        exit()
    a, b = X[u], total - B[idx]
    return (a, b)

def rec(u, prev):
    for v in nodes[u]:
        rec(v, u)
    W[u] = calc(u)
rec(0, -1)
print('POSSIBLE')


Measured memory_bytes: 111900
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();

        int n = sc.nextInt();
        var d = new int[n];
        for (int i = 0; i < n; i++)
        {
            d[i] = sc.nextInt();
        }

        long ans = 0;

        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (i <= j) continue;
                ans += (d[i] * d[j]);
            }
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;

int main(){

    int a, b, c, d;
    int start, end;
    cin >> a >> b >> c >> d;

    if (b > d) {
        end = d;
    }
    else {
        end = b;
    }
    if (a > c) {
        start = a;
    }
    else {
        start = c;
    }
    if ((end - start) < 0) cout << 0 << endl;
    else cout<< (end - start) << endl;


    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        char[] carr = br.readLine().toCharArray();
        int len = carr.length;
        int res = 0;
        int i = 0;
        int j = len-1;
        while(i < j){
            char left = carr[i];
            char right = carr[j];
            if(left == right){
                ++i;
                --j;
                continue;
            }
            if(left != 'x' && right != 'x'){
                System.out.println(-1);
                return;
            }
            else if(left == 'x'){
                ++res;
                ++i;
            }
            else if(right == 'x') {
                ++res;
                --j;
            }
        }
        System.out.println(res);
    }
}

Measured memory_bytes: 34788
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
static const ll MOD = (ll)1e9 + 7;
static const double EPS = 1e-9;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

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

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N, K;
    in >> N >> K;
    ll ans = 0;
    if (N > K) N = N % K;
    ans = min(N, K-N);
    out << ans << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
ll a[200005];
ll s[200005];


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  cin>>n;
  rep(i,n) cin>>a[i], a[i]-=(i+1);
  
  SORT(a,n);
  rep(i,n) s[i+1]=s[i]+a[i];
  
  ll ans=LINF;
  rep(i,n){
    ll tmp=abs(s[i+1]-a[i]*(i+1))+abs(s[n]-s[i+1]-a[i]*(n-i-1));
    chmin(ans,tmp);
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using vll = vector<ll> ;
#define all(v) v.begin(),v.end()


int main(){
  ll N,M;cin>>N>>M;
  vector<int> A(M);rep(i,M)cin>>A[i];
  int stick[10]{0,2,5,5,4,5,6,3,7,6};
  vector<bool> flag(10,false);
  rep(i,M)flag[A[i]]=true;
  for(int i=0;i<M-1;++i)for(int j=i+1;j<M;++j){
    if(stick[A[i]]==stick[A[j]]){
      if(A[i]>A[j]) flag[A[j]]=false;
      else flag[A[i]]=false;
    }
  }
  flag[0]=false;
  vector<pair<int,int>> num;
  rep(i,10){
    if(flag[i]){num.emplace_back(i,stick[i]);}
  }
  int dp[20000];
  fill(dp,dp+20000,-1e9);
  sort(all(num),[&](auto const& a,auto const& b){return a.first>b.first;});
  dp[0]=0;
  rep(i,10010){
    rep(j,num.size()){
      dp[i+num[j].second] = max(dp[i+num[j].second],dp[i]+1);
    }
  }
  int tmp=N;
  vector<int> v;
  while(tmp>0){
    rep(i,num.size()){
      //cout << "loopcheck i" << i << num[i].first << endl;
      if(tmp-num[i].second>=0 && dp[tmp-num[i].second] == dp[tmp]-1){
        tmp -= num[i].second;
        v.push_back(num[i].first);
        break;
      }
    }
  }
  //rep(i,20)cout<<"i " << i << "dp " << dp[i] << endl;
  sort(all(v),greater<int>());
  rep(i,v.size()) cout<<v[i];
  cout<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int w,h,n;
  cin >> w >> h >> n;
  Vi xin(1,0),xout(1,w),yin(1,0),yout(1,h);
  int a,b,c,d;
  rep(i,0,n){
    cin >> a >> b >> c;
    if(c==1) xin.pb(a);
    if(c==2) xout.pb(a);
    if(c==3) yin.pb(b);
    if(c==4) yout.pb(b);
  }
  sort(ALL(xin));
  reverse(ALL(xin));
  sort(ALL(xout));
  sort(ALL(yin));
  reverse(ALL(yin));
  sort(ALL(yout));
  
  a = xin[0],b=xout[0],c=yin[0],d=yout[0];
  
  cout << max(b-a,0LL)*max(d-c,0LL) << endl;
}


Measured memory_bytes: 256
/*
拼图最终一定被分成了若干个连续的部分，这里连续的定义是相邻的2个拼图拼在一起。对于一个连续的部分1 ~ N，需要满足的条件是：
C[1] = 0   D[N] = 0   对于相邻的两个拼图i和i + 1，D[i] = A[i + 1]且C[i + 1] = 0 或 B[i] = C[i + 1]且D[i] = 0
定义一个拼图的两个属性P和Q：
当C[i] = 0时，P[i] = A[i]；当C[i] > 0时，P[i] = -C[i]
当D[i] = 0时，Q[i] = -B[i]；当D[i] > 0时，Q[i] = D[i]
可以观察到这么几个性质：
(1)因为A[i] > 0且B[i] > 0，所以C[i] != 0且D[i] != 0
(2)两个拼图i和i + 1能拼接起来的条件等价于Q[i] = P[i + 1]
(3)C[1] = 0等价于P[1] > 0，D[N] = 0等价于Q[N] < 0
根据此可以建图，把每个权值当成一个点，一个拼图是一条P[i] -> Q[i]的有向边，所有> 0的点可以作为路径起点，所有< 0的点可以作为路径终点
一个合法的方案，对应的是若干条合法的路径，满足每条边被覆盖了恰好一次
可以考虑把所有路径顺次排列成一个环，每条路径的终点往下一条路径的起点连一条边。那么这个方案对应了新图的一条欧拉回路
只要能构造出存在这样欧拉回路的图，就能构造出合法的方案。直接根据度数判断能否令底图联通且每个点都满足入度 = 出度即可 
*/

#include <map>
#include <cstdio>

using namespace std;
const int Max_N(100050);
const int Max_H(205);

int N, H, P, Q, Sum1, Sum2, Fa[Max_H << 1], *Father = Fa + Max_H;
bool Ha[Max_H << 1], *Have = Ha + Max_H;
map<int, int> In, Out;

int Get_Father(int x)
{
	return Father[x] == x ? x : Father[x] = Get_Father(Father[x]);
}

int main()
{
	scanf("%d%d", &N, &H);
	for (int x = -H;x <= +H;++x)
		Father[x] = x;
	for (int i = 1, A, B, C, D, P, Q;i <= N;++i)
	{
		scanf("%d%d%d%d", &A, &B, &C, &D);
		if (C == 0)
			P = A;
		else
			P = -C;
		if (D == 0)
			Q = -B;
		else
			Q = D;
		//P -> Q
		++In[Q], ++Out[P], Father[Get_Father(P)] = Get_Father(Q);
	}
	for (int x = -H;x <= -1;++x)
	{
		if (Out[x] > In[x])
		{
			puts("NO");
			return 0;
		}
		if (In[x] - Out[x])
			Sum1 += In[x] - Out[x], Have[Get_Father(x)] = true;
	}
	for (int x = +1;x <= +H;++x)
	{
		if (In[x] > Out[x])
		{
			puts("NO");
			return 0;
		}
		if (Out[x] - In[x])
			Sum2 += Out[x] - In[x], Have[Get_Father(x)] = true;
	}
	if (Sum1 == Sum2)
	{
		for (int x = -H;x <= +H;++x)
			if ((In[x] || Out[x]) && Have[Get_Father(x)] == false)
			{
				puts("NO");
				return 0;
			}
		puts("YES");
	}
	else
		puts("NO");
	return 0;
}

Measured memory_bytes: 256
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long int lli;
typedef long long int ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<pll> vop;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define REP(i,a,b) for( long long i=a;i<b;i++)
#define REPR(i,a,b) for(long long i=a;i>=b;i--)
#define adb(a) for(auto ii:a) cout << ii << " "; cout << endl
#define adp(a) for(auto ii:a) cout << ii.F << " " << ii.S << endl;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
#define endl "\n"
#define mem(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define PI 3.14159265358979323846
const ll MAXN = 100007;
const ll p = 1000000007;
#define N 200003
#define INF INTMAX_MAX

struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1> {}(p.first);
        auto hash2 = hash<T2> {}(p.second);
        return hash1 ^ hash2;
    }
};

struct LessSecond
{
    template<typename T, typename U>
    bool operator()(const std::pair<T, U> &x, const std::pair<T, U> &y) const
    {
        return x.second < y.second;
    }
};


ll power(ll a, ll b, ll m) { ll ans = 1; a = a % m; while (b) { if (b & 1) ans = (ans * a) % m; b /= 2; a = (a * a) % m; } return ans; }

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

ll modInverse(ll a, ll m) { ll g = __gcd(a, m); return power(a, m - 2, m); }

bool cmp(const pll &a, const pll &b)
{
    if (a.F != b.F) {
        return a.F > b.F;
    }
    else
        return a.S < b.S;
}


// bool check(ll i, ll j)
// {
//     if (i >= 0 && i < n && j >= 0 && j < m && a[i][j] != '#')
//         return true;
//     return false;
// }

int main()
{


    fastIO;
    int test = 1;
    //cin >> test;
    while (test--)
    {
        ll n;
        cin >> n;
        string s;
        cin >> s;
        set<ll>a, b;
        REP(i, 0, n)
        {
            if (s[i] == 'R')
                a.insert(i);
            if (s[i] == 'W')
                b.insert(i);
        }
        if (a.size() == 0 || b.size() == 0) {
            cout << 0 << endl;
            return 0;
        }
        ll ans = 0;
        REP(i, 0, n)
        {
            if (a.size() == 0)
                break;
            if (s[i] == 'W') {
                auto x = a.end();
                x--;
                a.erase(*x);
                b.erase(i);
                b.insert(*x);
                s[*x] = 'W';
                ans++;
            }
            else
            {
                a.erase(a.begin());
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 13016
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

	int n, c[500], s[500], f[500];
	cin >> n;
	for (int i = 0; i < n-1; i++) {
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 0; i < n-1; i++) {
		int pos = s[i]+c[i];
		for (int j = i+1; j < n-1; j++) {
			if(pos <= s[j]) pos = s[j];
			elif((pos-s[j]) % f[j] != 0){
				pos = s[j] + f[j]*((pos-s[j]) / f[j] + 1);
			}
			pos += c[j];
		}
		cout << pos << endl;
	}
	cout << 0 << endl;

	return 0;
}

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

int main(){
    int n;
    cin >> n;
    
    vector<int> a(n), b(n), c(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> c[i];
    
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    
    long long ans = 0;
    for (int i = 0; i < n; i++){
        long long number_of_a = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        long long temp = upper_bound(c.begin(), c.end(), b[i]) - c.begin();
        long long number_of_c = n - temp;
        
       // cout << number_of_a << number_of_c << endl;
        
        ans += number_of_a * number_of_c;
         
    }
    cout << ans << endl;
}

Measured memory_bytes: 1536
package main

import "fmt"

func main() {
	cards := [3][3]int{}
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			fmt.Scan(&cards[i][j])
		}
	}

	var N int
	fmt.Scan(&N)

	nums := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&nums[i])
	}

	fmt.Println(exec(cards, nums))
}

func exec(cards [3][3]int, nums []int) string {
	r := [3][3]bool{}

	for _, v := range nums {
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if cards[i][j] == v {
					r[i][j] = true
				}
			}
		}
	}

	for i := 0; i < 3; i++ {
		if r[i][0] && r[i][1] && r[i][2] {
			return "Yes"
		}
		if r[0][i] && r[1][i] && r[2][i] {
			return "Yes"
		}
	}

	if r[0][0] && r[1][1] && r[2][2] {
		return "Yes"
	}

	if r[0][2] && r[1][1] && r[2][0] {
		return "Yes"
	}

	return "No"
}


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

int main() {
    // insert code here...
    string tarou, hanako;
    int a,tp=0,hp=0;
    cin>>a;
    for (int i=0; i<a; i++) {
        cin>>tarou>>hanako;
        if (tarou<hanako) {
            hp+=3;
        }else if(hanako<tarou){
            tp+=3;
        }else{
            hp+=1;
            tp+=1;
        }
        
        
        
    }
    cout<<tp<<" "<<hp<<endl;
    return 0;
}




Measured memory_bytes: 3148
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//namespace mp=boost::multiprecision;
//#define mulint mp::cpp_int
//#define mulfloat mp::cpp_dec_float_100
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
constexpr int MOD=1000000007;
//constexpr int MOD=998244353;
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcountll(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};
const int MAX_N=2e5+5;
//struct edge{lint to,num;};
//vector<int> bucket[MAX_N/1000];

lint powmod(lint a,lint b){
  return b?powmod(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;
}

lint par[200500]; //MAX_N
lint ufsize[200050]; //MAX_N

void init(lint x){
  rep(i,x) par[i]=i,ufsize[i]=1;
}

lint root(lint x){
  if(par[x]==x) return x;
  else return par[x]=root(par[x]);
}

bool same(lint x,lint y){
  return root(x)==root(y);
}

void unite(lint x,lint y){
  x=root(x);
  y=root(y);
  if(x==y) return;
  lint s=ufsize[x]+ufsize[y];
  ufsize[x]=s,ufsize[y]=s;
  par[x]=y;
}

lint size(lint x){
  return ufsize[root(x)];
}

int main(void){
    lint N,M;
    cin >> N >> M;
    init(N);
    int A[M],B[M];
    rep(i,M) cin >> A[i] >> B[i],A[i]--,B[i]--;
    rep(i,M) unite(A[i],B[i]);
    int ans=N-1;
    rep(i,N) if(par[i]==i) ans-=size(i)-1;
    cout << ans << endl;
}

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

int main() {
    int64_t N;
    cin >> N;
    vector<int64_t> vec(N);
    for (int64_t i=0; i < N; i++) {
        cin >> vec.at(i);
    }

    int64_t count = 1;
    int64_t min_ = vec[0];
    for (int64_t i=1; i < N; i++) {
        min_ = min(min_, vec[i]);
        if (min_ >= vec[i]) {
            count += 1;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "iostream"
using namespace std;

int main()
{
	int n, m, a[100][100], b[100], ans[100] = { };
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++)
	{
		cin >> b[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			ans[i] += a[i][j] * b[j];
		}
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3132
n   = int(input())
a,b = map(int,input().split())
p   = map(int,input().split())
p_  = sorted(p)

anum = bnum = cnum = 0
for i,pi in enumerate(p_):
    if pi > a :
        anum = i
        break

for i,pi in enumerate(p_):
    if pi > b :
        bnum = i - anum
        break

cnum = n - anum - bnum
print(min(anum,bnum,cnum))

Measured memory_bytes: 3064
n = int(input())
elems = list(map(int, input().split()))

ranges = [i for i in range(1, len(elems)+1)]
myElems = zip(elems, ranges)
newElems = sorted(myElems, key=lambda x: x[0])


res = []
for _,i in newElems:
	res.append(i)
print(*res)


Measured memory_bytes: 21308
#include <iostream>
#include <cmath>
#include <map>
#include <utility>
#include <list>
#include <string>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

#define LL long long

LL collatz(LL n){
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

int main() {
    set<LL> t;
    LL s;
    cin >> s;
    LL i = 2;
    t.insert(s);

    while (true) {
        s = collatz(s);
        //cout << s << endl;
        if (t.find(s) == t.end()){
            t.insert(s);
            i++;
        } else {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

ll INF=1000000000000000;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i,N){
        cin >> A[i];
    }
    vector<ll> B(N);
    B[0]=A[0];
    rep(i,N-1){
        B[i+1]=B[i]+A[i+1];
    }
    ll ans=INF;
    for (int i=1;i<=N-3;i++){
        auto itr1=lower_bound(B.begin(),B.end(),B[i]/2);
        auto itr2=lower_bound(B.begin(),B.end(),(B[N-1]+B[i])/2);
        ll b=B[i],d=B[N-1];
        vector<ll> a(2,INF),c(2,INF);
        if (itr1!=B.begin()){
            auto itr3=itr1-1;
            a[1]=*itr3;
        }
        if (itr2!=B.begin()+i){
            auto itr4=itr2-1;
            c[1]=*itr4;
        }
        a[0]=*itr1,c[0]=*itr2;
        rep(i,2){
            rep(j,2){
                ll M=max(max(max(a[i],b-a[i]),c[j]-b),d-c[j]);
                ll m=min(min(min(a[i],b-a[i]),c[j]-b),d-c[j]);
                ans=min(ans,M-m);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
const int M=10;
int H,W;
int c[10][10];
int a[201][201];
long long int ans=0;
void warshall_floyd(int n){
  for (int i=0;i<n;i++)      
    for (int j=0;j<n;j++)
      for (int k=0;k<n;k++)  
        c[j][k]=min(c[j][k],c[j][i]+c[i][k]);
}
int main(){
  cin >> H >> W;
  for(int i=0;i<M;i++){
    for(int j=0;j<M;j++){
      cin >> c[i][j];
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }
  warshall_floyd(M);

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      int x=a[i][j];
      if(x!=1){
	ans+=c[x][1];
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)



int main (){

  int n;
  cin >> n;
  ll now_T = 0,now_A = 0;
  ll next1;

  r(i,n){
    ll t,a;
    cin >> t >> a;
    if(now_T < t && now_A < a){
      now_T = t;
      now_A = a;
    }
    else{
      next1 = max((now_T + t - 1) / t,(now_A + a - 1) / a);
      now_T = t * next1;
      now_A = a * next1;
    }


  }

  cout << now_A + now_T << endl;


  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

const int MAX = 510000;
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;
}

int main(){

    ll n, k;
    cin >> n >> k;

    vector<ll> v(n);
    for(int i = 0; i < n; i++) cin >> v[i];

    sort( all(v) );

    ll ans = 0;
    COMinit();
    for(ll i = 0; i < n; i++){
        ll rem = k - 1;
        // 最小値として含まれる
        ll right = n - i - 1;
        if(right >= rem){
            ans -= COM( right, rem ) * v[i];
            ans %= MOD;
        }

        // 最大値として含まれる
        ll left = i;
        if(left >= rem){
            ans += COM( left, rem ) * v[i];
            ans %= MOD;
        }

    }
    cout << ans << endl;


}

Measured memory_bytes: 12928
#include <stdio.h>

int main()
{
   long long int a,b,c,x,y,flag=0,i,j,count,sum,max;
   
   scanf("%lld%lld%lld%lld",&a,&b,&x,&y);
    printf("%lld",(a>b)?(x>y)?b+y:b+x:(x>y)?a+y:a+x);
     return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

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

Measured memory_bytes: 256
def main():
    sx ,sy, tx, ty = map(int ,input().split())
    for i in range(sx,tx):
        print('R',end="")
    for i in range(sy,ty):
        print('U',end="")
    for i in range(sx,tx):
        print('L',end="")
    for i in range(sy,ty + 1):
        print('D',end="")
    for i in range(sx,tx + 1):
        print('R',end="")
    for i in range(sy,ty + 1):
        print('U',end="")
    print('L',end="")
    print('U',end="")
    for i in range(sx,tx + 1):
        print('L',end="")
    for i in range(sy,ty + 1):
        print('D',end="")
    print('R')

if __name__ == '__main__':
    main()


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

int main() {
  int A, B;
  int count = 0;
  cin >> A >> B;

  while (A < B + 1) {
    int reverse = 0;
    int remaind;
    int tmp;
    tmp = A;
    while (tmp != 0) {
      remaind = tmp % 10;
      reverse = reverse * 10 + remaind;
      tmp /= 10;
    }
    if (A == reverse) {
      count++;
    }
    A++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define CLR(A, X) memset(A, X, sizeof(A))
using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
const double eps = 1e-10;
int dcmp(double x) { if(fabs(x) < eps) return 0; return x>0?1:-1; }
const LL MOD = 1e9+7;
const int N = 1e2+5;

int a[N*N], mp[N][N];

int main() {
    int h, w, n;
    scanf("%d%d%d", &h, &w, &n);
    for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int x = 1, y = 1, id = 1, op = 0;
    for(;;) {
        if(a[id] == 0) id++;
        a[id]--;
//        printf("%d %d %d %d\n", id, a[id], x, y);
        mp[x][y] = id;
        if(op == 0) {
            y++;
            if(y == w+1) {
                x++;
                y = w;
                op = 1;
            }
        }
        else {
            y--;
            if(y == 0) {
                x++;
                y = 1;
                op = 0;
            }
        }
        if(x == h+1) break;
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            printf("%d%c", mp[i][j], j==w?'\n':' ');
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

int main()
{
	const long long int mod = 1e+9+7;
	int n;
	cin >> n;
	long long int power = 1;
	for(int i=1;i <= n;i ++)
	{
		power = (long long int)power%(long long int)mod * (long long int)i%(long long int)mod;
	}
	power = (long long int)power%(long long int)mod;
	cout << power << endl;

}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

vector<bitset<40> > neighbor;
vector<int> strong;

vector<vector<int> > memo;

int solve(int i, bitset<40> ng)
{
    if(i == -1)
        return 0;

    bitset<40> ng2((1<<18) - 1);
    ng2 &= ng;
    if(i < 18 && memo[i][ng2.to_ulong()] != -1)
        return memo[i][ng2.to_ulong()];

    int ret = solve(i-1, ng);
    if(!ng[i])
        ret = max(ret, solve(i-1, ng |= neighbor[i]) + strong[i]);

    if(i < 18)
        memo[i][ng2.to_ulong()] = ret;

    return ret;
}

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        map<string, int> index;
        vector<vector<string> > d(n);
        strong.resize(n);
        for(int i=n-1; i>=0; --i){
            string s;
            int m;
            cin >> s >> strong[i] >> m;
            index[s] = i;
            d[i].resize(m);
            for(int j=0; j<m; ++j)
                cin >> d[i][j];
        }

        neighbor.assign(n, 0);
        for(int i=0; i<n; ++i){
            for(unsigned j=0; j<d[i].size(); ++j){
                int k = index[d[i][j]];
                neighbor[i][k] = true;
            }
        }

        memo.assign(18, vector<int>(1<<18, -1));
        cout << (solve(n-2, neighbor[n-1]) + strong[n-1]) << endl;
    }
}

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

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

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

#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define ROF(i,b,a) for (int i=(b);i>(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,n-1,-1)

typedef int i32;
typedef long long int i64;
typedef unsigned long long int ui64;
typedef float f32;
typedef double f64;
typedef long double f128;
typedef pair<int,int> Pi;

constexpr int INF = 1e9 + 7;
constexpr int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};

int main() {
    i64 N,M; cin>>N>>M;
    M /= 2;
    cout<<min(M,(N+M)/2)<<endl;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int R;
	cin >> R;
	cout << 2 * (float)R * acos(-1) << "\n";

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 3808
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 10000
using namespace std;

vector<vector<int>> G;
vector<int>  dp;

int long_path(int x) {
    if (dp[x] != -1)return dp[x];

    int res = 0;
    for (auto p : G[x]) {
        res = max(res, long_path(p)+1);
    }
    dp[x] = res;
    return dp[x];
}

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

    G = vector<vector<int>>(N + 1);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
    }
    
    dp = vector<int>(N + 1,-1);
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        ans = max(ans, long_path(i));
    }

    cout << ans << endl;
}


Measured memory_bytes: 8192
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
#include <functional>
using namespace std;

int64_t min(int64_t a,int64_t b) {
    if (a > b)
    {
        return b ;
    }else
    {
        return a ;
    }
}


int main(){
    int n ;
    cin >> n ;
    int ans = 0 ;
    vector<int> a(n) ;
    for (size_t i = 0; i < n; i++)
    {
        cin >> a.at(i) ;
    }
    sort(a.begin(),a.end(),greater<int>()) ;
    for (size_t i = 0; i < n; i++)
    {
        if (i % 2 == 0)
        {
            ans += a.at(i) ;
        }else
        {
            ans -= a.at(i) ;
        }
        
        
    }
    cout << ans << endl ;
}

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

#define INF 100000000
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  REP(i,N) cin >> A[i];
  sort(A.begin(),A.end());
  int minv = A[0];
  for(int i=1;i<N;i++){
    if(minv>A[i]%minv && A[i] % minv != 0){
      minv = A[i]%minv;
      i=-1;
    }
  }  
  cout << minv << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;

// ===============================================================

ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll sum(ll n) {
	return (1 + n) * n / 2;
}
//1から整数nまでの合計
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定

// ===============================================================

int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	vl r(n);
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			r[i] = a[i];
		}
		else r[i] = r[i - 1] + a[i];
	}
	ll ans = 1000000000000000;
	for (int i = 0; i < n-1; i++) {
		if (min(ans, abs((r[n - 1] - r[i]) - r[i])) == abs((r[n - 1] - r[i]) - r[i])) {
			ans = abs((r[n - 1] - r[i]) - r[i]);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6452
#include <cstdio>
#include <set>
#define M(x,y)std::make_pair(x,y)
typedef std::set<std::pair<int,int> >S;
int n,x,y,x1,y1,x2,y2,dx,dy;main(){for(;scanf("%d",&n),n;){
	S s;
	for(;n;n--)scanf("%d%d",&x,&y),s.insert(M(x,y));
	S::iterator it1,it2;
	for(it1=s.begin();it1!=s.end();it1++){
		x1=it1->first,y1=it1->second;
		for(it2=it1,it2++;it2!=s.end();it2++){
			x2=it2->first,y2=it2->second,dx=x2-x1,dy=y2-y1;
			if(dx*dx+dy*dy>n&&(
				(s.find(M(x1-dy,y1+dx))!=s.end()&&s.find(M(x2-dy,y2+dx))!=s.end())||
				(s.find(M(x1+dy,y1-dx))!=s.end()&&s.find(M(x2+dy,y2-dx))!=s.end())
			))n=dx*dx+dy*dy;
		}
	}
	printf("%d\n",n);
}}

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

int main() {
    int n,m,a,b=0;
    cin >> n>>m;
    for (int i = 0; i < m; i++) {
        cin >> a;
        b = b + a;
    }
    if (n >= b) {
        cout << n - b;
    }
    else cout << -1;
}

Measured memory_bytes: 3608
(defun chmin (a b)
  (if (> a b)
      b
      a))

(defun main ()
  (let* ((n (read))
         (h (make-array n))
         (dp (make-array 100005 :initial-element 1000000000)))
    (dotimes (i n)
      (setf (aref h i) (read)))
    (setf (aref dp 0) 0)

    (dotimes (i (1- n))
      (setf (aref dp (1+ i)) (chmin (aref dp (1+ i)) (+ (aref dp i) (abs (- (aref h (1+ i)) (aref h i))))))
      (if (> i 0)
          (setf (aref dp (1+ i)) (chmin (aref dp (1+ i)) (+ (aref dp (1- i)) (abs (- (aref h (1+ i)) (aref h (1- i)))))))))
    (format t "~d~%" (aref dp (1- n)))))

(main)


Measured memory_bytes: 59748
#include<stdio.h>
#include<stdlib.h>

void S(char *p1, char *p2, char *p3, char *p, char *str);
void cut(char *p);

int main()
{
	char Sa[101], Sb[101], Sc[101];
	char ch = 'A', *p = &ch;
	char *str = Sa;
	Sa[0] = 'A';
	Sb[0] = 'B';
	Sc[0] = 'C';
	
	gets(Sa+1);
	gets(Sb+1);
	gets(Sc+1);
	
	S(Sa, Sb, Sc, p, str);
	
	printf("%c\n", *p);
	
	return 0;
}
void S(char *p1, char *p2, char *p3, char *p, char *str)
{
	switch(str[1]){
		case 'a':
			cut(str);
			S(p1, p2, p3, p, p1);
			break;
		case 'b':
			cut(str);
			S(p1, p2, p3, p, p2);
			break;
		case 'c':
			cut(str);
			S(p1, p2, p3, p, p3);
			break;
		case '\0':
			*p = str[0];
	}
}
void cut(char *p)
{
	int i;
	for( i=1; p[i]!='\0'; i++){
		p[i] = p[i+1];
	}
	p[i-1] = '\0';
}

Measured memory_bytes: 128
def DP(N,M):
    dp = [[0 for _ in range(N+1)] for _ in range(N+1)]
    dp_sum = [[0 for _ in range(N+1)] for _ in range(N+1)]
    dp[0][0] = 1
    for j in range(N+1):
        dp_sum[0][j] = 1
    #dp[i][j]:i個の項で和がj
    #dp_sum[i][j]:dp[i][0]+...+dp[i][j]
    for i in range(1,N+1):
        for j in range(1,N+1):
            dp[i][j] = (dp_sum[i-1][j-1] - dp_sum[i-1][i-1] + dp[i-1][i-1]) % M
            dp_sum[i][j] = (dp_sum[i][j-1] + dp[i][j]) % M

    return dp

def main():
    N,K = map(int,input().split())
    M = 10**9+7

    dp = DP(N,M)

    comb = 1
    for i in range(1,K+1):
        comb *= (N - K + 2 - i)
        comb *= pow(i,M-2,M)
        comb %= M
        if i > N - K + 1:
            comb = 0
        print((comb * dp[i][K]) % M)

if __name__ == "__main__":
    main()


Measured memory_bytes: 110300
#include <cstdio>
#include <iostream>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

int main()
{
	vector<int> n(4);
	cin >> n[0] >> n[1] >> n[2] >> n[3];
	bool isone = false;
	bool isfour = false;
	bool isseven = false;
	bool isnine = false;
	for (int i = 0; i < 4; i++) {
		if (n[i] == 1) isone = true;
		if (n[i] == 4) isfour = true;
		if (n[i] == 7) isseven = true;
		if (n[i] == 9) isnine = true;
	}
	if (isone == true && isfour == true && isseven == true && isnine == true) cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 256