akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    S = list(input())

    abc = [chr(i) for i in range(97, 123)]
    # print(abc)

    for s in S:
        if s in abc:
            abc[ord(s) - 97] = 0



    if len(S) == 26:
        # abc = [chr(i) for i in range(97, 123)]
        # print(S)
        SR = S[::-1]
        # print(SR)
        idx = (INF, INF)
        for i in range(26):
            for j in range(i+1, 26):
                if SR[i] > SR[j]:
                    # print(i, j)
                    # print(S[:-j])
                    if j < idx[1]:
                        idx = (i, j)
                    break
        # print(idx)
        i, j = idx
        if i == INF:
            print(-1)
        else:
            ans = S[:-j-1]
            ans.append(SR[i])
            printlist(ans, '')

    else:
        for t in abc:
            if t != 0:
                S.append(t)
                printlist(S, k='')
                return

if __name__ == '__main__':
    solve()


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

using namespace std;
const long mod = 1000000007;
typedef long long lint;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(N) for(int i = 0; i < (int)(N); i++)
#define all(x) (x).begin(),(x).end()
#define length(x) ((int)(x).size())
#define prln(s) cout<<s<<endl;

#define str(s) string s;cin>>s;
#define int1(x) int x;cin>>x;
#define int2(x,y) int x,y;cin>>x>>y;

int main() {
  int2(l,r);
  if(abs(l-r)>=2019){
    prln(0);
    return 0;
  }
  l=l%2019;
  r=(r%2019);
  
  int min=2018;
  for (int i = l; i <= r-1; ++i) {
    for (int j = i+1; j <= r; ++j) {
      
      int modans = (i*j)%2019;
      
      if(modans<min){
        min=modans;
      }
    }
  }
  prln(min);  
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
using namespace std;
int main(void){
int N;
cin>>N;
char str[N+1];
cin>>str;
int K;
cin>>K;
char check=str[K-1];
for(int i=0;i<N;i++){
    if(str[i]!=check){cout<<'*';}
    else cout<<check;
}
return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(void){
  long N,K,a;
  scanf("%ld%ld",&N,&K);

  for(int i = 0;i < N;i++){
    scanf("%ld",&a);
  }

  if((N-1)%(K-1) == 0)
    printf("%ld\n",(N-1)/(K-1));
  else
    printf("%ld\n",(N-1)/(K-1)+1);

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int xm=1e3;
bool b[xm+1];
int x;
int main(){
  b[1]=1;
  for(int i=2;i*i<=xm;i++){
    for(int j=i*i;j<=xm;j*=i){
      b[j]=1;
    }
  }
  cin>>x;
  while(!b[x])x--;
  cout<<x<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int main(){
  ll N;
  const int SIZE = 5;
  vector<ll> vec(SIZE);
  cin >> N; for(int i=0; i<SIZE; i++) cin >> vec[i];

  ll m = 1e15+1;
  for(int i=0; i<SIZE; i++) m = min(m, vec[i]);
  ll ans = (N+m-1)/m + 4;
  cout << ans << endl;

  return 0;
}


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

int main() {
 int a, b;
 cin >> a >> b;
 if (a == b) {
  cout << "a == b" << endl;
 }
 else if (a > b) {
   cout << "a > b" << endl;
 }
 else if (a < b) {
   cout << "a < b" << endl;
  }
 return 0;
 
}


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

int n;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    long long ans=0;
    for(int i=1;i<=n;i++){
        ans+=(long long)(n-i+1)*i;
    }
    for(int i=1;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        ans-=(long long)a*(n-b+1);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3660
"use strict";

var main = function main(input) {
  var N = parseInt(input.split(" ")[0]);
  var A = parseInt(input.split(" ")[1]);
  var B = parseInt(input.split(" ")[2]);
  var count = 0;

  for (var i = 1; i <= N; i++) {
    var sum = 0;
    var arr = i.toString().split("");
    var _iteratorNormalCompletion = true;
    var _didIteratorError = false;
    var _iteratorError = undefined;

    try {
      for (var _iterator = arr[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
        var c = _step.value;
        sum += parseInt(c, 10);
      }
    } catch (err) {
      _didIteratorError = true;
      _iteratorError = err;
    } finally {
      try {
        if (!_iteratorNormalCompletion && _iterator.return != null) {
          _iterator.return();
        }
      } finally {
        if (_didIteratorError) {
          throw _iteratorError;
        }
      }
    }

    if (sum <= B && sum >= A) {
      count += i;
    }
  }

  console.log(count);
};

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 25476
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

namespace MyProject
{
    class Program
    {
        static void Main(string[] args)
        {
#if Local
            var sw = new Stopwatch();
            sw.Start();
            Console.SetIn(new StreamReader("input.in"));
#endif

            var solver = new Solver();
            solver.Solve();
#if Local
            Console.WriteLine($"{sw.ElapsedMilliseconds}ms");
#endif
        }
    }

    class Solver
    {
        private Dictionary<int, int> cashe = new Dictionary<int, int>();

        public void Solve()
        {
            var K = int.Parse(Console.ReadLine());
            var answer = 0;
            foreach (var a in Enumerable.Range(0, K).Select(elem => K - elem))
            {
                foreach (var b in Enumerable.Range(0, K).Select(elem => K - elem))
                {
                    var temp = Gcd(a, b);
                    foreach (var c in Enumerable.Range(0, K).Select(elem => K - elem))
                    {
                        if (a == c || b == c)
                        {
                            answer += temp;
                        }
                        else
                        {
                            answer += Gcd(temp, c);
                        }
                    }
                }
            }

            Console.WriteLine(answer);
        }

        public int GcdRecursive(int a, int b)
        {
            var key = a * 1000 + b;
            if (cashe.ContainsKey(key))
            {
                return cashe[key];
            }
            else
            {
                var answer = b == 0 ? a : GcdRecursive(b, a % b);
                cashe[key] = answer;
                return answer;
            }
        }

        public int Gcd(int a, int b)
        {
            if (a < b)
            {
                return GcdRecursive(b, a);
            }
            else
            {
                return GcdRecursive(a, b);
            }
        }
    }
}


Measured memory_bytes: 32688
using System;

namespace AtCoder{
    public static class AtCoder{
        public static void Main(){
            int k = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();

            if(s.Length <= k){Console.WriteLine(s);}
            else{
                Console.WriteLine(s.Substring(0, k) + "...");
            }
        }
    }
}

Measured memory_bytes: 27548
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
int result_arr[10000000];
int collatz(int pre_result,int index){
    result_arr[index-1]=pre_result;
    if(pre_result==1&&index>=4){

        return index;
    }
    if(pre_result%2==0){
        return collatz(pre_result/2,index+1);
    }else{
        return collatz(pre_result*3+1,index+1);
    }
}

int main(int argc, char const *argv[])
{
    int s;
    cin>>s;
    int last_index=0;
    int ans=0;
    last_index=collatz(s,2);
    result_arr[last_index]=4;
    for(int i=1;i<=last_index;i++){
        for(int j=i+1;j<=last_index;j++){
            if(result_arr[i]==result_arr[j]){
                ans=j;
                goto LABEL;
            }
        }
    }
    LABEL:
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define For(x,a,b,c) for(x=a;x<b;x+=c)
#define mod 1000000007
 
 
int main(){
ll n;
cin>>n;
ll ar[n][3];
for(int i=0;i<n;i++)
	for(int j=0;j<3;j++)cin>>ar[i][j];
    ll a,b,c;
	for(int i=1;i<n;i++){
		a=ar[i][0]+max(ar[i-1][1],ar[i-1][2]);
		b=ar[i][1]+max(ar[i-1][0],ar[i-1][2]);
		c=ar[i][2]+max(ar[i-1][0],ar[i-1][1]);
		ar[i][0]=a;
        ar[i][1]=b;
        ar[i][2]=c;
	}
	cout<<*max_element(ar[n-1],ar[n-1]+3)<<endl;
 
  return 0;
}

Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.lang.Math;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collections;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt(); int b = fs.nextInt();
        System.out.println(a*b);


    }





    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }

}


Measured memory_bytes: 32740
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	int
		a, b;
	//string s="error";
	cin >> a; //cin >> b; //cin >> c;
	cout << a * 800 - (a / 15) * 200 << endl;
}

Measured memory_bytes: 256
import Control.Applicative ((<$>))
import Control.Monad (unless, guard)

main :: IO ()
main = do
  [x, y, s] <- map read <$> words <$> getLine
  unless (x == 0 && y == 0 && s == 0) $ do
    print $ solve x y s
    main

solve :: Int -> Int -> Int -> Int
solve x y s = maximum $ do
  (a1, b1) <- ls
  (a2, b2) <- ls
  guard $ a1 + a2 == s
  return $ b1 + b2
  where ls = takeWhile (\(u,_) -> u < s) $ do
          a <- [1..]
          return (a * (100+x) `div` 100, a * (100+y) `div` 100)



Measured memory_bytes: 5596
package main

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

func main() {
	scan := bufio.NewScanner(os.Stdin)
	scan.Split(bufio.ScanWords)
	scan.Scan()
	scan.Scan()
	k, _ := strconv.Atoi(scan.Text())
	scan.Scan()
	s := scan.Text()

	for i, v := range s {
		if i == k-1 {
			fmt.Print(strings.ToLower(string(v)))
		} else {
			fmt.Print(string(v))
		}
	}
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s[101],d[9],f=0,g=0,h=0,i,j;
	scanf("%d",&a);
	for(i=0;i<9;i++) d[i]=0;
	for(i=0;i<a;i++){
		scanf("%d",&s[i]);
		if(s[i]<400) d[0]=1;
		else if(s[i]<800) d[1]=1;
		else if(s[i]<1200) d[2]=1;
		else if(s[i]<1600) d[3]=1;
		else if(s[i]<2000) d[4]=1;
		else if(s[i]<2400) d[5]=1;
		else if(s[i]<2800) d[6]=1;
		else if(s[i]<3200) d[7]=1;
		else d[8]++;
	}
	for(i=0;i<8;i++){
		if(d[i]==1)	f++;
		if(d[i]==0)	h++;
	}
	g=f+d[8];
	if(f==0) f=1;
	printf("%d %d\n",f,g);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
 
int main() {
    ll h, w;
    cin >> h >> w;
    
    ll ans;
    
    if ((h == 1) || (w == 1)) {
        ans = 1;
    } else if ((h % 2 == 0) && (w % 2 == 0)) {
        ans = (w*h)/2;
    } else if ((h % 2 == 0) && (w % 2 != 0)) {
        ans = (h/2) * w;
    } else if ((h % 2 != 0) && (w % 2 == 0)) {
        ans = (w/2) * h;
    } else if ((h % 2 != 0) && (w % 2 != 0)) {
        ans = ((h * (w + 1)) / 2) - (h / 2);
    } else {
        ans = 0;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
#define inf (int)(1e9)

int solve(int N, string S, string T){
/*	printf("test1\n");
	cout << S << endl;
	cout << T << endl;
*/	int i, j;
	vector<vector<int> > sub(N + 1, vector<int>(N + 1, 0));
	for(i = N - 1; i >= 0; i--){
		for(j = N - 1; j >= 0; j--){
			sub[i][j] = sub[i + 1][j + 1] + (S[i] == T[j]);
		}
	}
	vector<vector<int> > dp(N + 1, vector<int>(N + 1, inf));
	dp[0][0] = 0;
	for(i = 0; i <= N; i++){
		for(j = 0; j <= N; j++){
			if(i > 0){
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + sub[i - 1][j]);
			}
			if(j > 0){
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + sub[i][j - 1]);
			}
		}
	}
/*	printf("sub:\n");
	for(i = 0; i <= N; i++){
		for(j = 0; j <= N; j++){
			printf("%d ", sub[i][j]);
		}
		printf("\n");
	}
	printf("\n");
	printf("dp:\n");
	for(i = 0; i <= N; i++){
		for(j = 0; j <= N; j++){
			printf("%d ", dp[i][j]);
		}
		printf("\n");
	}
	printf("\n");
*/	return dp[N][N];
}

int main(){
	int H, W, i, j;
	scanf("%d%d", &H, &W);
	char **c = new char *[H];
	for(i = 0; i < H; i++){
		c[i] = new char[W + 1];
		scanf("%s", c[i]);
	}
	vector<string> S(W, string(H, 'a'));
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
			S[j][H - 1 - i] = c[i][j];
		}
	}
	int ans = 0;
	for(j = 1; j < W; j++){
		ans += solve(H, S[j - 1], S[j]);
	}
	printf("%d\n", ans);
	return 0;
}

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

int main() {
    long long n, a, b;
    cin>>n>>a>>b;
    long long result=0;
    if(n==1) {
        if(a==b) 
          result=1;
        else 
          result=0;
    }
    else if (a > b) 
      result=0;
    else {
        result=(a + b*(n-1))-(a*(n-1) + b)+1;
    }
    cout <<result;
	return 0;
}


Measured memory_bytes: 3568
import java.util.Scanner;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		String abcd = sc.nextLine();

		int a = Integer.parseInt(abcd.substring(0, 1));
		int b = Integer.parseInt(abcd.substring(1, 2));
		int c = Integer.parseInt(abcd.substring(2, 3));
		int d = Integer.parseInt(abcd.substring(3, 4));

		for (int i = 0; i < 8; i++) {
			int op1 = (i & 4) > 0 ? 1 : -1;
			int op2 = (i & 2) > 0 ? 1 : -1;
			int op3 = (i & 1) > 0 ? 1 : -1;
			if ((a + (b * op1) + (c * op2) + (d * op3)) == 7) {
				System.out.println(answerString(a, b, c, d, op1, op2, op3));
				break;
			}
		}
		sc.close();
	}

	private String answerString(int a, int b, int c, int d, int op1, int op2, int op3) {
		StringBuilder str = new StringBuilder();
		str.append(a);
		str.append(toCharOps(op1));
		str.append(b);
		str.append(toCharOps(op2));
		str.append(c);
		str.append(toCharOps(op3));
		str.append(d);
		str.append("=7");
		return str.toString();
	}

	private char toCharOps(int op) {
		if (op == 1) {
			return '+';
		} else if (op == -1) {
			return '-';
		} else {
			throw new IllegalArgumentException();
		}
	}
}

Measured memory_bytes: 23892
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdin = new Scanner(System.in);
		int a =stdin.nextInt();
		int b =stdin.nextInt();
		int c =stdin.nextInt();
		int x =stdin.nextInt();
		int y =stdin.nextInt();
		int set=0;
		if(x<y) {
			set=x;
			if(a+b<2*c) {
				System.out.println(a*x+b*y);
			}else {
				System.out.println(Math.min(set*c*2+(y-set)*b,c*y*2));
			}
		}else {
			set=y;
			if(a+b<2*c) {
				System.out.println(a*x+b*y);
			}else {
				System.out.println(Math.min(set*c*2+(x-set)*a,c*x*2));
			}
		}
		

		


	}

}

Measured memory_bytes: 23124
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.parents=[-1]*n

    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x])
            return self.parents[x]

    def union(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.parents[x]>self.parents[y]:
            x,y=y,x
        self.parents[x]+=self.parents[y]
        self.parents[y]=x

    def size(self,x):
        return -self.parents[self.find(x)]

    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def members(self,x):
        root=self.find(x)
        return [i for i in range(self.n) if self.find(i)==root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x<0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n=int(input())
X=[]
Y=[]
for i in range(n):
    x,y=map(int,input().split())
    X.append([x,i])
    Y.append([y,i])
X.sort()
Y.sort()
E=[]
for i in range(n-1):
    E.append([X[i+1][0]-X[i][0],X[i][1],X[i+1][1]])
    E.append([Y[i+1][0]-Y[i][0],Y[i][1],Y[i+1][1]])
E.sort()
U=UnionFind(n)
ans=0
for i in range(2*n-2):
    d=E[i][0]
    j1=E[i][1]
    j2=E[i][2]
    if not U.same(j1,j2):
        ans+=d
        U.union(j1,j2)
print(ans)

Measured memory_bytes: 64044
while True:
    line = input()
    H, W = map(int, line.split())

    if H == 0 and W == 0:
        break

    for h in range(1, H+1):
        for w in range(1, W+1):
            if (h % 2 == 1 and w % 2 == 1) or (h % 2 == 0 and w % 2 == 0):
                c = '#'
            else:
                c = '.'
            print(c, end='')
        print('')
    print('')

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll a,b,c,k,ans; cin>>a>>b>>c>>k;
    ans = a-b;
    if(k%2) ans = b-a;
    if(ans>INF) cout<<"Unfair"<<endl;
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define PI 3.14159265358979323846
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

int main(void) {
	int n, m, i, x;
	ll ans = 1;
	cin >> n >> m;
	vector<ll> a(n * m + 2, 0), b(n * m + 2, 0);
	rep(i, n) {
		cin >> x;
		a[x]++;
	}
	rep(i, m) {
		cin >> x;
		b[x]++;
	}
	for(i = n * m; i > 0; i--) {
		if (a[i] > 1 || b[i] > 1)
			ans = 0;
		a[i] += a[i + 1];
		b[i] += b[i + 1];
	}
	for (i = n * m; i; i--) {
		if (a[i + 1] + 1 == a[i]) {
			if (b[i + 1] == b[i]) {
				ans *= b[i];
			}
		}
		else if (b[i + 1] + 1 == b[i]) {
			ans *= a[i];
		}
		else
			ans *= max(0ll, (a[i] * b[i] - n * m + i)) % MOD;
		ans %= MOD;
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 18836
/*
      author : nishi5451
      created: 12.08.2020 15:15:53
*/

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


int main(){
    string s;
    cin >> s;
    if(s.size()%2!=0) {
        cout << "No" << endl;
        return 0;
    }
    rep(i,s.size()){
        if(i%2==0 && s[i]=='h')
            continue;
        if(i%2==1 && s[i]=='i')
            continue;
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 3624
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    char C; cin >> C;

    if ('A' <= C && C <= 'Z') {
        cout << 'A' << nl;
    } else cout << 'a' << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


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

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

const ll mod =  1000000007;  //ansを出力する時は (ans % mod + mod) % mod とする(負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INFの値は1152921504606846976

int dx[8] = {-1,-1,-1,0,0,1,1,1};
int dy[8] = {-1,0,1,-1,1,-1,0,1};

int main()
{
    int h,w; cin >> h >> w;
    char f[h][w];
    rep(i,h) rep(j,w) cin >> f[i][j];
    rep(i,h){
        rep(j,w){
            if(f[i][j] == '#') cout << '#';
            else{
                int cnt = 0;
                rep(k,8){
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if(nx >= 0 && nx < w && ny >= 0 && ny < h){
                        if(f[ny][nx] == '#') cnt++;
                    }
                }
                cout << cnt;
            }
        }
        cout << endl;
    }

}

Measured memory_bytes: 256
import copy

N,M = map(int,input().split())
t_dict = dict()
for _ in range(M):
    a,b = map(int,input().split())
    try:
        t_dict[a] += [b]
    except KeyError:
        t_dict[a] = [b]
        
    try:
        t_dict[b] += [a]
    except KeyError:
        t_dict[b] = [a]
        

origin = [1]
new_origin = []
for one in t_dict[1]:
    new_origin.append(origin+[one])

for _ in range(N-2):
    origin = copy.deepcopy(new_origin)
    new_origin = []
    for one in origin:
        for two in t_dict[one[-1]]:
            if two  in one :
                pass
            else:
                new_origin.append(one+[two])
                
print(len(new_origin))

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

int main(){
  int x;
  cin>>x;
  
  for(int i=-119;i<119;i++){
    for(int j=-119;j<119;j++){
      if(x==i*i*i*i*i-j*j*j*j*j){
        cout<<i<<endl;
        cout<<j<<endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define mii unordered_map<int,int>
#define mll unordered_map<ll,ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi  first

#define se second
#define pb push_back
#define mp make_pair
#define pp pop_back
#define vii vector<int>
#define vll vector<ll>
#define vpp vector<pii>
#define all(c) c.begin(),c.end()
#define tr(it,c) for(it = c.begin() ; it!=c.end() ; it++)
int inf = INT_MAX ;
ll modulo(ll num,ll MOD=mod){ return ((num%MOD)+MOD)%MOD;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),MOD-2,MOD); }
ll gcd(ll a,ll b){ return ((b==0) ? a:gcd(b,a%b));}

int main(){
	boost;
	string str,str2;
	cin>>str>>str2;
	int n = str.size();
	int m = str2.size();
	int ans[n+1][m+1][3];
	for(int i = n;i>=0;i--){
		for(int j = m;j>=0;j--){
			if(i==n||j==m){
				ans[i][j][0] = 0;
				ans[i][j][1] = -1;
				ans[i][j][2] = -1;
			}else{
				if(str[i]==str2[j]){
					ans[i][j][0] = ans[i+1][j+1][0] + 1;
					ans[i][j][1] = i;
					ans[i][j][2] = j;
				}else{
					if(ans[i+1][j][0]<ans[i][j+1][0]){
						ans[i][j][0] = ans[i][j+1][0];
						ans[i][j][1] = ans[i][j+1][1];
						ans[i][j][2] = ans[i][j+1][2];
					}else{
						ans[i][j][0] = ans[i+1][j][0];
						ans[i][j][1] = ans[i+1][j][1];
						ans[i][j][2] = ans[i+1][j][2];
					}
				}
			}
			//cout<<ans[i][j][0]<<" ";
		}
		//cout<<endl;
	}
	
	vector<char> c;
	int i = 0,j = 0;
	while(i>=0&&i<=n&&j>=0&&j<=m){
		if(ans[i][j][1]==i&&ans[i][j][2]==j){
			c.pb(str[i]);
			i = i+1;
			j = j+1;
		}else{
			int k = i;
			i = ans[i][j][1];
			j = ans[k][j][2];
		}
		//cout<<i<<" "<<j<<endl;
	}
	
	for(char ch:c)
		cout<<ch;
	return 0;
}

//Total solved problems:- 13



Measured memory_bytes: 105856
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];

	if (a[0] + a[1] + a[2] >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}

	return 0;
}

Measured memory_bytes: 3600
import java.util.*;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int n = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        long ans = 0;
        int start = 0;
        long max = 0;

        for(int i = 0;i < n;i++){
            int dis = sc.nextInt();
            list.add(dis);
        }

        if(list.contains(0)){
            max = k- list.get(n-1);
        }else{
            max = k - list.get(n-1) + list.get(0);
        }

        for(int i = 1;i < n;i++){
            long distance = list.get(i)-list.get(i-1);
            if(distance>max){
                start = i;
                max = distance;
            }
        }
        
        System.out.println(k-max);
    }
}

Measured memory_bytes: 76112
import java.io.*; 
class Main {
public static void main(String[] args){
try{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int i=0;
int x;
while((x=Integer.parseInt(br.readLine())) != 0){
i++;
System.out.println("Case " +i+ ": " + x);
}
br.close();
}catch (IOException e){
}
}
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = 0;
            int[] n = System.Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)).ToArray();
            string s;
            for(int i = n[0]; i <= n[1]; i++)
            {
                s = i.ToString();
                if (s[0] == s[4] && s[1] == s[3]) count++;
            }
            System.Console.WriteLine(count);
        }
    }
}

Measured memory_bytes: 13396
#import sys
#input = sys.stdin.readline
def eratosthenes(N):
    from collections import deque
    work = [True] * (N+1)
    work[0] = False
    work[1] = False
    ret = []
    for i in range(N+1):
        if work[i]:
            ret.append(i)
            for j in range(2* i, N+1, i):
                work[j] = False
    return ret
from itertools import accumulate
def main():
    ANS = [1]*100001
    ANS[0] = 0
    ANS[1] = 0
    Primes = eratosthenes(100000)
    for p in Primes:
        ANS[p] = 0
        if p**2 <= 100000:
            ANS[p**2] = 0
        if p**3 <= 100000:
            ANS[p**3] = 0
    for p in Primes:
        for q in Primes:
            if p*q <= 100000:
                ANS[p*q] = 0
            else:
                break
    accANS = list( accumulate(ANS))
    Q = int( input())
    for _ in range(Q):
        print( accANS[ int( input())])
if __name__ == '__main__':
    main()




Measured memory_bytes: 11028
#include<bits/stdc++.h>
using namespace std;
void fl()
{
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
int main()
{
	ios::sync_with_stdio(0);
//   fl();
	int n;
	cin>>n;
	string a,b;
	cin>>a;
	cin>>b;
	string ans="";
	for(int i=0;i<n;i++)
	{
		ans+=a[i];
		ans+=b[i];
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define  ll long long int
main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
 if((abs(b-a)<=d&&abs(c-b)<=d)||abs(c-a)<=d)
    cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

}


Measured memory_bytes: 3604
import sys

def main():
    children = input()

    num_children = len(children)
    ret = {i: 0 for i in range(num_children)}

    previous_L = -1
    loop_flag = True
    for i, child in enumerate(children):
        if loop_flag:
            if child == 'L':
                ret[i] = (i - previous_L + 1) // 2
                ret[i - 1] = (i - previous_L) // 2
                loop_flag = False
                previous_L = i
                        
        else:
            if child == 'L':
                if (i - previous_L) % 2:
                    ret[previous_L - 1] += 1
                else:
                    ret[previous_L] += 1
            else:
                loop_flag = True
                previous_L = i - 1

    ret = [str(value) for value in ret.values()]       
    ret = ' '.join(ret)
    print(ret)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 55144
import re


S = input()
T = S.replace("RL", "$$")
devided_S = re.findall("R+L+", S)
ans = [-1 if T[i] == "$" else 0 for i in range(len(S))]

more_than_0 = []
for block in devided_S:
    count = len(block)
    r = block.count("R")
    l = count - r
    
    if count % 2 == 0:
        for _ in range(2):
            more_than_0.append(count//2)
    else:
        count_r = count//2 + (r > l)
        count_l = count - count_r
        more_than_0.append(count_r)
        more_than_0.append(count_l)
        if max(r, l) % 2 == 0:
            more_than_0[-1], more_than_0[-2] = more_than_0[-2], more_than_0[-1]

more_than_0.reverse()
for n in ans:
    if n == -1:
        print(more_than_0.pop(), end=" ")
    else:
        print(n, end=" ")
print()


Measured memory_bytes: 92036
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
vector<int> edges[200005];

struct hk {
  ll ps = 0, s = 0, c = 0;
};
hk seg[524288];
hk merge (hk a, hk b) {
  a.ps += a.s * b.c + b.ps;
  a.s += b.s;
  a.c += b.c;
  return a;
}
hk query (int l, int r, int i, int ql, int qr) {
  if (r < ql || qr < l) return {0, 0, 0};
  else if (ql <= l && r <= qr) return seg[i];
  int m = (l + r) >> 1;
  return merge(query(l, m, i << 1, ql, qr), query(m + 1, r, i << 1 | 1, ql, qr));
}
void update (int l, int r, int i, int k, int v) {
  if (l == r) {
    seg[i].ps += v; seg[i].s += v;
    return;
  }
  int m = (l + r) >> 1;
  if (k <= m) update(l, m, i << 1, k, v);
  else update(m + 1, r, i << 1 | 1, k, v);
  seg[i] = merge(seg[i << 1], seg[i << 1 | 1]);
}
int main () {
  int n;
  scanf("%d", &n);
  FOR(i, 1, n) seg[i + 262143].c = 1;
  FOR(i, 1, n) update(1, 262144, 1, i, 1);
  FOR(i, 1, n - 1) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (u > v) swap(u, v);
    edges[u].pb(v);
    update(1, 262144, 1, v, -1);
  }

  ll ans = 0;
  FOR(i, 1, n) {
    ans += query(1, 262144, 1, i, n).ps;
    for (int v : edges[i]) {
      update(1, 262144, 1, v, 1);
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 24048
public class Main {

	public static void main(String[] args) {

		java.util.Scanner sc = new java.util.Scanner(System.in);

		int n = sc.nextInt();
		int[] p = new int[n];
		int sum = 1;
		
		p[0] = sc.nextInt();
		int min = p[0];

		for (int i = 1; i < n; i++) {
			p[i] = sc.nextInt();
			if(p[i] < min) {
				min = p[i];
				sum++;
			}
		}

		System.out.println(sum);

	}
}


Measured memory_bytes: 77040
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using P = pair<lint, lint>;

struct Graph {
    struct Edge { int from; int to; lint cost; };
    struct Node {
        Node() : par(-1), done(false), dist(INF) {}
        int index;
        int par;
        bool done;
        lint dist;
        vector<Edge> edge;
    };

    int n;
    vector<Node> nodes;
    vector<Edge> edges;
    const static lint INF = 1e18;

    Graph(int n) : n(n) {
        nodes.resize(n);
        for(int i=0; i<n; i++)  nodes[i].index = i;
    }

    void add_edge(int from, int to, lint cost) {
        nodes[from].edge.push_back(Edge{from, to, cost});
        edges.push_back(Edge{from, to, cost});
    }

    void bfs(int s) {
        for(auto& e : nodes) e.dist = INF, e.par = -1;
        queue<int> que;
        nodes[s].dist = 0;
        que.push(s);

        while(!que.empty()) {
            int index = que.front(); que.pop();
            for(auto& e : nodes[index].edge) {
                if(nodes[e.to].dist != INF)  continue;
                nodes[e.to].dist = nodes[index].dist + 1;
                nodes[e.to].par = index;
                que.push(e.to);
            }
        }
    }

    lint shortest_dist(int to) { return nodes[to].dist; }
};

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

    Graph g(n);
    for(int i=0; i<n-1; i++) {
        int a, b;
        cin >> a >> b;
        g.add_edge(a-1, b-1, 1);
        g.add_edge(b-1, a-1, 1);
    }

    g.bfs(0);
    pair<lint, lint> mx;
    for(int i=0; i<n; i++) {
        mx = max(mx, P(g.shortest_dist(i), i));
    }

    g.bfs(mx.second);
    lint diameter = -1e18;
    for(int i=0; i<n; i++) {
        diameter = max(diameter, g.shortest_dist(i));
    }

    // bool: first == winner
    static vector<bool> dp(n);
    dp[0] = true;
    dp[1] = false;
    for(int i=2; i<n; i++) {
        dp[i] = not(dp[i-1]&dp[i-2]);
    }
    cout << (dp[diameter] ? "First" : "Second") << endl;
}

Measured memory_bytes: 27496
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    long long int k;
    cin >> s >> k;
    if(k == 1)
    {
        cout << s[0];
    }
    else
    {
        long long int i = 0;
        while(s[i] == '1' && i < k - 1)
        {
            i++;
        }
        cout << s[i];
    }
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
l.sort()
ans = 0
for i in range(n):
  for j in range(i+1,n):
    for k in range(j+1,n):
      a = l[i]
      b = l[j]
      c = l[k]
      if a == b or b == c or c == a:
        continue
      if l[i] + l[j] > l[k]:
        ans += 1
print(ans)


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

signed main(void)
{
	int n, tmp, ans;
	cin >> n;
	set<int> s;

	rep(i, n)
	{
		int a;
		cin >> a;
		s.insert(a);
	}
	tmp = -1;
	ans = 0;
	for (auto value : s)
	{
		if (tmp != -1)
		 ans += value - tmp;
		tmp = value;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define lld long double
#define F first
#define S second
#define f(i,a,b) for(int i=a;i<=b;i++)
#define g(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mh make_heap
#define ph push_heap
#define pq priority_queue
#define bits(x) __builtin_popcountll(x)
#define op(x) cout<<"Case #"<<x<<": "
#define op1(x) cout<<"Scenario #"<<x<<": "
#define endl "\n"
using namespace std;
const ll mod = 1000000007;
const ll INF = LLONG_MAX;
const int N = 18;

vector<ll> v[200001];
bool vis[200001];
ll sz = 0;

void dfs(ll u)
{
	vis[u] = true;
	sz++;
	for (auto i : v[u])
	{
		if (vis[i]) continue;
		dfs(i);
	}
}

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

	for (int i = 0; i <= n; i++)
	{
		v[i].clear();
		vis[i] = false;
	}

	for (int i = 0; i < m; i++)
	{
		ll x, y;
		cin >> x >> y;
		v[x].pb(y);
		v[y].pb(x);
	}

	ll ans = 0;

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

		if (!vis[i])
		{
			dfs(i);
			ans = max(ans, sz);
		}
	}

	cout << ans << endl;





}


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




	int t = 1;
	//cin >> t;



	for (int i = 1; i <= t; i++)
	{
		solve(i);

	}
}

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

//c<dのとき、飛び越す必要はない。２匹ともゴールまでに岩が連続して二つ無ければいい。
//c>dのとき飛び越す必要がある　ふぬけのさきに岩が連続して二つ無いのを前提として、
//すぬけは、動く岩が一つある状態でゴールまで向かう。

int main() {
  bool flag1=true,flag2=true;
  ll n,a,b,c,d;
  cin >> n>> a >> b >> c >> d;
  string s;
  cin >> s;
    for(int i = a; i < c-1; i++)if(s[i]=='#'&&s[i+1]=='#')flag1=false;
    for(int i = b; i < d-1; i++)if(s[i]=='#'&&s[i+1]=='#')flag2=false;
  if(c<d){
    if(flag1&&flag2)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  else{
    if(flag1&&flag2){
      bool flag3=false;
      for(int i = b-1; i<=d-1;i++){
        if(s[i-1]=='.'&&s[i]=='.'&&s[i+1]=='.')flag3=true;
      }
      if(flag3)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
    else cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

int main() {
  uint32_t N = 0, K = 0;
  std::cin >> N >> K;
  std::vector<uint32_t> A(N);
  for (auto &&a : A) std::cin >> a;

  size_t min_len = -1, K_count = 0;
  std::vector<uint32_t> count(K + 1, 0);
  for (size_t start = 0, end = 0; start < N; start++) {
    while (end < N && K_count < K) {
      if (A[end] <= K && count[A[end]]++ == 0) K_count++;
      end++;
    }
    if (K_count < K) break;
    min_len = std::min(min_len, end - start);
    if (A[start] <= K && --count[A[start]] == 0) K_count--;
  }

  std::cout << (min_len > N ? 0 : min_len) << std::endl;

  return 0;
}


Measured memory_bytes: 3540
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 calc(
    cards: &Vec<i32>,
    memo: &mut Vec<Vec<Vec<i32>>>,
    turn: usize,
    enemy: usize,
    index: usize,
) -> i32 {
    let n = cards.len();
    assert!(index < n);
    if index == n - 1 {
        return (cards[n - 1] - cards[enemy]).abs();
    }
    if memo[turn][enemy][index] != -1 {
        return memo[turn][enemy][index];
    }
    let mut ret = calc(cards, memo, turn, enemy, index + 1);
    let nret = calc(cards, memo, turn ^ 1, index, index + 1);
    if turn == 0 {
        ret = std::cmp::max(ret, nret);
    } else {
        ret = std::cmp::min(ret, nret);
    }
    memo[turn][enemy][index] = ret;
    ret
}

fn main() {
    let n: usize = read();
    let z: i32 = read();
    let w: i32 = read();
    let mut cards = vec![0 as i32; n + 2];
    cards[0] = z;
    cards[1] = w;
    for i in 0..n {
        cards[i + 2] = read();
    }
    let n = n + 2;
    let mut memo = vec![vec![vec![-1; n]; n]; 2];
    let ans = calc(&cards, &mut memo, 0, 1, 2);
    println!("{}", ans);
}


Measured memory_bytes: 37244
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

signed main()
{
	int a, b;
	cin >> a >> b;
	if (a < b)
	{
		REP(i, b) cout << a;
		cout << endl;
	}
	else
	{
		REP(i, a) cout << b;
		cout << endl;
	}
}



Measured memory_bytes: 256
N,Q = map(int,input().split())
s = input()
t = [0]
ans = []
for i in range(N):
    if s[i:i+2] == "AC":
        t.append(t[i] + 1)
    else:
        t.append(t[i])
for i in range(Q):
    l,r = map(int,input().split())
    ans.append(t[r-1]-t[l-1])
for i in ans:
    print(i)

Measured memory_bytes: 10228
#include<iostream>
#include<vector>
#include<algorithm>
#include<limits.h>
#include<set>
#include<map>
#include<string.h>
#include<queue>
#include<math.h>
#include<stdio.h>
#include<unordered_set>
using namespace std;

int main(){
    int n;
    while(cin>>n,n){
        vector<int>a;
        for(int i=0;i<n;i++){
            int x;
            cin>>x;
            a.push_back(x);
        }
        sort(a.begin(),a.end());
        int mi=INT_MAX;
        for(int i=1;i<n;i++){
            if(a[i]-a[i-1]<mi){
                mi=a[i]-a[i-1];
            }
        }
        cout<<mi<<endl;
    }
    return 0;
}

Measured memory_bytes: 3136
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int m = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int count=0,buff1,buff2;

		for(int i=4;i<=m;i++) {
			for(int j=1;j<=d;j++) {
				buff1 = j%10;
				buff2 = j/10;
				//System.out.println(buff1 +" "+buff2);
				if(buff1!=1 && buff2!=1) {
					if(i == buff1*buff2) {
						count++;
					}
				}

			}
		}
		System.out.println(count);


	}

}


Measured memory_bytes: 23124
#include<stdio.h>
#include<math.h>
int main(void)
{
	int d, w, h,n,r;
	double a;

	while (1) {
		scanf("%d %d %d",&d,&w,&h);
		if (d == 0 && w == 0 && h == 0)break;
		scanf("%d",&n);
		while (n--) {
			a = 0;
			scanf("%d",&r);
			if (r * 2 <= w)
				printf("NA\n");
			else {
				a = r*r - (w / 2)*(w / 2);
				a = sqrt(a);
				a = a * 2;
				if (a <= h)
					printf("NA\n");
				else
					printf("OK\n");
			}
		}
	}
	return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<char> c(2 * n);
    vector<int> a(2 * n);
    vector<int> b(n), w(n);
    for (int i = 0; i < 2 * n; i++) {
        cin >> c[i] >> a[i];
        if (c[i] == 'B') b[a[i] - 1] = i;
        else w[a[i] - 1] = i;
    }

    vector<int> memo1(2 * n, 0);
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < i; j++) {
            if (c[i] != c[j]) continue;
            memo1[i] += (a[i] < a[j]);
        }
    }

    vector< vector<int> > memo2(2 * n, vector<int>(n + 1, 0));
    for (int i = 0; i < 2 * n; i++) {
        for (int j = 0; j < i; j++) {
            if (c[i] == c[j]) continue;
            memo2[i][0]++;
            memo2[i][a[j]]--;
        }

        for (int j = 0; j < n; j++) {
            memo2[i][j + 1] += memo2[i][j];
        }
    }

    vector< vector<ll> > dp(n + 1, vector<ll>(n + 1, 1000000000000LL));
    dp[0][0] = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (i < n) dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + memo1[w[i]] + memo2[w[i]][j]);
            if (j < n) dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + memo1[b[j]] + memo2[b[j]][i]);
        }
    }

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

Measured memory_bytes: 63104
#exec({'RUBY_THREAD_VM_STACK_SIZE'=>'100000000'},'/usr/bin/ruby', $0) if !ENV['RUBY_THREAD_VM_STACK_SIZE']
require 'prime'

def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def sum(a) a.inject(:+) end

def big(a,b) return (a>b)? a:b end

def small(a,b) return (a<b)? a:b end
n = inp[0]
a = inp.sort
ans = 1
a.each do |d|
  ans *= d
  if(ans > 10**18)
    p -1
    exit
  end
end
p ans


Measured memory_bytes: 25548
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s>>t;
  int m=s.size(),n=t.size();
  int dp[m+1][n+1],mat[m+1][n+1];
  memset(dp,0,sizeof(dp));
  memset(mat,0,sizeof(mat));
  for(int i=1;i<=m;++i)
  {
    for(int j=1;j<=n;++j)
    {
      if(s[i-1] == t[j-1])
      {
         dp[i][j]=dp[i-1][j-1]+1;
      }
     
      else
      {
        dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
      }
      
    }
  }
  string ans="";
  int i=m,j=n;
  while(i+j)
  if(dp[i][j] == dp[i][j-1])
  {
    
    j--;
  }
  else if(dp[i-1][j] == dp[i][j])
  {
    i--;
  }
  else
  {
      ans+=s[i-1];
    i--;
    j--;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans;
}


Measured memory_bytes: 70656