akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
	Scanner sc;
	int N, L, R, M, D;
	static final int[] P10;
	static {
		P10 = new int[10];
		P10[0] = 1;
		for (int i = 1; i < 10; i++) P10[i] = P10[i-1]*10;
	}
	
	private void calc() {
		sc = new Scanner(System.in);
		N = sc.nextInt();
		String sn = String.valueOf(N);
		D = sn.length();
		L = sn.charAt(0) - '0';
		R = N%10;
		M = (D==1)?0:Integer.parseInt(sn.substring(1))/10;
		
		int sum = 0;
		for (int a = 1; a < 10; a++) {
			int c = count(a, a);
			sum += c * c;
			for (int b = a+1; b < 10; b++) {
				sum += 2 * count(a, b) * count(b, a);
			}
		}
		
		System.out.println(sum);
	}
	
	private int count(int a, int b) {
		int c = 0;
		if (a == b && a <= N) c++;
		for (int d = 2; d < D; d++) c += P10[d-2];
		if (D >= 2) {
			if (a < L) {
				c += P10[D-2];
			} else if (a == L) {
				if (b > R) c += M;
				else c += M+1;
			}
		}
		return c;
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw_2(62,1);


int main(){
    string s; cin>>s;
    ll N=sz(s)+1;
    vector<ll> ans(N,0);
    //A: 0 1 2 3 4 5 ..... N-1
    //s:  0 1 2 3 ..... N-2
    rep(i,N-1){
        if(s[i]=='<') chmax(ans[i+1],ans[i]+1);
    }
    rrep(i,N-1){
        if(s[i]=='>') chmax(ans[i],ans[i+1]+1);
    }
    ll ANS=0;
    rep(i,N) ANS+=ans[i];
    cout<<ANS<<endl;
}



Measured memory_bytes: 7656
#include <bits/stdc++.h>
using namespace std;
#define pair pair<int, int>
typedef long long ll;

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair> a(m);
    for(int i=0; i<m; i++) {
        int x, y;
        cin >> x >> y;
        a[i].first = y;
        a[i].second = x;
    }
    sort(a.begin(),a.end());
    int ans = 0, d = 0;
    for(int i=0; i<m; i++) {
        if(d <= a[i].second) {
            ans++;
            d = a[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4024
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>

// macros
#define ll long long int
#define pb push_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a); i<(b);++i)
#define rep(i, n) FOR(i, 0, n)

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
ll dp[100][3];

int main(int argc, char const* argv[])
{
  ll n;
  cin >> n;
  ll tmp = n;
  vector<int> vec;
  while(tmp){
    vec.pb(int(tmp % 2));
    tmp /= 2;
  }
  reverse(vec.begin(), vec.end());
  dp[0][0] = 1;
  FOR(i, 1, vec.size() + 1){
    dp[i][0] = dp[i-1][0];
    if(vec[i-1] == 0)dp[i][0] = (dp[i][0] + dp[i-1][1]) % mod;
    if(vec[i-1] == 0){
      dp[i][1] = dp[i-1][1];
    }else{
      dp[i][1] = (dp[i-1][0] + dp[i-1][1]) % mod;
    }
    dp[i][2] = dp[i-1][2] * 3 % mod;
    if(vec[i-1] == 0){
      dp[i][2] = (dp[i][2] + dp[i-1][1]) % mod;
    }else{
      dp[i][2] = (dp[i][2] + dp[i-1][1] * 2) % mod;
    }
  }
  cout << (dp[vec.size()][0] + dp[vec.size()][1] + dp[vec.size()][2]) % mod << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a0 = 1
a1 = 1

#print(a0, a1, end='')
if n == 0 or n == 1:
    a2 = 1

else:
    for i in range(n-1):
        a2 = a0 + a1
        a0 = a1
        a1 = a2
    #print('',a2,end='')
print(a2)


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

int main(void){
    string s;
    cin >> s;
    ll k;
    cin >> k;
    char ans = '1';
    ll i;
    for(i=0;i<=s.length()-1;i++){
        if(s[i] != '1'){
            ans =s[i];
            break;
        }
    }
    if(i>k-1){
        ans = '1';
    }
    
    cout << ans <<endl;
    
    return 0;
}


















































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

int a[100010];

int main(){
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		scanf("%d", a + i);
	sort(a, a + n);
	printf("%d\n", a[n / 2] - a[(n-1) / 2]);
}


Measured memory_bytes: 640
n=int(input())
G=[]
for i in range(n):
    u,k,*l=map(int,input().split())
    G.append(l)
#print(G)

#BFS
from collections import deque
def bfs(G,v,p):
    que=deque()
    que.append((v,p))
    log=[-1]*n
    log[0]=0
    while que:
        #queの先頭を取り出す
        V,P=que.popleft()
        for next_v in G[V-1]:
            if log[next_v-1]!=-1:continue
            log[next_v-1]=log[V-1]+1
            que.append((next_v,V))
    return log

log=bfs(G,1,-1)
for i in enumerate(log,1):
    print(*i)


Measured memory_bytes: 6032
#include <iostream>
#include <math.h>
#include <limits>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define rep(i, n) for (int i =0; i < (int)(n); i++)
typedef pair<int, string> P;


int main() {
    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N)cin >> P[i];
    rep(i, N)cin >> Q[i];

    vector<int> a(N);
    rep(i, N)a[i] = i + 1;//順列作成用

    map<vector<int>, int> mp;
    int x = 0;

    do {
        mp[a] = x;
        x++;
    } while (next_permutation(a.begin(), a.end()));

        int ans = abs(mp[P] - mp[Q]);
    cout << ans << endl;
}

Measured memory_bytes: 5248
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define fi first
#define se second

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

  int64 n, m; cin >> n >> m; 

  int64 a[n], b[n];
  rep(i, n) cin >> a[i] >> b[i];

  vector<pll> v;

  rep(i, n){
    v.emplace_back(a[i], b[i]);
  }

  sort(all(v));

  int64 ans = 0;

  for (int i = 0; i < n; ++i){
    if (v[i].second >= m){
      ans += m * v[i].first;
      print(ans); return 0;
    }
    else {
      ans += v[i].second * v[i].first;
      m -= v[i].second;
    }
  }


  return 0;
}

Measured memory_bytes: 3956
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
    ll n,ans=INF,ans_=0; cin>>n;
    vector<ll> sum(n,0);
    ll cnt=0;
    rep(i,n){
        cin>>sum[i];
        sum[i]+=cnt; cnt=sum[i];
    }
    ll a=1,d=0;
    rep(i,n){
        if(a*(sum[i]+d)<=0){
            ans_+=abs(a-(sum[i]+d));
            d+=a-(sum[i]+d); 
        }
        a*=(-1);
    }
    ans=min(ans,ans_);
    a=-1; d=0; ans_=0;
    rep(i,n){
        if(a*(sum[i]+d)<=0){
            ans_+=abs(a-(sum[i]+d));
            d+=a-(sum[i]+d); 
        }
        a*=(-1);
    }
    cout<<min(ans,ans_)<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb(x) push_back(x)
#define f(i,st,n) for(i=st;i<n;i++)
#define qu queue
#define ps(x) push(x)
#define vec vector
#define ft() front()
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mst(a,b) memset(a,b,sizeof(a))
#define mod 1000000007
#define sfl(x) scanf("%lld",&x)
#define pfl(x) printf("%lld\n",x)
#define pf(x) printf("%lld",x)
#define mpr make_pair
#define fs first
#define se second
#define inf LLONG_MAX
#define nnf LLONG_MIN





ll gcd(ll a, ll b) {
  if (a == 0) {
    return b;
  }
  return gcd(b % a, a);
}
ll power(ll x, ll y) {
  ll res = 1;
  while (y > 0) {
    if (y % 2 == 1) {
      res = ((res) * (x)) ;
    }
    x = ((x) * (x)) ;
    y = y / 2;
  }
  return res;
}



int main() {

  fast

/*#ifndef ONLINE_JUDGE

  freopen("input.txt", "r", stdin);

  freopen("output.txt", "w", stdout);
#endif*/

  ll n,i,x,ans=0;

  sfl(n);

  map<ll,ll>mp;

  f(i,1,n+1){

      sfl(x);
       ans+=mp[i-x];

       mp[x+i]++;

  }
  pf(ans);
  return 0;





}

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

#define REP(i,n) for(int i = 0; i < (n); ++i)
#define REP1(i,n) for(int i = 1; i <= (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)
#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

constexpr int MOD = 1e9 + 7;
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 4 * 1e18 + 1;
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n, m, d;
	cin >> n >> m >> d;
	double e = ((double) n + max(n - 2 * (d == 0 ? INF : d), 0)) / n / n;
	cout << fixed << setprecision(10) << e * (m - 1) << "\n"; 
	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		List<Long> list = new ArrayList<Long>(); 
		br.readLine();
		String str;
		while((str = br.readLine()) != null){
			list.add(Long.valueOf(str));
		}
		int cursor = list.size() - 2;
		long maxProfit = list.get(cursor + 1) - list.get(cursor);
		long a, b;
		long max = (a = list.get(cursor + 1)) > (b = list.get(cursor)) ? a : b;
		cursor--;
		while(cursor >= 0){
			if(max - list.get(cursor) > maxProfit){
				maxProfit = max - list.get(cursor);
			}
			if(list.get(cursor) > max){
				max = list.get(cursor);
			}
			cursor--;
		}
		System.out.println(maxProfit);
	}
}

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

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }



int main(){
    LL n, t;
    cin >> n >> t;
    vector<vector<LL>> dp(n+1, vector<LL>(t+1));
    vector<pair<LL,LL>> dish(n);
    for(LL i = 0; i < n; ++i){
        LL a, b;
        cin >> dish[i].first >> dish[i].second;
    }
    sort(dish.begin(), dish.end());

    LL ans = 0;
    for(LL i = 0; i < n; ++i){
        for(LL j = 0; j < t; ++j){
            LL t2 = min(t, j + dish[i].first);
            dp[i+1][t2] = max(dp[i+1][t2], dp[i][j] + dish[i].second);
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
        dp[i+1][t] = max(dp[i+1][t], dp[i][t]);
    }
    cout << dp[n][t] << endl;
    return 0;
}



Measured memory_bytes: 70784
#include <iostream>
#include <string>

int main() {
    std::ios_base::sync_with_stdio(0);
    int n;
    std::cin >> n;
    std::string a,b;
    std::cin >> a >> b;
    for (int i=0;i<n;++i) {
        std::cout.put(a[i]);
        std::cout.put(b[i]);
    }
    std::cout << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include<set>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <typeinfo>
#include <utility> 
#define all(x) (x).begin(),(x).end()
#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const ll MOD = 1e9 + 7;

int dp[12][1500];
int d, g;



int main() {
	int cnt = 0;
	cin >> d >> g;
	vector<vector<int>>v;
	rep(i, 0, d) {
		int p, c;
		cin >> p >> c;
		v.push_back({ p,c });
		cnt += p;
	}

	memset(dp, -1, sizeof(dp));
	rep(i, 0, 1500) {
		dp[0][i] = 0;
	}

	rep(i, 0, d)rep(j, 0,cnt+1) {
		rep(k, 0, v[i][0]+1) {
			if (j + k < 1500) {
				if (k != v[i][0]) {
					dp[i + 1][j + k]=max(dp[i][j + k], max(dp[i][j] + k * (i + 1) * 100,dp[i+1][j+k]));
				}
				else {
					dp[i + 1][j + k]=max(dp[i][j + k], max(dp[i][j] + k * (i + 1) * 100 + v[i][1],dp[i+1][j+k]));
				}
			}
		}
	}

	rep(i, 0, cnt+1) {
		if (dp[d][i] >= g) {
			cout << i << endl;
			exit(0);
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct Node{
    int key;
    struct Node *prev, *next;
} Node;

Node *nil;

void init() {
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    x->prev = nil;
    nil->next = x;
}

Node* listSearch(int key){
    // ノードを探す
    Node *cur = nil->next;
    while (cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void deleteNode(Node *t){
    if (t == nil) return;
    t->next->prev = t->prev;
    t->prev->next = t->next;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void deleteLast(){
    deleteNode(nil->prev);
}

void printList(){
    Node *cur = nil->next;
    int count = 0;
    while(1){
        if(cur == nil) break;
        if(count++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

int main(){
    int n, i, key;
    char com[100];
    scanf("%d", &n);
    
    init();
    for(i = 0; i< n; i++){
        scanf("%s%d", com, &key);
        if (com[0] == 'i') { insert(key);}
        else if( com[0] == 'd') {
            if (strlen(com) > 6) {
                if ( com[6] == 'F') deleteFirst();
                else deleteLast();
            } else{
                deleteKey(key);
            }
            
        }
    }
    
    printList();
    
    return 0;
}


Measured memory_bytes: 32956
N, M, X = map(int, input().split())
Nlist = [[] for _ in range(N)]
Ncost = [0]*N
ans = -1

for i in range(N):
    cost_Nlist = list(map(int, input().split()))
    Ncost[i], Nlist[i] = cost_Nlist[0], cost_Nlist[1:]

for i in range(1 << N):
    total_cost = 0
    total_arugo = [0]*M
    for j in range(N):
        if(i >> j) % 2 == 0:
            continue
        total_cost += Ncost[j]
        for k in range(M):
            total_arugo[k] += Nlist[j][k]
    count = True
    for k in range(M):
        if total_arugo[k] < X:
            count = False
            break
    if count == False:
        continue
    if ans == -1:
        ans = total_cost
    else:
        ans = min(ans, total_cost)

print(ans)

Measured memory_bytes: 9228
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<signed(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const ll INF = 20000000000;
struct edge {int to,cost;};
#define VMAX 51
typedef std::pair<int,int> P;
    ll d[VMAX];
    int N,M;
    ll C[VMAX][VMAX];
    int X[VMAX],Y[VMAX];
    bool F[VMAX];
    int ans;
    void Dijkstra(int s,int x,int y) {
    	std::fill(F, F + N , false);
    	std::fill(d, d + N , INF);

    	d[s] = 0;
    	while (true) {
    		int v = -1;
    		REP(i, N) {
    			if (!F[i] && (v == -1 || d[i]<d[v]))v = i;
    		}
    		if (v == -1)break;
    		F[v] = true;
    		REP(i, N) {
    			d[i] = std::min(d[i], d[v] +
                        ((v==x&&i==y)||(v==y&&i==x)?INF:C[v][i]));
    		}
    	}
    }

int main(){
    ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,51)REP(j,51)C[i][j]=INF;
    REP(i,M){
        int a,b;
        cin>>a>>b;
        C[a-1][b-1]=C[b-1][a-1]=1;
        X[i]=a-1;Y[i]=b-1;
    }
    REP(i,std::min(50,N*(N-1)*2)){
        Dijkstra(0,X[i],Y[i]);
        REP(j,N){
            if(d[j]==INF){
                ans++;
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

//https://youtu.be/m0uWO0ngzbs?t=14m14s


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

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

  vector<int> div;
  for(int i=1;i*i<=a[0];i++){
    if(a[0]%i == 0){
      div.push_back(i);
      if(i*i!=a[0])div.push_back(a[0]/i);
    }
  }
  sort(div.begin(),div.end());

  for(int d : div){
    bool f = true;
    for(int i=0;i<n;i++){
      f &= (a[i]%d == 0);
    }
    if(f)cout << d << endl;
  }
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

#include <bits/stdc++.h>
using namespace std;

class UnionFindTree{
    private:
        vector<int> par, rank;
    
    public:
        UnionFindTree(int n) {
            par = rank = vector<int>(n);

            for (int i = 0; i < n; ++i) {
                par[i] = i;
                rank[i] = 0;
            }
        }

        int find(int x) {
            if (par[x] == x) {
                return x;
            } else {
                return par[x] = find(par[x]);
            }
        }

        void unite(int x, int y) {
            x = find(x);
            y = find(y);
            if (x == y) return;

            if (rank[x] < rank[y]) {
                par[x] = y;
            } else {
                par[y] = x;
                if (rank[x] == rank[y]) rank[x]++;
            }
        }

        bool same(int x, int y) {
            return find(x) == find(y);
        }
};

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

    vector<int> p(N);
    rep(i, N) {
        cin >> p[i];
        p[i]--;
    }

    vector<int> X(M), Y(M);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        X[i] = x, Y[i] = y;
    }

    UnionFindTree uf = UnionFindTree(N);
    rep(i, M) {
        uf.unite(X[i], Y[i]);
    }

    map<int, vector<int>> m;
    rep(i, N) {
        int p = uf.find(i);
        m[p].push_back(i);
    }

    int ans = 0;
    for (auto &i : m) {
        vector<int> &v = i.second;
        map<int, int> cnt;
        for (int j : v) {
            cnt[j]++;
            cnt[p[j]]++;
            if (cnt[j] == 2) ans++;
            if (j != p[j] && cnt[p[j]] == 2) ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 13184
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int j=0; j < N; ++j) {
    cin >> a[j];
  }
  int before = a[0], cnt = 0;
  for (int j=1; j < N; ++j) {
    if (a[j] == before) {
      cnt += 1;
      before = 0;
    } else {
      before = a[j];
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

namespace {  // 名前なし名前空間
	// gcd, lcm は C++17 でstdに標準入りしたので言語のバージョンに注意
	// 最大公約数
	ll gcd(ll a, ll b) {
		if (b == 0) return a;
		return gcd(b, a % b);
	}

	// 最小公倍数
	ll lcm(ll a, ll b) {
		return a / gcd(a, b) * b;
	}
}

int main() {

	string s;
	cin >> s;
	string t;
	cin >> t;

	int sn = (int)s.size();
	int tn = (int)t.size();

	// tのすべての文字がsに含まれていないなら-1 それ以外は答えある
	vector<int> cnum(26, 0);
	rep(i, sn) {
		cnum[s[i] - 'a']++;
	}

	rep(i, tn) {
		if (cnum[t[i] - 'a'] == 0) {
			cout << -1 << endl;
			return 0;
		}
	}

	// 左から貪欲に見ていく
	int left = 0;
	// それぞれの文字がどこにあるのか記録しておく
	vector<vector<int>> c(26, vector<int>());
	rep(i, sn) {
		c[s[i] - 'a'].push_back(i + 1);
	}

	ll ans = 0;
	ll pos = 0;
	while (left != tn) {
		int size = (int)c[t[left] - 'a'].size();
		// 2分探索
		if (size != 0) {
			ll ma = c[t[left] - 'a'][size - 1];
			//cout << pos << " " << ma << endl;
			if (pos >= ma) {
				ans += (ll)sn - pos; // ここ怪しい // posを先頭に戻してる
				pos = c[t[left] - 'a'][0]; // 最初の文字のところへ
				ans += pos;
				left++;
				// << "a" << " " <<  ans << endl;
				continue;
			}
		}
		ll next = *upper_bound(allof(c[t[left] - 'a']), pos);
		ans += next - pos;
		pos = next;
		left++;
		// << "b " <<  ans << endl;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  map<char, int> mp;
  rep(i, h){
    string s;
    cin >> s;
    rep(j, w){
      mp[s.at(j)]++;
    }
  }

  int p4 = 0, p2 = 0, p1 = 0;
  for(auto p : mp){
    p4 += p.second/4;
    p.second %= 4;
    p2 += p.second/2;
    p.second %= 2;
    p1 += p.second;
  }

  bool e = false;
  if(h % 2 == 1 && w % 2 == 1){
    if(p1 != 1) e = true;
  }else{
    if(p1 != 0) e = true;
  }
  int h2 = h/2, w2 = w/2;
  if(p4 < h2*w2) e = true;
  if(e == false) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    int q;
    cin >> q;
    vector<int> b(q), c(q);
    for(int i = 0; i < q; i++) cin >> b[i] >> c[i];
    vector<long long int> backet(100010, 0);
    for(int i = 0; i < n; i++) backet[a[i]]++;

    long long int sum = 0;
    for(long long int i = 0; i <= 100000; i++){
        long long int cosum = backet[i];
        cosum *= i;
        sum += cosum;
    }

    for(int i = 0; i < q; i++){
        long long int cosum = b[i];
        cosum *= backet[b[i]];
        sum -= cosum;

        cosum = c[i];
        cosum *= backet[b[i]];
        sum += cosum;

        backet[c[i]] += backet[b[i]];
        backet[b[i]] = 0;
        
        cout << sum << endl;
    }
    
    return 0;  
}

Measured memory_bytes: 5364
#include <stdio.h>
#define mod 1000000007

int fib(int n, int *a){
    if(n == 1){
        a[n] = 1;
        return a[n];
    }else if(n == 2){
        int f_n1;
        if(a[n-1] < 0){f_n1 = fib(n-1, a);}
        else{f_n1 = a[n-1];}
        a[n] = 1 + f_n1;
        return a[n];
    }else{
        int f_n1, f_n2;
        if(a[n-1] < 0){f_n1 = fib(n-1, a);}
        else{f_n1 = a[n-1];}
        if(a[n-2] < 0){f_n2 = fib(n-2, a);}
        else{f_n2 = a[n-2];}
        a[n] = (f_n1 + f_n2) % mod;
        return a[n];
    }
}



int main(void){
    int n, m, tmp, i, ans;
    scanf("%d %d", &n, &m);
    int a[n];
    for(i = 0; i < n; ++i){
        a[i] = -1;
    }
    for(i = 0; i < m; ++i){
        scanf("%d", &tmp);
        a[tmp] = 0;
    }
    ans = fib(n, a);
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 5248
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <map>
#define INF 100000000
#define MAX_C 100
using namespace std;
map<int, int> mp;
int main()
{
	int d, n;
	cin >> d >> n;
	int s = 1;
	for (int i = 0; i < d; i++) s *= 100;
	if (n <= 99) cout << s * n << endl;
	else cout << s * 101 << endl;
	return 0;
}

Measured memory_bytes: 256
import math

n=int(input())
t,a=map(int,input().split())
vt=t
va=a
for i in range(1,n):
    t, a = map(int, input().split())
    if vt<=t and va<=a:
        vt=t
        va=a
    elif vt>t and va<=a:
        x=-(-vt//t)
        vt,va=x*t,x*a
    elif vt<=t and va>a:
        x=-(-va//a)
        vt,va=x*t,x*a
    else:
        x1 = -(-vt // t)
        x2 = -(-va // a)
        if x1*t+x1*a >=x2*t+x2*a:
            vt, va = x1 * t, x1 * a
        else:
            vt, va = x2 * t, x2 * a

print(va+vt)

Measured memory_bytes: 73396
a, b, c, d = [int(c) for c in input()]

done = False
ops = ['+', '-']
for op1 in ops:
    for op2 in ops:
        for op3 in ops:
            left = a
            left += b if op1 == '+' else -b
            left += c if op2 == '+' else -c
            left += d if op3 == '+' else -d
            if left == 7:
                done = True
                break
        if done:
            break
    if done:
        break
print('{a}{op1}{b}{op2}{c}{op3}{d}=7'.format(a=a, b=b, c=c, d=d, op1=op1, op2=op2, op3=op3))


Measured memory_bytes: 9100
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)


Measured memory_bytes: 107992
import sys

# sys.stdin = open('c1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def F(a, b):
    return max(len(str(a)), len(str(b)))


n = read_int()
res = 10 ** 20
for a in range(1, n + 1):
    if a * a > n:
        break
    if n % a == 0:
        b = n // a
        f = F(a, b)
        if f < res:
            res = f
print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main() {
    int N;
    int t;
    cin >> N;
    vector <int> m;
    int max1 = -1;
    for(int i = 0; i < N; i++){
        cin >> t;
        m.push_back(t);
    }
    int total = 1;
    max1 = m[0];
    for(int i = 1; i < N; i++){
        if(m[i] >= max1)
            total++;
        if(m[i] > max1)
            max1 = m[i];
    }
    cout << total;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int k = sc.nextInt();

    Integer sum = 0;
    if (a >= k) {
      sum = k;
    } else {
      sum = a;
      k = k - a - b;
      sum -= Math.min(c, k);
    }

    // 出力
    System.out.println(sum);
  }
}


Measured memory_bytes: 35792
function Main(input) {
  input=input.split("\n");
  var S=input[0].trim();
  var previous=S[0];
  var counter=0;
  for(var i=1;i<S.length;i++){
    if(previous!==S[i]){
      counter++;
    }
    previous=S[i];
  }
  console.log(counter);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 32468
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    vector<int> x(5);
    rep(i, 0, 5) cin >> x[i];
    rep(i, 0, 5) {
        if (x[i] == 0) cout << i + 1 << endl;
    }
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 1e5 + 5;

int ar[MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    scanf("%d", &n);
    vi vec[2];
    for (int i = 0; i < n; i++) {
        scanf("%d", &ar[i]);
        vec[i & 1].pb(ar[i]);
    }
    sort(all(vec[0]));
    sort(all(vec[1]));
    sort(ar, ar + n);
    int ans = 0;
    for (int i = 0; i < n; i += 2) {
        if (!binary_search(all(vec[0]), ar[i]))
            ans++;
    }
    printf("%d\n", ans);
    return 0;
}



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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> vec(N);
  for(int i=0;i<N;i++){
    int a;
    cin >> a;
    for (int j = 0; a>0 ; j++){
      if(a%2==1)vec[i].push_back(j);
      a = a/2;
    }
  }
  long sum=0;
  int right = 0;
  set<int> s;
  for (int left = 0; left < N; ++left) {
    while (right < N) {
      bool al=true;
      set<int> t=s;
      for(int i=0;i<vec[right].size();i++){
        auto r=t.insert(vec[right][i]);
        if(!r.second)al=false;
      }
      if(al){
        s=t;
        /* 実際に right を 1 進める */
        // ex: sum += a[right];
        ++right;
      }
      else break;
    }
    sum+=right-left;
    if(right==left) right++;
    else{
      for(int i=0;i<vec[left].size();i++){
        s.erase(vec[left][i]);
      }
    }
  }
  cout << sum;

    /* break した状態で right は条件を満たす最大なので、何かする */
    // ex: res += (right - left);

    /* left をインクリメントする準備 */
    // ex: if (right == left) ++right;
    // ex: else sum -= a[left];
}
//500てんもんだいのすごくながいこーどかけてえらい

Measured memory_bytes: 18944
#include<stdio.h>

int main(){
  int i, l, m, n, sum, trip;

  while(1){
    scanf("%d", &l);
    if(l == 0) break;

    sum = 0;
    trip = 0;
    for(i=0; i<12; i++){
      scanf("%d %d", &m, &n);

      if(trip == 0){
	sum = sum + (m - n);
	if(sum >= l) trip = i+1;
      }
    }

    if(trip == 0)
      printf("NA\n");
    else
      printf("%d\n", trip);
  }

  return 0;
}

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


#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

void solve() {
  int n, q; scanf("%d%d", &n, &q);
  fenwick_tree<long long> fw(n);
  for (int a, i = 0; i < n; ++i) {
    scanf("%d", &a);
    fw.add(i, a);
  }
  while (q--) {
    int t, u, v; scanf("%d%d%d", &t, &u, &v);
    if (t) {
      printf("%lld\n", fw.sum(u, v));
    } else {
      fw.add(u, v);
    }
  }
}

int main() {
  init();
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 8232
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
using pair = Pair<long, long>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;


    void solve()
    {
        int N = cin.nextint;
        var A = cin.scanlong;
        var B = cin.scanlong;

        var C = A.Sum();
        var D = B.Sum();

        if (C > D)
        {
            WriteLine("No");
        }
        else
        {
            var P = new pair[N];
            for (int i = 0; i < N; i++)
            {
                P[i] = new pair(A[i], B[i]);
            }
            P = P.OrderBy(k => k.f - k.s).ToArray();
            //long min = 0;
            long max = 0;
            for (int i = 0; i < N; i++)
            {
                if (P[i].f <= P[i].s)
                {
                    max += (P[i].s - P[i].f) / 2;
                }
                else
                {
                    max -= (P[i].f - P[i].s);
                }
            }
            if (max >= 0)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }
    }

}

class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f;
    public U s;
    public Pair(T f, U s)
    {
        this.f = f;
        this.s = s;
    }
    public int CompareTo(Pair<T, U> a)
    {
        return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    }
    public override string ToString()
    {
        return f + " " + s;
    }
}
class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

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

int main(void) {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  vector<pair<int,int>> v;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    v.emplace_back(A[i] + B[i], i);
  }
  sort(v.begin(), v.end());
  reverse(v.begin(), v.end());

  long long a = 0, b = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) a += A[v[i].second];
    else b += B[v[i].second];
  }

  cout << a - b << endl;
  return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int h[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }
    int dp[n+1];
    dp[0] = 0;
    dp[1] = 0;
    dp[2] = abs(h[2]-h[1]);
    for(int i=3;i<=n;i++)
    {
        dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    }
    cout << dp[n] << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <string>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define eb emplace_back
#define in insert
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define FOR(i, n, x) for(int i = x; i < n; i++)
#define OUT(a, e) FOR(i, e, 0) cout << a[i] << ' '
#define OUTV(a) for(auto e : a) cout << e << ' '; cout << endl;
#define OUTP(a) cout << a.f << ' ' << a.s << endl;
#define maxim(a, n, mx) FOR(i, n, x)mx = max(mx, a[i]);
#define get_lind(vec, val) (int)(lower_bound(all(vec), val) - vec.begin())
#define get_rind(vec, val) (int)(upper_bound(all(vec), val) - vec.begin())


using  namespace std;
const int N = 2e5 + 5;

int main()
{
    string s; cin >> s;
    if(s[2] == s[3] && s[4] == s[5])cout << "Yes" << endl;
    else cout << "No";
    return 0;
}


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

int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  double heikin=0;
  rep(i,n){
    cin>>a[i];
    heikin+=a[i];
  }
  heikin/=n;
  double div=10000000;
  int ans=0;
  rep(i,n){
    if(abs(heikin-a[i])<div){
      div=abs(heikin-a[i]);
      ans=i;
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3616
// 一般的なグラフの形で書いてみる
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  // Nは頂点の数
  ll N, K;
  cin >> N >> K;
  // 頂点、 町、　道筋
  vector<int> v(N, -1), a(N), path;
  for (auto &i : a) cin >> i, --i;
  int p = 0;
  while (v[p] == -1) {
    v[p] = path.size();
    if (v[p] == K) return cout << p + 1 << endl, 0;
    path.emplace_back(p);
    p = a[p];
  }

  int u = path.size();
  (K -= v[p]) %= u - v[p];
  cout << path[v[p] + K] + 1 << endl;
  return 0;
}

Measured memory_bytes: 5780
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC163_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string H = Console.ReadLine();
            int R = int.Parse(H);
            
            double result = (R) * 2 * Math.PI;

            Console.WriteLine(result);
        }
    }
}


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

int main(){
int n,m;
cin>>n>>m;
vector<int> v,v1;
vector<int>::iterator it;
int sum=0;
for(int i=0;i<m;i++){
    int x;
    cin>>x;
    v.push_back(x);
}
if(m==1){
    cout<<0;
}
else{
sort(v.begin(),v.end());

for(auto i=v.begin();i!=v.end()-1;i++){
       int y=*(i+1)-*i;
    v1.push_back(y);
}
sort(v1.begin(),v1.end());

for(auto i=v1.begin();i<=(v1.begin()+(m-n-1));i++)
{sum=sum+*i;}

cout<<sum;
}}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll inf=1e9+7;
const ll mod=998244353;
const int MAX=1000010;

signed main(){
    ll n;cin>>n;
    ll ans=0;
    vector<ll>l(n);
    rep(i,n)cin>>l[i];
    rep(i,n){
        REP(j,i+1,n){
            REP(k,j+1,n){
                vector<ll>a(3);
                a[0]=l[i];
                a[1]=l[j];
                a[2]=l[k];
                sort(all(a));
                if(a[0]==a[1]||a[1]==a[2])continue;
                if(a[0]+a[1]>a[2])ans++;
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			String string = scanner.nextLine();
			if (string.equals("0")) {
				break;
			}
			int sum = 0;
			for(int i=0;i<string.length();i++) {
				sum += string.charAt(i)-48;
			}
			System.out.println(sum);
		}
		scanner.close();
	}
}


Measured memory_bytes: 26768
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
int a,b,h,m;
double x,y,ang;
int main()
{
	scanf("%d%d%d%d",&a,&b,&h,&m);
	x=(h+m/60.0)*pi/6;
	y=m*pi/30;
	ang=min(fabs(x-y),2*pi-fabs(x-y));
	printf("%.20lf\n",sqrt(a*a+b*b-2*a*b*cos(ang)));
	return 0;
}


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

#define int long long
#define DEBUG(x) cerr <<#x<<":"<<x<<endl;
#define DEBUG2(x, y) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<endl;
#define DEBUG3(x, y, z) cerr <<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl;
#define DEBUGVC(x) cerr <<#x<<": "; for(auto a:x) cerr << a <<" "; cerr << endl;
#define DEBUGMP(x) cerr <<#x<<":"<<endl; for(auto a:x) cerr << a.first <<" "<< a.second << endl;
#define MAX_N (1000006)
#define INF (1LL << 60)
const int MOD = (int)1e9+7;


signed main() {
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        int ans = 0;
        for(int i=2; i<=n; i++){
            //DEBUG(i);
            for(int j=1; j<=n-i+1; j++){
                int sum = 0;
                for(int k=j; k<j+i; k++){
                    //DEBUG(k);
                    sum += k;
                }
                if(sum == n) ans++;
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using PP = pair<int,pair<int,int>>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};
int sy,sx,gy,gx;

int main(){
  int n; cin >> n;
  int ans = 0;
  for(int i = 0; i < n; i++){
    int l,r; cin >> l >> r;
    ans += r - l + 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, k, a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> k;
    FOR(i,1,n) cin >> a[i];
    sort(a+1, a+n+1);
    ll res = 0;
    FORE(i,n,1) {
        if (k) {
            k--;
        }
        else res += a[i];
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
N = int(input())
P = list(map(float, input().split()))

dp = [[0] * (N + 1) for _ in range(N + 1)]
dp[0][0] = 1

for i in range(N):
    p = P[i]
    q = 1 - p
    dp[i + 1][0] = dp[i][0] * q
    for j in range(1, i + 2):
        dp[i + 1][j] = dp[i][j - 1] * p + dp[i][j] * q

print (sum(dp[N][(N + 1) // 2:]))

Measured memory_bytes: 263432
#include <stdio.h>

char field[15][15];

int main(void)
{
	int i, j, x, y;
	int flag = 0;
	
	while (1){
		
		for (i = 0; i < 8; i++){
			if (scanf("%s", field[i]) == EOF){
				 flag = 1;
				 break;
			}
		}
		
		if (flag == 1) break;
		x = y = 10;
		
		for (i = 0; i < 8;i++){
			for (j = 0; j < 8; j++){
				if (field[i][j] == '1') {
					x = j;
					y = i;
					break;
				}
			}
			if (y == i) break;
		}
		
		if (field[y][x + 1] == '1' && field[y + 1][x] == '1' && field[y + 1][x + 1] == '1'){
			printf("A\n");
		}
		else if (field[y + 1][x] == '1' && field[y + 2][x] == '1' && field[y + 3][x] == '1'){
			printf("B\n");
		}
		else if (field[y][x + 1] == '1' && field[y][x + 2] == '1' && field[y][x + 3] == '1'){
			printf("C\n");
		}
		else if (field[y][x + 1] == '1' && field[y + 1][x + 1] == '1' && field[y + 1][x + 2] == '1'){
			printf("E\n");
		}
		else if (field[y + 1][x] == '1' && field[y + 1][x + 1] == '1' && field[y + 2][x + 1] == '1'){
			printf("F\n");
		}
		else if (field[y + 1][x - 1] == '1' && field[y + 1][x] == '1' && field[y][x + 1] == '1'){
			printf("G\n");
		}
		else if (field[y + 1][x] == '1' && field[y + 1][x - 1] == '1' && field[y + 2][x - 1] == '1'){
			printf("D\n");
		}
	}
	
	return (0);

}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  for(int i=0;i<n;i++)
    cin>>a.at(i);
  sort(a.begin(),a.end(),greater<int>());
  int p=0;
  for(int i=0;i<n;i++)
    p+=a.at(i)*(i%2==0?1:-1);
  cout<<p<<endl;
}

Measured memory_bytes: 3576