akhauriyash/Code-Regression huggingface dataset:
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace ConsoleApp29
{
    public class State
    {
        public int[] Skill { get; set; }
        public int Money { get; set; }

        public State(int m)
        {
            Skill = new int[m];
        }
        public void Clear()
        {
            for(int i = 0; i < Skill.Length; i++)
            {
                Skill[i] = 0;
            }
            Money = 0;
        }
    }
    
    class Program
    {
        static void Main(string[] args)
        {
            var temp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n_book = temp[0];
            int n_algorithm = temp[1];
            int skil_border = temp[2];

            var book = new int[n_book][];
            for(int i = 0; i < n_book; i++)
            {
                book[i] = ReadLine().Split(' ').Select(int.Parse).ToArray();
            }

            var state = new State(book[0].Length - 1);
            var index = new List<int>();
            var select = new List<int>();
            for(int i = 0; i < n_book; i++)
            {
                index.Add(i);
            }
            int min = int.MaxValue;
            foreach(int x in MinMoney(state, index, book, skil_border, select))
            {
                min = min > x ? x : min;
            }

            WriteLine(min != int.MaxValue ? min : -1);
            
        }

        static IEnumerable<int> MinMoney(State state, List<int> index, int[][] books, int skillborder, List<int> select)
        {
            foreach(int i in index)
            {
                var unusedindex = new List<int>(index);
                unusedindex.RemoveAll(e => e <= i);
                var newselect = new List<int>(select);
                newselect.Add(i);
                state.Clear();
                foreach(int x in newselect)
                {
                    state.Money += books[x][0];
                    for(int j = 0; j < books[x].Length - 1; j++)
                    {
                        state.Skill[j] += books[x][j + 1];
                    }
                }
                if (SkillCheck(state, skillborder))
                {
                    yield return state.Money;
                }
                else
                {
                    foreach(var x in MinMoney(state, unusedindex, books, skillborder, newselect))
                    {
                        yield return x;
                    }
                }
            }
            
            
        }

        static bool SkillCheck(State state, int skillborder)
        {
            foreach(int skill in state.Skill)
            {
                if(skill < skillborder)
                {
                    return false;
                }
            }
            return true;
        }
    }
}


Measured memory_bytes: 30128
/**
 *    Creator :  bizarre
 *    Date : 5/2020
 *    Problem Number : 536
**/
#include <bits/stdc++.h>
using namespace std;
#define bizarre  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define ll long long
#define ld long double
/*
vector<int> prime_Numbers;
bool primes[1000005];
void prime(int n)
{
    primes[1]=primes[0]=0;
    for(int i=2; i<=n; i++)
        primes[i]=true;
    for(int i=2; i<=n; i++)
    {
        if(primes[i]==true)
        {
            prime_Numbers.push_back(i);
            for(int j=i+i; j<=n; j+=i)
                primes[j]=false;
        }
    }
}
void move1step(long long& a, long long& b, long long q)
{
    long long c= a-q*b;
    a=b;
    b=c;
}
long long egcd(long long r0,long long r1,long long& x0,long long& y0)
{
    long long x1=0,y1=1;
    x0=1;
    y0=0;
    while(r1)
    {
        long long q=r0/r1;
        move1step(r0,r1,q);
        move1step(x0,x1,q);
        move1step(y0,y1,q);
    }
    return r0;
}
bool  solve (long long a, long long b, long long c,long long&x, long long& y)
{
    long long g=egcd(a,b,x,y);
    int m=c/g;
    x*=m;
    y*=m;
    return c%g==0;
}
int gcd(int a, int b)
{
    if(b==0)
        return a;
    return gcd(b,a%b);
}
void PrimeFactorization(int n)
{
    for(int i=2; i*i<=n; i++)
    {
        int c=0;
        if(n%i==0)
        {
            while(n%i==0)
            {
                n/=i;
            }

        }
    }

}
long long ncrtane(long long n, long long r)
{
    long long ans=1,cntr=1;
    for(int i=n; i>n-r; i--)
    {
        ans*=i;
        ans/=cntr;
        cntr++;
    }
    return ans;
}
const int N = 1e6 + 5, inf = 2e9, mod = 1e9 + 7;
long long fp(long long base, long long exp)
{
    if (exp == 0)
        return 1;
    long long ans = fp(base, exp / 2);
    ans = (ans * ans) % mod;
    if (exp % 2 != 0)
        ans = (ans * (base % mod)) % mod;
    return ans;
}
long long fact[N], inv[N];
void pre(long long n)
{
    fact[0] = 1;
    inv[0] = 1;
    for (long long i = 1; i <= n; i++)
    {
        fact[i] = (i * fact[i - 1]) % mod;
        inv[i] = fp(fact[i], mod - 2);
    }
}
int ncr(long long n, long long r)
{
    return (((fact[n] * inv[n - r]) % mod) * inv[r]) % mod;
}

int npr(long long n, long long r)
{
    return (fact[n] * inv[n - r]) % mod;
}
*/
int main()
{

    bizarre
     string s,t;
     cin >> s >> t;
     bool flag=true;
     int p =0;
     for(int i=0;i<t.size()-1;i++)
     {
         if(s[p]!=t[i])flag=false;
         p++;
     }
     if(flag)cout << "Yes";
     else cout << "No";
    return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<cstring>
using namespace std;
char Map[105][105];
bool vis[105][105];
int dir[4][2] = {{-1,0},{1,0},{0,-1},{0,1}};
int cnt;
int ans;
int W,H;
void dfs(int x,int y,char token){
    vis[x][y] = true;
    for(int i = 0;i < 4;i++){
        int xx = x + dir[i][0];
        int yy = y + dir[i][1];
        if(xx >= 0 && xx < H && yy >= 0 && yy < W && Map[xx][yy] == token && !vis[xx][yy]){
            vis[xx][yy] = true;
            dfs(xx,yy,token);
        }
    }
}
int main(){

    while(cin>>H>>W){
        if(W == 0 && H == 0)
        break;
        cnt = 0;
        int sx,sy;
        memset(vis,false,sizeof(vis));
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                cin>>Map[i][j];
            }
        }
        for(int i = 0;i < H;i++){
            for(int j = 0;j < W;j++){
                if(!vis[i][j]){
                    cnt++;
                    dfs(i,j,Map[i][j]);
                }


            }
        }
        cout<<cnt<<endl;

    }
    return 0;
}

Measured memory_bytes: 3492
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <functional>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <iostream>
#include <ctime>
#include <complex>

#define enp 	printf("**Entry Point**\n")
#define A		first
#define B		second
#define MP		make_pair

using namespace std;

typedef long long ll;

const int INF = 0x6fffffff;
const int MINF = 0x80000000;
const ll mod = 100003;
const int cons = 100001;
const double pi = 3.141592653589793;

int dp[1002][128];

int fn(int n, int d)
{
	int & ret = dp[n][d];
	if (ret != -1)return ret;

	if (n == 1)return ret = 0;

	for (int i = 0; i <= 127; i++)
	{
		ret = max(ret, fn(n - 1, i^d) + (i^d) + i - d);
		ret = max(ret, fn(n - 1, i) + (i^d) + i - d);
	}

	return ret;
}

int main()
{
	memset(dp, -1, sizeof(dp));

	int t;
	scanf("%d", &t);

	while (t--)
	{
		int n, d;
		scanf("%d%d", &n, &d);
		printf("%d\n", fn(n, d) + d);
	}

	return 0;
}

Measured memory_bytes: 768
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	b := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
		b[i] = a[i]
	}
	sort.Ints(b)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	for i := 0; i < N; i++ {
		if a[i] == b[len(b)-1] {
			fmt.Fprintln(w, b[len(b)-2])
		} else {
			fmt.Fprintln(w, b[len(b)-1])
		}
	}
}


Measured memory_bytes: 7680
#include <iostream>
#include <unordered_set>
#include <queue>
#include <utility>
#include <numeric>
 
using namespace std;
 
int parent[100001];
unordered_set<int> blue[100001], red[100001];
queue<pair<int, int>> q;
 
int getRoot(int x) {
	return x == parent[x] ? x : parent[x] = getRoot(parent[x]);
}
 
void print(const unordered_set<int> &m) {
	for (auto &&x: m) cerr << x << ' ';
	cerr << endl;
}
 
int main() {
	int n;
 
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		blue[a].insert(b);
		blue[b].insert(a);
	}
 
	for (int i = 1; i < n; ++i) {
		int a, b;
		cin >> a >> b;
		red[a].insert(b);
		red[b].insert(a);
		if (blue[a].find(b) != blue[a].end())
			q.emplace(a, b);
	}
 
	iota(parent + 1, parent + n + 1, 1);
 
	int cnt = 0;
	while (!q.empty()) {
//		++cnt;
 
		auto p = q.front();
		q.pop();
 
		int x = getRoot(p.first), y = getRoot(p.second);
                if (x == y) continue;
               ++cnt;
 
		if (blue[x].size() + red[x].size() < blue[y].size() + red[y].size()) swap(x, y);
		parent[y] = x;
 
		blue[x].erase(y);
		blue[y].erase(x);
		red[x].erase(y);
		red[y].erase(x);
		
		for (auto &&dest: blue[y]) {
			if (red[x].find(dest) != red[x].end()) q.emplace(x, dest);
			blue[x].insert(dest);
			blue[dest].erase(y);
			blue[dest].insert(x);
		}
		blue[y].clear();
 
		for (auto &&dest: red[y]) {
			if (blue[x].find(dest) != blue[x].end()) q.emplace(x, dest);
			red[x].insert(dest);
			red[dest].erase(y);
			red[dest].insert(x);
		}
		red[y].clear();
	}
 
	if (cnt == n - 1) cout << "YES" << endl; else cout << "NO" << endl;
 
	return 0;
}

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

using namespace std;

int const RSIZE = 4;

string toStr(int x) {
  stringstream ss; ss << x;
  return ss.str();
}

int toInt(string s) {
  stringstream ss(s);
  int x; ss>>x;
  return x;
}

int change(int n) {
  
  int res = 0;
  int get = n*n;
  string s = toStr(get); int const ssize = s.size();
  string t;
  for(int i=0; i<2*RSIZE; i++) {
    if(ssize-1-i>=0) {
      t = s[ssize-1-i] + t;
    }
    else {
      t = '0' + t;
    }
  }
  
  string pre;
  for(int i=2; i<6; i++) {
    pre += t[i];
  }
  
  return toInt(pre);
}

int main() {
  int Tc; cin >> Tc;
  
  for(int T = 1; T <= Tc; T++) {
    cout << "Case " << T << ":" << endl;
    
    int N; cin >> N;
    
    int n = N;
    for(int i=0; i<10; i++) {
      n = change(n);
      cout << n << endl;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>
int main(void){
    long long plus[200005] = {0};
    long long minus[200005] = {0};
    long long n = 0;
    scanf("%lld",&n);
    for(int i = 1; i <= n; i++){
        long long a;
        long long p;
        long long m;
        scanf("%lld",&a);
        p = i + a;
        m = i - a;
        if(p <= 200005){
            plus[p] += 1;
        }
        if(m >= 0){
            minus[m] += 1;
        }
    }
    long long count = 0;
    for(int i = 0; i < 200005; i++){
        count+=plus[i]*minus[i];
    }
    printf("%lld",count);

    return 0;
}

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

int func(int x){
  if(x%100!=0) return 0;
  return func(x/100)+1;
}

int main(){
  int D,N;
  cin>>D>>N;
  int cnt =0;
  for(int x=1;;x++){
    if(func(x)==D){
      cnt++;
      if(cnt==N){
        cout<<x<<endl;
        return 0;
      }
    }
  }
  return 0;
}

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

int main() {

  int N, A;
  cin >> N >> A;
  if (A >= 500)
  {
      cout << "Yes" << endl;
  }
  else if (A <500 && A >= N % 500 )
  {
      cout << "Yes" << endl;
  }
  else
  {
      cout << "No" <<endl;
  }
  
}


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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define debug(x) cout << x << endl;
#define endl '\n'
#define sz(x) (int)x.size()
#define popcount __builtin_popcount
#define MAXN 200005
#define LOG 20
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define int long long

typedef long long ll;
typedef pair <ll, ll> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

int n, t;
int a, b;

int32_t main(){
    fastio
    cin >> a >> b;
    cout << max(0LL, a - 2 * b) << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x,y,z;
  cin>>x>>y>>z;
  swap(x,y);
  swap(x,z);
  cout<<x<<" "<<y<<" "<<z<<"\n";
  return 0;
} 

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int p[125252];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",p+i);
  int ans = 0;
  REP(i,n){
    if(i==p[i]-1){
      i++;
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.length();
  VI t(n);
  set<char> ss;
  REP(i, 0, 26) ss.insert('a' + i);
  REP(i, 0, n) {
    int idx = distance(ss.begin(), ss.find(s[i]));
    t[i] = idx;
    ss.erase(s[i]);
  }
  if (n < 26) {
    t.push_back(0);
  } else {
    int ind = -1;
    for (int i = 25; i >= 0; --i) {
      if (t[i] == 25 - i) continue;
      ind = i;
      break;
    }
    if (ind == -1) {
      cout << -1 << endl;
      return 0;
    }
    while (t.size() > ind + 1) t.pop_back();
    t[ind]++;
  }
  if (0) {
    REP(i, 0, t.size()) cerr << " " << t[i];
    cerr << endl;
  }
  string ans(t.size(), '+');
  REP(i, 0, 26) ss.insert('a' + i);
  REP(i, 0, t.size()) {
    auto it = ss.begin();
    advance(it, t[i]);
    char c = *it;
    ans[i] = c;
    ss.erase(c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int fact(int);

int main(){
  int n, m, i,count;

  while(1){
    count = 0;
    scanf("%d",&n);
    if(n == 0) 
      break;
    for(i = n+1 ; i <= 2*n ; i++){
      m = fact(i);
      if(m == 1)
	count++;
    }
    printf("%d\n",count);
  }
  return 0;
}
int fact(int x)
{
  int i;
  for(i = 2 ; i*i <= x ; i++){
    if(x % i == 0) return 0;
  }
  return 1;
}

Measured memory_bytes: 600
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <bits/stdc++.h>


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORa(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define FORs(i,st) for(auto i : st)
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
#define VEC2(x,a,b) vector<vector<ll>> x = vector<vector<ll>>(a,vector<ll>(b,0))
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "; cout<<endl
#define cout(n) cout<<fixed<<setprecision(n)

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ld d;
    cin>>d;
    ld r2 = sqrt(2);
    ll x = d + 1;
    cout(9)<<max((ld)x, d*r2)<<endl;
}



Measured memory_bytes: 3272
num_n = int(input())
n = [int(x) for x in input().split()]
num_m = int(input())
m = [int(x) for x in input().split()]
     
def solve(i, m):
   if m == 0:
      return True
   if i >= num_n or m > sum(n):
      return False
   res = solve(i + 1, m) or solve(i + 1,m - n[i])
   return res
      
for k in range(num_m):
   if solve(0, m[k]):
      print ("yes")
   else:
      print ("no")


Measured memory_bytes: 5632
#include <iostream>
#include <string>
#include <cstdio>
#define INF 1e+9
using namespace std;

signed main(){
	int n,m,q,v[2001][2001] = {},te[2001][2001] = {},ye[2001][2001] = {};
	string field[2000];
	cin >> n >> m >> q;
	for(int i = 0;i < n;i++) {
		cin >> field[i];
		for(int j = 0;j < m;j++) {
			v[i + 1][j + 1] = v[i][j + 1] + v[i + 1][j] - v[i][j] + (field[i][j] - '0');
			te[i + 1][j + 1] = te[i][j + 1] + te[i + 1][j] - te[i][j];
			ye[i + 1][j + 1] = ye[i][j + 1] + ye[i + 1][j] - ye[i][j];
			if(i && field[i][j] == '1' && field[i - 1][j] == '1') te[i + 1][j + 1]++;
			if(j && field[i][j] == '1' && field[i][j - 1] == '1') ye[i + 1][j + 1]++;
		}
	}
	for(int i = 0;i < q;i++){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);a--;b--;
		printf("%d\n",(v[c][d] - v[a][d] - v[c][b] + v[a][b]) - (te[c][d] - te[a + 1][d] - te[c][b] + te[a + 1][b] + ye[c][d] - ye[a][d] - ye[c][b + 1] + ye[a][b + 1]));
	}
	return 0;
}

Measured memory_bytes: 52864
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[] last=new int[200000];
		Arrays.fill(last,Integer.MAX_VALUE);

		long[]dp=new long[n+1];
		dp[0]=1;
		for(int i=1;i<=n;++i) {
			int v=s.nextInt()-1;
			if(last[v]<i-1) {
				dp[i]+=dp[last[v]];
			}
			dp[i]+=dp[i-1];
			dp[i]%=mod;
			last[v]=i;
		}
		System.out.println(dp[n]);
		System.err.println();
	}
	static int mod=1000000007;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int N = S.size();
  map<char, char> M;
  bool transformable = true;
  for (int i = 0; i < N; i++) {
    if (M.find(S[i]) != M.end() && M[S[i]] != T[i]) { transformable = false; break; }
    M[S[i]] = T[i];
  }
  M.clear();
  for (int i = 0; i < N; i++) {
    if (M.find(T[i]) != M.end() && M[T[i]] != S[i]) { transformable = false; break; }
    M[T[i]] = S[i];
  }
  cout << (transformable ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3916
def prob(k)
  return 0.75 ** 8 if k == 0
  return 0.25 ** 8 if k == 8
  (1..8).inject(:*) / (1..k).inject(:*) / (1..8-k).inject(:*) * (0.25 ** k) * (0.75 ** (8 - k))
end

$prob = (0..8).map {|k| prob(k) }

def qualifiers(result)
  ret = []
  rest = [0, 1, 2, 3]

  qualify_by = proc do |criteria|
    g = rest.group_by {|i| criteria[i] }
    flag = false
    g.keys.sort.reverse.each do |k|
      if flag
        rest -= g[k]
      elsif ret.flatten.size + g[k].size <= 2
        ret << g[k]
        rest -= g[k]
      else
        flag = true
      end
    end
  end

  calc_points = proc do
    points = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      if s1 > s2
        points[i] += 3
      elsif s1 < s2
        points[j] += 3
      else
        points[i] += 1
        points[j] += 1
      end
    end
    points
  end

  calc_diffs = proc do
    diffs = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      diffs[i] += s1 - s2
      diffs[j] += s2 - s1
    end
    diffs
  end

  calc_goals = proc do
    goals = [0] * 4
    result.each_key do |i, j|
      s1, s2 = result[[i, j]]
      goals[i] += s1
      goals[j] += s2
    end
    goals
  end

  r = rest.size
  loop do
    result = Hash[result.keys.select {|i, j| rest.include?(i) && rest.include?(j) }.map {|i, j| [[i, j], result[[i, j]]] }]

    points = calc_points[]
    qualify_by[points]
    return ret if ret.flatten.size == 2

    diffs = calc_diffs[]
    qualify_by[diffs]
    return ret if ret.flatten.size == 2

    goals = calc_goals[]
    qualify_by[goals]
    return ret if ret.flatten.size == 2

    break if rest.size == r
    r = rest.size
  end

  ret << rest
  ret
end

n = gets.to_i
n.times do
  s = gets
  target = (0..3).find {|i| s[5 + 5 * i] == ?* }
  result = {}
  unplayed = []
  (0..2).each do |i|
    s = gets
    (i+1..3).each do |j|
      if s[6 + 5 * j] == ?_
        unplayed << [i, j]
      else
        result[[i, j]] = [s[6 + 5 * j].to_i, s[8 + 5 * j].to_i]
      end
    end
  end

  probs = []
  (0..8).to_a.repeated_permutation(4) do |scores|
    prob = scores.map {|k| $prob[k] }.inject(:*)
    result[unplayed[0]] = scores[0..1]
    result[unplayed[1]] = scores[2..3]
    a = qualifiers(result)
    if a[0].include?(target)
      if a[0].size == 1
        probs << prob
      else
        probs << prob * 2 / a[0].size
      end
    elsif a[1] && a[1].include?(target)
      probs << prob / a[1].size
    end
  end
  gets

  p probs.sort.inject(:+) || 0
end



Measured memory_bytes: 9144
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin>>s;
    int len = s.length();
    if(s[len-1] != 's'){
    	cout<<s<<"s"<<endl;
	}
	else{
		cout<<s<<"es"<<endl;
	}
}

Measured memory_bytes: 3644
k=int(input())
n=50
r = n-1 + k//n
k %= n
res = [r for _ in range(n)]
for i in range(k):
    for j in range(n):
        if i == j:
            res[j]+= n
        else:
            res[j]-= 1

print(n)
print(" ".join(map(str,res)))

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

int n, m;
vector< int > graph[MAX_N];

void draw(int v, int c, int color[]){
  if(color[v] != -1) return;
  color[v] = c;
  for(int w: graph[v])
    draw(w, c, color);
}

vector< set< int > > components(){
  int color[n];
  fill(color, color + n, -1);
  int count = 0;
  for(int s = 0; s < n; s++){
    if(color[s] == -1){
      draw(s, count++, color);
    }
  }
  vector< set< int > > result;
  for(int i = 0; i < count; i++){
    set< int > s;
    result.push_back(s);
  }
  for(int v = 0; v < n; v++){
    result[color[v]].insert(v);
  }
  return result;
}

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

  cin >> n >> m;
  int p[n];
  for(int i = 0; i < n; i++) cin >> p[i];
  int x[m], y[m];
  for(int i = 0; i < m; i++) cin >> x[i] >> y[i];

  for(int i = 0; i < m; i++){
    graph[x[i] - 1].push_back(y[i] - 1);
    graph[y[i] - 1].push_back(x[i] - 1);
  }

  int count = 0;
  for(set< int > vertices: components()){
    for(int v: vertices){
      if(vertices.find(p[v] - 1) != vertices.end())
        ++count;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 19712
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a = read::<usize>();
    let b = read::<usize>();
    println!(
        "{}",
        if a <= 5 {
            0
        } else if a <= 12 {
            b / 2
        } else {
            b
        }
    );
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n = 0, a ,b, c = 0, d = 0, e = 0;
	for (int i = 0; i < 3; i++) {
		cin >> a >> b;
		if (a == 1 || b == 1) { n++; }
		if (a == 2 || b == 2) { c++; }
		if (a == 3 || b == 3) { d++; }
		if (a == 4 || b == 4) { e++; }
	}
	if (n == 3 || c == 3 || d == 3 || e == 3) {
		cout << "NO" << endl;
	}
	else { cout << "YES" << endl; }
	cin >> a;
}

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

int main(void){
    string s;
    cin >> s;

    long long  sum = 0;
    int n = s.size();

    for(int temp = 0; temp < (1 << n-1); temp++){
        long long t = s[0] - '0';

        for(int i = 0; i < n-1; i++){

            if(temp & (1 << i)){ //1が立っていれば, プラス記号を入れる場所とみなす
                sum += t;
                t = s[i+1] - '0';
            }
            else{
                t *= 10; //1が立っていなければプラス記号を入れないとみなす
                t += s[i+1] - '0';
            }
        }
        sum += t;
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define all(x) x.begin(),x.end()

inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}

const ll MOD =998244353;
const ll hell=MOD;
const int INF=3e17;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
const int N=3001;
int s;int a[N];
int dpl[3001],dpr[3001];int suff[3001],pre[3001];int n;
int solve(int l,int r)
{
    if(l==r)
    {
        if(a[l]==s)
            return ((l+1)*(n-r))%hell;
        else
            return 0;
    }
    int m=(l+r)/2;
    int ansl=solve(l,m);
    int ansr=solve(m+1,r);
    int ans=(ansl+ansr)%hell;
    memset(dpl,0,sizeof(dpl));
    memset(dpr,0,sizeof(dpr));
    memset(suff,0,sizeof(suff));
    memset(pre,0,sizeof(pre));
    dpl[0]=0;suff[0]=1;
    dpr[0]=0;pre[0]=1;
    for(int i=m;i>=l;i--)
    {
        for(int j=s;j>=0;j--)
        {
            if(a[i]<=j)
            {
                dpl[j]=(dpl[j]+((i+1)*suff[j-a[i]])%hell)%hell;
                suff[j]=(suff[j]+suff[j-a[i]])%hell;
            }
        }
    }
    for(int i=m+1;i<=r;i++)
    {
        for(int j=s;j>=0;j--)
        {
            if(a[i]<=j)
            {
                dpr[j]=(dpr[j]+(n-i)*pre[j-a[i]])%hell;
                pre[j]=(pre[j]+pre[j-a[i]])%hell;
            }
        }
    }
    for(int i=1;i<s;i++)
        ans=(ans+(dpl[i]*dpr[s-i])%hell)%hell;
    
    return ans;
    
}
void solve()
{
    //int n;
    cin>>n>>s;
    for(int i=0;i<n;i++)
        cin>>a[i];
    cout<<solve(0,n-1)<<endl;
}
int32_t main()
{
    
    IOS;
    //FILE *fin = freopen("in","r",stdin);
    //FILE *fout = freopen("out","w",stdout);
    int t;
    t=1;
    //cin>>t;
    
    while(t--)
    {
        
        
        solve();
    }
    return 0;
}




Measured memory_bytes: 384
A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())
MA = ((A - 1) // 10 + 1) * 10
MB = ((B - 1) // 10 + 1) * 10
MC = ((C - 1) // 10 + 1) * 10
MD = ((D - 1) // 10 + 1) * 10
ME = ((E - 1) // 10 + 1) * 10
ma = (A + 9) % 10 + 1
mb = (B + 9) % 10 + 1
mc = (C + 9) % 10 + 1
md = (D + 9) % 10 + 1
me = (E + 9) % 10 + 1
min = min (ma, mb, mc, md, me)
print(MA + MB + MC + MD + ME - 10 + min)


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

typedef long long ll;
typedef vector<vector<ll>> M;

M mat;
const ll mod = 1e9+7;

M zero(int n){
    M rta(n);
    for(int i = 0; i<n; ++i){
        rta[i].resize(n, 0);
    }
    return rta;
}

M one(int n){
    M rta = zero(n);
    for(int i = 0; i<n; ++i){
        rta[i][i]=1;
    }
    return rta;
}

ll add(ll a, ll b){
    ll rta = a+b;
    return rta>=mod ? rta-mod : rta;
}

ll prod(ll a, ll b){
    ll rta = a*b;
    return rta>=mod ? rta%mod : rta;
}

M mul(M &m1, M &m2){
    int n = m1.size();
    M rta = zero(n);
    for(int i = 0; i<n; ++i){
        for(int j = 0; j<n; ++j){
            for(int k = 0; k<n; ++k){
                rta[i][j]=add(rta[i][j], prod(m1[i][k], m2[k][j]));
            }
        }
    }
    return rta;
}

M elev(M &b, ll e){
    int n = b.size();
    M rta = one(n);
    while(e){
        if(e&1){
            rta = mul(rta, b);
        }
        b = mul(b, b);
        e>>=1;
    }
    return rta;
}

int main(){
    int n;
    ll k;
    cin>>n>>k;
    M rta = zero(n);
    for(int i = 0; i<n; ++i){
        for(int j = 0; j<n; ++j){
            cin>>rta[i][j];
        }
    }
    rta = elev(rta, k);
    ll resp = 0;
    for(int i = 0; i<n; ++i){
        for(int j = 0; j<n; ++j){
            resp =add(resp, rta[i][j]);
        }
    }
    cout<<resp<<"\n";
}



Measured memory_bytes: 764
fn main() {
    let a: u32 = read();
    let b: u32 = read();
    let h: u32 = read();
    let ans = (a+b) * h / 2;
    println!("{}", ans);
}

// 以下関数

use std::io::*;
use std::str::FromStr;
pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

pub const MOD: u64 = 1_000_000_007;

pub fn is_prime(n: i32) -> bool {
    if n < 2 {
        return false;
    } else if n == 2 {
        return true;
    }
    let mut i = 2;
    while i * i < n {
        if n % i == 0 {
            return false;
        } else {
            i += 1;
            continue;
        }
    }
    true
}

pub fn lcm(mut n: i32, mut m: i32) -> i32 {
    n = if n > m { m } else { n };
    m = if n > m { n } else { m };
    let mut i = n;
    while i % m != 0 {
        i += n;
    }
    i
}

pub fn abs(n: i32) -> i32 {
    if n >= 0 {
        n
    } else {
        -n
    }
}

pub fn max(n: i32, m: i32) -> i32 {
    if n >= m {
        n
    } else {
        m
    }
}

pub fn min(n: i32, m: i32) -> i32 {
    if n <= m {
        n
    } else {
        m
    }
}

pub fn factorial(n: u32) -> u32 {
    if n == 0 {
        return 1;
    }
    let mut r = n;
    for i in 0..n - 1 {
        r *= n - i - 1;
    }
    r
}

pub fn combination(n: u32, m: u32) -> u32 {
    factorial(n) / factorial(m) / factorial(n - m)
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
int N,M;
cin>>N;
map<string,int> S;
vecs(A)
fx(N){
	vecps(A)
	S[A.at(x)]++;
}
cin>>M;
fx(M){
	string a;
	cin>>a;
	S[a]--;
}
int maxi=0;
fx(N){
	maxi=max(S[A.at(x)],maxi);
}
ce(maxi)

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc= new Scanner(System.in);
    int N = sc.nextInt();
    int array[] =new int[N];
    for(int i=0; i<N; i++){
      array[i]=sc.nextInt();
    }
    int idx=1;
    int cnt=0;
    while(cnt<100002){
      cnt++;
      if(array[idx-1]==2){
        break;
      }else if(cnt<100001){
        idx=array[idx-1];
    }else{
        cnt=-1;
        break;
     }
    }
    System.out.println(cnt);
  }  
}

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

typedef long long ll;
typedef unsigned long long ull;
#define MOD 998244353

ll fact[6001],factinv[6001];

ll mpow(ll x, ll p){
    if(p==0) return 1;
    if(p==1) return x%MOD;
    if(p%2==0) return mpow(x*x%MOD,p/2)%MOD;
    else return x*mpow(x*x%MOD,p/2)%MOD;
}

ll conv(ll n, ll r){
    if(n<0 || r<0 || n-r<0) return 0;
    return ((fact[n]*factinv[r])%MOD)*factinv[n-r]%MOD;
}

ll sepptn(ll n, ll to){
    return conv(n+to-1,n)%MOD;
}

int main(){
    fact[0]=1;
    for(int i=1;i<=6000;i++) fact[i]=i*fact[i-1]%MOD;
    for(int i=0;i<=6000;i++) factinv[i]=mpow(fact[i],MOD-2);

    ll K,N;
    cin >> K >> N;

    for(ll i=2;i<=2*K;i++){
        ll ans=0;
        ll kaku=0,pea=0;
        if(i%2==1){
            pea=min(i/2,K-i/2);
            kaku=K-pea*2;
            for(ll j=0;j<=pea;j++){
                if(kaku+j<=0) continue;
                ans=(ans+sepptn(N-j,j+kaku)*mpow(2,j)%MOD*conv(pea,j)%MOD)%MOD;
            }
        }else{
            pea=min(i/2-1,K-i/2);
            kaku=K-1-pea*2;
            for(ll j=0;j<=pea;j++){
                ans=(ans+sepptn(N-j,j+kaku)*mpow(2,j)%MOD*conv(pea,j)%MOD)%MOD;
                ans=(ans+sepptn(N-1-j,j+kaku)*mpow(2,j)%MOD*conv(pea,j)%MOD)%MOD;
            }
        }
        cout << ans << endl;
    }

    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define bug(x) do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define bugv(x) do{cerr<#x<<': "';for(auto&e:x)cerr<<e<<" ";cerr<<"\n";}while(0)

using namespace std;
using ll=long long;

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

  int N, K; cin >> N >> K;
  string S; cin >> S;
  S[K-1] = S[K-1] - 'A' + 'a';
  cout << S << endl;

  return 0;
}


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

int main()
{
    ll a, b, k;

    cin >> a >> b >> k;

    a -= k;

    if(a < 0){
        b += a;
        a = 0;
    }

    if(b < 0) b = 0;

    cout << a << ' ' << b << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int H = 0;
    int W = 0;
    
    while( 1 )
    {
        // input
        std::cin >> H;
        std::cin >> W;
        
        if( 0 == H && 0 == W )
        {
            break;
        }
        
        if( H < 1 || H > 300 || W < 1 || W > 300 )
        {
            std::cout << "Error : out of range!" << std::endl;
            return -1;
        }
        
        for( int i = 0; i < H; ++i )
        {
            for( int j = 0; j < W; ++j )
            {
                if( 0 == ( i + j )% 2 )
                {
                    std::cout << "#";
                }
                else
                {
                    std::cout << ".";
                }
            }
            std::cout << std::endl;
        }
        std::cout << std::endl;
    }
    
    return 0;
}


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

int main(){
char S[256];
int K, len_s, i;
scanf("%d", &K);
scanf("%s", S);
len_s = strlen(S);
if(len_s <= K){
  printf("%s\n", S);
}else if(len_s > K){
  for(i = 0; i < K; i++){
    printf("%c", S[i]);
  }
  printf("...\n");
}
  return 0;
}

Measured memory_bytes: 1664
#include <cstdio>

using namespace std;

typedef long long ll;

int main(void) {
  ll n;
  ll s = 0, i;
  scanf("%lld", &n);
  for (i = 1; s < n; i++) {
    s += i;
  }
  --i;
  while (n > 0) {
    if (n >= i) {
      n -= i;
      printf("%lld\n", i);
    }
    --i;
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  int a,b;
   cin >> a>> b;
   if(a!=b)cout << 2*max(a,b)-1 << endl;
  else cout << 2*a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int k,x,i;
    cin >> k >> x;
    for(i=k-1;i>0;i--){
        cout << x-i << " ";
    }
    for(i=0;i<k;i++){
        cout << x+i << " ";
    }
}

Measured memory_bytes: 256
import sys


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    k, n = map(int, input().split())
    houses = [int(s) for s in input().split()]
    houses = houses + [houses[0] + k]
    distance = 0
    for i in range(1, len(houses)):
        distance = max(distance, houses[i] - houses[i-1])
    print(k - distance)


if __name__ == "__main__":

    main()


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

#define fs first
#define sc second
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

const int32_t inf = 1001001001;
const int64_t infll = 1001001001001001001ll;
const int dx[] = {0, -1, 1, 0, -1, 1, -1, 1}, dy[] = {-1, 0, 0, 1, -1, -1, 1, 1};

template <typename T> using vector2d = vector<vector<T>>;

// clang-format off
template <typename T> void sort(vector<T> &v) { sort(all(v)); }
ostream &operator<<(ostream &os, __int128_t value) { if (ostream::sentry(os)) { __uint128_t tmp = value < 0 ? -value : value; char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __int128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } if (in[0] == '-') value *= -1; return is; }
ostream &operator<<(ostream &os, __uint128_t value) { if (ostream::sentry(os)) { char buffer[64]; char *d = end(buffer); do { --d; *d = "0123456789"[value % 10]; value /= 10; } while (value != 0); int len = end(buffer) - d; if (os.rdbuf()->sputn(d, len) != len) { os.setstate(ios_base::badbit); }} return os; }
istream &operator>>(istream &is, __uint128_t &value) { string in; is >> in; value = 0; for (const char &c : in) { if ('0' <= c && c <= '9') value = 10 * value + (c - '0'); } return is; }
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { os << v[0]; for (int i = 1; i < v.size(); ++i) os << " " << v[i]; return os; }
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.fs << " " << p.sc; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.fs >> p.sc; return is; }

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

inline int64_t in() { int64_t x = 0; cin >> x; return x; }
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

signed main(int argc, char *argv[]) {
  vector<int> a(3);
  cin >> a;

  sort(all(a));
  if (a[1] == a[0])
    cout << a[2] << endl;
  else
    cout << a[0] << endl;
}


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

def doit(s, e, t):
    if s == e:
        return 0
    ret = 1
    i = s
    for j in range(s, e):
        if h[j] == t:
            ret += doit(i, j, t + 1)
            i = j + 1
    ret += doit(i, e, t + 1)
    return ret

print(doit(0, n, 0) - 1)

Measured memory_bytes: 42260
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int A = a + b;
        int B = b + c;
        int C = a + c;
        if (A > B) {
            if (B > C) {
                System.out.println(C);
            } else  {
                System.out.println(B);
            }
        } else if(A>C){
            System.out.println(C);
        }else {
            System.out.println(A);
        }
    }

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/02/24  Problem: code-festival-2017-qual-c_c / Link: https://code-festival-2017-qualc.contest.atcoder.jp/tasks/code_festival_2017_qualc_c?lang=en  ----- */
/* ------問題------

英小文字のみからなる文字列 s があります。 すぬけ君は、次の操作を繰り返し行うことができます。
s の任意の位置 (先頭および末尾を含む) をひとつ選び、英小文字 x をひとつ挿入する。
すぬけ君の目標は、s を回文にすることです。 すぬけ君の目標が達成可能か判定し、達成可能ならば必要な操作回数の最小値を求めてください。
注釈
回文とは、前後を反転しても変わらない文字列のことです。 例えば、a, aa, abba, abcba は回文ですが、ab, abab, abcda は回文ではありません。

-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

LL N;

LL ans = 0LL;

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


	string s; cin >> s;
	int l = 0;
	int r = SZ(s) - 1;
	while (l < r) {
		if (s[l] != s[r]) {
			if (s[l] == 'x') {
				ans++;
				l++;
			}
			else if (s[r] == 'x') {
				ans++;
				r--;
			}
			else {
				ans = -1;
				break;
			}
		}
		else {
			l++;
			r--;
		}
	}


	cout << ans << "\n";

	return 0;
}


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

typedef long long ll;
typedef double d;

#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (abs(a*b)/gcd(a,b))
#define sqr(a) (a*a)

#define tt int t; cin>>t; while(t--)
#define lo(i, a, b) for(int i=a; i<b; i++)
#define rlo(i, a) for(int i=a; i>0; i--)
#define be(a) a.begin(),a.end()
#define sz(x) x.size()
#define nl cout<<"\n";
#define sp cout<<" ";

#define op() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

int main()
{
    op();
    int n,k,d,a,cnt=0;
    cin>>n>>k;
    int p[n+1]={0};
    while(k--)
    {
        cin>>d;
        while(d--)
        {
            cin>>a;
            p[a-1]=1;
        }
    }
    lo(i,0,n)
    {
        if(p[i]==0)
            cnt++;
    }
    cout<<cnt;
    nl;
    return 0;
}



Measured memory_bytes: 3644
N, M = map(int,input().split())
link = []
for _ in range(M):
    array = list(map(int,input().split()))
    link.append(array[1:])
p = list(map(int,input().split()))

s = ''
lamp = [0]*M
ans = 0

for i in range(2**N):
    lamp = [0] * M
    s = format(i, '#012b')[::-1]
    for j in range(M):
        for k in link[j]:
            if s[k-1] == '1':
                lamp[j] ^= 1
    if p == lamp:
        ans += 1

print(ans)


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll N; cin>>N;
	char s[101];
	rep(i,N) scanf("%c",&s[i]);

	rep(i,N){
		if(s[i]=='Y'){
			cout<<"Four";
			return 0;
		}
	}
	cout<<"Three";
}

Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;



int main() {
    string s, t;
    int stype[100] = {}, ttype[100] = {}, ss = 0, tt = 0;
    cin >> s >> t;
    for (int i = 0; i < s.length(); i++) stype[s[i]-'0']++;
    for (int i = 0; i < t.length(); i++) ttype[t[i]-'0']++;
    for (char i = 'a'; i <= 'z'; i++) {
        if (stype[i - '0'] != 0) ss++;
        if (ttype[i - '0'] != 0) tt++;
    }
    if (ss == 1 && tt == 1) {
        if (s.length() < t.length()) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    else{
        char smin = 'z';
        bool flag = false;
        for (int i = 0; i < s.length(); i++) smin = min(smin, s[i]);
        for (char i = smin; i <= 'z'; i++) {
            if (i == smin) continue;
            if (ttype[i-'0'] != 0) {
                cout << "Yes" << endl;
                flag = true;
                break;
            }
        }
        if(!flag) cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256