akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
#define nil -1

struct node{
	int p,l,r;
};

node A[100010];
int n,D[100010];

void print(void){
	for(int i=0;i<n;i++){
		printf("node %d: parent = %d, ",i,A[i].p);
		printf("depth = %d, ",D[i]);
		if(A[i].p==nil){
			printf("root, ");
			
		}
		else if(A[i].l==nil){
			printf("leaf, ");
		}
		else{
			printf("internal node, ");
		}
		printf("[");
		if(A[i].l!=nil){
			int j=A[i].l;
			printf("%d",j);
			while(A[j].r!=nil){
				j=A[j].r;
				printf(", %d",j);
			}
		}
		printf("]");
		printf("\n");
	}
}

void depth(int v,int d){
	D[v]=d;
	if(A[v].r!=nil){depth(A[v].r,d);}
	if(A[v].l!=nil){depth(A[v].l,d+1);}
}

int main() {
	cin>>n;
	int v,d,c,l,root;
	for(int i=0;i<n;i++){
		A[i].p=A[i].l=A[i].r=nil;
	}
	for(int i=0;i<n;i++){
		cin>>v>>d;
		for(int j=0;j<d;j++){
			cin>>c;
			if(j==0){A[v].l=c;}
			else{A[l].r=c;}
			l=c;
			A[c].p=v;
		}
	}
	for(int i=0;i<n;i++){
		if(A[i].p==nil){root=i;}
	}
	depth(root,0);
	print();
	return 0;
}


Measured memory_bytes: 7832
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")
//#pragma warning(disable : 4996)

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < (n);++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef pair<long long, long long>pll;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 998244353; constexpr int MAX = 200050;
const double pi = acos(-1); constexpr double EPS = 1e-12;
constexpr ll INF = 1e16;
void yes(bool c) { if (c)print("Yes"); else print("No"); };



string S[1000010];
void solve() {
	int N; cin >> N;
	REP(i, N)cin >> S[i];
	vector<pii>plus, minu;
	REP(i, N) {
		int mn = 0, res = 0;
		REP(j, S[i].size()) {
			if (S[i][j] == '(') {
				res++;
			}
			else {
				res--;
				mn = min(mn, res);
			}
		}
		if (res <= 0)minu.push_back({ -mn,res });
		else plus.push_back({ -mn,res });
	}
	VSORT(plus);
	sort(all(minu), [](const pii &a,const pii &b) {
		return a.first + a.second > b.first + b.second;
	});
	int now = 0;
	bool ok = true;
	for (auto p : plus) {
		int need = p.first, ad = p.second;
		if (now < need)ok = false;
		now += ad;
	}
	for (auto p : minu) {
		int need = p.first, ad = p.second;
		if (now < need)ok = false;
		now += ad;
		if (now < 0)ok = false;
	}

	if (!ok)print("No");
	else yes(now == 0);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}



Measured memory_bytes: 50328
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	cin >> n;
	ll x[110];
	FOR(i,n){
		cin >> x[i];
	}
	ll ans=MOD;
	for(ll i=1;i<=100;i++){
		ll sum=0;
		FOR(j,n){
			sum+=(i-x[j])*(i-x[j]);
		}
		chmin(ans,sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> sw[14];
int p[14];
int ans = 0;
void can(int state){
	int ret = 0;
	for(int i = 0;i<m;i++){
		int cnt = 0;
		for(int j : sw[i]){
			if((1<<j)&state)	cnt++;
		}
		if(cnt % 2 == p[i])
		ret += (1<<i);
	}
	if(ret == (1<<m)-1)	ans++;
}
int main() {
	cin>>n>>m;
	for(int i = 0;i<m;i++)
	{
		int t;
		cin>>t;
		int q;
		while(t--){
			cin>>q;
			sw[i].push_back(--q);
		}
	}
	for(int i = 0;i<m;i++)	cin>>p[i];
	for(int i = 0; i<(1<<n);i++)
		can(i);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto e : s) os << e; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += b % mod) %= mod; if (a < 0) a += mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(12); // debuged
  int T;
  T = 1;
  while (T--) solve();
}

vector<pii> runlength(vector<int> v) {
  vector<pii> ret;
  int cnt = 1;
  int n = sz(v);
  rep3(i, 1, n) {
    if (v[i] == v[i - 1]) {
      cnt++;
    } else {
      ret.eb(v[i - 1], cnt);
      cnt = 1;
    }
  }
  ret.eb(v[n - 1], cnt);
  return ret;
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  cin >> a;
  sort(all(a));

  auto v = runlength(a);
  a.clear();
  rep(i, sz(v)) a.eb(v[i].S);
  sort(all(a));

  vector<ll> b(sz(v) + 1);
  rep(i, sz(v)) b[i + 1] = b[i] + a[i];
  // cerr << a << endl << b << endl;

  int i = 1;
  auto binary_search = [&](int ok, int ng) {
    auto check = [&](int x) { // 最大何組とれるか
      int it = lb(a, x);
      ll sum = (it >= 0 ? b[it] : 0);
      sum += (sz(v) - it) * 1LL * x;
      if (sum >= x * 1LL * i) return 1;
      return 0;
    };
    int d = 1;
    while (abs(ng - ok) > d) {
      int mid = (ng + ok) / 2;
      (check(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
  };
  for (; i <= n; ++i) { // 何枚組でとるか
    binary_search(0, n + 1);
  }
}


Measured memory_bytes: 9632
def MI(): return map(int, input().split())
def II(): return int(input())
def IS(): return input()
def LI(): return list(map(int, input().split()))


n, m = MI()

if n == 1 and m == 1:
    print(1)
elif n == 1:
    print(1 * (m-2))
elif m == 1:
    print(1 * (n-2))
else:
    print((n-2) * (m-2))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0; i<(int)(n); i++)
 
int n,k,c;
char s[252521];
int lwork[252521], rwork[252521];
 
int main(){
  scanf("%d%d%d", &n, &k, &c);
  scanf("%s", s);
  REP(i,n){
    int add = s[i]=='x' ? 0 : 1;
    if(i==0){
      lwork[i] = add;
    }else if(i<c+1){
      lwork[i] = max(lwork[i-1], add);
    }else{
      lwork[i] = max(lwork[i-1], lwork[i-c-1] + add);
    }
  }
  REP(_i,n){
    int i = n-1-_i;
    int add = s[i]=='x' ? 0 : 1;
    if(_i==0){
      rwork[i] = add;
    }else if(_i<c+1){
      rwork[i] = max(rwork[i+1], add);
    }else{
      rwork[i] = max(rwork[i+1], rwork[i+c+1] + add);
    }
  }
  REP(i,n){
    int works = 0;
    if(i>0)works += lwork[i-1];
    if(i<n-1)works += rwork[i+1];
    if(works < k){
      printf("%d\n", i+1);
    }
  }
  return 0;
}

Measured memory_bytes: 3328
#include<stdio.h>
 
static const int N = 100;
 
int main(){
  int n,i,j;
  int v;
  int count=0;
  int A[N];
 
  /*scanf data*/
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);
 
  /*bubbule sort*/
  for(i=0;i<n-1;i++){
    for(j=n-1;j>i;j--){
      if(A[j-1]>A[j]){
    v=A[j];
    A[j]=A[j-1];
    A[j-1]=v;
    count++;
      }
    }
  }
 
  /*printf data*/
  printf("%d",A[0]);
  for(i=1;i<n;i++)printf(" %d",A[i]);
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 600
<?php
//https://atcoder.jp/contests/sumitrust2019/submissions/8763576
$N = (int)trim(fgets(STDIN));
$S = trim(fgets(STDIN));
//list($m2,$d2) =  explode(" ",trim(fgets(STDIN)));
//$A =  explode(" ",trim(fgets(STDIN)));

$ret=0;
for($i=0;$i<10;$i++) {
  $last[$i]=-1;
}
for($i=$N;~$i;$i--) {
  $nn[$i]=$last;
  if ($i) $last[(int)$S[$i-1]]=$i;
}
for($i=0;$i<1000;$i++) {
  $x = $nn[0][intdiv($i,100)];
  if ($x == -1) continue;
  $y=$nn[$x][intdiv($i,10)%10];
  if ($y == -1) continue;
  $z=$nn[$y][$i%10];
  if ($z == -1) continue;
  $ret++;
}
printf("%d\n",$ret);


Measured memory_bytes: 25080
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 11;
#define LL long long
int n;
LL a[N], f[N][2];
int main(){
    cin>>n;
    for(int i = 1;i <= n; i++){
        scanf("%lld", &a[i]);
    }
    memset(f, -127, sizeof f);
    f[0][0] = 0;
    for(int i = 0;i < n / 2; i++){
        for(int j = 0;j <= 1; j++){
            LL F = f[i][j];
            f[i+1][1] = max(f[i+1][1], F + a[i*2+2]);
            if(j != 1)f[i+1][0] = max(f[i+1][0], F + a[i*2+1]);
        }
    }
    if(n & 1){
        LL sum = a[n];
        LL ans = max(f[n/2][1], f[n/2][0]);
        int num = 1;
        for(int i = n - 2;i > 1; i -= 2){
            ans = max(ans, sum + max(f[(i-1)/2][0], f[(i-1)/2][1]));
            num++;
            sum += a[i];
            if(num == n / 2)ans = max(ans, sum);
        }
        cout<<ans<<endl;

    }
    else {
        printf("%lld\n", max(f[n/2][0], f[n/2][1]));
    }
    return 0;
}


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

namespace CS_AtCoder {
	class Program {
		static void Main(string[] args) {
			new Calc().Solve();
		}
	}
	public class Calc {
		public Calc() { }
		public void Solve() {
			int a = Utils.ReadInt();
			int b = Utils.ReadInt();
			int h = Utils.ReadInt();
			((a + b) * h / 2).WL();
			return;
		}
	}
	public static class Utils {
		public static int ReadInt() => int.Parse(Console.ReadLine());
		public static void WL(this object obj) {
			Console.WriteLine(obj);
		}
	}
}


Measured memory_bytes: 13140
package main

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

func main() {
	w := []rune(getString())

	m := make(map[rune]int, 26)
	for _, r := range w {
		m[r]++
	}

	ans := "Yes"
	for _, v := range m {
		if v%2 == 1 {
			ans = "No"
			break
		}
	}

	fmt.Println(ans)
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

func getInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


Measured memory_bytes: 640
#include <stdio.h>

int main() {
    int x;
    int y;
    int tmp;
    scanf("%d %d\n",&x,&y);
    while (!(x==0 && y==0)){
        if(x>y){
            tmp=x;
            x=y;
            y=tmp;
        }
        printf("%d %d\n",x,y);
        scanf("%d %d\n",&x,&y);
    }
    return 0;
}

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

#define MAX(X,Y) ((X)>(Y)?(X):(Y))

using namespace std;

int main(void){
  int n,m,ans;
  vector<int> h,f;
  
  cin >> n >> m;
  h.push_back(0); f.push_back(0); // [0]
  for (int i=0; i<n; i++){
    int t; cin >> t;
    h.push_back(t);
    f.push_back(1);
  }
  for (int i=0; i<m; i++){
    int a,b; cin >> a >> b;
    if (h[a]>=h[b]) f[b]=0;
    if (h[a]<=h[b]) f[a]=0;
  }
  ans = 0;
  for (int i=1; i<=n; i++){
    if (f[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int n,k;
    cin>>n>>k;

    vector<int>h(n);

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

    vector<int>dp(n,INF);//dp[i] -> minimum cost to reach position i

    dp[0]=0;

    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<=i+k;j++)
        {
            if(j<n)
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
        }
    }

    cout<<dp[n-1]<<endl;



    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>

using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define in(v) cin>>v;
#define out(v) cout<<v<<"\n"
const int MOD = 1e9+7;
const ll INF = numeric_limits<ll>::max();
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int A, B, Q; in(A); in(B); in(Q);
  ll s[A], t[B];
  rep(i, A)
    in(s[i]);
  rep(i, B)
    in(t[i]);

  rep(i, Q) {
    ll x; in(x);
    auto s_near = lower_bound(s, s+A, x);
    if (s_near == s+A)
      --s_near;
    auto t_near = lower_bound(t, t+B, x);
    if (t_near == t+B)
      --t_near;
    auto s_near2 = (s_near == s) ? s_near : s_near - 1;
    auto t_near2 = (t_near == t) ? t_near : t_near - 1;
    ll tmp = INF;
    chmin(tmp, abs(*s_near - x) + abs(*s_near - *t_near));
    chmin(tmp, abs(*s_near - x) + abs(*s_near - *t_near2));
    chmin(tmp, abs(*s_near2 - x) + abs(*s_near2 - *t_near));
    chmin(tmp, abs(*s_near2 - x) + abs(*s_near2 - *t_near2));

    chmin(tmp, abs(*t_near - x) + abs(*s_near - *t_near));
    chmin(tmp, abs(*t_near - x) + abs(*s_near2 - *t_near));
    chmin(tmp, abs(*t_near2 - x) + abs(*s_near - *t_near2));
    chmin(tmp, abs(*t_near2 - x) + abs(*s_near2 - *t_near2));
    out(tmp);
  }

  return 0;
}


Measured memory_bytes: 2944
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			new Main().exec(sc);
		}
	}

	public void exec(Scanner sc) {
		int n = sc.nextInt();
		double sum = 0;
		List<Double> list = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			double xi = sc.nextDouble();
			list.add(xi);
			sum += xi;
		}
		int ave = (int) Math.round(sum / list.size());
		long result = 0;
		for (Double d : list) {
			result += Math.pow(d - ave, 2);
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 25044
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
using namespace std;

void solve(){
    int n;
    cin>>n;
    string s,t;
    cin>>s>>t;
    rep(i,s.size()){
            if(s[i]==t[0]){
                int memo=i;
                int cur=i;
                int j=0;
                bool judge=true;
                while(cur+1<s.size()){
                    ++cur;++j;
                    if(s[cur]!=t[j]){
                        judge=false;
                        break;
                    }
                }
                if(judge){
                    cout<<t.size()+memo<<"\n";
                    return ;
                }
            }
    }
    cout<<s.size()+t.size()<<"\n";
}
 
signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)
#define fi first
#define se second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr const char* YES = "Yes";
static constexpr const char* NO = "No";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  rep(i, 0, 3) {
    if (s[i] == '7') {
      put(YES);
      return 0;
    }
  }
  put(NO);

  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

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

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

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) {
  T c = min(a, b), d = max(a, b);
  return c * (d / gcd(c, d));
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


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

using namespace std;

typedef long long ll;

const ll N=200000; ///(1<<17) , (1<<19)

ll n,v[N+5];
ll p[N+5],s[N+5];

ll slove(ll add)
{
    ll r=0,pas=(1<<17);
    while(pas)
    {
        if(r+pas<=n && v[r+pas]+add<=0)
            r+=pas;
        pas/=2;
    }
    ll ans=0;
    ans+=abs(p[r]+add*r);
    ans+=abs(s[r+1]+add*(n-r));
    return ans;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    for(ll i=1;i<=n;i++)
    {
        cin>>v[i];
        v[i]-=i;
    }
    sort(v+1,v+n+1);
    for(ll i=1;i<=n;i++) p[i]=p[i-1]+v[i];
    for(ll i=n;i>=1;i--) s[i]=s[i+1]+v[i];
    ll ans=slove(0);
    for(ll i=1;i<=n;i++)
    {
        ans=min(ans,slove(v[i]));
        ans=min(ans,slove(-v[i]));
   ///     cout<<i<<" "<<slove(i)<<"\n";
    }
    cout<<ans<<"\n";
    return 0;
}
/**

**/



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long
#define MOD 1000000007

using namespace std;

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

  ll result=1;
  rep(i,n){
    int t;cin>>t;
    if(t==0){
      result*=(3-m[0]);
      result%=MOD;
      m[t]++;
    }else{
//cout<<m[t]<<' '<<m[t-1]<<endl;
      result *= m[t-1]-m[t];
      m[t]++;
      result%=MOD;
    }
  }

  cout<<result;

  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin, (x).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
// scanf("%d %d %d %d",&w,&b,&d,&s); %lld
// printf("%d\n" ,points);
// const double PI=acos(-1);

int main(){
    ll r,d,x;
    cin >> r >> d >> x;
    for(int i=0;i<10;i++){
        x=r*x-d;
        cout << x << endl;
    }
    return 0;
}


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

vector<int> sya(200001,0);

int main(){
  int N;
  cin >> N;
  for(int i=2; i<=N; i++){
    int A; cin >> A;
    sya[A]++;
  }
  for(int i=1; i<=N; i++){
    cout << sya[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 3904
#pragma GCC optimize("Ofast") 
#include<algorithm>
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long 
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
int main()
{
    SYNC
    int n,k;
    in(n)>>k;
    int dp[n+1],ar[n+1];
    l(i,0,n)
    {
        in(ar[i]);
        //dp[i]=200009;
    }
    dp[0]=0;
    //if(n!=1)
    //dp[2]= abs(ar[2]-ar[1]);
    l(i,1,n)
    {
        dp[i]= dp[i-1] + abs(ar[i] - ar[i-1]);
        l(j,2,k+1)
        {
            if(i>=j)
            dp[i]=min(dp[i-j]+abs(ar[i]-ar[i-j]),dp[i]);
            else
            break;
        }
    }
    o(dp[n-1]);
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val s = readLine()!!
    val t = readLine()!!

    val gcd = gcd(n,m)
    val lcm = 1L*n/gcd*m

    val a = s.slice((0..n-1) step n/gcd)
    val b = t.slice((0..m-1) step m/gcd)
    if(a == b) {
        println(lcm)
    } else {
        println(-1)
    }

}
tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)


Measured memory_bytes: 40780
#include<bits/stdc++.h>
#define int long long int
#define inf 1000000000000
#define hell (int)(1e9+7)

using namespace std;

int dp[1000][4][2];

int helper(int st,string &s,bool flag,int k){
    if(k<0)
        return 0;
    if(st>=s.length())
        return k==0;
    if(dp[st][k][flag]!=-1)
        return dp[st][k][flag];
    int p;
    if(flag||st==0)
        p=s[st]-'0';
    else
        p=9;
    int ans=0;
    for(int i=0;i<=p;i++){
        if(st==0&&i==(s[st]-'0')){
            if(i!=0)
                ans+=helper(st+1,s,true,k-1);
            else
                ans+=helper(st+1,s,true,k);
        }
        else{
            if(i<(s[st]-'0')){
                if(i!=0)
                    ans+=helper(st+1,s,false,k-1);
                else
                    ans+=helper(st+1,s,false,k);
            }
            else{
                if(i!=0)
                    ans+=helper(st+1,s,flag,k-1);
                else
                    ans+=helper(st+1,s,flag,k);
            }
        }
    }
    return dp[st][k][flag]=ans;
}

void solve(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    memset(dp,-1,sizeof dp);
    int ans;
    ans=helper(0,s,false,k);
    cout<<ans;
}

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


Measured memory_bytes: 384
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,i,cnt=0;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        if(a[i]%2==1)
        {
            cnt++;
        }
    }
    if(cnt%2==0)
    {
        cout<<"YES";
    }
    else
    {
        cout<<"NO";
    }
}


Measured memory_bytes: 4400
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int N,M;
typedef pair <int,int> P;
vector <P> H;
vector <bool> red;
vector <int>num;




int main()
{

	cin >> N >> M;

	H.resize(M+1);
	red.resize(N+1);
	num.resize(N+1);
	FOR(i,1,M+1){
		cin >> H[i].first;
		cin >> H[i].second;
	}
	REP(i,N+1){
		red[i] = false;
		num[i] = 1;
	}
	red[1] = true;
	FOR(i,1,M+1){
		if(red[H[i].first])
			red[H[i].second] = true;
		num[H[i].first]--;
		if(num[H[i].first] == 0)
			red[H[i].first] = false;
		num[H[i].second]++;
	}

	int sum = 0;

	REP(i,N+1){
		if(red[i])
			sum++;
	}
	cout << sum << endl;

}

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

map<int,int> val;
int a,d;
int f(int x){
	if( !val.count(x) ) val[x] = a+(x-1)*d;
	return val[x];
}

signed main(){
	int N;
	cin >> N;
	cin >> a >> d;
	int M;
	cin >> M;
	for(int i = 0 ; i < M ; i++){
		int x,y,z;
		cin >> x >> y >> z;
		if( x == 0 ){
			f(y);
			f(z);
			swap(val[y],val[z]);
		}else{
			f(y);
			f(z);
			val[y] = val[z];
		}
	}
	int K;
	cin >> K;
	cout << f(K) << endl;
}

Measured memory_bytes: 1196
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)
func main(){
	W := nextInt()
	H := nextInt()
	x := nextInt()
	y := nextInt()
	r := nextInt()
	if (0<=x-r && x+r<=W && 0<=y-r && y+r<=H){
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

/* templates */

func Max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func Min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func Sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func Abs(a float64) float64 {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}

func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func nextString() string {
	return nextReader()
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}



Measured memory_bytes: 1072
S = input()

Sa = int(S[:2])
Sb = int(S[2:])

if 1 <= Sa <= 12 and 1 <= Sb <= 12 :
    print("AMBIGUOUS")
elif 1 <= Sa <= 12 :
    print("MMYY")
elif 1 <= Sb <= 12 :
    print("YYMM")
else :
    print("NA")


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

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

    vector<int> s = vector<int>(N);

    rep(i, K)
    {
        int d;
        cin >> d;

        rep(j, d)
        {
            int index;
            cin >> index;
            s.at(index - 1) += 1;
        }
    }

    size_t ss = s.size();

    size_t count = 0;

    for (long k = 0; k < ss; ++k)
    {
        if (s.at(k) == 0)
        {
            ++count;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, ans = 0;
    cin >> n;
    ll repeat = (n-1)/11;
    n -= repeat * 11;
    if (n <= 6) {
        cout << repeat*2 + 1 << endl;
    } else {
        cout << repeat*2 + 2 << endl;
    }
    return 0;
}



Measured memory_bytes: 256
N, K = [int(x) for x in input().split()]
temp = [int(x) for x in input().split()]
p = [-1]
for x in temp:
    p.append(x)
c = [-1]
temp = [int(x) for x in input().split()]
 
for x in temp:
    c.append(x)
 
# print(p)
# print(c)
# print()
ans = -int(1e12)
for i in range(1, N+1):
    ans = max(ans, c[p[i]])
# print(ans)
for i in range(1, N+1):
    # print("i: ", i)
    visited = [False] * (N+1)
    cur_sum = 0
    cur_box = i
    l = 0
    k = K
    while k > 0:
        if visited[cur_box]:
            break
        cur_sum += c[p[cur_box]]
        ans = max(ans, cur_sum)
        visited[cur_box] = True
        cur_box = p[cur_box]
        k -= 1
        l += 1
        # print(cur_sum)
    if k != 0 and cur_sum > 0:
        cur_sum = (cur_sum * ((K // l)-1))
        ans = max(ans, cur_sum)
        k = (K % l) + l
        while k > 0:
            cur_sum += c[p[cur_box]]
            ans = max(ans, cur_sum)
            cur_box = p[cur_box]
            k -= 1
            # print(cur_sum)
    
    # print("i:", i , ", sum:", cur_sum)
print(ans)

Measured memory_bytes: 69696
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int sz1 , sz2;
string s;

vector<int> c[128];
int off[128][322];
int dp[301][301];
pair<int,int> to[301][301];
int flag[301][301];

int dp_search(int sz1,int sz2){
	memset(dp,-1,sizeof(dp));
	memset(flag,0,sizeof(flag));
	int r;
	dp[0][sz1] = 0;
	to[0][sz1] = make_pair(-1,-1);
	for(int p1 = 0 ; p1 <= sz1 ; p1++){
		for(int p2 = sz1 ; p2 <= sz2 ; p2++){
			if(dp[p1][p2] != -1){
				if(p1 < sz1){
					int i = off[s[p1]][p2];
					if(i != 9999){
						r = dp[p1][p2]+1;
						if(r>dp[p1+1][i+1]){
							to[p1+1][i+1] = make_pair(p1,p2);
							dp[p1+1][i+1] = r;
							flag[p1+1][i+1] = 1;
						}
					}
					r = dp[p1][p2];
					if(r > dp[p1+1][p2]){
						to[p1+1][p2] = make_pair(p1,p2);
						dp[p1+1][p2] = r;
					}
				}
				if(p2 < sz2){
					r = dp[p1][p2];
					if(r > dp[p1][p2+1]){
						to[p1][p2+1] = make_pair(p1,p2);
						dp[p1][p2+1] = r;	
					}
				}
			}
		}
	}
	return dp[sz1][sz2];
}
string get(int sz1,int sz2){
	string ans = "";
	while(sz1 != -1){
		int x = to[sz1][sz2].first;
		int y = to[sz1][sz2].second;
		if( flag[sz1][sz2] ){
			ans = string(1,s[x]) + ans;
		}
		sz1 = x;
		sz2 = y;
	}
	return ans;
}

int main(){
	while(cin >> s && s[0] != '#'){
		int last[26];
		for(int i = 0 ; i < 26 ; i++) last[i] = 9999;
		for(int i = s.size() ; i >= 0 ; i--){
			last[s[i]-'A'] = i;
			for(int j = 0 ; j < 26 ; j++){
				off[j+'A'][i] = last[j];
			}
		}
		int save[333]={0};
		// Ü ^ñ©çâéÆÍâ­ÈÁ½æË
		int currentmx = 0;
		for(int i = s.size()/2 ; i >= 1 ; i--){
			sz1 = i; sz2 = s.size();
			if(min(sz1,sz2-sz1) <= currentmx ) continue;
			save[i] = dp_search(sz1,sz2);
			currentmx = max(save[i],currentmx);
		}
		for(int i = s.size()/2+1 ; i < s.size() ; i++){
			sz1 = i; sz2 = s.size();
			if(min(sz1,sz2-sz1) <= currentmx ) continue;
			save[i] = dp_search(sz1,sz2);
			currentmx = max(save[i],currentmx);
		}
		for(int i = 1 ; i < s.size() ; i++){
			if(save[i] == currentmx){
				sz1 = i; sz2 = s.size();
				dp_search(sz1,sz2);
				cout << get(sz1,sz2) << endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 2360
def is_prime(q):
    routeq = int(q ** 0.5) + 1
    for i in range(2, routeq):
        if q % i == 0:
            return False

    return True

N = int(input())

counter = 1
num = 11
print(str(num), end = '')

while counter < N:
    num += 10
    if is_prime(num):
        print(' ' + str(num), end = '')
        counter += 1

print()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define DEBUG_VARIABLE(variable) cout << #variable << ":" << variable << endl

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
#define INF (1 << 9)
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
int n;

void printArray(int *array, int);
void printVector(Vector &v);
void printDimention(DVector &dv);

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll h;
    cin >> n >> h;
    int a[n], b[n];
    rep(i, n){
        cin >> a[i] >> b[i];
    }
    
    sort(b, b + n);
    sort(a, a + n);
    reverse(b, b + n);
    reverse(a, a + n);
    //printArray(a, n);
    //printArray(b, n);
    ll cnt = 0;
    ll res_h = h;
    rep(i, n){
        if(b[i] < a[0] || res_h <= 0){
            //cnt = i;
            break;
        }
        //DEBUG_VARIABLE(b[i]);
        res_h -= b[i];
        cnt++;
    }
    //DEBUG_VARIABLE(a[0]);
    if(res_h > 0){
        ll div = res_h / a[0];
        cnt += div;
        if(res_h % a[0] != 0){
            cnt++;
        }
    }
    cout << cnt << endl;
}

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

//Vectorの表示
void printVector(Vector &v){
    rep(i, (int)v.size()){
        if(i)   cout << " ";
        cout << v[i];
    }
    cout << endl;
}

//二次元配列の表示
void printDimention(DVector &dv){
    rep(i, (int)dv.size()){
        rep(j, (int)dv[i].size()){
            if(j)   cout << " ";
            cout << dv[i][j];
        }
        cout << endl;
    }
}

//numの中に何個2がかかってるか
int factor2(int num){
    int cnt = 0;
    while(num % 2 == 0){
        num /= 2;
        cnt++;
    }
    return cnt;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
ll ans[100000]={};
ll fun(ll a[],ll pos,ll n)
{
	if(pos>=n-1)
		return 0;
	if(ans[pos]!=-1)
		return ans[pos];
	return ans[pos]=min(abs(a[pos]-a[pos+1])+fun(a,pos+1,n),abs(a[pos]-a[pos+2])+fun(a,pos+2,n));
}
int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	memset(ans, -1, sizeof(ans));
    cin.sync_with_stdio(0);
    cin.tie(0); cin.exceptions(cin.failbit);
    ll n;
    cin>>n;
    ll a[n];
    rep(i,0,n)
    cin>>a[i];
    cout<<fun(a,0,n);
    return 0;
}


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

int main(){
    string s;
    getline(cin, s);

    for (int i = 0; i < s.size(); i++)
    {
        if(s.at(i) >= 'A' && s.at(i) <= 'Z') s.at(i) -= 'A' - 'a';
        else if(s.at(i) >= 'a' && s.at(i) <= 'z') s.at(i) += 'A' - 'a';
        cout << s.at(i);
    }
    cout << endl;
}


Measured memory_bytes: 3168
n = int(input())
l = []
cnt = 0
te = [0,0,0]
for i in range(n):
    l.append(input())
for i in l:
    if i[0] == "B" and i[-1] == "A":
        te[0] += 1
    elif i[0] == "B":
        te[1] += 1
    elif i[-1] == "A":
        te[2] += 1
    for j in range(len(i)-1):
        if i[j] == "A" and i[j+1] == "B":
            cnt += 1
if te[0] != 0:
    te[0] -= 1
    if te[1]>0:
        te[0] += 1
        te[1] -= 1
    if te[2]>0:
        te[0] += 1
        te[2] -= 1
print(cnt+te[0]+min(te[1],te[2]))

Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define int long long 
int32_t main(){
  int H,W;
  cin>>H>>W;
  if(H%3==0 || W%3==0) cout<<0;
  else{
    int ans=1000000000000;
  for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            swap(H,W);
            for(int i=1;i<=H;i++){
    int a1 = W*i;
    int a2 = (W/2)*(H-i);
    int a3 = H*W -a1-a2;
    ans=min(ans,max(a1,max(a2,a3))-min(a1,min(a2,a3)));
            }
            cout<<min(ans,min(H,W));
  }
}


Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x) {
    cerr << '{';
    __print(x.first);
    cerr << ',';
    __print(x.second);
    cerr << '}';
}
template <typename T>
void __print(const T &x) {
    int f = 0;
    cerr << '{';
    for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
    __print(t);
    if (sizeof...(v)) cerr << ", ";
    _print(v...);
}
#ifdef LOCAL
#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#else
#define debug(x...)
#endif

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    vector<ll> v_ans(N);
    ll counter = 0;
    REP(i, S.length() - 1) {
        if (S[i] == 'A' && S[i + 1] == 'C') {
            counter++;
        }
        v_ans[i+1] = counter;
    }
    debug(v_ans);

    REP(i, Q) {
        ll l, r;
        cin >> l >> r;
        cout << v_ans[r - 1] - v_ans[l - 1] << endl;
    }

    return 0;
}


Measured memory_bytes: 1872
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

a = input()
N = int(a.split(" ")[0])
X = int(a.split(" ")[1])

place = list(map(int,input().split(" ")))

b = []
place.append(X)
place.sort()
for i in range(len(place)-1):
    b.append(int(place[i+1]) - int(place[i]))
print(gcd_list(b))


Measured memory_bytes: 16276
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){

long long a,b,x;
cin>>a>>b>>x;
long long zero=0;
long long ans;
if(a!=0)ans=(b/x+1)-((a-1)/x+1);

if(a==0)ans=(b/x+1);
if(b==0)ans=1;
cout<<ans<<endl;

return 0;
}
/*
4 8 2

3

0 5 1

6

9 9 2

0

1 1000000000000000000 3

333333333333333333

*/


Measured memory_bytes: 256
# https://atcoder.jp/contests/agc020/tasks/agc020_a

import itertools
import collections
import bisect
import sys
input = sys.stdin.readline

def main():
    N, A, B = map(int, input().split())

    diff = B - A
    if diff % 2 == 1:
        print("Borys")
    else:
        print("Alice")


if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
#define int ll
#define INF 100000000000000
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
#define mp make_pair
vector<bool>used;
vector<vector<pii>>edge;
vector<int>d;
bool judge=true;
void dfs(int v,int val){
    used[v]=false;
    rep(i,edge[v].size()){
        int next=edge[v][i].first;
        int cost=edge[v][i].second;
        if(d[next]==INF){
            d[next]=val+cost;
            if(used[next])dfs(next,val+cost);
            continue;
        }
        else{
            if(d[next]!=INF&&d[next]!=cost+val)judge=false;
            else if(d[next]==cost+val){
                d[next]=val+cost;
                if(used[next])dfs(next,val+cost);
            }
        }
    }
}
signed main(){
    int n,m; cin>>n>>m;
    edge.resize(n);
    used.resize(n);
    d.resize(n);
    rep(i,n)d[i]=INF,used[i]=true;
    rep(i,m){
        int a,b,c;cin>>a>>b>>c;
        --a,--b;
        edge[a].push_back(mp(b,c));
        edge[b].push_back(mp(a,-c));
    }
    rep(i,n)if(used[i])dfs(i,0);
    if(judge)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 16512
#include <stdio.h>
int main(void){
    // Your code here!
    int n;
    int m;
    int s[5];
    int c[5];
    int d[3];
    
    scanf("%d %d", &n, &m);
    
    for(int i=0; i<3; i++){
        d[i]=-1;
    }
    
    for(int i=0; i<m; i++){
        scanf("%d %d", &s[i], &c[i]);
        if(d[s[i]-1]!=-1 && c[i]!=d[s[i]-1]){
            printf("-1");
            return 0;
        }
        d[s[i]-1]=c[i];
    }

    if(d[0]==0){
        if(n!=1){
            printf("-1");
            return 0;
        }
        else{
            printf("0");
            return 0;
        }
    }
    if(d[0]==-1 && n==1){
        printf("0");
        return 0;
    }
    
    if(d[0]==-1) d[0]=1;
    if(d[1]==-1) d[1]=0;
    if(d[2]==-1) d[2]=0;
    
    if(n==3) printf("%d", d[0]*100+d[1]*10+d[2]);
    else if(n==2) printf("%d", d[0]*10+d[1]);
    else if(n==1) printf("%d", d[0]);
}


Measured memory_bytes: 128
#include<stdio.h>

int main()
{
  int h,n;
  scanf("%d %d",&h,&n);
  
  int a[n];
  int count=0;
  for(int i=0;i<n;i++)
  {
    scanf("%d",&a[i]);
    count+=a[i];
  }
  
  
  if(h<=count)
  	printf("Yes");
  else
    printf("No");
  
  return 0;
}

Measured memory_bytes: 512
import math

N,D = map(int, input().split())
points = []
for i in range(N):
    points.append(list(map(int, input().split())))
count = 0
for i in range(N):
    for j in range(i + 1, N):
        b = []
        for k in range(D):
            b.append((points[i][k] - points[j][k])**2)
        b = sum(b)
        b = math.sqrt(b)
        if int(b) == b:
            count += 1

print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define EPS (1e-15)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define bet(x, a, b) (a) <= (x) && (x) < (b)
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int N;

	cin >> N;

	N %= 10;

	if (N == 3) cout << "bon" << endl;
	else if (N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
	else cout << "hon" << endl;

	return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD (1000000007)
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("input.txt");ofstream coutt("output.txt");


signed main(){
    FASTER;
    int a,b;cin>>a>>b;
    if(a>b){
        cout<<string(a,to_string(b)[0]);
    }else{
        cout<<string(b,to_string(a)[0]);
    }
    
}

Measured memory_bytes: 256