akhauriyash/Code-Regression huggingface dataset:
S=input()
S=str(S)
list=['01','02','03','04','05','06','07','08','09','10','11','12']
if (S[0:2] in list) and (S[2:4] in list):
  print('AMBIGUOUS')
elif ((S[0:2] in list)==False) and ((S[2:4] in list)==True):
  print('YYMM')
elif ((S[0:2] in list)==True) and ((S[2:4] in list)==False):
  print('MMYY')
else:
  print('NA')

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		
		if(N/100 == N%10) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
	}

}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		int h = sc.nextInt();
		int w = sc.nextInt();

		int index = 0;
		int[][] a = new int[h][w];
		for(int i = 0; i < h; i++) {
			String str = sc.next();
			boolean Wcut = true;
			for(int j = 0; j < w; j++) {
				if(str.charAt(j) == '.') {
					a[index][j] = 0;
				} else {
					a[index][j] = 1;
					Wcut = false;
				}
			}
			if(!Wcut) {
				index++;
			}
		}
		
		for(int i = 0; i < w; i++) {
			boolean Hcut = true;
			for(int j = 0; j < index; j++) {
				if(a[j][i] == 1) {
					Hcut = false;
					break;
				}
			}
			if(Hcut) a[0][i] = -1;
		}

		for(int i = 0; i < index; i++) {
			for(int j = 0; j < w; j++) {
				if(a[0][j] == -1) continue;
				if(a[i][j] == 0) {
					System.out.print(".");
				} else {
					System.out.print("#");
				}
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 26576
def cost(i, y):
    if i == 1:
        return 5 * y
    else:
        return (2*i+1) * y


n, x = [int(_) for _ in input().split()]
xl = [int(_) for _ in input().split()]
xl.reverse()
sl = [0] * (n+1)
for i in range(n):
    sl[i+1] = sl[i] + xl[i]
answer = float('inf')
for k in range(1, n+1):
    sum = (n+k)*x
    c = n//k
    for i in range(c):
        sum += cost(i+1, (sl[k*(i+1)]-sl[k*i]))
    sum += cost(c+1, sl[n]-sl[k*c])
    if sum < answer:
        answer = sum
print(answer)

Measured memory_bytes: 26376
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
typedef long long ll;
using namespace std;
#define mod 1000000007
 
int main(){
    string s;cin >> s;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            if(s[i]!=s[0])cnt++;
        }
        else{
            if(s[i]==s[0])cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
   
}

Measured memory_bytes: 512
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define df 0
int dc=100000;
#define MAX 100010
int adj[10][10]={};
int s[10]={};
int unused[10]={};
int n;
int next();
int path();
int main(){
  if(df)printf("*** debug mode ***\n");
  int m,i,j;
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++){
    int a,b;
    scanf("%d%d",&a,&b);
    adj[a-1][b-1]++;
    adj[b-1][a-1]++;
  }
  for(i=0;i<n;i++){
    s[i]=i;
  }
  int flag=1,count=0;
  while(flag){
    if(df){
      for(i=0;i<n;i++){
	printf("%d ",s[i]);
      }
      printf("\n");
    }
    if(s[0]!=0)break;
    if(path())count++;
    next();
  }

  printf("%d",count);
  return 0;
}

int next(){
  int prev=s[n-1],i=n-2;
  unused[prev]=1;
  while(prev<s[i]){
    prev=s[i];
    unused[prev]=1;
    i--;
  }
  prev=s[i];
  unused[prev]=1;
  prev++;
  while(unused[prev]==0)prev++;
  s[i++]=prev;
  unused[prev]=0;
  for(prev=0;prev<n;prev++){
    if(unused[prev])s[i++]=prev;
    unused[prev]=0;
  }
}

int path(){
  int   flag=1,i;
  for(i=0;i<n-1;i++){
    if(adj[s[i]][s[i+1]]==0)flag=0;
  }
  return flag;
}


/// confirm df==0 ///


Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class C {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            int q = Integer.parseInt(in.next());
            int a[] = new int[n];
            for (int i = 0; i < q; i++) {
                int num = Integer.parseInt(in.next());
                a[num - 1]++;
            }
            // 出力
            for (int i = 0; i < n; i++) {
                if (q - a[i] < k) out.println("Yes");
                else out.println("No");
            }


        }

    }
}



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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


 
signed main() {
    int N;
    cin>>N;
    vector<int> a(N+1,0);
    for(int i=1; i<=N;i++) cin >> a[i];
    
    int ans=0;
    for(int i=1;i<=N; i++){
        if(a[a[i]]==i) ans++;
    }
    cout << ans/2 << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

int v=0;
map<string,int> nameToVertex;

bool cGraph[202][202];
bool eGraph[202][202];
bool visited[202];

int N,M;

string buf;

void buildE(){
    for(int i=0;i<v;i++){
        for(int j=i+1;j<v;j++){
            bool comm=false,order=false;
            for(int k=0;k<v;k++){
                if (i==k||j==k) continue;
                comm |= (cGraph[i][k]||cGraph[k][i])&&(cGraph[j][k]||cGraph[k][j]);
                order |= (cGraph[i][k]&&cGraph[k][j])||(cGraph[j][k]&&cGraph[k][i]);
            }
            if (comm&&!order) eGraph[i][j]=eGraph[j][i]=true;
        }
    }
}

bool DFS1(int cur,int target,bool d){
    if (cur==target) return d;
    visited[cur]=true;
    for(int i=0;i<v;i++){
        if (visited[i]) continue;
        if ((cGraph[cur][i]||cGraph[i][cur])&&DFS1(i,target,!d)) return true;
    }
    return false;
}

bool DFS2(int cur,int target){
    if (cur==target) return true;
    visited[cur]=true;
    for(int i=0;i<v;i++){
        if (visited[i]) continue;
        if ((cGraph[cur][i]||eGraph[cur][i])&&DFS2(i,target)) return true;
    }
    return false;
}


int main(){

    while(true){
        cin>>N;
        if (!N) break;

        for(int i=0;i<v;i++) 
            for(int j=0;j<v;j++)
                cGraph[i][j]=false,eGraph[i][j]=false;
        
        nameToVertex.clear();
        v=0;

        for(int k=0;k<N;k++) {
            cin>>buf;
            int i=0;
            while(buf[i]!='-') i++;
            auto fst=buf.substr(0,i);
            auto snd=buf.substr(i+1);

            if(!nameToVertex.count(fst)) 
                nameToVertex[fst]=v++;
            

            if(!nameToVertex.count(snd)) 
                nameToVertex[snd]=v++;
            

            auto fstNum=nameToVertex[fst],sndNum=nameToVertex[snd];
            cGraph[fstNum][sndNum]=true;
        }

        buildE();

        cin>>M;
        cout<<v<<endl;

        for(int k=0;k<M;k++) {
            cin>>buf;
            int i=0;
            while(buf[i]!='-') i++;
            auto fst=buf.substr(0,i);
            auto snd=buf.substr(i+1);

            if (!nameToVertex.count(fst)||!nameToVertex.count(snd)){
                puts("NO");
                continue;
            }

            auto fstNum=nameToVertex[fst],sndNum=nameToVertex[snd];
            
            for(int i=0;i<v;i++) visited[i]=false;
            if (!DFS1(fstNum,sndNum,false)){
                puts("NO");
                continue;
            }

            for(int i=0;i<v;i++) visited[i]=false;

            if (DFS2(fstNum,sndNum)) puts("YES");
            else puts("NO");
            
        }

    }

    return 0;
}


Measured memory_bytes: 3144
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if (a==1&&b==1)cout<<"Draw\n";
	else if (a==1)cout<<"Alice\n";
	else if (b==1)cout<<"Bob\n";
	else if (a>b)cout<<"Alice\n";
	else if (b>a)cout<<"Bob\n";
	else if (a==b)cout<<"Draw\n";
}

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

using namespace std;

int main() {
   int n;
   cin >> n;
   vector<int> a(n+1), b(n);
   for (int i=0; i<n+1; i++) cin >> a[i];
   for (int i=0; i<n; i++) cin >> b[i];

   long long ans = 0;

   for (int i=0; i<n; i++) {
       ans += min(b[i], a[i]);
       b[i] = max(b[i]-a[i], 0);
       ans += min(b[i], a[i+1]);
       a[i+1] = max(a[i+1]-b[i], 0);
   }

   cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define F first
#define S second
#define all(a) a.begin(),a.end()
#define setDP(arr) memset(arr,-1,sizeof arr)
#define Clear(arr) memset(arr,0,sizeof arr)
#define oo 2000000000
#define inf 1000000000000000000
#define P1 31
#define P2 37
#define M  1000000007
#define M2 1000000009
#define pii pair<ll,ll>
typedef long long ll;
using namespace std;
const int N = 355001;
const int SQRTN = 320;
const int LOGN = 20;
const long double PI = acos(-1);
const long double TAU = 2*PI;
ll n , a[4];

signed main(){
    cin >> a[0] >> a[1] >> a[2] >> a[3] >> n;
    if(a[0]<<1 < a[1])a[1]=a[0]<<1;
    if(a[1]<<1 < a[2])a[2]=a[1]<<1;
    if(a[2]<<1 < a[3])a[3]=a[2]<<1;
    ll ans = 0 ;
    ans = (n>>1)*a[3];
    n%=2;
    ans+=n*a[2];
    cout << ans << endl;




}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int s;
  int f,b;
  cin >> s;
  f = s / 100;
  b = s % 100;
  bool mf,mb;
  if(0 < f  && f < 13)mf = true;
  else mf = false;
  if(0 < b  && b < 13)mb = true;
  else mb = false;
  if(mf == true && mb == true)cout << "AMBIGUOUS" << endl;
  else if(mf == true && mb == false)cout << "MMYY" << endl;
  else if(mf == false && mb == true)cout << "YYMM" << endl;
  else cout << "NA" << endl;
}

Measured memory_bytes: 256
#import<complex>
#import<cstdio>
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){int n;float d,e,f,g,h,i;for(scanf("%d",&n);n--;){scanf("%f%f%f%f%f%f",&d,&g,&e,&h,&f,&i);std::complex<float>a(d,g),b(e,h),c(f,i);float A=abs(b-c),B=abs(c-a),C=abs(a-b),L=F(A,B,C),s=sin(2*L),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(L)/2);}}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int n;
    int maxnum = 0;
    cin >> n;
    map<string, int> count;
    vector<string> s(n);
    for (int i = 0; i < n; i++) {
        cin >> s.at(i);
    }
    sort(s.begin(), s.end());
    for (int i = 0; i < n - 1; i++) {
        if (s.at(i) == s.at(i + 1)) {
            count[s.at(i)]++;
        }
    }
    for (auto i : count) {
        maxnum = max(maxnum, i.second);
    }
    vector<string> ans;
    for (auto j : count) {
        if (j.second == maxnum) {
            ans.push_back(j.first);
        }
    }
    sort(ans.begin(), ans.end());
    for (int i = 0; i < ans.size(); i++) {
        cout << ans.at(i) << endl;
    }
    if (count.size() == 0) {
        for (int i = 0; i < n; i++) {
            cout << s.at(i) << endl;
        }
    }
}


Measured memory_bytes: 17404
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL A, B, C;
	in >> A >> B >> C;
	out << A + B + C - std::max({ A,B,C }) << std::endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main{
    public static void main (String args[]) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = br.readLine();
			
			if (line.length() <= 20 && line.length() > 0) {
				char[] str = line.toCharArray();
				for (int i = str.length-1; i >= 0; i--) {
					System.out.print(str[i]);
				}
			}else{
				System.exit(0);
			}
			System.out.println("");
			System.exit(0);
		}
		catch (IOException e) {
			e.printStackTrace();
		}	
    }
}

Measured memory_bytes: 18872
N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j
def num(m):
    return len(list(filter(lambda x: x >= m-1, e)))

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1)+ num(5) * (num(5) - 1) * (num(3) - 2) // 2)

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

using namespace std;


int H, W, D, Q;

int main() {

    cin >> H >> W >> D;
    vector<pair<int, int> > nums(90001);
    int A;
    for (int i = 0; i < H; i++) { 
        for (int j = 0; j < W; j++) {
            cin >> A;
            nums[A] = make_pair(i+1, j+1);
        }
    }
    vector<int> a(H*W+1, 0);
    for (int i = D+1; i <= D+D; i++) {
        for (int j = i; j < H*W+1; j+=D) {
            a[j] = abs(nums[j].first - nums[j-D].first) + abs(nums[j].second - nums[j-D].second);
        }
    }
/*h
    for (int i = 0; i < H * W + 1; i++) {
        cout << i << ' ' << a[i] << '\n';
    }
*/
    vector<int> s( H * W + 1, 0);

    for (int i = D+1; i <= D+D; i++) {
        for (int j = i; j < H*W+1; j+=D) {
            s[j] = a[j] + s[j-D];
        }
    }


/*
    for (int i = 0; i < H * W + 1; i++) {
        cout << s[i] << '\n';
    }
*/

    cin >> Q;
    int l, r;
    for (int i = 0; i < Q; i++) {
        cin >> l >> r;
        cout << s[r] - s[l] << '\n';

    }



}


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

int main() {
  int N, K, x, S = 0;
  cin >> N >> K;
  
  for (int i = 0; i < N; i++) {
    cin >> x;
    if (x < K - x) {
      S += 2 * x;
    }
    else {
      S += 2 * (K - x);
    }
  }
  cout << S << endl;
}


Measured memory_bytes: 3592
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e10
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextFloat() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func intSlicePrint(el interface{}) {
	fmt.Println(strings.Trim(fmt.Sprint(el), "[]"))
}

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 abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	s := make(map[int]int, n)
	sum := 0
	for i := 0; i < n; i++ {
		t := nextInt()
		sum += t
		s[t]++
	}

	q := nextInt()
	for i := 0; i < q; i++ {
		before, after := nextInt(), nextInt()
		diff := after - before
		sum += diff * s[before]

		s[after] += s[before]
		s[before] = 0

		fmt.Println(sum)
	}
}



Measured memory_bytes: 6260
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define MOD 1000000007
using namespace std;


int main(int argc, char* argv[])
{
    long n, k;
    scanf("%ld%ld", &n, &k);

    long x[100]={0};
    long y[100]={0};
    set<long> sx;
    set<long> sy;
    ll aa[100][100]={0};

    long i,j;
    for(i=0; i<n; i++) {
        scanf("%ld%ld", &x[i], &y[i]);
        sx.insert(x[i]);
        sy.insert(y[i]);
    }

    vector<long> vx;
    copy( sx.begin(), sx.end(), back_inserter(vx));
    vector<long> vy;
    copy( sy.begin(), sy.end(), back_inserter(vy)); 

    for(i=0; i<n; i++) {
        auto itx = find( vx.begin(), vx.end(), x[i] );
        auto ity = find( vy.begin(), vy.end(), y[i] );
        aa[itx - vx.begin()+1][ity - vy.begin()+1]++;
    }

    long szx=(long)vx.size();
    long szy=(long)vy.size();
    for(i=0; i<=szx+1; i++) {
        for(j=0; j<=szy+1; j++) {
            aa[i][j+1] += aa[i][j];
        }
    }
    for(i=0; i<=szx; i++) {
        for(j=0; j<=szy+1; j++) {
            aa[i+1][j] += aa[i][j];
        }
    }

    ll min = 9000000000000000000;
    for(long x0=0; x0<szx; x0++) {
        for(long x1=x0; x1<szx; x1++) {
            for(long y0=0; y0<szy; y0++) {
                for(long y1=y0; y1<szy; y1++) {
                    ll count = aa[x1+1][y1+1]-aa[x1+1][y0]-aa[x0][y1+1]+aa[x0][y0];
                    if(count >= k) {
                        ll area = ((ll)vx[x1]-vx[x0])*((ll)vy[y1]-vy[y0]);
                        min = MIN(min, area);
                    }
                }
            }
        }
    }

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


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

long long GCD (long long a, long long b)
{
    /*long long t;
    if (a>b) swap(a,b);
    while (1)
    {
        t=b%a;
        if (t==0) break;
        b=a;
        a=t;
    }
    return a;*/
    if (a%b==0) return b;
    else if (b%a==0) return a;
    else if (a>b) return GCD(a%b,b);
    else return GCD(b%a,a);
}

int main()
{
    long long a,b,gcd[50],lcm[50],c=0;
    while (cin>>a>>b)
    {
        gcd[c]=GCD(a,b);
        lcm[c]=a*b/gcd[c];
        c++;
    }
    for (int i=0; i<c; i++) cout<<gcd[i]<<" "<<lcm[i]<<'\n';
    return 0;
}




Measured memory_bytes: 3100
N, M, X = map(int, input().split())  # N冊の参考書, M個のアルゴリズム, X以上にしたい
books = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for mask in range(1 << N):  # 2のd乗になる
    binary = []
    for i in range(N):
        binary.append((mask >> i) & 1)
    # bitが立っている参考書だけを購入する
    tmp_cost = 0
    now_understand = [0]*M
    for i in range(N):
        if binary[i] == 1:
            c, *A = books[i]
            tmp_cost += c
            for j in range(len(A)):
                now_understand[j] += A[j]

    flag = True
    for i in range(M):
        if now_understand[i] < X:
            flag = False

    if flag:
        ans = min(ans, tmp_cost)

if ans == float("inf"):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 74568
#include <bits/stdc++.h>
#define MAXN 10010
#define pii pair<int, int>
#define pb push_back
typedef long long ll;

using namespace std;

int a[MAXN], n, d, mod = 1e9 + 7;
ll dp[MAXN][2][110];

ll go(int x, bool b, int m){	//using digits x-(n-1), how many ways to sum to m
	if(dp[x][b][m] != -1) return dp[x][b][m];
	if(x == n) return m == 0;
	ll t = 0;
	if(b){
		for(int i = 0; i < a[x]; i++){
			t += go(x + 1, 0, (d + m - i) % d);
		}
		t += go(x + 1, 1, (d + m - a[x]) % d);
	} else{
		for(int i = 0; i <= 9; i++){
			t += go(x + 1, b, (d + m - i) % d);
		}
	}
	return dp[x][b][m] = t % mod;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	string s;
	cin >> s;
	n = s.size();
	memset(dp, -1, sizeof(dp));
	for(int i = 0; i < n; i++){
		a[i] = s[i] - '0';
	}
    cin >> d;
    cout << (go(0, 1, 0) - 1 + mod) % mod;
}

Measured memory_bytes: 18304
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<numeric>
#include<stack>
#include<map>
#include<queue>
#include<unordered_map>
#include<cmath>
#include<utility>

#include<ctime>
#include<random>

using ULL = unsigned long long;
using LL = long long;
using String = std::string;
using Ints = std::vector<int>;
using Doubles = std::vector<double>;
using Bools = std::vector<bool>;
using Strings = std::vector<std::string>;
using ULLs = std::vector<ULL>;
using LLs = std::vector<LL>;

// pythonのdictionary相当
template <typename T1, typename T2>
using Dict = std::unordered_map<T1,T2>;



int culc(Ints &r, std::vector<Ints> &s, Ints &c){
    int res = 0;
    Ints last(26, 0);

    for(int i=0;i<(int)r.size();i++){
        last[r[i]-1] = i+1;
        for(int j=0;j<26;j++){
            if(r[i]-1==j) res+=s[i][j];
            else res-=c[i]*(i+1-last[j]);
        }
    }

    return res;
}

int main(void) {
    int t = std::clock();

    int D;
    std::cin >> D;
    Ints c;
    std::vector<Ints> s(D, Ints(26, 0));

    for(int i=0;i<26;i++){
        int _c;
        std::cin >> _c;
        c.push_back(_c);
    }

    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++){
            int _s;
            std::cin >> _s;
            s[i][j] = _s;
        }
    }

    Ints res(D, 1);
    std::vector<Ints> ss = s;
    Ints cnt(D, 0);

    for(int i=0;i<D;i++){
        std::sort(ss[i].begin(), ss[i].end(), std::greater<int>());
        auto itr = std::find(s[i].begin(), s[i].end(), ss[i].front());
        size_t index = std::distance(s[i].begin(), itr);
        res[i] = (int)index + 1;
    }

    LL nowp = culc(res, s, c);

    std::random_device rnd;
    std::mt19937 mt(rnd());
    while(static_cast<int>((double)(std::clock() - t) / CLOCKS_PER_SEC * 1000.0) < 1960){
        int max_day = 0;
        int max_day_p = 0;
        int max_day_idx = 0;
        int max_day_con = 0;
        for(int i=0;i<D;i++){
            //std::cout << cnt[i] << "UUUU" << std::endl;
            //std::cout << static_cast<int>(mt() % 2 == 0 ? 1 : -1) * static_cast<int>(mt() % 2 + 1) << "JJJ" << std::endl;
            int contest = std::min(std::max(static_cast<int>(cnt[i] + (mt() % 2 == 0 ? 1 : -1) * (mt() % 2 + 1)), 0), 25);
            //std::cout << contest << "!!!" << nowp << std::endl;
            auto itr = std::find(s[i].begin(), s[i].end(), ss[i][contest]);
            int index = (int)std::distance(s[i].begin(), itr);

            Ints res_tmp = res;
            res_tmp[i] = index + 1;
            LL tmpp = culc(res_tmp, s, c);
            if(max_day_p < tmpp){
                max_day_p = tmpp;
                max_day = i;
                max_day_idx = contest;
                max_day_con = index;
            }
        }

        if(nowp < max_day_p){
            cnt[max_day] = max_day_idx;
            res[max_day] = max_day_con + 1;
            nowp = max_day_p;

            //std::cout << max_day_p << " " << max_day << " " << max_day_idx << " " << max_day_con << std::endl;
        }
    }

    for(auto r : res) std::cout << r << std::endl;

    return 0;
}

Measured memory_bytes: 3768
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define UNIQUE(v) { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); }
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) (q ? "Yes" : "No")
#define YES(q) (q ? "YES" : "NO")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) { cerr << "[DEBUG] " #q ": ["; REP(dumpall_i, (q).size()) { cerr << q[dumpall_i] << (dumpall_i == (q).size() - 1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; }
template<class T> T gcd(const T &a, const T &b) { return a < b ? gcd(b, a) : b ? gcd(b, a % b) : a; }
template<class T> T lcm(const T &a, const T &b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
using  ll = long long;
using ull = unsigned long long;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    ll n, m; cin >> n >> m;

    vector<vector<ll>> s(m);
    REP(i, m) {
        ll k; cin >> k;
        s[i].resize(k);
        REP(j, k) {
            cin >> s[i][j];
            s[i][j]--; // 0-indexed
        }
    }

    vector<ll> p(m);
    REP(i, m) cin >> p[i];


    ll ans = 0;
    REP(mask, 1LL << n) {
        vector<ll> sw = p;
        REP(i, m) {
            REP(j, s[i].size()) {
                if (mask & (1LL << s[i][j])) {
                    sw[i] ^= 1;
                }
            }
        }
        ans += all_of(ALL_OF(sw), [](ll &x) -> bool { return !x; });
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<limits>
#include<iomanip>
#include<cmath>
#include<climits>

using namespace std;

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

const int mod=1e9+7;

int main(){
    int n,k;
    string s;
    cin >> n >> s >> k;
    char c=s[k-1];
    for(int i=0;i<n;i++){
        cout << (s[i]==c?c:'*');
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import(
	"fmt"
	"strings"
)

func evaluateSquares(squares [][]string) int {
	h := len(squares)
	w := len(squares[0])
	cnt := 0
	for i:=0;i<h;i++ {
		for j:=0;j<w;j++ {
			if squares[i][j]=="#" {
				cnt++
			}
		}
	}
	return cnt
}

func deepCopy(dst,src [][]string)  {
	for i,v := range src {
		copy(dst[i], v)
	}
}

func main() {
	var h,w,k int
	fmt.Scan(&h, &w, &k)
	squares := make([][]string, h)
	sc := make([][]string,h)
	sc1 := make([][]string,h)
	for i:=0; i<h; i++ {
		var tmp string
		fmt.Scan(&tmp)
		squares[i] = strings.Split(tmp, "")
		sc[i] = make([]string, w)
		sc1[i] = make([]string, w)
	}
	cnt := 0
	for height:=0;height<(1<<uint64(h));height++ {
		// fmt.Println(squares)
		deepCopy(sc, squares)
		// bitsの各要素についてのループ
		for i:=0;i<h;i++ { 
			if (height>>uint64(i))&1 == 1 {
				for iw:=0; iw<w; iw++ {
					sc[i][iw] = "r"
				}
			}
		}
		for width:=0;width<(1<<uint64(w));width++ {
			deepCopy(sc1, sc)
			for i:=0;i<w;i++ {
				if (width>>uint64(i))&1 == 1 {
					for ih:=0;ih<h;ih++ {
						sc1[ih][i] = "r"
					}
				}
			}
			// fmt.Println(sc1)
			if evaluateSquares(sc1)==k {
				cnt++
			}
		}
		// fmt.Println(sc)
		
	}
	
	fmt.Println(cnt)
}

Measured memory_bytes: 1840
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

struct s{
  int a;
  int b;
  double c;
};

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  string s;

  cin >> s;

  REP(i,s.length()){
    cout << "x";
  }

  cout << endl;
  
  return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    int mi = 1e9;
    string s;
    cin >> s;
    for (int i = 0; i <= s.size() - 3; ++i) {
        int tmp = abs(753 - stoi(s.substr(i, 3)));
        mi = min(mi, tmp);
    }
    cout << mi << endl;
    return 0;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll K;
    cin >> K;
    ll count = 9, i = 0;
    vector<ll> v;
    for(int i = 1; i < 10; i++) v.push_back(i);
    while(true) {
        if(count >= K) break;
        int digits = 0, last = v[i] % 10;
        int tmp = v[i];
        while(tmp) {
            digits++;
            tmp /= 10;
        }
        if(last != 0) {
            v.push_back(v[i] * 10 + last - 1);
            count++;
        }
        v.push_back(v[i] * 10 + last);
        count++;
        if(last != 9) {
            v.push_back(v[i] * 10 + last + 1);
            count++;
        }
        i++;
    }
    // for(int i = 0; i < v.size(); i++) cout << i + 1 << ":" << v[i] << "\n";
    cout << v[K - 1];
    return 0;
}

Measured memory_bytes: 1400
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int n;
main()
{
	cin>>n;
	vector<int>A;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		A.push_back(x);
	}
	vector<int>B=A;
	sort(B.begin(),B.end());
	for(int i=0;i<n;i++)
	{
		A[i]=lower_bound(B.begin(),B.end(),A[i])-B.begin();
	}
	int ans=0;
	for(int i=0;i<n;i++)
	{
		ans+=i%2!=A[i]%2;
	}
	cout<<ans/2<<endl;
}

Measured memory_bytes: 1144
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int K,S;
  int i,j;
  int res=0;
  cin>>K>>S;
  for(i=0;i<=K;i++){
    for(j=i;j<=(i+K)&&j<=S;j++){
      if((S-j)<=K) res++;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL n,m,i,j;
string st,s;
int main()
{
	cin>>s;
	for(i=0;i<s.size();i++)
	{
		if(s[i]=='0')
		  st+='0';
		if(s[i]=='1')  
		  st+='1';
		if(s[i]=='B')
		  if(st.size()>0)
		    st.erase(st.size()-1,1);  
	}	
	cout<<st;
} 

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

main() {

  int n;
  cin >> n;

  vector<int> d(n);
  for( int i; i<n; i++) {
      cin >> d.at(i);
  }

  int s=0;

  for ( int i; i<n; i++) {
      s += d.at(i);

  }

  int ss=0;

  for (int i; i<n; i++) {
      ss += d.at(i)*d.at(i);
  }
  int ans;
  ans = s*s-ss;
  ans = ans/2;

  cout << ans << endl;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int,input().split())
h = (60 * H + M) * 0.5
m = (60 * H + M) * 6
cosC = math.cos(math.radians(h - m))
ans = (A ** 2 + B ** 2 - 2 * A * B * cosC) ** 0.5
print(ans)

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

int main() {
    int a = 0;
    int b = 1;
    int c = 0;
    int d = 0;
    cin >> a;
    int Q = a;
    int N ;
    N = to_string(a).length();
    for(int i = 1; i < N; i++){
        b = b * 10;
    }

    for(int i = 1; i < N+1; i++){
        c = a/b + c;
        a = a%b;
        b = b / 10;
    }

    if(Q % c == 0)
    cout << "Yes\n";
    else
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int a, b, c;
    cin >> a >> b >> c;

    //(a * x) % b == c;
    
    if(a % 2 == 0 && b % 2 == 0 && c % 2 == 1){
        cout << "NO" << endl;
        return 0;
    }
    int n = 100000000;
    REP(i, n){
        if((a * (i+1)) % b == c){
            cout << "YES" << endl;
            return 0;
        } 
    }

    cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <functional>

int main(){
  int R,G,B,N;
  scanf("%d %d %d %d\n",&R,&G,&B,&N);
  
  int maxR = N/R;
  int count = 0;
  for(int r=0;r<=maxR;r++){
    int maxG = (N-R*r)/G;
    for(int g=0;g<=maxG;g++){
      if((N-R*r-G*g)/B>=0 && !((N-R*r-G*g)%B)) count++;
    }
  }
  
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
constexpr int inf=1e9+7;
constexpr ll longinf=1LL<<60 ;
constexpr ll mod=1e9+7 ;
 
 
string res;
 
int counter;
 
int query(string& s){
    ++counter;
    cout<<"? "<<s<<endl;
    int ret;
    cin>>ret;
    return ret;
}
 
const int m = 62;
int cnt[62][200], n;
string ans, cha;
 
void solve(int l, int r){
    if(l+1==r){
        rep(i,m)if(cnt[i][r]!=cnt[i][l]){
            ans[l]=cha[i];
            return;
        }
    }
    int mid=(l+r)/2;
    int sum = 0, num = 0;
    vector<int> c(m);
    int j = -1;
    vector<int> rem;
    REP(i,0,m){
        if(cnt[i][l]==cnt[i][r]){
            cnt[i][mid]=cnt[i][l];
            sum -= cnt[i][l];
            j=i;
        }
        else rem.push_back(i);
    }
    if(j == -1){
        for(auto i : rem){
            if(i == 0)continue;
            string s(n, 'a');
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[0][n];
            sum += c[i];
            num++;
        }
        assert((mid+sum)%(num+1)==0);
        int ret = (mid + sum)/(num + 1);
        cnt[0][mid]=cnt[0][0]+ret;
        REP(i,1,m){
            if(cnt[i][l]==cnt[i][r]){
                continue;
            }
            cnt[i][mid]=cnt[i][0]-c[i]+ret;
        }
    }
    else {
        sum += cnt[j][l];
        for(auto i : rem){
            if(i == rem.back()){
                c[i] = (rem.size()+1)*cnt[j][mid] - sum - mid;
                continue;
            }
            string s(n, cha[j]);
            REP(k,0,mid)s[k]=cha[i];
            c[i] = query(s) - n + cnt[j][n];
            sum += c[i];
        }
        for(auto i : rem){
            cnt[i][mid]=cnt[i][0]-c[i]+cnt[j][mid];
        }
    }
    solve(l,mid);
    solve(mid,r);
}
 
int main(){
    rep(i,26)cha += 'a'+i;
    rep(i,26)cha += 'A'+i;
    rep(i,10)cha += '0'+i;
    vector<int> c(m); 
    rep(i,m){
        string s(128,cha[i]);
        c[i]=query(s);
        n += 128 - c[i];
    }
    rep(i,m)cnt[i][n]=128-c[i];
    ans.resize(n, '-');
    solve(0,n);
    if(counter>761){
        cout<<3<<endl;
    }
    cout<<"! "<<ans<<endl;
}

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

ll INF = 1e18;
ll MOD = 1e9+7;

ll N;
vector<ll> t9, t6;

ll ans = 1e9;

int rec(ll x, ll cnt){
    //cout << x << endl;
    if(x >= 9){
        for(int i = 2; i < 20; i++){
            if(x < t9[i]){
                rec(x - t9[i-1], cnt+1);
                break;
            }
        }
    }
    if(x >= 6){
        for(int i = 2; i < 20; i++){
            if(x < t6[i]){
                rec(x - t6[i-1], cnt+1);
                break;
            }
        }
    }
    ans = min(cnt + x, ans);
    return 0;

}


int main(){
    cin >> N;
    t9.resize(20);
    t6.resize(20);

    for(int i = 0; i < 20; i++){
        t6[i] = pow(6, i);
        if(t6[i] > 100000) break;
    }

    for(int i = 0; i < 20; i++){
        t9[i] = pow(9, i);
        if(t9[i] > 100000) break;
    }

    rec(N, 0);
    cout << ans << endl;





}

Measured memory_bytes: 384
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int x,i;
  vector<int>w,k;
  for(i=0;i<10;i++)scanf("%d",&x),w.push_back(x);
  for(i=0;i<10;i++)scanf("%d",&x),k.push_back(x);
  sort(w.begin(),w.end());
  sort(k.begin(),k.end());
  printf("%d %d\n",w[7]+w[8]+w[9],k[7]+k[8]+k[9]);
}

Measured memory_bytes: 0
// type a
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using ll = long long;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000
#define mod = (int)1000000007;
#pragma endregion

int n;
vector<int> d;
void input() {
	cin >> n;
	d.resize(n);
	for (int i = 0; i < n; i++) 
		cin >> d[i];
	sort(d.begin(), d.end());
	return;
}
int solve() {
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n - 1; j ++) {
			//1,2を決めた
			//にぶたんで、3の範囲を決める
			int s = lower_bound(d.begin(), d.end(), d[i] + d[j]) - d.begin();
			int t = upper_bound(d.begin(), d.end(), max(d[i] - d[j], d[j] - d[i])) - d.begin();
			if (t <= j)
				t = j + 1;//被り防ぐ
			ans += max(0, s - t);
		}
	}
	return ans;
}

int main(void) {
	input();
	printf("%d\n", solve());

	return 0;
}

Measured memory_bytes: 3732
from fractions import gcd
from datetime import date
from math import factorial
import functools
from heapq import*
from collections import deque
import collections
import math
from collections import defaultdict, Counter
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
inf = float("inf")


def main():
    s = list(input())
    n = len(s)
    l, r = 0, n-1

    ans = 0
    while l < n and r >= 0 and l < r:
        if s[l] == "x" or s[r] == "x":
            if s[l] == "x" and s[r] == "x":
                l += 1
                r -= 1
            elif s[l] == "x":
                l += 1
                ans += 1
            elif s[r] == "x":
                r -= 1
                ans += 1
        elif s[l] == s[r]:
            l += 1
            r -= 1
        else:
            print(-1)
            exit()
    print(ans)


if __name__ == '__main__':
    main()


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

int equ(string&, int&);
int form(string&, int&);
int q(string&, int&);

int equ(string&s, int&i) {
	int v1 = form(s, i); i++;
	int v2 = form(s, i);
	return v1 == v2;
}
int form(string&s, int&i) {
	int v = q(s, i);
	while (s[i] == '>' || s[i] == '*' || s[i] == '+') {
		char op = s[i++];
		int v2 = q(s, i);
		if (op == '>')v = (!v || v2);
		if (op == '*')v = (v&&v2);
		if (op == '+')v = (v || v2);
	}
	return v;
}
int q(string&s, int&i) {
	if (s[i] == 'T' || s[i] == 'F')return s[i++] == 'T';
	if (s[i] == '-') {
		i++; return !q(s, i);
	}
	i++; int ret = form(s, i); i++;
	return ret;
}
int main() {
	string buf;
	while (cin >> buf, buf != "#") {
		string s;
		rep(i, buf.size()) {
			if (buf[i] == '-'&&buf[i + 1] == '>')s += '>', i++;
			else s += buf[i];
		}
		map<char, char>mp;
		for (char c : s) {
			if (islower(c))mp[c];
		}
		rep(i, 1 << mp.size()) {
			string t = s;
			int j = 0;
			for (auto&p : mp)p.second = ((i >> (j++) & 1) ? 'T' : 'F');
			for (char&c : t) {
				if (islower(c))c = mp[c];
			}
			j = 0;
			if (!equ(t, j)) { puts("NO"); goto g; }
		}
		puts("YES");
	g:;
	}
}

Measured memory_bytes: 3124
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int area = a * b;
		int length = 2 * (a + b);
		System.out.println(area + " " + length);
	}
}



Measured memory_bytes: 26020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#include<iomanip>
#include <cassert>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define Cout(x) cout << x << endl;
#define check(v) rep(i,v.size()) cout << v[i] << endl;
#define vint(x) vector<int> x
#define vll(x) vector<long long> x
#define vstr(x) vector<string> x
const long long LLINF = 1LL<<60;
const int INF = 1e9;
const long long MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
#define pint pair<int,int>
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    map<pint,int> m;
    REP(i,1,n+1) {
        string s = to_string(i);
        int fr = s[0]-'0', ba = s[s.size()-1]-'0';
        m[{fr,ba}]++;
    }
    int ans = 0;
    REP(i,1,10) {
        REP(j,1,10) {
            ans += m[{i,j}] * m[{j,i}];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#Coding:Utf-8

N=int(input())
p=list(map(int,input().split()))
Asc=sorted(p)
check=0
for i in range(N):
    if Asc[i]==p[i]:
        pass
    else:
        check+=1
    if check>2:
        print('NO')
        exit()
print('YES')


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

       public static void main(String[] args) throws IOException {
        // TODO 自動生成されたメソッド・スタブ
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while(true){
            String[] input = br.readLine().split(" ");
            if(input[0].equals("-1") && input[1].equals("-1") && input[2].equals("-1")){
                break;
            }
            if(input[0].equals("-1") || input[1].equals("-1")){
                System.out.println("F");
                continue;
            }
            int score = Integer.parseInt(input[0]) + Integer.parseInt(input[1]);

            if(score<30){
                System.out.println("F");
            }else if(score >= 80){
                System.out.println("A");
            }else if(score < 50){
                if(Integer.parseInt(input[2])>= 50){
                    System.out.println("C");
                }else{
                    System.out.println("D");
                }
            }else if(score<65){
                System.out.println("C");

            }else{
                System.out.println("B");
            }


        }
    }

}


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

using namespace std;

typedef long long ll; 
typedef long double ld;

const __int128_t M = (int64_t)1e18+1;

int main() {
	
	// make input and output more efficient
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	
	
	// to read whole line
	//string s;
	//getline(cin, s);
	
	int N;
	
	cin >> N;
	
	__int128_t answer = 1;
	
	while(N--) {
		int64_t a;
		cin >> a;
		answer = min(answer*a, M);
	}
	
	if(answer != M)
		printf("%ld", answer);
	else
		cout << -1 << "\n";
		
	return 0;
}

Measured memory_bytes: 3780
#include <iostream>

using namespace std;

int main()
{
   int A, B, C, D,i,a,b,c,d;
   
   cin >> A >> B >> C >> D;
   a = A;
   b = B;
   c = C;
   d = D;
   int flag;
   for (i=0;;i++){
       c = c - b;
       //cout << c << endl;
       if(c<=0){
           flag = 1;
           break;
       }
       a = a - d;
       //cout << a << endl;
       if(a<=0){
           flag = 0;
           break;
       }
   }
   if(flag==1) cout << "Yes";
   else cout << "No";
   
   return 0;
}

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

using namespace std;

long long n, k, a[200005], f[200005], gret, ans;
const long long zero = 0;

long long bs(long long l, long long r) {
	if (l == r) return l;
	long long mid = (l + r)/2;
	long long cum = k;
	for (int i=0; i<n; i++) cum -= max(a[i] - mid/f[n - 1 - i], zero);
	if (cum < 0) return bs(mid + 1, r);
	else return bs(l, mid);
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> k;
	for (int i=0; i<n; i++) cin >> a[i];
	for (int i=0; i<n; i++) cin >> f[i];
	sort(a, a + n);
	sort(f, f + n);
	for (int i=0; i<n; i++) gret = max(gret, a[i] * f[n - 1 - i]);
	ans = bs(0, gret);
	cout << ans << endl;
}

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

int main() {
 int A, B, C, D;
  cin >> A >> B >> C >> D;
    
while(A > 0 && C > 0){
 C -= B;
 A -= D;
}

if(C <= 0){
cout << "Yes" << endl;
}
  
else{
cout << "No" << endl;
}
  
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
long long int power(int a,int b)
{
    if(b==0)
        return 1;
    long long int k=power(a,b/2);
    if(b%2==0)
        return ((k%M)*(k%M))%M;
    else
        return ((k%M)*(k%M)*(a%M))%M;
}
long long int fact(long long int n)
{
    if(n==1 || n==0)
        return 1;
    else
        return ((n%M)*(fact(n-1)%M))%M;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     #ifndef ONLINE_JUDGE
 
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
 
   #endif
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++)
   {
    cin>>arr[i];
   }
   sort(arr,arr+n);
   cout<<arr[n-1]-arr[0];

    return 0;
}








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

const llong MOD = 1e9+7;
const llong inf = 1<<30;

int main() {
    int a, b, c; cin >> a >> b >> c;
    cout << max(c - (a-b), 0) << endl;
    return 0;
}

Measured memory_bytes: 256