akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let (n, k) = get!(usize, usize);
    let mut x_order = get!(i64, i64; n);
    let mut y_order = x_order.clone();

    x_order.sort_by_key(|xy| xy.0);
    y_order.sort_by_key(|xy| xy.1);

    let mut ans = i64::max_value();

    let mut deq = VecDeque::with_capacity(256);
    for i1 in 0..n {
        for i2 in i1 + 1..n {
            deq.clear();
            let l = x_order[i1].0;
            let r = x_order[i2].0;
            for &(x, y) in &y_order {
                if l <= x && x <= r {
                    deq.push_back(y);

                    if deq.len() == k {
                        ans = min(ans, (r - l) * (deq.back().unwrap() - deq.front().unwrap()));
                        deq.pop_front();
                    }
                }
            }
        }
    }

    println!("{}", ans);
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 100000+10;
const ll oo  = numeric_limits<ll>::max();
ll dp[maxn],A[maxn];
int N,K;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	forn(i,0,N)cin >> A[i];
	dp[0] = 0;
	forn(i,1,N){
		dp[i] = oo;
		forn(j,max(i-K,0),i){
			dp[i] = min(dp[i],dp[j]+abs(A[j]-A[i]));
		}
	}
	cout << dp[N-1] << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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


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

  int n; cin >> n;
  vector<int> N(n);
  rep(i,n) cin >> N[i];
  int mx = 0;
  rep(i,n){
    mx = max(mx,N[i]);
  }

  int mi = 0;
  for(int i = 1; i <= mx; i++){
    int sum = 0;
    rep(j,n){
      int x = i - N[j];
      sum += x * x;
    }
    if(mi == 0) mi = sum;
    mi = min(mi, sum);
  }

  cout << mi << endl;

  return 0;
}

Measured memory_bytes: 256
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <iostream>
#include <unordered_set>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, M;
	cin >> N >> M;
	unordered_set<int> a;
	for (int i = 0; i < M; ++i)
	{
		int tmp;
		cin >> tmp;
		a.insert(tmp);
	}

	vector<unsigned long> stairs(N);
	stairs[0] = a.find(1) == a.end() ? 1 : 0;
	stairs[1] = a.find(2) == a.end() ? stairs[0] + 1 : 0;
	for (int i = 2; i < N; ++i)
	{
		stairs[i] = a.find(i + 1) == a.end() ? ((stairs[i - 2] + stairs[i - 1]) % 1000000007) : 0;
	}
	cout << stairs[N - 1] % 1000000007 << endl;
	return 0;
}


Measured memory_bytes: 5156
s = input()
end = (len(s)-1)//2
start = (len(s)+3)//2
if s[0:end] == s[end-1::-1]:
    if s[start-1::] == s[-1:start-2:-1]:
        if s[0::] == s[::-1]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
// C - Guess The Number
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define NG puts("-1")

int main(){
	int N,M; cin>>N>>M;
	string T(N,'-');
	while(M--){
		int s,c; cin>>s>>c; s--, c+='0';
		if(T[s] !='-' && T[s] != c){ NG; return 0; }
		if(N!=1 && s==0 && c=='0'){ NG; return 0; }
		T[s] = c;
	}

	while(N--){
		if(T[N]=='-'){
			if(T.size()==1){
					T[N] = '0';
			}
			else{
				if(N==0){
					T[N] = '1';
				}
				else{
					T[N] = '0';
				}
			}
		}
	}
	cout<< stoi(T) <<endl;
}


Measured memory_bytes: 256
Sd = input()
T = input()
result = None

for i in range(len(Sd) - len(T), -1, -1):
    flag = True
    for j, k in zip(range(i, i+len(T)), T):
        if Sd[j] != k and Sd[j] != '?':
            flag = False
            break

    if flag:
        Sd_List = list(Sd)
        for j, k in zip(range(i, i+len(T)), T):
            Sd_List[j] = k
        Sd = "".join(Sd_List)
        result = Sd.replace('?', 'a')
        break

print(result if result else 'UNRESTORABLE')


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;

ll solve() {
    ll a, b1; cin >> a >> b1; // b: integer part of a decimal
    char c; cin >> c; // capture decimal point "."
    ll b2; cin >> b2; // capture decimal part
    ll d = b1 * 100 + b2;
    return a * d / 100;
}

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

	cout << solve() << endl;
}


Measured memory_bytes: 3608
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
s=[list() for i in range(n)]
for i in range(n):
	a,b=l[i]
	for j in range(i):
		c,d=l[j]
		s[i].append((a-c,b-d))
		s[i].append((c-a,d-b))
D=set()
for i in range(n):
	D=D|set(s[i])
ans=0
for x in D:
	cnt=0
	for k in s:
		cnt+=k.count(x)
	ans=max(ans,cnt)
print(n-ans)

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);++i)
#define rep2(i,a,b) for (int i=(a);i<(b);++i)
#define rrep(i,n) for (int i=(n)-1;i>=0;--i)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;--i)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cout<<(#v)<<":";for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;
#define printVS(vs) cout<<(#vs)<<":"<<endl;for(auto(s):(vs)){cout<<(s)<< endl;}
#define printVV(vv) cout<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cout<<" "<<(x);}cout<<endl;}
#define printP(p) cout<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cout<<(#vp)<<":"<<endl;for(auto(p):(vp)){cout<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cout << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cout << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1e9;
const int mod = 1e9 + 9;
using Graph = vector<vector<int>>;

using Vec = vector<int>;
using Mat = vector<Vec>;

Mat mulMatMat(const Mat& a, const Mat& b) {
    int n = a.size();
    int m = b[0].size();
    assert(a[0].size() == b.size());
    Mat c(n, Vec(m, 0));
    rep(i, n) {
        rep(j, m) {
            rep(k, a[0].size()) {
                (c[i][j] += (a[i][k] * b[k][j]) % mod) %= mod;
            }
        }
    }
    return c;
}

Vec mulMatVec(const Mat& a, const Vec& v) {
    int n = a.size();
    assert(a[0].size() == v.size());
    Vec c(n, 0);
    rep(i, n) {
        rep(j, a[0].size()) {
            (c[i] += a[i][j] * v[j]) %= mod;
        }
    }
    return c;
}


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

    int w, h, n;
    int testcase = 1;
    while (cin >> w >> h >> n, w) {
        map<int, vi> mp;
        rep(i, n) {
            int c, r;
            cin >> c >> r;
            c--; r--;
            mp[r].emplace_back(c);
        }
        mp[h - 1];

        Mat A(w, Vec(w, 0));
        rep(i, w) {
            for (int j = max(0ll, i - 1); j <= min(w - 1, i + 1); j++) {
                A[i][j] = 1;
            }
        }

        Vec v(w, 0);
        v[0] = 1;

        int c = 0;
        for (auto p : mp) {
            int nc; vi vr;
            tie(nc, vr) = p;

            Mat B = A;
            for (int i = nc - c; i > 0; i >>= 1) {
                if (i & 1) {
                    v = mulMatVec(B, v);
                }
                B = mulMatMat(B, B);
            }

            for (auto i : vr) {
                v[i] = 0;
            }

            c = nc;
        }

        cout << "Case " << testcase++ << ": " << v.back() << endl;
    }
}

Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define INF 999999999
#define rep(i, n) for(int i = 0;i < n;i++)
#define pb(n) push_back(n)
#define sort(n) sort(n.begin(), n.end());
#define Ivec vector<int>
#define Svec vector<string> 
int main() {
  lli A,B,C,D=0;
  string E,F;
  cin >> E >> F;
  E+=F;
  A=stoi(E);
  B=sqrt(A);
  if(B*B==A)cout << "Yes" << endl;
  else cout << "No" <<endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
	while(b){
		a%=b;
		swap(a,b);
	}
	return a;
}
int main()
{     

	int k;
	cin>>k;
     int res=0;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int p=1;p<=k;p++){
                int pihu=gcd(j,p);
                int lallu=gcd(pihu,i);
                res+=lallu;
			}
		}
	}
	
     cout<<res<<"\n";
   
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main() {
	vector<int> a(3);
	cin >>a.at(0)>>a.at(1)>>a.at(2);
	sort(a.begin(), a.end());
  if(a.at(1)+a.at(0)>a.at(2)||a.at(1)+a.at(0)<a.at(2))
	cout << "No"<<endl;
  else if(a.at(1)+a.at(0)==a.at(2)){
  cout<<"Yes"<<endl;
  }
}

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



/****
 * max differnce can be 1
 * if there's no difference, either everyone falls under a group of at least 2 or everyone is unique
 * if there's a difference, all those who see smaller number are unique, and everyone remaining falls under a
 * group of at least 2 
 */


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

    int n; cin >> n;

    vector <int> arr(n);
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    sort(arr.begin(), arr.end());

    bool flag = true;

    if (arr.back() - arr.front() > 1)
        flag = false;
    else if (arr.back() == arr.front())
    {
        if (n < 2*arr.front()  and n != arr.front()+1)
            flag = false;
    }
    else
    {
        int unique = count(arr.begin(), arr.end(), arr.front());
        int rem_cats = n - unique, rem_groups = arr.back() - unique;

        if (rem_cats < 2*rem_groups or rem_groups < 1)
            flag = false;
    }

    cout << (flag ? "Yes\n" : "No\n") << endl;
    
    return 0;
}

Measured memory_bytes: 640
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [list(input())[:-1] for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H,W,K = map(int,input().split())
P = [list(input())[:-1] for _ in range(H)]
num= 1
cur = 1
flag = [0]*H
ans = [[0]*W for _ in range(H)]
for i in range(H):
    count = 0
    li = [0]*W
    for j in range(W):
        if P[i][j] == "#":
            count += 1
    if count == 0:
        flag[i] = 1
    else:
        judge = 0
        d = 0
        for j in range(W):
            if P[i][j] == "." or d == 1:
                ans[i][j] = num
            else:
                ans[i][j] = num
                judge += 1
                if judge == count:
                    d = 1
                else:
                    num += 1
        num += 1
for i in range(H):
    if flag[i] == 0:
        index = i
        break
for i in range(index):
    flag[i] = 0
    for j in range(W):
        ans[i][j] = ans[index][j]
for i in range(H):
    if flag[i] == 1:
        for j in range(W):
            ans[i][j] = ans[i-1][j]
for i in range(H):
    print(*ans[i])

Measured memory_bytes: 18300
# coding: utf-8

import queue

def main():
	H, W = (int(x) for x in input().split())
	S = [[] for x in range(H)]

	for i in range(H):
		S[i] = [x for x in input()]

	max_d = [[-1 for x in range(W)] for y in range(H)]
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			d = [[-1 for x in range(W)] for y in range(H)]
			q = queue.Queue()
			q.put([i, j])
			d[i][j] = 0
			while not q.empty():
				n = q.get()
				for y, x in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
					if (n[0] == 0   and y == -1) or\
					   (n[0] == H-1 and y ==  1) or\
					   (n[1] == 0   and x == -1) or\
					   (n[1] == W-1 and x ==  1) or\
					   S[n[0]+y][n[1]+x] == "#"  or\
					   d[n[0]+y][n[1]+x] != -1:
						continue
					d[n[0]+y][n[1]+x] = d[n[0]][n[1]] + 1
					q.put([n[0]+y, n[1]+x])
			for y in range(H):
				for x in range(W):
					if max_d[i][j] < d[y][x]:
						max_d[i][j] = d[y][x]

	max = 0
	for i in range(H):
		for j in range(W):
			if max < max_d[i][j]:
				max = max_d[i][j]

	print(str(max))

if __name__ == "__main__":
	main()

Measured memory_bytes: 4080
import java.util.*;
class Main
{
    public static void main(String[] args)
    {
        
        Scanner sc = new Scanner(System.in);
        
        String a = sc.next();
        
        switch (a) {
            case "Sunny":
                System.out.println("Cloudy");
                break;
            case "Cloudy":
                System.out.println("Rainy");
                break;
            case "Rainy":
                System.out.println("Sunny");        
                break;
        }
       
    }
}

Measured memory_bytes: 19668
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;

int main() {
	int N;
	int A[200000];
	int cnt[200000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i]--;
	}

	for (int i = 0; i < N; i++) {
		cnt[i] = 0;
	}
	for (int i = 0; i < N; i++) {
		cnt[A[i]] += 1;
	}
	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ans += (long long)cnt[i] * (cnt[i] - 1) / 2;
	}
	for (int i = 0; i < N; i++) {
		if (cnt[A[i]] > 1) {
			cout << ans - cnt[A[i]] + 1 << "\n";
		}
		else {
			cout << ans << "\n";
		}

	}



}

Measured memory_bytes: 4096
/************************************************
* Author        :RunningTime
* Created Time  :2017/7/29 20:02:13
* File Name     :A.cpp
 ************************************************/

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

typedef long long ll;
typedef pair<int,int> pii;
const int N = 1e5 + 5;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << "ABC" << n << '\n';
    return 0;
}


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

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


int main(){

  ll n;
  cin >> n;
  map<ll, ll> mp;
  ll a,b;
  rep(i,n){
    cin >> a >> b;
    mp[b] += a;
  }

  bool ok = true;
  ll t = 0;
  for(auto itr : mp){
    t += itr.second;
    if(t > itr.first){
      ok = false;
      break;
    }
  }

  if(ok){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}



Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define fast_io cin.tie(0);ios_base::sync_with_stdio(0);
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cout << endl; }
void show() { cout << endl; }
void pret() { cout << endl; exit(0);}
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cout << " " << to_string(H); debug_out(T...);}
template <typename Head, typename... Tail> void show(Head H, Tail... T) {cout <<H<<" "; show(T...);}
template <typename Head, typename... Tail> void pret(Head H, Tail... T) {cout <<H<<" "; pret(T...);}
#define pr(...) cout << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
// #define int ll
typedef long double ld;
#define disp(x) cout<<x<<" ";
#define rep(i,a,b) for(int i=a;i<b;i++)
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define mp make_pair
#define pb emplace_back
#define F first
#define S second
#define endl '\n'
//cout.setf(ios::fixed);cout.precision(18)
const int MOD = 1e9+7;
const int N = 300000+10;

int32_t main(){
	fast_io;
	string s;
	cin>>s;
	int n=s.size();
	vector<ll>v;
	for (int i = 0; i < n; ++i)
	{
		if(s[i]=='W') v.emplace_back(i);
	}
	ll ans=0;
	for (ll i = 0; i < (int)v.size(); ++i)
	{
		ans+=v[i]-i;
	}
	show(ans);
	return 0;
}

Measured memory_bytes: 2700
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
int n,m;
vector<int> g[N];
bool b[N];
void dfs(int x)
{
	b[x]=1;
	for(int u:g[x])
	{
		if(!b[u])
		dfs(u);
	}
	return ;
}
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   cin>>n>>m;
   rep(i,0,n)
   {
   	int sze;
   	cin>>sze;
   	while(sze--)
   	{
   		int x;
   		cin>>x;
   		g[i].push_back(n-1+x);
   		g[n-1+x].push_back(i);
	   }
   }
   dfs(0);
   bool ans=true;
   rep(i,0,n)
   ans&=b[i];
   if(ans)
   cout<<"YES";
   else
   cout<<"NO";
	
}






Measured memory_bytes: 11008
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  ll a;
  cin>>a;
  ll p=a+(a*a)+(a*a*a);
  cout<<p;
  return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
int main(void){
  int A, B, C, D;
  int L, R;
  scanf("%d %d %d %d", &A, &B, &C, &D);
  L = A + B;
  R = C + D;
  if (L == R) printf("Balanced");
  else if (L > R) printf("Left");
  else printf("Right");
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main()
{
    string s;

    cin >> s;

    int topping = 0;
    for(int i = 0; i < s.size(); i++) {
        if (s[i] == 'o') 
            topping += 100;
    }

    cout << (700 + topping) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
/*
取りうるのは
全部A,Bで揃える
BまでCで揃えてのこりA
A   C             B
全部C
*/
int min(int a,int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a,int b){
    if(a<b){
        return b;
    }
    else{
        return a;
    }
}

int main(void){
    int A,B,C,X,Y;
    scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
    int val,val1,val2,val3,val4;
    val1 = X*A + B*Y;
    val2 = Y*2*C;
    if(X>Y){
        val2+=(X-Y)*A;
    }
    val3 = X*2*C;
    if(Y>X){
        val3+=(Y-X)*B;
    }
    val4 = max(X,Y)*2*C;
    val = min(min(val1,val2),min(val3,val4));
    printf("%d\n",val);


    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
  int d, t, s;
  cin >> d >> t >> s;
  
  if(d % s == 0 && d / s <= t){
    cout << "Yes" << endl;
    return 0;
  }else if(d % s != 0 && d / s < t){
    cout << "Yes" << endl;
    return 0;
  }else{
    cout << "No" << endl;
    return 0;
  };
  
  
}

Measured memory_bytes: 3632
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i < a + k && i <= b; ++i) {
		if (i == b - k + 1)
			break;
		printf("%d\n", i);
	}
	if (b - k + 1 < a)
		return 0;
	for (int i = b - k + 1; i <= b; ++i) {
		printf("%d\n", i);
	}
	return 0;
}

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

using namespace std;

int main(){
    int h, n;
    cin>>h>>n;
    int aa=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        aa+=a;
    }
    if(aa>=h){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public struct Medicine
{
    public int X;
    public int Y;
    public int Cost;
}

public class Program
{
    #region Standard I/O
    readonly TextReader input;
    readonly TextWriter output;

    X[] ReadLine<X>(Func<string, X> func)
    {
        return input.ReadLine().Split(' ').Select(func).ToArray();
    }

    void WriteLineOne(object obj)
    {
        output.WriteLine("{0}", obj);
    }

    void WriteLineMany(params object[] objects)
    {
        output.WriteLine(string.Join(" ", objects.Select(obj => obj.ToString())));
    }
    #endregion

    int n, mx, my;
    Medicine[] medicines;
    int totalX, totalY;

    void Read()
    {
        var line = ReadLine(int.Parse);
        n = line[0];
        mx = line[1];
        my = line[2];

        medicines = new Medicine[n];
        for (var i = 0; i < n; i++)
        {
            var l = ReadLine(int.Parse);
            var x = l[0];
            var y = l[1];
            var c = l[2];

            medicines[i] =
                new Medicine()
                {
                    X = my * x,
                    Y = mx * y,
                    Cost = c,
                };

            totalX += medicines[i].X;
            totalY += medicines[i].Y;
        }
    }

    int Solve()
    {
        var dp = new int[totalX + 1, totalY + 1];

        for (var x = 0; x <= totalX; x++)
        {
            for (var y = 0; y <= totalY; y++)
            {
                dp[x, y] = int.MaxValue;
            }
        }

        dp[0, 0] = 0;

        for (var i = 0; i < n; i++)
        {
            var m = medicines[i];

            for (var x = totalX; x >= m.X; x--)
            {
                for (var y = totalY; y >= m.Y; y--)
                {
                    var cost = dp[x - m.X, y - m.Y];
                    if (cost == int.MaxValue) continue;

                    dp[x, y] = Math.Min(dp[x, y], cost + m.Cost);
                }
            }
        }

        var totalCost = int.MaxValue;

        for (var x = 1; x <= Math.Min(totalX, totalY); x++)
        {
            totalCost = Math.Min(totalCost, dp[x, x]);
        }

        return totalCost == int.MaxValue ? -1 : totalCost;
    }

    public void Run()
    {
        Read();
        WriteLineOne(Solve());
    }

    public Program(TextReader input, TextWriter output)
    {
        this.input = input;
        this.output = output;
    }

    public static void Main(string[] args)
    {
        new Program(Console.In, Console.Out).Run();
    }
}


Measured memory_bytes: 26592
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main() {
    int n; cin >> n;
    vector<int> a(n+1), b(n);
    REP(i, n+1) cin >> a[i];
    REP(i, n) cin >> b[i];

    ll ans = 0;
    REP(i, n) {
        if(b[i] < a[i]) {
            ans += b[i];
            a[i] -= b[i];
            b[i] = 0;
        } else if(b[i] < a[i] + a[i+1]) {
            ans += b[i];
            a[i+1] -= b[i] - a[i];
            b[i] = 0;
        } else {
            ans += a[i] + a[i+1];
            b[i] -= a[i] + a[i+1];
            a[i+1] = 0;
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){

    long long int N,sum=0;

    scanf("%lld", &N);

    long long int d = 0; 
    for(int i = 1; i<1000000; i++){
        if(i==d) break;
        
        if(N%i == 0){
            d = N/i;
			if(d==1) break;
			if(N%(d-1) == N /(d-1) ) sum += d-1;
        }
        
    }

    printf("%lld\n",sum);
    return 0;

}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

/*

//S[0]から始まる文字列の長さを求める関数
int string_len(char* str){
    int len=0;
    while(str[len]!=0){
        len++;
    }
    return len;
}

//753数なら1,そうでないなら0
int judge_753(int N){
    //int型Nを、文字列char配列に変換
    char s[10]={'\0'};
    snprintf(s,10,"%d",N);

    //Nの桁数
    int digit=string_len(s);

    int count=0;
    for(int i=0;i<digit;i++){
        if(s[i]=='3'){
            count++;
            break;
        }
    }
    for(int i=0;i<digit;i++){
        if(s[i]=='5'){
            count++;
            break;
        }
    }
    for(int i=0;i<digit;i++){
        if(s[i]=='7'){
            count++;
            break;
        }
    }

    if(count==3) return 1;
    else return 0;
}

*/

long N;
long ans=0;

int count_753(long s,long N,int a, int b, int c){
    if(s>N) return ans;

    if(a+b+c==3) ans++;

    count_753((s*10+3),N,1,b,c);
    count_753((s*10+5),N,a,1,c);
    count_753((s*10+7),N,a,b,1);
}

int main(void){
    scanf("%ld",&N);
    ans=count_753(0,N,0,0,0);

    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
from numpy import*

def section_sum(numbers,separate):
    sep1=array(numbers[separate:],dtype=int)
    sep2=array(numbers[:-separate],dtype=int)
    sep3=sum(numbers[:separate])
    return [[0,i][i>0] for i in insert(sep3+cumsum(sep1-sep2),0,sep3)]

n,k,*a=map(int,open(0).read().split())
l=[]
b=[[0,i][i>0] for i in a]
c=cumsum(b)
d=cumsum(b[::-1])[::-1]

for s,t in enumerate(section_sum(a,k)):
    if s+k<n:
        l.append(t+[0,c[s-1]][s-1>=0]+d[s+k])
    else:
        l.append(t+[0,c[s-1]][s-1>=0])
print(int(max(l)))

Measured memory_bytes: 26640
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#include <cassert>
#include <chrono>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head
void dfs(int i, vector<vi>& graph, vector<bool>& visited) {
    visited[i] = true;
    for (auto x : graph[i]) {
        if (!visited[x])
            dfs(x, graph, visited);
    }
}

void solve() {
    int n, m;
    cin >> n >> m;

    vector<vi> graph(n+1);
    int u, v;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        graph[u].pb(v);
        graph[v].pb(u);
    }

    int ans = 0;
    vector<bool> visited(n+1);
    for (int i = 1; i <= n; i++) {
        if (!visited[i]) {
            dfs(i, graph, visited);
            ans++;
        }
    }
    cout << ans -1 << '\n';
}

int main() {
    #ifdef LOCAL
    auto t1 = std::chrono::high_resolution_clock::now();
    #endif

    io;
    solve();

    #ifdef LOCAL
    auto t2 = std::chrono::high_resolution_clock::now();
    auto duration = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();

    std::cout << "Time Taken: " << duration << "\n";
    #endif

}
// check for edge cases in limits
// printing double may print 1.223232e9 like values, beware of that
// carefully observe simulation of test cases
// multiset erase is does not do what it is supposed to


Measured memory_bytes: 9532
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
	string s;
    cin >> s;
    ll i;
    if(s.size()%2==1){
        cout <<"No";
        return 0;
    }
    for(i=0;i<s.size();i++){
        if(i%2==0 && s[i]!='h'){
            cout << "No";
            return 0;
        }
        if(i%2==1 && s[i]!='i'){
            cout << "No";
            return 0;
        }

    }
    cout << "Yes";
    return 0;
}


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

using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch: s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    }
    else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}

string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}

int letter_to_int(char c) {
  return tolower(c) - 'a';
}

int compare_array(vector<int> a1, vector<int>a2) {
  int n1 = a1.size();
  int n2 = a2.size();
  if (n1 != n2) {
    return n1 - n2;
  }
  for (int i=0; i<n1; i++) {
    if (a1.at(i) != a2.at(i)) {
      return a1.at(i) - a2.at(i);
    }
  }
  return 0;
}

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

char int_to_char(int a) {
  if (a == -1) {
    return 'z';
  }
  else {
    return 'a' + a;
  }
}

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

int divide_count(int a, int divider) {
  int r = 0;
  while(a % divider == 0) {
    a /= divider;
    r++;
  }
  return r;
}

bool is_prime(int a) {
  int i = 2;
  while(i * i <= a) {
    if(a % i == 0) {
      return false;
    }
    i++;
  }
  return true;
}

vector<vector<int>> all_comb(int n, int k) {
  vector<vector<int>> combs(nCr(n, k), vector<int>(k));
  for(int i=0; i<k; i++) {
    combs[0][i] = i;
    combs[1][i] = i;
  }
  
  for(long i=1; i<nCr(n, k); i++) {
    int p = 1;
    while(combs[i][k - p] == n - p) {
      p++;
      if(p > k) {
        break;
      }
    }
    combs[i][k - p]++;
    int q = combs[i][k - p];
    for(int j=1; j<p; j++) {
      combs[i][k - p + j] = q + j;
    }

    if(i < nCr(n, k) - 1) {
      for(int j=0; j<k; j++) {
        combs[i + 1][j] = combs[i][j];
      }
    }
  }

  return combs;
}

template <typename TYPE> void co(TYPE a) {
  cout << a << endl;
}

template <typename TYPE> void co_2(TYPE a, TYPE b) {
  cout << a << ' ' << b << endl;
}

template <typename TYPE> void co_l(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    cout << as[i] << endl;
  }
}

template <typename TYPE> void co_s(vector<TYPE> as) {
  int n = as.size();
  for(int i=0; i<n; i++) {
    if(i > 0) {
      cout << ' ';
    }
    cout << as[i];
  }
  cout << endl;
}

int main() {
  std::cout << std::setprecision(9);
  long mod = 1000000007;
  int n;
  cin >> n;
  vector<long> a(n);

  long ans = 0;
  long max = 0;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    if(a[i] < max) {
      ans += max - a[i];
    }
    if(a[i] > max) {
      max = a[i];
    }
  }

  co(ans);
}

Measured memory_bytes: 4856
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,w,e,q,t;
    cin >> a;
    if(a>=1000 && a<=9999)
    {
     w=a%10;
     q=(a/10)%10;
     e=(a/100)%10;
     t=(a/1000)%10;
     if(w==q && w==e|| q==e && q==t)
     {
         cout << "Yes";
     }
     else
        cout << "No";
    }
        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e5;
char a[MAXN+5];
int n,ans=1;
int main()
{
	scanf("%d",&n);
	scanf("%s",a+1);
	for(int i=2;i<=n;i++)
		if(a[i]!=a[i-1])
			ans++;
	printf("%d\n",ans);
	return 0;
}


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

typedef long long ll;

int main()
{
	ll n;
	while( std::cin >> n, n )
	{
		std::vector<ll> v;

		for( int i = 0; i != n; ++i )
		{
			ll t;
			std::cin >> t;
			v.push_back( t );
		}

		std::sort( v.begin(), v.end() );

		ll ans = 0, prv = 0;
		for( int i = 0; i != n; ++i )
		{
			ans += prv;
			prv += v[i];
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1340
class Dice(object):
    def __init__(self):
        self.u = 1
        self.f = 2
        self.r = 3
        self.l = 4
        self.d = 6
        self.b = 5

    def rotate(self, d):
        cu, cf, cr, cl, cd, cb = self.u, self.f, self.r, self.l, self.d, self.b
        if d == 0:  # N
            self.u, self.f, self.d, self.b = cf, cd, cb, cu
        elif d == 1: # E
            self.u, self.r, self.d, self.l = cl, cu, cr, cd
        elif d == 2: # W
            self.u, self.r, self.d, self.l = cr, cd, cl, cu
        elif d == 3: # S
            self.u, self.f, self.d, self.b = cb, cu, cf, cd
        elif d == 4: # R
            self.f, self.r, self.b, self.l = cr, cb, cl, cf
        elif d == 5: # L
            self.f, self.r, self.b, self.l = cl, cf, cr, cb


while True:
    n = int(input())
    if n == 0:
        break

    dice = Dice()
    count = 1
    for _ in range(n):
        s = input()[0]
        if s == "N":
            dice.rotate(0)
        elif s == "E":
            dice.rotate(1)
        elif s == "W":
            dice.rotate(2)
        elif s == "S":
            dice.rotate(3)
        elif s == "R":
            dice.rotate(4)
        elif s == "L":
            dice.rotate(5)
        else:
            pass
        count += dice.u
    print(count)


Measured memory_bytes: 5628
def inpl(): return [int(i) for i in input().split()]
Q = int(input())
for _ in range(Q):
    A, B = sorted(inpl())
    c = int(-(-(A*B)**0.5//1)-1)
    ans = A-1 + max(0, c-A) + (-((-A*B)//(c+1))-1)
    print(ans)

Measured memory_bytes: 3060
S = sorted(input())
T = sorted(input())
S_list = []
T_list = []
for alp in "abcdefghijklmnopqrstuvwxyz":
  S_list.append(S.count(alp))
  T_list.append(T.count(alp))
if(sorted(S_list) != sorted(T_list)):
  print('No')
else:
  print('Yes')

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int Free = 0;
set<int> st;
int main() {
    //cout.precision(10);
    int N;
    cin >> N;
    for(int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(a < 3200) {
            st.insert(a / 400);
        } else Free++;
    }
    int mini = max(1, (int)st.size());
    int maxi = (int)st.size() + Free;
    cout << mini << " "  << maxi << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;

int main(){
  int H, W;
  cin >> H >> W;
  string s;
  vector<string> Map(H+2, "");
  for (int i=0;i<W+2;i++){
    Map[0] = Map[0] + "#";
    Map[H+1] = Map[H+1] + "#";
  }
  for (int i=0;i<H;i++){
    cin >> s;
    Map[i+1] = "#" + s + "#";
  }
  vector<vector<long long>> A(H+2, vector<long long>(W+2, 0));
  A[1][1] = 1;
  long long cnt;
  for (int i=3;i<=H+W;i++){
    for (int j=max(1, i-W);j<=min(H, i-1);j++){
      if (Map[j][i-j] == '.'){
        cnt = 0;
        if (Map[j][i-j-1] == '.'){
          cnt += A[j][i-j-1];
          cnt %= mod;
        }
        if (Map[j-1][i-j] == '.'){
          cnt += A[j-1][i-j];
          cnt %= mod;
        }
        A[j][i-j] = cnt;
      }
    }
  }
  cout << A[H][W] << endl;
  return 0;
}

Measured memory_bytes: 10112
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    pair<int, int> shopprice[N];

    for(int i=0; i<N; i++){
        cin >> shopprice[i].first>> shopprice[i].second;
    }

    //printf("%d   %d\n", shopprice[N-1].first, shopprice[N-1].second);

    sort(shopprice, shopprice + N);
    long long int totalprice = 0;
    int rest = M;
    for(int i=0; i<N; i++){
        if(rest > shopprice[i].second){
            rest += -shopprice[i].second;
            totalprice += (long long int)(shopprice[i].first) * shopprice[i].second;
            //printf("rest: %d  totalprice: %ld", rest, totalprice);
        }else{
            
            totalprice += (long long int)shopprice[i].first * rest;
            
            break;
        }
    }

    cout << totalprice << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
#define vec_all(vec) vec.begin(), vec.end()

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

    vector<int> h(n);
    rep(i, n) {
        cin >> h[i];
    }

    int count = 0;
    int index = 0;

    bool is_start = false;
    int zero_count = 0;

    int l;
    int r;

    int tmp_min = 101;
    while (true) {
        if (is_start) {
            if (h[index] == 0) {
                r = index;
                is_start = false;
                index = 0;
                zero_count = 0;
                count += tmp_min;
                repr(i, l, r) {
                    h[i] -= tmp_min;
                }
                tmp_min = 101;
            } else {
                tmp_min = min(tmp_min, h[index]);
                index++;
            }
        } else {
            if (h[index] != 0) {
                l = index;
                is_start = true;
                tmp_min = min(tmp_min, h[index]);
            } else {
                zero_count++;
            }

            index++;
        }

        if (index == n) {
            if (zero_count == n) {
                break;
            } 
            r = n;
            is_start = false;
            index = 0;
            zero_count = 0;
            count += tmp_min;
            repr(i, l, r) {
                h[i] -= tmp_min;
            }
            tmp_min = 101;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    s = set()

    for i in range(n):
        w = input()
        if w in s:
            print("No")
            break
        s.add(w)

        if i != 0:
            if w[0] != last:
                print("No")
                break
                
        if i == n-1:
            print("Yes")
            break

        last = w[-1]

if __name__ == "__main__":
    main()

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

struct node {
    int key;
    struct node *prev;
    struct node *next;
};
typedef struct node *NodePointer;

NodePointer origin;

void setNodeKey(NodePointer, int);
void setNodePrev(NodePointer, NodePointer);
void setNodeNext(NodePointer, NodePointer);

NodePointer search(int);
void insert(int);
void delete(NodePointer);

void display();

int main() {
    int i;
    int n, input;
    char command[15];

    scanf("%d", &n);

    origin = (NodePointer)malloc(sizeof(struct node));
    setNodePrev(origin, origin);
    setNodeNext(origin, origin);

    for (i = 0; i < n; i++) {
        scanf("%s", command);
        if (strcmp("insert", command) == 0) {
            scanf("%d", &input);
            insert(input);
        }
        else if (strcmp("delete", command) == 0) {
            scanf("%d", &input);
            delete(search(input));
        }
        else if (strcmp("First", &command[6])) {
            delete(origin->prev);
        }
        else if (strcmp("Last", &command[6])) {
            delete(origin->next);
        }
    }
    display();

    return 0;
}

void setNodeKey(NodePointer n, int key) {
    n->key = key;
}

void setNodePrev(NodePointer n, NodePointer prev) {
    n->prev = prev;
}

void setNodeNext(NodePointer n, NodePointer next) {
    n->next = next;
}

NodePointer search(int key) {
    NodePointer target = origin->next;

    // 探しているノード( target ) == 最初のノード (origin) になったら一周
    while (target != origin) {
        // 探しているノード( target )と'key'が一致した場合
        if (target->key == key) {
            return target;
        }
        target = target->next;
    }

    return NULL;
}

void insert(int key) {
    NodePointer n;
    // 現在 : ( origin ) <-> ( 0 )...
    // 完成 : ( origin ) <-> ( n ) <-> ( 0 )...

    // 「新規追加ノード( n )」のprevを「最初のノード( origin )」にする
    // 「新規追加ノード( n )」のnextを「最初のノードの次のノード( 0 )」にする
    n = (NodePointer)malloc(sizeof(struct node));
    setNodePrev(n, origin);
    setNodeNext(n, origin->next);
    setNodeKey(n, key);

    // 「最初のノードの次のノード( 0 )」のprevを「新規追加ノード( n )」にする
    setNodePrev(origin->next, n);
    // 「最初のノード( origin )」のnextを「新規追加ノード( n )」にする
    setNodeNext(origin, n);
}

void delete(NodePointer n) {
    if (n == NULL) { return; }
    // 現在 : ...( 0 ) <-> ( n ) <-> ( 2 )...
    // 完成 : ...( 0 ) <-> ( 2 )...

    // 「取消対象ノードの次のノード( 2 )」のprevを「取消対象ノードの前のノード( 0 )」にする
    setNodePrev(n->next, n->prev);
    // 「取消対象ノードの前のノード( 0 )」のnextを「取消対象ノードの次のノード( 2 )」にする
    setNodeNext(n->prev, n->next);
    // 「取消対象ノード」を開放する
    free(n);
}

void display() {
    NodePointer target = origin->next;

    // 探しているノード( target ) == 最初のノード (origin) になったら一周
    while (target != origin) {
        if (target != origin->next) printf(" ");
        printf("%d", target->key);

        target = target->next;
    }
    printf("\n");
}


Measured memory_bytes: 32972
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

alpha = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s = input()
n = len(s)
if s[0] != 'A':
    print('WA')
    quit()
cnt = 0
for i in range(2,n-1):
    if s[i] == 'C':
        cnt += 1
    elif s[i] in alpha:
        print('WA')
        quit()
if cnt != 1:
    print('WA')
    quit()
if s[1] in alpha:
    print('WA')
    quit()
if s[-1] in alpha:
    print('WA')
    quit()
print('AC')


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    n %= 26;
    string s;
    cin >> s;
    for (char& c : s) {
        c = (c - 'A' + n) % 26 + 'A';
    }
    cout << s << "\n";
    return 0;
}

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

int main()
{
    int N;
    long ans, temp1, temp2;
    int a[100005], b[100005], c[100005];
    cin >> N;
    REP(i, N)
        cin >> a[i];
    REP(i, N)
        cin >> b[i];
    REP(i, N)
        cin >> c[i];
    sort(a, a+N);
    sort(b, b+N);
    sort(c, c+N);
    ans = 0;
    REP(i, N){
        temp1 = (int)(lower_bound(a, a+N, b[i])-a);
        temp2 = (int)(N-(int)(upper_bound(c, c+N, b[i])-c));
        ans += (long)temp1 * (long)temp2;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1408
# include<bits/stdc++.h>
# include<unordered_map>
# include<unordered_set>
//# include<prettyprint.hpp>
using namespace std;
# define ll long long
# define endl '\n'
ll n, m;
vector<vector<ll> > d;
vector<ll> order, vis;
void dfs(ll u){
	vis[u] = 1;
	for(auto v:d[u]){
		if (!vis[v]) dfs(v);
	}
	order.push_back(u);
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin >> n >> m;
	d.resize(n);
	vis.resize(n, 0);
	for(ll i = 0; i < m; i++){
		ll u, v; cin >> u >> v;
		u--, v--;
		d[u].push_back(v);
	}
	for(ll i = 0; i < n; i++){
		if (vis[i]) continue;
		dfs(i);
	}
	reverse(order.begin(), order.end());
	vector<ll> dist(n, 0);
	for(auto i:order){
		for(auto j:d[i]){
			dist[j] = max(dist[j], dist[i]+1);
		}
	}
	cout << *max_element(dist.begin(), dist.end()) << endl;
	return 0;
}

Measured memory_bytes: 13268