akhauriyash/Code-Regression huggingface dataset:
import sys
from collections import namedtuple, defaultdict
from math import gcd
input = sys.stdin.readline

class Point:
    def __init__(self, x, y):
        g = gcd(abs(x), abs(y))

        x //= g
        y //= g

        if x < 0:
            x *= -1
            y *= -1

        elif x == 0 and y < 0:
            y *= -1

        self.x = x
        self.y = y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def __hash__(self):
        return hash((self.x, self.y))

    def __repr__(self):
        return f'({self.x}, {self.y})'

def main():
    n = int(input())
    
    p = []
    d = defaultdict(lambda: 0)
    zeros = 0

    for _ in range(n):
        x, y = map(int, input().split())

        if x == 0 and y == 0:
            n -= 1
            zeros += 1
            continue

        p.append(Point(x, y))
        d[p[-1]] += 1

    MOD = 10 ** 9 + 7

    pw = [ pow(2, i, MOD) for i in range(n + 1) ]

    ans = 1
    tot = 0

    for x in d.keys():
        if x.x > 0 and x.y >= 0 and Point(-x.y, x.x) in d:
            s = d[x]
            t = d[Point(-x.y, x.x)]

            tot += s + t
            value = (pw[s] + pw[t] - 1 + MOD) % MOD
            ans = ans * value % MOD

    ans = ans * pw[n - tot] % MOD
    ans = (ans - 1 + MOD + zeros) % MOD

    print(ans)
main()


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

int n;
string str;
vector<vector<int>> v(2222);
int sumDist[2222];
int minDist[2222];
int hasPoint[2222];

void dfs(int node, int pre){
	sumDist[node] = 0;
	minDist[node] = 0;
	hasPoint[node] = (str[node] == '1' ? 1 : 0);
	if(pre != -1 && v[node].size() == 1) return;

	vector<P> vec;
	REP(i, v[node].size()){
		int aite = v[node][i];
		if(aite == pre) continue;

		dfs(aite, node);
		//cout << " in dfs " << aite << " " << hasPoint[aite] << " " << sumDist[aite] << " " << minDist[aite] << endl;

		sumDist[aite] += hasPoint[aite];
		minDist[aite] += hasPoint[aite];

		sumDist[node] += sumDist[aite];
		hasPoint[node] += hasPoint[aite];
		vec.EB(sumDist[aite], minDist[aite]);
	}

	sort(ALL(vec), greater<P>());

	if(vec[0].FI > sumDist[node] / 2) {
		int now = vec[0].FI;
		for(int i = 1;i < vec.size();i++){
			now -= vec[i].FI;
		}
		if(now > vec[0].FI - vec[0].SE){
			now -= vec[0].FI - vec[0].SE;
		}
		else {
			now %= 2;
		}
		minDist[node] = now;
	}
	else {
		int now = 0;
		REP(i, vec.size()){
			now += vec[i].FI % 2;
		}
		minDist[node] = now % 2;
	}
}

int check(int root){
	dfs(root, -1);
	//cout << "check " << root << " " << hasPoint[root] << " " << sumDist[root] << " " << minDist[root] << endl;

	if(minDist[root] == 0){
		return sumDist[root];
	}
	else {
		return INF;
	}
}

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

	cin >> n;
	cin >> str;
	REP(i, n-1){
		int a, b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}

	int ans = INF;
	REP(i, n)ans = min(ans, check(i));

	cout << (ans == INF ? -1 : ans / 2) << endl;

	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main() {
    int n, m; cin >> n >> m;
    vector<int> x(m);
    rep(i, m) cin >> x[i];
    if(n >= m) cout << 0;
    else {
        sort(x.begin(), x.end());
        int len = x[m-1] - x[0];
        vector<int> tmp(m-1);
        rep(i, m-1) {
            tmp[i] = x[i+1] - x[i];
        }
        sort(tmp.begin(), tmp.end());
        reverse(tmp.begin(), tmp.end());
        rep(i, n-1) {
            len -= tmp[i];
        }
        cout << len;
    }
}


Measured memory_bytes: 1024
// practice with kaiboy, coached by rainboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int l = sc.nextInt();
		int[][] aa = new int[n][n];
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				aa[i][j] = l + 1;
		while (m-- > 0) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			int c = sc.nextInt();
			if (c <= l)
				aa[i][j] = aa[j][i] = c;
		}
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					aa[i][j] = Math.min(aa[i][j], aa[i][k] + aa[k][j]);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++)
				aa[i][j] = aa[i][j] <= l ? 1 : n;
		for (int k = 0; k < n; k++)
			for (int i = 0; i < n; i++)
				for (int j = 0; j < n; j++)
					aa[i][j] = Math.min(aa[i][j], aa[i][k] + aa[k][j]);
		int q = sc.nextInt();
		while (q-- > 0) {
			int i = sc.nextInt() - 1;
			int j = sc.nextInt() - 1;
			int k = aa[i][j];
			if (k == n)
				k = 0;
			println(k - 1);
		}
	}
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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; }


const ll MRINF = 5000000000000000;
int main() {

    REP(i, 5){
        int s;
        cin >> s;
        if(s==0){
            cout << i+1 << endl;
            return 0;
        }
    }

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3576
s = gets.chomp
tmp = sum = 0
h = Hash.new(0)
h[0] += 1

s.size.times do |i|
  tmp += s[-1 - i].to_i * 10.pow(i, 2019)
  h[tmp % 2019] += 1
end

h.values.each { |i| sum += i * (i - 1) }

puts sum / 2

Measured memory_bytes: 14616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int N;
    cin>> N;
    vector<int>A(N);
    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    sort(A.begin(),A.end());
    for(int i=0;i<N-1;i++){
        if(A[i]==A[i+1]){
            cout <<"NO";
            break;
        }else if(i==N-2){
            cout << "YES";
        }
    }

}

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

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int N,old,now;
  int ans = 0;
  cin >>N>>now;
  ans += now;
  check(ans);
  rep(i, N-2) {
    old=now;
    cin >> now;
    ans += min(old,now);
  }
  check(ans);
  ans += now;
  check(ans);
  cout << ans;
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

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

  string S;
  cin >> S;

  vector<LL> v(S.size() + 1,0);

  LL cnt = 0;

  REP(i,S.size()){
    if(S[i]=='<'){
      cnt++;
      v[i + 1] = max(v[i+1],cnt);
    }else{
      cnt = 0;
    }
  }

  cnt = 0;

  REP(j,S.size()){
    LL i = S.size() - j -1;
    if (S[i] == '>')
    {
      cnt++;
      v[i] = max(v[i],cnt);
    }else{
      cnt = 0;
    }
  }

  LL sum = 0;
  REP(i, v.size())
  {
    sum += v[i];
  }

  cout << sum << endl;
}
// 0<3>2>1>0<1<2>0<1<2<3<4<5>2>1>0<1


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

int main() {
    int n, b, f, r, v, room[100][100][100] = {};
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> b >> f >> r >> v;
        room[b][f][r] += v;
    }
    for (int i = 1; i <= 4; ++i) {
        for (int j = 1; j <= 3; ++j) {
            for (int k = 1; k <= 10; ++k) {
                cout << ' ' << room[i][j][k];
            }
            cout << endl;
        }
        if (i <= 3) cout << "####################" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 6980
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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; }

// 無限大の値
const ll  LINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int x;
  cin >> x; 
  cout << (x < 1200 ? "ABC" : "ARC") << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> v, w;
  rep(i,N){
    ll a;
    cin >> a;
    v.push_back(a);
  }
  rep(i,M){
    ll a;
    cin >> a;
    w.push_back(a);
  }

  
  ll ret = 0;
  
  vector<ll> sum;
  sum.push_back(0);
  ll base = 0;
  rep(i,w.size()){
    base += w[i];
    if(base <= K) ret = max(ret, (ll)(i+1));
    sum.push_back(base);
  }

  base = 0;
  rep(i,v.size()){
    base += v[i];
    ll rem = K-base;
    if(rem < 0) continue;
    
    ll lb = 0, ub = sum.size();
    while(ub-lb>1){
      int m = (lb+ub)/2;
      if(sum[m] <= rem) lb = m;
      else ub = m;
    }

    ret = max(ret, i+1 + lb);
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 9556
def solve():
    s = input()
    t = input()

    for i in range(len(s)):
        if s[i:] + s[:i] == t:
            return True
    return False


def main():
    ans = solve()
    if ans:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    string s; cin>>s;
    vector<int> sumw(n+10, 0), sumb(n+10, 0);
    for(int i=0; i<n; i++){
        if(s[i] == '.'){
            sumw[i+1] = sumw[i] + 1;
            sumb[i+1] = sumb[i];
        }
        else{
            sumw[i+1] = sumw[i];
            sumb[i+1] = sumb[i] + 1;
        }
    }

    int ans=1e9;
    for(int i=0; i<=n; i++){
        int rb = sumw[n] - sumw[i];
        int lw = sumb[i];

        chmin(ans, rb + lw);
    }

    cout << ans << endl;
}

Measured memory_bytes: 2180
n = int(raw_input())
S = []
for _ in range(n):
    S.append(int(raw_input()))
S.sort()
sumS = sum(S)
sumS2 = sumS
i = 0
while sumS2 % 10 == 0 and i < n:
    sumS2 = sumS - S[i]
    i += 1
if sumS2 % 10 == 0:
    print 0
else:
    print sumS2

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;
  cin>>n;
  vector<int>h(n);
  rep(i,n) cin>>h[i];
  int cm=-1;
  rep(i,n){
    if(cm<=h[i]-1){
      cm=h[i]-1;
    }
    else if(cm<=h[i])
      cm=h[i];
    else{
      cout<<"No"<<endl;
      return 0;
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 640
import java.util.*

private val WHITESPACE = "\\s+".toRegex()

private fun readLn() = readLine()!!
private fun readList() = readLn().split(WHITESPACE)

// helps split strings into multiple tokens
private var tokenizer = StringTokenizer("")
private fun read(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), " ")
    return tokenizer.nextToken()
}

private fun readInt() = read().toInt()
private fun readLong() = read().toLong()
private fun readDouble() = read().toDouble()

private fun readIntList() = readList().map { it.toInt() }
private fun readLongList() = readList().map { it.toLong() }
private fun readDoubleList() = readList().map { it.toDouble() }

private fun readIntArray(n: Int = 0) =
    if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }

fun main() {
    val s = readLn()

    val sum = s.toCharArray().sumBy { it - '0' }
    println(if (sum % 9 == 0) "Yes" else "No")
}


Measured memory_bytes: 39588
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
const int infty = 1000000007;

string A;
int N;

void clear(bool* ary) {
  fill(ary, ary+26, false);
}

int first(bool* ary) {
  for (auto i = 0; i < 26; ++i) {
    if (!ary[i]) return i;
  }
  assert(false);
  return infty;
}

int main () {
  cin >> A;
  N = A.size();
  vector<int> V;
  V.push_back(N);
  int size = 0;
  bool used[26];
  clear(used);
  for (auto i = N-1; i >= 0; --i) {
    if (!used[A[i] - 'a']) {
      ++size;
      used[A[i] - 'a'] = true;
    }
    if (size == 26) {
      size = 0;
      clear(used);
      V.push_back(i);
    }
  }
  V.push_back(0);
  reverse(V.begin(), V.end());
  vector<string> W;
  for (auto i = 0; i < (int)V.size()-1; ++i) {
    W.push_back(A.substr(V[i], V[i+1] - V[i]));
  }
  vector<int> ans;
  clear(used);
  for (auto x : W[0]) {
    used[x - 'a'] = true;
  }
  ans.push_back(first(used));
  for (auto i = 1; i < (int)W.size(); ++i) {
    string str = W[i];
    char c = 'a' + ans[i-1];    
    int found = infty;
    for (auto j = 0; j < (int)str.size(); ++j) {
      if (str[j] == c) {
        found = j;
        break;
      }
    }
    assert(found < infty);
    clear(used);
    for (auto j = found+1; j < (int)str.size(); ++j) {
      used[str[j] - 'a'] = true;
    }
    ans.push_back(first(used));
  }
  string ret = "";
  for (auto x : ans) {
    string t{(char)('a' + x)};
    ret = ret + t;
  }
  cout << ret << endl;
}


Measured memory_bytes: 1156
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = Date.now();
  Main();
  var end = Date.now() - start;
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		var tmp = nextIntArray();
		for(var j = 0; j < N - 1; j++){
			tmp[j]--;
		}
		list[i] = {
			next : tmp,
			lastIndex : 0
		};
	}
	var queue = [];
	var output = 0;
	function check(left){
		if(list[left].lastIndex == N - 1){
			return;
		}
		var right = list[left].next[list[left].lastIndex];
		if(list[right].lastIndex == N - 1){
			return;
		}
		if(list[right].next[list[right].lastIndex] == left){
			if(right < left){
				var tmp = left;
				left = right;
				right = tmp;
			}
			if(queue.indexOf(left + ":" + right) == -1){
				var add = left + ":" + right;
				queue.push(add);
			}
		}
	}
	for(var i = 0; i < N; i++){
		check(i);
	}
	while(queue.length > 0){
		var tmpQueue = queue;
		queue = [];
		output++;
		while(tmpQueue.length > 0){
			var tmp = tmpQueue.shift();
			var L = myconv(tmp.split(":")[0],1);
			var R = myconv(tmp.split(":")[1],1);
			list[L].lastIndex++;
			list[R].lastIndex++;
			check(L);
			check(R);
		}
	}
	for(var i = 0; i < N; i++){
		if(list[i].lastIndex != N - 1){
			output = -1;
		}
	}
	myout(output);
}


Measured memory_bytes: 77708
# from math import sqrt
# from heapq import heappush, heappop
# from collections import deque
from functools import reduce

# a, b = [int(v) for v in input().split()]


def main():
    N, M = [int(v) for v in input().split()]
    A = list(set([int(v) // 2 for v in input().split()]))

    def func(a):
        count = 0
        while a % 2 == 0:
            count += 1
            a //= 2
        return count

    fa = func(A[0])
    for a in A[1:]:
        if func(a) != fa:
            print(0)
            exit()

    def gcd(a, b):
        if b == 0:
            return a
        return gcd(b, a % b)

    def lcm(v1, v2):
        return v1 * v2 // gcd(v1, v2)

    a_lcm = reduce(lambda v1, v2: lcm(v1, v2), A)
    if a_lcm > M:
        print(0)
        exit()

    print((M // a_lcm + 1) // 2)


main()


Measured memory_bytes: 14748
// author -> LetsGoAC
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using    namespace std;
using    namespace __gnu_pbds; 
#define  ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
//  ordered_set<int> os;
//  order_of_key (k) : Number of items strictly smaller than k .
//  *find_by_order(k) : K-th element in a set (counting from zero).
typedef  long double ld;
#define  int long long
typedef  pair<int,int> pii;
#define  RAGE ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  rep(i,n) for(i=0; i <n; i++)
#define  repv(i,k,n) for(int i=k; i<=n; i++)
#define  pb push_back
#define  mp make_pair
#define  F  first
#define  S  second
#define  sz(x)  (int)x.size()
#define  all(v) v.begin(),v.end()
#define  endl '\n'
#define  deb(x) cout<<#x<<" = "<<x<<endl
#define  gcd   __gcd
#define  inf   LLONG_MAX
#define  minf  LLONG_MIN 
#define  gi  greater<int> 
#define  gpi greater<pii>  
#define  sp(n) fixed<<setprecision(n)
vector   <int> Fact(100005 , 0);
const int mod = (int)(1e9+7);
int power(int x,int n)
{   
    if(n==0)    return 1;
    if(n==1)    return x%mod;
    if(n%2==0)  {   int y = power(x,n/2)%mod;return (y*y)%mod;}
    if(n&1)     {   int y = power(x,n-1);return (x%mod * y%mod)%mod;}
    return 0;
}
int mod_inverse(int n , int m)
{   //mod = m; // change const mod;
    int modi = power(n , m-2);
    return modi;
}
int  pct(int x)
{    return __builtin_popcountll(x);}
int  lcm(int a,int b){return a*b/gcd(a,b);}
bool is_power_2(int n){ return log2(n)==floor(log2(n));}
bool is_prime(int n){if(n<=1)return 0;for(int i=2; i*i<=n; i++)if(n%i==0)return 0; return 1;}
void cal_fac()
{
     Fact[0] = Fact[1] = 1;
     for(int i=2; i<100000; i++)
         Fact[i] = (Fact[i-1]*i)%mod;
}
int C(int n , int k)
{
    int res = Fact[n];
    res = (res * mod_inverse( Fact[k] , mod ))%mod;
    res = (res * mod_inverse( Fact[n-k] ,mod ))%mod;
    return res;
}
void db()
{       
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
void timeit()
{  
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: " <<sp(10)<< 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
}
int     dx []    =  {-1 , 0 , 1 , 0 ,-1,-1, 1,  1};
int     dy []    =  { 0 , 1 , 0 ,-1 ,-1, 1, 1, -1};
char    dir[]    =  {'U','R','D','L'};
/* ---------------------- ar.cpp --------------------------------- */
const int maxn = 1e6+5;
void solve(int tc)
{
    //  cout<<"Case #"<<tc<<": ";
    int n,i,j,k,m,q,l,r;
    int d ,t, s;
    cin>>d>>t>>s;
    ld p = 1.0*d/s;
    if(p <= t)
        cout<<"Yes";
    else
        cout<<"No";

}
signed main()
{
    // ar.cpp
    RAGE;
   // db();    
    int t=1;
    //  cin>>t;
    for(int i=1; i<=t; i++)
    {
        solve(i);
    }
   // timeit();
    return 0;
}
/*
    1. To find 2's complement , reverse all the bits after 1st set bit. (right - >left.)
*/



Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    ll n,p,c[200005],sum[200005]={0},ans=0,k[10005]={0},ts=1;
    char s[200005];
    cin >> n >> p >> s;
    rep(i,0,n-1) c[n-i]=s[i]-'0';
    k[0]=1;
    rep(i,1,n){
        sum[i]=(sum[i-1]+ts*c[i]%p)%p;
        k[sum[i]]++;
        ts=(ts*10)%p;
    }
    if(p==2||p==5){
      rep(i,1,n) if(c[i]%p==0) ans+=(n-i+1);
    } else rep(i,0,p-1) ans+=((k[i]-1)*(k[i])/2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define X first
#define Y second
#define mod 1e9+7
#define pb push_back
#define mp make_pair
#define abs(x) ((x)>0?(x):(-(x)))
#define F(n) Fi(i,n)
#define Fi(i,n) Fl(i,0,n)
#define Fl(i,l,n) for(int i=l;i<n;i++)
#define memres(a) memset(a,0,sizeof(a))
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	int a,b;
	cin>>a>>b;
	cout<<6-a-b<<endl;
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int a, b;
    cin >> a >> b;
    string s;
    cin >> s;
    bool ok = true;
    rep(i, s.length()) {
        if ( i == a ) {
            if ( s[i] != '-' ) ok =false;
        }
        else {
            if ( s[i] < '0' || s[i] > '9' ) ok = false;
        }
    }
    if ( ok ) cout << "Yes" << endl;
    else      cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int x, y;
    string a, b, ans="";
    cin>>a>>b;
    a=' '+a, b=' '+b;
    int backtrack[a.length()][b.length()], dp[a.length()][b.length()];
    for (int i=0; i<a.length(); i++){
        for (int j=0; j<b.length(); j++){
            dp[i][j]=0;
        }
    }
    for (int i=1; i<a.length(); i++){
        for (int j=1; j<b.length(); j++){
            if (a[i]==b[j]) dp[i][j]=dp[i-1][j-1]+1, backtrack[i][j]=3;
            else {
                dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
                if (dp[i-1][j]==dp[i][j]) backtrack[i][j]=1;
                else backtrack[i][j]=2;
            }
        }
    }
    x=a.length()-1, y=b.length()-1;
    while (x>=1 && y>=1){
        if (backtrack[x][y]==1) x--;
        else if (backtrack[x][y]==2) y--;
        else ans=a[x]+ans, x--, y--;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 70656
#!/usr/bin/env python3

from functools import reduce

def II(): return int(input())
def MII(): return map(int, input().split())
def LII(): return list(map(int, input().split()))

def main():
    N = II()
    A = LII()
  
    mn = 10 ** 9
    n = 0
    ans = 0
    for a in A:
        ans += abs(a)
        mn = min(mn, abs(a))
        if a < 0:
            n += 1

    if n % 2 == 0:
        print(ans)
    else:
        print(ans - 2 * mn)

if __name__ == '__main__':
    main()


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplece_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define Edge pair< i_i, int>
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
 
//int dxy[5] = {0, 1, 0, -1, 0};
// assign

int n;
vvi graph;
vi path;
vb used;

bool dfsroot(int pos)
{
    used[pos] = true;
    if (pos == n-1) {
        path.pb(pos);
        return true;
    }
    bool ret = false;
    rep(i, graph[pos].size()) {
        if (!used[graph[pos][i]]) {
            ret |= dfsroot(graph[pos][i]);
        }
    }
    if (ret) {
        path.pb(pos);
    }
    return ret;
}

int dfscnt(int pos)
{
    used[pos] = true;
    int ret = 1;
    rep(i, graph[pos].size()) {
        if (!used[graph[pos][i]]) 
        ret += dfscnt(graph[pos][i]);
    }
    return ret;
}


int snuke, feneck;

signed main()
{
    cin >> n;
    graph = vvi(n);
    rep(i, n-1) {
        int2(a, b);
        graph[a-1].pb(b-1);
        graph[b-1].pb(a-1);
    }

    used = vb(n, false);
    dfsroot(0);
    reverse(all(path));
   /* 
    rep(i, path.size()) {
        cout << path[i] << " ";
    }cout << endl;
    */

    used = vb(n, false);
    rep(i, path.size()) {
        used[path[i]] = true;
    }
    //snuke += (path.size()-1) / 2;
    rep(i, (path.size()) / 2) {
  //      cout << snuke << " ";
 //       cout << path[(path.size()-1 - i)] << endl;
        snuke += dfscnt( path[(path.size()-1 - i)] );
    }
    feneck = n - snuke;
//    cout << snuke << " " << feneck << endl;
    if (snuke < feneck) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }

    return 0;
}



Measured memory_bytes: 11512
main () {
  int a, b, i, j;
  while(~scanf("%d %d", &a, &b)) {
    if (!a && !b) return 0;
    for (i = 0; i < a; i++) {
      for (j = 0; j < b; j++) putchar((i + j) % 2? '.' : '#');
      putchar('\n');
    }
    putchar('\n');
  }
}


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

int main(){
	bool is_prime[1000000];
	
	is_prime[0]=is_prime[1]=false;
	for(int i=2;i<1000000;i++){
		is_prime[i]=true;
	}
	
	for(int i=2;i*i<1000000;i++){
		if(is_prime[i]){
			for(int j=i*i;j<1000000;j+=i){
				is_prime[j]=false;
				}
			}
		}
		
		int n_prime[1000000];
		
		int cnt=0;
		for(int i=0;i<1000000;i++){
			if(is_prime[i]){
				cnt++;
			}
			n_prime[i]=cnt;
		}
		
		while(true){
			int n;
			cin>>n;
			if(cin.eof())
				break;
				
			cout<<n_prime[n]<<endl;
		}
		
		return 0;
}								

Measured memory_bytes: 7876
class Heap:
    def __init__(self, nodes):
        self._nodes = nodes
        self.size = len(nodes)

    def max_heapify(self):
        def _max_heapify(i):
            left = (i+1) * 2 - 1
            right = (i+1) * 2
            if left < self.size and self._nodes[left] > self._nodes[i]:
                largest = left
            else:
                largest = i

            if right < self.size and self._nodes[right] > self._nodes[largest]:
                largest = right

            if largest > i:
                self._nodes[i], self._nodes[largest] = \
                        self._nodes[largest], self._nodes[i]
                _max_heapify(largest)

        for i in reversed(range(self.size//2)):
            _max_heapify(i)

    def __iter__(self):
        self.cur = 0
        return self

    def __next__(self):
        if self.cur >= self.size:
            raise StopIteration
        node = self._nodes[self.cur]
        self.cur += 1

        return node

    @classmethod
    def create(cls, li):
        heap = cls(li[:])
        heap.max_heapify()
        return heap


def run():
    _ = int(input())

    nodes = [int(i) for i in input().split()]
    heap = Heap.create(nodes)

    s = ''
    for node in heap:
        s += ' {}'.format(node)

    print(s)


if __name__ == '__main__':
    run()



Measured memory_bytes: 63988
#include <stdio.h>

int main(void)
{
	int x, y, temp;
	
	while (1){
		scanf("%d %d", &x, &y);
		if (x == 0 && y == 0){
			break;
		}
		if (y < x){
			temp = x;
			x = y;
			y = temp;
		}
		printf("%d %d\n", x, y);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define print(a,n)  for(lli i=0;i<n;i++)cout<<a[i]<<' ';br
#define br          cout<<endl;
#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define upar        1000000007
#define fr(i,a,b)   for(int i=a;i<=b;i++)
#define tez         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;


void solve()
{

  int n;
  cin>>n;
 if(n%2==0) cout<<"0.5000000000";
 else
 {
     n=n/2;
     //cout<<n;
     cout<<setprecision(10)<<(n+1)*1.0/((2*n)+1);
 }

}


signed main() {

  tez;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
  return 0;
}





Measured memory_bytes: 256
import Data.Sequence (fromList, index)

g = fromList [0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1]

solve [a, b] = if (g `index` a) == (g `index` b) then "Yes" else "No"

main = interact $ solve . map read . words

Measured memory_bytes: 508
import java.io.*;

public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String input = br.readLine();
        int space1 = input.indexOf(" ");
        int space2 = input.indexOf(" ", space1 +1);
        int n = Integer.parseInt(input.substring(0,space1));
        int a = Integer.parseInt(input.substring(space1+1, space2));
        int b = Integer.parseInt(input.substring(space2+1));

        int ans = 0;

        for(int i = 1; i<n+1; i++){
            int now = i;
            int sum = 0;
            for(int j = 0; j<String.valueOf(n).length(); j++){
                sum = sum + now%10;
                now = (now-now%10)/10;
            }
            //ここでチェックしてもいいかも
            if(a<=sum && sum<=b){
                ans = ans + i;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23892
N, M, C = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)

ans = 0

def calc_product(a)
  sum = C
  a.each_index do |i|
    sum = sum + a[i]*B[i]
  end
  return sum
end
N.times do
  a = gets.split.map(&:to_i)
  if calc_product(a) > 0
    ans = ans+1
  end
end
puts ans

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

int main(){
  int n,m;
  cin >> n >> m;
  vector <int> a(m);
  rep(i,m)cin >> a[i];
  rep(i,m)n-=a[i];
  
  if(n>=0)cout << n << endl;
  else cout << "-1" << endl;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main() {
	int r;
	cin>>r;
	if(r<1200){
	    cout<<"ABC"<<endl;
	    return 0;
	}
	if(r<2800){
	    cout<<"ARC"<<endl;
	    return 0;
	}
	
	cout<<"AGC"<<endl;
return 0;	

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int n,m,l;
    cin>>n>>m>>l;
    int a[n][m], b[m][l];
    //int c[n][l]={{0}};
    long long int c[n][l];
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++)  c[i][j]=0;
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            cin>>a[i][j];
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<l; j++){
            cin>>b[i][j];
        }
    }
    for(int i=0; i<n; i++){
        for(int j=0; j<l; j++){
            long long t=0;
            for(int k=0; k<m; k++){
                //c[i][j]+=a[i][k]*b[k][j];
                t+=a[i][k]*b[k][j];
            }
            if(j==l-1)  cout<<t<<endl;
            else    cout<<t<<" ";
        }
    }
    /*for(int i=0; i<n; i++){
        for(int j=0; j<l-1; j++){
            cout<<c[i][j]<<" ";
        }
        cout<<c[i][l-1]<<endl;
    }*/
    return 0;
}


Measured memory_bytes: 3248
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,counter=0;
    cin>>a>>b>>c;
    for(a;a<=b;a++)
    {
        if(c%a==0)
            counter++;
        else
            continue;
    }
    cout<<counter<<endl;
 return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 2e5+5;

const ll MOD = 1000000007LL;

void solve() {

}

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll e = (c*d) / __gcd(c, d);
    ll mod;

    ll fC = a, fD = a, fE = a;
    ll lC = b, lD = b, lE = b;

    if (c >= a && c <= b) {
        fC = c;
    }
    mod = fC%c;
    if (mod > 0) {
        fC += (c-mod);
    }
    mod = b%c;
    if (mod > 0) {
        lC = b-mod;
    }

    if (d > a && d < b) {
        fD = d;
    }
    mod = fD%d;
    if (mod > 0) {
        fD += (d-mod);
    }
    mod = b%d;
    if (mod > 0) {
        lD = b-mod;
    }

    if (e > a && e < b) {
        fE = e;
    }
    mod = fE%e;
    if (mod > 0) {
        fE += (e-mod);
    }
    mod = b%e;
    if (mod > 0) {
        lE = b-mod;
    }

		//cout << "D: " << fE << " " << lE << "\n";
    ll byC = max(0LL, (lC - fC)/c + 1);
    ll byD = max(0LL, (lD - fD)/d + 1);
    ll byE = max(0LL, (lE - fE)/e + 1);

    if (c > b) byC = 0;
    if (d > b) byD = 0;
    if (e > b) byE = 0;
    ll ans = byC + byD - byE;

    cout << (b-a+1) - ans;

    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;

typedef long long LL;
typedef long double ldouble;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int a, b;
    cin >> a >> b;
    a *= b;
    if(a % 2 == 0) cout << "Even";
    else cout << "Odd";
    cout << endl;
    return 0;
}



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

#define int long long
#define MOD 1000000007

vector<int> graph[100010];
int used[100010];


int n, k;
void test(int i, int oya){
    int x = k-2;
    if(oya == -1){
        x++;
    }

    for(int j = 0;j < graph[i].size();j++){
        if(graph[i][j] != oya){
            used[graph[i][j]] = x;
            x--;
            test(graph[i][j], i);
        }
    }

    return;
}



signed main(){
    cin >> n >> k;

    for(int i = 0;i < n-1;i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    test(0, -1);

    int ans = k;
    for(int i = 1;i < n;i++){
        ans = (ans*used[i]) % MOD;
    }

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



Measured memory_bytes: 11136
loop do
  h,m,s = gets.split.map(&:to_i)
  break if [h,m,s].all?{|i| i==-1}
  sec = Time.new(1,1,1,2,0,0) - Time.new(1,1,1,h,m,s)
  t = Time.new(1,1,1,sec/3600,(sec%3600)/60,sec%60)
  puts t.strftime("%H:%M:%S")
  t += sec*2
  puts t.strftime("%H:%M:%S")
end

Measured memory_bytes: 6160
from collections import defaultdict


N,P = map(int, input().split())
S = input()
ans = 0
if P in [2,5]:
    
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i + 1

else:
    d = defaultdict(int)
    d[0] = 1
    curr = 0
    for i in range(N):
        curr = curr + int(S[N-1-i]) * pow(10, i, P)
        curr %= P
        ans += d[curr]
        d[curr] += 1

print(ans)

Measured memory_bytes: 42972
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ
char in[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	printf("%.12f\n",(double)a/b);
}

Measured memory_bytes: 128
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] S = {0,0,0,0,0,0,0,0,0,0,0,0,0};
        int[] H = {0,0,0,0,0,0,0,0,0,0,0,0,0};
        int[] C = {0,0,0,0,0,0,0,0,0,0,0,0,0};
        int[] D = {0,0,0,0,0,0,0,0,0,0,0,0,0};
        for (int i=0; i<n; i++) {
        		String a = sc.next();
        		int b = sc.nextInt();
        		switch (a) {
        			case "S": S[b-1] = b; break;
        			case "H": H[b-1] = b; break;
        			case "C": C[b-1] = b; break;
        			case "D": D[b-1] = b; break;
        		}
        }
        for(int i=0; i<S.length; i++) {
        		if(S[i] == 0) {
        			System.out.println("S " + (i+1));
        		}
        }
        for(int i=0; i<H.length; i++) {
    			if(H[i] == 0) {
    				System.out.println("H " + (i+1));
    			}
        }
        for(int i=0; i<C.length; i++) {
			if(C[i] == 0) {
				System.out.println("C " + (i+1));
			}
        }
        for(int i=0; i<D.length; i++) {
			if(D[i] == 0) {
				System.out.println("D " + (i+1));
			}
        }
    }
}


Measured memory_bytes: 26172
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main {
	
	static class Point {
		
		int x, y;
		Point(int x, int y) {
			
			this.x = x;
			this.y = y;
		}
	}

	static char[][] grid;
	
	public static void main(String args[]) throws Exception {

		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt() - 1;
		int y = sc.nextInt() - 1;
		int a = sc.nextInt() - 1;
		int b = sc.nextInt() - 1;
		grid = new char[n][m];
		int[][] dist = new int[n][m];
		
		for (int i = 0; i < n; i++) {
			
			grid[i] = sc.next().toCharArray();
			Arrays.fill(dist[i], (int)1e8);
		}
		
		int[] dx = {1, -1, 0, 0};
		int[] dy = {0, 0, 1, -1};
		
		Deque<Point> q = new LinkedList<>();
		q.add(new Point(x, y));
		dist[x][y] = 0;
		
		while(!q.isEmpty()) {
			
			Point p = q.poll();
			//System.out.println(p.x + " " + p.y);
			// 0 cost edges
			for(int i = 0; i < 4; i++) {
				
				int newX = p.x + dx[i];
				int newY = p.y + dy[i];
				
				if(!isSafe(newX, newY))
					continue;
				
				if(dist[newX][newY] > dist[p.x][p.y]) {
					
					dist[newX][newY] = dist[p.x][p.y];
					q.addFirst(new Point(newX, newY));
				}
			}
			
			//1 cost edges
			for(int i = -2; i <= 2; i++) {
				for(int j = -2; j <= 2; j++) {
					
					int newX = p.x + i;
					int newY = p.y + j;
					
					if(!isSafe(newX, newY))
						continue;
					
					if(dist[newX][newY] > dist[p.x][p.y] + 1) {
						
						dist[newX][newY] = dist[p.x][p.y] + 1;
						q.addLast(new Point(newX, newY));
					}
				}
			}
		}
		
		/*for(int[] i : dist) {
			for(int p : i)
				System.out.print(p + " ");
			System.out.println();
				
		}*/
		pr.print(dist[a][b] >= (int)1e8 ? -1 : dist[a][b]);
		pr.close();
	}

	private static boolean isSafe(int x, int y) {

		if (x < 0 || y < 0 || x >= grid.length || y >= grid[0].length || grid[x][y] == '#')
			return false;

		return true;
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 61520
def find(N):
    ans = [0]*(N+2)
    pre = [0]*(N+2)
    suf = [0]*(N+2)
    temp = 0
    for i in range(N+1):
        temp += i
        pre[i+1] = temp
    
    for i in range(N+1,0,-1):
        suf[i] = temp
        temp -= (N+1-i)
    
        
    
    
    for i in range(1,N+2):
        ans[i] = suf[i] - pre[i] + 1
#     print(pre)
#     print(suf)
#     print(ans)
    return ans

def find_ans(N,K):
    ans = find(N)
    real_ans = 0
    for i in range(K,N+2):
        real_ans += ans[i]
    return real_ans

N,K = list(map(int,input().strip().split()))
print(find_ans(N,K)%(10**9+7))
    
    

Measured memory_bytes: 69552