akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		String o = scan.next();
		String e = scan.next();
		String[] O = o.split("",0);
		String[] E = e.split("",0);
		StringBuffer sb = new StringBuffer();
		for(int i=0; i<o.length()+e.length(); i++){
			if(i%2==0){
				sb.append(O[i/2]);
			}
			else{sb.append(E[(i-1)/2]);}
		}
		String s = sb.toString();
		System.out.println(s);
	}
}

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

int main(){
  int N,H;
  cin >> N >> H;
  vector< pair<int, int> > ab;
  REP(i, N) {
    int a,b;
    cin >> a >> b;
    ab.emplace_back( a, 0 );
    ab.emplace_back( b, 1 );
  }
  sort( ab.begin(), ab.end(),greater<pair<int,int> >() );
  ll ans = 0;
  for (int i=0; H>0; i++ ) {
    if (ab[i].second == 0) {
      ans += (H+ab[i].first-1) / ab[i].first;
      break;
    } else {
      ans += 1;
      H -= ab[i].first;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 2420
function main(s) {
	s = s.split("\n")[0].split(" ").map(x => Number(x));
	var x = 0;
	for (var i = 0; i < s[1]; i++) {
		if (i * s[0] % s[1] === s[2]) {x++;}
	}
	console.log(x > 0 ? "YES" : "NO");
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));



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

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

    vector<int> v;
    for(int i=0;i < n;i++) {
        int j;
        cin >> j;
        v.emplace_back(j);
    }
    int sum = accumulate(v.begin(),v.end(), 0);
    double avg = sum / (double)n;

    int ans = 0;
    double min = 1000;
    for(int i = 0; i < n; i++){
        if (abs(v[i] - avg) < min) {
            ans = i;
            min = abs(v[i] - avg);
        }
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
n=input()


count_1=0
count_2=0

p1_1=[0]*len(n)
p1_2=[0]*len(n)
p2_1=[0]*len(n)
p2_2=[0]*len(n)
i=0
p1_1[i]=1
p1_2[i]=10-int(n[i])
p2_1[i]=int(n[i])
p2_2[i]=0

c_1=p1_1[i]+p1_2[i]
c_2=p2_1[i]+p2_2[i]

for i in range(1,len(n)):
    p1_1[i]=1
    p1_2[i]=10-int(n[i])
    p2_1[i]=int(n[i])
    p2_2[i]=0
    
    tmp_c_1 = min([c_2,c_1-2])+(p1_1[i]+p1_2[i])
    tmp_c_2 = min([c_1,c_2])+(p2_1[i]+p2_2[i])
    c_1=tmp_c_1
    c_2=tmp_c_2

print(min([c_1,c_2]))
    

Measured memory_bytes: 35512
#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define filein freopen ("in.txt", "r", stdin)
#define fileout freopen ("out.txt", "w", stdout)
#define dbg(args...) do {cerr << #args << " : "; debug(args); } while(false)
#define all(v) ((v).begin()),((v).end())
#define size(x) (int) x.size() 
#define pb emplace_back
#define mp make_pair
#define PI 3.14159265
#define mod 1000000007
void debug () {cerr << endl;}
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template < typename T, typename ... hello>void debug( T arg, const hello &... rest) {cerr << arg << ' ';debug(rest...);}
const int maxN = 1e5 + 10;
lli dp[101][maxN];
lli get_res(int n,int w,vector<int> prod,vector<int> prices){
	if(n == 0 or w == 0){
		return 0;
	}
	if(dp[n][w] != -1){
		return dp[n][w];
	}
	if(prod[n - 1] > w){
		return dp[n][w] = get_res(n - 1,w,prod,prices);
	}
	return dp[n][w] = max(prices[n - 1] + get_res(n - 1,w - prod[n - 1],prod,prices),get_res(n - 1,w,prod,prices));
}
int main(){
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,w;
    cin >> n >> w;
    vector<int> prod,prices;
    memset(dp,-1,sizeof(dp));
    for(int i = 0;i < n; i++){
		int x,y;
		cin >> x >> y;
		prod.pb(x),prices.pb(y);
	}
	cout << get_res(n,w,prod,prices);
}
 


Measured memory_bytes: 82660
N, M, C = map(int, input().split())  # スペース、改行、タブは引数に指定しなくても split する
BB = list(map(int, input().split()))

ans = 0
for i in range(N):
    AA = list(map(int, input().split()))
    _sum = 0
    for j in range(M):
        _sum += AA[j] * BB[j]
    _sum += C
    if _sum > 0:
        ans += 1

print(ans)


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

typedef long long ll;

int main() {

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

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    long double a;
    long double b;

    cin >> a >> b;
    b = (long long int) (b * 100 + 0.001);
    cout << (long long int) (a * b/100) << endl;
    return 0;
}

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

#define int long long
#define double long double

const int INF=2147483647;
const int MOD=1000000007;
const int mod=998244353;
const double eps=1e-12;

using namespace std;

int n;
int arr[300001];
int k;

struct Node{

    int sl,sr;
    int Max;

};

Node st[1200001];

void build(int cidx,int cl,int cr){

    st[cidx].sl=cl;
    st[cidx].sr=cr;
    st[cidx].Max=0;

    if(cl<cr){
        int mid=(cl+cr)/2;
        build(cidx*2,cl,mid);
        build(cidx*2+1,mid+1,cr);
    }

}

void modify(int midx,int val,int cidx){

    int cl=st[cidx].sl;
    int cr=st[cidx].sr;

    if( !(cl<=midx and midx<=cr) ){
        return;
    }

    st[cidx].Max=max(st[cidx].Max,val);

    if(cl<cr){
        modify(midx,val,cidx*2);
        modify(midx,val,cidx*2+1);
    }

}

int query(int ql,int qr,int cidx){

    int cl=st[cidx].sl;
    int cr=st[cidx].sr;

    if( qr<cl or cr<ql ){
        return 0;
    }

    if( ql<=cl and cr<=qr ){
        return st[cidx].Max;
    }
    else{
        return max( query(ql,qr,cidx*2) , query(ql,qr,cidx*2+1) );
    }

}

signed main(){

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

    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>arr[i];
    }

    build(1,0,300000);

    for(int i=0;i<n;i++){
        int r=query(arr[i]-k,arr[i]+k,1);
        modify(arr[i],r+1,1);
    }

    cout<<query(0,300000,1)<<endl;

    return 0;
}


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

int main()
{
  int A, B, C;
  cin >> A >> B >> C;

  int ans = A;
  if (A == B)
    ans = C;
  if (A == C)
    ans = B;
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int min = 999;
  int tmp;
  for(int i=0;i<=s.size()-3;i++){
    tmp = abs(753 - stoi(s.substr(i,3)));
    if(tmp < min)
      min = tmp;
  }
    cout << min << endl;
  return 0;
}

Measured memory_bytes: 256
import sys,queue,math,copy,itertools
from fractions import gcd
sys.setrecursionlimit(10**7)
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,X = LI()
A = LI()
ans = 0
for i in range(1, N):
    if A[i-1] + A[i] > X:
        sa = (A[i-1]+A[i]) - X
        if A[i] >= sa:
            A[i] -= sa
        else:
            A[i] = 0
        ans += sa
print (ans)


Measured memory_bytes: 83052
#include<stdio.h>
int main(){
  int s,a,b;
  scanf("%d",&s);
  a=s/100;
  b=s%100;
  if(0<a&&a<13){
    if(0<b&&b<13){
      printf("AMBIGUOUS");
    }else{
      printf("MMYY");
    }
  }else{
    if(0<b&&b<13){
      printf("YYMM");
    }else{
      printf("NA");
    }
  }
  return 0;
}

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

using namespace std;

void printOddLine(int n, int w) {
    for (int j = 0; j < w / 2; j++) {
        if (n % 2 == 0) {
            cout << "#.";
        } else {
            cout << ".#";
        }
    }
    if (n % 2 == 0) {
        cout << "#";
    } else {
        cout << ".";
    }
    cout << endl;
}

void printEvenLine(int n, int w) {
    for (int j = 0; j < w / 2; j++) {
        if (n % 2 == 0) {
            cout << "#.";
        } else {
            cout << ".#";
        }
    }
    cout << endl;
}


int main() {
    while (true) {
        int h, w;
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        for (int i = 0; i < h; i++) {
            if (w % 2 == 0) {
                printEvenLine(i, w);
            } else {
                printOddLine(i, w);
            }
        }
        cout << endl;
    }
    return 0;
}



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

using namespace std;

const long long MOD = 1e9 + 7;

int str[1000001]  = {0};

void Factor1(int k) {
	int x = round(sqrt(k));
	for (int i = 2; i <= x; ++i) {
		int t = 0;
		while (k % i == 0) {
			k /= i;
			++t;
		}
		str[i] = max(str[i], t);
	} 
	if (k > 1) str[k] = max(str[k], 1);
}

long long expo(long long a, long long n) {
	long long ans = 1;
	for (; n; n >>= 1) {
		if (n & 1) {
			ans = (ans * a) % MOD;
		}
		a = (a * a) % MOD;
	}
	return ans;
}


int main() {
	long long ans = 0;
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n; 
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) cin >> a[i], Factor1(a[i]);
	long long tmp = 1;
	for (int i = 2; i <= 1e6; ++i) {
		while (str[i]--) {
			tmp = (tmp * i) % MOD;
		}
	}
	for (int i = 0; i < n; ++i) {
		ans = (ans + tmp * expo(a[i], MOD - 2) % MOD) % MOD;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 4224
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
	
		if(A % 2 == 1 && B % 2 == 1) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  int h, n, w;
  for (long long i = 1; i <= 3500; i++){
    for (long long j = 1; j <= 3500; j++){
      long long a = 4 * i * j - N * (i + j);
      long long b = N * i * j;
      if (a > 0){
        if (b % a == 0){
          h = i;
          n = j;
          w = b / a;
        }
      }
    }
  }
  cout << h << ' ' << n << ' ' << w << endl;
}


Measured memory_bytes: 3604
import java.util.Scanner;

public class Main {

    public static void main(String... args) {
        Scanner sc = new Scanner(System.in);{
            int arr1Size = sc.nextInt();
            int[] arr1 = new int[arr1Size];
            for(int i = 0; i < arr1Size; ++i)
                arr1[i] = sc.nextInt();

            int arr2Size = sc.nextInt();
            int[] arr2 = new int[arr2Size];
            for(int i = 0; i < arr2Size; ++i)
                arr2[i] = sc.nextInt();

            int count = 0;
            for(int n : arr2)
                count += bs(arr1, n);

            System.out.println(count);
        }
    }
    public static int bs(int[] arr, int e) {
        int lower = 0;
        int mid = arr.length/2;
        int upper = arr.length;

        while(lower < upper) {
            if(arr[mid] == e) return 1;
            else if(mid == lower) return 0;
            else if(mid == upper) mid--;
            else if(e < arr[mid]) {
                upper = mid;
                mid -= (upper - lower) / 2;
            } else {
                lower = mid;
                mid += (upper - lower) / 2;
            }
        }
        return 0;
    }
}



Measured memory_bytes: 67460
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


H, W, K = map(int,readline().split())
grid = np.frombuffer(read(),'S1').reshape(H, -1)[:,:W]
X, Y = np.where(grid == b'#')
A = np.zeros((H, W),np.int32)
A[X, Y] = np.arange(1, K+1)
np.maximum.accumulate(A, axis=1, out=A)
for w in range(W-2,-1,-1):
    A[:,w] += A[:,w+1] * (A[:,w] == 0)
for h in range(1,H):
    if A[h,-1] == 0:
        A[h] += A[h-1]
for h in range(H-1,-1,-1):
    if A[h,-1] == 0:
        A[h] += A[h+1]
print('\n'.join(' '.join(row) for row in A.astype(str)))


Measured memory_bytes: 20404
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> P;
typedef long long int ll;
typedef pair<int,int> Pii;
const int INF=(1<<30)-1;
const ll INFl=9223372036854775807;
const int MAX=310;
const ll MOD=1000000007;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

int main(void){
	int n;
	cin>>n;
	ll ans=0;
	ll a[100100],b[100100],ab[100100];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		ans+=(ll)b[i];
		ab[i]=a[i]+b[i];
	}
	ans*=(-1);
	sort(ab,ab+n,greater<int>());
	for(int i=0;i<(n+1)/2;i++)
		ans+=(ll)ab[i*2];
	cout<<ans<<endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{ 
    cool;
    int n,i;
    cin>>n;
    float a[n],sum=0.0,ans=0.0;
    for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n;i++)
    {
    	sum+=(1/a[i]);
	}
	ans=(1/sum);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+5;
struct node
{
    int l,r;
    bool operator<(const node&o)const
    {
        return l<o.l;
    }
}a[N];
int n;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        int x,p;
        scanf("%d%d",&x,&p);
        a[i].l=x-p;
        a[i].r=x+p;
    }
    sort(a+1,a+1+n);
    int ans=0,now=-1e9;
    now-=10;
    for(int i=1;i<=n;i++)
        if(a[i].l>=now)
    {
        ans++;now=a[i].r;
    }
    else now=min(now,a[i].r);
    printf("%d\n",ans);
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int N;
	int i;
	int asumikana = 0;
	if (scanf("%d", &N) != 1) return 1;
	for (i = 0; i < N; i++) {
		int l, r;
		if (scanf("%d%d", &l, &r) != 2) return 1;
		asumikana += r - l + 1;
	}
	printf("%d\n", asumikana);
	return 0;
}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb emplace_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

int n;
struct P
{
    double x, y;
};
vector<P> p;

double dist(P a, P b)
{
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

double f(double x, double y)
{
    double res = 0;
    rep(i, n)
    {
        res = max(res, dist({x, y}, p[i]));
    }
    return res;
}

double g(double x)
{
    double l = 0, r = 1000;
    rep(i, 80)
    {
        double c1 = (l * 2 + r) / 3;
        double c2 = (l + r * 2) / 3;
        if (f(x, c1) > f(x, c2))
            l = c1;
        else
            r = c2;
    }
    return f(x, l);
}

void Main()
{
    cin >> n;
    p = vector<P>(n);
    rep(i, n) cin >> p[i].x >> p[i].y;

    double l = 0, r = 1000;
    rep(i, 80)
    {
        double c1 = (l * 2 + r) / 3;
        double c2 = (l + r * 2) / 3;
        if (g(c1) > g(c2))
            l = c1;
        else
            r = c2;
    }
    double ans = g(l);
    cout << ans << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

const int N=3010,Mod=1e9+7;

int n,m,dp[2][N][2];

void Init() {
	scanf("%d%d",&n,&m);
}

void Add(int &x,int v) { x+=v; if (x>=Mod) x-=Mod; }

void Solve() {
	for (int i=1;i<=n;++i) dp[0][i][0]=1; dp[0][0][1]=1;
	int op=0;
	for (int i=0;i<m;++i) {
		for (int j=0;j<=n;++j) for (int k=0;k<2;++k) dp[op^1][j][k]=0;
		for (int j=0;j<=n;++j) for (int k=0;k<2;++k) if (dp[op][j][k]) {
			if (j) Add(dp[op^1][j-1][(j-1)?k:1],dp[op][j][k]),Add(dp[op^1][j][(j-1)?k:1],dp[op][j][k]);
			if (n-j) Add(dp[op^1][j+1][k],dp[op][j][k]),Add(dp[op^1][j][k],dp[op][j][k]);
		}
		op^=1;
	}
	int ans=0;
	for (int i=0;i<=n;++i) ans=(ans+dp[op][i][1])%Mod;
	printf("%d\n",ans);
}

int main() {
	Init();
	Solve();
	return 0;
}

Measured memory_bytes: 256
N = int(input())
Alist = list(map(int,input().split(" ")))
Alist.sort()
Amax = Alist[-1]
dp = [1]*(Amax+1)
count = 0
for i in range(len(Alist)-1):
    p = Alist[i]
    if dp[p] == 1:
        for j in range(Amax//p+1):
            dp[p*j] = 0
        if Alist[i] != Alist[i+1]:
            count+=1
if dp[Amax] == 1:
    count += 1
print(count)

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

int main() {
  long long N;
  cin >> N;
  string A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  
  long long count = 0;
  
  long long B2[N];
  long long B5[N];
  long long shosu[N];
  for (int i = 0; i < N; i++) B2[i] = B5[i] = shosu[i] = 0;
  
  /*long long sum_B2[100];
  long long sum_B5[100];
  long long sum_10[100];
  for (int i = 0; i < 100; i++) sum_B2[i] = sum_B5[i] = sum_10[i] = 0;*/
  long long sum[100][100];
  for (int i = 0; i < 100; i++) for (int j = 0; j < 100; j++) sum[i][j] = 0;
  
  for (int i = 0; i < N; i++){
    int a = A[i].size();
    long long seisu = 0;
    for (int j = 0; j < a; j++){
      if (A[i][j] == '.') {
        shosu[i] = a - j - 1;
        continue;
      }
      seisu = seisu * 10 + (A[i][j] - '0');
    }
    while (seisu % 2 == 0 || seisu % 5 == 0){
      if (seisu % 2 == 0) {
        B2[i]++;
        seisu /= 2;
      }
      if (seisu % 5 == 0) {
        B5[i]++;
        seisu /= 5;
      }
    }
    sum[B2[i] - shosu[i] + 50][B5[i] - shosu[i] + 50]++;
  }
  
  long long sum_[100][100];
  for (int i = 99; i >= 0; i--){
    for (int j = 99; j >= 0; j--){
      if (i == 99 || j == 99) {
        sum_[i][j] = 0;
        continue;
      }
      sum_[i][j] = sum_[i][j + 1] + sum_[i + 1][j] - sum_[i + 1][j + 1] + sum[i][j];
    }
  }
  
  for (int i = 0; i < 100; i++){
    for (int j = 0; j < 100; j++){
      count += sum_[100 - i][100 - j] * sum[i][j];
    }
  }
  count = (count - sum_[50][50]) / 2;
  
  cout << count << endl;
}

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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;
#define u_b upper_bound
#define l_b lower_bound

const int mod = 1000000007;

template<int M = 1000000007>
struct ModInt {
    int data;

    ModInt(int data) : data(data) {}

    ModInt() : data(0) {}

    inline ModInt<M> operator+(ModInt<M> const &right) const {
        int temp = data + right.data;
        return ModInt(temp > M ? temp - M : temp);
    }

    inline ModInt<M> operator-(ModInt<M> const &right) const {
        int temp = data - right.data;
        return ModInt(temp < 0 ? temp + M : temp);
    }

    inline ModInt<M> operator*(ModInt<M> const &right) const {
        int temp = data * right.data % M;
        return ModInt(temp < 0 ? temp + M : temp);
    }

    inline bool operator==(ModInt<M> const &right) const {
        return data == right.data;
    }

    inline bool operator!=(ModInt<M> const &right) const {
        return data != right.data;
    }
};

vector<ModInt<>> createHash(string s);

int solve(int begin);//sのbegin文字目から始めた時の答え

void preCalc();

string S, T;
vector<ModInt<>> shash, thash;
bool inf;//無限?
bool calling[500500];//再帰関数solveでループになっているか確認

signed main() {
    preCalc();
    cin >> S >> T;
    shash = createHash(S);
    thash = createHash(T);
    int ans = 0;
    rep(i, S.length()) {
        ans = max(ans, solve(i));
        if (inf) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

ModInt<> powMemo[500500];
int memo[500500];

void preCalc() {
    memo[0] = -1;
    powMemo[0] = 1;
    for (int i = 1; i < 500500; ++i) {
        memo[i] = -1;
        powMemo[i] = powMemo[i - 1] * 27;
    }
}

ModInt<> Slice(vector<ModInt<>> const &hash, int begin, int length) {
    return hash[begin + length] - hash[begin] * powMemo[length];
}

int solve(int begin) {
    if (calling[begin]) {
        inf = true;
        return memo[begin] = 0;
    }
    calling[begin] = true;
    int tPlace = 0;
    int sPlace = begin;
    int remainLength = T.length();
    while (remainLength) {
        int nextLength = min(remainLength, (int) min(T.length() - tPlace, S.length() - sPlace));
        if (Slice(shash, sPlace, nextLength) != Slice(thash, tPlace, nextLength)) {
            calling[begin] = false;
            return memo[begin] = 0;
        }
        remainLength -= nextLength;
        sPlace += nextLength;
        tPlace += nextLength;
        if (sPlace == S.length())sPlace = 0;
        if (tPlace == T.length())tPlace = 0;
    }
    int res = (memo[sPlace] != -1 ? memo[sPlace] : solve(sPlace)) + 1;
    calling[begin] = false;
    return memo[begin] = res;
}

vector<ModInt<>> createHash(string s) {
    vector<ModInt<>> hash(s.length() + 1);
    rep(i, s.length()) {
        hash[i + 1] = hash[i] * 27 + (s[i] - 96);
    }
    return hash;
}


Measured memory_bytes: 56860
import bisect
n = int(input())
a = sorted(map(int,input().split()))
b = sorted(map(int,input().split()))
c = sorted(map(int,input().split()))
ans = 0
for i in b:
  a_ind = bisect.bisect_left(a,i)
  c_ind = bisect.bisect_right(c,i)
  ans += a_ind*(n-c_ind)
print(ans)

Measured memory_bytes: 23360
//agc005_a.cpp
//Sun Oct 21 21:17:07 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	int ans = s.size();
	int prevpos = -1;
	for (int i=0;i<s.size()-1;i++){
		if (s[i] == 'S' && s[i+1] == 'T'){
			ans = ans -2;
			s[i] = 'Z';
			s[i+1] = 'Z';
			int nextpos = i+2;
			for (int j=i-1;j>=0;j--){
				if (s[j] == 'Z'){
					continue;
				}else if (s[j] == 'S' && s[nextpos] == 'T'){
					ans = ans-2;
					s[j] = 'Z';
					s[nextpos] = 'Z';
					nextpos++;
				}else {
					break;
				}
			}
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define N 10
#define M 30
using namespace std;
int h,w,sy,sx,sd,ocnt;
string s[N],ans;
char c[M];
int dy[4]={-1,0,1,0};
int dx[4]={0,1,0,-1};
char itoc[4]={'U','R','D','L'};

void dfs(int y,int x,int d,int cnt){
  if(cnt==ocnt){
    for(int i=0;i<cnt;i++)ans+=c[i];
    return;
  }
  for(int i=-1;i<=1;i++){
    int nd=(d+i+4)%4;
    int ny=y+dy[nd],nx=x+dx[nd];
    while(1){
      if(ny<0||nx<0||h<=ny||w<=nx)break;
      if(s[ny][nx]=='o'){
	s[ny][nx]='.';
	c[cnt]=itoc[nd];
	dfs(ny,nx,nd,cnt+1);
	s[ny][nx]='o';
	break;
      }
      ny+=dy[nd];
      nx+=dx[nd];
    }
  }
}

int main(){
  cin>>h>>w;
  for(int i=0;i<h;i++){
    cin>>s[i];
    for(int j=0;j<w;j++){
      if(s[i][j]=='o')ocnt++;
      else if(s[i][j]!='.'){
	sy=i,sx=j;
	if(s[i][j]=='U')sd=0;
	if(s[i][j]=='R')sd=1;
	if(s[i][j]=='D')sd=2;
	if(s[i][j]=='L')sd=3;
      }
    }
  }

  dfs(sy,sx,sd,0);
  cout<<ans<<endl;
  return 0;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define REP(i,n) for(int i=0; i < (n); ++i)
#define SIZE(c) (int) (c).size()
#define ALL(c) (c).begin(), (c).end()
#define PB push_back
#define MP make_pair
#define ST first
#define ND second
#define FWD(i,a,b) for (int i=(a); i<(b); ++i)
#define BCK(i,a,b) for (int i=(a); i>(b); --i)
#define PI 3.14159265358979311600
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

typedef vector < int > VI;
typedef vector<ll> VL;

typedef long double K;

const int N = 400005;
const K pi = acos(-1.0);
const int inf = 1000 * 1000 * 1000 + 7;

int n;
pll s, f, a[N];

vector<int> cmp;

K result = 0.0;

int calc[N];

int t[4*N];

int go(int v, int tl, int tr, int l, int r) {
	if (l > tr || r < tl) return -inf;
	if (l <= tl && r >= tr) return t[v];
	int tm = (tl + tr) / 2;
	return max(go(2*v, tl, tm, l, r), go(2*v+1, tm+1, tr, l, r));
}

void update(int v, int tl, int tr, int pos, int val) {
	if (tl == tr) {
		t[v] = max(t[v], val);
		return;
	}
	int tm = (tl + tr) / 2;
	if (pos <= tm) {
		update(2*v, tl, tm, pos, val);
	} else {
		update(2*v+1, tm+1, tr, pos, val);
	}
	t[v] = max(t[2*v], t[2*v+1]);
}

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

	cin >> s.x >> s.y;
	cin >> f.x >> f.y;
	cin >> n;

	ll total = abs(s.x - f.x) + abs(s.y - f.y);
	total *= 100;

	if (s > f) swap(s, f);

	REP(i, 4*N) t[i] = -inf;

	int mul = +1;

	if (s.y > f.y) mul = -1;

	f.x *= mul;
	s.x *= mul;
	if (mul == -1) swap(f, s);

	FOR (i, 1, n) {
		cin >> a[i].x >> a[i].y;
		a[i].x *= mul;
		if (a[i] < s || a[i] > f) {
			--i; --n;
		}
	}

	n += 2;
	a[0] = s;
	a[n - 1] = f;

	sort(a, a + n);

	REP(i, n) cmp.push_back(a[i].y);
	sort(cmp.begin(), cmp.end());
	cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());

	int here = lower_bound(cmp.begin(), cmp.end(), a[0].y) - cmp.begin();
	update(1, 0, SIZE(cmp), here, 0);

	FOR (i, 1, n - 1) {
		here = lower_bound(cmp.begin(), cmp.end(), a[i].y) - cmp.begin();
		calc[i] = go(1, 0, SIZE(cmp), 0, here) + 1;
		update(1, 0, SIZE(cmp), here, calc[i]);
	}
	ll cnt = calc[n - 1] - 1;

	result += (K)cnt*(-20.0 + pi*5.0);
	if (cnt == min(abs(s.x - f.x), abs(s.y - f.y)) + 1) {
		result += pi*5.0;
	}

	cout << setprecision(15) << fixed << total + result << '\n';

	return 0;
}

Measured memory_bytes: 13688
#!/usr/bin/env python3
import sys
INF = float("inf")


def no():
    print("IMPOSSIBLE")  # type: str


def solve(A: int, B: int):
    K = (A+B)//2
    if abs(A-K) == abs(B-K):
        print(K)
    else:
        no()

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <stdio.h>

int main(void) {
    int X, Y, S;
    scanf("%d%d", &X, &Y);
    S=0;
    if (X==1) S+=300000;
    else if (X==2) S+=200000;
    else if (X==3) S+=100000;
    if (Y==1) S+=300000;
    else if (Y==2) S+=200000;
    else if (Y==3) S+=100000;
    if (X==1 && Y==1) S+=400000;
    printf("%d", S);
    return 0;
}


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

int main(){
	int ax, ay;
	char f[12][12];
	bool flag = false;

	for(int y=0 ; y<12 ; y++){
		for(int x=0 ; x<12 ; x++){
			f[y][x] = 0;
		}
	}

	while( 1 ){
		for(int i=0 ; i<8 ; i++) {
			if( scanf("%s", f[i]) == EOF ){
				flag = true;
				break;
			}
		}
		if(flag) break;

		for(int i=0 ; i<64 ; i++){
			if(f[i/8][i%8]=='1'){
				ax = i%8;
				ay = i/8;
				break;
			}
		}
		if( f[ay+1][ax]=='1' && f[ay][ax+1]=='1' && f[ay+1][ax+1]=='1' ){
			printf("A\n");
		}else if( f[ay+1][ax]=='1' && f[ay+2][ax]=='1' && f[ay+3][ax]=='1' ){
			printf("B\n");
		}else if( f[ay][ax+1]=='1' && f[ay][ax+2]=='1' && f[ay][ax+3]=='1' ){
			printf("C\n");
		}else if( f[ay][ax+1]=='1' && f[ay+1][ax+1]=='1' && f[ay+1][ax+2]=='1' ){
			printf("E\n");
		}else if( f[ay+1][ax]=='1' && f[ay+1][ax+1]=='1' && f[ay+2][ax+1]=='1' ){
			printf("F\n");
		}else if( f[ay][ax+1]=='1' && f[ay+1][ax]=='1' && f[ay+1][ax-1]=='1' ){
			printf("G\n");
		}else if( f[ay+2][ax-1]=='1' && f[ay+1][ax]=='1' && f[ay+1][ax-1]=='1' ){
			printf("D\n");
		}
	}
}

Measured memory_bytes: 1112
import java.util.Scanner;

// https://atcoder.jp/contests/abc137/tasks/abc137_a
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();


		System.out.println(Math.max(a*b,Math.max(a+b,a-b)));
	}

}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n,k; cin>>n>>k;
  vi a(n);
  rep(i,n) cin>>a[i];
  vector<ll> v(n+1);
  vector<ll> w(n+1);
  rep(i,n){
    v[i+1]=(ll)v[i]+a[i];
    w[i+1]=(ll)w[i]+max(a[i], 0);
  }
  ll ans=-1e14;
  for(int i=0; i<n-k+1; i++){
    int l=i; int r=i+k;
    ll tmp=w[l]+max(v[r]-v[l], 0LL) + w[n] - w[r];
    chmax(ans, tmp);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

bool isok(int a, int b, int c){
	if(a+b>c and a+c>b and b+c>a and a!=b and b!=c and a!=c){
		return true;
	}
	return false;
}
void solve()
{
	int n;
	cin>>n;
	vector<int>l(n);
	rep(i,n)cin>>l[i];
	int ans=0;
	rep(i,n){
		FOR(j,i+1,n){
			FOR(k,j+1,n){
				if(isok(l[i],l[j],l[k])){
					ans++;
				}
			}
		}
	}
	cout<<ans<<endl;
	
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
		int count = 0;
		
		String str;
		while((str = br.readLine()) != null){
			if(isPrime(Long.valueOf(str)))
				count++;
		}
		System.out.println(count);
	}
	
	private static boolean isPrime(long n){
		if(n < 2)
			return false;
		else if(n == 2)
			return true;
		
		if(n % 2 == 0)
			return false;
		
		for(long i = 3;i <= n / i; i += 2)
			if(n % i == 0)
				return false;
		return true;
		
	}
}

Measured memory_bytes: 22844
from math import gcd

n = int(input())


def p(x):
    a = []
    i = 2
    while True:
        if x % i == 0:
            j = 0
            while x % i == 0:
                x //= i
                j += 1
            a.append((i, j))
        if i * i > x:
            break
        i += 1
    if x != 1:
        a.append((x, 1))
    return a


pp = set()
a = [int(i) for i in input().split()]

j = 0
for i in a:
    j = gcd(j, i)
ok1 = j == 1

ok2 = True
for i in a:
    for (j, _) in p(i):
        if j in pp:
            ok2 = False
        else:
            pp.add(j)
    if not ok2:
        break
if ok2:
    print("pairwise coprime")
else:
    if ok1:
        print("setwise coprime")
    else:
        print("not coprime")


Measured memory_bytes: 181204
//https://atcoder.jp/contests/arc081/tasks/arc081_b
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}}star;
#define DEBUG if(0)
#endif
#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}
class reverse_range {private:struct I {int x;int operator*() {return x-1;}bool operator!=(I& lhs) {return x>lhs.x;}void operator++() {--x;}};I i, n;public:reverse_range(int n) :i({ 0 }), n({ n }){}reverse_range(int i, int n) :i({ i }), n({ n }){}I& begin() {return n;}I& end() {return i;}};
class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }reverse_range operator!(){return reverse_range(*i,*n);}};

constexpr int mod = 1e9+7;
struct ModInt{
    int x;
    LL operator*()const{
        return x;
    }
    ModInt(){}
    ModInt(const int y){
        x=y;
    }
    ModInt(const LL y){
        x=(int)(y%mod);
    }

    static inline ModInt raw(const LL x){
        assert(x<mod);
        return ModInt((int)x);
    }
    static inline ModInt get(const LL x){
        return ModInt((int)(x%mod));
    }
    ModInt& operator=(const int o){
        this->x=o;
        return *this;
    }
    ModInt& operator=(const LL o){
        this->x=(int)(o%mod);
        return *this;
    }
};
inline ModInt mul(const ModInt l,const ModInt r){
    return ModInt::raw(*l**r%mod);
}
inline ModInt add(const ModInt l,const ModInt r){
    LL x = *l+*r;
    return ModInt::raw(x>=mod?x-mod:x);
}
inline ModInt operator+(const ModInt l,const ModInt r){
    return add(l,r);
}
inline ModInt operator*(const ModInt l,const ModInt r){
    return mul(l,r);
}
inline ModInt operator+(const ModInt l,const int r){
    return add(l,ModInt::raw(r));
}
inline ModInt operator+(const ModInt l,const LL r){
    return add(l,ModInt::get(r));
}
inline ModInt operator*(const ModInt l,const int r){
    return mul(l,ModInt::raw(r));
}
inline ModInt operator*(const ModInt l,const LL r){
    return mul(l,ModInt::get(r));
}
int main(){
    int N;
    string S,T;
    cin>>N>>S>>T;
    vector<int> v;
    for(int id=0;id<N;){
        if(S[id]==T[id]){
            v.push_back(1);
        }
        else{
            v.push_back(2);
        }
        id+=v.back();
    }
    vector<ModInt> dp(v.size());
    dp[0]=1;
    for(int i:range(1,v.size())){
        if(v[i-1]==1&&v[i]==2){
            dp[i]=dp[i-1];
        }
        else if(v[i-1]==2&&v[i]==2){
            dp[i]=dp[i-1]*3;
        }
        else{
            dp[i]=dp[i-1]*2;
        }
    }
    cout<<*(dp.back()*v.back()*3)<<endl;
    return 0;
}

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

int main(){
  int H, W, N;
  cin >> H >> W >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a.at(i);
  int m[H][W];
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++) m[i][j]=0;
  }
  int cnt=0;
  int temp=1;
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(i%2==0){
        m[i][j]=cnt+1;
      }
      else{
        m[i][W-j-1]=cnt+1;
      }
      if(temp!=a.at(cnt)) temp++;
      else{
        temp=1;
        cnt++;
      }
    }
  }
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++) cout << m[i][j] << ' ';
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,t;
  cin >> a >> b >> t;
  int n = t/a;
  int ans = n*b;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){fastio
    
    ll n;cin>>n;
    string s;cin>>s;
    bool dp[10][n+2],ep[10][n+2];
    memset(dp,false,sizeof(dp));
    memset(ep,false,sizeof(ep));
    rep(i,0,n-1){
        rep(j,0,9){
            dp[j][i+1]=dp[j][i];
        }
        dp[s[i]-'0'][i+1]=true;
    }
    for(ll i=n-1;i>=0;i--){
        rep(j,0,9){
            ep[j][i+1]=ep[j][i+2];
        }
        ep[s[i]-'0'][i+1]=true;
    }
    bool ans[1000];memset(ans,false,sizeof(ans));
    rep(i,2,n-1){
        ll mid=s[i-1]-'0';
        rep(x,0,9){
            rep(z,0,9){
                if(dp[x][i-1]&&ep[z][i+1]){
                    ll k=mid*10+x*100+z;
                    ans[k]=true;
                }
            }
        }
    }
    /*
    rep(i,0,n+1){
        rep(j,0,9){
            cout<<dp[j][i]<<" ";
        }cout<<endl;
    }cout<<endl;
     */
    ll sum=0;
    rep(i,0,999){
        if(ans[i])sum++;
    }
    cout<<sum<<endl;
    
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,k;
  string s;
  cin>>n>>k;
  cin>>s;
  s[k-1]+=32;
  cout<<s<<"\n";
  return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    vector<int> cnt(m);
    for(int i = 0; i < n; ++i) {
        int k; cin >> k;
        for(int j = 0; j < k; ++j) {
            int a; cin >> a;
            cnt[a - 1] += 1;
        }
    }
    cout << count(begin(cnt), end(cnt), n) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N, D, A, Ans;
  cin >> N >> D;
  A = 2 * D + 1;
  Ans = N / A;
  if(N % A != 0){
    Ans += 1;
  }
  cout << Ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define up(i,a,b) for(int i=a;i<=b;i++)
#define down(i,a,b) for(int i=a;i>=b;i--)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repd(i,a,b) for(int i=a-1;i>=b;i--)
#define pb push_back
#define CL(x) (x<<1)
#define CR(x) (CL(x)+1)
//#define Kamisama

typedef long long ll;

using namespace std;

const int maxn=2e5+7;

int n;
int a[maxn];
ll s[maxn];
ll kq=1e16;

inline void Enter(){
    cin>>n;
    up(i,1,n) cin>>a[i],s[i]=s[i-1]+a[i];
}

inline int Left(int x){
    int l=1,h=x,pos=0;
    ll res=0;
    while(l<=h){
        int mid=(l+h)>>1;
        ll L1=s[mid],
           L2=s[x]-s[mid];
        if(L1>=L2) h=mid-1;
        else l=mid+1;
    }

    res=abs(s[l]-s[x]+s[l]); pos=l;

    l=1,h=x;
    while(l<=h){
        int mid=(l+h)>>1;
        ll L1=s[mid],
           L2=s[x]-s[mid];
        if(L2>=L1) l=mid+1;
        else h=mid-1;
    }

    if(res>abs((s[x]-s[h])-(s[h]))) return h;
    else return l;

}

inline int Right(int x){
    int l=x+1,h=n,pos=0;
    ll res=0;
    while(l<=h){
        int mid=(l+h)>>1;
        ll R1=s[mid]-s[x],
           R2=s[n]-s[mid];
        if(R1>=R2) h=mid-1;
        else l=mid+1;
        //cerr<<x<<' '<<R1<<' '<<R2<<'\n';
    }

    //cerr<<"---\n";

    res=abs((s[l]-s[x])-(s[n]-s[l])); pos=l;

    l=x+1,h=n;
    while(l<=h){
        int mid=(l+h)>>1;
        ll R1=s[mid]-s[x],
           R2=s[n]-s[mid];
        //cerr<<x<<' '<<R1<<' '<<R2<<'\n';
        if(R2>=R1) l=mid+1;
        else h=mid-1;
    }

    //cerr<<res<<'\n';
    if(res>abs((s[h]-s[x])-(s[n]-s[h]))) return h;
    else return pos;
}

inline void Solve(){
    up(i,2,n-1){
        ll L1=s[Left(i)],L2=s[i]-L1;
        ll R1=s[Right(i)]-s[i],R2=s[n]-s[i]-R1;
        ll Max=max(L1,max(L2,max(R1,R2))),
           Min=min(L1,min(L2,min(R1,R2)));
        //kq=min(kq,Max-Min);
        //cerr<<Left(i)<<' '<<i<<' '<<Right(i)<<" -> "<<L1<<' '<<L2<<' '<<R1<<' '<<R2<<'\n';
        if(kq>Max-Min){
            kq=Max-Min;
        }
    }
    cout<<kq;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    #ifdef Kamisama
    freopen("TEST.INP","r",stdin);
    freopen("TEST.OUT","w",stdout);
    #endif //Kamisama

    Enter();
    Solve();

    return 0;
}


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

public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        ArrayDeque<String> array = new ArrayDeque<>();
        StringBuilder ans = new StringBuilder();
        for(int i=0; i<n; i++){
            String command = sc.nextLine();
            if(command.charAt(0) == 'i'){
                array.addFirst(command.substring(7));
            }else{
                if(command.charAt(6) == 'F'){
                    // deleteFirst
                    array.removeFirst();
                }else if(command.charAt(6) == 'L'){
                    // deleteLast
                    array.removeLast();
                }else{
                    // delete
                    array.remove(command.substring(7));
                }
            }
        }
        int num = 0;

        while(!array.isEmpty()){
            if(num == 0) ans.append(array.pollFirst());
            else ans.append(" ").append(array.pollFirst());
            num++;
        }
        System.out.println(ans.toString());

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define mkp make_pair
#define F first
#define S second
typedef pair<int,int> pii;

map<pii,pii> N,R;

int main(){
	N[mkp(1,2)]=mkp(2,6);
	N[mkp(1,3)]=mkp(3,6);
	N[mkp(1,4)]=mkp(4,6);
	N[mkp(1,5)]=mkp(5,6);
	N[mkp(2,1)]=mkp(1,5);
	N[mkp(2,3)]=mkp(3,5);
	N[mkp(2,4)]=mkp(4,5);
	N[mkp(2,6)]=mkp(6,5);
	N[mkp(3,1)]=mkp(1,4);
	N[mkp(3,2)]=mkp(2,4);
	N[mkp(3,5)]=mkp(5,4);
	N[mkp(3,6)]=mkp(6,4);
	N[mkp(4,1)]=mkp(1,3);
	N[mkp(4,2)]=mkp(2,3);
	N[mkp(4,5)]=mkp(5,3);
	N[mkp(4,6)]=mkp(6,3);
	N[mkp(5,1)]=mkp(1,2);
	N[mkp(5,3)]=mkp(3,2);
	N[mkp(5,4)]=mkp(4,2);
	N[mkp(5,6)]=mkp(6,2);
	N[mkp(6,2)]=mkp(2,1);
	N[mkp(6,3)]=mkp(3,1);
	N[mkp(6,4)]=mkp(4,1);
	N[mkp(6,5)]=mkp(5,1);



	R[mkp(1,2)]=mkp(1,3);
	R[mkp(1,3)]=mkp(1,5);
	R[mkp(1,4)]=mkp(1,2);
	R[mkp(1,5)]=mkp(1,4);
	R[mkp(2,1)]=mkp(2,4);
	R[mkp(2,3)]=mkp(2,1);
	R[mkp(2,4)]=mkp(2,6);
	R[mkp(2,6)]=mkp(2,3);
	R[mkp(3,1)]=mkp(3,2);
	R[mkp(3,2)]=mkp(3,6);
	R[mkp(3,5)]=mkp(3,1);
	R[mkp(3,6)]=mkp(3,5);
	R[mkp(4,1)]=mkp(4,5);
	R[mkp(4,2)]=mkp(4,1);
	R[mkp(4,5)]=mkp(4,6);
	R[mkp(4,6)]=mkp(4,2);
	R[mkp(5,1)]=mkp(5,3);
	R[mkp(5,3)]=mkp(5,6);
	R[mkp(5,4)]=mkp(5,1);
	R[mkp(5,6)]=mkp(5,4);
	R[mkp(6,2)]=mkp(6,4);
	R[mkp(6,3)]=mkp(6,2);
	R[mkp(6,4)]=mkp(6,5);
	R[mkp(6,5)]=mkp(6,3);
	
	int n;
	while(cin>>n,n){
		pii now=mkp(1,2);
		int ans=1;
		rep(i,n){
			string tmp;
			cin>>tmp;
			// cout<<ans<<endl;
			if(tmp=="North"){
				now=N[now];
				ans+=now.F;
				// cout<<now.F<<" "<<now.S<<endl;
			}
			else if(tmp=="East"){
				rep(i,3) now=R[now];
				now=N[now];
				ans+=now.F;
				now=R[now];
				// cout<<now.F<<" "<<now.S<<endl;
			}
			else if(tmp=="South"){
				rep(i,3) now=N[now];
				ans+=now.F;
				// cout<<now.F<<" "<<now.S<<endl;

			}
			else if(tmp=="West"){
				now=R[now];
				now=N[now];
				ans+=now.F;
				rep(i,3) now=R[now];
				// cout<<now.F<<" "<<now.S<<endl;

			}
			else if(tmp=="Right"){
				now=R[now];
				ans+=now.F;
				// cout<<now.F<<" "<<now.S<<endl;

			}
			else if(tmp=="Left"){
				rep(i,3) now=R[now];
				ans+=now.F;
				// cout<<now.F<<" "<<now.S<<endl;

			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1220
N=int(input())
S=input()
S="N"+S+"N"
ans=0
E=0
W=S.count("W")
for i in range(1,N+1):
    if S[i-1]=="E":
        E+=1
    if S[i]=="W":
        W-=1
    tmp=E+W
    if tmp>ans:
        ans=tmp
ans=N-1-ans
print(ans)


Measured memory_bytes: 9736