akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    while (1) {
        int n;
        int k;
        int m;
        cin >> n >> k >> m;
        if (n == 0 && k == 0 && m == 0) {
            break;
        }

        Vec<int> list(n, 1);

        int remain = n;
        int active;
        int now = m % n;
        int check;

        list[now] = 0;
        remain--;

        while (remain > 1) {
            active = k % remain;
            if (active == 0) {
                active = k;
            }
            //cout << "ACTIVE = " << active << endl;
            //cout << "HERE" << endl;
            //cout << "REM = " << remain << endl;
            while (1) {
                if (now == n) {
                    now = 0;
                }
                check = now;
                //cout << "CHECK = " << check << endl;
                if (list[check] == 1) {
                    active--;
                    if (active == 0) {
                        list[check] = 0;
                        now = check;
                        //cout << "CHECK_END = " << check << endl;
                        break;
                    }
                }
                now++;
            }
            remain--;
        }

        for (int i = 0; i < n; i++) {
            if (list[0] == 1) {
                cout << n << endl;
                break;
            }
            if (list[i] == 1) {
                cout << i << endl;
                break;
            }
        }

    }
    return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (n); ++i)
#define repe(i, n) for (int64_t i = 0; i <= (n); ++i)
#define reps(i, s, n) for (int64_t i = (s); i < (n); ++i)
#define repse(i, s, n) for (int64_t i = (s); i <= (n); ++i)
#define repr(i, n) for (int64_t i = (n); i >= 0; --i)
const int64_t inf = (int64_t)1e18;
const int64_t mod = (int64_t)1e9 + 7;


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

  int64_t A, B;
  cin >> A >> B;

  if (A == B) cout << A * 2 << endl;
  else cout << max(A, B) * 2 - 1 << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        List<List<Integer>> graph = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            graph.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int temp1 = in.nextInt();
            int temp2 = in.nextInt();
            graph.get(temp1 - 1).add(temp2-1);
        }
        int max = 0;
        //  System.out.println(go(mat,0,0));
        boolean vis[] = new boolean[n];
        int dis[] = new int[n];
        for (int i = 0; i < n; i++) {
            if (!vis[i]) {
                int temp = go(graph, i, 0, vis,dis);
                //System.out.println(i+" "+temp+" ");
                max = Math.max(max, temp);
            }
        }
        System.out.println(max);

    }

    static int go(List<List<Integer>> graph, int curr, int level, boolean vis[],int dis[]) {
        // System.out.println("Curr = "+curr+" "+level);
        int currL = level;
        if(dis[curr]>0){
            vis[curr] = true;
            return dis[curr];
        }
        vis[curr] = true;
        for (int i = 0; i < graph.get(curr).size(); i++) {
            level = Math.max(level, go(graph, graph.get(curr).get(i), currL, vis,dis) + 1);
        }
        dis[curr] = level;
        return level;
    }

}

Measured memory_bytes: 96544
#include<iostream>
using namespace std;

int main() {
	int n,d,ans=0;
	cin >> n >> d;
	int i;
	for (i = 1 + d;i<=n; i += 2 * d + 1) {
		ans++;
	}
	if (i - d - 1 < n)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }


signed main()
{
    char S[101];
    char T[101];

    cin >> S;
    cin >> T;

    int len = strlen(S);
    for (int i = 0; i <= len; i++)
    {
        if (strcmp(S, T) == 0)
        {
            cout << "Yes" << endl;
            return 0;
        }

        char f = S[0];
        for (int i = 0; i < len - 1; i++)
        {
            S[i] = S[i + 1];
        }
        S[len - 1] = f;
    }
    cout << "No" << endl;
}

 

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#define MAX_N 300000
using namespace std;

int prime[MAX_N];
bool is_prime[MAX_N + 1];

int sieve(int n){
  int x;
  //int i,j;
  int p = 0;
  for(int i = 0; i<n+1;i++) is_prime[i] = true;
  is_prime[0] = is_prime[1] = false;
  for(int i = 2;i < n+1;i++){
    if(is_prime[i]){
      prime[p++]  = i;
      for(int j = 2*i ;j < n+1;j +=i) is_prime[j] = false;
    }
    if(i == n/2) x= p;
  }
  //for(i = 0;i < p; i++) cout << prime[i]<<endl;
  return p;
}

int main(){
  int n,x;
  while(cin >> n,n){
    x = sieve(2*n);
    cout <<x - sieve(n)<<endl;
  }

  return 0;
}

Measured memory_bytes: 1492
import java.util.*;
import java.io.*;
class Main
{
	public static void main(String args[]) throws java.lang.Exception
	{
		BufferedReader inp = new BufferedReader (new InputStreamReader(System.in));
			// String h[]=inp.readLine().split(" ");
			String h[]=inp.readLine().split(" ");
			int n=Integer.parseInt(h[0]);
			long wa=Long.parseLong(h[1]);
			int v[]=new int[n+1];
			int w[]=new int[n+1];
			// HashSet<Long>hash=new HashSet<>();
			// hash.put((long)0,(long)0);
			// hash.add((long)0);
			int total=0;
			for(int i=0;i<n;i++)
			{
					
				String hh[]=inp.readLine().split(" ");
				int w1=Integer.parseInt(hh[0]);
				int v1=Integer.parseInt(hh[1]);
				v[i]=v1;
				w[i]=w1;
				total+=v1;


					
				
			}
			boolean dp[][]=new boolean[n+1][total+1];
			long aa[][]=new long[n+1][total+1];
			for(int i=0;i<=n;i++)
			{
				for(int j=0;j<=total;j++)
				{
					aa[i][j]=Integer.MAX_VALUE;
				}
			}
			aa[0][0]=(long)0;
			dp[0][0]=true;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<=total;j++)
				{
					
						dp[i+1][j]=dp[i][j];
						
					
					if(j>=v[i] && dp[i][j-v[i]] && aa[i][j-v[i]]+w[i]<=wa)
					{
						dp[i+1][j]=true;
						// System.out.println(j);
						aa[i+1][j]=aa[i][j-v[i]]+w[i];
					}
					aa[i+1][j]=Math.min(aa[i][j],aa[i+1][j]);

				}
			}
			for(int j=total;j>=0;j--)
			{
				if(dp[n][j]){System.out.println(j);break;}
			}
			
					
		
	}
	
}
class Pair
{
	int a;
	long b;
	
	Pair(int e, long f)
	{
		a=e;
		b=f;
		
	}
}

Measured memory_bytes: 161472
// 参考
// https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

use std::cmp::max;
// Input macro
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

// Test Code
macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r"3 1
" => r"4",

r"4 -2
" => r"6",

r"0 0
" => r"0"
}

fn main() {
    println!("{}", solve(&stdin!()));
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: i32,
        b: i32
    }

    max(a + b, max(a - b, a * b)).to_string()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, K, X[201010];
int Q;
//---------------------------------------------------------------------------------------------------
int toRight[201010], toLeft[201010];
int toR[19][201010], toL[19][201010];
int totR[19][201010], totL[19][201010];
//---------------------------------------------------------------------------------------------------
int getTot(int L, int R) {
	int res = 1;
	int cu = L;
	rrep(p, 18, 0) {
		if (toR[p][cu] <= R) {
			res += 1 << p;
			cu = toR[p][cu];
		}
	}
	return res;
}
int getRight(int L, int R) {
	int cnt = getTot(L, R);

	ll tot = R; cnt--;
	int cu = R;
	rep(p, 0, 19) if (cnt & (1 << p)) {
		tot += totL[p][cu];
		cu = toL[p][cu];
	}

	return tot;
}
int getLeft(int L, int R) {
	int cnt = getTot(L, R);

	ll tot = L; cnt--;
	int cu = L;
	rep(p, 0, 19) if (cnt & (1 << p)) {
		tot += totR[p][cu];
		cu = toR[p][cu];
	}

	return tot;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> K;
	rep(i, 0, N) cin >> X[i];
	cin >> Q;

	rep(i, 0, N) toRight[i] = lower_bound(X, X + N, X[i] + K) - X;
	rep(i, 0, N) {
		int id = upper_bound(X, X + N, X[i] - K) - X;
		toLeft[i] = id - 1;
	}

	rep(p, 0, 19) toR[p][N] = N;
	rep(i, 0, N) toR[0][i] = toRight[i];
	rep(p, 1, 19) rep(i, 0, N) toR[p][i] = toR[p - 1][toR[p - 1][i]];

	rep(i, 0, N) totR[0][i] = toR[0][i];
	rep(p, 1, 19) rep(i, 0, N) totR[p][i] = totR[p - 1][i] + totR[p - 1][toR[p - 1][i]];

	rep(i, 0, N) toL[0][i] = toLeft[i];
	rep(p, 1, 19) rep(i, 0, N) {
		if (toL[p - 1][i] < 0) toL[p][i] = -1;
		else toL[p][i] = toL[p - 1][toL[p - 1][i]];
	}

	rep(i, 0, N) totL[0][i] = toL[0][i];
	rep(p, 1, 19) rep(i, 0, N) {
		if (toL[p - 1][i] < 0) totL[p][i] = totL[p - 1][i];
		else totL[p][i] = totL[p - 1][i] + totL[p - 1][toL[p - 1][i]];
	}

	rep(q, 0, Q) {
		int L, R; cin >> L >> R;
		L--; R--;
		ll ans = getRight(L, R) - getLeft(L, R) + getTot(L, R);
		printf("%lld\n", ans);
	}

}







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

using namespace std;

typedef long long ll;

int main() {
    string N;
    cin >> N;
    int mod = 0;
    for (int i = 0; i < N.size(); i++) {
        mod += N[i] - '0';
        mod %= 9;
    }
    if (mod == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

#define T9 1000000000

int main(void){
	long s;
	long a, b;
	scanf("%ld", &s);
	a=s/T9+1;
	if(a>T9) a=T9;
	b=a*T9-s;
	printf("%d %d %d %d %d %d\n", 0, 0, T9, 1, b, a);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a,b,c,k,x=0;
  cin>>a>>b>>c>>k;
  if (a>=k)
    x=k;
  else if((a+b)>=k)
    x=a;
  else
    x=a-(k-a-b);
  cout<<x<<endl;
}

Measured memory_bytes: 3620
N, M = map(int,input().split())
li = [list(map(int,input().split())) for i in range(M)]
s = []
g = []
li.sort()

for i in range(M):
  if li[i][0]==1:
    s.append(li[i][1])
  else:
    break

li.sort(key=lambda x: x[1],reverse=True)

for i in range(M):
  if li[i][1]==N:
    g.append(li[i][0])
  else:
    break

if len(set(s)&set(g))>0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

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

#define ll long long

template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

void solve() {
  string a,b,c; cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << '\n';

  return;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T=1;
  //cin >> T;
  while(T--) solve();

  return 0;
}


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


int main()
{
	int i,c=0;
	int a[4];
	for(i=1;i<=3;i++) cin>>a[i];
	sort (a+1,a+3+1);
	for(i=2;i<=3;i++)
	{
		c += a[i]-a[i-1];
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
io = STDIN
n=io.gets.to_i

ab=n.times.map{io.gets.split.map(&:to_i)}
ar= ab.sort_by{|a,b|[b,a]}
def check(ar)
  ar.inject(0) do |s,(a,b)|
    rui = s+a
    return "No" if rui>b
    rui
  end
  "Yes"
end
puts check(ar)


Measured memory_bytes: 26488
import sys
n = int(input())
if n < 3:
	print("No")
else:
	#print("Yes")
	ans = []
	for i in range(2, n, 2):
		ans.append([1, i])
		ans.append([i, i+1])
		ans.append([1, n+i+1])
		ans.append([n+i+1, n+i])
	ans.append([3, n+1])
	if n%2 == 0:
		for i in range(1, n):
			if (n+1)^i < n:
				if i%2 == 0:
					ans.append([i, n])
					ans.append([((n+1)^i) + n, 2*n])
				else:
					ans.append([(n+1)^i, n])
					ans.append([n+i, 2*n])
				break
		else:
			print("No")
			sys.exit()
	print("Yes")
	for a in ans:
		print(*a)

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

int main() {
    int N; cin >> N;
    vector<char> c(N);
    int lastr = N;
    rep(i, N){
        cin >> c[i];
        if(c[i] == 'R'){
            lastr = i;
        }
    }

    stack<int> R;
    queue<int> W;
    for (int i = 0; i <= lastr; i++){
        if(c[i] == 'R'){
            R.push(i);
        } else {
            W.push(i);
        }
    }

    ll ans = 0;
    while(!R.empty() && !W.empty()){
        int r = R.top(); R.pop();
        int w = W.front(); W.pop();
        if(r > w){
            ans++;
        } else {
            break;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    long long ans = 0;
    for(auto& p : mp){
        int s = p.second;
        ans += (long long)s*(s-1)/2;
    }
    cout << ans;
}


Measured memory_bytes: 11136
package main

import (
	"fmt"
)

func main() {
	var c int
	var s, t string
	fmt.Scan(&s)
	fmt.Scan(&t)
	for i := 0; i < len(s); i++ {
		if s[i] == t[i] {
			continue
		}
		c++
	}
	fmt.Println(c)
}


Measured memory_bytes: 4508
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{BufWriter, Write};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: i64,
        k: usize,
        d: [i64; k],
    }

    'outer1: for i in n..10 * n as i64 {
        //10*nが解の上限
        let mut flag = true;
        let mut a = i;
        'outer2: while a > 0 {
            for j in 0..k {
                if a % 10 == d[j] {
                    flag = false;
                    break 'outer2;
                }
            }
            a = a / 10;
        }
        if flag == true {
            puts!("{}\n", i);
            break 'outer1;
        }
    }
}

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


Measured memory_bytes: 2248
#include <stdio.h>

 

int main(void) {

    int a,b,c,i;

    int count;

    scanf("%d %d %d\n", &a, &b, &c);

    for(i=a,count=0;i<=b;i++) {

        if(c%i==0) count ++;

    }

    printf("%d\n", count);

     

    return 0;

}

Measured memory_bytes: 600
XS = list(map(int, open(0).read().split()))
for i in range(0, len(XS), 2):
    H = XS[i]
    W = XS[i+1]
    if H == 0 and W == 0:
        break
    for _ in range(H):
        print("#" * W)
    print("")


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

int main(void){
  int n;
  cin >> n;
  int c = 0;
  bool flag = true;
  for(int i = 0; i < n; i++){
    string input; cin >> input;
    if(input[0] == 'A') c++;
    else c--;
    if(c < 0) flag = false;
  }

  if(flag && c == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define chmin(a,b) (a)=min((a),(b));

using vi = vector<int>;
using vvi = vector<vi>;
const int inf = 1e9;
using Graph = vector<vector<int>>;

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

    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }

    int q;
    cin >> q;

    vvi dp(n, vi(11, inf));
    vi c(q);
    rep(i, q) {
        int v, d;
        cin >> v >> d >> c[q - i - 1];
        v--;
        dp[v][d] = q - i - 1;
    }

    for (int d = 10; d > 0; d--) {
        rep(i, n) {
            chmin(dp[i][d - 1], dp[i][d]);
            for (auto j : G[i]) {
                chmin(dp[j][d - 1], dp[i][d]);
            }
        }
    }

    rep(i, n) {
        cout << (dp[i][0] == inf ? 0 : c[dp[i][0]]) << endl;
    }
}


Measured memory_bytes: 15480
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 1000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
bitset<maxx/2>vis;
vector<ll>prime;
void sieve(){
    ll x=maxx/2, y=sqrt(maxx)/2;
    for(ll i=1;i<=y;i++){
        if(vis[i]==0){
            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
                vis[j]=1;
        }
    }
    prime.push_back(2);
    for(ll i=3;i<maxx;i+=2)
        if(vis[i/2]==0)
        prime.push_back(i);
}
bool isprime(ll a)
{
    if(a==2){
        return true;
    }
    if(a%2==0){
        return false;
    }
    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++){
        if(a%prime[i]==0){
            return false;
        }
    }
    return true;
}
ll lcm(ll a,ll b)
{
    return (a*b)/__gcd(a,b);
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
string a="abcdefghijklmnopqrstuvwxyz";
void Dufaux()
{
    ll n;
    cin>>n;
    vector<ll>vec;
    while(n){
        n-=1;
        vec.pb(n%26);
        n/=26;
    }
    for(int i=vec.size()-1;i>-1;i--){
        cout<<a[vec[i]];
    }
    cout<<endl;
}
int main()
{
	FastIO;
	///sieve();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		if (a>=b) {
			System.out.println("delicious");
			return;
		}
		if (b-a > x) {
			System.out.println("dangerous");
			return;
		}
		if (b-a <= x) {
			System.out.println("safe");
			return;
		}
	}
}


Measured memory_bytes: 20564
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> y;
  bool f = false;
  for(int i=0; i <= n; i++) {
    for(int j=0; i + j <= n; j++) {
      int k = (n - (i + j));
      if((i * 10000 + j * 5000 + k * 1000) == y) {
        cout << i << " " << j << " " << k << endl;
        f = true;
      }
      if(f) break;
    }
    if(f) break;
  }

  if(!f) cout << -1 << " " << -1 << " " << -1 << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int MAX(int a,int b){return a<b?b:a;}
int MIN(int a,int b){return a<b?a:b;}
int f(long long a){
	int i;
	for(i=0;a;i++)a/=10;
	return i;
}
int main(){
	long long n,i;
	int m=11;
	scanf("%lld",&n);
	for(i=1;i*i<=n;i++){
		if(n%i)continue;
		m=MIN(m,MAX(f(i),f(n/i)));
	}
	printf("%d\n",m);
	return 0;
}

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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 2e5+5;

int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

void solve() {


   int n, z = 0;
   cin>>n;
   map<pii,int> mp;
   rep(_,0,n){
     int a,b;
     cin>>a>>b;
     if(!a&&!b)
       z++;
     else if(!b){
       mp[{-1,0}]++;
     }else if(!a){
       mp[{0,1}]++;
     }else{
       int g = __gcd(abs(a),abs(b));
       a/=g, b/=g;
       if(b<0)
         b=-b, a=-a;
       mp[{a,b}]++;
     }
   }
  
  int ans = 1;
   
  trav(p,mp){
     int x = -p.fi.se, y = p.fi.fi;
     if(y<0)
       x=-x,y=-y;
     pii p1 = {x,y};
     (ans*=powm(2ll,p.se)+powm(2ll,mp[p1])-1)%=mod;
     mp.erase(p1);
  }
  (ans += z - 1 + mod)%=mod;
  cout<<ans;


}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}





int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}


Measured memory_bytes: 15940
import java.math.BigDecimal;
import java.util.*;
import static java.lang.System.out;

public class Main {
    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);
        int l = sc.nextInt();
        BigDecimal decimalL = new BigDecimal(l);
        BigDecimal height = decimalL.divide(new BigDecimal(3),7, BigDecimal.ROUND_HALF_DOWN);
        BigDecimal ans = height.multiply(height).multiply(height);
        System.out.println(ans);
    }

}


Measured memory_bytes: 21844
fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let t = read1::<String>().chars().collect::<Vec<char>>();

    let mut ans = "".to_string();
    for &c in t.iter() {
        if c == '?' {
            ans = ans + "D";
        } else {
            ans = ans + &(c.to_string());
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 3112
N,M,K = map(int,input().split())

MOD =  998244353
mod = MOD
MAX = N+1
fac = [0] * MAX
finv = [0] * MAX
inv = [0] * MAX
def cominit():
    fac[0] = 1
    fac[1] = 1
    finv[0] = 1
    finv[1] = 1
    inv[1] = 1
    for i in range(2,MAX):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod//i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
def cmb(n,r):
    if n < 0 or r < 0 or r > n:return 0
    if r > n/2: r = n-r        
    return fac[n] * (finv[r] * finv[n-r] % mod) % mod
    
cominit()

ans = pow(M,N,MOD)
minus = 0
for k  in range(K+1,N):
    minus += M * pow(M-1,N-k-1,MOD) * cmb(N-1,k)
    minus %= MOD

ans -= minus 
ans = (ans+MOD)%MOD
print(ans)

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

int main(){
	int N,K;
	cin >> N >> K;
	vector<int> a(N);
	for(auto &i:a)cin >> i;
	
	vector<int> b;
	for(auto i:a)if(i<K)b.push_back(i);
	int M=b.size();
	sort(b.begin(),b.end());
	
	if(M<=1){
		cout << M << endl;
		return 0;
	}
	
	int ok=-1,ng=M;
	while(abs(ok-ng)>1){
		int mid=(ok+ng)/2;
		bool dp[M+1][5000];
		for(int i=0;i<M+1;i++)for(int j=0;j<5000;j++)dp[i][j]=false;
		dp[0][0]=true;
		for(int i=0;i<M;i++){
			if(i==mid){
				for(int j=0;j<5000;j++){
					dp[i+1][j]|=dp[i][j];
				}
			}else{
				for(int j=0;j<5000;j++){
					dp[i+1][j]|=dp[i][j];
					if(j>=b[i])dp[i+1][j]|=dp[i][j-b[i]];
				}
			}
		}
		bool flag=false;
		for(int j=K-b[mid];j<K;j++)flag|=dp[M][j];
		if(!flag)ok=mid;
		else ng=mid;
	}
	cout << ok+1 << endl;
	return 0;
}

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

int main() {
  int N;
  long long Ans=0, a=2, b=1;
  cin >> N;
  if (N==1) Ans=1;
  else{
    rep(i, N-1){
      Ans=a+b;
      a=b;
      b=Ans;
    }
  }
  cout << Ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
void BubbleSort(char**, int);
void SelectionSort(char**, int);
char C[36],D[36];
int main(){
  int i, N, flag;
  char **A, *B;
  scanf("%d",&N);
  A = (char **)malloc(sizeof(char*) * N);
  for(i=0; i<N; i++)
    A[i] = (char *)malloc(sizeof(char) * 2);
  for(i=0; i<N; i++)
    scanf("%s",A[i]);
  
  BubbleSort(A, N);
  SelectionSort(A, N);
  for(i=0,flag=1; i<N; i++)
    if(D[i] != C[i]){
      flag = 0;
      break;
    }
  flag ? printf("Stable\n"):printf("Not stable\n");
  free(A);
  return 0;
}

void BubbleSort(char* A[], int N){
  int n, i, j;
  char B[N][2];
  char x[2];
  n = N;
  for(i=0;i<N;i++)
    B[i][0]=A[i][0],B[i][1]=A[i][1];

  for(i=0; i<N-1; i++){
    for(j=N-1; j>i; j--)
      if(B[j][1] < B[j-1][1]){
	x[0] = B[j-1][0];
	x[1] = B[j-1][1];
	B[j-1][0] = B[j][0];
	B[j-1][1] = B[j][1];
	B[j][0] = x[0];
	B[j][1] = x[1];
      }
  }
  for(i=0; i<N; i++){
    printf("%c%c",B[i][0],B[i][1]);
    i < N-1 ? printf(" "):printf("\n");
    C[i] = B[i][0];
  }
  printf("Stable\n");
}

void SelectionSort(char* A[], int N){
  int i, j, min;
  char x[2];
  for(i=0; i<N-1; i++){
    min = i;
    for(j=i; j<N; j++){
      if(A[j][1] < A[min][1])
	min = j;
    }
    x[0] = A[i][0];
    x[1] = A[i][1];
    A[i][0] = A[min][0];
    A[i][1] = A[min][1];
    A[min][0] = x[0];
    A[min][1] = x[1];
  }
  for(i=0; i<N; i++){
    printf("%c%c",A[i][0],A[i][1]);
    i < N-1 ? printf(" "):printf("\n");
    D[i] = A[i][0];
  }
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, e) for (int i = s; i < e; ++i)
#define sort_(a) stable_sort(a.begin(), a.end())
#define rsort(a) stable_sort(a.rbegin(), a.rend())
#define sum(a) accumulate(a.begin(), a.end(), 0LL)
#define __lcm(a, b) std::__detail::__lcm(a, b)
typedef long long ll;
const long mod = 1e9 + 7;

int main(void) {
#ifdef DEBUG
  freopen("input.txt", "r", stdin);
#endif

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

  string S;
  cin >> S;
  int t = S.size();
  int l;
  reverse(S.begin(), S.end());
  rep(i, 0, t) {
    S.erase(0, 1);
    if (S.size() % 2 == 0) {
      l = S.size() / 2;
      if (S.substr(0, l) == S.substr(l)) {
        cout << S.size() << endl;
        break;
      }
    }
  }
  return 0;
}


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

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

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

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

ll dp[101][100100];

int main() {
    int n, W;
    cin >> n >> W;
    vector<int> w(n);
    vector<ll> v(n);
    rep(i,n) cin >> w[i] >> v[i];

    rep(i,n) {
        for (int j = 0; j<=W; ++j) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j-w[i]>=0) dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]]+v[i]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}



















Measured memory_bytes: 78464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll h,m;
	vector<ll>ch;
	cin>>h>>m;
	for(ll i=0;i<h;i++){
		ll x;
		cin>>x;
		ch.push_back(x);
	}
	sort(ch.begin(),ch.end());
	ll sum=0;
	for(ll i=0;i<h-m;i++){
		sum+=ch[i];
	}
	cout <<sum;
	// your code goes here
	return 0;
}

Measured memory_bytes: 5356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int isprime[100001];
int likenum[100002];
int main()
{
	int q;
	cin >> q;
	for(int i = 2;i<100001;i++)
	{
		if(isprime[i]==0)
		{
			for(int j = i*2;j<100001;j+=i)
			{
				isprime[j] = 1;
			}
		}
	}
	isprime[0] = isprime[1] = 1;
	//for(int i = 0;i<12;i++)cout<<i<<' '<<isprime[i]<<endl;
	for(int i = 1;i<100002;i+=2)
	{
		if(isprime[i]==0&&isprime[(i+1)/2]==0)
		{
			likenum[i]++;
		}
	}
	for(int i = 0;i<100001;i++)
	{
		likenum[i+1] += likenum[i];
	}
	while(q--)
	{
		int l,r;
		cin >> l >> r;
		cout<<likenum[r]-likenum[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
#define ll long long

int main(){
    ll N;
    cin >> N;
    ll i;
    ll A[N];
    for(i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A,A+N);
    ll a=0,b=0,c=1;
    ll t=A[0];
    ll ans=1;
    for(i=1;i<N;i++){
        if(A[i-1]==A[i])c++;
        if(A[i-1]+1==A[i]){
            a=b;
            b=c;
            c=1;
        }
        if(A[i-1]+2==A[i]){
            a=c;
            b=0;
            c=1;
        }
        if(A[i-1]+2<A[i]){
            a=0;
            b=0;
            c=1;
        }
        ans=max(ans,a+b+c);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;

vector<double>a;
double dp[3005][3005];
double fun(int i, int k){
    // deb(i);
    // deb(k);
    if(k<0){
        return 0;
    }
    if(k>i){
        return 0;
    }
    if(i==1){
        if(k==1){
            return a[i];
        }
        if(k==0){
            double ans=1-a[i];
            return ans;
        }
    }
    if(dp[i][k]!=-1){
        return dp[i][k];
    }
    dp[i][k]=a[i]*fun(i-1,k-1)+(1-a[i])*fun(i-1,k);
    return dp[i][k];
}
int32_t main(){
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    a.resize(n+1);
    for(int i=0;i<3005;i++){
        for(int j=0;j<3005;j++){
            dp[i][j]=-1;
        }
    }

    REP(i,1,n+1){
        cin>>a[i];
    }
    double ans=0;
    for(int i=(n/2)+1;i<=n;i++){
        ans+=fun(n,i);
    }
    printf("%0.12lf\n",ans);



    return 0;
}

Measured memory_bytes: 71040
#include <iostream>
#include <complex>
#include <utility>
#include <vector>
using namespace std;

typedef complex<double> Point, Vector;
typedef pair<Point, Point> Segment, Line;
typedef vector<Point> Polygon;

#define X real()
#define Y imag()
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)

double dot(Vector a, Vector b){
    return a.X * b.X + a.Y * b.Y;
}

double cross(Vector a, Vector b){
    return a.X * b.Y - a.Y * b.X;
}

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

// ベクトルと点の位置関係
int ccw(Point p0, Point p1, Point p2){
    Vector a = p1 - p0;
    Vector b = p2 - p0;
    if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
    if(cross(a, b) < -EPS) return CLOCKWISE;
    if(dot(a, b) < -EPS) return ONLINE_BACK;
    if(norm(a) < norm(b)) return ONLINE_FRONT;

    return ON_SEGMENT;
}

bool isConvex(Polygon pol){
    int n = pol.size();

    for(int i=0; i<n; i++){
        if(ccw(pol[i], pol[(i+1)%n], pol[(i+2)%n]) == CLOCKWISE){
            return false;
        }
    }

    return true;
}

int main(){
    int n; cin>>n;
    Polygon pol;
    for(int i=0; i<n; i++){
        double x, y; cin>>x>>y;
        pol.emplace_back(x, y);
    }

    cout << isConvex(pol) << endl;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> index(N + 1);
    for(int i=0; i<N; ++i) {
        int a;
        cin >> a;
        index[a - 1] = i;
    }

    long long res = 0;
    set<int> S;
    S.insert(-1);
    S.insert(N);

    for(int i=0; i<N; ++i) {
        auto itr = S.lower_bound(index[i]);
        long long r = *itr;
        --itr;
        long long l = *itr;
        res += (r - index[i]) * (index[i] - l) * (i + 1);
        S.insert(index[i]);
    }

    cout << res << endl;
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long li;
#define MOD 1000000007
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }
// Container コンテナ型, map以外
template< template<class ...> class Ctn,class T>
std::ostream& operator<<(std::ostream& os,const Ctn<T>& v){
  auto itr=v.begin();
  while(itr!=v.end()){
    if(itr!=v.begin())cout << " ";
    cout << *(itr++);
  }
  return os;
}

li totient(li n,vector<li>& factor){
  if(df)print("totient",n,":");
  for(li x:factor){
    n/=x;
    n*=x-1;
  }
  if(df)print(n);
  return n;
}

li pow(li a,li r){
  li b=a,s=1;
  if(df)print("pow",a,r);
  while(r){
    if(r%2) (s*=b)%=MOD;
    (b*=b)%=MOD;
    r/=2;
  }
  if(df)print(s);
  return s;
}

int main(){
  li n,k; cin >>k >>n;
  vector<vector<li>> factor(n+1);
  repa(i,2,n+1){
    if(factor[i].size())continue;
    repa(j,1,n+1){
      if(i*j>n)break;
      factor[i*j].push_back(i);
    }
  }
  if(df)rep(i,n+1)print(factor[i]);
  li s=0; 
  repa(i,1,n+1){
    s+=pow(n/i,k)*totient(i,factor[i])%MOD;
    s%=MOD;
  }
  print(s);
}


Measured memory_bytes: 10108
#include "bits/stdc++.h"
using namespace std;

#define ub upper_bound
#define sum(a) accumulate(all(a),0ll)
#define lb lower_bound
#define all(v) begin(v),end(v)
#define allr(v) rbegin(v),rend(v)
#define sort_dec(v) sort(all(v),[](auto e1,auto e2){return e1>e2;})
#define For(n) for(ll i=0;i<n;i++)
#define Forj(n) for(ll j=0;j<n;j++)
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define Mp 1e9+7
#define vpll vector< pair<ll,ll> >
#define bug(n) {cout<<n;return;}
#define cont(n) {cout<<n<<endl;continue;}
#define pb push_back
 
void solve()
{
	string s,t;
	cin>>s>>t;
	ll n=s.size(),m=t.size();
	ll dp[n+1][m+1];
	memset(dp,0,sizeof(dp));
	For(n)
	{
		Forj(m)
		{
			if(s[i]==t[j])dp[i+1][j+1]=dp[i][j]+1;
			else dp[i+1][j+1]=max(dp[i][j+1],dp[i+1][j]);
		}
	}
	string ans="";
	 int i = n, j = m; 
   while (i > 0 && j > 0) 
   { 
      // If current character in X[] and Y are same, then 
      // current character is part of LCS 
      if (s[i-1] == t[j-1]) 
      { 
          ans+= s[i-1]; // Put current character in result 
          i--; j--;    // reduce values of i, j and index 
      } 
  
      // If not same, then find the larger of two and 
      // go in the direction of larger value 
      else if (dp[i-1][j] > dp[i][j-1]) 
         i--; 
      else
         j--; 
   }
	reverse(ans.begin(),ans.end());
	cout<<ans;
	// cout<<dp[n][m];
}
 
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	 
	// freopen("error.txt", "w", stderr);
	 
	int t=1;
	 
	while(t--)
	{
		solve();
	}

	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	 
	return 0;
}

Measured memory_bytes: 74104
//NMD WSM
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
typedef long long ll;
ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
#define pr std::pair<int,int>
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
template<class T>void cxk(T&a,T b){a=a>b?a:b;}
template<class T>void cnk(T&a,T b){a=a<b?a:b;}
int mod;
int pow(int x,int y){
	int ret=1;
	while(y){
		if(y&1)ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
template<class Ta,class Tb>void inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;}
template<class Ta,class Tb>void dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;}
int g[101][101],C[101][101],CC[101][101],pw[101][10086],f[2][101][101];
int main(){
#ifdef LOCAL
	freopen("in.in","r",stdin);
	//freopen("out.out","w",stdout);
#endif
	int n=gi(),m=gi(),k=gi();mod=gi();
	C[0][0]=1;
	pw[0][0]=1;
	for(int i=1;i<=100;++i){
		C[i][0]=1;
		for(int j=1;j<=i;++j)C[i][j]=(C[i-1][j]+C[i-1][j-1])%mod;
		pw[i][0]=1;
		for(int j=1;j<=10000;++j)pw[i][j]=1ll*pw[i][j-1]*i%mod;
	}
	for(int i=0;i<=100;++i)
		for(int j=0;j<=100;++j)
			CC[i][j]=C[j][i];
	f[0][0][0]=1;
	int t=0;
	for(int o=1;o<=k;++o){
		memset(f[!t],0,101*101*4);
		for(int j=0;j<=m;++j)for(int i=0;i<=n;++i)g[j][i]=1ll*pw[o][i*(m-j)]*pw[k-o+1][i*j]%mod;
		for(int i=0;i<=n;++i)
			for(int j=0;j<=m;++j){
				int w=f[t][i][j];if(!w)continue;
				int*CCC=CC[i]+i,*shit=f[!t][j]+i;
				for(int ni=0;ni<=n-i;++ni)inc(shit[ni],1ll*w*CCC[ni]%mod*g[j][ni]%mod);
			}
		t^=1;memset(f[!t],0,101*101*4);
		for(int i=0;i<=100;++i)for(int j=i+1;j<=100;++j)std::swap(f[t][i][j],f[t][j][i]);
		for(int i=0;i<=n;++i)for(int j=0;j<=m;++j)g[i][j]=1ll*pw[o][j*(n-i)]*pw[k-o+1][i*j]%mod;
		for(int i=0;i<=n;++i)
			for(int j=0;j<=m;++j){
				int*CCC=CC[j]+j,*shit=f[!t][i]+j;
				int w=f[t][i][j];if(!w)continue;
				for(int nj=0;nj<=m-j;++nj)inc(shit[nj],1ll*w*CCC[nj]%mod*g[i][nj]%mod);
			}
		t^=1;memset(f[!t],0,101*101*4);
		for(int j=0;j<=m;++j)for(int i=0,M=1;i<=n;++i,M=mod-M)g[j][i]=1ll*pw[o][i*(m-j)]*pw[k-o][i*j]%mod*M%mod;
		for(int i=0;i<=n;++i)
			for(int j=0;j<=m;++j){
				int w=f[t][i][j];if(!w)continue;
				int*CCC=CC[i]+i,*shit=f[!t][j]+i;
				for(int ni=0;ni<=n-i;++ni)inc(shit[ni],1ll*w*CCC[ni]%mod*g[j][ni]%mod);
			}
		t^=1;memset(f[!t],0,101*101*4);
		for(int i=0;i<=100;++i)for(int j=i+1;j<=100;++j)std::swap(f[t][i][j],f[t][j][i]);
		for(int i=0;i<=n;++i)for(int j=0,M=1;j<=m;++j,M=mod-M)g[i][j]=1ll*pw[o][j*(n-i)]*pw[k-o][i*j]%mod*M%mod;
		for(int i=0;i<=n;++i)
			for(int j=0;j<=m;++j){
				int*CCC=CC[j]+j,*shit=f[!t][i]+j;
				int w=f[t][i][j];if(!w)continue;
				for(int nj=0;nj<=m-j;++nj)inc(shit[nj],1ll*w*CCC[nj]%mod*g[i][nj]%mod);
			}
		t^=1;
	}
	printf("%d\n",f[t][n][m]);
	return 0;
}


Measured memory_bytes: 4352
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	int a,b,k;
	cin >> a >> b >> k;
	if (a + k * 2 > b) {
		REP(i, b - a + 1) {
			cout << a + i << endl;
		}
		return(0);
	}
	REP(i, k) {
		cout << a + i << endl;
	}
	REP(i, k) {
		cout << b - k + i +1 << endl;
	}
	return(0);
}

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

int N;
void dfs(string s, char mx){
  if(s.length() == N){
    cout<<s<<endl;
  }else{
    for(char c='a';c<=mx;c++){
      char moji;
      if(c==mx){
        moji=char(mx+1);
      }else{
        moji=mx;
      }
      dfs(s+c, moji);
    }
  }
}

int main(void){
  cin >> N;
  dfs("", 'a');
  return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>
#define N 1000000

int main(void)
{

  int i,j,n,m,key,count=0;
  int s[N],t[N];
  int left,mid,right;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&s[i]);
    }

  scanf("%d",&m);
  for(j=0;j<m;j++)
    {
      scanf("%d",&t[j]);
    }
  

  for(j=0;j<m;j++)
    {
      left = 0;
      right = n;
      key = t[j];
      while(left < right)
	{
	  mid = (left + right) / 2;
	  if(s[mid] == key)
	    {
	      count++;
	      break;
	    }
	  else if(key < s[mid])
	    {
	      right = mid;
	    }
	  else
	    {
	      left = mid + 1;
	    }
	}
    }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 3040
#include<stdio.h>
int main(){
  double w;
  while(scanf("%lf",&w)!=-1){
    if(w<=48)
      puts("light fly");
    else if(w<=51)
      puts("fly");
    else if(w<=54)
      puts("bantam");
    else if(w<=57)
      puts("feather");
    else if(w<=60)
      puts("light");
    else if(w<=64)
      puts("light welter");
    else if(w<=69)
      puts("welter");
    else if(w<=75)
      puts("light middle");
    else if(w<=81)
      puts("middle");
    else if(w<=91)
      puts("light heavy");
    else
      puts("heavy");
  }
  return 0;
}

Measured memory_bytes: 0