akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
int main()
{
    fast;
    ll t,n,m,i,j,k;
    string s;
    cin>>n;
    cin>>s;
    string p,z;
    for(i=0;i<n;i++)
    {
        if(i<(n/2))p+=s[i];
        else z+=s[i];
    }
    if(p==z)cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
    ll n,x,t;
    cin>>n>>x>>t;
    if(n<=x)
    cout<<t<<endl;
    else
    {
     ll r=n%x;
     if(r==0)
     cout<<(n/x)*t<<endl;
     else
     cout<<(n/x +1)*t<<endl;
    }
    
}


Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    int cnt = 0;
    
    rep(i, s.length()) {
        if (s[i] == '1') {
            cnt++;
        }
    }
    
    cout << cnt << endl;
    return 0;
}


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

int f(int x) {
  if(x < 10) return x;
  return x%10 + f(x/10);
}

int main() {
  int n;
  cin >> n;
  int s = f(n);
  if(n%s == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  } 
  return 0;
}

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

using namespace std;

int main()
{
    int n;
    long long l1=2,l3,l2=1;
    cin>>n;

    if(n==1)
       
          cout<<1;
       else
        {

        for(int i=2 ; i <= n ; i ++)
              {
                  l3=l1+l2;
                  l1=l2;
                  l2=l3;

              }
       cout<<l3;
       }



}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int count = 0;
		int exp = 1;
		boolean possible = false;

		for(int i = 1; i <= n; i++) {
			int a = sc.nextInt();

			if(a != exp) {
				count++;
				continue;
			}

			exp++;
			possible = true;

		}

		if(possible) {
			System.out.println(count);
		}else {
			System.out.println(-1);
		}

		sc.close();

	}

}


Measured memory_bytes: 63208
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <math.h>
#include <tuple>

#include <set>
#include <unordered_map>
#include <stack>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T>bool chmaxj(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; }
void YesNo(bool y) { cout << (y ? "Yes" : "No") << endl; } //true==yes


#define INF 21474836

//////////////////////////////////////////////////////////////


int main() {


	long long N;
	cin >> N;
	long long ans = 0;

	rep(i, N+1) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
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(){
  ll N,A,B;
  cin>>N>>A>>B;
  vector<int> X(N);
  REP(i,N){
    int P;
    cin>>P;
    P--;
    X[P]=i;
  }
  
  vector<vector<ll>> DP(N+1,vector<ll>(N+1,INF));
  REP(i,N+1) DP[0][i]=0;
  
  REP(i,N){
    REP(j,N+1){
      if(j>0) DP[i+1][j]=DP[i+1][j-1];
      chmin(DP[i+1][j],DP[i][j]+(X[i]<=j-1 ? A : B));
      if(X[i]==j-1) chmin(DP[i+1][j],DP[i][j-1]);
    }
  }
  cout<<DP[N][N]<<endl;
  return 0;
}

Measured memory_bytes: 198712
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	// ReadString returns a WORD string.
	ReadString func() string
)

func init() {
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
}

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt64() int64 {
	n, _ := strconv.ParseInt(ReadString(), 10, 64)
	return n
}

func readInt() int {
	return int(readInt64())
}

// 10 11 12 => [10, 11, 12]
func readIntSlice(size int) []int {
	a := make([]int, size)
	for i := 0; i < size; i++ {
		a[i] = readInt()
	}
	return a
}

func get2byte(size int) [][]byte {
	a := make([][]byte, size)
	for i := 0; i < size; i++ {
		var low string
		fmt.Scan(&low)
		a[i] = []byte(low)
	}
	return a
}

func transpose(a [][]int) {
	n := len(a)
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a[i][j], a[j][i] = a[j][i], a[i][j]
		}
	}
}

func fact(n, m int) int {
	res := 1
	for i := m + 1; i <= n; i++ {
		res *= i
	}
	return res
}

func perm(n, r int) int {
	if r > n {
		return 0
	}
	return fact(n, n-r)
}

func comb(n, m int) int {
	if m > n {
		return 0
	}
	return fact(n, n-m) / fact(m, 0)
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

type Range struct {
	Left  int
	Right int
}

func main() {
	var mod int64 = 998244353
	N, K := readInt(), readInt()
	var ranges []Range
	for i := 0; i < K; i++ {
		ranges = append(ranges, Range{
			Left:  1 - readInt(),
			Right: -readInt(),
		})
	}
	results := make([]int64, N)
	results[0] = 1
	rangeSum := make([]int64, K)
	for i := 1; i < N; i++ {

		for j, r := range ranges {
			if r.Right >= 0 {
				rangeSum[j] -= results[r.Right]
			}
			if r.Left >= 0 {
				rangeSum[j] += results[r.Left]
			}
			rangeSum[j] %= mod
			if rangeSum[j] < 0 {
				rangeSum[j] += mod
			}
			ranges[j].Right++
			ranges[j].Left++
		}
		for _, s := range rangeSum {
			results[i] += s
			results[i] %= mod
			if results[i] < 0 {
				results[i] += mod
			}
		}
	}
	fmt.Println(results[N-1])

}


Measured memory_bytes: 3416
#include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;

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

int main()
{
  int w=0;
  int n=0;
  cin >> w >> n;

  int lines[w+1];
  REP(i,w+1)
    lines[i] = i;

  REP(i,n){
    int from, to;
    char del;
    cin >> from >> del >> to;
    swap(lines[from], lines[to]);
  }

  for(int i=1; i<w+1; i++)
    cout << lines[i] << endl;

  return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <math.h>
#define PI 3.14159265359
int main(void)
{
    int a,b,C;
    double S,L,h,R;
    scanf("%d %d %d",&a,&b,&C);
    
    R=C*PI/180;
    S=0.5*a*b*sin(R);
    L=a+b+sqrt(a*a+b*b-2*a*b*cos(R));
    h=2*S/a;
    

    printf("%.8f\n%.8f\n%.8f\n",S,L,h);
    
    return 0;
}



Measured memory_bytes: 2040
#include<stdio.h>
#include<string.h>
int main()
{
    int n;
    char s[10010];
    scanf("%d %s",&n,s);
    int len=strlen(s);
    for(int i=0;i<len;i++){
        int x=s[i]-'A';
        x=(x+n)%26;
        putchar('A'+x);
        }
    putchar('\n');
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define int long long
#define INF 1000000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);



signed main(){

    int N; cin >> N;
    vec A(N); readvec(A);

    map<int, int> m;
    REP(i, N) m[A[i]] += 1;
    int n = 0;
    for(auto p: m) n += p.second - 1;
    cout << N - (n + 1) / 2 * 2;
    
    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 7296
int main(void){
 int n;
 int a;
 int i;
 int from[101];
 int to[101];
 scanf("%d",&n);
   
 for(i=0;i<n;i++){
  scanf("%d",&a);
  from[i] = a;
 }
  
 for(i=0;i<n;i++){
  to[i] = from[(n-1)-i];
 }
  
   
 for(i=0;i<n;i++){
  if(i == n-1){
   printf("%d\n",to[i]);
  }else{
   printf("%d ",to[i]);
  }
 }
 return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define MAXN 200005
#define TRACE(x) cout<<#x<<" = "<<x<<'\n'
#define TRACE2(x, y) cout<<#x<<" = "<<x<<" "<<#y<<" = "<<y<<'\n'
#define TRACEA(arr, i) cout<<#arr<<"["<<i<<"]"<<" = "<<arr[i]<<'\n'
#define PRINT(arr, n) for (int iDx = 0; iDx < (n); iDx++) cout << arr[iDx] << " \n"[iDx == (n)-1]
#define SZ(x) (int)(x).size()
using namespace std;
struct ii {
	int a, b;
	bool operator < (ii o) const { return tie(a, b) < tie(o.a, o.b); }
	bool operator > (ii o) const { return tie(a, b) > tie(o.a, o.b); }
};
struct iii {
	int a, b, c;
	bool operator < (iii o) const { return tie(a, b, c) < tie(o.a, o.b, o.c); }
};
int TC, N, M, K, Q, x, y, z;

vector<ii> h1, h2, v1, v2;
int pacar[MAXN], pos[MAXN];
vector<int> rec;
bool bisa;

void cek(int l, int r) {
	if (pacar[l] > r) bisa = 0;
	else {
		if (l+1 <= pacar[l]-1) cek(l+1, pacar[l]-1);
		if (pacar[l]+1 <= r) cek(pacar[l]+1, r);
	}
}

bool ujung(int x, int y) {
	return x == 0 || x == N || y == 0 || y == M;
}

void masukin(int a, int b, int i) {	
	if (a == 0) h1.push_back({b, i});
	else if (b == M) v2.push_back({a, i});
	else if (a == N) h2.push_back({b, i});
	else if (b == 0) v1.push_back({a, i});
}

int main() {
	#ifdef FAIRUZI10
	freopen("/home/fairuzi/Documents/CP/input.in", "r", stdin);
	#endif
	
	scanf("%d%d%d", &N, &M, &K);
	for (int i = 0; i < K; i++) {
		int a, b, c, d;
		scanf("%d%d%d%d", &a, &b, &c, &d);
		if (!(ujung(a, b) && ujung(c, d))) continue;
		masukin(a, b, i);
		masukin(c, d, i);
	}
	sort(h1.begin(), h1.end());
	sort(h2.begin(), h2.end(), greater<ii>());
	sort(v1.begin(), v1.end(), greater<ii>());
	sort(v2.begin(), v2.end());
	for (auto i: h1) rec.push_back(i.b);
	for (auto i: v2) rec.push_back(i.b);
	for (auto i: h2) rec.push_back(i.b);
	for (auto i: v1) rec.push_back(i.b);
	
	memset(pos, -1, sizeof(pos));
	for (int i = 0; i < SZ(rec); i++) {
		if (pos[rec[i]] == -1) pos[rec[i]] = i;
		else {
			pacar[pos[rec[i]]] = i;
			pacar[i] = pos[rec[i]];
		}
	}
	bisa = 1;
	if (!rec.empty()) cek(0, SZ(rec)-1);
	if (bisa) puts("YES");
	else puts("NO");
	
	return 0;
}


Measured memory_bytes: 6868
function Main(input) {
  var n = parseInt(input.split(" ")[0]);
  var a = parseInt(input.split(" ")[1]);
  var b = parseInt(input.split(" ")[2]);
  
  var densya = a * n;
  if(densya > b){
     console.log(b);
     }else{
       console.log(densya);
     }
  
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <bits/stdc++.h>//stayCalmNeverSettle
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define endl "\n"
#define pb push_back
#define x first
#define y second
using namespace std;
typedef long long ll;

const ll M = 1e9+7;

void solve(){
	ll a,ans;
	long double b;
	cin >> a >> b;
	ans = round(b*100);
	cout << (a*ans)/100 << endl;
}   
    
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if(A + B > C + D) {
    cout << "Left" << endl;
  }
  else if (A + B == C + D) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}


Measured memory_bytes: 3584
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define F first
#define S second
#define MK make_pair




int main(){
    int n;
    cin>>n;
    if(n%2==0){n/=2;}
    cout<<n*2<<endl;
    
    
    return 0;
}




Measured memory_bytes: 384
N = int(input())
A = []
largest = -1
second_largest = -1
more_than_one_largetst = False

for i in range(N):
  a = int(input())
  A.append(a)
  if largest == a:
    more_than_one_largest = True
  else:
    if largest < a:
      second_largest = largest
      largest = a
      more_than_one_largest = False
    else:
      if second_largest < a:
        second_largest = a
      else:
        pass

for a in A:
  if a != largest:
    print(largest)
  else:
    if more_than_one_largest:
      print(largest)
    else:
      print(second_largest)


Measured memory_bytes: 12524
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
      }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
const int MAX = 5e5;


signed main(){
   string str[3];
   rep(i,3)cin >> str[i];
   cout << "A" << str[1][0] << "C" << endl;
  return 0;
}










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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    string S;
    int cnt = 0;
    cin >> S;
    if (S[0] == 'A') {
        S.erase(0, 1);
        for (int i = 1; i < S.size() - 1; i++) {
            if (S[i] == 'C') {
                cnt++;
                S.erase(i, 1);
            }
        }
        if (cnt == 1) {
            bool flag = true;
            for (int i = 0; i < S.size(); i++) {
                if (S[i] >= 'A' && S[i] <= 'Z') {
                    flag = false;
                }
            }
            if (flag) {
                AC;
                return 0;
            }
        }
    }
    WA;
}


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

int main(){
  int n;
  cin>>n;
  vector<long long int> a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  vector<long long int> s(n);
  s[0]=a[0];
  for(int i=1;i<n;i++) s[i]=s[i-1]+a[i];

  int lb=-1;
  int ub=n;
  while(ub-lb>1){
    int mid=(lb+ub)/2;
    long long int now_size=s[mid];
    bool ispos=true;
    for(int i=mid+1;i<n;i++){
      if(now_size*2<a[i]){
	ispos=false;
      }
      else{
	now_size+=a[i];
      }
    }
    if(ispos){
      ub=mid;
    }
    else{
      lb=mid;
    }

  }
  cout<<n-ub<<endl;
  return 0;
}


Measured memory_bytes: 1792
import fractions

N = int(input())
a = list(map(int, input().split()))

# 最小公倍数
lcm = a[0]
for i in range(1, N):
    lcm = lcm * a[i] // fractions.gcd(lcm, a[i])

total = 0
for i in range(N):
    total += (lcm - 1) % a[i]
print(total)

Measured memory_bytes: 5472
#include<stdio.h>
int main(){

  int n,i;
  int number[100];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%d",&number[i]);
  }

  for(i=0;i<n;i++){
    if(i)printf(" ");
    printf("%d",number[n-i-1]);
  }
  printf("\n");
  return 0;
}
    

Measured memory_bytes: 1028
import java.util.*;

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

        int N = Integer.parseInt(sc.next());


        int ans = 0;
        for(int i=1; i<=N; i++){
            ans += i;
        }

        System.out.println(ans);
    }
}


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

int main(){
  int N;
  cin >> N;
  vector<int> P(N);
  for(int i=0;i<N;i++){
    cin >> P.at(i);
  }
  sort(P.rbegin(),P.rend());
  P.at(0)/=2;
  int sum=0;
  for(int i=0;i<N;i++){
    sum+=P.at(i);
  }
  cout << sum << endl;
}
  
  

Measured memory_bytes: 3632
N, K = map(int, input().split())
P = list(map(int, input().split()))

#期待値L
L = [0 for _ in range(N)]
for i in range(N):
    L[i] = (1+P[i])/2

#累積和S
S = [0 for i in range(N)]
S[0] = L[0]
for i in range(1, N):
    S[i] = S[i-1] + L[i]

total = S[K-1]
for i in range(N-K):
    tmp = S[i+K]-S[i]
    if total < tmp:
        total = tmp

print(total)

Measured memory_bytes: 24812
#include <stdio.h>
int main(void)
{
    int H,W,i,j;
    while(1)
    {
    scanf("%d%d",&H,&W);
    if(H==0&&W==0)
            break;
    for(i=0;i<H;i++)
    {
        for(j=0;j<W;j++)
        {
            if(H==0&&W==0)
            break;
            if(i>0&&i<H-1&&j>0&&j<W-1)
            {
                printf(".");
            }
            else printf("#");
        }
        printf("\n");
    }
    printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2040
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
cnt = 0
def dm(i, j):
    d = min(a[i], b[j])
    a[i] -= d; b[j] -= d
    return d

for i in range(n):
    cnt += dm(i, i)
    cnt += dm(i + 1, i)
print(cnt)

Measured memory_bytes: 25384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
int sum=0;
vector<int> a[2500];	
int n,k;
int dfs(int x,int fa,int d)
{
	if(d>k/2) return 0; ++sum;
	for(int i=0;i<a[x].size();++i)
	{
		int son=a[x][i];
		if(son==fa) continue;
		dfs(son,x,d+1);
	}
	return 0;
}
int main ()
{

	scanf("%d%d",&n,&k);
	for(int i=1;i<n;++i)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y); a[y].push_back(x);
	}
	int ans=0;
	for(int i=1;i<=n;++i)
	{
		sum=0;
		if(k%2==0) dfs(i,0,0);
		else dfs(i,a[i][0],0),dfs(a[i][0],i,0);
		ans=max(sum,ans);
//		cout<<ans<<" "<<sum<<"  "<<i<<endl;
	}
	printf("%d\n",n-ans);
       return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

const int MAXN = 1e6 + 100;
int a[MAXN], n, sol;

int main()
{
	int d;
	scanf("%d %d",&n,&d);
	int sol = 0;
	for (int i = 1;i<=n;i++)
	{
		long long x,y;
		scanf("%lld %lld",&x,&y);

		long long dd = d*1LL*d;

		if (dd >= x*x + y*y)sol++;


	}
	printf("%d\n",sol);
	return 0;
}

Measured memory_bytes: 3824
#include <stdio.h>
#include <string.h>

#define LENGTH 4

int count(char judge[LENGTH], char result[LENGTH]) {
    int compare = strcmp(judge, result);
    if (compare == 0) return 1;

    return 0;
}

int main(void) {
    int n;
    do {
        scanf("%d", &n);
    } while (n < 1 || 100000 < n);

    char result[n][LENGTH];
    for (int i = 0; i < n; i++) {
        scanf("%s", result[i]);
    }

    int ACcount = 0, WAcount = 0, TLEcount = 0, REcount = 0;
    for (int i = 0; i < n; i++) {
        if (count("AC", result[i]) == 1) {
            ACcount++;
        } else if (count("WA", result[i]) == 1) {
            WAcount++;
        } else if (count("TLE", result[i]) == 1) {
            TLEcount++;
        } else if (count("RE", result[i]) == 1){
            REcount++;
        }
    }

    printf("AC x %d\n", ACcount);
    printf("WA x %d\n", WAcount);
    printf("TLE x %d\n", TLEcount);
    printf("RE x %d\n", REcount);

    return 0;
}


Measured memory_bytes: 2092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;
const int MAX = 510000;
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 modPow(long long a, long long n, long long p) {
  if (n == 0) return 1; // 0乗にも対応する場合
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
  long long t = modPow(a, n / 2, p);
  return (t * t) % p;
}


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

    int n,a,b;
    cin>>n>>a>>b;
    COMinit();
    int ans=modPow(2,n,MOD);
    
    ans--;
    int def=1;
    rep(i,a){
        def*=n-i;
        def%=MOD;
    }
    def*=finv[a];
    ans-=def%MOD;
    def=1;
    rep(i,b){
        def*=n-i;
        def%=MOD;

    }
    def*=finv[b];
    ans-=def%MOD;
    while(ans<0) ans+=MOD;
    cout << ans << endl;





}


Measured memory_bytes: 12160
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    int inf,sup;

    //printf("Input sup(10000~):");
    scanf("%d",&sup);
    //printf("input inf(~99999):");
    scanf("%d",&inf);
    int i;
    int rest;
    int count=0;

    for(i=sup;i<=inf;i++){
        if((i%10)==i/10000){
            rest=(i%100)/10;
            if((i/1000)%10==rest){
                count++;
            }
        }
    }
    printf("%d",count);
    return 0;


}



Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		int sum = 0;
		for (int i = 1; i <= n; i += 2) {
			if (enumDivisors(i).size() == 8) {
				sum++;
			}
		}
		System.out.println(sum);
		sc.close();
	}

	//約数列挙
	//約数列挙の処理は、計算量O(√N)
	static List<Long> enumDivisors(long n) {
		List<Long> list = new ArrayList<>();
		for (long i = 1; i * i <= n; i++) {
			if (n % i == 0) {
				list.add(i);
				if (n / i != i) {
					list.add(n / i);
				}
			}
		}
		Collections.sort(list);
		return list;
	}
}

Measured memory_bytes: 35712
#include <stdio.h>
int main(void){
    int n,m,a,b;
    int i,j;
    
    scanf("%d %d %d %d",&n,&m,&a,&b);
    
    int aset[n],bset[m];
    int maxa=a,minb=b;
    for(i=0;i<n;i++){
        scanf("%d",&aset[i]);
        if(aset[i]>maxa){
            maxa=aset[i];
        }
    }
    for(j=0;j<m;j++){
        scanf("%d",&bset[j]);
        if(bset[j]<minb){
            minb=bset[j];
        }
    }
    
    if(maxa>=minb){
        printf("War\n");
    }else{
        printf("No War\n");
    }
    
    return 0;
}


Measured memory_bytes: 128
n,m = map(int,input().split())
ipyx=[]
for _ in range(m):
  p_,y_ = map(int,input().split())
  ipyx.append([_+1,p_,y_,0])
"""
2 3
1 32
2 63
1 12
->
000001000002
000002000001
000001000001

2 3
2 5
2 77
2 99
->
000002000001
000002000002
000002000003
"""
# ipyx = [i,p,y,x]
A=[1]*(n+1)
ipyx.sort(key=lambda x:x[2])
for j in ipyx:
  j[3] = A[j[1]]
  A[j[1]] += 1
ipyx.sort(key=lambda x:x[0])
for j in ipyx:
  print(('00000'+str(j[1]))[-6:]+('00000'+str(j[3]))[-6:])


Measured memory_bytes: 29732
s = input()
t = input()
x = []
y = []
for i in range(len(s)):
    if s[i] not in x:
        x.append(s[i])
    if t[i] not in y:
        y.append(t[i])
for i in range(len(x)):
    s = s.replace(x[i], str(i))
for i in range(len(y)):
    t = t.replace(y[i], str(i))
if s == t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9624
def count(P, N):
  cnt = 0
  min = P[0]
  M = [0] * N
  for i in range(N):
    if P[i] <= min:
      M[i] = P[i]
      min = P[i]
      cnt += 1
    else:
      M[i] = min
        
  return cnt

N = int(input())
P = list(map(int, input().split()))
print(count(P, N))

Measured memory_bytes: 26012
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;
static const ll MOD = 1000000007;

int main(){
	int N, M;
	cin >> N >> M;
	vector<int> S(N + 1, 0), T(M + 1, 0);
	for(int i = 1; i < N + 1; i++) cin >> S[i];
	for(int i = 1; i < M + 1; i++) cin >> T[i];
	vector<vector<ll>> memo(N + 1, vector<ll>(M + 1, 0));
	for(int i = 0; i < N + 1; i++){
		for(int j = 0; j < M + 1; j++){
			if(i == 0 || j == 0) memo[i][j] = 1;
			else if(S[i] != T[j]) memo[i][j] = memo[i - 1][j] + memo[i][j - 1] - memo[i - 1][j - 1];
			else memo[i][j] = memo[i - 1][j] + memo[i][j - 1];
			while(memo[i][j] < 0) memo[i][j] += MOD;
			memo[i][j] %= MOD;
		}
	}
	cout << memo[N][M] << endl;
	return 0;
}

Measured memory_bytes: 31616
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using namespace std;
//LLONG_MAX = 90^18
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No"); }
void Yes() { cout << "Yes"; }
void No() { cout << "No"; }
//max_element


int N, K;
int A[200010];
bool flg[200010];
vector<int> path;

signed main()
{
	cin >> N >> K;
	REP(i, N)
	{
		cin >> A[i + 1];
	}

	int cur = 1;
	path.push_back(1);
	flg[1] = true;
	int loop_pos = 0;
	while (true)
	{
		int next = A[cur];
		if (flg[next])
		{
			for (int i = 0; i < path.size(); i++)
			{
				if (path[i] == next)
				{
					loop_pos = i;
				}
			}
			break;
		}
		else
		{
			flg[next] = true;
			path.push_back(next);
		}
		cur = next;
	}


	if (loop_pos > K)
	{
		cout << path[K] << endl;
	}
	else
	{
		int rest = K - loop_pos;
		int s = path.size() - loop_pos;
		int m = rest % s;
		cout << path[loop_pos + m] << endl;
	}
}




Measured memory_bytes: 7040
N=int(input())
S=list(input()[0] for _ in range(N))
m=S.count('M')
a=S.count('A')
r=S.count('R')
c=S.count('C')
h=S.count('H')
print(m*a*r+m*a*c+m*a*h
      +m*r*c+m*r*h
      +m*c*h
      +a*r*c+a*r*h
      +a*c*h
      +r*c*h)

Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
inline int getInt() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MX = 200005;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//---------------------------------------------------------------
#define fastio std::ios::sync_with_stdio(false);
#define myio ifstream iofi; if(argc>1){iofi.open(argv[1]); std::cin.rdbuf(iofi.rdbuf());}
//--------------------------------------------------------------


int main(int argc,char** argv){ fastio; myio;
  int h,w;
  cin>>h>>w;
  v(string) s(h);
  cin>>s;
  vvi can(h,vi(w,0));
  rep(i,h) rep(j,w){
    if(s[i][j]=='#'){
      if(0<=i-1) can[i-1][j]=1;
      if(i+1<h ) can[i+1][j]=1;
      if(0<=j-1) can[i][j-1]=1;
      if(j+1<w ) can[i][j+1]=1;
    }
  }
  rep(i,h) rep(j,w){
    if(s[i][j]=='#' and can[i][j]==false){
      cout<<"No"; return 0;
    }
  }
  cout<<"Yes"; return 0;
}

Measured memory_bytes: 256
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1,n-1):
        lp = j+1
        rp = n-1
        while lp < rp:
            mp = (lp+rp)//2
            if l[mp] < l[i] + l[j]:
                lp = mp+1
            else:
                rp = mp-1
        if l[lp] < l[i] + l[j]:
            ans += lp-j
        else:
            ans += lp-j-1
print(ans)
   

Measured memory_bytes: 44900
use std::io::Read;
use std::f64::consts::PI;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    solve(&buf);
}

fn solve(input: &str) {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();


    let p1 = Point { x: 0.0, y: 0.0 };
    let p2 = Point { x: 100.0, y: 0.0 };

    p1.print();
    koch(n, &p1, &p2);
    p2.print();
}

#[derive(Debug)]
struct Point {
    x: f64,
    y: f64
}

impl Point {
    fn print(&self) {
        println!("{:.8} {:.8}", self.x, self.y);
    }
}

fn koch(n: usize, start: &Point, end: &Point) {
    if n == 0 {
        return;
    }

    let th = PI * 60.0 / 180.0;
    let p1 = Point {
        x: (2.0 * start.x + end.x) / 3.0,
        y: (2.0 * start.y + end.y) / 3.0,
    };
    let p3 = Point {
        x: (start.x + 2.0 * end.x) / 3.0,
        y: (start.y + 2.0 * end.y) / 3.0,
    };
    let p2 = Point {
        x: (p3.x - p1.x) * th.cos() - (p3.y - p1.y) * th.sin() + p1.x,
        y: (p3.x - p1.x) * th.sin() + (p3.y - p1.y) * th.cos() + p1.y,
    };

    koch(n - 1, start, &p1);
    p1.print();
    koch(n - 1, &p1, &p2);
    p2.print();
    koch(n - 1, &p2, &p3);
    p3.print();
    koch(n - 1, &p3, end);
}



Measured memory_bytes: 5036
N = int(input())
p = list(map(int, input().split()))

a = list(range(1, N**2+1, N+1))
b = list(range(N**2+1, 1, -(N+1)))

for i in range(N):
    a[p[i]-1] += i
    b[p[i]-1] += i

a = map(str, a)
b = map(str, b)

print(" ".join(a))
print(" ".join(b))


Measured memory_bytes: 6900
fn factors(mut n: usize) -> Vec<(usize, usize)> {
    let mut d = 1;
    let mut fs = vec![];
    while d * d <= n {
        if n % d == 0 {
            fs.push((d, n / d));
        }
        d += 1;
    }
    fs
}

fn solve() {
    let n = read();
    let fs = factors(n);
    let mut res = std::usize::MAX;
    for (a, b) in fs {
        let mut restmp = 0;
        let mut atmp = a;
        let mut btmp = b;
        while atmp > 0 || btmp > 0 {
            atmp /= 10;
            btmp /= 10;
            restmp += 1;
        }
        // println!("{:?}", (a, b, restmp));
        res = min(res, restmp);
    }
    println!("{}", res);
}

fn main() {
    let stack_size = 104_857_600;
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

// =========
#[allow(unused_imports)]
use std::cmp::{max, min, Reverse};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};
#[allow(unused_imports)]
use std::process::exit;

#[allow(dead_code)]
const MOD: usize = 1000000007;

fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// =========


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

int main() {
  long h,w,k,ans=0;
  cin >> h >> w >> k;
  vector<string> c(h);
  for(long i=0;i<h;i++) cin >> c[i];
  for(long i=0;i<(1<<h);i++) {
    for(long j=0;j<(1<<w);j++) {
      long x=0;
      for(long ii=0;ii<h;ii++) for(long jj=0;jj<w;jj++) if(c[ii][jj]=='#'&&((i&(1<<ii))&&(j&(1<<jj)))) x++;
      if(x==k) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3592
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    LL K;
    cin >> N >> K;
    vector<int> A(N);
    vector<bool> visited(N);
    rep(i, N) {
        cin >> A[i];
        --A[i];
    }

    //! find loop head
    visited[0] = true;
    int loopHead = -1;
    int curr = 0;
    while (loopHead < 0) {
        int next = A[curr];
        if (visited[next]) {
            loopHead = next;
        } else {
            curr = next;
            visited[curr] = true;
        }
    }

    //! move to loop head first
    curr = 0;
    while (curr != loopHead) {
        --K;
        curr = A[curr];
        if (K == 0) {
            //! reached K moves before arriving the loop head
            cout << (curr+1) << endl;
            return 0;
        }
    }

    vector<int> loop;
    while (loop.empty() || curr != loopHead) {
        curr = A[curr];
        loop.push_back(curr);
    }

    int index = static_cast<int>((K+loop.size()-1) % loop.size());
    cout << (loop[index]+1) << endl;

    return 0;
}


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

int main(){
    int n;
    cin>>n;
    
    int x;
    x = n / 1.08;

    int n_p1=x*1.08;
    int n_p2=(x+1)*1.08;
    int n_p3=(x+1)*1.08;

    if(n_p1==n){
        cout<<x<<endl;
    }else if(n_p2==n){
        cout<<x+1<<endl;
    }else if(n_p3==n){
        cout<<x-1<<endl;
    }else{
        cout<<":("<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	string s;
	cin >> s;
	int n=s.size();
	lld ans=0;
	for(int i=0;i<(1<<n);i++)
	{
		lld temp=0;
		lld sum=0;
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				temp=temp*10+(s[j]-'0');
			}
			else
			{
				sum+=temp;
				temp=0;
			}
		}
		ans+=(sum+temp);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
#define LEN 100000
   
typedef struct pp{
    char name[100];
    int t;
}P;
   
P Q[LEN+1];
int head = 0, tail, n, empty = 0;
   
void push(P x){
    empty++;
    Q[tail] = x;
    if(tail+1 == LEN) tail = 0;
    else tail++;
}
   
P pop(){
    P res;
    empty--;
    res = Q[head];
    if(head+1 == LEN) head = 0;
    else head++;
    return res;
}
   
   
int main(){
    int time = 0, count = 0;
    int i, ms;
    P u;
    scanf("%d %d", &n, &ms);
   
    empty = n;
    tail = n;
   
    for ( i = 0; i < n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
   
    while(empty != 0){
   
        u = pop();
        if(u.t <= ms) {
            time += u.t;
            printf("%s %d\n", u.name, time);
        }
   
        else if(u.t > ms){
            time += ms;
            u.t -= ms;
            push(u);
        }
        else if(u.t == 0) continue;
    }
   
   
    return 0;
}

Measured memory_bytes: 10756
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	/** 入力数字の数 */
	private static final int NUM = 3;

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int[] a = new int[NUM];
			int sum = IntStream.range(0, NUM).map(i -> a[i] = scanner.nextInt()).sum();
			int max = Arrays.stream(a).max().getAsInt();
			System.out.println((sum == max + max) ? "Yes" : "No");
		}
	}
}


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

int main () {
  int n ; 
  cin >> n ;
  string S ; 
  cin >> S;
  int64_t cnt = 0 ; 
  vector<int64_t> A(3,0) ; 
  
  for(int i = 0 ; i < n ; i++){
    if(S.at(i) == 'R') A.at(0)++ ; 
    if(S.at(i) == 'G') A.at(1)++ ; 
    if(S.at(i) == 'B') A.at(2)++ ;     
  }

  int64_t max_n ; 
  max_n = A.at(0)*A.at(1)*A.at(2) ; 
  
  for(int i = 0 ; i < n-2 ; i++){
    for(int j = i+1 ; j < n-1 ; j++){
      int k  = j+j - i  ;
      if( k < n ) {
        if ( S.at(i) != S.at(j) && S.at(i) != S.at(k) && S.at(j) != S.at(k) ) cnt++ ; 
      }
    }
  }
  cout << max_n - cnt << endl ; 
}

Measured memory_bytes: 3648
import sys
import numpy as np
input = sys.stdin.readline

def main():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

    dp = np.zeros((N+1, W+1), dtype=int)

    for i in range(N):
        w, v = wv[i]
        dp[i+1] = dp[i]
        dp[i+1, w:] = np.maximum(dp[i+1, w:], dp[i+1, :-w] + v)
    
    print(dp[-1][-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 92216
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] b = new long[n];

        long d = sc.nextLong();
        
        for(int i = 0; i < n; i++) {
        	a[i] = sc.nextLong();
        	b[i] = sc.nextLong();
        }
        
        long D = d * d;
        
        int ans = 0;
        for(int i = 0; i < n; i++) {
        	if(D >= (a[i]*a[i] + b[i]*b[i]))
        		++ans;
        }
        System.out.println(ans);
    }

}


Measured memory_bytes: 64192
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
long long n,i,d,k;
long long dp[405][405];
long long s[405];
long long a[405];
long long sum(int l, int r)
{
    return s[r]-s[l-1];
}
int main()
{
    cin>>n;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
        s[i]=s[i-1]+a[i];

    for(d=1;d<n;d++)
    {
        for(i=1;i+d<=n;i++)
        {
            dp[i][i+d]=1e18;
            for(k=i;k<i+d;k++)
                dp[i][i+d]=min(dp[i][i+d], dp[i][k]+dp[k+1][i+d]);

            dp[i][i+d]+=sum(i, i+d);
        }
    }

    cout<<dp[1][n];
    return 0;
}


Measured memory_bytes: 4772
from heapq import *

X, Y, Z, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]
A = sorted([int(x) for x in A], reverse=True)
B = sorted([int(x) for x in B], reverse=True)
C = sorted([int(x) for x in C], reverse=True)

res = []
memo = []
ans = []
heappush(res, (-A[0]-B[0]-C[0], 0, 0, 0))
while len(ans) < K:
  e, i, j, k = heappop(res)
  ans.append(-e)
  if i+1 < X and [i+1, j, k] not in memo:
    heappush(res, (-A[i+1]-B[j]-C[k], i+1, j, k))
    memo.append([i+1, j, k])
  if j+1 < Y and [i, j+1, k] not in memo:
    heappush(res, (-A[i]-B[j+1]-C[k], i, j+1, k))
    memo.append([i, j+1, k])
  if k+1 < Z and [i, j, k+1] not in memo:
    heappush(res, (-A[i]-B[j]-C[k+1], i, j, k+1))
    memo.append([i, j, k+1])

for i in ans:
  print(i)

Measured memory_bytes: 4852
#include <iostream>
#include <queue>
#include <utility>

using namespace std;

typedef pair<int, int> P;

int n, m, s, t;
vector<int> edge[110000];
queue<P> q;
bool visited[110000];

int main()
{
  cin >> n >> m;
  
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    edge[u].push_back(v);
  }
  
  cin >> s >> t;
  
  q.push(make_pair(s, 0));
  visited[s] = true;
  
  while (q.size()) {
    for (int v: edge[q.front().first]) {
      for (int w: edge[v]) {
        for (int x: edge[w]) {
          if (visited[x]) continue;
          visited[x] = true;
          if (x == t) {
            cout << q.front().second+1 << endl;
            return 0;
          }
          q.push(make_pair(x, q.front().second+1));
        }
      }
    }
    q.pop();
  }
  
  cout << -1 << endl;
  return 0;
}

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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

bool comp(P a, P b){return a.second < b.second;}

void findAllOccurances(vector<size_t>& vec, string& data, string toSearch)
{
    size_t pos = data.find(toSearch);
    while( pos != string::npos)
    {
        vec.push_back(pos);
        pos = data.find(toSearch, pos + toSearch.size());
    }
}

int main() {
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    string s, t; cin >> s >> t;
    int len = s.size();
    int last_index = 0;
    bool ret = false;
    for(int i = 0; i < s.size() - t.size() + 1; ++i){
        bool flag = true;
        for(int j = 0; j < t.size(); ++j){
            if(s[i + j] != '?' && s[i + j] != t[j]){
                flag = false;
                break;
            }
        }
        if(flag){
            ret = true;
            last_index = i;
        }
    }

    if(!ret){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }

    for(int j = 0; j < t.size(); ++j){
        s[last_index + j] = t[j];
    }
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == '?'){
            s[i] = 'a';
        }
    }
    cout << s << endl;

    return 0;
}



Measured memory_bytes: 256