akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";

    //浅いのと先に戦う。
    void Solve()
    {
       
        int N = cin.Nextint;
        var G = Enumerable.Range(0, N).Select(i => new List<int>()).ToArray();
        for (int i = 1; i < N; i++)
        {
            G[cin.Nextint - 1].Add(i);
        }
        //sw.Start();
        var B = new bool[N];
        var dp = new int[N];
        var S = new Stack<int>();
        S.Push(0);
        while (S.Any())
        {
            int u = S.Pop();
            if (B[u])
            {
                if (G[u].Count == 0)
                {
                    dp[u] = 0;
                    continue;
                }
                var L = new List<int>();
                foreach (var v in G[u])
                {
                    L.Add(dp[v]);
                }
                dp[u] = L.OrderBy(k => rnd.Next()).OrderByDescending(k => k).Select((v, i) => new { v, i }).Max(k => k.v + k.i) + 1;
            }
            else
            {
                B[u] = true;
                S.Push(u);
                foreach (var v in G[u])
                {
                    S.Push(v);
                }
            }
        }

        WriteLine(dp[0]);
        //WriteLine(sw.Elapsed);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

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

using namespace std;

void insert_values(const vector<int>& vec, vector<int>& ret, int idx, int temp){
    if(idx == int(vec.size())){
        ret.push_back(temp);
        return;
    }
    insert_values(vec, ret, idx+1, temp);
    insert_values(vec, ret, idx+1, temp+vec[idx]);
}

vector<int> valid_values(const vector<int>& vec){
    auto ret = new vector<int>();
    insert_values(vec, *ret, 0, 0);
    sort(ret->begin(), ret->end());
    return *ret;
}

void print_vector(vector<int>& vec){
    for(auto it = vec.begin(); it != vec.end(); ++it){
        cout << *it << ' ';
    }
    cout << '\n';
}

int main(){
    int n;
    cin >> n;
    auto vec = vector<int>();
    for(int i = 0; i < n; ++i){
        int temp;
        cin >> temp;
        vec.push_back(temp);
    }
    auto vs = valid_values(vec);
    //print_vector(vs);
    int q;
    cin >> q;
    while(q--){
        int v;
        cin >> v;
        cout << (binary_search(vs.begin(), vs.end(), v) ? "yes" : "no") << endl;
    }
}

Measured memory_bytes: 9288
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
vector<long> divisor(long long m){
    vector<long> divisors; 
    for(int i = 1;i<=long(sqrt(m));i++){
        if(m%i == 0){
            if(m/i==i) divisors.push_back(i);
            else{
                divisors.push_back(i);
                divisors.push_back(m/i);
            }
        }
    }
    return divisors;
}
int main(){
    long long n;
    cin >> n;
    int a[n+1];
    rep(i,n){
        cin >> a[i+1];
    }
    long long b[n+1];
    long long c[n+1];
    rep(i,n+1){
        c[i]=0;
    }
    long long k;
    long long ans = 0;
    vector<long> divi; 
    for(int i = n;i>=1;i--){
        if(c[i]%2==0){
            b[i] = a[i];
        }
        else{
            if(a[i]==1) b[i]=0;
            else b[i]=1;
        }
        if(b[i]==1){
            ans++;
            k = i;
            divi = divisor(k);
            rep(j,divi.size()){
                c[divi[j]]++;
            }
        }
    }
    cout << ans << endl;
    rep(i,n){
        if(b[i+1]==1) cout << i+1 << " ";
    }
    cout << endl;
}

Measured memory_bytes: 4736
def main():
    n = int(input())
    lr = [list(map(int, input().split())) for _ in [0] * n]
    lr.sort(key=lambda x: (x[0], x[1]))
    min_r = [0] * n
    min_r[0] = lr[0][1]
    min_l = [0] * n
    min_l[n-1] = lr[n-1][1]
    for i in range(1,n):
        min_r[i] = min(min_r[i - 1], lr[i][1])
    for i in range(n-2,-1,-1):
        min_l[i] = min(min_l[i + 1], lr[i][1])
    ans = max([max(min_r[i] - lr[i][0] + 1, 0) + max(min_l[i + 1] - lr[n - 1][0] + 1, 0) for i in range(n - 1)])
    l,r,w=0,10**9+1,0
    for i in range(n):
        l = max(l, lr[i][0])
        r = min(r, lr[i][1])
        w = max(w, lr[i][1] - lr[i][0]+1)
    ans = max(ans, max(r - l + 1, 0) + w)
    print(ans)
main()


Measured memory_bytes: 37564
while True:
    H, W = map(int, input().split())
    if H==0 and W==0:
        break
    for i in range(H):
        line = ""
        for j in range(W):
            line += '#' if (i%2==0 and j%2==0) or (i%2!=0 and j%2!=0) else '.'
        print(line)
    print()


Measured memory_bytes: 5612
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
string s;

int main()
{
	cin>>s;
	int l=s.length();
	int c=200,f=0;
	for(int i=0;i<l;i++)
	{
		if(s[i]=='C')
		{
			c=i;
			break;
		}
	}
	for(int i=l-1;i>=0;i--)
		if(s[i]=='F')
		{
			f=i;
			break;
		}
	if(f>c) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll n,m;cin >> n >>m;
    vl v(n);
    rep(i,n){
        ll a;cin >> a;a--;
        v[i]=a;
    }
    UnionFind uf(n);
    rep(i,m){
        ll a,b;cin >>a >>b;a--;b--;
        uf.merge(a,b);
    }
    ll ans=0;
    rep(i,n){
        if(uf.same(v[i],i))ans++;
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rep2(i,start,end) for(ll i = start; i < end; i++)
#define dwn(i,n) for(int i = n; i >= 0; i--)
#define dwn2(i,start,end) for(ll i = start; i >= end; i--)
#define pll pair<ll,ll>
#define mk(x,y) make_pair(x,y)
#define pdl pair<double, ll>
const ll N = 4e5 + 200;
const ll INF = 0x3f3f3f;
const ll Mode = 1e9 + 7;


int main(){
	ll n;
	cin>>n;
	priority_queue<double, vector<double>, greater<double>> p;
	rep(i,n){
		ll x;
		cin>>x;
		p.push(x);
	}
	while(p.size() > 1){
		double x,y;
		x = p.top();
		p.pop();
		y = p.top();
		p.pop();
		p.push((x+y)/2.0);
	}
	cout<<p.top()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int a,b,c,d;
	d = 0;
	scanf("%d %d",&a,&b);


	for(int i=0;i<b;i++){
		scanf("%d",&c);
		d += c;
	}
	if(a<=d){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}

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

const int INF = 1e9;

int main() {
  int n;
  cin>>n;
  int t[n+1],x[n+1],y[n+1];
  t[0]=0;
  x[0]=0;
  y[0]=0;
  for(int i=1;i<n+1;i++){
    cin>>t[i]>>x[i]>>y[i];
  }
  for(int i=1;i<n+1;i++){
    int dist=abs(x[i]-x[i-1])+abs(y[i]-y[i-1]);
    if(dist>t[i]-t[i-1]){
      cout<<"No"<<endl;
      return 0;
    }
    if(abs(dist-(t[i]-t[i-1]))%2 != 0){
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;

}

Measured memory_bytes: 1408
<?php

//10,000個超の素数作成
$max = 105000;
$arr = new \SplFixedArray($max + 1);
for ($i = 2; $i <= $max; $i++) {
    $arr[$i] = 1;
}
for ($i = 2, $len = sqrt($max); $i <= $len; $i++) {
    if (!$arr[$i]) {
        continue;
    }

    for ($j = $i, $len2 = $max / $i; $j <= $len2; $j++) {
        $arr[$i * $j] = 0;
    }
}

while (($line = trim(fgets(STDIN))) !== '0') {
    $n = (int)$line;
    $result = 0;
    $cnt = 0;
    for ($i = 2; $i <= $max; $i++) {
        if ($cnt === $n) {
            break;
        } elseif ($arr[$i]) {
            $result += $i;
            $cnt++;
        }
    }
    echo $result, PHP_EOL;
}

Measured memory_bytes: 12292
x = int(input())

if x < 600:
  print('8')
elif 600 <= x and x < 800:
  print('7')
elif 800 <= x and x < 1000:
  print('6')
elif 1000 <= x and x < 1200:
  print('5')
elif 1200 <= x and x < 1400:
  print('4')
elif 1400 <= x and x < 1600:
  print('3')
elif 1600 <= x and x < 1800:
  print('2')
elif 1800 <= x and x < 2000:
  print('1')

Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;

int main(){
    int N;cin >>N;
    vector<long long> B(N);
    vector<long long > A(N);
    long long ans = 0;
    for(int i=0;i<N;i++) {cin >> A[i]; A[i]--; B[A[i]]++;}
    for(int i=0;i<N;i++){
        ans += B[i]*(B[i]-1)/2;
    }

    for(int i=0; i<N;i++){
        cout << ans - B[A[i]] + 1 << endl;
    }
}


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

MOD = 10**9
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

N = int(input())
l = []
for i in range(N):
    l.append(input())

print(len(set(l)))




Measured memory_bytes: 35716
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
		long p = 1;
	    for(int i = 1; i <= A; i++){
	    	p = p * i;
	    	p = p % 1000000007;
	    }
		System.out.println(p);
		// TODO Auto-generated method stub

	}

}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
using ll = long long;
#define ull unsigned ll
#define endl "\n"
#define vi vector<int>
#define vl vector<ll>
#define all(v) (v).begin(),(v).end()
#define mst(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ppi pair<int, pii>
#define mt make_tuple
#define eb emplace_back
using namespace std;

const int N = 5e5 + 5, mod = 1e9 + 7;
const int inf = 1e9;
void solve(){
    int n;
    cin >> n;
    vi x(n+ 5);
    int ans = 0;
    for(int i = 1; i * i <= 2 * n; i++){
        for(int j = 1; j * j <= 2 * n; j++){
            for(int k = 1; k * k <= 2 * n; k++){
                int a = i + j;
                int b = j + k;
                int c = k + i;
                int y = a * a + b * b + c * c;
                if(y > 2 * n){
                    break;
                }
                if(y % 2 == 0){
                    x[y / 2]++;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++){
        cout << x[i] << endl;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);//cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ll t,p;
    t=1;
    //cin>>t;
    for(p=1;p<=t;p++){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3528
#include <iostream>

using namespace std;
int main(int argc, char const *argv[])
{
	int a;
	cin >> a;

	int b;
	cin >> b;

	int h;
	cin >> h;

	int res = 0;
	res = ((a+b)*h)/2;

	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String [] args)
    {
        Scanner keyboard = new Scanner(System.in);
        int num = keyboard.nextInt();
        
        int points_500 = 0;
        int points_5 = 0;

        while(num > 5)
        {
            
            if(num > 499)
            {
                points_500 = num/500;
                num = num % 500;
            }
            else
            {
                points_5 = num/5;
                num = num%5;
            }

            
        }
        System.out.println((points_5 * 5) + (points_500 *1000));
    }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define eps 1e-10
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N;
vector<P> v;

int main () {
  cin >> N;

  Rep(i, N) {
    ll x, l;
    cin >> x >> l;
    v.emplace_back(x-l, x+l);
  }

  sort(All(v), [](P& x, P& y){ return x.second < y.second; });

  ll tmp = -LINF;
  ll ans = 0;

  for (auto p: v) {
    ll b = p.first;
    ll e = p.second;

    if (tmp > b) continue;

    ans++;
    tmp = e;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W,a,b; cin>>H>>W>>a>>b;
int counter=0;
int counter1=0;
for(int i=0;i<b;i++){
for(int j=0;j<W;j++){
if(counter<a){
cout<<0;}
else{
cout<<1;}
counter++;}
cout<<endl;
counter=0;
}
counter=0;
for(int i=0;i<H-b;i++){
for(int j=0;j<W;j++){
if(counter<a){
cout<<1;}
else{
cout<<0;}
counter++;}
cout<<endl;
counter=0;
}}



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

#define INF (1 << 21)


int min(int a,int b){
  if(a > b){
    return b;
  }
  else return a;
}

int matrixChainOrder(int *p,int n){
  int i, j ,k, l, q;
  int **m;
  m = (int **)malloc(sizeof(int *)*(n+1));
  for(i=0; i<=n; i++){
    m[i] = (int *)malloc(sizeof(int)*(n+1));
  }

  for(i=0; i<=n; i++){
    m[i][i] = 0;
  }
  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k < j; k++){
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        m[i][j] = min(m[i][j], q);
      }
    }
  }
  return m[1][n];
}



int main(){

  int n, i, m, r, c, *p;

  scanf("%d", &n);
  p = (int *)malloc(sizeof(int)*(n+1));

  for(i=0; i< n; i++){
    scanf("%d%d", &r, &c);
    p[i] = r;
  }
  p[i] = c;

  m = matrixChainOrder(p,n);

  printf("%d\n", m);
  return 0;
}


Measured memory_bytes: 2112
import java.util.*;
public class Main {
	public static void main(String[] args){
    	Scanner scanner = new Scanner(System.in);
      
      	int N = scanner.nextInt();
      	int K = scanner.nextInt();
      
   		//Listにうまく変換するため
      	Integer[] dislikeNumberInteger = new Integer[K];

      	for(int i = 0; i < K; i++) {
          	dislikeNumberInteger[i] = Integer.valueOf(scanner.nextInt());
        }
     
      	for(int i = 0; i < 10; i++) {
          	int count = 0;
        	first:while(true) {
              	if(Arrays.asList(dislikeNumberInteger).contains(N / (int) Math.pow(10, i) - (N / (int) Math.pow(10, i + 1)) * 10) == false) {
               		if(count != 0) {
                   		//処理＊
                       	Integer[] digits = new Integer[6];
                      	int rest = N;
                      	for(int m = 5; m > -1; m--) {
                       		digits[m] = rest / (int) Math.pow(10, m);
                           	rest = rest % (int) Math.pow(10, m);
                      	}
                     	second:for(int k = 0; k < 10; k++) {
                       		if(Arrays.asList(dislikeNumberInteger).contains(k) == false) {
                            	for(int j = i - 1; j > -1; j--) {
                              		digits[j] = k;
                               	}
                              	break second;
                            }
                      	}
                		N = 0;
                      	for(int z = 0; z < 6; z++) {
                    		N = N + (int) Math.pow(10, z) * digits[z];
                        }
                      	
                    }
                  	if(N < (int) Math.pow(10, i + 1)) {
                    	System.out.println(N);
                      	return;
                    }
                  	break first;
                }
              	N = N + (int) Math.pow(10, i);
              	count = count + 1;
            }
        }	
	}
}
 

 



Measured memory_bytes: 23636
#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
#pragma intrinsic(_umul128)
using namespace std; using namespace atcoder;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//--------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int N, Q;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> Q;

	dsu uf(N);
	rep(q, 0, Q) {
		int t, u, v; cin >> t >> u >> v;
		if (t == 0) uf.merge(u, v);
		else {
			printf("%d\n", uf.same(u, v) ? 1 : 0);
		}
	}
}


Measured memory_bytes: 3992
#include<stdio.h>
int main()
{
    int x,a,b,m,n;
    while(~scanf("%d%d%d",&x,&a,&b))
    {
        if(x-a>0)
        {
            m=x-a;
            }
       else
       {
           m=-(x-a);
       }
    if(x-b>0)
       {
           n=x-b;
       }
       else
    {
        n=-(x-b);
       }
    if(m>n)
       {
           printf("B\n");
       }
       else
{
    printf("A\n");
}
    }

}








Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{

    int a,b;
    char op;

    for(int i=0;i<=1000;i++)
    {
        scanf("%d %c %d", &a, &op, &b);
        if (op == '?')break;
        else if (op == '+')printf("%d\n", a + b);
        else if (op == '-')printf("%d\n", a - b);
        else if (op == '*')printf("%d\n", a * b);
        else if (op == '/')printf("%d\n", a / b);
    }

    return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int64_t i = 0; i < (int64_t)(n); i++)
#define mod(a) a % 1000000007;

int64_t myadd(int64_t a, int64_t b) {
  int64_t a_ = mod(a);
  int64_t b_ = mod(b);
  return mod( a_ + b_ );
}

int64_t myprod(int64_t a, int64_t b) {
  int64_t a_ = mod(a);
  int64_t b_ = mod(b);
  return mod( a_ * b_ );
}

int64_t myfact(int64_t n) {
  if ( n == 1 ) {
    return 1;
  }
  return myprod(n, myfact(n-1));
}

int main() {
  //input
  int64_t N;
  string S;
  cin >> N >> S;
  //calc
  int64_t answer;
  
  if ( S.at(0) == 'W' ) {
    answer = 0;
  }
  else {
    int64_t base = 1;
    int64_t l = 0;
    int64_t r = 0;
    bool is_left = true;
    char pre_c = '_';
    char c;
    rep(i,2*N) {
      c = S.at(i);
      if ( c == pre_c ) {
        is_left = !is_left;
      }
      if ( is_left ) {
        l++;
      }
      else {
        base = myprod(base, l-r);
        r++;
      }
  //    cout << "(" << l << "," << r << ")" << endl;
      pre_c = c;
    }
    if ( l == r ) {
      answer = myprod(base, myfact(N));
    }
    else {
      answer = 0;
    }
  }
  //output
  cout << answer << endl;
}


Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int h[100010];
int dp[100010];
int main()
{
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> h[i];
		dp[i] = mod * 2;
	}
	dp[0] = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 1; j <= K; j++) {
			if (i + j < N) {
				dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
			}
		}
	}
	cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1024
A, B = map(int, input().split())

m = 1/0.08
M = 100/0.08

#print(m, M)

for i in range(13, 1250):
    a = int(i * 0.08)
    b = int(i * 0.10)
    if a == A and b == B:
        print(i)
        exit()
print(-1)

Measured memory_bytes: 38640
#include <iostream>
#include <vector>
#include <atcoder/scc>

namespace ac = atcoder;

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

    ac::scc_graph graph(n);
    while (m--) {
        int u, v;
        std::cin >> u >> v;
        graph.add_edge(u, v);
    }

    auto gs = graph.scc();

    std::cout << gs.size() << "\n";
    for (const auto& vs : gs) {
        std::cout << vs.size();
        for (auto v : vs) std::cout << " " << v;
        std::cout << "\n";
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 40088
let pair f s = s |>
               Str.split (Str.regexp " ") |>
               List.map f |>
               (function | [a; b] -> (a, b)
                         | _ -> failwith "invalid input")

let board (h, w) =
  let rows =
    let rec make_row i acc = match i with
      | 0 -> String.concat "" acc
      | _ -> make_row (i-1) ((if i mod 2 = 0 then "." else "#") :: acc)
    in
    let row_sub = String.sub (make_row (w+1) []) in
    [|(row_sub 1 w) ^ "\n"; (row_sub 0 w) ^ "\n"|]
  in
  let rec loop i acc = match i with
    | 0 -> acc
    | _ -> loop (i-1) (rows.(i mod 2) :: acc)
  in
  String.concat "" (loop h [])

let rec main_loop () =
  match read_line () with
  | "0 0" -> ()
  | line -> main_loop (print_endline (board (pair int_of_string line)))

let () = main_loop ()

Measured memory_bytes: 2180
package main

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

func main() {
	r := bufio.NewReader(os.Stdin)
	var k int
	fmt.Fscan(r, &k)

	ans := 0
	for a := 1; a <= k; a++ {
		for b := 1; b <= k; b++ {
			for c := 1; c <= k; c++ {
				ans += gcd(gcd(a, b), c)
			}
		}
	}
	fmt.Println(ans)
}

// Union-Find
type unionFind struct {
	d []int
}

func newUnionFind(n int) *unionFind {
	uf := new(unionFind)
	uf.d = make([]int, n)
	for i := 0; i < n; i++ {
		uf.d[i] = -1
	}
	return uf
}

func (uf *unionFind) find(x int) int {
	if uf.d[x] < 0 {
		return x
	}
	uf.d[x] = uf.find(uf.d[x])
	return uf.d[x]
}

func (uf *unionFind) unite(x, y int) bool {
	rootX := uf.find(x)
	rootY := uf.find(y)
	if rootX == rootY {
		return false
	}

	if uf.d[rootX] < uf.d[rootY] {
		uf.d[rootX] += uf.d[rootY]
		uf.d[rootY] = rootX
	} else {
		uf.d[rootY] += uf.d[rootX]
		uf.d[rootX] = rootY
	}

	return true
}

func (uf *unionFind) same(x, y int) bool {
	return uf.find(x) == uf.find(y)
}

func (uf *unionFind) size(x int) int {
	return -uf.d[uf.find(x)]
}

// mod combination
func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

// Utility

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}

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

// Queue ...
type Queue []int

// pop ...
func (q *Queue) empty() bool {
	return len(*q) == 0
}

// push ...
func (q *Queue) push(i int) {
	*q = append(*q, i)
}

// pop ...
func (q *Queue) pop() (int, bool) {
	if q.empty() {
		return 0, false
	} else {
		res := (*q)[0]
		*q = (*q)[1:]
		return res, true
	}
}

// Stack ...
type Stack []int

// pop ...
func (s *Stack) empty() bool {
	return len(*s) == 0
}

// push ...
func (s *Stack) push(i int) {
	*s = append(*s, i)
}

// pop ...
func (s *Stack) pop() (int, bool) {
	if s.empty() {
		return 0, false
	} else {
		index := len(*s) - 1
		res := (*s)[index]
		*s = (*s)[:index]
		return res, true
	}
}


Measured memory_bytes: 1860
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long x;
long long ans;
int main()
{
	cin>>x;
	for(ans=1;1;ans++)
	{
		if(ans*(ans+1)/2>=x)
		{
			cout<<ans<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a[200001];
bool v[200001];

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }

  int t = 1, ans = 0;
  while (1) {
    ans++;
    v[t] = true;
    t = a[t];
    if (t == 2)
      break;
    if (v[t]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <iomanip>
#include <vector>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <ctime>
#include <fstream>
#include <stdarg.h>
using namespace std;
const bool debug=false;
const bool INJUDGE=false;
#define FASTERCIN cin.tie(0);ios_base::sync_with_stdio(false)
typedef long long ll;
/*Time:2018.4.7
Status:
Type:Atcoder Beginner #93
Author:zm_x*/
string s;
int main(){
	cin>>s;
	sort(s.begin(),s.end());
	if(s=="abc")puts("Yes"); else puts("No");
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N;
ll A[202020];
ll mk[1010101];
ll prmk[1010101];

ll i, j, k;

int main(){
    scanf("%lld", &N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        ++mk[A[i]];
    }
    
    ll ans = 0;
    fornum(i,1,1010101){
        if(mk[i]==0)
            continue;
        if(mk[i]==1)
            ++ans;
        for (j = i; j < 1010101; j += i)
        {
            mk[j] = 0;
        }
    }

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

Measured memory_bytes: 13144
def chmin(a, b):
  if a > b:
    return b
  else:
    return a

def main():
  dp = [1e10]*100010
  hs = [0]*100010
  
  N = int(input())
  hs[:N] = map(int, input().split())
  
  dp[0] = 0
  for i in range(N):
    dp[i+1] = chmin(dp[i+1], dp[i]+abs(hs[i+1]-hs[i]))
    dp[i+2] = chmin(dp[i+2], dp[i]+abs(hs[i+2]-hs[i]))
  print(dp[N-1])
  return

if __name__ == '__main__':
  main()

Measured memory_bytes: 15312
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

}


Measured memory_bytes: 1152
import sys
x,y = map(int,input().split())
if (y == 0):
  print('No')
  sys.exit()
for turu in range(x + 1):
  f = ( 4 * x - y ) / 2 
  if( int(f) == int(turu) and f.is_integer()):
    print('Yes')
    sys.exit()
print('No')  

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

int main() {
	string ra[8] = { "AAA","AA","A","B","C","D","E","NA" };
	int fr,tr,n;
	double fm, tm;
	while (cin >> fm >> tm) {
		if (fm < 35.5) { fr = 0; }
		else if (fm < 37.5) { fr = 1; }
		else if (fm < 40) { fr = 2; }
		else if (fm < 43) { fr = 3; }
		else if (fm < 50) { fr = 4; }
		else if (fm < 55) { fr = 5; }
		else if (fm < 70) { fr = 6; }
		else { fr = 7; }

		if (tm < 71) { tr = 0; }
		else if (tm < 77) { tr = 1; }
		else if (tm< 83) { tr = 2; }
		else if (tm < 89) { tr = 3; }
		else if (tm < 105) { tr = 4; }
		else if (tm < 116) { tr = 5; }
		else if (tm < 148) { tr = 6; }
		else { tr = 7; }

		if (fr <= tr) { n = tr; }
		else { n = fr; }

		cout << ra[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;

int fun(int x,int y,int z)
{
	return x*x + y*y + z*z + x*y + y*z + z*x;
}

int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS


    map<int,int> mp;

    int n;
    cin >> n;

    for(int i = 1; i <= 100; i++){
    	for(int j = 1; j <= 100; j++){
    		for(int k = 1; k <= 100; k++){
    			int val = fun(i,j,k);
    			if(val > n)break;
    			mp[val]++;
    		}
    	}
    }

    for(int i = 1; i <= n; i++){
    	cout << mp[i] << endl;
    }




    return 0;
}


Measured memory_bytes: 4284
using System;

namespace ITP1_5_C
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string[] strs = Console.ReadLine().Split(' ');
                int h = int.Parse(strs[0]);
                int w = int.Parse(strs[1]);
                if (h == 0 && w == 0) break;
                for (int i = 0; i < h; i++)
                {
                    for (int j = 0; j < w; j++)
                    {
                        Console.Write(((i + j & 1) == 1) ? '.' : '#');
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}

Measured memory_bytes: 8720
A, B, K = map(int, input().split())
tmp = []
for i, n in enumerate(range(A, B+1)):
    if i >= K:
        break
    tmp.append(n)
for i, n in enumerate(range(B, A-1, -1)):
    if i >= K:
        break
    tmp.append(n)
tmp = list(set(tmp))
tmp.sort()
for i in tmp:
    print(i)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int inf=1e16;
const int N=2e5+5;
const int mod=1e9+7;
int n,a[N],dp[N][3][2];

/// 0:none
/// 1:left
/// 2:right

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=2;j++)
        {
            for(int k=0;k<=1;k++) dp[i][j][k]=-inf;
        }
    }
    dp[0][0][0]=0;
    for(int i=1;i<=n;i+=2)
    {
        int id=(i+1)/2;
        dp[id][0][1]=max({dp[id-1][1][0],dp[id-1][2][0],dp[id-1][0][0]});
        dp[id][1][0]=max(dp[id-1][0][0],dp[id-1][1][0])+a[i];
        dp[id][2][0]=max({dp[id-1][0][0],dp[id-1][1][0],dp[id-1][2][0]})+a[i+1];
        dp[id][1][1]=max(dp[id-1][0][1],dp[id-1][1][1])+a[i];
        dp[id][2][1]=max({dp[id-1][0][1],dp[id-1][1][1],dp[id-1][2][1]})+a[i+1];
    }
    int res=max(dp[n/2][1][0],dp[n/2][2][0]);
    if(n%2==0) cout<<res;
    else
    {
        int val=max(dp[n/2][0][1],dp[n/2][1][1])+a[n];
        cout<<max(res,val);
    }
}


Measured memory_bytes: 14548
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# L と 2 ** n の差
L = ir()
length = L.bit_length()
edges = []
for i in range(1, length):
    edges.append((i, i+1, 0))
    edges.append((i, i+1, 2**(i-1)))

for i in range(length-1):
    if L >> i & 1:
        L -= 2**i
        edges.append((i+1, length, L))

print(length, len(edges))
for e in edges:
    print(*e)

# 56

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author NMouad21
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    NSlimes solver = new NSlimes();
    solver.solve(1, in, out);
    out.close();
  }

  static class NSlimes {
    public final void solve(int testNumber, InputReader in, PrintWriter out) {
      int n = in.nextInt();
      int[] a = in.nextIntArrayOneBased(n);
      long[] pre = new long[n + 1];
      for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] + a[i];
      }

      long[][] dp = new long[n + 1][n + 1];
      for (int i = n; i >= 1; i--) {
        for (int j = i + 1; j <= n; j++) {
          dp[i][j] = pre[j] - pre[i - 1] + dp[i][i] + dp[i + 1][j];
          for (int k = i + 1; k < j; k++) {
            dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j] + pre[j] - pre[i - 1]);
          }
        }
      }

      out.println(dp[1][n]);
    }
  }

  static final class InputReader {
    private final InputStream stream;
    private final byte[] buf = new byte[1 << 16];
    private int curChar;
    private int numChars;

    public InputReader() {
      this.stream = System.in;
    }

    public InputReader(final InputStream stream) {
      this.stream = stream;
    }

    private final int read() {
      if (this.numChars == -1) {
        throw new UnknownError();
      } else {
        if (this.curChar >= this.numChars) {
          this.curChar = 0;

          try {
            this.numChars = this.stream.read(this.buf);
          } catch (IOException ex) {
            throw new InputMismatchException();
          }

          if (this.numChars <= 0) {
            return -1;
          }
        }

        return this.buf[this.curChar++];
      }
    }

    public final int nextInt() {
      int c;
      for (c = this.read(); isSpaceChar(c); c = this.read()) {}

      byte sgn = 1;
      if (c == 45) { // 45 == '-'
        sgn = -1;
        c = this.read();
      }

      int res = 0;

      while (c >= 48 && c <= 57) { // 48 == '0', 57 == '9'
        res *= 10;
        res += c - 48; // 48 == '0'
        c = this.read();
        if (isSpaceChar(c)) {
          return res * sgn;
        }
      }

      throw new InputMismatchException();
    }

    private static final boolean isSpaceChar(final int c) {
      return c == 32 || c == 10 || c == 13 || c == 9
          || c == -1; // 32 == ' ', 10 == '\n', 13 == '\r', 9 == '\t'
    }

    public final int[] nextIntArrayOneBased(final int n) {
      int[] ret = new int[n + 1];
      for (int i = 1; i <= n; i++) {
        ret[i] = nextInt();
      }
      return ret;
    }
  }
}


Measured memory_bytes: 22100
#include<iostream>
#include<deque>
#include<vector>
#include<algorithm>

using namespace std;

const int MAXN = 200005;

int n;
int a[MAXN];
deque <int> q;

int main () {
	cin >> n;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		if (i&1) q.push_front(a[i]); else q.push_back(a[i]);
	}
	if (n%2==0) {
		for (int i=0; i<n; i++) {
			cout << q.front() << " ";
			q.pop_front();
		}
	} else {
		for (int i=0; i<n; i++) {
			cout << q.back() << " ";
			q.pop_back();
		}
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

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

int main() {
  ll a, b;
  while (cin >> a >> b) {
    cout << gcd(a, b) << " " << lcm(a, b) << endl;
  }
  return 0;
}


Measured memory_bytes: 3096
/*
❤️❤️❤️I_love_QMsh❤️❤️❤️
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // <int> .find_by_order(int) .order_of_key(int)

template<typename T> bool smin(T &a, const T &b) { bool ret = b < a;  return a = (ret ? b : a), ret; }
template<typename T> bool smax(T &a, const T &b) { bool ret = a < b; return a = (ret ? b : a), ret; }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

mt19937 rnd;

signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  string s;
  cin >> s;
  int n = s.size();
  vector<int> cnt(26);
  vector<int> old(26);
  vector<pair<int, int>> m_diff(26, {0, -1});
  for (int i = 0; i < n; i++) {
    int c = s[i] - 'a';
    cnt[c]++;
    if (i > 0 && cnt[c] - (i + 1 - cnt[c]) + m_diff[c].first > 0) {
      return cout << m_diff[c].second + 2 << " " << i + 1, 0;
    }
    for (int t = 0; t < 26; t++) {
      smax(m_diff[t], {(i - old[t]) - old[t], i - 1});
    }
    old = cnt;
  }

  cout << "-1 -1";
  return 0;
}

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


vector<int>E[100],G[100];
int a[100],b[100];
bool used[100];

int main(){
	int n;scanf("%d",&n);
	rep(i,n)scanf("%d",&a[i]);
	rep(i,n)scanf("%d",&b[i]);
	ll ans=0;
	for(int i=51;i>=1;i--){
		rep(j,51)G[j]=E[j];
		for(int j=1;j<i;j++){
			rep(k,51)G[k].push_back(k%j);
		}
		bool flag=false;
		rep(j,n){
			queue<int>que;
			memset(used,0,sizeof(used));
			used[a[j]]=true;que.push(a[j]);
			while(!que.empty()){
				int p=que.front();que.pop();
				for(int u:G[p]){
					if(!used[u]){
						used[u]=true;que.push(u);
					}
				}
			}
			if(!used[b[j]]){
				flag=true;break;
			}
		}
		if(flag){
			if(i==51){
				puts("-1");return 0;
			}
			ans|=1LL<<i;
			rep(j,51)E[j].push_back(j%i);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define mem(a,b) memset((a),(b),sizeof(a))
#define MP make_pair
#define pb push_back
#define fi first
#define se second
#define sz(x) (int)x.size()
#define len(x) (int) x.length()
#define all(x) x.begin(),x.end()
#define _GLIBCXX_PERMIT_BACKWARD_HASH
#include <ext/hash_map>
using namespace __gnu_cxx;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
struct str_hash{size_t operator()(const string& str)const{return __stl_hash_string(str.c_str());}};
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double eps=1e-4;
const int MAX=1e5+10;
const ll mod=1e9+7;
/****************************************  head  ****************************************/
int main()
{
	int n,i,ans;
	while(~scanf("%d",&n))
	{
		VI a(n);
		for(auto &it:a) scanf("%d",&it);
		ans=0;
		int tot=1;
		for(i=1;i<n;i++)
		{
			if(a[i]==a[i-1]) a[i]=-(tot++),ans++;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

N = int(input())
A = []
for i in range(N):
	A.append(int(input()))

B = []
min = -10000000000
for i in range(N):
	loc = bisect.bisect_right(B, -A[i])
	if loc == len(B):
		B.append(-A[i])
	else:
		B[loc] = -A[i]

print(len(B))

Measured memory_bytes: 48860
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,ans=0; cin>>n;
    vector<int> a(n,0),b(n,0);
    rep(i,n){
        cin>>a[i];
        b[i]=a[i];
    }
    sort(al(a));
    set<int> s;
    rep(i,(n+1)/2) s.insert(a[2*i]);
    rep(i,(n+1)/2) if(s.count(b[2*i])==0) ans++;
    cout<<ans<<endl;
}

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

int main() {
char character;
cin >> character;
if (character == 'a' || character == 'i'  || character == 'u' || character == 'e' || character == 'o' ) {
cout << "vowel" << endl;
}
else {
cout << "consonant" << endl;
}
}


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

vector<pair<ll, ll> > prime_factorize(ll N) {
    vector<pair<ll, ll> > res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back(make_pair(a, ex));
    }

    if (N != 1) res.push_back(make_pair(N, 1));
    return res;
}

int main() {
    ll N;
    cin >> N;
    const auto &res = prime_factorize(N);
    int ans=0;
    for (auto p : res) {
        int x = p.second;
        int b = 1;
        while (b <= x) {
            x -= b;
            b++;
            ++ans;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;
string s;

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

    llong cnt = 1;
    for (int i = 1; i < s.size(); i++) {
        if (s[i] != s[i - 1]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	while(true){
		int N=in();
		if(!N) break;
		auto V=vecin<ll>(N);
		sort(ALL(V));
		vector<ll> S(N-1,0);
		if(N>1) S[0]=V[0];
		for(int i=1;i<N-1;i++){
			S[i]=S[i-1]+V[i];
		}
		auto ans=accumulate(ALL(S),0LL);
		out(ans);
	}
	return 0;
}



Measured memory_bytes: 3200
#include <stdio.h>

int main(void)
{
	int p, q;
	int residue[100];
	int n, n1;
	int i;

	while (scanf("%d%d", &p, &q) != EOF){
		n = 0;
		
		while (1){
			for (i = 0; i < n; i++){
				if (residue[i] == p){
					n1 = i;
					break;
				}
			}
			if (i != n){
				break;
			}

			residue[n++] = p;

			p *= 10;
			printf("%d", p / q);
			p %= q;

			if (p == 0){
				break;
			}
		}
		printf("\n");
		if (p != 0){
			for (i = 0; i < n; i++){
				if (i < n1){
					printf(" ");
				}
				else {
					printf("^");
				}
			}
			printf("\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0