akhauriyash/Code-Regression huggingface dataset:
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 200005
int arr[MAX];
int dp[MAX][2];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n; cin>>n;
    string s; cin>>s;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='1') cnt++;
    }
    if(n==1 && cnt==1)  { cout<<0<<endl; return 0 ;} 
    arr[0]=0;
    for(int i=1;i<MAX;i++){
        bitset<33> bs(i);
        ll  md=bs.count();
        ll val=i%md;
        arr[i]=1+arr[val];
    }
    if(cnt-1!=0)
    {
        int x=cnt-1;
        dp[0][0]=1;
        for(int i=1;i<MAX;i++){
            dp[i][0]=(dp[i-1][0]*2)%x;
        }
    }
    int x=cnt+1;
    dp[0][1]=1;
    for(int i=1;i<MAX;i++){
        dp[i][1]=(dp[i-1][1]*2)%x;
    }
    ll ans1=0;
    ll ans2=0;
    for(int i=s.size()-1;i>=0;i--)
    {
        if(s[i]=='1') {
           if(cnt-1!=0) ans1=(ans1+dp[s.size()-1-i][0]) % (cnt-1) ; 
           ans2=(ans2+dp[s.size()-1-i][1])%(cnt+1);
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[i]=='1')
        {
            int x=cnt-1;
            if(x==0) cout<<0<<endl;
            else{
                int pw=s.size()-1-i;
                ll val=dp[pw][0];
                ll fck=ans1;
                ans1-=val;
                ans1%=x;
                ans1+=x; ans1%=x;
                cout<<1+arr[ans1]<<endl;
                ans1=fck;
            }
        }
        else{
            int x=cnt+1;
            int pw=s.size()-1-i;
                ll val=dp[pw][1];
                ll fck=ans2;
                ans2+=val;
                ans2%=x;
                ans2+=x; ans2%=x;
                cout<<1+arr[ans2]<<endl;
                ans2=fck;
        }
    }
    
    
}

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

#define INF (1<<21)
#define MAX 1000

int dp[MAX];
int main(){
	int p[4],t[4];

	int n;	cin>>n;
	for(int i=0;i<4;i++) cin>>p[i];
	for(int i=0;i<4;i++) cin>>t[i];

	dp[0]=0;
	for(int i=1;i<MAX;i++) dp[i]=INF;

	for(int i=0;i<=100;i++){
		for(int j=0;j<4;j++){
			dp[i+t[j]] = min(dp[i+t[j]] , dp[i] + p[j]);
		}

	}

	int ans=INF;
	for(int i=n;i<MAX;i++) ans=min(ans, dp[i]);

	cout<<ans<<endl;



	return 0;
}



Measured memory_bytes: 3108
n = input()
len_n = len(n)
dp = [[0,2] for i in range(len_n+1)]
for k,v in enumerate(n[::-1]):
    v = int(v)
    dp[k+1][0] = min(dp[k][0] + v, dp[k][1] + v)
    dp[k+1][1] = min(dp[k][0] + 10 - v + 1, dp[k][1] + 10 - v - 1)
print(min(dp[len_n]))


Measured memory_bytes: 171096
#include<stdio.h>
int main()
{
  int h,n,sum=0,a,i;
  scanf("%d %d",&h,&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&a);
    sum+=a;
  }
  if(sum>=h)
    printf("Yes");
  else
    printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void) {
	int n, v[51], temp, sort;
	int i, j;
	float ans;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &v[i]);
	}
	for (i = 0; i < n; i++) {
		for (j = n - 1; j >= i + 1; j--) {
			if (v[j] < v[j - 1]) {
				temp = v[j];
				v[j] = v[j - 1];
				v[j - 1] = temp;
			}
		}
	}
	ans = (float)v[0];
	for (j = 1; j < n; j++) {
		ans = (ans + v[j]) / 2;
	}
	printf("%f\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
main()
{
	char s[10000];
	long long n,i,j,k,r=0,g=0,b=0,ans;
	scanf("%d%s",&n,s);
	for(i=0;i<n;i++)
	{
		if(s[i]=='R') r++;
		if(s[i]=='G') g++;
		if(s[i]=='B') b++;
	}
	ans=r*g*b;
	for(i=0;i<n;i++)
	{
		for(j=i+1;j<n;j++)
		{
		    k=2*j-i;
	        if(k<n&&s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) ans--;
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define COUT(x) cout<<(x)<<endl
#define dump(x)  cout << #x << " = " << (x) << endl;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
using M = map<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int, vector<int>, greater<int>>;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  char a,b; cin >> a >> b;
  int x = a-'A', y = b-'A';
  COUT(x == y ? '=' : (x > y ? '>' : '<'));
  return 0;
}


Measured memory_bytes: 256
import numpy as np

a1 = input()
a2 = input()

list1 = np.array(list(map(int,a1.split(" "))))

list2 = (np.array(list(map(int,a2.split(" "))))*10+10)/2

res = 0
now = 0

k = list1[1]
n = list1[0]
i = 0
while i < n:
    now = now + list2[i]
    if i>k-1:
        now = now - list2[i-k]
        res = max(res,now)
    res = max(res,now)
    i = i + 1
print(res/10)


Measured memory_bytes: 34884
def makearray()
  $n = gets.to_i
  $a = []
  $b = []
  for k in 0..$n-1
    $b[k] = []
    for l in 0..$n+1
      $b[k][l] = 0
    end
  end
  for i in 0..$n-1
    $a[i] = gets.split(' ').map(&:to_i)
    if $a[i][1] > 0
      for j in 2..$a[i][1]+1
        c = $a[i][j] - 1
        $b[i][c] = 1
      end
    end
  end
end

makearray()
Q = [0]
D = Array.new($n, -1)
D[0] = 0
$b[0][$n] = 1
while Q.size > 0
  c = Q.shift
  for i in 0..$n-1
    if $b[c][i] == 1 && $b[i][$n] == 0
      D[i] = D[c] + 1
      $b[i][$n] = 1
      Q << i
    end
  end
end
for i in 0..$n-1
  print i+1
  print ' '
  puts D[i]
end

Measured memory_bytes: 6976
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define inf 1000000000000000000

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(10);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,m;
    cin>>n>>m;
    vi a(n);
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        a[i+1]+=a[i];
    }
    map<int,int> map;
    map[0]++;
    rep(i,n){
        map[a[i]%m]++;
    }
    int ans=0;
    for(auto i:map){
        int a=i.se;
        ans+=a*(a-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int arr[100005],n,dp[100005];

int recur(int i){
    if(i >= n)return 99999;
    if(i == n-1)return 0;
    if(dp[i] != -1)return dp[i];

    int opt1 = abs(arr[i] - arr[i+1]) +  recur(i+1);
    int opt2 = abs(arr[i] - arr[i+2]) +  recur(i+2);
    return dp[i] = min(opt1,opt2);
}

int main() {
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        dp[i]=-1;
    }
    int ans = recur(0);
    cout<<ans<<"\n";
    return 0;
}


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

#include <boost/range/adaptors.hpp>
#include <boost/range/combine.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t k, a, b;
    cin >> k >> a >> b;

    for (auto i : irange(a, b + 1)) {
        if (i % k == 0) {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}

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

long long j,p[16],n;
vector<long long> v;

void rec(int pos, int s, long long now){
	if (p[j]*s<now){
		return;
	}
	if (pos>15){
		if (p[j]*s>=now){
			v.push_back(now);
		}
		return;
	}
	for (int i=0;i<=9;i++){
		rec(pos+1,s+i,now+p[pos-1]*i);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	p[0]=1;
	for (int i=1;i<=15;i++){
		p[i]=p[i-1]*10;
	}
	for (j=0;j<=15;j++){
		rec(j+1,9*j,p[j]-1);
	}
	sort (v.begin(),v.end());
	v.erase(unique(v.begin(),v.end()),v.end());
	cin >> n;
	for (int i=1;i<=n;i++){
		cout << v[i] << "\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}

int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<char>());
	cout << (s < t ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2000000000)
input=lambda : sys.stdin.readline().rstrip('\n')

n=int(input())
data=[]
s=[0]
for i in range(n):
    data.append(tuple(map(int,input().split())))
data=[(0,0)]+sorted(data)
for i in range(n):
    s.append(s[-1]+data[i+1][1])
mx=0
ans=0
mn=10**18
for i in range(1,n+1):
    if mn>s[i-1]-data[i][0]:
        mn=s[i-1]-data[i][0]
    if ans<s[i]-data[i][0]-mn:
        ans=s[i]-data[i][0]-mn
print(ans)


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

int main(){//main_program
  int max;
  string S;
  cin >> S;
  max = S.size();
  vector<int> A(max);
  vector<int> B(max);
  
  for(int i = 0; i<max ; i++){
    if(S.at(i) == '?'){
      A.at(i) = 1;
    }else{
      if(S.at(i) == 'P'){
        A.at(i) = 2;
      }else{
        A.at(i) = 3;
      }
    }
  }
  
  for(int i = 0; i<max ; i++){
    if(A.at(i) == 1){
      B.at(i) = 3;
    }else{
      B.at(i) = A.at(i);
    }
  }
  
  for(int i = 0; i<max ; i++){
    if(B.at(i) == 2){
      cout << 'P';
    }else{
      cout << 'D';
    }
  }
  cout << endl;
}

Measured memory_bytes: 5248
//package abc124.B;

import java.util.Scanner;

public class Main {

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

}


Measured memory_bytes: 22996
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    static int[][] getMagicSquare(int n) {
        int[][] result = new int[n][n];
        int x = n / 2;
        int y = n / 2 + 1;
        result[y][x] = 1;

        for (int i = 1; i < n * n; i++) {
            x++;
            y++;
            // x,yを決める
            while (true) {
                if (x == -1)
                    x = n - 1; // 左
                if (x == n)
                    x = 0; // 右
                if (y == n)
                    y = 0; // 下 

                if (result[y][x] == 0) {
                    break;
                } else {
                    x--;
                    y++;
                }
            }

            result[y][x] = i + 1;
        }

        return result;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;

        while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);

            int[][] answer = getMagicSquare(n);

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < n; j++) {
                    System.out.print(String.format("%4d", answer[i][j]));
                }
                System.out.println();
            }
        }

    }
}


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


int main(void) {

  string s;
  string a = "abcdefghijklmnopqrstuvwxyz";
  vector<int> alp(26, 0);
  while(cin >> s){
    for(int i=0; i<s.size(); i++){
      if( s[i]-'A' >= 0 && s[i]-'A' < 26 ) alp[ s[i]-'A' ]++;
      if( s[i]-'a' >= 0 && s[i]-'a' < 26 ) alp[ s[i]-'a' ]++;
    }

  }

  for(int i=0; i<26; i++){
    cout << a[i] << " : " << alp[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3216
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#

"""
gc032 A
"""

from collections import Counter

n = int(input())
bli = list(map(int, input().split()))
cli = bli.copy()
cli.reverse()
dli = []

for i in range(1, n+1):
    if 1 in cli:
        x = cli.index(1)
        for j in range(0, x+1):
            cli[j] -= 1
    else:
        print(-1)
        quit()
    dli.append(bli[n-1-x])

for i in dli:
    print(i)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define sz(x) ((int)x.size())
#define pb push_back
#define ii pair<int,int>
#define ppb pop_back
#define orta ((bas+son)>>1)
#define st first
#define nd second
#define ll long long
#define N 200005
#define inf 1000000005
#define MOD 1000000007
#define LOG 20
#define EPS 0.000000001
#define M 305
using namespace std;

ll f(ll n) {

	if(!n) return 0;
	return 2*f(n/2)+1;

}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	ll n;
	cin>>n;	
	cout<<f(n);

}

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

int main(void) {
  int r;
  cin >> r;

  cout << (r*r) << endl;
 
  return 0;
}

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

int main () {
  int N;
  cin >> N;
  for (int i = 0; i < 3; i++) {
    if (N % 10 == 7) {
      cout << "Yes" << endl;
      break;
    }
    else if (i == 2) 
      cout << "No" << endl;
    
    N /= 10;
  }
}

Measured memory_bytes: 3632
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1235
// ICPC: アジア地区予選2002D
// Life Line

#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

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

int s_dir[2][6] = {{-1, 0, 1, 1, 0, -1}, {0, 1, 1, 0, -1, -1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

#define INF 100

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n, c;
  while(cin >> n >> c, n){
    vvi s(n, vi(n, -1));
    for(int i = 0; i < n; i++){
      for(int j = 0; j <= i; j++){
        cin >> s[i][j];
      }
    }
    int ans = -INF;
    for(int i = 0; i < n; i++){
      for(int j = 0; j <= i; j++){
        auto f = [=]() mutable -> int {
          int ret = 0;
          s[i][j] = c;
          vvi used(n, vi(n, 0));
          for(int k = 0; k < n; k++){
            for(int l = 0; l <= k; l++){
              if(used[k][l]) continue;
              int mode = s[k][l];
              bool removed = true;
              queue<pii> q, ud;
              ud.push({k, l});
              while(!ud.empty()){
                pii a = ud.front(); ud.pop();
                if(used[a.first][a.second]) continue;
                used[a.first][a.second] = 1;
                q.push({a.first, a.second});
                for(int m = 0; m < 6; m++){
                  int ny = a.first+s_dir[0][m], nx = a.second+s_dir[1][m];
                  if(is_in_field(ny, nx, n, n) && s[ny][nx] != -1){
                    if(s[ny][nx] == 0) removed = false;
                    if(s[ny][nx] == s[k][l] && !used[ny][nx]) ud.push({ny, nx});
                  }
                }
              }
              if(removed){
                if(s[k][l] == c) mode = -INF;
                else if(s[k][l] != 0) mode = INF;
              }
              while(!q.empty()){
                pii a = q.front(); q.pop();
                if(mode == INF) ret++;
                else if(mode == -INF) ret--;
                s[a.first][a.second] = mode;
              }
            }
          }
          // for(int k = 0; k < n; k++){
          //   for(int l = 0; l <= k; l++){
          //     cout << s[k][l] << ' ';
          //   }
          //   cout << endl;
          // }
          // cout << i << ' ' << j << ' ' << ret << endl;
          return ret;
        };
        if(s[i][j] == 0){
          ans = max(ans, f());
        }
      }
    }
    cout << ans << endl;
  }

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}



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

int main(){
    int x, y;
    cin >> x >> y;

    if(x == 4 || x == 6 || x == 9 || x == 11) x = 100;
    else if(x == 2) x = 101;
    else x = 102;

    if(y == 4 || y == 6 || y == 9 || y == 11) y = 100;
    else if(y == 2) y = 101;
    else y = 102;

    if(x == y) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <list>
#include <array>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <random>
#include <chrono>

#define PI 3.14159265359
#define mt make_tuple
#define mp make_pair
#define pii pair <int, int>
#define pll pair <long long, long long>
#define all(x) (x).begin(), (x).end()

//mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

const int MAX = 100005;

int main()
{
	///ce meet in the middle genial
	int N;
	cin >> N;
	vector <int> v(N + 5, 0);
	vector <int> w(N + 5, 0);
	for (int i = 1; i <= N; ++i)
		cin >> v[i] >> w[i];
	int limit = min(512, N);
	vector < vector <int> > dp(limit + 5, vector <int>(MAX, 0));
	for (int i = 0; i < MAX; ++i)
		if (w[1] <= i)
			dp[1][i] = v[1];
	for (int i = 2; i <= limit; ++i)
	{
		int p = i / 2;
		for (int j = 0; j < MAX; ++j)
		{
			dp[i][j] = dp[p][j];
			if (w[i] <= j)
				dp[i][j] = max(dp[i][j], dp[p][j - w[i]] + v[i]);
		}
	}	
	int Q;
	cin >> Q;
	while (Q-- > 0)
	{
		int node, L;
		cin >> node >> L;
		vector <int> a;
		while (node > limit)
		{
			a.push_back(node);
			node /= 2;
		}
		int M = a.size();
		int answer = 0;
		for (int state = 0; state < (1 << M); ++state)
		{
			int sumv = 0, sumw = 0;
			for (int i = 0; i < M; ++i)
			{
				if ((1 << i) & state)
				{
					sumv += v[a[i]];
					sumw += w[a[i]];
				}
			}
			if (sumw <= L)
				answer = max(answer, dp[node][L - sumw] + sumv);
		}
		cout << answer << "\n";
	}
	return 0;
}



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

using namespace std;

#define ll long long
ll input(){
	ll x=0,f=0;char ch=getchar();
	while(ch<'0'||ch>'9') f|=ch=='-',ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return f? -x:x;
}

const int N=2e5+7;

ll t[N<<2],lazy[N<<2];

void putdown(int rt){
	if(lazy[rt]){
		t[rt<<1]+=lazy[rt];
		t[rt<<1|1]+=lazy[rt];
		lazy[rt<<1]+=lazy[rt];
		lazy[rt<<1|1]+=lazy[rt];
		lazy[rt]=0;
	}
}

void put(int rt){
	t[rt]=max(t[rt<<1],t[rt<<1|1]);
}

ll query(int rt,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr) return t[rt];
	putdown(rt);
	int mid=(l+r)>>1;
	if(qr<=mid) return query(rt<<1,l,mid,ql,qr);
	if(mid<ql) return query(rt<<1|1,mid+1,r,ql,qr);
	return max(query(rt<<1,l,mid,ql,qr),query(rt<<1|1,mid+1,r,ql,qr));
}

void update(int rt,int l,int r,int ul,int ur,ll x){
	if(ul<=l&&r<=ur){t[rt]+=x,lazy[rt]+=x;return;}
	putdown(rt);
	int mid=(l+r)>>1;
	if(ul<=mid) update(rt<<1,l,mid,ul,ur,x);
	if(ur>mid) update(rt<<1|1,mid+1,r,ul,ur,x);
	put(rt);
}

struct opr{
	int l,r,c;
}a[N];
bool cmp(opr a,opr b){
	return a.r<b.r;
}

int main(){
	int n=input(),m=input();
	for(int i=1;i<=m;i++){
		a[i].l=input(),a[i].r=input(),a[i].c=input();
	}

	sort(a+1,a+1+m,cmp);

	ll p=0;

	for(int i=1;i<=n;i++){
		update(1,0,n,i,i,query(1,0,n,0,i-1));
		while(p<m&&a[p+1].r==i) p++,update(1,0,n,a[p].l,a[p].r,a[p].c);
	}
	printf("%lld\n",query(1,0,n,0,n));
}

Measured memory_bytes: 14592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin>>H>>W;
  vector<vector<char>> BorW(H,vector<char>(W));
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
    cin>>BorW.at(i).at(j);
    }
  }
  vector<int> A(H),B(W);
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(BorW.at(i).at(j)=='#'){
        A.at(i)=1;
        break;
      }
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      if(BorW.at(i).at(j)=='#'){
        B.at(j)=1;
        break;
      }
    }
  }
  for(int i=0;i<H;i++){
    if(A.at(i)==0)
      continue;
    for(int j=0;j<W;j++){
      if(B.at(j)==1)
        cout<<BorW.at(i).at(j);
    }
    cout<<endl;
  }
}

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

//1,2,3,4,5,6,7,8,9
//2,5,5,4,5,6,3,7,6
//2,3,4,5,6,7
//1,7,4,5,9,8
using P=pair<int,int>;

map<int,int>mx;
vector<int>num={0,2,5,5,4,5,6,3,7,6};
const int vnum=10020;
int dp[vnum];
int dig[vnum];

signed main(){
	int n,m;cin>>n>>m;
	vector<int>a(m);

	for(auto&& w:a){
	cin>>w;
	mx[num[w]]=max(mx[num[w]],w);
	}
	vector<P>vmx=vector<P>(mx.begin(),mx.end());
sort(vmx.begin(),vmx.end(),[&](P x,P y){return x.second<y.second;});

    fill(dp,dp+vnum,-1);
	fill(dig,dig+vnum,-1);
	dp[0]=0;
	
	for(auto&& w:vmx){
		for(int i=0;i<=n;i++){
			if(dp[i]==-1)continue;
			if(dp[i+w.first]<=dp[i]+1){	
		    	dp[i+w.first]=dp[i]+1;		
		//		if(dig[i+w.first]<w.second)	
                dig[i+w.first]=w.second;

            }
		}
	}

	string ans="";
	int y=n;int b;
	while(y>0){
		int x=dig[y];
		ans+=('0'+x);
		y-=num[x];
	}
	cout<<ans<<endl;

}


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

using namespace std;

vector< vector<int> > map(11, vector<int>(7));
int direction = 0;   //R:0 L:1 U:2 D:3
int x = 2, y = 1;
char a[4], b[5];


void init(){
	for (int i = 1; i <= 9; i++)
	{
		if (i % 2)
		{
			cin >> a;
			for (int j = 0; j < 4; ++j)map[i][j + 1] = char(a[j]) - '0';
		}
		else 
		{
			cin >> b;
			for (int j = 0; j < 5; ++j)map[i][j + 1] = char(b[j]) - '0';
		}
	}
}

void Right()
{
	if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else if (map[y][x])direction = 0, x += 1, cout << 'R';
	else if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else  direction = 1, x -= 1, cout << 'L';
}

void Left()
{
	if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else direction = 0, x += 1, cout << 'R';
}

void Up()
{
	if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else if (map[y - 1][x])direction = 2, y -= 2, cout << 'U';
	else if (map[y][x])direction = 0, x += 1, cout << 'R';
	else direction = 3, y += 2, cout << 'D';
}

void Down()
{
	if (map[y][x])direction = 0, x += 1, cout << 'R';
	else if (map[y + 1][x])direction = 3, y += 2, cout << 'D';
	else if (map[y][x - 1])direction = 1, x -= 1, cout << 'L';
	else direction = 2, y -= 2, cout << 'U';
}


void solve()
{
	while (!(x == 1 && y == 1))
	{
		switch (direction)
		{
			case 0: Right(); break;
			case 1: Left(); break;
			case 2: Up(); break;
			case 3: Down(); break;
			default: return;
		}
	}
}

int main(){
	init();

	cout << 'R';
	solve();
	cout << endl;
	return(0);
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
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;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
ll N;
string S;
int P = 2019;

long long solve() {
    vector<long long> val(P, 0);
    long long tenfactor = 1;
    long long cur = 0;
    val[cur]++;
    for (int i = 0; i < N; ++i) {
        cur = (cur + (S[N-i-1]-'0') * tenfactor) % P;
        tenfactor = (tenfactor * 10) % P;
        val[cur]++;
    }
    long long res = 0;
    for (int p = 0; p < P; ++p) {
		res += val[p] * (val[p] - 1) / 2;
	}
    return res;
}
int main() {
    cin >> S;
	N = S.length();
	cout << solve() << endl;
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
using namespace std;
int d[3] = {0,1,-1};
void dfs(int x,int y,vector<vector<int> > &field){
  if((x < 0 || y < 0 || x >= field[0].size() || y >= field.size()) || field[y][x] == 0)return ;
  field[y][x] = 0;
  for(int i = -1;i <= 1;i++){
	for(int j = -1;j <= 1;j++){
	  if(i == 0 && j == 0)continue;
	  dfs(x+i,y+j,field);
	}
  }
  
}

int main(){
  int w,h;
  while(cin >> w >> h && w && h){
	vector<vector<int> > field(h,vector<int>(w,0));
	for(int i = 0;i < h;i++){
	  for(int j = 0;j < w;j++){
		cin >> field[i][j];
	  }
	}
	int ans = 0;
	for(int i = 0;i < h;i++){
	  for(int j =0;j < w;j++){
		if(field[i][j] == 1){
		  dfs(j,i,field);
		  ans++;
		}
	  }
	}
	cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1376
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void) {

	int N,L[200],i;
	long ans=0;
	scanf("%d",&N);
	REP(i,N*2)	scanf("%d", &L[i]);
	qsort(L,N*2,sizeof(int),compare_int);
	REP(i,N)	ans +=L[i*2];

	printf("%ld\n", ans);
	return 0;
}

/* 最後の改行忘れるな！！ */


Measured memory_bytes: 128
#include "stdio.h"

int main()
{
	int n=0;
	char pre[4],real[4];
	scanf("%s %s", &pre,&real);
	if (pre[0] == real[0])n++;
	if (pre[1] == real[1])n++;
	if (pre[2] == real[2])n++;
    printf("%d\n",n); 
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Deque;

/**
 * A-Z Cat
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();
		Deque<Character> az = new ArrayDeque<>();

		boolean a = true;
		for (int i = 0; i < line.length(); i++) {
			char c = line.charAt(i);
			if (c == 'A' && a) {
				az.add(c);
				a = false;
			} else if (c == 'Z' && !a) {
				az.add(c);
				a = true;
			}
		}
		if (!az.isEmpty() && az.peekLast() == 'A') {
			az.pollLast();
		}

		if (!az.isEmpty()) {
			StringBuilder sb = new StringBuilder();
			for (char c : az) sb.append(c);
			System.out.println(sb.toString());
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 24508
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<ctime>
#include<cmath>
#include<utility>
#include<cstdlib>
#include<bitset>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iomanip>
using namespace std;                       

#define ll long long
#define pb push_back
#define mp make_pair

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const ll M = 1e9 + 7;

ll fastpo(ll a, ll x){
    if(x == 0) return 1ll;
    if(x == 1) return a;
    ll y = fastpo(a, x/2);
    if(x%2 == 0){
        return y*y;
    }
    return y*y*a;
}

ll inv(ll a, ll M){
    return fastpo(a, M-2);
}

ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
    if (g != 1) 
        return -1; 
    else
    { 
        ll res = (x%m + m) % m; 
        return res;
    } 
}


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

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

void print(vector<int> &a){
    int n = a.size();
    for(int i=0; i<n; i++){
        cout<<a[i]<<" ";
    }
    cout<<endl;
}

int main(){
//    clock_t time_req;
//     time_req = clock();
    fastio;
    ll n;
    cin>>n;
    vector<ll> a(n+1, 0);
    ll sumOfVertices = (n*(n+1)*(n+2))/6;
    ll sumOfEdges = 0;
    for(int i=0; i<n-1; i++){
        ll u, v;
        cin>>u>>v;
        if(u > v) swap(u, v);
        // a[u]++;
        // a[v]++;
        sumOfEdges += (u*(n-v+1));
    }
    ll ans = sumOfVertices - sumOfEdges;
    cout<<ans<<endl;
    // time_req = clock()-time_req;
    // cout<<"Time taken: "<<(float)time_req/CLOCKS_PER_SEC<<"s"<<endl;
    return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  cout << min(A, B) + min(C, D) << endl;
  return 0;
}

Measured memory_bytes: 3608
import sys

def main():
    lines = sys.stdin.readlines()

    max_elem_num = 0
    nums = []
    for index, line in enumerate(lines):
        line = line.strip('\n')
        elems = line.split(" ")
        #print elems
        if index == 0:
            max_elem_num = int(elems[0])
            #print max_elem_num
        elif index == 1:
            for i in range(0, max_elem_num):
                print elems[max_elem_num - 1 - i],
        else:
            break

if __name__ == "__main__":
    main()

Measured memory_bytes: 6452
def main():
	n = int(input())
	arr =list(map(int,input().split()))
	cnt = 0
	for i in range(1,n-1):
		if arr[i]>arr[i-1] and arr[i]<arr[i+1]:
			cnt+=1
		elif arr[i]<arr[i-1] and arr[i]>arr[i+1]:
			cnt+=1
	print(cnt)
main()

Measured memory_bytes: 3060
from sys import stdin
from sys import setrecursionlimit
from math import ceil
from collections import Counter, deque, defaultdict
setrecursionlimit(1000000)

# INF = float('inf')
INF = int(1e10)

def input():
    return stdin.readline()[:-1]

def main():
    from builtins import int, map
    N, M = map(int, input().split())
    A = list(map(int, input().split()))
    Asum = sum(A)
    A = [4 * M * a for a in A]

    count = 0
    for a in A:
        if a >= Asum:
            count += 1
    
    if count >= M:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

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

int a[100001][2];


int main(void) {

	int n;
	int i, j;
	int flag = 1;

	scanf("%d", &n);

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

	//ループのiに数列の値を代入してみる//
	j = 0;
	for (i = 0; i < n; i = a[i][0] - 1) {
		if (a[i][0] == 1) {
			printf("-1\n");
			return 0;
		}
		if (a[i][0] == 2) {
			printf("%d", j+1);
			return 0;
		}
		if (a[i][1] == 0) {
			printf("-1\n");
			return 0;
		}
		a[i][1] = 0;
		j++;
	}

	printf("-1\n");
	return 0;
}

Measured memory_bytes: 896
<?php

$line = explode(' ', trim(fgets(STDIN)));
$all = $line[0];
$legs = $line[1];

for($i=0; $i<=$all; $i++)
{
  $amount = $i * 2 + ($all - $i) * 4;

  if($amount == $legs)
  {
    echo 'Yes' . PHP_EOL;
    return;
  }
}

echo 'No' . PHP_EOL;


Measured memory_bytes: 16216
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

struct edge{
  ll to;
  ll cost;
};

int solve() {
  ll n;
  string a1,s2;
  cin >> n;
  vector<vector<char> > s(2, vector<char> (n));
  for(ll i = 0;i < 2; i++){
    for(ll j = 0;j < n; j++){
      cin >> s[i][j];
    }
  }
  const ll MOD = 1000000007;
  // cout << MOD <<endl;
  ll lasttype = 0;
  ll type = 0;
  // x = 1, y = 2
  ll ans = 1;
  for(ll j = 0;j < n; j++){
    if(s[0][j] == s[1][j]){
      type = 1;
    }else{
      // cout << s[0][i] << " " << s[1][i] << endl;
      j++;
      type = 2;
    }
    if(lasttype == 0 && type == 1){
      ans *= 1;
    }else if(lasttype == 0 && type == 2){
      ans = (ans * 2) % MOD;
    }else if(lasttype == 1 && type == 1){
      ans = (ans * 2) % MOD;
    }else if(lasttype == 1 && type == 2){
      ans = (ans * 2) % MOD;
    }else if(lasttype == 2 && type == 1){
      ans *= 1;
    }else if(lasttype == 2 && type == 2){
      ans = (ans * 3) % MOD;
    }
    lasttype = type;
  }
  cout << (ans * 3) % MOD << endl;
  return 0;
}


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


Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	long X = sc.nextLong();
	long i = 100;
    int years = 0;
	while(i < X){
      i += i / 100L;
      years++;
    }
      System.out.println(years);
	}
}

Measured memory_bytes: 35828
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
long long change(string s)
{
    long long sum=0,tmp=0;
    for (int i=0;i<s.size();i++)
    {
        if(s[i]=='+')
        {
           sum+=tmp;
           tmp=0;
        }
        else
            tmp=tmp*10+s[i]-'0';
 
    }
    return sum+tmp;
}
int main ()
{
    string nu;
    cin>>nu;
    int len =nu.size()-1,a[11]={0};
    long long sum=0;
	while(true)
    {
		 string s;
        for (int i=0;i<len;i++)
        {
            a[i+1]+=a[i]/2;
            a[i]%=2;
        }
        
        if(a[len])
            break;
        for (int i=0;i<len;i++)
        {
            s+=nu[i];
            if(a[i])
                s+="+";
        }
        s+=nu[len];
        sum+=change(s);
        a[0]++;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 500010
using namespace std;
#define G c=getchar()
typedef long long LL;
inline LL read()
{
    LL x=0,f=1;char G;
    while(c>57||c<48){if(c=='-')f=-1;G;}
    while(c>47&&c<58)x=x*10+c-48,G;
    return x*f;
}
int d[maxn],a[maxn],b[maxn];
int n,q,i;
int main()
{
	n=read();
	a[0]=read();
	for(int i=1;i<=n;i++)
		d[i]=read(),
		a[i]=min(a[i-1],abs(a[i-1]-d[i]));
	b[n]=1;
	for(int i=n-1;i;i--)
		if(b[i+1]<=d[i+1]/2)b[i]=b[i+1];
		else b[i]=b[i+1]+d[i+1];
	for(q=read();q--;)
	{
		i=read();
		puts(b[i]<=a[i-1]?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll n;
  cin>>n;
  string s,t;
  cin>>s>>t;
  string z;
  loop(i,n){
    z+=s[i];
    z+=t[i];
  }
  putout(z);
  
}

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

int main() {
  int x, a, b;
  scanf("%d %d %d", &x, &a, &b);
  if (b - a <= 0) {
    printf("delicious");
  } else if (b - a < x + 1) {
    printf("safe");
  } else {
    printf("dangerous");
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;

int x;
bool isPossible[100010];

int main()
{
	scanf("%d", &x);
	
	memset(isPossible, false, sizeof(isPossible));
	
	isPossible[0] = true;
	for (int i = 1 ; i <= x ; i++)
	{
		isPossible[i] = false;
		for (int t = 100 ; t <= 105 ; t++)
		{
			int base = i - t;
			if ((base >= 0) && (isPossible[base] == true))
			{
				isPossible[i] = true;
				break;
			}
		}
	}
	
	if (isPossible[x] == true)
		printf("1\n");
	else
		printf("0\n");
		
	return 0;
}


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

int main(void) {
    int N;
    cin >> N;
    vector< string > S(N);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    sort(S.begin(), S.end());
    reverse(S.begin(), S.end());
    int last = 0, count = 1;
    vector< pair< int, int > > v;
    for (int i = 1; i < N; i++) {
        if (S[last] == S[i]) {
            ++count;
        } else {
            v.push_back(make_pair(count, last));
            last = i;
            count = 1;
        }
    }
    v.push_back(make_pair(count, last));
    sort(v.begin(), v.end());
    int len = v.size();
    cout << S[v[len - 1].second] << "\n";
    for (int i = len - 2; i >= 0; i--) {
        if (v[i].first == v[len - 1].first) {
            cout << S[v[i].second] << "\n";
        } else {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 15988
using System;
using CompLib.Util;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int L = sc.NextInt();

        double a = (double) L / 3;

        Console.WriteLine(a*a*a);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define sort(a) sort(a.begin(),a.end())
typedef long long ll;
const int MOD = (int)(1e9+7);
const int INF = (int)(1e9+1e7);
const ll INFL = (ll)(1e17);
const double EPS = 1e-8;
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  cout << (a^b) << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main()
{
  int r, g, b;
  std::cin >> r >> g >> b;
  bool is_multi_4 = (10 * g + b) % 4 == 0;

  std::cout << (is_multi_4 ? "YES" : "NO") << std::endl;

  return 0;
}


Measured memory_bytes: 3528
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;

//034
int main() {
	ll N, A, B, C, D;
	scanf("%lld %lld %lld %lld %lld", &N, &A, &B, &C, &D);

	bool passing = C > D ? true : false;

	static char S[200010];
	scanf("%s", S);

	bool unable = false;
	bool able_pass = false;

	if (B <= C) {
		//A-D�Ԃ̓��j�\���𒲂ׂ�(�₪2�A��������_��)
		//���łɒǂ��z���\�������ׂ�(���n��3������OK)
		ll stone_continue = 0;
		ll plane_continue = 0;
		for (ll i = A; i <= max(C, D); i++) {
			if (S[i - 1] == '#') {
				stone_continue++;
				plane_continue = 0;
				if (stone_continue >= 2) {
					unable = true;
					break;
				}
			}
			else {
				plane_continue++;
				stone_continue = 0;
				if (plane_continue >= 3 && i >= B + 1 && i <= C && i <= D + 1) {
					able_pass = true;
				}
			}

			if (unable == true) {
				break;
			}
		}

		if (passing == true && able_pass == false) {
			unable = true;
		}
	}
	else {
		ll stone_continue = 0;

		//A-C�𒲂ׂ�
		for (ll i = A; i <= C; i++) {
			if (S[i - 1] == '#') {
				stone_continue++;
				if (stone_continue >= 2) {
					unable = true;
					break;
				}
			}
			else {
				stone_continue = 0;
			}
		}

		if (unable == false) {
			//B-D�𒲂ׂ�
			for (ll i = B; i <= D; i++) {
				if (S[i - 1] == '#') {
					stone_continue++;
					if (stone_continue >= 2) {
						unable = true;
						break;
					}
				}
				else {
					stone_continue = 0;
				}
			}
		}
	}

	if (unable == true) {
		printf("No\n");
	}
	else {
		printf("Yes\n");
	}
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  string s; cin >> s;
  int plus=0, minus=0;
  rep(i,s.size()){
    if(s[i]=='+'){plus++;}
    else{minus++;}
  }

  cout << plus - minus << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int a,b,c,d;
    scanf("%d %d %d %d", &a,&b,&c,&d);
	int A = a * b;
    int B = c * d;
    if (A > B) printf("%d", A);
    else if (B > A) printf("%d", B);
    else if (A == B) printf("%d", A);
    
    return 0;
}

Measured memory_bytes: 128
def solve():
    A,B = map(int,input().split())
    S = input()
    seq = [str(x) for x in range(10)]

    for i in range(A+B+1):
        if i== A:
            if S[i] != "-":
                return False
        else:
            if not(S[i] in seq):
                return False
    return True

if __name__ == '__main__':
    cond = solve()
    if cond:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    //freopen("in.txt", "r", stdin);
    unsigned long long int n;
    cin>>n;
    if(n&1){
        return 0*puts("0");
    }
    unsigned long long t=10;
    unsigned long long cnt=0;
    while(n>=t){
        cnt+=n/t;
        t=t*5;
    }
    cout<<cnt<<endl;
}



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

int main(void)
{
	char str[2000];
	char ans[2000];
	int num, num2, num3, x, y, z;
	
	fgets(str, 1025, stdin);
	
	num = 0;
	num2 = 0;
	num3 = 0;
	z = 0;
	while (str[num] != '\0') {
		if (str[num] == ' ' || str[num] == '.') {
			if (num2 <= 6 && num2 >= 3) {
				for (x = num - num3; x < num - num3 + num2; x++) {
					ans[z] = str[x];
					z++;
				}
				ans[z] = ' ';
				z++;
			}
			num3 = -1;
			num2 = 0;
		}
		if (str[num] <= 'z' && str[num] >= 'a') {
			num2++;
		}
		else if (str[num] <= 'Z' && str[num] >= 'A') {
			num2++;
		}
		if (str[num] == 0x27) {
			num2++;
		}
		num3++;
		num++;
	}
	ans[z - 1] = '\0';
	printf("%s\n", ans);
	
	return (0);
}

Measured memory_bytes: 524
import heapq

N,M,R = map(int,input().split())
r = list(map(int,input().split()))
r = [a-1 for a in r]
paper = set()
T = [[] for i in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    T[a].append((c,b))
    T[b].append((c,a))

inf = 1 << 60
memo = {}
def distance(a,b):
    #print('distance(',a,',',b,') =?')
    if (a,b) in memo.keys():
        #print('distance(',a,',',b,') =',memo[(a,b)])
        return memo[(a,b)]
    d = [inf] * N
    d[a] = 0
    q = []
    heapq.heappush(q, (0,a))
    try:
        while True:
            c, t = heapq.heappop(q)
            if t == b:
                memo[(a,b)] = c
                memo[(b,a)] = c
                #print('distance(',a,',',b,') =',c)
                return c
            for i in T[t]:
                if d[i[1]] > c + i[0]:
                    d[i[1]] = c + i[0]
                    heapq.heappush(q, (c + i[0], i[1]))

    except IndexError:
        pass

arrived = [False] * R
ans = inf

def calc(src, rest, total):
    global ans
    if total >= ans:
        return
    if rest == 0:
        ans = min(ans,total)
        return

    for i in range(R):
        if not arrived[i]:
            arrived[i] = True
            calc(r[i], rest-1, total + distance(src,r[i]))
            arrived[i] = False

for i in range(R):
    arrived[i] = True
    calc(r[i], R-1, 0)
    arrived[i] = False

print(ans)


Measured memory_bytes: 6736
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i,j;
	char s[100];
	while(gets(s))
	{
		for(i=0,n=strlen(s);i<n;i++)
		{
			if(s[i]=='@')
			{
				
				for(j=s[++i]-'0';j>0;j--)
					putchar(s[i+1]);
				i++;
			}
			else
				putchar(s[i]);
		}
		puts("");
	}
	return 0;
}

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

int main()
{
  int N,K;
  cin >> N >> K;
  vector<int> P(N);
  for(int i = 0;i < N;i++) cin >> P[i];
  sort(P.begin(), P.end());
  int ans = 0;
  for(int i = 0;i < K;i++){
    ans += P[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3624
#include<iostream>
#include<vector>
#include <queue>
#include <string>
using namespace std;
typedef unsigned long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    if (b <= n) {
        cout << (a * (b - 1)) / b << endl;
    } else {
        cout << (a * n) / b << endl;
    }
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll n,k,i,h[1000000];
	
	cin>>n>>k;
	for(i=0;i<n;i++)
	{
		cin>>h[i];
		}
	sort(h,h+n);
	ll ans=0;
	for(i=0;i<n-k;i++)
	{
		ans+=h[i];
		}
	cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 3584
a,b=list(map(int,input().split()))
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
c=0
if a!=1 and a!= 0:
    c+=comb(a,2)
if b!=1 and b!=0:
    c+=comb(b,2)
print(c)

Measured memory_bytes: 3064