akhauriyash/Code-Regression huggingface dataset:
program AIsing2019B
    implicit none
    integer(8)::N,A,B,a_count=0,b_count=0,i
    integer(8),allocatable::P(:)
    read*,N,A,B
    allocate(P(N))
    read*,P
    call heapsort(N,P)
    do i=1,N
        if(P(i)<=A)a_count=a_count+1
        if(P(i)>=A+1.and.P(i)<=B)b_count=b_count+1
    end do
    print'(i0)',min(a_count,b_count,N-a_count-b_count)
end program AIsing2019B

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
end subroutine heapsort

Measured memory_bytes: 2896
/* winners never quit and quitters never win.
      #swap                                 */
      
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize ("-O3")
using ll = long long;
using ld = long double;
const ll mod = 1000000007;
const ll inf = 1000000000000000000;
const ll rk = 256;
const ld PI = 3.141592653589793;

typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

#define endl '\n'
#define pb push_back
#define mp make_pair
#define vc vector
#define fs first
#define sec second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pls pair<ll,string>
#define psl pair<string,ll>
#define plc pair<ll,char>
#define pcl pair<char,ll>
#define pss pair<string,string>
#define all(x) (x).begin(), (x).end()
#define tol(s) transform(s.begin(),s.end(),s.begin(),::tolower);
#define tou(s) transform(s.begin(),s.end(),s.begin(),::toupper);
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define T ll t=0;cin>>t;for(ll test=0;test<t;test++)

ll nxt() {
    ll TemporaryVariable;
    cin >> TemporaryVariable;
    return TemporaryVariable;
}

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
	//isprime();
	//coeff();
	/*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    ld n;
	cin>>n;
	cout<<2*PI*n<<endl;
	printclock;
	return 0;
}

Measured memory_bytes: 3800
import java.lang.Math.max

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = Array(n) {
        readLine()!!.toInt() / 10
    }

    fun isPossibleToReach(): Boolean {
        var current = 0
        for (i in d.indices) {
            if (current < i) return false
            current = max(current, i + d[i])
        }
        return current >= d.size
    }

    if (!isPossibleToReach()) {
        println("no")
        return
    }
    d.reverse()
    if (!isPossibleToReach()) {
        println("no")
        return
    }
    println("yes")
}


Measured memory_bytes: 56808
#!/usr/bin/ruby
# coding: utf-8

PI = Math.acos(-1)

$memo = [nil, [1.0, 0.0], [1.0, 1.0]]

def f(n)
  if $memo[n] != nil
    return $memo[n]
  end
  x, y = f(n-1)
  z = Math.sqrt(x**2 + y**2)
  [x - y/z, y + x/z]
end

while true
  n = gets.to_i
  if n < 0
    break
  else
    puts f(n)
  end
end

Measured memory_bytes: 6288
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;
public class Main { 
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = (int)(1e5);
		boolean[] prime = new boolean[N+1];
		ArrayList<Long> p = new ArrayList<Long>();
		Arrays.fill(prime, true);
		for (long f = 2; f <= N; f++) {
			if (prime[(int)f]) {
				p.add(f);
				for (long next = f*f; next <= N; next+=f) {
					prime[(int)next]=false;
				}
			}
		}
		int[] pref = new int[N+1];
		//for (int i = 2; i <= N; i++) if (prime[i]) p.add(i);
		for (int i = 3; i <= N; i++) {
			pref[i] = pref[i-1];
			if (prime[i]&&prime[(i+1)/2]) pref[i]++;
		}
		int Q = I.nextInt();
		while (Q-->0) {
			int ans = 0;
			int L = I.nextInt();
			int R = I.nextInt();
			L--; //Want to include lower bound just in case L is valid ([3,5] --> ans = 
			//pref[5]-pref[2]
			ans = pref[R]-pref[L];
			O.pln(ans);
		}
	}
	public static void sort(long[] a) {Arrays.sort(a);}
	public static void sort(int[] a) {Arrays.sort(a);}
	public static void sort(String[] a) {Arrays.sort(a);}
	public static void sort(char[] a) {Arrays.sort(a);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(boolean x) {w.println(x);w.flush();}
	}
}


Measured memory_bytes: 66380
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			long[] array = new long[n];
			for (int i = 0; i < n; i++) array[i] = sc.nextLong();
			int times = sc.nextInt();  
			for (int i = 0; i < times; i++) {
				int query = sc.nextInt(); 
				int start = sc.nextInt();
				int end = sc.nextInt();
				switch (query) {
				
				case 0:
					long min = array[start];
					for (int j = start+1; j < end; j++) {
						min = Math.min(min, array[j]);
					}
					System.out.println(min);
					break;

				case 1:
					long max = array[start];
					for (int j = start + 1; j < end; j++) {
						max = Math.max(max,array[j]);
					}
					System.out.println(max);
					break;

				}
			}
		}
	}
}



Measured memory_bytes: 35120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    string S;
    cin >> S;
    int diff = 999;
    for ( int i = 0; i <= S.size() - 3; i++ ) {
        int n = std::stoi(S.substr(i,3));
        int d = abs(n-753);
        if ( diff > d ) {
            diff = d;
        }
    }
    cout << diff << '\n';
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc154/tasks/abc154_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    REP(i, s.length()) { cout << 'x'; }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    char S[4];
    int i,ans=1;

    scanf("%s",S);

    if(S[0] == S[1] && S[0] == S[2]) ans = 0;

    if(ans == 0) printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
package main

// Solution for https://atcoder.jp/contests/abc174/tasks/abc174_e

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}
func (con *contest) main() error {
	var n, k int
	con.Scan(&n, &k)
	a := make([]int, n)
	lo := 1
	hi := 0
	for i := 0; i < n; i++ {
		con.Scan(&a[i])
		if a[i] > hi {
			hi = a[i]
		}
	}
	for lo < hi {
		mid := (lo + hi) / 2
		c := 0
		for i := 0; i < n; i++ {
			c += (a[i] - 1) / mid
		}
		if c <= k {
			hi = mid
		} else if lo == mid {
			lo++
		} else {
			lo = mid
		}
	}
	con.Println((lo + hi) / 2)
	return nil
}


Measured memory_bytes: 5996
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define loop(i, a, b) for(li i=a; i<=b; i++)
#define stuff ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long li;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<li, li> lii;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ii> vii;
typedef vector<lii> vlii;
li mod = 1e9+7;
li expo(li base, li exponent)
{
	li ans=1;
	while(exponent)
	{
		if(exponent&1) ans = (ans*base)%mod;
		base = (base*base)%mod;
		exponent >>= 1;
	}
	return ans;
}
li gcd(li x, li y)
{
	if(y==0) return x;
	return gcd(y, x%y);
}


typedef tree<li, null_type, less<li>,
rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int main()
{
	stuff;
	// #ifndef ONLINE_JUDGE 
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// freopen("error.txt", "w", stderr);
	// #endif

	li n, m;
	cin >> n >> m;
	vector<bool> vis(n+1, 0);
	if(n%2==1)
	{
		li pt=n/2, gap=1, cnt=0;
		while(cnt<m)
		{
			// while(vis[pt]) pt++;
			cout << pt << " " << pt+gap << "\n";
			// vis[pt] = 1; vis[pt+gap] = 1;
			gap+=2;
			pt--;
			cnt++;
		}
	}
	else
	{
		li a=1, b, c, d=n, gap=(n/2)-1, cnt=0;
		while(cnt<m)
		{
			cout << a << " " << a+gap << "\n";
			// vis[pt]=1; vis[pt+gap]=1;
			gap--; 
			cnt++;
			a++;
			if(cnt==m) break;
			cout << d << " " << d-gap << "\n";
			gap--;
			cnt++;
			d--;
			if(cnt==m) break;
		}
	}
	return 0;
}


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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll int dp[101][21];
int main(){
	int n;
	cin >> n;
	REP(i,101) REP(j,21) dp[i][j] = 0;
	REP(i,n-1){
		int t;
		cin >> t;
		if(i == 0){
			dp[1][t] = 1;
			continue;
		}
		REP(j,21){
			int v = j + t;
			int v2 = j - t;
			if(v >= 0 && v <= 20) dp[i+1][v] += dp[i][j];
			if(v2 >= 0 && v2 <= 20) dp[i+1][v2] += dp[i][j];
		}
	}
	int a;
	cin >> a;
	cout << dp[n-1][a] << endl;
}

Measured memory_bytes: 1172
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;
long[(10^^6)*2+50] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

void main()
{
    init();
    auto K = readln.chomp.to!long;
    auto S = readln.chomp;
    auto len = S.length.to!long;

    long x;
    foreach (k; 0..K+1) {
        auto y = comb(len+K, len+k) * pow(25, K-k) % P;
        (x += y) %= P;
    }
    writeln(x);
}

Measured memory_bytes: 35916
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int n,x;cin>>n;
    vector<int> vec(3*n);
    for(int i=0;i<3*n;i++){
        cin>>x;vec[i]=x;
    }
    lint ans=0;
    sort(all(vec),greater<int>());
    for(int i=1;i<2*n;i+=2){
        ans+=vec[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4576
#include <stdio.h>

int main() {
	int a, b, c;
	long long k;
	scanf("%d%d%d%lld", &a, &b, &c, &k);
	
	int res = (k % 2) ? (b-a) : (a-b);
	
	printf("%d", res);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		String ans="";
		ans=String.valueOf(z)+" "+String.valueOf(x)+" "+String.valueOf(y);
		System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <set>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;


int main() {
    char c;
    cin >> c;

    if (isupper(c))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }
}


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<28
#define mk make_pair
using namespace std;
int main(){
  int n,m,t;
  cin>>n>>m>>t;
  vector<pair<int,int> >a[n];
  rep(i,m){
    int q,w,e;
    cin>>q>>w>>e;
    a[q].push_back(mk(w,e));
  }
    priority_queue<P,vector<P>,greater<P> >q;
    int d[n];
    fill(d,d+n,INF);
    q.push(mk(0,t));
    d[t]=0;
    while(!q.empty()){
      P p=q.top();q.pop();
      int v=p.second;
      if(d[v]<p.first)continue;
      for(int i=0;i<a[v].size();i++){
        P ed=a[v][i];
        if(d[ed.first]>d[v]+ed.second){
          d[ed.first]=d[v]+ed.second;
          if(d[ed.first]<-120000)goto L;
          q.push(mk(d[ed.first],ed.first));
        }
      }
    }
  rep(i,n){
    if(d[i]==INF)cout<<"INF"<<endl;
    else cout<<d[i]<<endl;
  }
if(0)L:cout<<"NEGATIVE CYCLE"<<endl;
}

Measured memory_bytes: 4852
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		long a=scan.nextLong();
		long b=scan.nextLong();
		long c=scan.nextLong();
		long d=scan.nextLong();
		System.out.println(Math.max(a*c, Math.max(a*d, Math.max(b*c, b*d))));
		scan.close();
	}

}


Measured memory_bytes: 27116
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int sum_of_digits(int num) {
	int sum = 0;
	while (num) {
		sum += num % 10;
		num /= 10;
	}
	return sum;
}

int main() {

	//入力
	int N, A, B;
	cin >> N >> A >> B;
	int tmp_sum, total = 0;
	for (int i = 1; i <= N; i++) {
		tmp_sum = sum_of_digits(i);
		if (A <= tmp_sum && tmp_sum <= B) {
			total += i;
		}
	}
	cout << total;


	return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace ABC
{
    class ProgramA
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(" ");
            var x = long.Parse(inputs[0]);
            var t = long.Parse(inputs[1]);
            var result = x - t < 0 ? 0 : x-t;
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 27512
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

newtype MyGraph = MyGraph (A.Array Int [Int])

listToGraph :: Int -> [(Int, Int)] -> Bool -> MyGraph
listToGraph n paths inverse = MyGraph $ STA.runSTArray $ do
    a <- MA.newArray (1, n) []
    forM_ paths $ \(from, to) -> do
        f <- MA.readArray a from
        MA.writeArray a from $ to : f
        when inverse $ do 
            t <- MA.readArray a to
            MA.writeArray a to $ from : t
    pure a

getPaths :: Int -> MyGraph -> [Int]
getPaths i (MyGraph lst) = lst A.! i


solve :: Int -> UV.Vector Int -> [(Int, Int)] -> Int
solve n heights paths = let 
    grp = listToGraph n paths True
    isGood i = case getPaths i grp of
        [] -> True
        paths -> let
            mine = heights GV.! (i - 1)
            in
            all ((mine>) . (heights GV.!) . (subtract 1)) paths
    in 
    length $ filter isGood [1..n]

readIntS :: BC.ByteString -> Maybe (Int, BC.ByteString)
readIntS = fmap (BC.tail <$>) . BC.readInt

readIntsV :: Int -> IO (UV.Vector Int)
readIntsV n = UV.unfoldrN n readIntS <$> BC.getLine

readTuple2' :: IO (Int, Int)
readTuple2' = do
    v <- readIntsV 2
    pure (v GV.! 0, v GV.! 1)

main :: IO ()
main = do
    (n, m) <- readTuple2'
    heights <- readIntsV n
    paths <- replicateM m readTuple2
    print $ solve n heights paths





Measured memory_bytes: 46580
import sys
input = sys.stdin.readline
n = int(input())
a = [0]*n
b = [0]*n
c = [0]*n
for i in range(n):
    a[i],b[i],c[i] = map(int,input().split())

dpa = [a[0]]+[0]*(n-1)
dpb = [b[0]]+[0]*(n-1)
dpc = [c[0]]+[0]*(n-1)
for i in range(1,n):
    dpa[i] = max(dpb[i-1],dpc[i-1]) + a[i]
    dpb[i] = max(dpc[i-1],dpa[i-1]) + b[i]
    dpc[i] = max(dpa[i-1],dpb[i-1]) + c[i]
print(max(dpa[-1],dpb[-1],dpc[-1]))


Measured memory_bytes: 27492
n, m, x = map(int, input().split())
min_c = float('inf')
l = []
for i in range(n):
    ns = list(map(int, input().split()))
    l.append(ns)
for i in range(1, 2 ** n):
    flag = True
    a = bin(i)[2:].zfill(n)
    for j in range(m):
        s = 0
        for index, b in enumerate(a):
            if b == '1':
                s += l[index][j+1]
        if s < x:
            flag = False
            break
    if flag:
        min_c = min(min_c, sum(l[i][0] for i in range(n) if a[i] == '1'))
if min_c == float('inf'):
    print(-1)
else:
    print(min_c)

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

bool is_prime(int n){
	if(n<=1) return false;
	for(int i=2;i*i<n;i++){
		if(n%i==0) return false;
	}
 return true;
}
	
int main(){
	bool p[100000];
	p[0]=p[1]=false;
	for(int i=2;i<100000;i++){
		p[i]=true;
	}
	for(int i=2;i*i<100000;i++){
		if(p[i])
			for(int j=i*i;j<100000;j+=i){
				p[j]=false;
			}
	}

	while(1){
		int count=0;
		int N;
		cin>>N;
		if(N==0)
			break;
		for(int i=2;i<(N/2)+1;i++){
			if(p[i]&&p[N-i])
				count++;
		}
		cout<<count<<endl;
	}
	return 0;
}

Measured memory_bytes: 3196
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, W = sc.nextInt()
  val ls = (for (i <- 1 to N) yield (sc.nextInt, sc.nextInt, sc.nextInt)).toList

  type Item = (Int,Int) // (value, Weight)

  def mkItems(t:(Int,Int,Int)):List[Item] = {
    def iter(v:Int, w:Int, m:Int, s:Int, acc:List[Item]):(Int, List[Item]) = {
      if (m > 1) {
        iter(v << 1,w << 1,m >> 1, s << 1, (v, w)::acc)
      } else (s,acc)
    }
    val (v,w,m) = t
    val (s, items) = iter(v, w, m, 1, Nil)
    val k = m - (s -1)
    if (k > 0) (v*k,w*k)::items else items
  }
 
  class DP(num:Int, wgt:Int, items:Array[Item]) {
    val memo = Array.fill(wgt+1)(0)
    override def toString:String = (for (e <- memo) yield f" $e%3d").foldLeft("")(_+_)
    def solver():Int = {
      for (i <- 1 to num) {
        val (v, w) = items(i-1)
        for (j <- wgt to 0 by -1) {
          if (j >= w) {
            val v0 = memo(j)
            val v1 = memo(j-w) + v
            memo(j)= v0 max v1
          }
        }
      }
      memo(wgt)
    }
  }
  
  val items = (for (e <- ls) yield mkItems(e)).flatten.toArray

  val dp = new DP(items.length, W, items)
  println(dp.solver())

}


Measured memory_bytes: 46756
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

ans = 0
for i, b in enumerate(B):
    l = min(A[i], b)
    b -= l
    r = min(A[i + 1], b)
    A[i] -= l
    A[i + 1] -= r

    ans += l + r

print(ans)


Measured memory_bytes: 18624
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define vec(T) vector<T>
using namespace std;
using ull = unsigned long long;
using ll = long long;


int main() {
    int s;
    cin >> s;
    int mae = s / 100;
    int ato = s % 100;
    if(1 <= mae and mae <= 12){
        if(1 <= ato and ato <= 12) printf("AMBIGUOUS\n");
        else puts("MMYY");
    }else{
        if(1 <= ato and ato <= 12) puts("YYMM");
        else puts("NA");
    }
}

Measured memory_bytes: 256
s = input()
k = int(input())
ans = ""
l = 26
for i in range(len(s)-1):
    if l - ord(s[i]) + 97 <= k and s[i] != "a":
        k -= l - ord(s[i]) + 97
        ans += "a"
    else:
        ans += s[i]
ans += (chr(((ord(s[-1]) - 97) + k + l) % l + 97))
print(ans)

Measured memory_bytes: 3444
N = int(input())
A = []
for _ in range(2):
    temp = list(map(int, input().strip().split()))
    A.append(temp)

total = 0

for j in range(N):
    row = 0
    col = 0
    total_temp = 0
    while col < N:
        if col == j:
            total_temp += A[row][col]
            row += 1
        total_temp += A[row][col]
        col += 1
    if total < total_temp:
        total = total_temp

print(total)


Measured memory_bytes: 3060
#include <stdio.h>
int main(void) {
	int a, b;
	scanf("%d %d", &a, &b);

	if (a < b) printf("a < b\n");
	else if (a > b) printf("a > b\n");
	else if (a == b) printf("a == b\n");

	return 0;
}

Measured memory_bytes: 580
#define taskname "test"

#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)x.size()
#define fi first
#define se second

typedef long long lli;
typedef pair<int, int> pii;

const int maxn = 5e5 + 5;
const int inf = 1e9 + 9;

int n, m;
pii segs[maxn];

struct segment_tree
{
    int val[maxn * 4], lazy[maxn * 4];

    void init()
    {
        fill(begin(val), end(val), 0);
        fill(begin(lazy), end(lazy), 0);
    }

    void push(int x)
    {
        if(lazy[x] == 0) return;
        int t = lazy[x];

        lazy[x * 2] = t; val[x * 2] = t;
        lazy[x * 2 + 1] = t; val[x * 2 + 1] = t;

        lazy[x] = 0;
    }

    void update(int x, int l, int r, int L, int R)
    {
        if(L > r || l > R) return;
        if(l >= L && r <= R)
        {
            val[x] = inf;
            lazy[x] = inf;
            return;
        }
        push(x);
        int mid = (l + r) / 2;
        update(x * 2, l, mid, L, R);
        update(x * 2 + 1, mid + 1, r, L, R);
        val[x] = min(val[x * 2], val[x * 2 + 1]);
    }

    void rep(int x, int l, int r, int p, int k)
    {
        if(l == r)
        {
            val[x] = k;
            return;
        }
        push(x);
        int mid = (l + r) / 2;
        if(p <= mid) rep(x * 2, l, mid, p, k);
        else rep(x * 2 + 1, mid + 1, r, p, k);
        val[x] = min(val[x * 2], val[x * 2 + 1]);
    }

    int get(int x, int l, int r, int L, int R)
    {
        if(L > r || l > R) return inf;
        if(l >= L && r <= R)
            return val[x];
        push(x);
        int mid = (l + r) / 2;
        return min(get(x * 2, l, mid, L, R),
                   get(x * 2 + 1, mid + 1, r, L, R));
    }
} tree1, tree2;

void read_input()
{
    cin >> n >> m;
    for(int i = 1; i <= n; ++i)
        cin >> segs[i].fi >> segs[i].se;
}

void solve()
{
    tree1.init(); tree2.init();
    for(int i = 1; i <= m; ++i)
        tree2.rep(1, 1, m, i, -i);
    for(int i = 1; i <= n + 1; ++i)
    {
        if(i > 1)
        {
            int ans = tree1.get(1, 1, m, 1, m);
            if(ans == inf) ans = -1;
            else ans += i - 1;
            cout << ans << '\n';
        }
        if(i == n + 1) break;
        int l = segs[i].fi, r = segs[i].se;
        if(r < m)
        {
            int temp = tree2.get(1, 1, m, l, r);
            int val = tree1.get(1, 1, m, r + 1, r + 1);
            if(val > temp + r + 1)
            {
                tree1.rep(1, 1, m, r + 1, temp + r + 1);
                tree2.rep(1, 1, m, r + 1, temp);
            }
        }
        tree1.update(1, 1, m, l, r);
        tree2.update(1, 1, m, l, r);
    }
}

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



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

#define ll long long
#define mod 100000000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

int main()
{
    int n;
    cin>>n;
    ll ans=0;
    int b[n-1];
    ffor(i,0,n-1) cin>>b[i];
    ans=b[0];
    ffor(i,0,n-2)
    {
        ans+=min(b[i],b[i+1]);
    }
    ans+=b[n-2];
    cout<<ans;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int a,b,c,n;
  while(1){
    cin>>a>>b>>c;
    if(a+b+c==0)break;
    cin>>n;
    vi v(a+b+c,2);
    vi p,q,r;
    rep(i,n){
      int tp,tq,tr,ts;
      cin>>tp>>tq>>tr>>ts;
      tp--;tq--;tr--;
      if(ts){
	v[tp]=v[tq]=v[tr]=1;//ok
      }else{
	p.push_back(tp);
	q.push_back(tq);
	r.push_back(tr);
      }
    }
    rep(i,p.size()){
      if(v[p[i]]==1&&v[q[i]]==1)v[r[i]]=0;
      if(v[p[i]]==1&&v[r[i]]==1)v[q[i]]=0;
      if(v[r[i]]==1&&v[q[i]]==1)v[p[i]]=0;
    }
    rep(i,a+b+c)cout<<v[i]<<endl;
  }
}

Measured memory_bytes: 3124
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    s, t = list(map(str, readline().rstrip().decode('utf-8').split()))
    res = []
    for i in range(n):
        res.append(s[i])
        res.append(t[i])
    print("".join(res))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define READ freopen("in.txt","r",stdin)
#define WRITE freopen("out.txt","w",stdout);
#define pb push_back
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define sf(x) scanf("%d",&x)
#define sf2(x,y) scanf("%d %d",&x,&y)
#define sf3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define sl(x) scanf("%lld",&x)
#define sl2(x,y) scanf("%lld %lld",&x,&y)
#define sl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define sd(x) scanf("%lf",&x);
#define pii pair<int,int>
#define pLL pair<long long,long long>
#define ff first
#define sn second
#define PRINT_CASE  printf("Case %d: ",tc++)
#define mx 100005
#define lnd tree[ind<<1]
#define rnd tree[(ind<<1)+1]
#define cnd tree[ind]
#define lndp b,(b+e)>>1,(ind<<1)
#define rndp ((b+e)>>1)+1,e,(ind<<1)+1
#define IN(a,x,y) (a>=x && a<=y)
typedef long long ll;
typedef long long int lln;
ll INF=1<<28;
//typedef long long lld;
const double pi=acos(-1.0);
int fx[]={1,-1,0,0}; //direction array
int fy[]={0,0,1,-1};
int dir[4][2]={1,0,-1,0,0,-1,0,1};
const long double EPS=1e-7;
//#define INF 10000
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
ll lcm(ll a,ll b)
{
    return a/gcd(a,b)*b;
}

bool cmp(int a, int b)
{
    return a<b;
}

struct compare
{
  bool operator()(const int& l, const int& r)
  {
      return l>r;
  }
};
bool cmp1(int a,int b)
{
    return a>b;
}
struct Point
{
    int x, y;
};
int mod=1e8+7;
int Coins[3010],n,m,color;
bitset<4000005>vis,tmp;
int main()
{
//    READ;
//    WRITE;
    int t,tc=1;
    ll x,y;
    int c;
    sf(n);
    int summ=0;
    for(int i=0;i<n;i++)
    {
        sf(Coins[i]);
        summ+=Coins[i];
    }
    int median=(summ+1)/2;
    color=1;
    vis[0]=1;
    int sizee=1;
    int j;
    for(int i=0;i<n;i++)
    {
        vis|=vis<<Coins[i];
    }
    for(int i=median;i<=summ;i++)
    {
        if(vis[i])
        {
            printf("%d\n",i);
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 1664
import math
def resolve():
    A, B, H, M = map(int, input().split())
    theta = 30*(H+(M/60)) - (6*M)
    cosine = math.cos(math.radians(theta))
    c = math.sqrt((A**2)+(B**2)-(2*A*B*cosine))
    print(c)

if __name__ == '__main__':
    resolve()

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

int ok[100005];

bool _ok(int x) { return x >= 0 ? ok[x] : 0; }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ok[0] = 1;
    for (int i = 1; i <= 100000; i++) {
        ok[i] = _ok(i - 100) || _ok(i - 101) || _ok(i - 102) || _ok(i - 103) || _ok(i - 104) || _ok(i - 105);
    }
    int x;
    cin >> x;
    cout << ok[x] << endl;
}

Measured memory_bytes: 640
n, k = map(int, input().split())
h = [0] + list(map(int, input().split())) + [0]
inf = 10 ** 13
dp = [[0] * (k + 1)]
for i in range(1, n + 2):
    dp.append([inf] * (k + 1))
    for j in range(i):
        for u in range(i - j - 1, k + 1):
            dp[-1][u] = min(dp[-1][u], dp[j][u - i + j + 1] + max(h[i] - h[j], 0))
print(min(dp[-1]))


Measured memory_bytes: 74336
while True:
    try:
        s=str(input())
        JOI=0
        IOI=0
        for i in range(len(s)-2):
            if s[i]=="J" and s[i+1]=="O" and s[i+2]=="I":
                JOI+= 1
            elif s[i] =="I" and s[i+1]=="O" and s[i+2]=="I":
                IOI+= 1
        print(JOI)
        print(IOI)
    except:
        break


Measured memory_bytes: 5568
#include<iostream>
#include<cmath>

using namespace std;














int main(){

  int a=0,b=0;
  double x = 0.0;
  double ans=0.0;
  int y=0;

  cin >> a >> b;
  
   x = 0.5*(a+b);


   ans = ceil(x);
   y = ans*1;

   cout << y ;



    return 0;
}

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

int main(){
    long long n,m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i=0; i<m; i++){
        cin >> a.at(i);
    }
    long long sum=0;
    for (int i=0; i<m; i++){
        sum += a.at(i);
    }
    if(sum<=n){
        cout << n-sum;
    }
    else cout << -1;
    return 0;
}

Measured memory_bytes: 3644
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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


signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n,q; cin >> n >> q;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    fenwick_tree<ll> seg(n);
    rep(i,0,n){
        seg.add(i, a[i]);
    }
    rep(i,0,q){
        ll t,a,b; cin >> t >> a >> b;
        if(t == 0){
            seg.add(a, b);
        }
        else{
            cout << seg.sum(a, b) << "\n";
        }
    }
}

Measured memory_bytes: 12116
N = int(input())
A = list(int(i) for i in input().split())

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
    print(min_HP)
else:
    min_HP = A[1] - A[0]
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

    # そのループでまだmin_HPが更新されていない
    while(True):
        min_flag = False
        for a in A:
            if ((a % min_HP) < min_HP and (a % min_HP) > 0):
                min_HP = a % min_HP
                min_flag = True
        if( min_HP > 0 and min_flag ):
            continue
        else:
            break
    print(min_HP)

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

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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; }

ll n,result;
string s;
int main() {
    INIT();

    cin >> n;
    vector<ll> vec(n+1);
    for(ll i = 1; i <= n; i++) {
        cin >> vec[i];
    }
    for(ll i = 1; i <= n; i++) {
        if(i % 2 == 1 && vec[i] % 2 == 1) result++;
    }
    cout << fixed << result;
}

Measured memory_bytes: 3644
#include <stdio.h>
int main() 
{
	int n;
	scanf("%d",&n);
	if(n<1200)
	{
	    printf("ABC\n");
	}
	else if(n<2800)
	{
	    printf("ARC\n");
	}
	else
	{
	    printf("AGC\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>

using namespace std;

const int N = 100;
int a[N];

int main() {
	::ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	int diff = sum + 1000;
	int best = -1;
	for (int i = 0; i < n; ++i) {
		if (abs(sum - a[i] * n) < diff) {
			diff = abs(sum - a[i] * n);
			best = i;
		}
	}
	cout << best << endl;

	return 0;
}


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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n); 0<=i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());                   //昇順
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());    //降順
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper); 
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);
#define SetPre(x) setprecision(x)

int main(void){
    ll a;
    cin >> a;
    cout << a+a*a+a*a*a;
    
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int n;
	int count = 1;
	while(scanf("%d",&n)){
		if(n == 0){
			break;
		}
		if(n == 1){
			printf("Case %d:\n",count);
			count++;
			printf("  1\n");
		}
		if(n == 2){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2\n");
			printf("  3  4\n");
		}
		if(n == 3){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6\n");
			printf("  3  5  7\n");
			printf("  4  8  9\n");
		}
		if(n == 4){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7\n");
			printf("  3  5  8 13\n");
			printf("  4  9 12 14\n");
			printf(" 10 11 15 16\n");
		}
		if(n == 5){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7 15\n");
			printf("  3  5  8 14 16\n");
			printf("  4  9 13 17 22\n");
			printf(" 10 12 18 21 23\n");
			printf(" 11 19 20 24 25\n");
		}
		if(n == 6){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7 15 16\n");
			printf("  3  5  8 14 17 26\n");
			printf("  4  9 13 18 25 27\n");
			printf(" 10 12 19 24 28 33\n");
			printf(" 11 20 23 29 32 34\n");
			printf(" 21 22 30 31 35 36\n");
		}
		if(n == 7){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7 15 16 28\n");
			printf("  3  5  8 14 17 27 29\n");
			printf("  4  9 13 18 26 30 39\n");
			printf(" 10 12 19 25 31 38 40\n");
			printf(" 11 20 24 32 37 41 46\n");
			printf(" 21 23 33 36 42 45 47\n");
			printf(" 22 34 35 43 44 48 49\n");
		}
		if(n == 8){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7 15 16 28 29\n");
			printf("  3  5  8 14 17 27 30 43\n");
			printf("  4  9 13 18 26 31 42 44\n");
			printf(" 10 12 19 25 32 41 45 54\n");
			printf(" 11 20 24 33 40 46 53 55\n");
			printf(" 21 23 34 39 47 52 56 61\n");
			printf(" 22 35 38 48 51 57 60 62\n");
			printf(" 36 37 49 50 58 59 63 64\n");
		}
		if(n == 9){
			printf("Case %d:\n",count);
			count++;
			printf("  1  2  6  7 15 16 28 29 45\n");
			printf("  3  5  8 14 17 27 30 44 46\n");
			printf("  4  9 13 18 26 31 43 47 60\n");
			printf(" 10 12 19 25 32 42 48 59 61\n");
			printf(" 11 20 24 33 41 49 58 62 71\n");
			printf(" 21 23 34 40 50 57 63 70 72\n");
			printf(" 22 35 39 51 56 64 69 73 78\n");
			printf(" 36 38 52 55 65 68 74 77 79\n");
			printf(" 37 53 54 66 67 75 76 80 81\n");
		}
	}
	return 0;
}

Measured memory_bytes: 612
import sys,bisect

from sys  import stdin,stdout

from bisect import bisect_left,bisect_right,bisect,insort,insort_left,insort_right

from math import gcd,ceil,floor,sqrt

from collections import Counter,defaultdict,deque,OrderedDict

from queue import Queue,PriorityQueue

from string import ascii_lowercase


sys.setrecursionlimit(10**6)
INF = float('inf')
MOD = 998244353
mod = 10**9+7

def isPrime(n):
    if (n <= 1) :return False
    if (n <= 3) :return True
    if (n%2 == 0 or n%3 == 0):return False
    for i in range(5,ceil(sqrt(n))+1,6):
        if (n%i==0 or n%(i+2)==0):
            return False
    return True

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")
    
def DFS(dictionary,vertex,visited):
    visited[vertex]=True
    stack=[vertex]
    print(vertex)
    while stack:
        a=stack.pop()
        for i in dictionary[a]:
            if not visited[i]:
                print(i)
                visited[i]=True
                stack.append(i)


def BFS(dictionary, vertex,visited):
    visited[vertex]=True
    q=deque()
    q.append(vertex)
    while q:
        a=q.popleft()
        for i in dictionary[a]:
            if not visited[i]:
                visited[i]=True
                q.append(i)
                print(i)

                


def soe(limit):
    l=[1]*(limit+1)
    l[0]=0
    l[1]=0
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0
    
    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)
                
def gcd(a,b):
    while b:
        a=a%b
        b,a=a,b
    return a

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r
            
    
def solve():
    s=input().split()
    if s[1]=='+':
        pr(int(s[0])+int(s[2]))
    else:
        pr(int(s[0])-int(s[2]))



for _ in range(1):
    solve()
    


Measured memory_bytes: 10168
import itertools


N = int(input())

ans = 0
flags = [0 for _ in range(N)]
for idx, p in enumerate(map(int, input().split())):
    if idx + 1 == p:
        flags[idx] = 1

for key, elems in itertools.groupby(flags):
    elems = list(elems)
    len_elems = len(elems)
    if key == 1:
        if len_elems == 1:
            ans += 1
        else:
            ans += (len_elems + 1) // 2

print(ans)


Measured memory_bytes: 57392
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
typedef std::pair<LL, LL> P;
struct edge { LL to, cost; };

const LL inf = 11234567890123;
LL N, M;
std::map<LL, LL>dist;
std::map<LL, std::vector<edge>>G;

void dijkstra(LL s)
{
	std::priority_queue<P, std::vector<P>, std::greater<P>>que;
	for (auto i : G) dist[i.first] = inf;
	dist[s] = 0;
	que.push(P(0, s));
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;
		if (dist[v] < p.first) { continue; }
		rep(i, G[v].size())
		{
			edge e = G[v][i];
			if (dist[e.to] > dist[v] + e.cost)
			{
				dist[e.to] = dist[v] + e.cost;
				que.push(P(dist[e.to], e.to));
			}
		}
	}
}

int main()
{
	in >> N >> M;
	std::vector<LL>p(M), q(M), c(M);
	rep(i, M)
	{
		in >> p[i] >> q[i] >> c[i];
		G[p[i] + c[i] * N].push_back({ q[i] + c[i] * N,0 });
		G[q[i] + c[i] * N].push_back({ p[i] + c[i] * N,0 });
		G[p[i]].push_back({ p[i] + c[i] * N ,1 });
		G[p[i] + c[i] * N].push_back({ p[i] ,0 });
		G[q[i]].push_back({ q[i] + c[i] * N ,1 });
		G[q[i] + c[i] * N].push_back({ q[i] ,0 });
	}
	dist[N] = inf;
	dijkstra(1);
	out << (dist[N] >= inf ? -1 : dist[N]) << std::endl;
	return 0;
}


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

#define ll long long
#define scl(n) scanf("%lld",&n)
#define scd(n) scanf("%d",&n)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

ll ara[200005];

int main()
{
    ll n,m,i,j,k,a,b,c,x,y,z;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        scl(ara[i]);
    }
    sort(ara+1,ara+n+1);
    z=n-m;
    k=0;
    for(j=z;j>0;j--)
    {
        k+=ara[j];
    }
    cout<<k<<endl;


    return 0;
}



Measured memory_bytes: 1792
k = gets.to_i

inf = 10**9
d = Array.new(k, inf)

d[1] = 1
q = [1]
while q.size != 0
  x = q.shift
  
  y = x*10%k
  if d[y] > d[x]
    d[y] = d[x]
    q.unshift(y)
  end
  
  z = (x+1)%k
  if d[z] > d[x]+1
    d[z] = d[x]+1
    q.push(z)
  end
end

p d[0]


Measured memory_bytes: 3964