akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<fstream>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int n;
char s[1000][100];
void init()
{
    cin>>n;
    for (int i=0; i<n; ++i)
        cin>>s[i];
    for (int i=0; i<n; ++i)
        if (((i>0)&&s[i][0]!=s[i-1][strlen(s[i-1])-1]) || (i<n-1 && s[i][strlen(s[i])-1]!=s[i+1][0]))
        {
            cout<<"No"<<endl;
            return;
        }
    
    for (int i=0; i<n; ++i)
        for (int j=0; j<n; ++j)
            if(!strcmp(s[i],s[j])&&i!=j)
            {
                cout<<"No"<<endl;
                return;
            }
    cout<<"Yes"<<endl;

}

void work()
{

}


int main()
{
    init();
    work();
    return 0;
}



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

namespace AtCoder
{
    static class Program
    {
        static void Main()
        {
            //ここから

            var N = IO.ReadLineToLong();
            var plan = new List<List<long>>();
            for(var i = 0; i < N; i++)
            {
                plan.Add(IO.ReadLineToLongList());
            }

            long lastx = 0;
            long lasty = 0;
            long lastt = 0;

            string ans = "Yes";
            for(var i = 0; i < N; i++)
            {
                var length = Math.Abs(plan[i][1] - lastx) + Math.Abs(plan[i][2] - lasty);
                var time = plan[i][0] - lastt;
                if (length > time) { ans = "No";break; }
                if ((time - length) % 2 == 1) { ans = "No";break; }

                lastx = plan[i][1];
                lasty = plan[i][2];
                lastt = plan[i][0];
            }

            //ここまで

            Console.WriteLine(ans);
            Console.ReadKey();
        }

    }

    static class Func
    {
        static public long mod = 1000000007;
        static public void Swap<T>(ref T a, ref T b) { T temp = a; a = b; b = temp; }
        static public long GCD(long a, long b) { return b != 0 ? GCD(b, a % b) : a; }
        static public long LCM(long a, long b) { return (long)a * b / GCD(a, b); }
        static public long Factorial(long a) { return a == 1 ? a : a * Factorial(a - 1); }


        public static double ToAngle(this double radian)
        {
            return (double)(radian * 180 / Math.PI);
        }

        public static double ToRadian(this double angle)
        {
            return (double)(angle * Math.PI / 180);
        }

        static public long Conbination(long n,long m)
        {
            if (m == 0) return 1;
            if (n == 0) return 0;
            return n * Conbination(n - 1, m - 1) / m;
        }

        static public void Factoring(long num, ref long[] vs)
        {
            if (num == 1)
            {
                vs[1]++;
            }
            for (long i = 2; i < Math.Sqrt(num); i++)
            {
                if (num % i == 0)
                {
                    vs[i]++;
                    Factoring(num / i, ref vs);
                }
            }
            vs[1]++;
        }
    }

    static class IO
    {
        static public string ReadLineToString() { return Console.ReadLine(); }
        static public long ReadLineToLong() { return long.Parse(Console.ReadLine()); }
        static public List<string> ReadLineToStringList() { return Console.ReadLine().Split(' ').ToList(); }
        static public List<long> ReadLineToLongList() { return Console.ReadLine().Split(' ').Select(long.Parse).ToList(); }

        static public List<double> ReadLineToDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }

        static public void WriteStrings(object[] strings) { foreach (var o in strings) { Console.Write(o + " "); } }
    }
}

Measured memory_bytes: 26928
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    int g=min(a,b);
    int h=min(g,c);
    int i=min(d,e);
    if((max(max(max(a,b),c),max(d,e))-min(h,i))>f)
		cout<<":(";
	else
		cout<<"Yay!";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
global count

def recursive_f(h):
    global count
    hmin = min(h)
    count += hmin
    h = h - hmin
    
    zeroidx = list(h).index(0)
    if len(h) == 1:
        return 0
    else :
        if zeroidx > 0 & zeroidx < len(h)-1:
            h1 = h[0:zeroidx]
            h2 = h[zeroidx+1:len(h)]
            if len(h1) > 0:
                recursive_f(h1)
            if len(h2) > 0:
                recursive_f(h2)
            
        elif zeroidx == 0:
            h2 = h[1:]
            if len(h2) > 0:
                recursive_f(h2)
            
        elif zeroidx == len(h)-1:
            h1 = h[0:len(h)-1]
            if len(h1) > 0:
                recursive_f(h1)
            
        


N = int(input())
h = list(map(int,input().split()))

h = np.array(h)
count = 0
a = 0
recursive_f(h)
print(count)

Measured memory_bytes: 12504
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;

int n;
int m;
int x;
int a[101];
int main() {
	for (int i = 0; i < 101; i++) {
		a[i] = -1;
	}
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) {
		a[i] = 0;
	}
	for (int i = 0; i < m; i++) {
		int tmp;
		cin >> tmp;
		a[tmp] = 1;
	}
	int routecost = 1919;
	int tmpcst = 0;
	for (int i = x; i >= 0; i--) {
		tmpcst += a[i];
	}
	routecost = min(routecost, tmpcst);
	tmpcst = 0;
	for (int i = x; i < n; i++) {
		tmpcst += a[i];
	}
	routecost = min(routecost, tmpcst);
	cout << routecost << endl;
	return 0;
}


Measured memory_bytes: 256
def sub_solve(l,c,r):
    a = [0 for i in range(r-l+1)]
    num_r = c-l + 1
    num_l = r-c
    a[c-l] = (num_r//2 + num_r%2) + (num_l//2)
    a[c-l+1] = (num_r//2 ) + (num_l//2 + num_l%2)
    return a

S = input()
N = len(S)

ans = []
p = [0]

i = 0
while i < N:
    l = i
    c = 0
    r = 0
    for j in range(i,N):
        if S[j]=='R' and S[j+1]=='L':
            c = j
        if j+1 >= N or S[j]=='L' and S[j+1]=='R':
            r = j
            break

    ans.extend(sub_solve(l,c,r))

    i = r+1




print(" ".join(map(str,ans)))


Measured memory_bytes: 10988
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Data.List
import Data.Array.ST
import Data.Array (elems)
import Data.Maybe (fromJust)
import Debug.Trace


recover :: String -> String -> Int -> String
recover [] [] _ = ""
recover [a] [] _ = [a]
recover [] [b] _ = [b]
recover (a:as) (b:bs) index
    | (index `mod` 2) == 0 = a:(recover as (b:bs) (index + 1))
    | otherwise = b:(recover (a:as) bs (index + 1))


solve :: String -> String -> String
solve a b = recover a b 0


main :: IO ()
main = do
    a <- getLine
    b <- getLine
    putStrLn $ solve a b



Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            for (; ; )
            {
                var inputLine = Console.In.ReadLine();
                var inputs = inputLine.Split(new char[] { ' ', '\t', '　' });
                if (inputs.Length != 2)
                {
                    return;
                }

                var H = int.Parse(inputs[0]);
                var W = int.Parse(inputs[1]);
                if (H == 0 && W == 0)
                {
                    break;
                }

                for (int ih = 0; ih < H; ++ih)
                {
                    bool onBorderH = false;
                    if (ih == 0 || ih == H - 1)
                    {
                        onBorderH = true;
                    }
                    for (int iw = 0; iw < W; ++iw)
                    {
                        bool onBorderW = false;
                        if (iw == 0 || iw == W - 1)
                        {
                            onBorderW = true;
                        }
                        if (onBorderH || onBorderW)
                        {
                            Console.Write("#");
                        }
                        else
                        {
                            Console.Write(".");
                        }
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 15944
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] p = new int[n];
        for (int i = 0; i < p.length; i++) {
            p[i] = sc.nextInt();
        }
        int a = n / 2 - 1;
        Arrays.sort(p);
        int ans = p[a + 1] - p[a];
        System.out.println(ans);
    }
}

Measured memory_bytes: 60656
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int m, d;
    int ans=0;
    cin >> m >> d;
    rep1(i,m+1){
        rep1(j,d+1){
            int s = (j/10)*(j%10);
            if((s==i)&&((j/10)>=2)&&((j%10)>=2)){
                ans++;
            }
        }
    }
    co(ans);
}

Measured memory_bytes: 256
N, K = map(int, input().split())
R, S, P = map(int, input().split())
POINTS = (R, P, S)
T = [("r", "p", "s").index(c) for c in input()]
WIN = [(t + 1) % 3 for t in T]

ans = 0
for i in range(K):
    p = [0] * 3
    p[WIN[i]] = POINTS[WIN[i]]
    j = i + K
    while j < N:
        n = [-1] * 3
        for px, pp in enumerate(p):
            if pp < 0:
                continue
            for nx in range(3):
                if nx == px:
                    continue
                np = pp
                if nx == WIN[j]:
                    np += POINTS[WIN[j]]
                n[nx] = max(n[nx], np)
        p = n
        j += K
    ans += max(p)
print(ans)

Measured memory_bytes: 10620
/**
*   @author: Kshitiz Srivastava (Pirate_ksh) @ MNNIT Allahabad
*/
#include<bits/stdc++.h>
using namespace std;
 
// General
#define ll long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define mod_ 998244353 
#define endl "\n"
#define debug(x) cout<<x<<endl
#define REP(i,n) for(i=0;i<n;++i)
#define FOR(i,x,n) for(i=x;i<n;++i)
 
// Bounds
#define lb(a, x) a.lower_bound(x)
#define ub(a, x) a.upper_bound(x)
#define all(a) a.begin(),a.end()
 
// Vector
#define vi vector <int>
#define pb(v, x) v.push_back(x)
#define vsi vector <set <int> >
 
// Map
#define mii map <int, int>
 
// Set
#define si set <int>
 
// Pair
#define vpii vector<pair < int, int > >
#define pii pair < int, int >
#define F first
#define S second

ll t, i, j, k, h, w;
char grid[1005][1005];

ll dp[1005][1005];
ll DP(int i, int j) {
    if(i == h-1 && j == w-1) return dp[i][j] = 1;
    if(dp[i][j] != -1) return dp[i][j];
    ll right = 0, down = 0;
    if(j+1 < w && grid[i][j+1] == '.') right = DP(i,j+1) % mod;
    if(i+1 < h && grid[i+1][j] == '.') down = DP(i+1,j) % mod;
    return dp[i][j] = (right + down) % mod;
}

int main(){
    io;
    t=1;
    while(t--) { 
        cin >> h >> w;
        REP(i,h) REP(j,w) cin >> grid[i][j];
        memset(dp, -1, sizeof(dp));
        cout << DP(0,0) << endl;
    }
    return 0;
}


Measured memory_bytes: 9216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

struct Graph {
    static constexpr int INF = 1 << 30;
    struct Edge {
        int i, r, f;
    };
    Graph(int n) : v(n), e(n) {}
    void add_edge(int i, int j, int f) {
        int r0 = e[j].size();
        int r1 = e[i].size();
        e[i].push_back({ j, r0, max(+f, 0) });
        e[j].push_back({ i, r1, max(-f, 0) });
    }
    void bfs(int i0, int i1) {
        fill(v.begin(), v.end(), -1);
        v[i0] = 0;
        queue<int> q;
        q.push(i0);
        while (!q.empty()) {
            int i = q.front(); q.pop();
            for (Edge& o : e[i]) {
                if (v[o.i] >= 0 || o.f == 0) continue;

                v[o.i] = v[i] + 1;
                if (o.i == i1) return;
                q.push(o.i);
            }
        }
    }
    int dfs(int i, int i1, int f0) {
        for (Edge& o : e[i]) {
            if (v[o.i] <= v[i] || o.f == 0) continue;

            int f = min(f0, o.f);
            if (o.i != i1) f = dfs(o.i, i1, f);
            if (f == 0) continue;

            o.f -= f;
            e[o.i][o.r].f += f;
            return f;
        }
        return 0;
    }
    int64_t max_flow(int i0, int i1) { // i0 != i1
        for (int64_t f = 0;;) {
            bfs(i0, i1);
            if (v[i1] < 0) return f;
            while (1) {
                int t = dfs(i0, i1, INF);
                if (t == 0) break;
                f += t;
            }
        }
    }
    vector<int> v;
    vector<vector<Edge>> e;
};

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

    Graph g(n + 2);
    int S = 0, T = n + 1;
    int64_t p = 0;

    for (int i = 1; i <= n; i++) {
        int a;
        cin >> a;

        if (a < 0) {
            g.add_edge(S, i, -a);
        } else if (a > 0) {
            g.add_edge(i, T, a);
            p += a;
        }
        for (int j = i * 2; j <= n; j += i) {
            g.add_edge(i, j, Graph::INF);
        }
    }

    cout << p - g.max_flow(S, T) << endl;

    return 0;
}

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

int gi() {
	int x=0,o=1;char ch=getchar();
	while(!isdigit(ch)&&ch!='-') ch=getchar();
	if(ch=='-') o=-1,ch=getchar();
	while(isdigit(ch)) x=x*10+ch-'0',ch=getchar();
	return x*o;
}

struct mat {
	
	ll v[26][26];

	mat() {
		memset(v,0x3f,sizeof(v));
	}

	mat operator*(const mat &A) const {
		mat ret;
		for(int i=0;i<26;i++)
			for(int j=0;j<26;j++)
				for(int k=0;k<26;k++) ret.v[i][j]=min(ret.v[i][j],v[i][k]+A.v[k][j]);
		return ret;
	}
	
} S,T;

char s[N];
int n,k,f[N][26];

int main() {
	scanf("%s",s+1),n=strlen(s+1);cin>>k;
	for(int i=0;i<26;i++)
		for(int j=0;j<26;j++) {
			memset(f,0x3f,sizeof(f));
			f[0][i]=0;
			for(int k=1;k<=n;k++)
				for(int l=0;l<26;l++)
					for(int m=0;m<26;m++)
						if(l!=m) f[k][l]=min(f[k][l],f[k-1][m]+(s[k]-'a'!=l));
			T.v[i][j]=f[n][j];
		}
	S=T;--k;
	while(k) {
		if(k&1) S=S*T;
		T=T*T,k>>=1;
	}
	ll ans=1e18;
	for(int i=0;i<26;i++)
		for(int j=0;j<26;j++) ans=min(ans,S.v[i][j]);
	cout<<ans;
	return 0;
}


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

using namespace std;

int main(){
	string S;
	cin >> S;
	int n = S.size();
	string ans;

	if(S[n-1] == 's') {
		string s1 = "es";
		ans = S + s1;
	}
	else {
		string s1 = "s";
		ans = S + s1;		
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
  ll n,m;
  cin>>n>>m;
  if(m<=2*n)
  { 
    cout<<m/2<<endl;
  }
  else
  {
    int x=m-(2*n);
    int y=x/4;
    cout<<(n+((m-2*n)/4))<<endl;
    
    
  }

}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
even = []

ans = 'APPROVED'

for x in a:
    if x %2 == 0:
        even.append(x)

if all(x % 3 == 0 or x % 5 == 0 for x in even):
    print('APPROVED')
else:
    print('DENIED')


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

#ifdef LOCAL
#include "dump.hpp"
#else
#define dump(...)
#define dumpv(...)
#endif

#define rep(i, n) for (int i = 0; i < (n); i++)
#define mins(x, y) (x = min(x, y))
#define maxs(x, y) (x = max(x, y))
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
const int MOD = 1e9 + 7;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

template<typename T>
struct Bit {
  int n; // 2のべき乗でなくてもOK
  vector<T> node;
  Bit(int n) : n(n), node(n + 1, 0) {}
  void add(int i, T w) { // node[i] += w
    for (int x = ++i; x <= n; x += x & -x) node[x] += w;
  }
  T sum(int i) { // return sum [0, i)
    T ans = 0;
    for (int x = i; x > 0; x -= x & -x) ans += node[x];
    return ans;
  }
  T sum(int i, int j) { // return sum [i, j)
    return sum(j) - sum(i);
  }
  vector<T> debug() { // for debug
    vector<T> a;
    rep(i, n) a.push_back(sum(i, i + 1));
    return a;
  }
};

struct T {
  int x, y, z;
  T(int x = 0, int y = 0, int z = 0) : x(x), y(y), z(z) {}
};
bool operator<(const T& a, const T& b) { // compare function for sort
  return a.y != b.y ? a.y < b.y : a.z < b.z;
}
inline ostream& operator<<(ostream& o, const T& a) { // stream function for debug
  return o << a.x << "," << a.y << "," << a.z;
}

void solve() {
  int n, m, q;
  cin >> n >> m >> q;
  Bit<int> bit(n);
  vector<T> a;
  rep(i, m) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    a.emplace_back(l, r, -1);
  }
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    a.emplace_back(l, r, i);
  }
  sort(a.begin(), a.end());
  vi ans(q);
  rep(i, a.size()) {
    if (a[i].z == -1) {
      dump("a", a[i].x);
      bit.add(a[i].x, 1);
    } else {
      dump("q", a[i]);
      ans[a[i].z] = bit.sum(a[i].x, a[i].y + 1);
    }
  }
  rep(i, q) cout << ans[i] << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  // freopen("temp.1", "r", stdin);
  solve();
  return 0;
}

Measured memory_bytes: 8304
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int N,mi=99999999999999;
    cin >> N;
    vector<long long int> yakusu;
    for(long long int i=1;i*i<=N;i++)
        if(N % i == 0){
            mi = min(mi,(N/i+i) - 2);
        }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.buffer.readline().rstrip()
rs = lambda: sys.stdin.buffer.readline().split()
ri = lambda: int(sys.stdin.buffer.readline())
rm = lambda: map(int, sys.stdin.buffer.readline().split())
rl = lambda: list(map(int, sys.stdin.buffer.readline().split()))

n = ri()
a = rl()
cnt = 0
ans = 0
for i in range(n-1):
    if a[i] >= a[i+1]:
        cnt += 1
        ans = max(cnt, ans)
    else:
        cnt = 0
print(ans)





Measured memory_bytes: 21544
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    set<ll> a, b;
    for (ll i = 0; i < n; i++) {
        ll tmpa; cin >> tmpa;
        if (a.find(tmpa) != a.end()) {
            cout << 0 << '\n';
            return 0;
        }
        a.insert(tmpa);
    }

    for (ll i = 0; i < m; i++) {
        ll tmpb; cin >> tmpb;
        if (b.find(tmpb) != b.end()) {
            cout << 0 << '\n';
            return 0;
        }
        b.insert(tmpb);
    }

    ll ac = 0, bc = 0;
    ll ans = 1;
    for (ll i = n * m; i >= 1; i--) {
        if (a.find(i) != a.end() && b.find(i) != b.end()) ac++, bc++;
        else if (a.find(i) == a.end() && b.find(i) != b.end()) (ans *= bc) %= MOD, ac++;
        else if (a.find(i) != a.end() && b.find(i) == b.end()) (ans *= ac) %= MOD, bc++;
        else (ans *= ac * bc - (n * m - i)) %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


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

int main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n),v(n);
    for(auto& P : p)
        cin >> P;
    for(auto& Q : q)
        cin >> Q;
    for(int i = 0; i < n; i++)
        v[i] = i + 1;
    int cnt=1;
    int a=0,b=0;
    do{
        if(v==p) a=cnt;
        if(v==q) b=cnt;
        cnt++;
    }while(next_permutation(v.begin(),v.end()));
    cout<<abs(a-b)<<endl;

    return 0;
}



Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<double> v(N);
    for(int i=0;i<N;i++) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = (v[0]+v[1])/2;
    for(int i=2;i<N;i++) ans = (ans + v[i])/2;
    //setprecisionと併用して小数部n桁にできる
    //cout << fixed;
    cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
//
// Created by PIIMUU on 8/29/2020.
//
#include <bits/stdc++.h>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    int answer = 2e9;
    for (int i = 0; i < s.size() - t.size() + 1; i++) {
        int cnt = 0;
        for (int j = 0; j < t.size(); j++) {
            if (t[j] != s[j + i]) {
                cnt++;
            }
        }
        answer = min(answer, cnt);
    }
    cout << answer;
}



Measured memory_bytes: 3620
N,x=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
y=x
ans=0
for i in range(N-1):
    if a[i]<=y:
        ans+=1
        y-=a[i]
    else:
        break
if a[N-1]==y:
    ans+=1
print(ans)

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

int main(){
  double a,b,x,men;
  cin>>a>>b>>x;
  if(x>=a*a*b/2.0){
    men=a*b-(x/a);
    cout<<std::setprecision(12)<<atan(2.0*men/(a*a))*180.0/3.141592653589793;
  }else{
    men=x/a;
    cout<<std::setprecision(12)<<atan(b*b/(2.0*men))*180.0/3.141592653589793;
  }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n, ans=0, a, b;
	string s = "Yes";
	vector<pi> v;
	cin >> n;
	REP(i, 0, n){
		cin >> a >> b;
		v.PB(make_pair(a, b));
	}
	sort(v.begin(), v.end(), sort_by);
	for(auto it = v. begin(); it != v.end(); it++){
		ans += it->F;
		if(ans > it->S){
			s = "No";
			break;
		}
	}
	cout << s;
		

}


Measured memory_bytes: 2420
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	public void run() {
		Scanner sc = new Scanner(System.in);
		long MOD = 1000000007;
		long n=sc.nextLong();
		n++;
		long k=sc.nextLong();
		long ans = 0;
		for(long i=k; i<=n; i++) {
			long max = n*(n+1)/2 - (n-i)*(n-i+1)/2;
			long min = i*(i+1)/2;
			ans = (ans + (max - min + 1)) % MOD;
		}
		System.out.println(ans);
		sc.close();
	}

}




Measured memory_bytes: 35836
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		if(a==1)
			cout<<6000*b<<endl;
		if(a==2)
			cout<<4000*b<<endl;
		if(a==3)
			cout<<3000*b<<endl;
		if(a==4)
			cout<<2000*b<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
import itertools
N,M = map(int,input().split())
ks = []
for _ in range(M):
    ks.append(input().split())

pList = list(input().split())
result = 0
was = []
cases = list(itertools.product(['1','0'], repeat=N))
for case in cases:
    light = 0
    for p,x in zip(pList,ks):
        k = x[0]
        s = x[1:]
        oncount = 0
        for c in s:
            if case[int(c)-1] == '1':
                oncount += 1
        if oncount%2 == int(p):
            light += 1
    if light == M:
        result += 1
print(result)

Measured memory_bytes: 3188
import itertools

a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

x = float('inf')
for vals in itertools.permutations((a, b, c, d, e)):
    y = 0
    for val in vals[:-1]:
        y += val
        while y % 10 != 0:
            y += 1
    y += vals[-1]
    x = min(x, y)

print(x)


Measured memory_bytes: 39024
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <iomanip>

using namespace std;

#define pi 3.141592653589
#define repeat(i,n) for(int i=0;i<n;i++)

string word;	//見つけたい文字列
string str;		//文章中の単語

int main()
{
	int cnt=0;
	cin >> word;
	while (1)
	{
		cin >> str;
		if (str == "END_OF_TEXT") break;
		transform(str.begin(), str.end(), str.begin(), ::tolower);
		if (str == word) cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 1192
macro_rules! get_tuple {
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };

    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get_tuple!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (x, y) = get_tuple!(isize, isize);

    if has_solution(x, y) {
        println!("Yes")
    } else {
        println!("No")
    }
}

fn has_solution(x: isize, y: isize) -> bool {
    if y % 2 != 0 {
        return false
    }

    if y / 2 - x < 0 {
        return false
    }

    if 2 * x - (y / 2) < 0 {
        return false
    }

    true
}


Measured memory_bytes: 2156
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (d, t, s) = (v[0], v[1], v[2]);
    if d <= s * t {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 2164
using System.Collections.Generic;
using static System.Console;

class Program {
	static void Main() {
		var dic = new HashSet<int>();
		var N = NextInt();
		for (var i = 0; i < N; i++) {
			dic.Add(NextInt());
		}
		WriteLine(dic.Count);
	}

	static int NextInt() {
		return int.Parse(ReadLine());
	}
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long
#define vi vector<int>
#define mod 10000000
using namespace std;

ll dp[100001][4];

int getans(int*a,int*b,int*c,int n,int g)
{
if(n==0)	
	return 0;
	if(dp[n][g]!=0)
	return dp[n][g];
if(g==0)
{
	int o1=a[0]+getans(a+1,b+1,c+1,n-1,1);
	int o2=b[0]+getans(a+1,b+1,c+1,n-1,2);
int o3=c[0]+getans(a+1,b+1,c+1,n-1,3);
int ans=max(o1,max(o2,o3));
dp[n][g]=ans;
return ans;
}
if(g==1)
	{
		int o2=b[0]+getans(a+1,b+1,c+1,n-1,2);
int o3=c[0]+getans(a+1,b+1,c+1,n-1,3);
dp[n][g]=max(o2,o3);
	}
if(g==2)
{
	int o1=a[0]+getans(a+1,b+1,c+1,n-1,1);
	
int o3=c[0]+getans(a+1,b+1,c+1,n-1,3);
dp[n][g]=max(o1,o3);
}
if(g==3)
{
	int o1=a[0]+getans(a+1,b+1,c+1,n-1,1);
	int o2=b[0]+getans(a+1,b+1,c+1,n-1,2);
dp[n][g]=max(o1,o2);
	}	
	return dp[n][g];
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(NULL);
int n,a[100000],b[100000],c[100000];
cin>>n;
for(int i=0;i<n;i++)
{
	cin>>a[i]>>b[i]>>c[i];
}
cout<<getans(a,b,c,n,0)<<endl;
return 0;
}



Measured memory_bytes: 13952
s = list(input())
n = len(s)
ans = 0

for i in range(1 << (n - 1)):
    formula = s[0]
    for j in range(n - 1):
        if i & (1 << j):
            formula += "+"
        formula += s[j + 1]
    ans += eval(formula)

print(ans)


Measured memory_bytes: 3064
import sys
read = sys.stdin.buffer.read
mod=10**9+7
n, *clst = map(int, read().split())
if n == 1:
  print(clst[0]*2%mod)
  quit()
clst.sort(reverse=True)
res=sum(i*item for i, item in enumerate(clst,2))
print((4**(n-1)*res)%mod)

Measured memory_bytes: 21948
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long ans = 700;
		for(char c : s.toCharArray()) {
			if(c=='o') {
				ans+=100;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <cmath>
#include <vector>
using namespace std;
#define pi M_PI
#define ll long long

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

    if(r < 1200){
        cout << "ABC" << endl;
    }
    else if(r < 2800){
        cout << "ARC" << endl;
    }
    else{
        cout << "AGC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define MODB 998244353
#define INF 9223372036854775807

signed main()
{
  int x=0,y=0,z=0,w=0,n=0,m=0;
  std::cin >> x;
  std::vector<int> v(x);
  rep(i,x){
    std::cin >> v[i];
  }
  sort(all(v));
    rep(i,v.size()-1){
    if(v[i]==v[i+1]){
      eraser(v,i+1);
      i--;
    }
  }
  std::cout << v.size() << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  cout << n*n*n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  int f = 0;
  for (int i=1; i<=9; i++) {
    if (N % i != 0) continue;
    if (N / i > 9) continue;
    f = 1;
    break;
  }
  if (f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
N, P  = list(map(int, input().split(" ")))

def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i:
            i += 1
        else:
            n //= i
            factors.append(i)
    if n > 1:
        factors.append(n)
    return factors

factors = prime_factors(P)

factor_dict = {}

first = True
for factor in factors:
    if first or before_factor != factor:
        factor_dict[factor] = 1
        first = False
    else:
        factor_dict[factor] += 1
    before_factor = factor

out = 1
for factor, num in factor_dict.items():
    if num >= N:
        out *= (factor ** (num // N))
print(out)

Measured memory_bytes: 3064
S = input()

ans = 0
for i in range(2**(len(S)-1)):
    tmp = S
    for j in range(len(S)-1):
        if((i >> j) & 1):
            tmp = tmp[:(len(S)-1-j)] + "+" + tmp[(len(S)-1-j):]
    ans += sum([int(k) for k in tmp.split("+")])       
print(ans)

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;

	double sum=0.0;
	for(int i=0; i<n; i++){
		double tmp; cin>>tmp;

		sum += 1/tmp;
	}

	printf("%0.10f",1/sum);
}




Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
 
using namespace std;
 
typedef long long ll;
 
#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define per(i,a,b) for(ll i=b-1LL;i>=(a);--i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define endl "\n"
#define print(x) cout<<#x<<" = "<<x<<endl;
 
#define MOD 1000000007

int main() {
	ll n;
	cin>>n;
	n--;
	vector<ll> v;
	rep(i,0,n){
		ll a;
		cin>>a;
		v.pb(a);
	}
	ll ans = v[0]+v[v.sz-1];
	rep(i,1,v.sz){
		ans += min(v[i-1],v[i]);
	}
	cout << ans << endl;
	return 0;
}

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

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var v = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        if (v.Distinct().Count() == 1)
        {
            Console.WriteLine(N/2);
            return;
        }
        var evenDic = new Dictionary<int,int>();
        var oddDic = new Dictionary<int,int>();
        for (int i=0;i<N;++i)
        {
            if (i % 2 == 0)
            {
                if (evenDic.ContainsKey(v[i])) evenDic[v[i]]++;
                else evenDic.Add(v[i],1);
            }
            else
            {
                if (oddDic.ContainsKey(v[i])) oddDic[v[i]]++;
                else oddDic.Add(v[i], 1);
            }
        }
        evenDic=evenDic.OrderByDescending(x => x.Value).ToDictionary(x=>x.Key,x=>x.Value);
        oddDic = oddDic.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
        var cost = 0L;
        var evenFirst = evenDic.First();
        var oddFirst = oddDic.First();
        var half = N / 2;
        if (evenFirst.Key == oddFirst.Key)
        {
            var evenSecond = 1<evenDic.Count()?evenDic.Skip(1).First().Value:int.MinValue;
            var oddSecond = 1 < oddDic.Count() ? oddDic.Skip(1).First().Value : int.MinValue;
            //even→evenFirst,odd→oddSecond
            long plan1 = (half - evenFirst.Value) + (half - oddSecond);
            //even→evenSecond,odd→oddFirst
            long plan2 = (half - evenSecond) + (half - oddFirst.Value);
            cost = Math.Min(plan1,plan2);
        }
        else
        {
            cost = (half - evenFirst.Value) + (half - oddFirst.Value);
        }
        Console.WriteLine(cost);
    }
}

Measured memory_bytes: 27616
#include<stdio.h>
int main()
{
    int r,g,b, res;
    scanf("%d %d %d",&r ,&g, &b);
    res = 100*r + 10*g +b;
    if( res%4==0 )
    {
         printf("YES");
    }
    else
    {
         printf("NO");
    }
    return 0;
}

Measured memory_bytes: 1664
#include<iostream>
using namespace std;
int main(){
int i;
int n,p,ans=0,max=0;

cin>>n;
for(i=0;i<n;i++){
cin>>p;
ans+=p;
if(p>max)max=p;
}
ans-=max/2;

cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    a = list(map(int, input().split()))
    left = [0] * N
    tmp = 0
    for i in range(N):
        tmp += a[i]
        left[i] = tmp
    dic = {}
    ans = 0
    for i in range(N):
        if left[i] == 0:
            ans += 1
        if left[i] in dic:
            dic[left[i]] += 1
        else:
            dic[left[i]] = 1
    # print(dic)
    for key in dic:
        tmp = dic[key]
        if tmp > 1:
            tmp *= tmp-1
            ans += tmp//2
    
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 41460
from collections import defaultdict
from heapq import heappop, heappush
from math import ceil

class Graph(object):

    def __init__(self):
        self.graph = defaultdict(list)

    def __len__(self):
        return len(self.graph)

    def add_edge(self, From, To, cost=1):
        self.graph[From].append((To,cost))

    def get_nodes(self):
        return self.graph.keys()

class Dijkstra(object):

    def __init__(self, graph, start):
        self.g = graph.graph
        self.dist = defaultdict(lambda:float('inf'))
        self.dist[start] = 0
        self.prev = defaultdict(lambda: None)
        self.Q = []
        heappush(self.Q,(self.dist[start], start))

        while  self.Q:
            dist_u, u = heappop(self.Q)
            if self.dist[u] < dist_u:
                continue
            for v, cost in self.g[u]:
                alt = dist_u + cost
                if self.dist[v] > alt:
                    self.dist[v] = alt
                    self.prev[v] = u
                    heappush(self.Q,(alt, v))

    def shortest_distance(self, goal):
        return self.dist[goal]

    def shortest_path(self, goal):
        path = []
        node = goal
        while node is not None:
            path.append(node)
            node = self.prev[node]

        return path[::-1]

N = int(input())
g = Graph()

for _ in range(N-1):
    a,b = map(int,input().split())
    g.add_edge(a,b)
    g.add_edge(b,a)

dij = Dijkstra(g,1)
path = dij.shortest_path(N)
c1 = path[ceil(len(path)/2)-1]
c2 = path[ceil(len(path)/2)]

g.graph[c1] = [(to,cost) for to,cost in g.graph[c1] if to != c2]
g.graph[c2] = [(to,cost) for to,cost in g.graph[c2] if to != c1]

dij = Dijkstra(g,1)
f = 0
for i in range(1,N):
    if dij.shortest_distance(i) != float('inf'):
        f += 1
if f > N-f:
    print('Fennec')
else:
    print('Snuke')

Measured memory_bytes: 66272
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
    
    int count = 0;
    int H,W;
    cin >> H;
    cin >> W;
    
    
    for ( int i = 0; i < H; i++ ) {
        string s;
        cin >> s;
        
        for ( int j = 0; j < s.length(); j++ ) {
            if ( s[j] == '#' ) { count++; }
        }
        
    }
    
    cout << (count == (H-1 + W-1 + 1) ? "Possible" : "Impossible" ) << endl;
    
    return 0;
}

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

const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 5;

vector<int> e[MAX_N];
long long dp[MAX_N][2];

void dfs(int a, int parent = -1)
{
    if (dp[a][0] > 0 && dp[a][1] > 0)
        return;

    int dp0 = 1, dp1 = 1;
    for (int b : e[a]) {
        if (b != parent) {
            dfs(b, a);
            dp1 = (dp1 * dp[b][0]) % MOD;
            dp0 = (dp0 * ((dp[b][0] + dp[b][1]) % MOD)) % MOD;
        }
    }
    dp[a][0] = dp0;
    dp[a][1] = dp1;
}

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i) {
        int a, b;
        scanf("%d%d", &a, &b);
        e[a].push_back(b);
        e[b].push_back(a);
    }

    for (int i = 0; i < n - 1; ++i)
        dp[i][0] = dp[i][1] = -1;

    dfs(1);
    printf("%lld\n", (dp[1][0] + dp[1][1]) % MOD);
    return 0;
}


Measured memory_bytes: 14208
n = int(input())
a = [int(i)-1 for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]


satis = 0

for i in range(n):
  if i == 0:
    satis += b[a[i]]
  else:
    if a[i-1] + 1 == a[i]:
      satis += c[a[i-1]]
    satis += b[a[i]]
print(satis)

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> l(n);
    REP(i, n){
        cin >> l.at(i);
    }
    sort(l.begin(), l.end());
    ll ans = 0;
    for(ll i = 0; i < l.size() - 2; ++i){
        const ll a = l.at(i);
        for(ll j = i + 1; j < l.size() - 1; ++j){
            const ll b = l.at(j);
            auto it_ub = lower_bound(l.begin() + j + 1, l.end(), a + b);
            ans += max(0LL, (it_ub - l.begin()) - j - 1LL);
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<int, P> PIP;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;
typedef set<int> S;

#define INF INT_MAX/3
#define MAX_N 1000000001

int main(){
  cin.sync_with_stdio(false);
  int n;
  while(cin >> n, n) {
    vector<int> v[30];
    S map[n];
    rep(i, n) {
      map[i].insert(i);
      int m;
      cin >> m;
      rep(j, m) {
        int s;
        cin >> s;
        v[s - 1].pb(i);
      }
    }

    int ans = -1;
    rep(i, 30) {
      S s;
      rep(j, v[i].size()) {
        each(itr, map[v[i][j]]) s.insert(itr);
      }

      rep(j, v[i].size()) map[v[i][j]] = s;

      if (s.size() == n) {
        ans = i + 1;
        break;
      }
    }
    cout << ans << endl;
  }

  return 0;
}

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

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define pp pop_back
#define f first
#define s second
#define sz(a) (int)((a).size())
#define NoType ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair

typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
//find_by_order(x) -> returns an iterator to the element at a given position
//order_of_key(x) -> returns the position of a given element

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pi;

const int mod = (int)1e9 + 7;
const int MAXN = 1e5+12;
//indexed_set s;

int n,m;
vector<int>g[2*MAXN];
int used[2*MAXN];
vector<int>comp;

void dfs (int v) {
    used[v] = 1;
    comp.pb(v);
    for (int i = 0; i < g[v].size(); i++) {
        int to = g[v][i];
        if (!used[to]) {
            dfs(to);
        }
    }
}

int main() {

    cin >> n >> m;

    for (int i = 1; i <= m; i++) {
        int u=0,v=0;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    int mx = -1;
    for (int i = 1; i <= n; i++) {
        if (!used[i]) {
            comp.clear();
            dfs(i);
            mx = max(mx, sz(comp));
        }
    }

    cout << mx;

return 0;
}


Measured memory_bytes: 25244
# -*- coding:utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
mod = 1000000007
inf = float("INF")
def I(): return int(input().rstrip())
def IR(n): return [I() for _ in range(n)]
def LI(): return list(map(int, input().rstrip().split()))
def LIR(n): return [LI() for _ in range(n)]
def LI_(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def LIR_(n): return [LI_() for _ in range(n)]
def F(): return float(input().rstrip())
def FR(n): return [F() for _ in range(n)]
def LF(): return list(map(float, input().rstrip().split()))
def LFR(n): return [LI() for _ in range(n)]
def S(): return input().rstrip()
def SR(n): return [S() for _ in range(n)]
def LS(): return list(sys.stdin.readline().rstrip().split())
def LSR(n): return [LS() for _ in range(n)]
# ↑template↑
# ↓solution↑
n, a, b = LI()
def digitSum(i):
    s = str(i)
    ary = list(map(int, s))
    return sum(ary)
res = 0
for n in range(n+1):
    if a <= digitSum(n) <= b:
        res += n
print(res)


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

using namespace std;
int main(){
    int a;
    cin>>a;
    vector<int> b(a,0);
    for(int i=0;i<a;++i)
        cin>>b[i];
    int sum=0;
    for(int i=0;i<(a-1);++i){
        for(int j=i+1;j<a;++j){
            sum=sum+b[i]*b[j];
        }
    }
    cout<<sum;
    return 0;
}


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

using namespace std;

typedef long long ll ;
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int, int> p; 
//q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数


int f(char ch){

    int turn;

    if(ch=='a') turn=1;
    else if(ch=='b') turn=2;
    else turn=3; 

    return turn;
}


int main (){

    string sa;
    string sb;
    string sc;
    cin >> sa >> sb >> sc;

    int la = sa.size();
    int lb = sb.size();
    int lc = sc.size();

    // cout << int (sa[0]) << endl;

    //sa.erase(sa.begin());
    int turn = 1;

   // while(sa.size()!=0 && sb.size()!=0 && sc.size()!=0 ){
       int xxx = 1;
        while(1){
        switch(turn){

            case 1:  {char a = sa[0];
                     turn = f(a);
                     if(sa.size()==0) {cout << 'A'; goto X;}
                     sa.erase(sa.begin());
                     break;}
            case 2:  {char b = sb[0];
                     turn = f(b);
                     if(sb.size()==0) {cout << 'B'; goto X;}
                     sb.erase(sb.begin());
                     break;}
            case 3:  {char c = sc[0];
                     turn = f(c);
                     if(sc.size()==0) {cout << 'C'; goto X;}
                     sc.erase(sc.begin());
                     break;}
            }
        }
        X: ;
    }
// if(sa.size()==0) cout << 'a';
// if(sb.size()==0) cout << 'b';
// if(sc.size()==0) cout << 'c';

Measured memory_bytes: 256
ans_list = []

while True:
    n = int(input())
    if n == 0:
        break
    C = input().split()
    al = [0]*26
    ans = "TIE"
    for i, c in enumerate(C):
        al[ord(c)-65] += 1
        tmp = sorted(al,reverse=True)
        one = tmp[0]
        two = tmp[1]
        remain = n - i - 1
        if one > two + remain:
            win = chr(al.index(one) + 65)
            ans = "{} {}".format(win, i+1)
            break
    ans_list.append(ans)

for ans in ans_list:
    print(ans)


Measured memory_bytes: 5864