akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

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

void solve() {
    int N;
    cin >> N;
    vector<ll> v(N);
    REP(i,N) cin >> v[i];

    // エッジをみつける
    ll kabu = 0;
    ll money = 1000;
    bool lowing = true;
    REP(i,N) {
        if(i == N-1) {
            if(kabu > 0) {
                money += v[i] * kabu;
                kabu = 0;
            }
            break;
        }
        if(lowing && ((v[i] - v[i+1]) >= 0)) {
            continue;
        }
        if (lowing && ((v[i] - v[i+1]) < 0)) {
            // buy
            kabu = money/v[i];
            lowing = false;
            money -= v[i]*kabu;
        }
        if( !lowing && ((v[i] - v[i+1]) >= 0)) {
            money += v[i]*kabu;
            kabu = 0;
            lowing = true;
        }
        if(!lowing && ((v[i] - v[i+1]) < 0)) {
            continue;
        }
    }
    cout << money << endl;


}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
int main(void)
{
	int N;
	long long int H[100000];
	long long int count = 0, max;
	
	scanf("%d", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &H[i]);
	}

	for (int i = 0; i < N; i++) {
		if (i == 0) {
			max = H[i];
		}
		if (max < H[i]) {
			max = H[i];
		}

		if (H[i] < max) {
			if (max - H[i] > 1) {
				printf("No");
				return 0;
			}
		}
		//printf("%d", max);
	}
	printf("Yes");
	return 0;
}


Measured memory_bytes: 896
import collections
n, k = map(int, input().split())
a = list(map(int, input().split()))
t = 0
ans = n

l = collections.Counter(a)
x = l.most_common(k)

for i in range(len(x)):
    t += x[i][1]

ans -= t
if ans < 0:
    ans = 0
print(ans)


Measured memory_bytes: 32564
#include <iostream>
#include <string>
using namespace std;
int main(){
    string str;
    cin >> str;
    for(int i=0;i<str.size();i++){
        if(str[i]<'D'){
            str[i]=str[i]+23;
        }else{
            str[i]=str[i]-3;
        }
    }
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 3152
import fractions
A,B,C=map(int,input().split())
lcm = A*B#//fractions.gcd(A,B)
#A*(i+j)%B=C
#A*(i+j)=BX+C
i=A
while i<=lcm:
  #print(i,lcm)
  if i%B==C:
    print("YES")
    exit()
  i+=A
print("NO")

Measured memory_bytes: 5048
N=gets.to_i
if N==1
    ps=[gets.to_f]
else
    ps=gets.split.map(&:to_f)
end

ps.unshift(0)
dp=Array.new(N+1)
for i in 0..N
    dp[i]=Array.new(i+1,0.0)
end
dp[0][0]=1.0
for i in 1..N
    f=ps[i]
    for j in 0..i
        if j==0
            dp[i][j]=dp[i-1][0]*(1-f)
        elsif j==i && j!=0
            dp[i][j]=dp[i-1][i-1]*f
        else
            dp[i][j]=dp[i-1][j-1]*f+dp[i-1][j]*(1-f)
        end
    end
end
puts dp[N][N/2+1..-1].inject(:+)


Measured memory_bytes: 147196
A=input()
B=input()
a=len(A)
b=len(B)

def less():
  print('LESS')
  exit()
def greater():
  print('GREATER')
  exit()
def equals():
  print('EQUAL')
  exit()

if a<b:
  less()
if a>b:
  greater()
for i in range(a):
  if int(A[i])<int(B[i]):
    less()
  if int(A[i])>int(B[i]):
    greater()
else:
  equals()

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

typedef long long LL;

const int N=20;

int n;
char e[N*2+9][N*2+9];

void into(){
  scanf("%d",&n);n<<=1;
  for (int i=1;i<=n;++i)
	scanf("%s",e[i]+1);
}

LL f[N*2+9][N*2+9][N*2+9],g[N*2+9][N*2+9][N*2+9],ans;

void Get_fg(){
  for (int i=1;i<n;++i){
	f[i][i][i]=1;
	for (int j=i+1;j<=n;++j)
	  if (e[i][j]=='1') g[i][i][j]=1;
  }
  for (int len=3;len<n;len+=2){
	for (int l=1;l+len<=n;++l){
	  int r=l+len-1;
	  for (int x=l;x<=r;x+=2)
		for (int y=r;y>l;y-=2){
	      LL sum=0;
		  for (int i=y;i<=r;++i) sum+=g[l][x][i]*f[y][r][i];
		  for (int i=x+1;i<y;++i) f[l][r][i]+=f[x+1][y-1][i]*sum;
		}
	  for (int x=l+1;x<r;++x)
		for (int y=r+1;y<n;++y)
		  if (e[x][y]=='1') g[l][r][y]+=f[l][r][x];
	}
  }
  for (int i=1;i<n;++i)
	if (e[i][n]=='1') ans+=f[1][n-1][i];
}

void work(){
  Get_fg();
}

void outo(){
  printf("%lld\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4700
S = input()
a = S[0]
count = 1
flag = 1
if len(S) == 1:
    print(1)
else:
    for i in range(1, len(S)):
        if flag == 0:
            flag = 1
            a = "A"
            continue
        if a != S[i]:
            count += 1
        else:
            if i != len(S) - 1:
                count += 1
            flag = 0
        #print(count, S[i], i, a, flag)
        a = S[i]
    print(count)

Measured memory_bytes: 3500
#include<iostream>

using namespace std;

string S;
string T;

int main() {
    cin >> S;
    cin >> T;

    bool isSame = false;
    for (int i = 0; i < S.size(); i++) {
        isSame = true;
        for (int j = 0; j < S.size(); j++) {
            int b = (i + j < S.size()) ? i + j : i + j - S.size();
            if (S[b] != T[j]) {
                isSame = false;
            }
        }
        if (isSame) {
            break;
        }
    }
    if (isSame) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner
import scala.collection.mutable._
import scala.math.Ordering.Implicits._

object Main {

	def main(args: Array[String]): Unit = {
		val in = new Scanner(System.in)

		val map = Map.empty[String, List[Int]]
		while (in.hasNext) {
			var s = in.next
			var p = in.nextInt

			if (map.contains(s)) {
				map.put(s, p::map.get(s).get)
			} else {
				map.put(s, List(p))
			}
		}

		var outer = ListBuffer.empty[(String, List[Int])]
		map.foreach { item =>
			outer += item
		}
		outer = outer.sortWith(_ < _)

		outer.foreach { case (s, p) =>
			println(s)
			val pl = p.sorted
			pl.foreach { i =>
				if (i == pl.last){
					println(i)
				} else {
					print(i+" ")
				}
			}
		}
	}
}

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

int dfs(vector<vector<int>> &books,int c,int idx,vector<int> tmp){
    int i;
    for(i=0;i<tmp.size();i++){
        if(tmp[i]<c){        
            break;    
        }
    }
    if(i==tmp.size()) return 0;
    if(idx == books.size()) return INT_MAX;

    int a = dfs(books,c,idx+1,tmp);

    for(int i=0;i<tmp.size();i++){
        tmp[i]+=books[idx][i+1];
    }
    int b = dfs(books,c,idx+1,tmp);
    if(b!=INT_MAX) b +=books[idx][0];

    return min(b,a);
}

int main(){
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> books(n,vector<int>(m+1));
    for(int i=0;i<n;i++){
        for(int j=0;j<=m;j++){
            cin>>books[i][j];
        }
    }
    int cc;
    int cost = dfs(books,x,0,vector<int>(m,0));
    if(cost==INT_MAX) cout<<-1;
    else cout<<cost;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e16;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 2510;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s[0] == 'S' && s[1] == 'U') PRINT(7);
    else if (s[0] == 'M') PRINT(6);
    else if (s[2] == 'E') PRINT(5);
    else if (s[0] == 'W') PRINT(4);
    else if (s[0] == 'T') PRINT(3);
    else if (s[0] == 'F') PRINT(2);
    else PRINT(1);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int a,b;
    cin>>a>>b;
    if (a+b==15) {
        cout<<"+"<<endl;
    } else if (a*b==15) {
        cout<<"*"<<endl;
    } else {
        cout<<"x"<<endl;
    }
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int maxx=a[0];
    int ans=0;
    for(int i=1;i<n;i++){
        if(a[i]<maxx){
            ans+=maxx-a[i];
        }
        else if(a[i]>maxx){
            maxx=a[i];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 5196
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int N; cin >> N; 
	long long A[200010] = {}; 
	for(int i = 0; i < N; i++) cin >> A[i]; 
	sort(A, A+N, greater<long long>());
	long long ans = 0;  
	for(int i = 1; i < N; i++){
		ans += A[i/2]; 
	}
	cout << ans << "\n"; 
}

Measured memory_bytes: 5152
A, B, Q = gets.split.map(&:to_i)
Ss = A.times.map{gets.to_i}
Ts = B.times.map{gets.to_i}
Xs = Q.times.map{gets.to_i}
INF = 1E18.to_i

ss = [-INF] + Ss + [INF]
ts = [-INF] + Ts + [INF]
Xs.each do |x|
  i = ss.bsearch_index{|s| s >= x}
  j = ts.bsearch_index{|t| t >= x}
  puts ss[i - 1, 2].product(ts[j - 1, 2]).flat_map{|s, t| [(s - x).abs + (t - s).abs, (t - x).abs + (s - t).abs]}.min
end

Measured memory_bytes: 8044
#include<bits/stdc++.h>
using namespace std;
char a[100005];
int main()
{
	cin>>a;
	int len=strlen(a),ans;
	for(int i=1;i<len;i++)
		if(a[i]!=a[i-1])
			ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a<0&&b<0){
    if((b-a)%2==0) cout << "Negative" << endl;
    else cout << "Positive" << endl;
  }else if(0<a&&0<b){
    cout << "Positive" << endl;
  }else{
    cout << "Zero" << endl;
  }
  return 0;
}


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

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		long[] A = nextLongs();

		long sum = 0;
		for(int i=0;i<N;i++){
			sum+=A[i];
		}
		long sl = 0;
		long sr = sum;
		long ans = sum;
		for(int i=0;i<N-1;i++){
			sl+=A[i];
			sr-=A[i];
			ans=Math.min(ans, Math.abs(sl-sr));
		}
		System.out.println(ans);
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 71220
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <cstdlib>
#include <queue>
#include <vector>
#include <unordered_set>

using namespace std;
int main() {
	int n;
	cin >> n;
	typedef unordered_set <string> set_t;
	set_t A;
		string s;
	while( n > 0 ) { 
		cin >> s;
		if ( s == "insert" ) {
			cin >> s;
			A.insert(s);
		}
		else
			if ( s == "find" ) {
			cin >> s;
				int m = A.count(s);
			if (m == 1) cout << "yes" << endl;
			else cout << "no" << endl;
		}
		n = n-1;
		}
}

Measured memory_bytes: 30568
//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share 

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

ll a[2*100002];
int main(){
    ll n;
    cin>>n;
    forn(i,n-1) {
        ll te;
        cin>>te;
        a[te]++;
    }
    for1(i,n) cout<<a[i]<<endl;
}

Measured memory_bytes: 5208
x1, y1, x2, y2 = map(int, input().split())

x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)

x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)
print(x3, y3, x4, y4)

Measured memory_bytes: 38256
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] isRights = new boolean[n];
		for (int i = 0; i < n; i++) {
		    isRights[i] = (sc.nextInt() == 0);
		}
		PriorityQueue<Integer> rights = new PriorityQueue<>();
		PriorityQueue<Integer> lefts = new PriorityQueue<>();
		for (int i = 0; i < n; i++) {
		    if (isRights[i]) {
		        rights.add(sc.nextInt());
		    } else {
		        lefts.add(sc.nextInt());
		    }
		}
		if (rights.size() == 0 || lefts.size() == 0) {
		    System.out.println(0);
		} else {
		    System.out.println(rights.peek() + lefts.peek());
		}
	}
}



Measured memory_bytes: 26348
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []

for i in range(N):
    if i < N - 1:
        B.append(A[i + 1] - A[i])
    else:
        B.append((A[0] + K) - A[i])

# print(B)
print(K - max(B))


Measured memory_bytes: 26444
#include<cassert>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

const int MAX = 10000000;
int min_factor[MAX+1];
vector<int>prime;
void make_prime() {
    for (int i=2; i<=MAX; i+=2) min_factor[i] = 2;
    for (int i=3; i<=MAX; i+=3) if (!min_factor[i]) min_factor[i] = 3;
    for (int i=5, d=2; i*i<=MAX; ) {
	if (!min_factor[i]) {
	    min_factor[i] = i;
	    for (int j=i*i; j<=MAX; j+=i)
		if (!min_factor[j]) min_factor[j] = i;
	}
	i += d; d = 6 - d;
    }
    for (int i=2; i<=MAX; i++) {
	if (min_factor[i]==0) min_factor[i] = i;
	if (min_factor[i]==i) prime.push_back(i);
    }
}
typedef unsigned long long ULL;
ULL gcd(ULL x, ULL y) {
    while (1) {
	if (x) y %= x; else return y;
	if (y) x %= y; else return x;
    }
}
ULL lcm(ULL x, ULL y) {
    return x / gcd(x, y) * y;
}

int N;
const int SIZE = 500;
ULL A[511][511];

void MAIN() {
    make_prime();

    scanf("%d", &N);

    REP (i, SIZE) REP (j, SIZE) if ((i+j)%2 == 0) {
	int p = (i+j)/2, q = (i-j)/2;
	A[i][j] = (LL)prime[p%SIZE] * prime[(q+SIZE)%SIZE+SIZE];
    }
    REP (i, SIZE) REP (j, SIZE) if ((i+j)%2 == 1) {
	ULL x = 1;
	if (i) x = lcm(x, A[i-1][j]);
	if (j) x = lcm(x, A[i][j-1]);
	if (i+1<SIZE) x = lcm(x, A[i+1][j]);
	if (j+1<SIZE) x = lcm(x, A[i][j+1]);
	A[i][j] = x + 1;
    }

    REP (i, N) rprintf("%llu", A[i], A[i]+N);
}


int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 48236
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
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; }

int a, b;

int main(){
  cin >> a >> b;
  int res = -1;
  for(int i = 1; i <= 20000; i++){
    if((i * 8) / 100 == a && (i * 10) / 100 == b){
      res = i;
      break;
    }
  }
  cout << res << endl;
}


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

using namespace std;

int main() {
	int n; cin >> n;
	vector<vector<int> > a(n, vector<int> (2));
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 2; ++j) {
			cin >> a[i][j];
		}
	}
	bool ok = false;
	for (int i = 0; i + 2 < n; ++i) {
		bool tmp = true;
		for (int j = 0; j < 3; ++j) {
			if (a[i + j][0] != a[i + j][1]) tmp = false;
		}
		if (tmp) ok = true;
	}
	if (ok) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;
using D = long double;
const D PI = std::acos(-1);
int main() {
    D R;
    cin >> R;
    cout << setprecision(10) << 2 * PI * R << endl;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int TEST,CASE=1;
int n,a,b,x,y,m,mm,ans=0;
int east[400005];
int west[400005];
string str;
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
#ifdef FILE_INPUT
    freopen("input.txt","r",stdin);
#endif // FILE_INPUT
    cin>>n;
    cin>>str;
    a=b=0;
    if(str[0]=='W'){
       west[0]=1;
       east[0]=0;
    }else{
        east[0]=1;
        west[0]=0;
    }
    for(int i=1;i<n;i++){
        if(str[i]=='W'){
            west[i]=west[i-1]+1;
            east[i]=east[i-1];
        }else{
            east[i]=east[i-1]+1;
            west[i]=west[i-1];
        }
    }
    ans=INT_MAX;
    ans=east[n-1]-east[0];
    ans=min(ans,west[n-2]);
    for(int i=1;i<n-1;i++){
        m=west[i]+east[n-1]-east[i-1];
        m--;
        ans=min(ans,m);
    }
    cout<<ans<<endl;


#ifdef FILE_INPUT
#endif // FILE_INPUT
    return 0;
}



Measured memory_bytes: 3092
from collections import defaultdict
n = int(input())
a = list(map(int,input().split()))
dic1 = defaultdict(int)
dic2 = defaultdict(int)
for i in range(n):
    dic1[a[i]+i] += 1
    dic2[i-a[i]] += 1
ans = 0
for i in dic1.keys():
    ans += dic1[i]*dic2[i]
print(ans)

Measured memory_bytes: 163620
#include <iostream>
#include <algorithm>
#include <cstring>
#define ll long long 
using namespace std;

ll dp[100000];
ll h[100000];
int n;

ll solve(int i){
  if(i == n - 1)
    return 0;
  
  if(dp[i] != -1)
    return dp[i];

  if(i + 2 == n)
    return dp[i] = solve(i+1) + abs(h[i] - h[i+1]);
  
  return dp[i] = min(solve(i+1) + abs(h[i] - h[i+1]), solve(i+2) + abs(h[i] - h[i+2]));
}

int main()
{
    cin >> n;

    memset(dp, -1, sizeof dp);

    for(int i = 0; i < n; i++)
      cin >> h[i];

    cout << solve(0) << endl;

    return 0;
}

Measured memory_bytes: 8252
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val A = readLine()!!.split(" ").map { it.toInt() }
    var min = 2L
    var max = 2L
    if (A[N - 1] >= 3) {
        println("-1")
        return
    }
    for (i in N - 1 downTo 0) {
        max += A[i] - 1
        if (i == 0) break
        max = max / A[i - 1] * A[i - 1]
        min = ((min - 1) / A[i - 1] + 1) * A[i - 1]
        if (min > max) {
            println("-1")
            return
        }
    }
    println("$min $max")
}


Measured memory_bytes: 57680
// AOJ DPL_1_H Huge Knapsack Problem
// 2018.5.11 bal4u
 
#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
long long in()
{
    long long n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}

#define MAX  ((1<<20)+5)

int N; long long W;
typedef struct { long long v, w; } TBL;
TBL a[42]; int c;
TBL s1[MAX]; int c1;
TBL s2[MAX]; int c2;
TBL *p, *q; int len;

long long binarysearch_upper(long long x)
{
	int m, l = 0, r = len;

    while (l < r) {
        m = (l+r) >> 1;
		if ((q+m)->w <= x) l = m + 1; else r = m;
    }
	return (q+l-1)->v;
}

int cmp(TBL *a, TBL *b)
{
	if (a->w == b->w) {
		if (a->v == b->v) return 0;
		if (a->v < b->v) return 1;
		return -1;
	}
	if (a->w < b->w) return -1;
	return 1;
}

int sum(TBL *s, int base, int len)
{
	int i, j, k, lim;
	long long x, y;

	lim = 1 << len;
	k = 0; for (i = 0; i < lim; i++) {
		x = 0, y = 0;
		for (j = 0; ; j++) {
			if (j == len) {
				s[k].v = x, s[k++].w = y;
				break;
			}
			if ((i >> j) & 1) {
				if ((y += a[base+j].w) > W) break;
				x += a[base+j].v;
			}
		}
	}
	qsort(s, k, sizeof(TBL), cmp);

	len = 1;
	for (i = 1; i < k; i++) {
		if (s[len-1].v < s[i].v) s[len++] = s[i];
	}
	return len;
}

int main()
{
	int i, m1, m2, m;
	long long t, ans;

	N = (int)in(), W = in();

	c = 0; for (i = 0; i < N; i++) {
		a[c].v = in(), a[c].w = in();
		if (a[c].w <= W) c++;
	}

	m1 = c / 2,	c1 = sum(s1, 0, m1);
	m2 = c - m1, c2 = sum(s2, m1, m2);

	ans = 0;
	if (c1 <= c2) p = s1, q = s2, m = c1, len = c2;
	else          p = s2, q = s1, m = c2, len = c1;
	for (i = 0; i < m; i++) {
		t = p[i].v + binarysearch_upper(W - p[i].w);
		if (t > ans) ans = t;
	}
	printf("%lld\n", ans);

	return 0;
}


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

using namespace std;
typedef long long ll;

const int N = 100'010;
const ll INF = 1ll << 60;
int n, a[N];

int main() {
    scanf("%d", &n);
    for (int i = 0; i <= n; i++) scanf("%d", &a[i]);
    ll sum = 0;
    for (int i = 0; i <= n; i++) sum += a[i];
    ll ans = 0;
    ll left = sum, cnt = 1;
    bool yes = 1;
    for (int i = 0; i <= n; i++) {
        ans += min(cnt, left);
        left -= a[i];
        cnt -= a[i];
        if (cnt <= 0 && i < n || cnt < 0 && i == n) {
            yes = 0;
            break;
        }
        if (cnt < INF) cnt *= 2;
    }
    if (yes) {
        printf("%lld\n", ans);
    } else {
        printf("-1\n");
    }
}


Measured memory_bytes: 4216
#include<stdio.h>

int main(){
	int CO[26];
	char A;
	for(A=0;A<26;A++)
		CO[A]=0;
	while(!feof(stdin)){
		A=fgetc(stdin);
		if('a'<=A&&A<='z')
			A-='a'-'A';
		if('A'<=A&&A<='Z')
			CO[A-'A']++;
	}
	for(A=0;A<26;A++)
		printf("%c : %d\n",'a'+A,CO[A]);
	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    int N;
    cin >> N;
    map<int, int> m;
    REP(i, N) {
        int a;
        cin >> a;
        m[a]++;
    }

    int ans = 0;
    for (auto&& i : m) {
        if (i.second > i.first) {
            ans += i.second - i.first;
        }
        else if (i.second < i.first) {
            ans += i.second;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main(){
	string x;
	int n,m;
    vector<int> p, a;
	p.push_back(-1);
	a.push_back(-1);
	getline(cin, x);
	while(n=x.find("peach", p.back() + 1), ~n)
		p.push_back(n);
	while(m=x.find("apple", a.back() + 1), ~m)
		a.push_back(m);
	for(int i = 1; i < p.size(); i++)
		x.replace(p[i], 5, "apple");
	for(int j = 1; j < a.size(); j++)
		x.replace(a[j], 5, "peach");
	cout<< x <<endl;
	return 0;
}


Measured memory_bytes: 3200
using System;
using System.Collections.Generic;

namespace B___Palace
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ');
            var t = int.Parse(input[0]);
            var a = int.Parse(input[1]);
            input = Console.ReadLine().Split(' ');
            var b = new List<double>();
            var ans = double.MaxValue;
            for (var i = 0; i < n; i++)
            {
                b.Add(t - int.Parse(input[i]) * 0.006);
                ans = Math.Min(Math.Abs(a - b[i]), ans);
            }
            for (var i = 0; i < n; i++)
            {
                if (Math.Abs(a-b[i]) == ans)
                {
                    Console.WriteLine(i+1);
                    break;
                }
            }
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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 long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
#define MAX_N 100100
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

int main(){
    ll n,ans=0;
    cin >> n;
    ll a[n];
    for (ll i=0;i<n;i++){
        cin >> a[i];
    }
    ans=abs(a[0]);
    for (ll i=1;i<n;i++){
        ans+=abs(a[i-1]-a[i]);
    }
    ans+=abs(a[n-1]);
    cout << ans-abs(a[0])-abs(a[0]-a[1])+abs(a[1]) << endl;
    for (ll i=1;i<n-1;i++){
        cout << ans-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
    }
    cout << ans-abs(a[n-2]-a[n-1])-abs(a[n-1])+abs(a[n-2]) << endl;
    return 0;
}


Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <cctype>

using namespace std;

using State = string::const_iterator;

int number(State &begin);
int expression(State &begin);
int term(State &begin);
int factor(State &begin);

int number(State &begin){
    int ret = 0;
    while(isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }

    return ret;
}

int factor(State &begin){
    if(*begin == '('){
        begin++;
        int ret = expression(begin);
        begin++;
        return ret;
    }
    else{
        return number(begin);
    }
}

int expression(State &begin){
    int ret = term(begin);

    while(true){
        if(*begin == '+'){
            begin++;
            ret += term(begin);
        }
        else if(*begin == '-'){
            begin++;
            ret -= term(begin);
        }
        else{
            break;
        }
    }

    return ret;
}

int term(State &begin){
    int ret = factor(begin);

    while(true){
        if(*begin == '*'){
            begin++;
            ret *= factor(begin);
        }
        else if(*begin == '/'){
            begin++;
            ret /= factor(begin);
        }
        else{
            break;
        }
    }

    return ret;
}

int main(){

    int N;
    cin >> N;
    string s;
    for(int i = 0; i < N; i++){
        cin >> s;
        State begin = s.begin();
        cout << expression(begin) << endl;
    }

    return 0;
}


Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, M;
string s, t;

ll Gcd(ll b, ll d){
  	if (d == 0) return b;
 	else return Gcd(d, b % d);
}
ll Lcm(ll m, ll n){
    if ((0 == m) || (0 == n)) return 0;
    return ((m / Gcd(m, n)) * n);
}

int main(void){
    
    scanf("%d %d", &N, &M);
    cin >> s >> t;
    s = ' ' + s;
    t = ' ' + t;
    
    ll mn = Lcm(N, M);
    map<ll, char> mp;
        
    for(int n = 0; n < N; ++n){
        ll temp = n * mn / N + 1;
        if(mp.find(temp) != mp.end() && mp[temp] != s[n + 1]){ printf("-1\n"); return 0; }
        mp[temp] = s[n + 1];
    }
    
    for(int n = 0; n < M; ++n){
        ll temp = n * mn / M + 1;
        if(mp.find(temp) != mp.end() && mp[temp] != t[n + 1]){ printf("-1\n"); return 0; }
        mp[temp] = t[n + 1];
    }
    
    printf("%lld\n", mn);
    
    return 0;
}


Measured memory_bytes: 10828
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
#define MAX 300000
vector<ll> G[MAX];
ll d[MAX];
ll dfs(ll v,ll pre){
  cout <<v <<" "<<pre<<endl;
  ll res = 0;
  for(auto nv:G[v]){
    if(nv!=pre){
      res += dfs(nv,v);
    }
  }
  d[v] = res;
  return res+1;
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  ll x;
  for(int i=0;i<n-1;i++){
    cin >> x;
    x--;
    G[x].push_back(i+1);
  }
  for(int i=0;i<n;i++){
    cout << G[i].size() << endl;
  }
}


Measured memory_bytes: 16932
N = int(input())
P = list(map(float, input().split()))
dp = [[0 for _ in range(N+1)] for _ in range(1, N+1, 2)]

dp[0][0], dp[0][1] = 1-P[0], P[0]
for i in range(0, (N-1)//2):
    hh, tt = P[2*i+1] * P[2*i+2], (1 - P[2*i+1]) * (1 - P[2*i+2])
    ht = 1 - hh - tt
    for j in range(0, 2*i+2):
        dp[i+1][j+2] += hh * dp[i][j]
        dp[i+1][j+1] += ht * dp[i][j]
        dp[i+1][j] += tt * dp[i][j]
print(sum(dp[(N-1)//2][(N+1)//2:]))

Measured memory_bytes: 152584
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int n, ans;
bool bused[105], rused[105];
int main() {
	cin >> n;
	vector<tuple<int, int>>v, w;

	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		v.emplace_back(a, b);
	}
	sort(all(v));
	reverse(all(v));
	for (int i = 0; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		w.emplace_back(b, a);
	}
	sort(all(w));

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (!bused[i] && !rused[j] && get<0>(v[i]) < get<1>(w[j]) && get<1>(v[i]) < get<0>(w[j])) {
				bused[i] = 1; rused[j] = 1;
				++ans;
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    string x;
    cin >> x;
    ll ans = (ll)x.size();
    deque<char> dq;
    for (char c : x) {
        if (!dq.empty() && dq.back() == 'S' && c == 'T') dq.pop_back(), ans-=2;
        else dq.push_back(c);
    }
    cout << ans << endl;
}

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

int main(){
   int w, h, n; cin>>w>>h>>n;
   int square[w][h];

   // 初期化
   for(int i = 0; i < w; i ++) {
      for (int j = 0; j < h; j ++) {
         square[i][j] = 0;
      }
   }

   for(int i = 0; i < n; i ++) {
      int x, y, a;
      cin >> x >> y >> a;
      switch (a)
      {
      case 1:
         for (int j = 0; j < x; j++) {
            for(int k = 0; k < h; k++) {
               square[j][k] = 1;
            }
         }
         break;
      case 2:
         for (int j = x; j < w; j ++) {
            for(int k = 0; k < h; k ++) {
               square[j][k] = 1;
            }
         }
         break;
      case 3:
         for (int j = 0; j < w; j ++) {
            for(int k = 0; k < y; k ++) {
               square[j][k] = 1;
            }
         }
         break;
      case 4:
         for (int j = 0; j < w; j ++) {
            for(int k = y; k < h; k ++) {
               square[j][k] = 1;
            }
         }
         break;

      default:
         break;
      }
   }
   int ans = 0;
   for(int i = 0; i < w; i ++) {
      for (int j = 0; j < h; j ++) {
         if (square[i][j] == 0) ans++;
      }
   }

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


Measured memory_bytes: 256
#include<stdio.h>
long long n,srx[101];
int i;
long long lgx(long long n)
{
    if(srx[n])
    return srx[n];
    if(n>0)
    srx[n]=lgx(n-1)*2+2;
}
int main()
{
    scanf("%d",&n);
    srx[0]=2;
    lgx(n);
    printf("%lld\n",srx[n]);
    return 0;
}

Measured memory_bytes: 128
#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>;

int main(){
	int a;
	cin >> a;
	if(a%2 == 0){
    	cout << a/2 << endl;
    }else{
    	cout << a/2+1 << endl;
    }
}

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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

string s;
void solve() {
    cin >> s;
    auto n = sz(s);

    bool ok = true;
    rep(i, n) if (s[i] != s[n - 1 - i]) ok = false;
    rep(i, (n - 1) / 2) if (s[i] != s[(n - 1) / 2 - 1 - i]) ok = false;
    int j = n - 1;
    loop(i, (n + 3) / 2 - 1, n) {
        if (s[i] != s[j]) ok = false;
        --j;
    }

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

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


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

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;
    unsigned long long k;
    cin >> n >> k;
    vector<int> A(n);
    rep(i,n){
        int x;
        cin >> x;
        A[i]=x-1;
    }
    if(k<=n){
        int ans=A[0];
        for(int i=0;i<k-1;i++){
            ans=A[ans];
        }
        cout << ans+1 << endl;
        return 0;
    }else{
        int ans=A[0];
        int first_num=1;
        set<int> st;
        st.insert(0);
        st.insert(ans);
        while(st.size()==first_num+1){
            ++first_num;
            ans=A[ans];
            st.insert(ans);
        }
        //first_num--;
        ans=A[0];
        for(int i=0;i<first_num-1;i++){
            ans=A[ans];
        }
        int cycle=0;
        set<int> st2;
        st2.insert(ans);
        while(st2.size()==cycle+1){
            ++cycle;
            ans=A[ans];
            st2.insert(ans);
        }
        cycle=st2.size();
        //corner
        if(cycle==1){
            cout << ans+1 << endl;
            return 0;
        }
        int num=(k-first_num)%cycle;
        ans=A[0];
        for(int j=0;j<first_num+num-1;j++){
            ans=A[ans];
        }
        cout << ans+1 << endl;
        return 0;
    }
}

Measured memory_bytes: 16460
n = int(input())
a = list(map(int, input().split()))
ball = [0] * (n+1)
for i in a:
  ball[i] += 1
base = 0
for i in ball:
  base += i * (i-1) // 2
for i in a:
  b = ball[i]
  ans = base - (b-1) * 2 // 2
  print(ans)

Measured memory_bytes: 83916
#include <iostream>
#include <stdio.h>
#include <math.h> 
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <string>

using namespace std;
string s;

int main() {

	cin >> s;
	int cnt = 0;

	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '1') {
			cnt++;
		}
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		long N = scan.nextLong();
		long b = scan.nextLong();
		long r = scan.nextLong();
		long res = N / (b+ r);
		long mod = N % (b+ r);

		if(mod > b){
			mod = b;
		}
		System.out.println(res*b + mod);

	}
}

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

using namespace std;
#define PB push_back
#define LL long long
#define int LL
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for (int i = (a); i >= (b); i--)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define st first
#define nd second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define VI vector<int>
#define PII pair<int,int>
#define LD long double

template<class C> void mini(C& a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C& a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream &os, vector<T> V){
  os<<"[";for(auto vv:V)os<<vv<<",";return os<<"]";
} 

template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}


#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif


int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  int n;
  cin>>n;
  VI inp(n);
  map<int,int> last;
  int res = 0;
  REP(i, n){
    cin>>inp[i];
    inp[i]--;
    last[inp[i]] = last[inp[i] - 1] + 1;
    maxi(res, last[inp[i]]);
  }
  cout<<n - res<<"\n";

}

Measured memory_bytes: 14336
#include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    using namespace std;

    struct node
    {
        char st[101];
    }a[100];
    bool cmp(node s1,node s2)
    {
        return strcmp(s1.st,s2.st)<0;
    }

    int main()
    {
        int n,l;
        scanf("%d%d",&n,&l);
        for(int i=0;i<n;i++){
            scanf("%s",a[i].st);
        }
        sort(a,a+n,cmp);
        for(int i=0;i<n;i++) printf("%s",a[i].st);
        return 0;
    }


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

using namespace std;

int main(){
  int n;
  cin >> n;
  int tmp=0;
  int max=1;
  int min=1000000000;
  for(int i=0;i<n;i++){
    cin >> tmp;
    if(tmp<min)min=tmp;
    if(tmp>max)max=tmp;
  }
  cout << max - min << endl;
  
}

Measured memory_bytes: 256
n=int(input())
s=input().split()
l=[]
for i in s:
    l.append(int(i))
s=0
for i in range(n):
    l[i]-=i+1
l.sort()
b=l[n//2]
for i in range(n):
    l[i]-=b
    l[i]=abs(l[i])
print(sum(l))

Measured memory_bytes: 26128
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
typedef long long ll;
using namespace std;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    int ans[n] = {0};
    repi(ri, 2, 0)
    {
        { //solve
            int cnt = 0;
            repi(i, n, 0)
            {
                if (s[i] == 'R')
                    cnt++;
                else
                {
                    ans[i] += cnt / 2;
                    ans[i - 1] += (cnt + 1) / 2;
                    cnt = 0;
                }
            }
        }
        reverse(ans, ans + n);
        reverse(s.begin(), s.end());
        repi(i, n, 0)
        {
            if (s[i] == 'L')
                s[i] = 'R';
            else
                s[i] = 'L';
        }
    }

    repi(i, n, 0)
    {
        cout << ans[i] << ((i + 1) % n ? " " : "\n");
    }
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
int main()
{
  char last = 0;
  bool bad = false;
  for(int i=0;i<4;++i)
  {
    char now = getchar();
    if(last==now){
       bad = true;
    }
    last = now;
  }
  if(bad) printf("Bad\n");
  else printf("Good\n");
}


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

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(long long N, long long R){
  if(N>=10)
    std::cout << R << std::endl;
  else
    std::cout << R+100*(10-N) << std::endl;
}

int main(){
  long long N;
  scanf("%lld",&N);
  long long R;
  scanf("%lld",&R);
  solve(N, R);
  return 0;
}



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

using namespace std;

int main(int argc, char const *argv[])
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a;
    vector<int> b;
    int tmp;
    for (int i = 0; i < A; i++)
    {
        cin >> tmp;
        a.emplace_back(tmp);
    }
    for (int i = 0; i < B; i++)
    {
        cin >> tmp;
        b.emplace_back(tmp);
    }
    
    int x, y, c;
    int pri;
    int min = 200000;
    for (int i = 0; i < M; i++)
    {
        cin >> x >> y >> c;
        pri = a[x - 1] + b[y - 1] - c;
        if (pri < min)
        {
            min = pri;
        }
        
    }
    pri = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    if (pri < min)
    {
        min = pri;
    }
    
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0)
//#define MULTI_TEST
//#define GOOGLE
#ifdef LOCAL
#include "debugger.h"
#else
#define db(...)
#endif
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
const ll MOD = 1e9 + 7;
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }

void solve()
{
	ll x;
	cin >> x;
	ll curr = 100;
	for (ll t = 1;; t++)
	{
		ll temp = (curr / 100);
		if (curr + temp < x)
			curr += temp;
		else
		{
			cout << t << ln;
			return;
		}
	}
	return;
}

int main()
{
#ifndef LOCAL
	FASTIO;
#endif
	int t = 1;
#ifdef LOCAL
	clock_t start, stop;
	start = clock();
#endif
#ifdef MULTI_TEST
	cin >> t;
#endif
	for (int tc = 1; tc < t + 1; tc++)
	{
#ifdef GOOGLE
		cout << "Case #" << tc << ": ";
#endif
		solve();
	}
#ifdef LOCAL
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3608