akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final int INF=(int)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int n=fs.nextInt(),cnt=0;
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i=0;i<n;i++)
		{
			list.add(fs.nextInt());
		}
		for(int i=0;i<list.size();i++)
		{
			for(int j=i+1;j<list.size();j++)
			{
				for(int k=j+1;k<list.size();k++)
				{
					int sum=list.get(i)+list.get(j)+list.get(k);
					int max=Math.max(list.get(i),list.get(k));
					max=Math.max(max,list.get(j));
					Set<Integer> set = new HashSet<>();
					set.add(list.get(i));set.add(list.get(j));set.add(list.get(k));
					if(sum-max>max && set.size()==3)
					{
						cnt++;
					}
				}
			}
		}
		System.out.println(cnt);
	}
}
class FastScanner 
{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public double nextDouble()
		{
			return Double.parseDouble(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

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

#define MAX 500005

int main(int, char**)
{
  int n, l;
  cin >> n >> l;

  vector<int> a(n);
  rep(i,n) cin >> a[i];

  deque<int> q;
  vector<int> ans;
  rep(i,n) {
    while (!q.empty() && a[q.back()] >= a[i]) q.pop_back();
    q.push_back(i);
    if (i < l-1) continue;
    ans.push_back(a[q.front()]);
    if (q.front() == i-l+1) q.pop_front();
  }

  int as = ans.size();
  rep(i,as) {
    cout << ans[i];
    if (i==as-1) cout << endl;
    else cout << " ";
  }

  return 0;
}



Measured memory_bytes: 11000
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

vector<string>onoff(int N) {
	//N個のスイッチの状態列挙
	vector<string>ans;
	if (N == 1) {
		ans = { "0","1" };
	}
	else {
		vector<string>TMP = onoff(N - 1);
		string tmp;
		rep(i, TMP.size()) {
			tmp = TMP[i];
			tmp.push_back('0');
			ans.push_back(tmp);
			tmp = TMP[i];
			tmp.push_back('1');
			ans.push_back(tmp);
		}
	}
	return ans;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>K(M);
	vector<vector<int>>S(M);
	vector<int>P(M);
	int tmp = 0;
	rep(i, M) {
		cin >> K[i];
		rep(j, K[i]) {
			cin >> tmp;
			S[i].push_back(tmp);
		}
	}
	rep(i, M) {
		cin >> P[i];
	}
	vector<string>V;
	V = onoff(N);
	

	int on = 0;
	int cnt = 0;
	int ans = 0;
	rep(i, V.size()) {
		rep(j, M) {
			rep(k, K[j]) {
				if (V[i][S[j][k] - 1] == '1') {
					on++;
				}
			}
			if (on % 2 == P[j]) {
				cnt++;
			}
			on = 0;
		}
		if (cnt == M) {
			ans++;
		}
		cnt = 0;
	}
	cout << ans << endl;
}

Measured memory_bytes: 384
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = input()
	ret = 0
	pp_b = 0
	for c in s:
		if c == 'B':
			pp_b += 1
		else:
			ret += pp_b
	return ret
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 40048
from collections import deque
import sys

H,W = map(int,input().split())
maze = [list(input())for _ in range(H)]
count = 0
for i in range(H):
  for j in range(W):
    if maze[i][j]==".":
      count += 1

maze[0][0]=0

patterns = [[1,0],[-1,0],[0,1],[0,-1]]
que=deque([[0,0]])
flag = True
while que:
  now = que.popleft()
  nowY = now[0]
  nowX = now[1]
  nowstep = maze[nowY][nowX]
  if nowY == H-1 and nowX == W-1:
    flag = False
    break
  for pattern in patterns:
    nextY = nowY + pattern[0]
    nextX = nowX + pattern[1]
    nextstep = nowstep + 1
    if 0<=nextY<H and 0<=nextX<W and maze[nextY][nextX]==".":
      que.append([nextY,nextX])
      maze[nextY][nextX]=nextstep
      
if flag:
  print(-1)
else:
  print(count-nowstep-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3f3f3f3f;

const int MAX_N=1e5+3;
int N;
int H[MAX_N];
int dp[MAX_N];

void solve()
{
	memset(dp, 0x3f, sizeof(dp));
	dp[0]=0;
	for(int i=0; i<N; ++i){
		if(dp[i] < INF){
			if(i<N-1) dp[i+1]=min(dp[i+1], dp[i]+abs(H[i+1]-H[i]));
			if(i<N-2) dp[i+2]=min(dp[i+2], dp[i]+abs(H[i+2]-H[i]));
		}
	}
	cout << dp[N-1] << endl;
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i) cin >> H[i];
	solve();
	return 0;
}	

Measured memory_bytes: 1024
#include <bits/stdc++.h>
// Hey! 僕の提出を見てくれてありがとう.
// ロボ子さん可愛いぞ！！！！！君もV沼にはまろう↓
// https://www.youtube.com/channel/UCDqI2jOz0weumE8s7paEk6g
using namespace std;
/*
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
namespace mp = boost::multiprecision;// 任意長整数型
using bint = mp::cpp_int;// 仮数部長が32の浮動小数点数型
using real32 = mp::number<mp::cpp_dec_float<32>>;// 仮数部長が1024の浮動小数点数型
using real1024 = mp::number<mp::cpp_dec_float<1024>>;// ついでに有理数型
using rat = boost::rational<bint>;
*/
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
//sortを降順にする時は greater<型>()
string x;
unordered_map<char,int> n;
int main(){ //srand((unsigned)time(NULL));
  while(1){
    getline(cin,x);
    if(x == "")break;
    for (int i = 0; i < x.length(); i++) {
      if('a' <= x[i] && x[i] <= 'z')n[x[i]]++;
      else if('A' <= x[i] && x[i] <= 'Z')n[x[i]+('a'-'A')]++;
    }
  }
  for (char i = 'a'; i <= 'z'; i++) {
    cout << i << " : " << n[i] << endl;
  }
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
using ll = long long;

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    
    rep(i, 1, N-1){
        vector<char>x;
        vector<char>y;
        rep(j, 0, i) x.push_back(S[j]);
        rep(j, i, N) y.push_back(S[j]);
        vector<bool>xb(x.size(), true);
        vector<bool>yb(y.size(), true);

        set<char> count;

        rep(j, 0, x.size()){
            rep(k, 0, y.size()){
                if(x[j] == y[k] && xb[j] == true && yb[k] == true){
                    xb[j] = false;
                    yb[k] = false;
                    count.insert(x[j]);
                }
            }
        }
        int tempans = count.size();
        ans = max(ans, tempans);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
#include <fstream>
#include<set>
//AtCoderC++.cpp

using namespace std;

template<typename T>
inline T ceiling(T n, T d) {
	return n % d == 0 ? n / d : n / d + 1;
}

long long fact(long n) {
	if (n == 1)return 1;
	else return n * (fact(n - 1));
}

int main() {
	long long N, K; cin >> N >> K;
	auto As = vector<long long>(N);
	for (int i = 0; i < N; i++) cin >> As[i];
	auto count = vector<long long>(N, 0);
	auto after_count = vector<long long>(N, 0);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			if (As[i] > As[j]) {
				++count[i];
				if (i < j)++after_count[i];
			}
		}
	}
	long long answer = 0;
	for (size_t i = 0; i < N; i++) {
		long long C = (K * (K - 1) / 2) % 1000000007;
		answer += count[i] * C + (K * after_count[i]);
		answer %= 1000000007;
	}
	cout << answer << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n;
    cin >> n;
    if(n%2){
        cout << 0 << endl;
        return 0;
    }
    intl a = 10;
    intl cnt = 0;
    while(true){
        cnt += (n/a);
        a *= 5;
        if(a > n)break;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  int H, W; cin >> H >> W;
  vector<string> G(H);
  vector<vector<int>> ans(H, vector<int>(W, -1));
  rep(i, H) cin >> G[i];

  rep(i, H) {
    rep(j, W) {
      if(G[i][j] == 'c')
        ans[i][j] = 0;
      if(j < W-1 && ans[i][j] >= 0)
        ans[i][j+1] = ans[i][j] + 1;
    }
  }

  rep(i, H) rep(j, W) printf("%d%c", ans[i][j], j==W-1?'\n':' ');
  
  return 0;
}

Measured memory_bytes: 3380
# -*- coding: utf-8 -*-

def lcm(a):
    from fractions import gcd
    x = a[0]
    for i in range(1, len(a)):
        x = (x * a[i]) // gcd(x, a[i])
    return x

A, B = map(int, input().split())

print(lcm([A, B]))


Measured memory_bytes: 5044
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7,N=1e5+5;
int mul(int a,int b){return (long long)a*b;}
typedef long long ll;
int n,x[N],y[N],d[N];
const double inf=1e20;
double getans(double mid)
{
    double mnx=inf,mxx=-inf,mny=inf,mxy=-inf;
    for(int i=1;i<=n;i++)
    {
        double xx=x[i],yy=y[i];
        if(d[i]==1) xx-=mid;
        if(d[i]==2) xx+=mid;
        if(d[i]==3) yy+=mid;
        if(d[i]==4) yy-=mid;
        mnx=min(mnx,xx);
        mxx=max(mxx,xx);
        mny=min(mny,yy);
        mxy=max(mxy,yy);
    }
    return (mxx-mnx)*(mxy-mny);
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        char s[5];
        scanf("%d%d%s",&x[i],&y[i],s);
        if(s[0]=='L') d[i]=1;
        else if(s[0]=='R') d[i]=2;
        else if(s[0]=='U') d[i]=3;
        else d[i]=4;
    }
    double l=0,r=1e10;
    for(int i=1;i<=1000;i++)
    {
        double len=(r-l)/3,mid=l+len,midmid=l+2*len;
        if(getans(midmid)>=getans(mid)) r=midmid;
        else l=mid;
    }
    printf("%f\n",getans((r+l)/2));
}


Measured memory_bytes: 1408
#include<bits/stdc++.h> 
using namespace std;
int main(){
  int n;
  cin>>n;
  int dp[n][3];
  for(int i=0;i<n;i++){
    cin>>dp[i][0];
    cin>>dp[i][1];
    cin>>dp[i][2];
  }
  for(int i=1;i<n;i++){
    dp[i][0]+=max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]+=max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]+=max(dp[i-1][1],dp[i-1][0]);
  }
  int ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
  cout<<ans;
  return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

#define Array_MAX 100000

int A[Array_MAX];

int partition(int r){
  int x = A[r];
  int i=-1,j,tmp;
  for(j=0;j<r;j++){
    
    if(A[j]<=x){
      i+=1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
      tmp = A[i+1];
      A[i+1]=A[r];
      A[r]=tmp;
  

    return i+1;
}
  

int main(){

  int  i,n;
  int fond;

  scanf("%d",&n);

  for(i=0;i<n;i++)scanf("%d",&A[i]);

  fond=partition(n-1);
  for(i=0;i<fond;i++) printf("%d ",A[i]);
  printf("[%d] ",A[fond]);
  for(i=fond+1;i<n-1;i++)  printf("%d ",A[i]);
  printf("%d\n",A[n-1]);


  return 0;
}

Measured memory_bytes: 988
n,m=map(int,input().split())
def yak1(n,m):
  l=[]
  for i in range(1,min(int((m)**(1/2))+1,(m//n)+1)):
    if m%i==0:
      l.append(i)
      if m//i!=i and m//i<=m//n:
        l.append(m//i)
  return l
print(max(yak1(n,m)))     


Measured memory_bytes: 3060
N,M=map(int,input().split())
p_lgngs=[[]for _ in range(N)]
l_peops=[[]for _ in  range(M+1)]
n_isl=0
lset=set()

data=[-1]*(M+1)
rank=[1 ]*(M+1)
def find(x):
  while data[x]!=-1: 
    x=data[x]
  return x
def unite(a,b):
  a,b=find(a),find(b)
  if a!=b:
    if  rank[a]<rank[b]:
      a,b=b,a
    if rank[a]==rank[b]:
      rank[a]+=1
    data[b]=a
    return True
  else: 
    return False
    
for i in range(N):
  k,*L=list(map(int,input().split()))
  p_lgngs[i]+=L
  for ll in L:
    l_peops[ll].append(i)
    lset.add(ll)
  for q in range(1,k):
    if unite(L[q-1], L[q]):
      n_isl-=1
if n_isl+len(lset)==1:
  print("YES")
else:
  print("NO")
exit(0)
print(n_isl+len(lset))
#print(lset)
#print(data)

Measured memory_bytes: 93728
#include <stdio.h>
#include <string.h>

int main(void){
    int size,i;
    char str[22];
    fgets(str, 22, stdin);
    size = strlen(str);
    for(i=size-2;0<=i;i--){
        printf("%c",str[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 524
"use strict";
const Main = (input) =>{
   let xs = input.trim().split('');
   let list = [];
   for(let i = 0; i<xs.length; i++){
     list.push({
     xs: xs[i],
     index: i
     });    
    }
   let ans ="";
   for(let j = 0; j<xs.length; j++){
     if(list[j].index % 2 == 0){
       if(list[j].xs != "L"){
       ans ="Yes";
        }else{
       ans="No";
       break;
        }
     }else if(list[j].index % 2 != 0){
       if(list[j].xs != "R"){
       ans ="Yes";
        }else{
       ans ="No";
       break;
        }
     } 
   }
  console.log(ans)
}
Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
void YESNO(bool), YesNo(bool);
template <class T1, class T2>
bool chmin(T1 &l, const T2 &r);
template <class T1, class T2>
bool chmax(T1 &l, const T2 &r);

void solve(long long N, long long P, string S)
{
  lli mod = P;
  map<lli, lli> mem;
  if (P == 2)
  {
    lli ans = 0;
    rep(i, N)
    {
      if (((S[i] - '0') % 2) == 0)
      {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return;
  }
  else if (P == 5)
  {
    lli ans = 0;
    rep(i, N)
    {
      if (S[i] == '0' || S[i] == '5')
      {
        ans += (i + 1);
      }
    }
    cout << ans << endl;
    return;
  }
  mem[0] = 1;
  lli cur = 0;
  lli pow = 1;
  rrep(i, S.size())
  {
    cur = cur + pow * lli(S[i] - '0');
    cur %= mod;
    pow *= 10;
    pow %= mod;
    mem[cur]++;
  }
  lli ans = 0;
  rep(i, P)
  {
    ans += mem[i] * (mem[i] - 1) / 2;
  }
  cout << ans << endl;
}

int main()
{
  long long N;
  scanf("%lld", &N);
  long long P;
  scanf("%lld", &P);
  string S;
  cin >> S;
  solve(N, P, S);
  return 0;
}

// -- lib
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }

template <class T1, class T2>
bool chmin(T1 &l, const T2 &r)
{
  return (l > r) ? (l = r, true) : false;
}

template <class T1, class T2>
bool chmax(T1 &l, const T2 &r)
{
  return (l < r) ? (l = r, true) : false;
}


Measured memory_bytes: 1284
H, W, K = map(int, input().split())
C = []
for _ in range(H):
    C.append(list(input()))
# print(f'{C=}')

# ビット全探索
# 147,456回なので各セルを毎回サーチする
ans = 0
for H_bit in range(1 << H):
    H_idx = []
    for i in range(H):
        if H_bit & (1 << i):
            H_idx.append(i)
    # print(f'{H_bit=}, {H_idx=}')

    for W_bit in range(1 << W):
        W_idx = []
        for i in range(W):
            if W_bit & (1 << i):
                W_idx.append(i)

        # print(f'{H_idx=}, {W_idx=}')

        cnt = 0
        for i in range(H):
            for j in range(W):
                if i not in H_idx and j not in W_idx and C[i][j] == '#':
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


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

using namespace std;

int main() {

	int n;
	cin >> n;
	// Cost to jump to stone i
	vector<int> cost(n);
	for (int &x : cost) {
		cin >> x;
	}

	// The shortest cost path to stone i is stored in dp[i]
	int dp[n] = {};
	dp[0] = 0;
	dp[1] = abs(cost[0] - cost[1]);
	for (int i = 2; i < n; ++i) {
		dp[i] = min(dp[i - 2] + abs(cost[i - 2] - cost[i]),
			    dp[i - 1] + abs(cost[i - 1] - cost[i]));
	}

	cout << dp[n - 1];

	return 0;
}


Measured memory_bytes: 1024
// 座標が最大の位置と最小の位置の距離が最短距離に等しい.
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> v(n);
  for(int i=0;i<n;i++) cin >> v[i];
  sort(v.begin(), v.end());
  cout << v[n-1] - v[0] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a[10],b[10],i,c[2],j,st;
  for(i=0;i<10;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<10;i++){
    scanf("%d",&b[i]);
  }
  for(i=0;i<10;i++){
    for(j=1;j<10;j++){
      if(a[j-1]<a[j]){
	st=a[j];
	a[j]=a[j-1];
	a[j-1]=st;
      }
      if(b[j-1]<b[j]){
	st=b[j];
	b[j]=b[j-1];
	b[j-1]=st;
      }
    }
  }
  c[0]=0;
  c[1]=0;
  for(i=0;i<3;i++){
    c[0]+=a[i];
    c[1]+=b[i];
  }
  printf("%d %d\n",c[0],c[1]);
  return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Text.RegularExpressions;

namespace ITP1_8
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] sl = Console.ReadLine().ToCharArray().Select(e => e.ToString()).ToArray();
            Regex bre = new Regex(@"^[A-Z]$");
            Regex sre = new Regex(@"^[a-z]$");
            foreach(string s in sl)
                Console.Write(bre.IsMatch(s) ? s.ToLower() :
                              sre.IsMatch(s) ? s.ToUpper() : s);
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 11544
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 

//power of 2 ...n&(n-1)==0

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	 //ll testcase;
	 //cin>>testcase;
	 //for(ll t=0;t<testcase;t++)
	{
		// use long long
		//donot memeset other than 0 or 1 or -1
		//segmentation fault-> check for uninitialized global variable or out of bounds
		//always check for bottle neck (whether original constraints can be reduced by introducing some condition)
		//dont rush to writing code think through the logic	
		ll n;
		cin>>n;
		string out="";
		while(1)
		{
			ll add=(ll)(n%(ll)26);
			n=(ll)n/(ll)26;
			if(add==0)
			{
				n--;
				out+='z';
			}
			else
			{
				out+=(char)(96+add);
			}
			if(n<=0)
				break;
		}
		reverse(out.begin(),out.end());
		cout<<out<<'\n';
	}
	return 0;
}





























































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

using namespace std;

int x;

bool ok(int mid) {
  return (long long) mid * (mid + 1) >= 2 * x;
}

int main() {
  scanf("%d", &x);
  int low = 1, high = (int) 1e9, mid;
  while (low < high) {
    mid = low + high >> 1;
    if (ok(mid)) high = mid;
    else low = mid + 1;
  }
  printf("%d\n", low);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(  (a%2 == 0 && b%2 == 0) ||  (a%2==0 && c%2==0) || (b%2==0 && c%2==0) ){
	cout<<"Tem"<<endl;
    }else{
	cout<<"Hom"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3112
#include<iostream>
using namespace std;
int main(){
int a,b,c;
cin>>a>>b>>c;

if(a==b&&a==c&&c==b){cout<<"1";}
else{if(a==b){cout<<"2";}
else{if(a==c){cout<<"2";}
else{if(c==b){cout<<"2";}
else{cout<<"3";}}}}


cout<<endl;

	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
using namespace std;

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

    string s;
    cin>>s;
    int a=INF,z=0;

    rep(i,s.size()){
	if(s[i]=='A'){
	    a=min(a,i);
	}
	if(s[i]=='Z'){
	    z=max(z,i);
	}
    }
    cout<<z-a+1<<'\n';

    return 0;
}


Measured memory_bytes: 720
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin>>n;
    vector<ll> d(n);
    for(ll i=0;i<n;i++) cin>>d[i];
    sort(all(d));
    cout<<max((ll)0,d[n/2]-d[n/2-1])<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cassert>
#include <queue>
using namespace std;

int N, C;
int b[11][11];
int v[11][11];

bool in(int x, int y) {
	return 1 <= x && x <= y && 1 <= y && y <= N;
}

struct P {
	int x, y;
};

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

int calc() {
	int ret = 0;
	memset(v, 0, sizeof v);
	for(int sy = 1; sy <= N; sy++) {
		for(int sx = 1; sx <= sy; sx++) {
			if(v[sy][sx] || b[sy][sx] == 0) continue;
			int num = b[sy][sx];
			queue<P> q;
			q.push(P{ sx, sy });
			v[sy][sx] = true;
			int vnum = 0;
			bool zero = false;
			while(q.size()) {
				vnum++;
				int x = q.front().x, y = q.front().y;
				q.pop();
				for(int k = 0; k < 6; k++) {
					int nx = x + dx[k], ny = y + dy[k];
					if(!in(nx, ny)) continue;
					if(!v[ny][nx] && b[ny][nx] == num) {
						v[ny][nx] = true;
						q.push(P{ nx, ny });
					}
					else if(b[ny][nx] == 0) zero = true;
				}
			}
			if(!zero) {
				if(num != C) ret += vnum;
				else ret -= vnum;
			}
		}
	}
	return ret;
}

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

	while(cin >> N >> C, N | C) {
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= i; j++) {
				cin >> b[i][j];
			}
		}

		int ans = -1000000;
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= i; j++) {
				if(b[i][j] == 0) {
					b[i][j] = C;
					ans = max(ans, calc());
					b[i][j] = 0;
				}
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 3124
#include <iostream>
#include <iomanip>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void)
{
    string T, P;
    cin >> T >> P;
    int ans = 0;
    for (ans = 0; ans < (int)T.length() - (int)P.length() + 1; ans++)
    {
        if (T.compare(ans, P.length(), P) == 0)
        {
            // ans += P.length() - 1;
            cout << ans << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
# define int long long
# define mo 1000000007
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

signed main()
{
   gok
    int a,b;
    cin>>a>>b;
    map<pair<int,int>,int> mp;
    mp[{1,2}]=3;
     mp[{2,3}]=1;
      mp[{1,3}]=2;
      if(a>b)
        swap(a,b);
      cout<<mp[{a,b}];
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef long long ll;
#define rep(i,l,r) for(int i=l; i<(int)(r); i++)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
int upcmpll(const void *a, const void *b){
    return (*(ll*)a == *(ll*)b ? 0 : (*(ll*)a > *(ll*)b ? 1 : -1));
}
void sort_u(ll *a, int n){ qsort(a, n, sizeof(ll), upcmpll); }

int A[25], m[202], ch[2020] = {0};

int main(){
    int n; scanf("%d", &n);
    rep(i,0,n) scanf("%d", A+i);
    int q; scanf("%d", &q);
    rep(i,0,q) scanf("%d", m+i);

    rep(bit, 1, (1 << n)) {
        int tmp = 0;
        rep(i, 0, n) {
            //i番目のビットが立っていた時の処理
            if (bit & (1<<i)) {
                tmp += A[i];
            }
        }
        if(tmp <= 2000) ch[tmp]++;
    }

    rep(i,0,q){
        printf("%s\n", (ch[m[i]] > 0?"yes":"no"));
    }
    return 0;
}


Measured memory_bytes: 2100
while True:
    h,w = input().split()
    h,w = int(h),int(w)
    if h==0 and w==0:
        break
    s1 = '#'*w
    s2 = '#'+'.'*(w-2)+'#'
    print(s1)
    for i in range(h-2):
        print(s2)
    print(s1)
    print()


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

int main()
{
  int N, K;
  string S;
  cin >> N >> K >> S;

  // 文字コードの差分を引く
  S[K-1] -= 'A' - 'a';
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = []
for i in range(N):
	A.append(int(input()))

A.sort()

i = 0

ans = 0

while i != len(A):
	num = A[i]
	count = 0
	j = i
	while A[j] == num:
		count += 1
		j += 1
		if j == len(A):
			break

	if count % 2 == 1:
		ans += 1
	i += count
	
print(ans)

Measured memory_bytes: 7388
#include <iostream>
#include <vector>
#include <set>
#include <limits>
#include <utility>
using i64 = long long;

int main() {
    constexpr int inf = std::numeric_limits<int>::max() / 10;
    int n, m;
    std::cin >> n >> m;

    std::vector<int> ret(m);
    std::set<std::pair<int, int>> pc, cp;
    for (int i = 0; i < m; i++) {
        pc.emplace(i, 0);
        cp.emplace(0, i);
    }

    for (int i = 0; i < n; i++) {
        int a, b;
        std::cin >> a >> b;
        auto it = pc.lower_bound(std::make_pair(a - 1, 0));
        std::pair p { inf, 0 };
        while (it != pc.end() && it->first <= b) {
            p = *it;
            cp.erase(std::make_pair(it->second, it->first));
            it = pc.erase(it);
        }
        if (p.first < m && b < m) {
            const int pos = b, cost = b - p.first + p.second;
            pc.emplace(pos, cost);
            cp.emplace(cost, pos);
        }

        if (cp.empty()) std::cout << "-1\n";
        else std::cout << 1 + i + cp.begin()->first << '\n';
    }

    return 0;
}


Measured memory_bytes: 22644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int a,b,c,d;
	cin >> a>>b>>c>>d;
	int k = max(a,c);
  	int l = min(b,d);
    if(k>=l) cout <<0<<endl;
    else cout <<l-k<<endl;
}

Measured memory_bytes: 256
package main

import (
	f "fmt"
)

func main() {

	var num int
	f.Scan(&num)
	var sum int
	f.Scan(&sum)

	var x, y int
	for x = 0; x <= num; x++ {
		for y = 0; y <= num-x; y++ {
			if 10000*x+5000*y+1000*(num-x-y) == sum {
				f.Printf("%d %d %d", x, y, num-x-y)
				return
			}
		}
	}

	f.Println("-1 -1 -1")

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long int
#define MAX 1000007
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
vector <int> v;
void SieveOfEratosthenes(int n) 
{ 
	//n = 100005;
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          v.push_back(p);
}
void solve() {
 	int n;
 	cin >> n;
 	SieveOfEratosthenes(100005);
 	auto it = (lower_bound(v.begin(), v.end(), n) - v.begin());
    cout << v[it];
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
#define ar array 

void test_case() {
	int x;
	cin >> x;
	if(x==1)
		cout<<0;
	else
		cout<<1;
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T = 1;
	//cin >> T;
	while(T--){
		test_case();
	}
}


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

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

	string s = to_string(n);

	while (!(s.at(0) == s.at(1) && s.at(1) == s.at(2)))
	{
		n++;
		s = to_string(n);
	}

	cout << s << endl;
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    string s;
    cin >> s;
    int l = s.length();
    if(s[l - 1] == 's'){
    	cout << s << "es";
    }else{
    	cout << s << "s";
    }
    
	return 0;
}

Measured memory_bytes: 3648
import math
n,d=map(int,input().split())
x=[list(map(int,input().split()))for _ in range(n)]
def a(a,b):
  aa=0
  for i in range(d):aa+=abs(a[i]-b[i])**2
  if math.sqrt(aa)%1==0:return 1
  return 0
ans=0
for i in range(n-1):
  for j in range(i+1,n):ans+=a(x[i],x[j])
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

constexpr ll mod = 1000000007;
 
int main() {
    int n = 0;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }
    
    int cnt0 = 0;
    for (int x : a) {
        if (x == 0) {
            cnt0++;
        }
    }
 
    if (cnt0 > 3) {
        cout << 0 << endl;
        return 0;
    }
 
    ll color = (cnt0 == 1) ? 3 : 6;
 
    ll ans = 1;
    vector<ll> cur(1e5, 0);
    for (int i=0; i<n; i++) {
        if (a.at(i) == 0) {
            cur.at(0)++;
        } else {
            ans *= cur.at(a.at(i)-1);
            ans %= mod;
            cur.at(a.at(i))++;
            cur.at(a.at(i)-1)--;
        }
    }
    
    cout << ans * color % mod << endl;
 
    return 0;
}


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

const ll p = 1e9+7;
const int MAXN = 1e5+5;

int n, m, q;
int a[MAXN], take[MAXN];
vector<int> pl[MAXN];

map<int, int> s;

int main() {
	cin >> n >> m >> q;
	for (int i = 0; i < q; ++i) {
		cin >> a[i]; a[i]--;
		pl[a[i]].push_back(i);
	}
	for (int i = 0; i < m; ++i)
		s[i] = 1;

	for (int i = 0; i < n; ++i)
		take[i] = q;
	for (int i = q-1; i >= 0; --i) {
		if (s.empty())
			break;
		if (s.count(a[i]) == 0)
			continue;
		int fir = (*s.begin()).first;
		s.erase(a[i]);
		int ct = n-1;
		if (fir == a[i]) {
			for (int j = pl[a[i]].size()-1; j >= 0; --j) {
				if (ct == -1)
					break;
				if (pl[a[i]][j] <= take[ct]) {
					take[ct] = pl[a[i]][j]; ct--;
				}
			}

			for (int j = ct; j >= 0; --j)
				take[ct] = -1;
		} else {
			for (int j = pl[a[i]].size()-1; j >= 0; --j) {
				if (ct == -1)
					break;
				if (pl[a[i]][j] <= take[ct]) {
					take[ct] = pl[a[i]][j]; ct--;
				}
			}

			if (ct >= 0) {
				cout << "No\n"; return 0;
			}
		}
	}

	cout << "Yes\n";
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<vi> vii;
typedef map<int, int> mp;
typedef set<int> set;
typedef multiset<int> mset;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
typedef vector<int64> vi64;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define form(i,j,k,l) for(int i=j;i<int(k);i+=l)
#define rform(i,j,k,l) for(int i=int(j);i>int(l);i-=l)
#define rep(i, j) for(int i=0;i<int(j);i++)
#define rrep(i, j) for(int i=int(j);i>=0;i--)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define forc(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000009
#define read(type) readInt<type>()
#define F first
#define S  second
const double pie = acos(-1.0);
template <typename T>
T Max(T x, T y)
{
	return (x > y) ? x : y;
}
template <typename T>
T Min(T x, T y)
{
	return (x > y) ? y : x;
}

int gcd(int n1, int n2)
{
	if (n2 != 0) return gcd(n2, n1 % n2);
	else return n1;
}
int main()
{	fast;
 /*
 
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif*/
	string s;
	string t;
	cin >> s >> t;
	vector<vector<int > >dp(s.length() + 1, vector<int>(t.length() + 1, 0));
	for (int i = 1; i <= s.length(); i++)
	{	for (int j = 1; j <= (int)t.length(); j++)
		{	if (s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
			{	dp[i][j] = Max(dp[i - 1][j], dp[i][j - 1]);
			}
		}

	}
	int l = dp[s.length()][t.length()];
	int i = s.length(), j = t.length();
	string str;
	while (l >= 1 && i >= 1  && j >= 1)
	{	
		if (s[i - 1] == t[j - 1])
		{	str =  s[i - 1] + str;
			i--;
			j--;
			l--;
		}

		else if (dp[i][j] == dp[i - 1][j])
		{	i--;
		}
		else if (dp[i][j] == dp[i][j - 1])
		{	j--;

		}
	}
	cout << str;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  for (int i = 0; i < k && i*i < n; i++) {
    vector<int> imos(n+1);
    rep(j, n) {
      imos[max(j-a[j], 0)]++;
      imos[min(j+a[j]+1, n)]--;
    }
    rep(j, n)
      imos[j+1] += imos[j];
    a = imos;
  }
  rep(i, n) {
    if (i)
      cout << ' ';
    cout << a[i];
  }
  cout << endl;
  return 0;
}

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

using namespace std;

inline long long gcd(long long a,long long b){
	for(long long r;b;) r=a%b,a=b,b=r;
	return a;
}

inline bool jud(long long A,long long B,long long C,long long D){
	if(A<B || D<B) return false;
	if(C>=B) return true;
	long long g=gcd(B,D);
	return B-g+A%g<=C;
}

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		long long A,B,C,D;
		scanf("%lld%lld%lld%lld",&A,&B,&C,&D);
		puts(jud(A,B,C,D) ? "Yes":"No");
	}
	return 0;
}

Measured memory_bytes: 256
import sys
S = input()
S = S[::-1]
while S != '':
    if S[:5] == 'maerd':
        S = S[5:]
    elif S[:5] == 'esare':
        S = S[5:]
    elif S[:6] == 'resare':
        S = S[6:]
    elif S[:7] == 'remaerd':
        S = S[7:]
    else:
        print('NO')
        exit()
print('YES')

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)2e5 + 9;
int p[N];

int main(){
  fastIO;
  int n;
  cin >> n;
  int q;
  for(int i = 1; i <= n; i ++ ){
    cin >> q;
    p[q] = i;
  }
  int cnt = 1;
  int mx = 1;
  for(int i = 1; i <= n; i ++ ){
    mx = max(mx, cnt);
    if(i < n){
      if(p[i] < p[i + 1])
        cnt ++ ;
      else
        cnt = 1;
    }
  }
  cout << n - mx;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
    using namespace std;
    const int N = 350;
    const int INF = 1<<30;

    int a, b, s, t, sum, d[N][N], f[N][N];

    inline void ck_min( int &a, int b ) { if( a > b ) a = b; }
    inline void ck_max( int &a, int b ) { if( a < b ) a = b; }

    inline bool check( int x, int y, int val )
    {
        int res = INF;
        for( int i = 0; i <= 100; i ++ )
            for( int j = 0; j <= 100; j ++ )
                if( f[i][j] >= 0 ) ck_min( res, i*x + j*y + f[i][j] );

    //  printf( "x:%d, y:%d, res:%d\n", x, y, res );
        return res == val;
    }

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

        scanf( "%d%d", &a, &b );
        for( int i = 1; i <= a; i ++ )
            for( int j = 1; j <= b; j ++ )
                scanf( "%d", &d[i][j] );

        s = 201, t = 202; 
        // s --> 1 --> 2 --> ... --> 100
        // t <-- 101 <-- 102 <-- ... <-- 200

        for( int i = 0; i <= 100; i ++ )
            for( int j = 0; j <= 100; j ++ )
            {
                int tmp = -INF;
                for( int _a = 1; _a <= a; _a ++ )
                    for( int _b = 1; _b <= b; _b ++ )
                        ck_max( tmp, d[_a][_b] - i*_a - j*_b ); 
                f[i][j] = tmp; 
                if( f[i][j] < 0 ) break;

                sum ++;
    //          printf( "i:%d, j:%d, f:%d\n", i, j, f[i][j] );
            }

        for( int i = 1; i <= a; i ++ )
            for( int j = 1; j <= b; j ++ )  
                if( !check( i, j, d[i][j] ) ) {
                    printf( "Impossible\n" ); return 0;
                } 

        printf( "Possible\n" );

        printf( "%d %d\n", 202, sum+200 );
        for( int i = 1; i < 100; i ++ )
            printf( "%d %d X\n%d %d Y\n", i, i+1, i+101, i+100 );

        printf( "%d %d X\n%d %d Y\n", s, 1, 101, t );
        for( int i = 0; i <= 100; i ++ )
            for( int j = 0; j <= 100; j ++ )
                if( f[i][j] >= 0 )  printf( "%d %d %d\n", !i ? s : i, !j ? t : j+100, f[i][j] );

        printf( "%d %d\n", s, t );

        return 0;
    }

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

public class Main {

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

  private void solve() {
    try(InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out)) {

      final int A = in.nextInt();
      final int B = in.nextInt();
      final int Q = in.nextInt();

      long[] s = new long[A+1];
      for (int i = 0; i < A; i++) {
        s[i] = in.nextLong();
      }
      s[A] = 1L << 40;

      long[] t = new long[B+1];
      for (int i = 0; i < B; i++) {
        t[i] = in.nextLong();
      }
      t[B] = 1L << 40;

      for (int q = 0; q < Q; q++) {
        long x = in.nextLong();
        long dist = 1L << 50;

        for (int c = 0; c < 2; c++) {
          long[] af = c == 0 ? s : t;
          long[] as = c == 0 ? t : s;

          for (int i = 0; i < 2; i++) {
            int posF = binarySearch(af, x) + i;
            long df = af[posF];

            for (int j = 0; j < 2; j++) {
              int posS = binarySearch(as, x) + j;
              long ds = as[posS];
              
              long d = Math.abs(x - df);
              d += Math.abs(df - ds);
              dist = Math.min(dist, d);
            }
          }
        }

        out.println(dist);
      }
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }

  private int binarySearch(long[] arr, long x) {
    int left = 0;
    int right = arr.length;

    while(right - left > 1) {
      int mid = (left + right) / 2;
      if(arr[mid] <= x)  left = mid;
      else right = mid;
    }
    return left;
  }

  static class InputReader implements AutoCloseable {
    public BufferedReader br;
    public StringTokenizer st;

    public InputReader(InputStream stream) {
      br = new BufferedReader(new InputStreamReader(stream), 32768);
      st = null;
    }
    public String next() {
      if (st == null || !st.hasMoreTokens()) {
        try { st = new StringTokenizer(br.readLine());
        } catch (IOException e) {
          throw new UncheckedIOException(e);
        }
      }
      return st.nextToken();
    }
    public int nextInt() { return Integer.parseInt(next()); }
    public long nextLong() { return Long.parseLong(next()); }
    int[] mapInt(int len) {
      int[] ret = new int[len];
      for (int i = 0; i < len; i++) ret[i] = Integer.parseInt(next());
      return ret;
    }
    long[] mapLong(int len) {
      long[] ret = new long[len];
      for (int i = 0; i < len; i++) ret[i] = Long.parseLong(next());
      return ret;
    }
    @Override public void close() throws IOException { br.close(); }
  }
}

Measured memory_bytes: 48668
#include<iostream>

using namespace std;

int G[55][55];
int a[55],b[55];
bool used[55];
int N,M;

void dfs (int x) {
    if(used[x]) return ;
    used[x] = true;
    for(int i=1; i<=N; i++) if(G[x][i]) dfs(i);
}

int main () {
    cin >> N >> M;
    for(int i=0; i<M; i++) {
        cin >> a[i] >> b[i];
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }

    int ans = 0;
    for(int i=0; i<M; i++) {
        bool bri = false;
        for(int j=1; j<=N; j++) used[j] = false;
        G[a[i]][b[i]] = G[b[i]][a[i]] = 0;
        dfs(1);
        for(int j=1; j<=N; j++) if(!used[j]) bri = true;
        if(bri) ans++;
        G[a[i]][b[i]] = G[b[i]][a[i]] = 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

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


Measured memory_bytes: 256