akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)
#define rep(i,x,N) for(int i=x;i<=N;i++)
#define revrep(i,x,N) for(int i=x;i>=N;i--)
#define ar array

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;
using vvi=vector<vi>;
int ctoi(char c) {return c-'0';}
int slen(string s) {return s.length();}
int vsize(vi a) {return (int)a.size();}
int in() {int x;cin>>x;return x;}
void tf(bool ok) {cout<<(ok ? "YES" : "NO")<<endl;}

//https://dmoj.ca/problem/dpv

const int mxn=1e5+10;
vector<int> g[mxn];
ll dp[mxn],c[mxn],ans[mxn];
int N,M;

void dfs1(int e,int p){
	dp[e]=1;
	vi cdrn;
	for(int& u : g[e]){
    if(u!=p) {
      dfs1(u,e);
      dp[e]=(dp[e]*(dp[u]+1))%M;
      cdrn.pb(u);
    }
	}

	vll ps,ss;
	ll pref=1,suf=1;
	forn(i,vsize(cdrn)) {
    ps.pb(pref);
		pref=(pref*(dp[cdrn[i]]+1))%M;
	}
	revrep(i,vsize(cdrn)-1,0) {
    ss.pb(suf);
		suf=(suf*(dp[cdrn[i]]+1))%M;
	}
	reverse(all(ss));
	forn(i,vsize(cdrn)) {
		c[cdrn[i]]=(ps[i]*ss[i])%M;
	}
}

void dfs2(int e,int p){
	ans[e]=(dp[e]*c[e])%M;
	for(int& u: g[e]){
      if(u!=p) {
      c[u]=(c[u]*c[e]+1)%M;
      dfs2(u,e);
    }
	}
}

int main(){

cin>>N>>M;
forn(i,N-1) {
  int u,v;
  cin>>u>>v;
  g[u].pb(v);
  g[v].pb(u);
}

dfs1(1,-1);
c[1]=1;
dfs2(1,-1);

rep(i,1,N)
  cout<<ans[i]<<endl;
return 0;
}


Measured memory_bytes: 25012
#include <iostream>
using namespace std;
int main() {

	int a[5], no = 0, k = 0;
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
	}
	cin >> k;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			if (a[j] - a[i] > k) {
				cout << ":(" << endl;
				goto end;
			}
		}
	}

	cout << "Yay!" << endl;

end:

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
int main()
{
	int a, b, c, k;
	scanf("%d%d%d%d", &a, &b, &c, &k);
	if (k % 2 == 0) printf("%d", a - b);
	else printf("%d", b - a);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define F               first
#define S               second
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18 + 1
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define forI(i,a,n)     for(int i=a;i<=n;i++)
#define forD(i,a,n)     for(int i=n;i>=a;i--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
void init(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

struct flower{
    int hi, bty;
};

int compute(vector<flower> &v, int n){
    vi dp(n+1);
    mii meaningful;
    dp[1] = v[1].bty;
    meaningful[v[1].hi] = dp[1];
    int ans=dp[1];

    forI(i, 2, n){
        dp[i] = v[i].bty;
        auto it = meaningful.lower_bound(v[i].hi+1);
        if(it != meaningful.begin()){
            it--;
            dp[i] += it->ss;
        }
        meaningful[v[i].hi] = dp[i];
        it = meaningful.upper_bound(v[i].hi);
        while(it != meaningful.end() && it->ss <= dp[i]){
            auto temp = it;
            temp++;
            meaningful.erase(it);
            it = temp;
        }
        ans = max(ans, dp[i]);
    }
    return ans;
}

void solve(){
    int n;  cin>>n;
    vector<flower> v(n+1);
    forI(i, 1, n)   cin>>v[i].hi;  forI(i, 1, n)   cin>>v[i].bty;

    cout<<compute(v, n);
}   

int32_t main(){
    init();
    // w(t) 
    solve();
    return 0;
}

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

int main(){
    long long N, K;
    cin >> N >> K;

    vector<long long> H(N);
    for (int i = 0; i < N; i++){
        cin >> H.at(i);
    }
    sort(H.begin(), H.end());
    
    long long  ans = 0;

    if (K <= N){
        for (int i = 0; i < N - K; i++){
            ans += H.at(i);
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 1792
import java.util.Scanner;

//Trading
public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] t = new int[1001];
		int[] t2 = new int[1001];
		while(true){
			String s = sc.nextLine();
			if(s.equals(""))break;
			t[Integer.parseInt(s.split(",")[0])]++;
		}
		while(sc.hasNext()){
			int x = Integer.parseInt(sc.nextLine().split(",")[0]);
			t2[x]++;
		}
		for(int i=0;i<=1000;i++)if(t[i]>0&&t2[i]>0)System.out.println(i+" "+(t[i]+t2[i]));
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
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(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n")
using P = pair<int,int>;
using vi = vector<int>;
using vii = vector<vi>;
using ll = long long;
const int dx4[4] = {1,0,-1,0};
const int dy4[4] = {0,1,0,-1};
const int dx8[8] = {-1,0,1,1,1,0,-1,-1};
const int dy8[8] = {1,1,1,0,-1,-1,-1,0};

ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}


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

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  map<ll, ll> mp;
  rep(i,n) mp[a[i]]++;
  ll sum = 0;

  for(auto it = mp.begin(); it != mp.end(); it++){
    sum += com((*it).second, 2);
  }
  //cout << sum << endl;
  rep(i,n){
    ll ans = sum;
    ans -= com(mp[a[i]], 2);
    ans += com(mp[a[i]]-1, 2);
    cout << ans << endl;
  }
}

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

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<double,double> P;

//少数点表示
//cout <<std::fixed << std::setprecision(14)
//階乗
double calcProduct(double n) {
  return (n == 1)? 1: n * calcProduct(n - 1);
}

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    double n;
    cin >> n;
    vector<P> xy(n);
    vector<int> v(n);
    rep(i,n){
        cin >> xy[i].first >> xy[i].second;
        v[i]=i;
    }

    double kyori=0;
    do{
        for(int i=0; i<n-1; i++){
            kyori+=sqrt(pow((xy[v[i+1]].first-xy[v[i]].first),2)+pow((xy[v[i+1]].second-xy[v[i]].second),2));
        }

    }while(next_permutation(v.begin(),v.end()));

    double heikin = kyori/calcProduct(n);

    cout <<std::fixed<< std::setprecision(7)<<heikin;

}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := make(map[int]struct{})
	d[intScanner()] = struct{}{}
	d[intScanner()] = struct{}{}
	d[intScanner()] = struct{}{}
	fmt.Println(len(d))
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int count=0,x;
  cin>>s;
  x=s.length();
  for(int i=0;i<x;i++){
    if(s[i]=='B'){
      if(s[i+1]=='W'){
	count++;
      }
    }else{
      if(s[i+1]=='B'){
	count++;
      }
    }
  }
  cout<<count<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
   int n;
   cin >> n;
   int first, second;
   int maxim = -1;
   int nrPatrateMaxim = -1;
   int patratul = -1;
   int nrPatrate = 0;
   if (n == 1)
   {
       cout << 0 << " ";
   }
   else
   {    cin >> second;
        n -= 1;
       while (n > 0)
      {
       cin >> first;
       if (first > second)
       {
           if (nrPatrateMaxim < nrPatrate)
           {
               nrPatrateMaxim = nrPatrate;
           }
           nrPatrate = 0;
       }
       if (second >= first)
       {
           nrPatrate += 1;
       }
       second = first;
       n -- ;
//        cout << nrPatrate << " ";
      }
      if (nrPatrate > nrPatrateMaxim)
   {
       nrPatrateMaxim = nrPatrate;
   }
//   cout << "\n";
   cout << nrPatrateMaxim;
   }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==c&&b!=a) {
		cout<<"Yes";
		return 0;
	}
	if(a==b&&c!=a){
		cout<<"Yes";
		return 0;
	}
	if(b==c&&a!=b){
		cout<<"Yes";
		return 0;
	} 
	cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int L,R;
int main(){
	scanf("%d%d",&L,&R);
	if(L%2019==0||R%2019==0)return puts("0"),0;
	int t=2019-L%2019+L;
	if(R>=t)return puts("0"),0;
	int ans=2018;
	for(int i=L;i<R;i++)
		for(int j=i+1;j<=R;j++)
			ans=min(ans,(int)(1LL*i*j%2019));
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  vector<int> ans(n);
  
  rep(i,n) ans[a[i]-1] = i+1;
  
  rep(i,n){
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 1664
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


A,B = MI()
print(max(A+B,A-B,A*B))


Measured memory_bytes: 61588
/*
 _  __    _   _   _ ____ _____ 
| |/ /   / \ | | | / ___|_   _|
| ' /   / _ \| | | \___ \ | |  
| . \  / ___ \ |_| |___) || |  
|_|\_\/_/   \_\___/|____/ |_|  
*/
#include <bits/stdc++.h>
#include <fstream>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define a(x) (x.begin(), x.end())
#define ar(x) (x.rbegin(), x.rend())
#define pb push_back
#define Pb() pop_back()
#define ll long long int
#define ull unsigned long long int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sc scanf
#define scin(x) sc("%d", &(x))
#define scln(x) sc("%lld", &(x))
#define pf prllf
#define ms(a, b) memset(a, b, sizeof(a))
#define mp make_pair
#define db double
#define EPS 10E-10
#define ff first
#define ss second
#define sqr(x) (x) * (x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define vll vector<vector<ll>>
#define DBG pf("HI\n")
#define MOD 1000000007
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define RUN_CASE(t, T) for (__typeof(t) t = 1; t <= T; t++)
#define CASE(t) prllf("Case %d: ", t)
#define CASEL(t) prllf("Case %d:\n", t)
#define intlimit 2147483647
#define longlimit 9223372036854775807
#define infinity (1 << 28)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) * (b) / gcd(a, b))
#define PI 2 * acos(0.0)
using namespace std;
vector<pair<ll, ll>> v;
ll n, w;
vll dp;
ll find_max(ll index, ll weight)
{
    if ( weight == 0 || (weight>0 && index>=n))
    {
        return 0;
    }
    if(weight < 0 || index >= n){
        return -100000000000;
    }
    if(dp[index][weight]!=-1){
        return dp[index][weight];
    }
    ll maxi = 0;
    maxi = max(v[index].second+find_max(index+1,weight-v[index].first),find_max(index+1,weight));
    dp[index][weight] = maxi;
    return maxi;
}
int main()
{
    CIN;
    cin >> n >> w;
    v.resize(n);
    dp.resize(n,vl(w+1,-1));
    rep(i, 0, n)
    {
        cin >> v[i].first >> v[i].second;
    }
    cout << find_max(0, w);
}

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

using namespace std;

int main(){

  int N,H,W;

  int cntH = 0, cntW = 0;
  
  cin >> N >> H >> W;

  cntH = N / H + (H - 1) * (N / H - 1) + (N % H);

  cntW = N / W + (W - 1) * (N / W - 1) + (N % W);

  cout << cntH * cntW << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//:/
#define pb emplace_back
#define mp make_pair
#define nt _ll128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=1e9+7;
const ll inf=1e17;
const ll ms=(2e5)+5;


ll ar[ms];
ll ans[ms];

int main()
{
    idfc;
    int n;
    cin>>n;
    map<int,int>mm;
    int i;
    int e;
    for(i=1;i<=n;i++)
    {
        cin>>e;
        mm[e]+=1;
    }
    if(n%2)
    {
        for(i=2;i<n;i+=2)
        {
            if(mm[i]!=2)
            {
                cout<<0;
                return 0;
            }
        }
        if(mm[0]!=1)
        {
            cout<<0;
            return 0;
        }
    }
    else{
        for(i=1;i<n;i+=2)
        {
            if(mm[i]!=2)
            {
                cout<<0;
                return 0;
            }
        }
    }
    ll ans=1;
    n/=2;
    for(i=1;i<=n;i++)
    {
        ans=(ans*2)%modo;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 6532
n=int(input())
a=list(map(int,input().split()))
a.sort()
ans=n
sum_former=sum(a)
for i in range(n-1,-1,-1):
    sum_former-=a[i]
    if(2*sum_former < a[i]):
        ans=n-i
        break

print(ans)


Measured memory_bytes: 14320
#include<stdio.h>
#include<string.h>
int main()
{
int i,len,l=0,l1=0,m=0;
char a[50],b[50],c[50];
scanf("%s",a);
len=strlen(a);
for(i=0;i<len;i++)
{
if(a[i]=='0')
{
b[m]='0';
m++;
l=m;
}
else if(a[i]=='1')
{
b[m]='1';
m++;
l=m;
}
else if(a[i]=='B')
{
if(l>0)
{
b[l-1]=' ';
l--;
}
}
}
for(i=0;i<m;i++)
{
if(b[i]!=' ')
{
c[l1]=b[i];
l1++;
}
}
c[l1]='\0';
printf("%s",c);
}

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

int n, A[36], B[36];
char a[36], b[36];

string isStable(){
  for (int i=0;i<n;i++){
    if(A[i]==B[i] && a[i]==b[i]) continue;
    return "Not stable";
  }
  return "Stable";
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>A[i];
    b[i]=a[i];
    B[i]=A[i];
  }
  for(int i=0;i<n;i++){
    for(int j=n-1;j>i;j--){
      if(A[j]<A[j-1]){
	swap(A[j], A[j-1]);
	swap(a[j], a[j-1]);
      }
    }
  }
  for(int i=0;i<n;i++){
    int minj = i;
    for(int j=i+1;j<n;j++){
      if(B[j]<B[minj]) minj = j;
    }
    swap(B[i], B[minj]);
    swap(b[i], b[minj]);
  }
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<a[i]<<A[i];
  }
  cout<<endl<<"Stable"<<endl;
  for(int i=0;i<n;i++){
    if(i) cout<<" ";
    cout<<b[i]<<B[i];
  }
  cout<<endl<<isStable()<<endl;
  return 0;
}



Measured memory_bytes: 3176
// 問題URL
//

import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int gohyaku =0, hyaku = 0, gozyu = 0, zyu = 0, go = 0, ichi = 0;
        int sum = 0;
        int uresisa = 0;

        gohyaku = n / 500;
        sum += gohyaku * 500;

        hyaku = (n - sum) / 100;
        sum += (hyaku * 100);

        gozyu = (n - sum) / 50;
        sum += gozyu * 50;

        zyu = (n-sum) / 10;
        sum += zyu * 10;

        go = (n-sum) / 5;
        sum += go * 5;

        ichi = n - sum;
        sum += ichi;


        uresisa += gohyaku * 1000;
        uresisa += hyaku * 100;
        uresisa += gozyu * 50;
        uresisa += zyu * 10;
        uresisa += go * 5;
        //uresisa += ichi;



        System.out.println(uresisa);
    }
}

Measured memory_bytes: 21716
N = ("00"+input())[::-1]

ans = 0
carry = 0
for i in range(len(N)-1):
    n = int(N[i])
    nextn = int(N[i+1])
    if carry == 1:
        carry = 0
        n += 1

    if n <=4:
        ans += n
    elif n >= 6:
        ans += 10-n
        carry = 1
    else: # n==5
        if nextn <= 4:
            ans += n
        else:
            ans += 10-n
            carry = 1

print(ans)
    

Measured memory_bytes: 5516
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
#define PI 3.141592
 
using namespace std;
 
int main(void) {
    ll n;
    cin >> n;
    ll a[n];
    rep(i, n){
        a[i] = 0;
    }
    rep(i, n-1){
        ll x;
        cin >> x;
        a[x-1]++;
    }
    rep(i, n){
        cout << a[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 5184
# include <algorithm>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <string>
# include <vector>

using namespace std;
typedef long long ll;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w; cin >> h >> w;

    ll edges[2] = { h, w };

    ll min1 = h * w;
    if (h % 3 == 0 || w % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll edgeMins[2];
    for (int i = 0; i < 2; i++) {
        ll first = edges[i] / 3;
        ll second = (edges[i] - first)/2;
        ll third = edges[i] - first - second;
        edgeMins[i] = third - first;
    }
    for (int i = 0; i < 2; i++) {
        min1 = min(min1, edgeMins[1 - i] * edges[i]);
    }

    ll min2 = h * w;
    for (int i = 0; i < 2; i++) {
        ll w1 = edges[i] / 3;
        ll w2 = w1 + 1;
        ll ws[2] = { w1, w2 };
        for (int k = 0; k < 2; k++) {
            ll maxs = ws[k] * edges[1 - i];
            ll mins = ws[k] * edges[1 - i];
            ll left = edges[i] - ws[k];
            ll first = edges[1 - i] / 2;
            ll second = edges[1 - i] - first;
            mins = min(mins, left * first);
            maxs = max(maxs, left * second);
            min2 = min(min2, maxs - mins);
        }
    }

    cout << min(min1, min2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



int main() {	
	int n;
	cin >> n;

	vector<int> v;
	v.push_back(1);

	int temp_6=6;
	while (temp_6 <= n) {
		v.push_back(temp_6);
		temp_6 *= 6;
	}

	int temp_9 = 9;
	while (temp_9 <= n){
		v.push_back(temp_9);
		temp_9 *= 9;
	}




	int m = v.size();
	vector< vector<int> > dp(m + 1, vector<int>(n + 1, 0));


	int INF = 101010;
	rep(i,0,m+1) {
		rep(j,0,n+1) {
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;
	rep(i,0,m) {
		rep(j,0,n+1) {
			if (j-v[i] >= 0) {
				dp[i + 1][j] = min(dp[i][j],dp[i+1][j-v[i]]+1);
			}
			else {
				dp[i + 1][j] = dp[i][j];
			}
		}
	}


	cout << dp[m][n] << endl;
	
	return 0;

}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

class Trie {
    private:
        vector<int> val;
        Trie *parent;
        std::vector<Trie *> children;
    public:
        Trie(Trie *parent = nullptr) : val(26, 0), parent(parent), children(26, nullptr) {}
        ~Trie() {
            for (Trie *ptr : children)
                delete ptr;
        }
        Trie *find(const std::string &str) {
            Trie *ptr = this;
            for (char c : str) {
                int idx = c - 'a';
                if (ptr->children[idx] == nullptr)
                    ptr->children[idx] = new Trie(ptr);
                ptr = ptr->children[idx];
            }
            return ptr;
        }
        void insert(const std::string &str) {
            Trie *ptr = this->find(str);
            vector<bool> check(26, false);
            auto iter = str.rbegin();
            while (true) {
                for (int i=0; i<26; ++i)
                    ptr->val[i] += check[i];
                if (ptr->parent == nullptr)
                    break;
                check[*iter-'a'] = true;
                ++iter;
                ptr = ptr->parent;
            }
        }
        vector<int> getVal() const { return val; }
};

void solve() {
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i=0; i<N; ++i) cin >> S[i];

    for (int i=0; i<N; ++i) reverse(S[i].begin(), S[i].end());
    sort(S.begin(), S.end(), [](auto a, auto b){return (int)a.size() > (int)b.size();});

    Trie trie;
    ll res = 0;
    for (int i=0; i<N; ++i) {
        Trie *ptr = trie.find(S[i].substr(0, (int)S[i].size()-1));
        res += ptr->getVal()[S[i].back()-'a'];
        trie.insert(S[i]);
    }

    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 435756
N,K = list(map(int,input().split(" ")))
hs = list(map(int,input().split(" ")))
dp = [9999999999999] * N

dp[0] = 0
for i in range(1,N):
#ind → i-1 ~ i-stepLim -1   [i-stepLim -1:i]
    stepLim = min(K,i)
    temp = 9999999999999999999
    dp[i] = min([d+abs(hs[i]-h) for d,h in zip(dp[i-stepLim:i],hs[i-stepLim:i])])
print(dp[-1])

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

int main() {
    int d;
    cin >> d;

    string ans = "";
    if (d == 25) ans = "Christmas";
    if (d == 24) ans = "Christmas Eve";
    if (d == 23) ans = "Christmas Eve Eve";
    if (d == 22) ans = "Christmas Eve Eve Eve";
    cout << ans << endl;
    return 0;
}

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

int main(){
    
    int x;
    cin>>x;
    
    int h = x/3600;
    int m = (x/60)%60;
    int s = x%60;
    cout<<h<<":"<<m<<":"<<s<<endl;
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <limits>
#include <utility>
#include <algorithm>
#include <tuple>
#include <limits>

typedef long long ll;

const ll MOD = 1000000007;

int main(int argc, char *argv[])
{
    ll n;
    std::vector<ll> a;

    std::cin >> n;

    a.resize(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }

    std::vector<ll> b(n);
    b[n - 1] = a[n - 1];
    for (int i = n - 1; i > 0; i--) {
        b[i - 1] = (b[i] + a[i - 1]) % MOD;
    }

    ll sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += a[i] * b[i + 1];
        sum %= MOD;
    }

    std::cout << sum << std::endl;

    return 0;
}


Measured memory_bytes: 6368
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        for(int i=0;i<n;i++) {
           String[] s=sc.next().split(":");
           double a=Double.parseDouble(s[0])*60;
           double b=Double.parseDouble(s[1])*11;
           double d=Math.min(Math.abs((a-b)/2),Math.abs((-a+b)/2));
           if(d>=180) d=360-d;
           System.out.println(d<30?"alert":d<90?"warning":"safe");
        }
    }
}


Measured memory_bytes: 29840
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define plll pair<ll,pll>
#define ppll pair<pll, pll>
#define pii pair<int, int> 
#define pb push_back
#define mod 1000000007
#define N 1000007
ll power(ll a,ll b){
    ll res=1ll;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res%mod;
}
ll ncr(ll n,ll k){
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro)%mod;
}

void swap(ll *a,ll *b) {
    ll temp=*a;
    *a=*b;
    *b=temp;
}
vector<ll> prime;
void seive(){
    vector<bool > isprime(1000001,true);
    for(int i=2;i*i<=1000000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=1000000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=1000000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}
vector<ll> parent;
ll find(ll p) {
    if(parent[p]==p) return parent[p];
    return parent[p]=find(parent[p]); 
}
void unun(ll a,ll b) {
    ll r1=find(a);
    ll r2=find(b);
    if(r1!=r2) parent[r2]=r1;
}
void solve() {   
    ll n,a,b;
    cin>>n>>a>>b;
    for(int i=a;i<=b;i++) {
        if(i%n==0) {
            cout<<"OK";
            return ;
        }
    }
    cout<<"NG";
    return ;
}   


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

}


Measured memory_bytes: 3616
N=int(input())
ans=[-1]*(N-1)
rootLine=[0]*N
numLine=[0]*N
l=[]
for i in range(N-1):
  a,b=map(int,input().split())
  a-=1
  b-=1
  l.append([a,b,i])
l.sort()

for a,b,i in l:
  numLine[a]+=1
  if numLine[a]==rootLine[a]:
    numLine[a]+=1
  ans[i]=numLine[a]
  rootLine[b]=numLine[a]

print(max(ans))
for i in ans:
  print(i)

Measured memory_bytes: 92160
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b = map(int, readline().split())
    if (a * b) % 2 == 0:
        print("Even")
    else:
        print("Odd")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
typedef pair<int, int>P;
typedef tuple<ll, int, int>T;
#define PI 3.14159265358979


int main(){
  int x1,y11,x2,y2;
  int H,W,K;
  cin>>H>>W>>K>>x1>>y11>>x2>>y2;
  x1--;y11--;x2--;y2--;
  char dp[H][W];
  vector<vector<int>>memo(H,vector<int>(W,1000000)); 
  rep(i,H){
    rep(j,W){
      cin>>dp[i][j];
    } 
  }
    memo[x1][y11]=0;  
   queue<P>qu;
   qu.push(P(x1,y11));
  while(!qu.empty()){
    auto t=qu.front();qu.pop();
    int x=t.first,y=t.second;
    for(int i=1;i<=K;i++){
      if(x+i>=H){break;}
        if(dp[x+i][y]=='@'){break;}
        if(memo[x+i][y]>memo[x][y]+1){
          memo[x+i][y]=memo[x][y]+1;
          qu.push(P(x+i,y));
        }
       else if(memo[x+i][y]<memo[x][y]+1){break;}
    }
    for(int i=1;i<=K;i++){
      if(y+i>=W){break;}
        if(dp[x][y+i]=='@'){break;}
        if(memo[x][y+i]>memo[x][y]+1){
          memo[x][y+i]=memo[x][y]+1;
          qu.push(P(x,y+i));
        }
      else if(memo[x][y+i]<memo[x][y]+1){break;}
    }
    for(int i=1;i<=K;i++){
      if(x-i<0){break;}
      if(dp[x-i][y]=='@'){break;}
      if(memo[x-i][y]>memo[x][y]+1){
        memo[x-i][y]=memo[x][y]+1;
        qu.push(P(x-i,y));
      }
      else if(memo[x-i][y]<memo[x][y]+1){break;}
    }
    for(int i=1;i<=K;i++){
      if(y-i<0){break;}
      if(dp[x][y-i]=='@'){break;}
      if(memo[x][y-i]>memo[x][y]+1){
      memo[x][y-i]=memo[x][y]+1;
        qu.push(P(x,y-i));
      }
      else if(memo[x][y-i]<memo[x][y]+1){break;}
    }
  }
  
   
  if(memo[x2][y2]!=1000000){
    cout<<memo[x2][y2];
  }
  else{cout<<-1;}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int, int> P;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    if (a >= k) {
        ans = k;
    } else if (a + b >= k) {
        ans = a;
    } else if (a + b < k && k <= a + b + c) {
        ans = a - (k - a - b);
    }

    cout << ans << endl;
    return 0;
}


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

int main() {
    long long N;
    cin >> N;
    for (long long h = 1; h < 3501; ++h){
        for (long long n = h; n < 3501; ++n){
            // w = 1/(4/N - 1/h - 1/n) = Nhn/(4hn - N(n + h))
            long long num = N * h * n;
            long long den = 4 * h * n - N * (n + h);
            if (den > 0 and (num % den) == 0){
                cout << h << ' ' << n << ' ' << num / den << endl;
                return 0;
            }

        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <stdio.h>
#include <vector>
#include <thread>
#include <atomic>
#include <mutex>
#include <future>
#define int long long
#define endre getchar();getchar();return 0
#define INF 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define input() for(int i=0;i<n;i++)cin>>a[i];
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return (y, x%y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int n) {
	if (n == 0)return 1;
	return (kai(n - 1)*n) % INF;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x%mod;
		}
		x = x * x%mod;
		y >>= 1;
	}
	return res;
}
int mystoi(string s) {
	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		cnt += (int)(s[i] - '0') * pow(10, s.size() - i - 1);
	}
	return cnt;
}
int n, h[100005], dp[100005];
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> h[i];
		dp[i] = INF;
	}
	dp[1] = 0, dp[2] = abs(h[1] - h[2]);
	for (int i = 3; i <= n; i++) {
		dp[i] = min(dp[i - 1] + abs(h[i - 1] - h[i]), dp[i - 2] + abs(h[i - 2] - h[i]));
	}
	cout << dp[n] << endl;
	endre;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);

int main() {
    // source
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { cin >> a[i]; }

    map<int, int> m;
    rep(i, n) {
        int num = a[i];
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
    }

    int ans = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
        if (iter->second % 2 == 1) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

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

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

void prime_map(map<ll, ll> &m, ll num) {

    if (num == 1) {
        return;
    }
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }
    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }

        return;
    }
    prime_map(m, num);
    return;
}


Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin>>a>>b;
    if(a + b == 3){
        cout<< "3" <<endl;
    }
    else if(a > b){
        cout<< a - b <<endl;
    }
    else{
        cout<< b - a <<endl;
    }
}


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

const int MOD = 1e9 + 7;
const int MAX = 2e6 + 10;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a) {
    return modpow(a, MOD - 2);
}

int main() {
    COMinit();
    int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    ll ans = 0;
    for (int i = r1; i <= r2; i++) {
        ans += ((((c2 + 1) * COM(c2 + i + 1, c2 + 1) % MOD) - ((c1 * COM(c1 + i, c1)) % MOD)) * modinv(i + 1) % MOD);
        ans  =(ans + MOD) % MOD;
    }
    cout << ans << endl;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int n, m, q;
    vector<int> a[505];
    cin >> n >> m >> q;
    REP(i,m){
        int l, r;
        cin >> l >> r;
        a[l].push_back(r);
    }
    REP(i,n)SORT(a[i]);
    REP(i,q){
        int p, q, ans = 0;
        cin >> p >> q;
        for(int j = p; j<=q; ++j){
            ans += upper_bound(ALL(a[j]),q) - a[j].begin();
        }
        cout << ans << endl;
    }
    return 0;
}


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

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

using namespace std;

using ll = long long;

template <class T, T M>
class modulo {
public:
    T data;

    modulo(T data = 0) : data(data % M) {
    }

    modulo operator+(const modulo &x) const {
        return modulo(data + x.data);
    }

    modulo operator-(const modulo &x) const {
        return modulo(data + (M - x.data));
    }

    modulo operator*(const modulo &x) const {
        return modulo(data * x.data);
    }

    modulo operator/(const modulo &x) const {
        return modulo(data * x.inv().data);
    }

    modulo operator+=(const modulo &x) {
        return data = (data + x.data) % M;
    }

    modulo operator-=(const modulo &x) {
        return data = (data + (M - x.data)) % M;
    }

    modulo operator*=(const modulo &x) {
        return data = (data * x.data) % M;
    }

    modulo operator/=(const modulo &x) {
        return data = (data * x.inv().data) % M;
    }

    modulo inv() const {
        return _pow(M - 2);
    }

    template <class Integer>
    modulo operator^(Integer n) const {
        if (n >= 0) {
            return _pow(n);
        } else {
            return _pow(M - 1 - (-n) % (M - 1));
        }
    }

    friend std::ostream& operator<<(std::ostream &os, const modulo &x) {
        os << x.data;
        return os;
    }

private:
    template <class NonNegativeInteger>
    modulo _pow(NonNegativeInteger n) const {
        modulo result(1);
        modulo x(*this);
        while (n) {
            if (n & 1) {
                result *= x;
            }
            x *= x;
            n >>= 1;
        }
        return result;
    }
};

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

    constexpr ll MOD = 998244353;

    using Mod = modulo<ll, MOD>;

    int N;
    cin >> N;
    vector<int> D(N), count(N, 0);
    REP(i, N) {
        cin >> D[i];
        ++count[D[i]];
    }

    if (D[0] != 0 || count[0] != 1) {
        cout << 0 << endl;
        return 0;
    }

    Mod result = 1;
    REP(i, N) {
        result *= Mod(count[i]) ^ count[i + 1];
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int dfs(int p,int q,int a,int n,int l){
	if(p==0)return 1;
	if(p<0||n<=0)return 0;
	int res=0;
	for(int i=l;i<=a;i++){
		if(i*p>n*q)break;
		if(i*p-q<0)continue;
		res+=dfs((p*i-q),q*i,a/i,n-1,i);
	}
	return res;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	while(1){
		int p,q,a,n; cin >> p >> q >> a >> n;
		if(p==0&&q==0&&a==0&&n==0)break;
		int g=__gcd(p,q);
		p/=g; q/=g;
		cout << dfs(p,q,a,n,1) << endl;
	}
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
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;
}
int main() {
    int n;cin>>n;
    vector<int> v(n+1);
    rep(i,n){
        cin>>v[i+1];
    }
    int a=1;
    int e=0;
    set<int> s;
    while(1){
        if(a==2){
            break;
        }
        if(s.count(a)){
            e=-1;
            break;
        }else{
            s.insert(a);
            a=v[a];
        }
        e++;
    }
    cout<<e<<endl;
    return 0;
}

Measured memory_bytes: 5376
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main
{
    public static void main(String[]args)
    {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Solver solver = new Solver();
        solver.solve(1,in,out);
        out.close();
    }
    static class Solver
    {

        public int a[];

        public void solve(int ca,InputReader in,PrintWriter out)
        {
            while(ca -- != 0)
            {
                String str = in.next();
                int ans = 0;
                for(int i = 0;i<str.length();i++)
                {
                    if(str.charAt(i) == '2') ans++;
                }
                out.print(ans);
            }
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }
        public BigInteger nextBigInteger()
        {
            return new BigInteger(next());
        }

    }
}


Measured memory_bytes: 21332
/***     
 * When I wrote this
 * only God & I understood
 * what I was doing
 * Now, God only knows 
 /***/ 
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9+7;
using namespace std;
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;}
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll t;
    while (cin >> t)
    {
        if(t>=30)cout<<"Yes\n";
        else cout<<"No\n";
    }
}

Measured memory_bytes: 3156
#include "bits/stdc++.h"
using namespace std;
int main() {
	int x1, x2, x3;
	cin >> x1 >> x2 >> x3;

	if (x1 + x2 + x3 >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    S, T = (s.decode() for s in readline().rstrip().split())
    A, B = map(int, readline().split())
    U = readline().rstrip().decode()
    if S == U:
        A -= 1
    else:
        B -= 1
    print(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>

static int n;
static std::vector<std::vector<int>> link_mat;

enum STATUS {
    IN,
    OUT,
    EDGE,
};


void updateEdge(int node, std::vector<STATUS> &statuses) {
    statuses[node] = STATUS::IN;
    for (int i = 0; i < link_mat[node].size(); i++) {
        if (link_mat[node][i] == -1) {
            continue;
        }
        if (statuses[i] == STATUS::OUT) {
            statuses[i] = STATUS::EDGE;
        }
    }
}


int search(int node, std::vector<STATUS> &statuses) {
    updateEdge(node, statuses);
    int min = 2001;
    int min_node = -1;
    for (int i = 0; i < n; i++) {
        if (statuses[i] != STATUS::EDGE) {
            continue;
        }
        for (int j = 0; j < n; j++) {
            int w = link_mat[i][j];
            if (w == -1 || w > min) {
                continue;
            }
            if (statuses[j] != STATUS::IN) {
                continue;
            }
            min = w;
            min_node = i;
        }
    }
    if (min_node == -1) {
        return 0;
    }
    return min + search(min_node, statuses);
}


int main() {
    std::cin >> n;
    link_mat = std::vector<std::vector<int>>(n, std::vector<int>(n));
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            std::cin >> link_mat[i][j];
        }
    }
    std::vector<STATUS> statuses(n, STATUS::OUT);
    int cost = search(0, statuses);
    
    std::cout << cost << std::endl;
}



Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define endl "\n"
#define print_array(name,n) for(ll o=0;o<n;o++) cout<<name[o]<<" "
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 2e18
#define pll pair<ll,ll>
#define pii pair<int,int>
bool sortbysecond(const pair<int,int> &a,const pair<int,int> &b){
	return (a.ss>b.ss);
}
 
ll gcd(ll a,ll b){ if(b==0) return a; return gcd(b,a%b) ;} 

template <typename T>
string NumberTostring(T Number )
{
	ostringstream ss;
	ss<<Number;
	return ss.str();
}
 

 
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
 	ll x,k,d;
 	cin>>x>>k>>d;
 	x = abs(x);
 	ll mv = x/d;
 	ll ans;
 	if(k<=mv){
 		ans = x - d*k;

 	}   
 	else{
 		ans = x - d*mv;
 		x = x - d*mv;
 		k = k - mv;
 		if(k%2==0){
 			ans = x;
 		}
 		else{
 			ans = d - x;
 		}
 	}
 	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3656
n, m = map(int,input().split())
 
l1 = []
l2 = []
for i in range(m):
    a,b = map(int,input().split())
    if a==1:
        l1.append(b)
    elif b==n:
        l2.append(a)

if len(set(l1)&set(l2)) >=1:
  print('POSSIBLE')
else:
  print('IMPOSSIBLE')

Measured memory_bytes: 27644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(void){
    int i,n;
    cin>>n;
    vector<int> a(n,0);
    rep(i,n)cin>>a[i];
    rep(i,n){
        if(a[i]%2==0){
            if(!(a[i]%3==0||a[i]%5==0)){
            cout<<"DENIED";
            return 0;
            }
        }
    }

    cout<<"APPROVED";
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = input()

ta = []
for i in range(n) :
  ta.append([t[i],1])

for i in range(n-k) :
  if ta[i][0] == ta[i+k][0] and ta[i][1] == ta[i+k][1]: 
    ta[i+k][1] = 0

ans = 0
for i in range(n) :
  if ta[i][1] == 1 :
    if ta[i][0] == 'r' :
      ans += p
    if ta[i][0] == 's' :
      ans += r
    if ta[i][0] == 'p' :
      ans += s

print(ans)

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

#define LL long long

using namespace std;

LL n,a[410],dp[410][410],sum[410];

int main()
{
  cin>>n;
  for(int i=0;i<n;i++)
  {
	cin>>a[i];
    sum[i+1]=sum[i]+a[i];
  }
  for(int len=2;len<=n;len++)
    for(int i=0;i<n;i++)
    {
      if(i+len-1>=n) break;
      int j=i+len-1;
      dp[i][j]=1e18;
      for(int k=i;k<j;k++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[j+1]-sum[i]);
    }
  cout<<dp[0][n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1536
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
using namespace std;

/*
#include <math.h>
int standerd = int(pow(10.0,9.0)) + 7;
*/
string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 
 

int main(){

    int A;
    int B;
    double Z;
    
    cin >> A;
    cin >> B;
    cin >> Z;

    int count = 0;
    int number = 1;
    while(A * number <= Z + 0.5){
        count = count + B;
        number++;
    }


    cout << count;
    

}

Measured memory_bytes: 256