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

public class Main {
    static MyReader in = new MyReader();

    public static void main(String[] args) {
        int N = in.i();
        int[] L = in.ii(2 * N);
        Arrays.sort(L);
        int ans = 0;
        for (int i = 0; i < L.length; i += 2) {
            ans += L[i];
        }
        System.out.println(ans);
    }
}

class MyReader extends BufferedReader {
    char[] cbuf = new char[1024];
    int head = 0;
    int tail = 0;

    MyReader() {
        super(new InputStreamReader(System.in));
    }

    char next() {
        if (head == tail) {
            try {
                tail = super.read(cbuf, 0, cbuf.length);
            } catch (IOException e) {
                e.printStackTrace();
            }
            head = 0;
        }
        return cbuf[head++];
    }

    int i() {
        int k = next() - '0';
        boolean minus = k == -3;
        int n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    int[] ii(final int N) {
        int[] a = new int[N];
        for (int j = 0; j < a.length; j++) a[j] = i();
        return a;
    }

    long l() {
        int k = next() - '0';
        boolean minus = k == -3;
        long n = minus ? 0 : k;
        while (0 <= (k = next() - '0') && k <= 9) n = 10 * n + k;
        return minus ? -n : n;
    }

    char[] s(final int N) {
        char[] s = new char[N];
        for (int i = 0; i < N; i++) {
            s[i] = next();
        }
        next();
        return s;
    }

    public int read(char[] cbuf) {
        int i;
        char c;
        for (i = 0; (c = next()) != ' ' && c != '\n'; i++) cbuf[i] = c;
        return i;
    }

    public String readLine() {
        try {
            return super.readLine();
        } catch (IOException e) {
            return null;
        }
    }
}


Measured memory_bytes: 32472
#include<bits/stdc++.h>
using namespace std; 
#define mod 1000000007
#define INF 0x3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n" 
#define pb push_back
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define mp make_pair
#define print(v); for(auto x:v) cout<<x<<" "; cout<<endl;
typedef long long int ll;
int main()
{
    fast;
    string s;
    cin >> s;
    string t;
    cin >> t;
    ll len = s.length();
    string s2 = t.substr(0, len);
    // cout << "s2: " << s2 << endl;
    if(s == s2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3660
use std::collections::VecDeque;
use std::io::Read;
use std::iter::FromIterator;
use std::string::String;
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut it = buf.split_whitespace();
    let s = it.next().unwrap();
    let q = it.next().unwrap().parse::<i64>().unwrap();
    let mut reversed = false;

    let mut deque = VecDeque::<char>::from_iter(s.chars());

    for _ in 0..q {
        let query = it.next().unwrap().parse::<i64>().unwrap();
        if query == 1 {
            reversed = !reversed;
        } else if query == 2 {
            let f = it.next().unwrap().parse::<i64>().unwrap();
            let c = it.next().unwrap().chars().next().unwrap();
            let push_front = if f == 1 { !reversed } else { reversed };
            if push_front {
                deque.push_front(c);
            } else {
                deque.push_back(c);
            }
        }
    }
    if reversed {
        let out = deque.iter().rev();
        let mut s = String::new();
        s.extend(out);
        println!("{}", s);
    } else {
        let out = deque.iter();
        let mut s = String::new();
        s.extend(out);
        println!("{}", s);
    }
}


Measured memory_bytes: 10492
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <float.h>

#include <cstdio>
#include <iomanip>


using namespace std;
typedef long long ll;
#define loop(i, N) for(int i=0; i<N; ++i)


int main(void) {
	int n;
	cin >> n;
	double a[110];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	long double sum = 0.000000000;
	for (int i = 0; i < n; i++)
	{
		sum += 1.00000000000 / (long double)a[i];
	}
	cout << std::fixed << std::setprecision(10) << 1.0/sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;


#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back

int main(){
    ll n; cin >> n;
    vector<ll> v(n);
    rep(i,n) cin >> v.at(i);
    cout << *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()) << endl;
}

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

signed main(void)
{
	int n;
	cin >> n;
	while(n)
	{
		if (n % 10 == 9)
		{
			cout << "Yes" << endl;
			return 0;
		}
		n /= 10;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
//   HVARDHANSINGH   //
 
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
 
#define ll      long long
#define F       first
#define S       second
#define endl    "\n"

const ll M =    200006;
const int mod = 1000000007;

vector<int> vis(M,0);
vector<int> adj[M];
vector<int> cnt(M,0);

void dfs(int i, vector<int> &tr)
{
	vis[i] = 1;
	cnt[i] = 1;
	tr.push_back(i);
	
	for(auto x:adj[i])
	{
		if(!vis[x])
		{
			dfs(x, tr);
			cnt[i]+= cnt[x];
		}
	}
}

void solve()
{
	int n;	cin>>n;
	int q;	cin>>q;
	
	for(int i=0; i<n-1; i++)
	{
		int u,v;	cin>>u>>v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	
	vector<int> tr;
	
	dfs(1,tr);
	
	unordered_map< int,int > mp;
	
	for(int i=0; i<n; i++)	mp[tr[i]] = i;
	
	vector<ll> tmp(n+1,0);
	
	for(int i=0; i<q; i++)
	{
		ll p,x;	cin>>p>>x;
		
		int idx = mp[p];
		
		tmp[idx]+= x;
		tmp[idx+cnt[p]]-= x;
	}
	for(int i=1; i<n; i++)
	{
		tmp[i]+= tmp[i-1];
	}
	
	vector<ll> ans(n+1);
	
	for(int i=0; i<n; i++)
	{
		ans[tr[i]] = tmp[i];
	}
	
	for(int i=1; i<=n; i++)	cout<<ans[i]<<" ";
	
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}


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

#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++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

#define MOD 1000000007

using namespace std;

ll add(ll a, ll b) {
    return ((a % MOD) + (b % MOD)) % MOD;
}

string s;
ll n;

ll DP[100010][14];

ll solve(int i, int mod) {
    if(i >= n){
        return mod == 5;
    }

    if(DP[i][mod] != -1) return DP[i][mod];

    ll res = 0;
    if(s[i] == '?') {
        int tmp;
        for(int j = 0; j < 10; j++) {
            tmp = ((10 * mod) + j) % 13;
            res = add(res, solve(i+1, tmp));
        }
    }else {
        res = solve(i+1, ((10 * mod) + s[i] - '0') % 13);
    }
    return DP[i][mod] = res;
}

int main() {
    ios_base::sync_with_stdio(false);
    memset(DP, -1, sizeof DP);

    cin >> s;
    n = s.size();

    ll ans = solve(0,0);
    cout << ans << endl;
}


Measured memory_bytes: 19280
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define IOS ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
#define ff first
#define ss second
#define pb push_back
#define debug(val) cerr << "The value of " << #val << " is = " << val << '\n';
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 0x3f3f3f3f;
const ll mininf = -922337203685477;
const ll nax = 1e5+5;
ll n, m, maks=-1, mins=inf;
	
int main(){
	IOS
	cin >> n >> m;
	for(int i=0;i<m;i++){
		ll l, r;
		cin >> l >> r;
		mins=min(mins, r);
		maks=max(maks, l);
	}
	ll temp=mins-maks+1;
	if(temp<0){
		cout << 0 << '\n';
	}
	else{
		cout << temp << '\n';
	}
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <deque>
#include <stack>
using namespace std;
struct pp
{
	long long time,dead;
};
bool comp(pp a,pp b)
{
	return a.dead<b.dead;
}
int main()
{
	//freopen("input.txt", "r", stdin); /*freopen("output.txt","w",stdout);*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin>>n;
	long long a,b;
	int sum=0;
	bool res=1;
	pp arr[n];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i].time>>arr[i].dead;
	}
	sort(arr,arr+n,comp);
	for(int i=0;i<n;i++)
	{
		
		sum+=arr[i].time;
		
		if(sum>arr[i].dead)
		res=0;
		//cout<<sum<<" "<<arr[i].dead<<" "<<res<<endl;
	}
	if(res)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
	string s, t;
	cin >> s >> t;
    int ans = 0;
    rep(i, 3) {
        if (s[i] == t[i]) ++ans;
    }
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

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

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var A, B, C int

func main() {
	sc.Split(bufio.ScanWords)
	A, B, C = nextInt(), nextInt(), nextInt()

	pfsA := PrimeFactors(A + B)
	pfsB := PrimeFactors(B + C)
	pfsC := PrimeFactors(C + A)

	if A%2 == 1 || B%2 == 1 || C%2 == 1 {
		fmt.Println(0)
		return
	}

	if A == B && B == C {
		fmt.Println(-1)
		return
	}

	if A%2 == 1 || B%2 == 1 || C%2 == 1 {
		fmt.Println(0)
		return
	}

	var a2, b2, c2 int
	for _, p := range pfsA {
		if p == 2 {
			a2++
		}
	}

	for _, p := range pfsB {
		if p == 2 {
			b2++
		}
	}

	for _, p := range pfsC {
		if p == 2 {
			c2++
		}
	}

	fmt.Println(minInt(a2, minInt(b2, c2)))
}


Measured memory_bytes: 640
#include<stdio.h>

int main(void)
{
  int i,num[100],a,j;

  scanf("%d",&a);

  for(i=0;i<a;i++){
    scanf("%d",&num[i]);
  }
  for(j=a-1;j>=0;j--){
    if(j>0&&j<=a-1){
      printf("%d ",num[j]);
    }
    else{
      printf("%d\n",num[0]);
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(NULL);
inline void IO() {
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
}

int main(int argc, char const *argv[])
{
	//IO();
	FAST_IO
	
	ll a; cin >> a;
	cout << a + (a*a) + (a*a*a);		
	return 0;
}

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

int main(){
  
  string S;
  cin >> S ;
  
  if (S == "Sunny") cout << "Cloudy" << endl;
   
  else if (S == "Cloudy") cout << "Rainy" << endl;
  
  else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    int n, m;
    map<string, int> ma;

    cin >> n;
    rep(i, n) {
        string s;
        cin >> s;
        ma[s]++;
    }

    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        ma[s]--;
    }

    int ans = 0;
    for (auto a : ma) ans = max(ans, a.second);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>

long long n,m,x[100000],y[100000];

int main(void){
    scanf("%lld%lld",&n,&m);
    for(int i = 0;i < n;i++)
        scanf("%lld",&x[i]);
    for(int i = 0;i < m;i++)
        scanf("%lld",&y[i]);

    long long n2,m2;

    n2 = (-1) * n;m2 = m * (-1);n2++;m2++;

    long long xx = 0,yy = 0;

    for(int i = 0;i < n;i++){
        xx += n2 * x[i] % 1000000007;
        xx %= 1000000007;
        n2 += 2;
    }
    for(int i = 0;i < m;i++){
        yy += m2 * y[i] % 1000000007;
        yy %= 1000000007;
        m2 += 2;
    }
    printf("%lld\n",xx * yy % 1000000007);
    return 0;
}

Measured memory_bytes: 1664
from math import factorial

n, a, b = map(int, input().split(" "));
v = list(map(int, input().split(" ")))

def product(iterable):
    prod = 1
    for n in iterable:
        prod *= n
    return prod

def npr(n, r):
    return product(range(n - r + 1, n + 1))

def ncr(n, r):
    if r > n // 2:
        r = n - r
    return npr(n, r) // factorial(r)

v.sort();
revv=list(reversed(v))
print(sum(v[-a:])/a)
revpos=revv.index(v[-a]);
num=v.count(v[-a]);
ans=0
if v[-1] == v[-a] == v[-a-1]:
    for i in range(a-revpos, b-revpos+1):
        if i > num:
            continue;
        ans+=ncr(num, i);
    print(ans);    
else:
    print(ncr(num,a-revpos));


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int n,k;
    cin>>n>>k;
    int a[n],dp[n+1]={0};
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
    {
        int mn=1e18;
        for(int j=max(0ll,i-k);j<i;j++)
        {
            mn=min(mn,abs(a[j]-a[i])+dp[j]);
        }
        dp[i]=mn;
    }
    cout<<dp[n-1];
}

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

#define LL long long
#define LD long double
#define SC(t,x) static_cast<t>(x)
#define AR(t) vector < t >
#define PII pair < int, int >
#define PLL pair < LL, LL >
#define PIL pair < int, LL >
#define PLI pair < LL, int >
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define PRF first
#define PRS second
#define INIT(ar,val) memset ( ar, val, sizeof ( ar ) )
#define lp(loop,start,end) for ( int loop = start; loop < end; ++loop )
#define lpd(loop,start,end) for ( int loop = start; loop > end; --loop )
#define lpi(loop,start,end) for ( int loop = start; loop <= end; ++loop )
#define lpdi(loop,start,end) for ( int loop = start; loop >= end; --loop )
#define qmax(a,b) (((a)>(b))?(a):(b))
#define qmin(a,b) (((a)<(b))?(a):(b))
#define qabs(a) (((a)>=0)?(a):(-(a)))

const int INF = 0x3fffffff;
const int SINF = 0x7fffffff;
const long long LINF = 0x3fffffffffffffff;
const long long SLINF = 0x7fffffffffffffff;
const int MAXN = 300007;

int n, L, L2;
int a[MAXN];
int t[MAXN];
LL v[MAXN], vl[MAXN], vr[MAXN];
int st[MAXN];

void init ();
void input ();
void work ();

inline LL getval ( int x )
{
	return ( x > 0 ) ? ( ( SC ( LL, x ) + L2 - 1 ) / L2 * L2 ) : 0;
}



int main ()
{
	init ();
	input ();
	work ();
}



void init ()
{
	// Init Everything Here

	ios::sync_with_stdio ( false );
}

void input ()
{
	// input method

	scanf ( "%d%d", &n, &L );
	lpi ( i, 1, n ) scanf ( "%d", &a[i] );
	lpi ( i, 1, n ) scanf ( "%d", &t[i] );
}

void work ()
{
	// main work
	
	L2 = L << 1;

	lpi ( i, 1, n ) v[i] = getval ( t[i] ), vl[i] = getval ( t[i] - ( a[i] << 1 ) ) + ( a[i] << 1 ), vr[i] = getval ( t[i] - ( ( L - a[i] ) << 1 ) ) + ( ( L - a[i] ) << 1 );
	
	LL ans = SC ( LL, a[n] << 1 ) + vr[n];
	--n;
	lpi ( i, 1, n ) ans += v[i];
	
	int s3 = 0;
	lpi ( i, 1, n ){
		if ( vl[i] < v[i] ) st[i] |= 1;
		if ( vr[i] < v[i] ) st[i] |= 2;
		if ( st[i] == 3 ) ++s3;
	}
	
	int cc = 0;
	int bc = 0;
	lpi ( i, 1, n ){
		if ( st[i] == 1 ) ++cc;
		if ( st[i] == 3 ){
			if ( cc ) --cc, ++bc;
		}
	}
	cc = 0;
	lpd ( i, n, 0 ){
		if ( st[i] == 2 ) ++cc;
		if ( st[i] == 3 ){
			if ( cc ) --cc, ++bc;
		}
	}
	
	bc += ( s3 - bc ) >> 1;
	cout << ( ans - SC ( LL, bc ) * L2 ) << endl;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<20)
#define MAX_V 15

int V, E, d[MAX_V][MAX_V], dp[1<<MAX_V][MAX_V][MAX_V];

int rec(int bit, int u, int v){
    
    if(dp[bit][u][v] != -1) return dp[bit][u][v];
    
    if(bit == (1<<u)) return dp[bit][u][v] = 0;
    
    int res = INF;
    int prev_bit = bit & ~(1<<v);
    
    for(int v0 = 0; v0 < V; v0++){
        if(!(prev_bit & (1<<v0))) continue;
        res = min(res, rec(prev_bit, u, v0) + d[v0][v]);
    }
    
    return dp[bit][u][v] = res;
}

int main(){
    for(int i = 0; i < MAX_V; i++)
        fill(d[i], d[i] + MAX_V, INF);
    for(int i = 0; i < (1<<MAX_V); i++)
        for(int j = 0; j < MAX_V; j++)
            fill(dp[i][j], dp[i][j] + MAX_V, -1);
    cin >> V >> E;
    for(int i = 0; i < E; i++){
        int u, v, x;
        cin >> u >> v >> x;
        d[u][v] = x;
    }
    int res = INF;
    for(int u = 0; u < V; u++)
        for(int v = 0; v < V; v++){
            if(u == v) continue;
            res = min(res, rec((1<<V) - 1, u, v) + d[v][u]);
        }
    
    cout << (res >= INF ? -1 : res) << endl;
    
    return 0;
}


Measured memory_bytes: 31904
import java.util.*;

public class Main {

    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int A = sc.nextInt();
    	int B = sc.nextInt();

    	System.out.println(Math.min(A*N, B));
   	}
}


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


//wierd debugging stuff
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << "\n" ; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
//end of weird debugging stuff
using ll = long long;
using vi = vector<int>;
using ii = pair<int,int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()
 
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define ar array
// no change 

const ll MOD = 1e9+7;   // it is an prime...

template<typename T,typename L>
T power(T a, L b);				// to find reverse modulo its power(a,MOD-2);
template < typename T ,typename L> 
L coefficient(T n, T k);  // computing nCk

//const int MxN = 1e9+5;

int main() {
	FASTER;
		int n;
		cin >> n;
		
		cout<< (n%1000 == 0? 0 : 1000 - n%1000);
}


template<typename T,typename L>
T power(T a, L b){
	
	T result = 1;
	while(b){
		if(b&1) result = (result% MOD * a%MOD) % MOD;
	   	a = (a%MOD * a%MOD) % MOD;
   		b/=2;	   
	}
	return result;
}

template < typename T ,typename L> 
L coefficient(T n, T k){  // computing nCk
	k = min(k,(n-k));
	L res = 1;
	for(T i = 0; i< k;i++){
		res *= (n-i);
		res /= (i+1);

	}
	return res;
}



Measured memory_bytes: 3648
// Membership Management
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			String[][] data = new String[n][];
			for (int i = 0; i < n; i++)
				data[i] = scanner.next().replace(".", "").split("[:,]");
			Queue<Integer> queue = new LinkedList<Integer>();
			Set<String> result = new HashSet<String>();
			boolean[] visited = new boolean[n];
			Arrays.fill(visited, false);
			queue.add(0);
			visited[0] = true;
			while (!queue.isEmpty()) {
				int group = queue.poll();
				out: for (int i = 1; i < data[group].length; i++) {
					for (int j = 0; j < n; j++) {
						if (data[j][0].equals(data[group][i])) {
							if (!visited[j]) {
								visited[j] = true;
								queue.add(j);
							}
							continue out;
						}
					}
					result.add(data[group][i]);
				}
			}
			System.out.println(result.size());
		}
		scanner.close();
	}
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
#define prev PREV
#define next NEXT
                         
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

#define filename ""

int n;
int m;
int cnt[26];
string s[100];

int main () {
	cin >> n >> m;
	for (int i = 0; i < n; i++) cin >> s[i];
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++)
			cnt[s[i][j] - 'a']++;
	int ok = 1;
	if (n % 2 == 1 && m % 2 == 1) {
		vi v;
		for (int i = 0; i < 26; i++)
			if (cnt[i] % 2 == 1)
				v.pb (i);
		if (sz (v) != 1)
			ok = 0;
		else {
			cnt[v[0]]--;
			int rem = n / 2 + m / 2;
			v.clear ();
			for (int i = 0; i < 26; i++)
				if (cnt[i] % 4 == 2)
					v.pb (i);
			if (sz (v) > rem)
				ok = 0;
			else {
				rem -= sz (v);
				if (rem % 2 != 0)
					ok = 0;
			}	
		}	
	} else
	if (n % 2 == 0 && m % 2 == 0) {
		for (int i = 0; i < 26; i++)
			ok &= int (cnt[i] % 4 == 0);
	} else {
		if (n % 2 == 0) swap (n, m);
		vi v;
		for (int i = 0; i < 26; i++)
			if (cnt[i] % 2 == 1)
				v.pb (i);
		if (sz (v) != 0)
			ok = 0;
		else {
			int rem = m / 2;
			v.clear ();
			for (int i = 0; i < 26; i++)
				if (cnt[i] % 4 == 2)
					v.pb (i);
			if (sz (v) > rem)
				ok = 0;
			else {
				rem -= sz (v);
				if (rem % 2 != 0)
					ok = 0;
			}
		}
	}
	if (ok) printf ("Yes\n"); else printf ("No\n");
	return 0;
}


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

int main(){
    int a;
    
    int b;
    
    int c;
    
    cin >> a >> b >> c;
    
    if(a > b){
        if(b > c){
            cout << c << " " << b << " " << a <<endl;            
        }else if (a > c){
            cout << b << " " << c << " " << a <<endl;
        }else{
            cout << b << " " << a << " " << c <<endl;  
        }
    } else {
         if(a > c){
            cout << c << " " << a << " " << b <<endl;            
        }else if (b > c){
            cout << a << " " << c << " " << b <<endl;
        }else{
            cout << a << " " << b << " " << c <<endl;  
        }
    }
return 0;
}


Measured memory_bytes: 3100
n, k = map(int,input().split())
A = list(map(int, input().split()))
mod = 10**9+7

if n == 1:
    print(0)
    exit()

ans = 0
for i in range(n-1):
    for j in range(i, n):
        if A[i] < A[j]:
            ans += (k-1)*k//2
        elif A[i] > A[j]:
            ans += k*(k+1)//2
        else:
            pass
        ans %= mod
print(ans)


Measured memory_bytes: 70484
import java.util.*;
public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n = Integer.parseInt(scan.next());
		int m = Integer.parseInt(scan.next());
		long ans =1;
		if (Math.abs(n-m)>1){
			System.out.print(0);
		}else{
			if (n==m)ans=2;
			while(n!=1 || m !=1){
				ans*=n;
				ans%=1000000007;
				ans*=m;
				ans%=1000000007;

				n=Math.max(1, n-1);
				m=Math.max(1, m-1);
			}
			System.out.print(ans);

		}



	}
}
//end


Measured memory_bytes: 22612
A = int(input())
B = int(input())
C = int(input())
X = int(input())
L = []
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if 500*a + 100*b + 50*c == X:
                L.append((a,b,c))
print(len(L))





Measured memory_bytes: 9064
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template <typename T>
vector<T> dijkstra(int s,vector< vector< pair<int, T> > > & G){
  const T INF = numeric_limits<T>::max();
  using P = pair<T, int>;
  int n=G.size();
  vector<T> ds(n,INF);
  vector<int> bs(n,-1);
  priority_queue<P, vector<P>, greater<P> > pq;
  ds[s]=0;
  pq.emplace(ds[s],s);
  while(!pq.empty()){
    P p=pq.top();pq.pop();
    int v=p.second;
    if(ds[v]<p.first) continue;
    for(auto& e:G[v]){
      int u=e.first;
      T c=e.second;
      if(ds[u]>ds[v]+c){
        ds[u]=ds[v]+c;
        bs[u]=v;
        pq.emplace(ds[u],u);
      }
    }
  }
  return ds;
}
signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int N,M; cin >> N >> M;
    vvc<pi> G(3*N+1);
    rep(i,M){
        int a,b; cin >> a >> b;
        a--; b--;
        G[a].eb(b+N,1);
        G[a+N].eb(b+2*N,1);
        G[a+2*N].eb(b,1);
    }
    int s,t; cin >> s >> t;
    s--; t--;
    int a=dijkstra(s,G)[t];
    if(a==numeric_limits<int>::max() || a%3!=0) cout << -1 << endl;
    else cout << a/3 << endl;
}

Measured memory_bytes: 21376
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;

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

  long long x = max(a - k, 0LL);
  k -= (a - x);
  long long y = max(b - k, 0LL);
  cout << x << " " << y;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,k;
	cin>>n>>k;
	if(n==k){
		cout<<0<<endl;
	}else if(n<k){
		cout<<min(n,k-n)<<endl;
	}else if(n%k==0){
		cout<<0<<endl;	
	}else{
		long long ans=n-k;
		long long hoge=n/k;
		hoge*=k;
		n-=hoge;
		ans=min(ans,k-n);
		cout<<ans<<endl;
	}
	return 0;
}

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

flag = 0

for a in A:
  if a%2 == 0:
    if not (a%3 == 0 or a%5 == 0):
      flag = 1

if flag == 0:
  print('APPROVED')
else:
  print('DENIED')

Measured memory_bytes: 38384
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n; cin>>n;
	map<map<char,ll>,ll> r;
	rep(i,n){
		string s;
		cin>>s;
		map<char,ll> ss;
		rep(i,10){
			ss[s[i]]++;
		}
		r[ss]++;
	}
	ll ans = 0;
	for(auto x: r){
		ans += (x.second*(x.second-1))/2;
	}
	cout<<ans<<endl; return 0;
}


Measured memory_bytes: 62336
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args){

	//	for(int i = 0;i< args.length/2;i++){
		while(scan.hasNextLine()){	
			int a = scan.nextInt();
			int b = scan.nextInt();
//			int a = Integer.parseInt(args[i]);
//			int b = Integer.parseInt(args[i+1]);
			if(a == 0 && b == 0){
				break;
			}
			if(a<b){
				System.out.println(a + " " + b);
			}else if(b<a){
				System.out.println(b + " " + a);
			}else{
				System.out.println(a + " " + b);
			}
		}
	}
}



Measured memory_bytes: 43172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int h[105];
int ans;
int k;
bool t;
int main(void){
	int n; cin>>n;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	while(true){
		t=true;
		for(int i=0;i<n;i++){
			if(h[i]!=0){
				if(t){
					ans++;
					t=false;
				}
				h[i]--;
			}else{
				t=true;
			}
		}
		k=0;
		for(int i=0;i<n;i++){
			if(h[i]!=0){
				k++;
			}
		}
		if(k==0){
			cout<<ans<<endl;
			return 0;
		}
		//cout<<ans<<endl;
	}
	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

struct Node{

	Node(int arg_to,int arg_cost){
		to = arg_to;
		cost = arg_cost;
	}
	bool operator<(const struct Node &arg) const{
			return cost > arg.cost;
	};

	int to,cost;
};

int main(){

	int N;
	scanf("%d",&N);

	vector<Node> V[N];

	int node,num,to,cost,D[N];;

	for(int loop = 0; loop < N; loop++){
		scanf("%d",&node);
		scanf("%d",&num);
		for(int i = 0; i < num; i++){
			scanf("%d %d",&to,&cost);
			V[node].push_back(Node(to,cost));
		}
		D[loop] = BIG_NUM;
	}

	D[0] = 0;

	priority_queue<Node> Q;

	for(int i = 0; i < V[0].size(); i++){
		D[V[0][i].to] = V[0][i].cost;
		Q.push(Node(V[0][i].to,V[0][i].cost));
	}

	int min_index;

	while(!Q.empty()){
		if(Q.top().cost == D[Q.top().to]){
			min_index = Q.top().to;
			Q.pop();
		}else{
			Q.pop();
			continue;
		}

		for(int k = 0; k < V[min_index].size(); k++){
			if(D[V[min_index][k].to] > D[min_index] + V[min_index][k].cost){
				D[V[min_index][k].to] = D[min_index] + V[min_index][k].cost;
				Q.push(Node(V[min_index][k].to,D[V[min_index][k].to]));
			}
		}
	}

	for(int i = 0; i < N; i++)printf("%d %d\n",i,D[i]);

    return 0;
}



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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define rrev(i, m, n) for(int (i)=(n)-1; (i)>=(m); (i)--)
#define erev(i, m, n) for(int (i)=(n); (i)>=(m); (i)--)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define pb            push_back
template<class T, class S> inline pair<T, S> mp(T x, S y){ return make_pair(x, y); }
template<class T, class S> inline bool minup(T& m, S x){ return m>(T)x ? (m=(T)x, true) : false; }
template<class T, class S> inline bool maxup(T& m, S x){ return m<(T)x ? (m=(T)x, true) : false; }

static const int    INF = 1000000000;
static const ll     MOD = 1000000007LL;
static const double EPS = 1E-12;

const int MAX_N = 1555;
const int MAX_M = 1555;
int h[MAX_N + 1];
int w[MAX_N + 1];
int N, M;

int main()
{
  while(cin >> N >> M, N){
    rep(i, N) cin >> h[i + 1];
    rep(i, M) cin >> w[i + 1];

    rep(i, N) h[i + 1] += h[i];
    rep(i, M) w[i + 1] += w[i];

    vi l, r;
    rep(i, N + 1) rep(j, i) l.pb(h[i] - h[j]);
    rep(i, M + 1) rep(j, i) r.pb(w[i] - w[j]);
    sort(ALL(l));
    sort(ALL(r));

    int res = 0;
    for(int i=0; i<l.size(); ){
      int np = upper_bound(ALL(l), l[i]) - lower_bound(ALL(l), l[i]);
      res += np * (upper_bound(ALL(r), l[i]) - lower_bound(ALL(r), l[i]));
      i = np + lower_bound(ALL(l), l[i]) - l.begin();
    }

    cout << res << endl;
  }

  return 0;
}

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

typedef pair<int, int> PII;
const int K = 100000 + 5;

int k;
vector<PII> g[K];
queue<int> q;
int d[K], inq[K];

int main() {
    scanf("%d", &k);
    for (int i = 1; i < k; ++i) {
        g[i].push_back(make_pair((i + 1) % k, 1));
        g[i].push_back(make_pair((i * 10) % k, 0));
    }
    memset(d, 0x3f, sizeof(d));
    d[1] = 0, q.push(1), inq[1] = 1;
    while (q.size()) {
        int x = q.front(); q.pop(); inq[x] = 0;
        for (int i = 0; i < g[x].size(); ++i) {
            int y = g[x][i].first;
            if (d[x] + g[x][i].second < d[y]) {
                d[y] = d[x] + g[x][i].second;
                if (!inq[y]) q.push(y), inq[y] = 1;
            }
        }
    }
    printf("%d\n", d[0] + 1);
    return 0;
}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {


      public static void main(String[] args) {

            Scanner sc = new Scanner(System.in);
            int h1 = sc.nextInt();
            int m1 = sc.nextInt();
            int h2 = sc.nextInt();
            int m2 = sc.nextInt();
            int k = sc.nextInt();
            int time1 = h1*60+m1;
            int time2 = h2*60+m2;
            System.out.println(time2 - time1 - k);


      }


}


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

string to_string(const string& s) { return '"' + s + '"'; }
string to_string(char c) { string s = "'"; s += c; return s + "'"; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) res += ", ";
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  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;
}
istream_iterator<string> eos;
void dbg_out(istream_iterator<string> it) { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(istream_iterator<string> it, Head H, Tail... T) {
    cerr << *it << " = " << to_string(H);
    if(++it != eos) cerr << ", ";
    dbg_out(it, T...);
}
#ifdef LOCAL
    #define dbg(...) { string _s = #__VA_ARGS__; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); dbg_out(_it, __VA_ARGS__); }
#else
    #define dbg(...)
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define sz(v) ((int)(v).size())
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 2e5+5;

void solve(){
    int n, ans = 0;
    cin >> n;
    for(int i = 2; i * i <= n; i++) {
        int c = 0;
        while(n % i == 0) {
            n /= i;
            c++;
        }
        int k = 0, j = 0;
        if(c){
            while(1) {
                k += j;
                if(k > c) break;
                j++;
            }
            dbg(i, c, j);
            ans += j-1;
        }
    }
    if(n > 1) ans++;
    cout << ans << nl;
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
using pa = pair<int,int>;
int n;
vector<vector<pa>>v;
bool judge(int bit){
    for(int i=0; i<n; i++){
        if(!(bit&(1<<i)))continue;
        for(pa xy:v.at(i)){
                int x=xy.first;
                int y=xy.second;

                if(y==1&&!(bit&(1<<x)))return false;
                if(y==0&&(bit&(1<<x))) return false;
        }
    }
    return true;
}
int main(){
    cin>>n;
    v.resize(n);
    for (int i = 0; i < n; i++) {
        int a; 
        cin >> a;
        v.at(i).resize(a);
        for (int j = 0; j < a; j++) {
            cin >> v.at(i).at(j).first >> v.at(i).at(j).second;
            --v.at(i).at(j).first;
        }
    }

    int res=0;
    for(int bit=0; bit<(1<<n); bit++){
        if(judge(bit)){
            int count=0;
            for(int i=0; i<n; i++){
                if(bit&(1<<i))count++;
            }
            res=max(res,count);
        }
    }
    cout<<res<<endl;


}



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

#define ll long long

using namespace std;

const int MAXN = 200010;
const int MAXM = 100010;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;

int n, m;
ll k;
int ans, tot, cnt;

int a[MAXN];
int head[MAXN];

int s, t;

inline int read() {
	int s = 0, f = 1;
	char ch = getchar();
	while ('0' > ch || ch > '9') {if (ch == '-') f = -1; ch = getchar();}
	while ('0' <= ch && ch <= '9') {s = (s << 3) + (s << 1) + ch - 48; ch = getchar();}
	return s * f;
}

int vis[MAXN];
int xun[MAXN];
int b[MAXN];

void dfs(int x) {
	if (vis[x]) {
		s = vis[x], t = cnt;
		return;
	}
	vis[x] = ++cnt;
	b[cnt] = x;
	dfs(a[x]);
	return;
}

int main(){
	int T;
	scanf("%d%lld", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		
	}
	dfs(1);
	++k;
	if (k <= cnt) {
		printf("%d\n", b[k]);
		return 0;
	}
	k -= (s - 1);
	k = (k - 1) % (t - s + 1) + 1;
	printf("%d\n", b[s + k - 1]);
	return 0;
}



Measured memory_bytes: 6152
def main():
	t = input().split(" ")
	n, m, d = int(t[0]), int(t[1]), int(t[2])
	if d == 0:
		r = (m-1) / n
	elif d > n:
		r = 0
	else:
		r = 2 * (n-d) * (m-1) / n / n
	print(r)
main()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;

int main() {
	string s;
	int counter[26];
	cin >> s;
	for (int i = 0; i < 26; i++) {
		counter[i] = 0;
	}
	for (int i = 0; i < s.length(); i++) {
		counter[s[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (counter[i] % 2 != 0) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
from sys import exit, stdin
N = int(stdin.readline().rstrip())
H = [int(_) for _ in stdin.readline().rstrip().split()]
 
ans = 0
cnt = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        cnt = 0
    ans = max(ans, cnt)
 
print(ans)

Measured memory_bytes: 14228
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;

#define PI 3.14159265358979323846  // 円周率

long double deg2rad(long double degree)
{
    return degree * PI / 180.0;
}

int main(){
	int a, b, h, m;
	cin >> a >> b >> h >> m;

	double radA = 30*h + 0.5*m;
	double radB = 6*m;

	long double radC = fabs(radA-radB);

	if (radC > 180){
		radC = 360 -radC;
	}

	long double answer = a*a + b*b -(2*a*b * cos(deg2rad(radC)));
	answer = sqrt(answer);

	printf("%20.20Lf\n", answer);

	return 0;
}


Measured memory_bytes: 3512
import java.util.*;
import java.util.ArrayDeque;
import java.util.Queue;
import java.math.RoundingMode;
import java.math.BigDecimal;



public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	   	long n = sc.nextLong();
	   	long k = sc.nextLong();
	   	long mod = 1000000007L;
	   	long sum = 0;
	   	long min = 0;
	   	long max = 0;
	   	for(long i = k; i <= n+1; i++) {
	   		min = i*(i-1)/2;
	   		max = i*(2*n-(i-1))/2;
	   		sum+=(max-min+1)%mod;
	   	} 		
	   	System.out.println(sum%mod);
	 }
}

Measured memory_bytes: 35760
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
#define int long long

const int MAX_N = 100010;

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s; cin >> s;
	if (s == "SUN")cout << 7 << endl;
	else if (s == "MON")cout << 6 << endl;
	else if (s == "TUE")cout << 5 << endl;
	else if (s == "WED")cout << 4 << endl;
	else if (s == "THU")cout << 3 << endl;
	else if (s == "FRI")cout << 2 << endl;
	else cout << 1 << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
static int top, S[1000];

void push(int x){
  S[++top] = x;
}

int pop(){
  return S[top--];
}

int main(){
  int a, b;
  char c[100];
  while((scanf("%s", &c))!=EOF){
    if(c[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    }else if(c[0]=='-'){
      b = pop();
      a = pop();
      push(a-b);
    }else if(c[0]=='*'){
      a = pop();
      b = pop();
      push(a*b);
    }else{
      push(atoi(c));
    }
  }
  printf("%d\n", pop());
  return 0;
}

Measured memory_bytes: 1856
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  input = input.split("\n");

  var tmp = input[0].split( ' ' );
  var h1 = parseInt( tmp[0] );
  var m1 = parseInt( tmp[1] );
  var h2 = parseInt( tmp[2] );
  var m2 = parseInt( tmp[3] );
  var k = parseInt( tmp[4] );

  var min1 = 60 * h1 + m1;
  var min2 = 60 * h2 + m2;
  var a = min2 - min1 - k;
  console.log( a );
}

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


Measured memory_bytes: 29628
program takahashi_is_missing
  implicit none
  integer :: x
  real(8) :: p, e
  character(64) :: s
  read(*,*) x
  read(*,*) p
  p = 0.01d0*p
  e = real((x+1)/2,8)/p
  write(s,'(f32.16)') e
  write(*,'(a)') trim(adjustl(s))
  stop
end program takahashi_is_missing

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    if(A+B>=C){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23636
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
tim, ans = sum(B), 0
r = M - 1

#Aを1冊も読まないとき
while r > -1 and tim > K:
    tim -= B[r]
    r -= 1
ans = r + 1

#Aを1冊以上読むとき
for l in range(N):
    tim += A[l]
    while r > -1 and tim > K:
        tim -= B[r]
        r -= 1
    if tim > K:
        break
    ans = max(ans, l + r + 2)
print(ans)


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    string num;
    cin >> num;

    string ans = "";
    REP(i, 3) {
        if (num[i] == '1') {
            ans += '9';
        } else if (num[i] == '9') {
            ans += '1';
        } else {
            ans += num[i];
        }
    }
    print(ans);
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#include <iostream>
  #include <string>
   
   int main()
   {
     int n;
     std::string s;
   
     std::cin >> n;
    std::cin >> s;
    
    
    if (0 == n % 2 && s.substr(0,n/2) == s.substr(n/2)){
      std::cout << "Yes" << std::endl;
    }else{
      std::cout << "No" << std::endl;
    } 
    
  } 


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

int selectionSort(int A[], int N) {
	int i, j, t, sw = 0, minj;
	for (i = 0; i < N - 1; i++) {
		minj = i;
		for (j = i; j < N; j++) {
			if (A[j] < A[minj]) minj = j;
		}
		t = A[i]; A[i] = A[minj]; A[minj] = t;
		if (i != minj) sw++;
	}
	return sw;
}

int main() {
	int A[100], N, i, sw;

	cin >> N;
	for (i = 0; i < N; i++) cin >>  A[i];

	sw = selectionSort(A, N);

	for (i = 0; i < N; i++) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;

	return 0;
	
}


Measured memory_bytes: 3104