akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> T;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
template<class T>
void dump(vector<T> &vec){
	for(int i=0;i<vec.size();i++){
		cout << vec[i];
		if(i+1<vec.size())cout << ' ';
		else cout << endl;
	}
	return;
}
template<class T>
void input(vector<T>& vec,int n){
	vec.resize(n);
	for(int i=0;i<n;i++){
		cin >> vec[i];
	}
}
int N,Q;
vector<int> g[100100];
char type[100100];
int p[100100];
int ver[100100];
int depth[100100];
int marked[100100];
const int SIZE = 100100;
struct UnionFind{
	int par[SIZE];
	void init(int n){
		for(int i=0;i<n;i++){
			par[i] = i;
		}
	}
	int find(int x){
		if(par[x] == x)return x;
		else return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x==y)return;
		if(depth[x] > depth[y])par[x] = y;
		else par[y] = x;	
	}
	bool same(int x,int y){
		return find(x) == find(y);
	}
}uf;
void dfs(int v,int pa,int d){
	depth[v] = d;
	if(!marked[v]){
		if(pa!=-1)uf.par[v]=pa;
	}
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		if(u==pa)continue;
		dfs(u,v,d+1);
	}
}
void add_edge(int a,int b){
	g[a].pb(b);
	g[b].pb(a);
}
bool solve(){
	scanf("%d %d",&N,&Q);
	if(N==0)return false;
	for(int i=0;i<N;i++)g[i].clear();
	memset(marked,0,sizeof(marked));
	for(int i=1;i<N;i++){
		scanf("%d",&p[i]);
		p[i]--;
		add_edge(i,p[i]);
	}
	for(int i=0;i<Q;i++){
		scanf(" %c %d",&type[i],&ver[i]);
		ver[i]--;
		if(type[i]=='M')marked[ver[i]]++;
	}
	uf.init(N);
	dfs(0,-1,0);
	ll ans = 0ll;
	for(int i=Q-1;i>=0;i--){
		if(type[i]=='Q'){
			// cout << uf.find(ver[i]) << endl;
			ans += 1+uf.find(ver[i]);
		}else{
			marked[ver[i]]--;
			if(marked[ver[i]]==0)uf.par[ver[i]] = p[ver[i]];
		}
	}
	cout << ans << endl;
	return true;
}
int main(){
	while(solve()){}
	return 0;
}



Measured memory_bytes: 15868
//Score	620
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
int n, m, p, MOD;
lint pow2[2505], ans;
inline int ask(int x1, int y1, int x2, int y2) {
	cout << "? " << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
	int ret = 0; cin >> ret; return ret;
}
inline int siz(int x1, int y1, int x2, int y2) {
	return (x2 - x1 + 1) * (y2 - y1 + 1);
}
inline void search(int x1, int y1, int x2, int y2, int las) {
	if (x1 == x2 && y1 == y2) {
		ans = (ans + pow2[x1 * m + y1]) % MOD;
	} else if (x2 - x1 < y2 - y1) {
		int mid = (y1 + y2) >> 1;
		int a1 = ask(x1, y1, x2, mid);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, x2, mid)) {
				rep (i, x1, x2) {
					rep (j, y1, mid) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, x2, mid, a1);
			}
		}
		if (a2) {
			if (a2 == siz(x1, mid + 1, x2, y2)) {
				rep (i, x1, x2) {
					rep (j, mid + 1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, mid + 1, x2, y2, a2);
			}
		}
	} else {
		int mid = (x1 + x2) >> 1;
		int a1 = ask(x1, y1, mid, y2);
		int a2 = las - a1;
		if (a1) {
			if (a1 == siz(x1, y1, mid, y2)) {
				rep (i, x1, mid) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(x1, y1, mid, y2, a1);
			}
		}
		if (a2) {
			if (a2 == siz(mid + 1, y1, x2, y2)) {
				rep (i, mid + 1, x2) {
					rep (j, y1, y2) {
						search(i, j, i, j, 1);
					}
				}
			} else {
				search(mid + 1, y1, x2, y2, a2);
			}
		}
	}
}
int main() {
	cin >> n >> m >> p >> MOD;
	pow2[0] = 1;
	rep (i, 1, 2500) {
		pow2[i] = pow2[i - 1] * 2 % MOD;
	}
	//search(0, 0, n - 1, m - 1, p);
	for (int i = 0; i < 50; i += 10) {
		for (int j = 0; j < 50; j += 10) {
			search(i, j, i + 9, j + 9, ask(i, j, i + 9, j + 9));
		}
	}
	cout << "! " <<  ans << endl;
	return 0;
}

Measured memory_bytes: 720
/**
 *    author        : Saurav Paul 
 *    created       : August 02, 2020 6:00 PM
 *    Problem Name  : A - Air Conditioner
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/abc174/tasks/abc174_a
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);

    int x ;
    cin >> x;

    cout << (x >= 30? "Yes" : "No") << endl ;


    return 0 ;
}


Measured memory_bytes: 3636
n=int(input())
m1=0
s1=0
m2=0
l=[]
for i in range(n):
  n1=int(input())
  l.append(n1)
  if n1>m1:
    m2=m1
    m1=n1    
    s1=0
  elif n1==m1:
    s1+=1
  elif n1>m2:
    m2=n1
if s1>0:
  for i in range(n):
    print(m1)
else:
  for i in range(n):
    if m1==l[i]:
      print(m2)
    else:
      print(m1)

Measured memory_bytes: 12532
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int N,Q;
string s;
vector<pair<char,char> > td;

bool sim_hidari(int x){
  for(int i=0;i<Q;i++){
    if(x==0) return true;
    if(x==N+1) return false;
    if(td[i].first==s[x]){
      if(td[i].second=='R') x++;
      else x--;
    }
  }
  if(x==0) return true;
  if(x==N+1) return false;
  return false;
}

bool sim_migi(int x){
  for(int i=0;i<Q;i++){
    if(x==0) return false;
    if(x==N+1) return true;
    if(td[i].first==s[x]){
      if(td[i].second=='R') x++;
      else x--;
    }
  }
  if(x==0) return false;
  if(x==N+1) return true;
  return false;
}

int main(){
  cin>>N>>Q;
  cin>>s;
  s="0"+s;
  char t,d;
  for(int i=0;i<Q;i++){
    cin>>t>>d;
    td.pb(make_pair(t,d));
  }

  int l,r,m;
  l=0;r=N+1;
  m=(l+r)/2;
  
  while(l<r-1){
    //printf("%d %d %d %d\n",l,r,m,sim_hidari(m));
    if(sim_hidari(m)) l=m;
    else r=m;
     m=(l+r)/2;
  }
  int res=l;

  l=0;r=N+1;
  m=(l+r)/2;  
  while(l<r-1){
    //printf("%d %d %d %d\n",l,r,m,sim_migi(m));
    if(sim_migi(m)) r=m;
    else l=m;
     m=(l+r)/2;
  }
  cout<<max(l-res,0)<<endl;
  return 0;
}


Measured memory_bytes: 1240
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100005;
const ll INF=(1LL<<60)-1;
ll a[MAXN],mx[MAXN];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<=n;i++)
        scanf("%lld",&a[i]);
    mx[0]=1;
    for(int i=0;i<=n;i++)
    {
        mx[i]-=a[i];
        if(mx[i]<0)return 0*printf("-1\n");
        mx[i+1]=min(mx[i]*2,INF);
    }
    ll res=0,now=0;
    for(int i=n;i>=0;i--)
    {
        now=min(mx[i],now)+a[i];
        res+=now;
    }
    return 0*printf("%lld\n",res);
}


Measured memory_bytes: 5388
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF=1e+09;
int main(){
    int N,H;
    cin >> N >> H;
    vector<int> a(N),b(N);

    rep(i,N) cin>>a[i]>>b[i];

    sort(a.begin(),a.end(),greater<int>());
    sort(b.begin(),b.end(),greater<int>());
    int ans=0;
    rep(i,N){
        ans++;
        if(b[i]>a[0]){
            H-=b[i];
        }else{
            H-=a[0];
            break;
        }
        if(H<=0){
            cout << ans << endl;
            return 0;
        }
    }
    while(H>0){
        ans++;
        H-=a[0];
    }
    cout << ans << endl;
}

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

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)


typedef long long ll;

int n;

bool input(){
  return cin>>n;
}

ll  solve(){

  const int N = 1000;
  const int M = N*2;
  const int L = M*2;

  ll val[M+1] = {0};
  ll num[L+1] = {0};

  rep(i,N+1)rep(j,N+1)val[i+j]++;
  rep(i,M+1)rep(j,M+1)num[i+j]+=val[i]*val[j];


  //rep(i,10)printf("%d ",num[i]);puts("");

  return num[n];
}

int main(){

  while(input()){
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1208
#include <iostream>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int n, a;
    map<ll, int> m;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a;

        if(m.find(a)!=m.end()) m.erase(a);
        else m.insert(make_pair(a, 1));

    }
    cout << m.size() << endl;
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  if (s == "RRR") {
    cout << "3";
  } else if (s == "RRS" || s == "SRR") {
    cout << "2";
  } else if (s == "SSS") {
    cout << "0";
  } else {
    cout << "1";
  }
	return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    long long n,m;
    cin >> n >> m;
    map<long long,bool> mp;
    long long a;
    rep(i,n+1){
        mp[i] = true;
    }
    rep(i,m){
        cin >> a;
        mp[a] = false;
    }
    long long dp[n+5];
    dp[0] = 1;
    dp[1] = mp[1];
    for(int i = 2;i<=n;i++){
        dp[i] = mp[i-2]*dp[i-2] + mp[i-1]*dp[i-1];
        dp[i]%=MOD;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int arr[n];
	int xr = 0;
	for(int i=0;i<n;i++){
		cin >> arr[i];
		xr ^= arr[i];
	}
	for(int i=0;i<n;i++){
		int temp = xr^arr[i];
		cout <<  temp  << " ";
	}
}

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

public class Hello
{
    public static void Main()
    {
        hoge();
        //System.Console.ReadLine();
    }

    public static void hoge()
    {
        var vars = System.Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var a = vars[0];
        var b = vars[1];
        var c = vars[2];
        var k = vars[3];
        long sum = 0;
        if(a <= k)
        {
            sum = a;
            k -= a;
        }
        else
        {
            System.Console.WriteLine(k);
            return;
        }

        if(b <= k)
        {
            k -= b;
        }
        else
        {
            System.Console.WriteLine(sum);
            return;
        }


        if (c <= k)
        {
            sum -= c;
            k -= c;
            System.Console.WriteLine(sum);
            return;
        }
        else
        {
            System.Console.WriteLine(sum - 1 * k);
            return;
        }
    }
}

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

int h, w, n, a[10001], ans[101][101];

void solve () {
    int c = 1, a_c = a[0];

    for (int i = 0; i < h; ++i) {
        if (i % 2 == 0) {
            for (int j = 0; j < w; ++j) {
                if (a_c == 0) {
                    c++;
                    a_c = a[c-1];
                }
                ans[i][j] = c;
                a_c--;
            }
        }
        else {
            for (int j = w-1; j >= 0; j--) {
                if (a_c == 0) {
                    c++;
                    a_c = a[c-1];
                }
                ans[i][j] = c;
                a_c--;
            }
        }
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w-1; ++j) {
            cout << ans[i][j] << " ";
        }
        cout << ans[i][w-1] << endl;
    }

}

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

    cin >> h >> w;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    solve();

    return 0;
}

Measured memory_bytes: 384
n = gets.to_i

as = []
n.times{
	as << gets.to_i
}

branch = []

as.each{ |x|
	isExists = false

	index = branch.bsearch_index{ |y| y < x }

	if index then
		branch[index] = x
	else
		branch << x
	end
}

puts branch.size


Measured memory_bytes: 3764
function main()
	N=parse(Int,readline())
	A=map(x->parse(Int,x),split(readline()))
	for c=A
		if c==0
			println(0)
			exit()
		end
	end
	T=1
	for c=A
		if T>div(10^18,c)
			println(-1)
			exit()
		end
		T*=c
	end
	println(T)
end
main()


Measured memory_bytes: 181400
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}

	sort.Ints(a)
	// s := make([]int, n)
	// s[0] = 0
	// for i := 1; i < n; i++ {
	// 	s[i] = gcd(s[i-1], abs(a[i]-a[i-1]))
	// }
	start := a[0]
	end := a[n-1]

	ans := math.Inf(1)

	for s := start; s <= end; s++ {
		cost := 0
		for i := 0; i < n; i++ {
			cost += (a[i] - s) * (a[i] - s)
		}
		if ans > float64(cost) {
			ans = float64(cost)
		}
	}

	fmt.Println(int(ans))
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}

	return gcd(b, a%b)
}

func abs(a int) int {
	if a < 0 {
		return -1 * a
	}
	return a
}


Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <ctype.h>

int main(void)
{
	char ch;

	while (1) {
		scanf("%c", &ch);

		if (islower(ch))
			printf("%c", toupper(ch));
		else if (isupper(ch))
			printf("%c", tolower(ch));
		else
			printf("%c", ch);

		if (ch == '\n')
			break;
	}

	return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,ans=0,s,e;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>s>>e;
    for(int j=s;j<=e;j++){
      ans++;
    }
  }
  cout<<ans<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    const int MAX_N = 100000;
    int N, K;
    cin >> N >> K;
    cout << 1 + ceil(N - K, K - 1) << endl;
    return 0;
}


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

#define rep(i, N) for(ll i = 0;i < N;i++)

typedef long long ll;

const int mod = 1e9 + 7;

using namespace std;



int main(void) {
	ll N; cin >> N;
	vector<ll> A(N);
	rep(i, N)cin >> A[i];

	vector<ll> S(N);
	S[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		S[i] = (S[i + 1] + A[i])%mod;
	}

	ll ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ans += (A[i] * S[i + 1])%mod;
		ans %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 6360
#include <stdio.h>
  
int main(){
	int a,b,ans,i;
	while(scanf("%d %d", &a, &b) != EOF){
		ans = a + b;
		for(i = 0; ans != 0; i++){
			ans = ans / 10;
		}
		printf("%d\n", i);
	}
return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;
	
	for (int i = sy; i < ty; i++) {
		cout << 'U';
	}
	for (int i = sx; i < tx; i++) {
		cout << 'R';
	}
	for (int i = ty; i > sy; i--) {
		cout << 'D';
	}
	for (int i = tx; i > sx; i--) {
		cout << 'L';
	}

	cout << 'L';
	for (int i = sy; i <= ty; i++) {
		cout << 'U';
	}
	for (int i = sx; i <= tx; i++) {
		cout << 'R';
	}
	cout << 'D';
	cout << 'R';
	for (int i = ty; i >= sy; i--) {
		cout << 'D';
	}
	for (int i = tx; i >= sx; i--) {
		cout << 'L';
	}
	cout << 'U';

	return 0;
}

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

int main()
{
   int a,b,c;
   cin>>a>>b>>c;
   set <int> color;
   color.insert(a);
   color.insert(b);
   color.insert(c);
   cout<<color.size()<<endl;
   return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS;

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,h=0,w=0,ans=0,sum = 1, Max = -1, Min = 3e9+1;
  string s;
  bool ok=true;
  cin >> n;
  MP mp;
  rep(i,n){
    cin >> x;
    auto itr = mp.find(x);
    if(itr != mp.end()){
      itr->second++;
    }
    else{
        mp.insert(make_pair(x,1));
    }
  }
  for( auto i = mp.begin(); i != mp.end();i++) { 
    if(i->second%2!=0){
      ans++;
    }
  }

  pri(ans);
  return 0;
}

Measured memory_bytes: 6528
#include<stdio.h>
#include <string.h>
#include<math.h>
#include<iostream>
using namespace std;

int main()
{
    char S[2000];
    int ans = 0;


    cin >> S;

    for (int i = 0; i < 1002; i++) {
        if (S[i] == '\0') {
            if (S[i - 1] == 's') {
                S[i] = 'e';
                S[i + 1] = 's';
                S[i + 2] = '\0';
            }
            else {
                S[i] = 's';
                S[i + 1] = '\0';
            }
            break;
        }
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            string sS = System.Console.ReadLine().Trim();
            int iN = int.Parse(sS);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            decimal iOut = 0M;
            if (iN == 1) { iOut = 1M; }
            else if (iN % 2 == 0) { iOut = 0.5M; }
            else { iOut = (decimal)(iN / 2 + 1) / (decimal)iN; }

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString());


            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


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

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.14159265

const ll maxn=2e5+1,mod=1e9+7;

vector<int> g[maxn];
vector<ll> combo;
vector<int> dp(maxn,0);
int n;

void dfs(int cur){
	dp[cur] = 1;
	int val = 0;
	cout<<cur<<endl;
	for(auto it:g[cur]){
		if(dp[it]==0) dfs(it);
		val = max(val,dp[it]);
	}
	dp[cur]+=val;
} 

void file(){
	#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
    #endif
}

int main(){

    sync
   // file();
    int m;
    cin>>n>>m;
    vector<int> in_deg(n+1);
    forn(i,m){
    	int u,v;
    	cin>>u>>v;
    	g[u].pb(v);
    	in_deg[v]++;
    }

    int ans = 0;
    queue<int> q;
    fore(i,1,n){
    	if(in_deg[i]==0) q.push(i);
    }
    while(!q.empty()){
   		vector<int> v;
   		// cout<<1<<endl;
   		while(!q.empty()){
   			int val = q.front();
   			q.pop();
   			// cout<<val<<endl;s
   			for(auto it:g[val]){
   				in_deg[it]--;
   				if(in_deg[it]==0) v.pb(it);
   			}
   			// q.pop();
   		}

   		while(!v.empty()){
   			// cout<<v.back()<<endl;
   			q.push(v.back());
   			v.pop_back();
   		}
   		ans++;
    }
    cout<<ans-1;   

}

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

int cost[22][22]={0};


int main(){
	int n,m,i,j,k,a,b,c,d;
	char cc;
	cin>>n>>m;
	for(i=1;i<=n;i++)
		for(j=1;j<=n;j++)
			cost[i][j] = 1<<28;
	for(i=0;i<m;i++){
		cin>>a>>cc>>b>>cc>>c>>cc>>d;
		cost[a][b]=c;cost[b][a]=d;
	}
	for(k=1;k<=n;k++)
	  for(i=1;i<=n;i++)
	    for(j=1;j<=n;j++)
		cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
	cin>>a>>cc>>b>>cc>>c>>cc>>d;
	cout << c-d-cost[a][b]-cost[b][a] << endl;
}

Measured memory_bytes: 1160
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
# import sys
# sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)

def main():
    k, x = map(int, input().split())
    if 500 * k >= x:
        print("Yes")
    else:
        print("No")
    # n, m = map(int, input().split())
    # a = list(map(int, input().split()))

    # g = lcm(a[0], a[1])
    # for i in range(2, n):
    #     g = lcm(g, a[i])
    # if g // 2 > m:
    #     print(0)
    #     exit()
    # print(g)
    # print(math.ceil(m//g + 0.5))



    


if __name__ == '__main__':
    main()


Measured memory_bytes: 5588
var  a,b,c,d:longint;
     s:string;
     
begin
  readln(s);
  a:=ord(s[1])-ord('0');
  b:=ord(s[2])-ord('0');
  c:=ord(s[3])-ord('0');
  d:=ord(s[4])-ord('0');
  if  a+b+c+d=7  then
    begin  writeln(a,'+',b,'+',c,'+',d,'=7');  exit;  end;
  if  a+b+c-d=7  then
    begin  writeln(a,'+',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c+d=7  then
    begin  writeln(a,'+',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c+d=7  then
    begin  writeln(a,'-',b,'+',c,'+',d,'=7');  exit;  end;
  if  a-b-c+d=7  then
    begin  writeln(a,'-',b,'-',c,'+',d,'=7');  exit;  end;
  if  a-b+c-d=7  then
    begin  writeln(a,'-',b,'+',c,'-',d,'=7');  exit;  end;
  if  a+b-c-d=7  then
    begin  writeln(a,'+',b,'-',c,'-',d,'=7');  exit;  end;
  if  a-b-c-d=7  then
    begin  writeln(a,'-',b,'-',c,'-',d,'=7');  exit;  end;
end.

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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{
    int n, se[112345];

    memset(se, -1, sizeof(se));

    cin >> n;

    cout << 0 << endl;

    string s;
    cin >> s;

    if (s == "Vacant")
        return 0;

    se[0] = s == "Female";
    se[n - 1] = s == "Male";
    se[1] = s == "Male";

    int l = 0, r = n - 1;

    int cnt = 1;
    while (cnt < 20)
    {
        int mid = (r + l) / 2;

        cout << mid << endl; // " " << l << " " << r << " " << se[l] << endl;

        string s;
        cin >> s;

        if (s == "Vacant")
            break;

        int sn = s == "Female";

        se[mid] = sn;
        if (se[mid + 1] == -1)
            se[mid + 1] = 1 - sn;
        if (se[mid - 1] == -1)
            se[mid - 1] = 1 - sn;

        if ((mid - l) % 2 == 0)
        {
            if (sn == se[l])
            {
                l = mid + 1;
            }
            else
            {
                r = mid - 1;
            }
        }
        else
        {
            if (sn == se[l])
            {
                r = mid - 1;
            }
            else
            {
                l = mid + 1;
            }
        }

        cnt++;
    }

    return 0;
}

Measured memory_bytes: 1360
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

long long ans[105];

long long gcd(long long a,long long b){
    if (a > b){
        long long temp = a;
        a = b;
        b = temp;
    }
    while(b%a!=0){
        long long temp = b%a;
        b = a;
        a = temp;
    }
    return a;
}

long long lcm(long long a ,long long b){
    long long temp = gcd(a,b);
    long long result = temp*(a/temp)*(b/temp);
    return result;
}

int main(){
    int T;
    scanf("%d",&T);
    for(int i = 0;i < T;i++){
        scanf("%lld",&ans[i]);
    }
    sort(ans,ans+T);
    if (T==1){
        printf("%lld",ans[0]);
        return 0;
    }
    long long result = lcm(ans[0],ans[1]);
    for (int i = 2; i < T;i++){
        result = lcm(result,ans[i]);
    }
    printf("%lld",result);
    return 0;
}


Measured memory_bytes: 256
N=int(input())
'''
4hnw=N(hn+nw+wh)
=(n+w)Nh + nwN
0=(Nw+Nn-4nw)h + nwN
h = -(nwN)/(Nw+Nn-4nw)
'''
for w in range(1,3501):
	for n in range(1,3501):
		if (N*w+N*n!= 4*n*w) :
			h = -(n*w*N)/(N*w+N*n-4*n*w)
			if  h==int(h) and h > 0:
			  print(int(h),n,w)
			  exit(0)

Measured memory_bytes: 68860
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll keta(ll n) {  // 正整数nの桁数
    ll res = 0;
    while(n != 0) {
        res++;
        n /= 10;
    }
    return res;
}

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

    ll ans = 100;
    for(ll i = 1; i*i <= n; i++) {
        if(n%i == 0) {
            ll x = i;
            ll y = n/i;
            chmin(ans, max(keta(x), keta(y)));
        }
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
N = int(input())
L = [i for i in range(1,N+1) if i%2 != 0]
ans = 0
for i in L:
    count = 0
    for j in range(1,i+1):
        if i%j == 0:
            count += 1
    if count == 8:
        ans += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds; 
using namespace std;

using   ll=long long;
using   ld=long double;

#define fast        	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ordered_set 	tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
#define endl        	"\n"
#define int         	long long int  
#define pb          	push_back
#define mp          	make_pair
#define F           	first
#define S           	second
#define ALL(v)      	v.begin(),v.end()
#define ALLR(v)     	v.rbegin(),v.rend()
#define pii         	3.14159265358979323
#define inf     		LLONG_MAX
#define ones(x)     	__builtin_popcount(x)
#define fill(a,b)   	memset(a,b,sizeof(a))
#define mod 			1000000007



const int N = 200005;

int vis[N];

void solve()
{
	ll n,k;
	
	cin>>n>>k;
	
	int a[n+1];
	
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	
	ll tot = 1;
	
	vis[1] = 1;
	
	int id = 1;
	
	while(vis[a[id]] == 0)
	{
		id = a[id];
		
		vis[id] = 1;
		
		tot++;
	}
	
	if(k < tot)
	{
		
		fill(vis,0);
		
		vis[1] = 1;
	
		id = 1;
		
		k--;
		
		while(vis[a[id]] == 0)
		{
			if(k == 0)	
			{
				cout<<a[id];
				return;
			}
			
			id = a[id];
			
			vis[id] = 1;
			
			k--;
		}
	}
	else
	{
		fill(vis,0);
		
		vis[1] = 1;
	
		id = 1;
		
		while(vis[a[id]] == 0)
		{
			id = a[id];
			
			vis[id] = 1;
		}
		
		fill(vis,0);
		
		id = a[id];
		
		vis[id] = 1;
		
		vector<int> seq;
		
		seq.pb(id);
		
		while(vis[a[id]] == 0)
		{
			id = a[id];
			
			vis[id] = 1;
			
			seq.pb(id);
		}
		
		k = k - tot + seq.size();
		
		cout<<seq[k%seq.size()];
		
		return;
	}
}


signed main()
{
 
    fast;
 
    ll t;
    
    t=1;
    
    //cin>>t;
    
    while(t--)
    {
        solve();
    }
 
    return 0;
}


Measured memory_bytes: 8324
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll MOD=1e9+7;
const ll N=2e5+5;
const ld pi=3.14159265359;
const ll INF=(1LL<<63);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()
 
ll x,s;
 
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	REP(i,3)cin>>x,s+=x;
	cout<<(s>=22?"bust\n":"win\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);
        
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.printf("%d %d %.10f\n", a/b, a%b, (double)a/(double)b);
    }
}


Measured memory_bytes: 26440
N = int(input())
S = input()

Slist = list(S)

count = 0

Slist.append('0')
Slist.append('0')

for i in range(N):
  if Slist[i] == 'A':
    if Slist[i+1] == 'B':
      if Slist[i+2] == 'C':
        count = count + 1


print(count)

#print('N = ', N)
#print('S = ', S)
#print('Slist = ', Slist)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define MP make_pair
#define PB push_back
#define X first
#define Y second
#define SZ(a) (LL)((a).size())
const int INF = 1000 * 1000 * 1000 + 47;
const int mod = 1000 * 1000 * 1000 + 7;
int add(int a , int b)
{
	return a + b >= mod ? a + b - mod : a + b;
}
int sub(int a , int b)
{
	return a - b < 0 ? a - b + mod : a - b;
}
int mult(int a , int b)
{
	return a *(LL)b % mod;
}
void Add(int &a , int b)
{
	a = add(a , b);
}

int modPow(int a , int step)
{
	int ans = 1;
	while(step)
	{
		if(step & 1)
			ans = mult(ans , a);
		a = mult(a , a);
		step >>= 1;
	}
	return ans;
}
int fact[100005];
int inv[100005];
void init()
{
	fact[0] = inv[0] = 1;
	for(int i = 1; i < 100005; i++)
	{
		fact[i] = mult(fact[i - 1] , i);
		inv[i] = modPow(fact[i] , mod - 2);
	}
}
int c(int n , int k)
{
	if(n < k)
		return 0;
	return mult(fact[n] , mult(inv[k] , inv[n - k]));
}
int dp[17][1 << 16];
int n , m;
int a[16];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	init();
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n >> m;
	for(int i = 0; i < m; i++)
		cin >> a[i];
	sort(a , a + m);
	reverse(a , a + m);
	dp[0][0] = 1;
	for(int i = 0; i < m; i++)
	{
		for(int s = 0; s < (1 << n); s++)
		{
			for(int bit = 0; bit < n; bit++)
			{
				if((s >> bit) & 1)
					continue;
				Add(dp[i + 1][s | (1 << bit)] , mult(fact[1 << bit] , mult(c((1 << n) - a[i] - s , (1 << bit) - 1) , dp[i][s])));
			}
			Add(dp[i + 1][s] , dp[i][s]);
		}
		
	}
	int ans = 0;
	for(int i = 0; i < (1 << n); i++)
	{
		ans = (__builtin_popcount(i) & 1) ? sub(ans , mult(dp[m][i] , fact[(1 << n) - i - 1])) : add(ans , mult(dp[m][i] , fact[(1 << n) - i - 1]));
	}
	ans = mult(ans , 1 << n);
	cout << ans;
	return 0;
}


Measured memory_bytes: 5120
//----------------------------------------------------------------------
#include <algorithm>
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

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

int main(void) {
    ll n; cin >> n;
    vector<ll> a(5);

    rep(i, 5) {
        cin >> a[i];
    }

    ll min_v = a[0];

    for(int i = 0; i < 5; ++i) {
        if(min_v>a[i]) {
            min_v = a[i];
        }
    }

    ll ans = ceil((double)n / min_v);
    ans += 4;

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


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


def solve(n: int, a: "List[int]"):
    a.sort()
    n = a[-1]
    a = a[0:len(a)-1]
    maxDiff = 0
    maxK = a[0]
    for k in a:
        if maxDiff <= min(n-k, k):
            maxDiff = min(n-k, k)
            maxK = k
    print(str(n) + " " + str(maxK))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(n)]  # type: "List[int]"
    solve(n, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 15940
import java.util.*;
import java.math.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] nums = new int[num];
		int minusNum = 0, zeroNum = 0, min = 1000000000;
		BigInteger ans = BigInteger.ZERO;
		for(int i = 0; i < num; i++) {
			nums[i] = sc.nextInt();
			if(nums[i] == 0) {
				zeroNum++;
			} else if(nums[i] < 0) {
				minusNum++;
				nums[i] = -nums[i];
			}
			min = min > nums[i] ? nums[i] : min;
			ans = ans.add(BigInteger.valueOf(nums[i]));
		}
		if(zeroNum == 0 && minusNum % 2 == 1) {
			ans = ans.subtract(BigInteger.valueOf(min*2));
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 61200
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;

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

  int a, b;
  cin >> a >> b;

  if(a <= 8 && b <= 8) cout << "Yay!" << endl;
  else cout << ":(" << endl;

  return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, BufRead};

fn main() {
    // stdin()のロックを取得
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let stdin = &mut stdin;

    let mut buildings = [
        Building::default(),
        Building::default(),
        Building::default(),
        Building::default(),
    ];

    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();

    for _ in 0..buf.trim().parse::<i32>().unwrap() {
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();

        let mut input_line = buf.split_whitespace();
        let building = input_line.next().unwrap().parse::<usize>().unwrap();
        let floor = input_line.next().unwrap().parse::<usize>().unwrap();
        let room = input_line.next().unwrap().parse::<usize>().unwrap();
        let resident = input_line.next().unwrap().parse::<i32>().unwrap();
        buildings[building - 1].floor[floor - 1].room[room - 1] += resident;
    }

    let mut output = String::with_capacity(200);
    for index in 0..buildings.len() {
        let building = &buildings[index];
        for floor in building.floor.iter() {
            for &room in floor.room.iter() {
                output.push_str(&format!(" {}", room));
            }
            output.push_str("\n");
        }
        if index < 3 {
            output.push_str("####################\n")
        }
    }
    print!("{}", output);
}

#[derive(Default)]
struct Building {
    floor: [Floor; 3],
}
#[derive(Default)]
struct Floor {
    room: [i32; 10],
}



Measured memory_bytes: 5036
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
#define int long long

int a[2500], b[2500], c[2500];
ll d[1500];
bool used[1500];
vector<int>E[1500];
void dfs(int v) {
	used[v] = 1;
	for (int u : E[v]) {
		if (!used[u])dfs(u);
	}
}
signed main() {
	int n, m; scanf("%lld%lld", &n, &m);
	rep(i, m) {
		scanf("%lld%lld%lld", &a[i], &b[i], &c[i]); a[i]--; b[i]--;
		E[b[i]].push_back(a[i]);
	}
	fill(d, d + n, LLONG_MIN);
	d[0] = 0;
	dfs(n - 1);
	rep(i, n) {
		bool update = false;
		rep(j, m) {
			if (d[a[j]] != LLONG_MIN&&d[b[j]] < d[a[j]] + c[j]) {
				d[b[j]] = d[a[j]] + c[j];
				if(used[b[j]])update = true;
			}
		}
		if (i == n - 1 && update) {
			puts("inf"); return 0;
		}
	}
	printf("%lld\n", d[n - 1]);
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

const int BITS = 60;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;
    vl ct(BITS);
    for (ll i = 0, j; i < n; i++) {
        cin >> j;
        for (ll k = 0; k < BITS; k++) {
            if ((1LL << k) & j) ct[k]++;
        }
    }

    ll res = 0, ans = 0;
    for (ll i = BITS - 1; i >= 0; i--) {
        if (ct[i] < n - ct[i] and res + (1LL << i) <= k) {
            res += (1LL << i);
            ans += (n - ct[i]) * (1LL << i);
        }
        else ans += ct[i] * (1LL << i);
    }

    cout << ans << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/
/*
7 4 0 3

1001

0111
0100
0000
0011

0221
4223


dp:


*/

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());

int main(){
	int a[4];
	rep(i,4){
		cin>>a[i];
		// cout<<a[i]<<endl;
	}
	int s=0;
	rep(i,4){
		s+=a[i];
	}
	// cout<<s<<endl;
	int b[]={60,1};
	int c[2]={0};
	rep(i,2){
		while(s>=b[i]){
			s-=b[i];
			c[i]++;
		}
	}
	cout<<c[0]<<endl<<c[1]<<endl;
	return 0;
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  if(s == "Cloudy") cout << "Rainy" << endl;
  if(s == "Rainy") cout << "Sunny" << endl;
}

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


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
int n;
long long k;
long long p[5010],c[5010];
long long mx=-1e18;
long long a[5010][5010];
long long sz[5010][5010];
/*
void dfs(int beg,int x,int num,long long sum){
	if(num>0){
		if(s.find(x)!=s.end()){
			return ;
		}
		s.insert(x);
		mx1[beg]=max(mx1[beg],sum);
		a[beg][num]=sum;
		make[beg]=sum;
	}
	dfs(beg,p[x],num+1,sum+c[p[x]]);
}
*/
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			sz[i][j]=1e9+10;
		}
	}
	for(int i=1;i<=n;i++){
		cin>>p[i];
	}
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=1;i<=n;i++){
		int j=p[i];
		long long sum=c[p[i]];
		int num=1;
		while(i!=j){
			a[i][j]=sum;
			sz[i][j]=num;
			sum+=c[p[j]];
			j=p[j];
			num++;
		}
		a[i][i]=sum;
		sz[i][i]=num;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(sz[i][j]>k)continue;
			long long tmp=(k-sz[i][j])/sz[i][i];
			if(a[i][i]>0)mx=max(mx,tmp*a[i][i]+a[i][j]);
			else mx=max(mx,a[i][j]);
		}
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 395100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//解説写し
const int INF=1001001001;
int a[12][12];

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>c(n);
  rep(i,n){
    cin>>c[i];
    rep(j,m)cin>>a[i][j];
  }
  int ans =INF;
  rep(s,1<<n){
    int cost=0;
    vector<int>d(m);
    rep(i,n){
      if(s>>i&1){
        cost+=c[i];
        rep(j,m)d[j]+=a[i][j];
      }
    }
    bool ok=true;
    rep(j,m)if(d[j]<x)ok=false;
    if(ok)ans=min(ans,cost);
  }
  if(ans==INF)cout<<-1<<endl;
  else cout<<ans<<endl;
  return 0;
}
          

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

using namespace std;

const long long MAX = 1e18;
#define int long long

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    
    int n;
    cin >> n;
    vector<long long> v(n);
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }
    long long ans = 1LL;
    int pos = -1;
    for(int i = 0; i < n; i++) {
        if(v[i] == 0) {
            pos = i;
        }
    }
    if(pos != -1) {
        cout << "0\n";
        return 0;
    }
    pos++;
    while(ans <= (MAX / v[pos]) && pos < n) {
        ans = ans * v[pos];
        pos++;
        if(ans > MAX) {
            cout << "-1\n";
            return 0;
        }
        if(pos == n) break; 
    } 
    if(pos == n)  
        cout << ans << "\n";
    else 
        cout << "-1\n";
    
    return 0;
}


Measured memory_bytes: 3992
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int mod = 1e9+7;
ll gcd(ll a,ll b){
    if(b==0)
    return a;return gcd(b,a%b);
}
ll expo(ll base,ll pow){
    ll ans = 1;
    while(pow!=0){
        if(pow&1==1){
            ans = ans*base;
            ans = ans%mod;
        }
        base *= base;base%=mod;
        pow/=2;
    }return ans;
}
ll inv(ll x){
    return expo(x,mod-2);
}

const int M = 5e5 + 5;
int arr[M], n;

int segTree[4*M][26];

void merge(int node){
    for(int i = 0 ; i < 26 ; i++){
        segTree[node][i] = segTree[2*node][i] + segTree[2*node + 1][i];
    }
}

void build(int node, int l, int r){
    if(l > r) return;
    if(l == r){
        segTree[node][arr[l]] = 1;
        return;
    }
    int mid = (l + r)/2;
    build(2*node , l , mid);
    build(2*node + 1 , mid + 1 , r);
    merge(node);
}

void update(int node , int l, int r, int point , int val){
    if(l > point || r < point) return;

    if(l == r){
        for(int i = 0 ; i < 26 ; i++){
            segTree[node][i] = 0;
        }
        segTree[node][val] = 1;
        return;
    }

    int mid = (l + r)/2;
    update(2*node , l , mid , point, val);
    update(2*node + 1 , mid + 1 , r , point, val);

    merge(node);
}

vector<int> query(int node , int l, int r , int ql , int qr){
    vector<int> vec;
    if(l > qr || r < ql) return vec;

    if(l >= ql && r <= qr){
        for(int i = 0 ; i < 26 ; i++){
            if(segTree[node][i] > 0) vec.push_back(i);
        }
        return vec;
    }

    int mid = (l + r)/2;
    vector<int> v1 = query(2*node , l, mid , ql , qr);
    vector<int> v2 = query(2*node + 1 , mid + 1, r , ql , qr);
    set<int> se;
    for(int i = 0 ; i < v1.size() ; i++){
        if(se.count(v1[i])) continue;
        se.insert(v1[i]);
        vec.push_back(v1[i]);
    }
    for(int i = 0 ; i < v2.size() ; i++){
        if(se.count(v2[i])) continue;
        se.insert(v2[i]);
        vec.push_back(v2[i]);
    }
    return vec;
}

int main(){

    si(n);

    string str;
    cin >> str;

    for(int i = 0 ; i < n ; i++){
        arr[i + 1] = str[i] - 'a';
    }

    build(1 , 1 , n);

    int q;
    si(q);


    while(q--){
        int typ;
        si(typ);

        if(typ == 1){
            int pos;
            char ex;
            si(pos);
            cin >> ex;

            update(1 , 1 , n , pos , ex - 'a');

        }
        else{
            int ql, qr;
            si(ql);  si(qr);
           /* vector<int> v1= query(1 , 1 , n , ql , qr);
            for(int i = 0 ; i < v1.size() ; i++){
                cout<<v1[i]<<endl;
            }*/
            printf("%d\n" , query(1 , 1 , n , ql , qr).size());
        }


    }
}



Measured memory_bytes: 111876
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int a[50],n,i,j,temp;
    n=10;
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<(n-1);i++){
        for(j=0;j<(n-1)-i;j++){
            if(a[j]<a[j+1]){
                temp=a[j];
                a[j]=a[j+1];
                a[j+1]=temp;
            }
        }
    }
    for(i=0;i<3;i++)
        printf("%d\n",a[i]);
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  ll N;
  cin>>N;
  vector<ll> p(N);
  for(ll i=0;i<N;i++) {
cin>>p[i];
  }
  
  ll ans=0;
  for(ll i=1;i<N-1;i++) {
if(p[i]>p[i+1]&&p[i]<p[i-1]) {
ans++;
}
    else if(p[i]<p[i+1]&&p[i]>p[i-1]) {
ans++;
    }
  }
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3612