akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		@SuppressWarnings("resource")
		Scanner scan = new Scanner(System.in);
		while (true) {
			int m = scan.nextInt();
			int f = scan.nextInt();
			int r = scan.nextInt();
			if (m == -1 && f == -1 && r == -1)
				break;
			System.out.println(run(m, f, r));
		}
		System.exit(0);
	}

	private static String run(int m, int f, int r) {
		if (m == -1 || f == -1)
			return ("F");
		if (m + f >= 80)
			return ("A");
		if (m + f >= 65)
			return ("B");
		if (m + f >= 50)
			return ("C");
		if (m + f >= 30)
			if (r >= 50)
				return ("C");
			else
				return ("D");
		return ("F");

	}
}

Measured memory_bytes: 26436
#include<bits/stdc++.h>
using namespace std;
long long n,x;
long long calc(long long x)
{
	long long s=0;
	while(x)
	{
		x/=10;
		s++;
	}
	return s;
}
double cal(long long x)
{
	long long s1=0,a1=x;
	while(x>0)
	{
		s1+=x%10;
		x/=10; 
	}
	return a1*1.0/s1;
}
long long pd(long long x)
{
	for(long long i=0;i<=calc(x);i++)if(cal(x+(long long)(pow(10,i)))<cal(x))return 0;
	return 1;
}
int main()
{
	cin>>n;
	for(long long i=1;i<=n;i++)
	{
		for(long long j=0;j<=calc(x);j++)
		if(pd(x+(long long)(pow(10,j))))
		{
			x=x+(long long)(pow(10,j));
			break;
		}
		cout<<x<<endl;
	}
	return 0;
} 

Measured memory_bytes: 3832
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    while (scanner.hasNext()) {
      int n = scanner.nextInt();
      if (n == 0) {
        break;
      }
      int ii = 0;
      for (; n != 1; ii++) {
        if (n % 2 == 0) {
          n /= 2;
        } else {
          n = n * 3 + 1;
        }
      }
      System.out.println(ii);
    }
  }
}

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

int main()
{
    int N;
    cin >> N;
    auto c = [](double x, double y) { return x > y; };
    priority_queue<double, vector<double>, decltype(c)> V(c);
    for(int i = 0; i < N; ++i) {
        double tmp;
        cin >> tmp;
        V.push(tmp);
    }
    while(V.size() > 1) {
        double tmp1 = V.top(); V.pop();
        double tmp2 = V.top(); V.pop();
        V.push((tmp1 + tmp2)/2.0);
    }
    cout << fixed << setprecision(7) <<  V.top() << endl;
    return 0;
}

Measured memory_bytes: 256
n, q = gets.split.map &:to_i

queue = []
n.times do
	name, time = gets.split
	time = time.to_i
	queue.push({:name => name, :time => time})
end

jikoku = 0
while (que = queue.shift) != nil
	if que[:time] <= q
		jikoku += que[:time]
		printf("%s %d\n", que[:name], jikoku)
	else
		jikoku += q
		queue.push({:name => que[:name], :time => que[:time] - q})
	end
end

Measured memory_bytes: 44120
N = int(input())
W = list(map(int,input().split()))
minSum = 100000
for i in range(N):
    T = i
    S_1 = W[0:i+1]
    S_2 = W[i+1:]
    minSum = min(abs(sum(S_1)-sum(S_2)),minSum)
print(minSum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define Rep(i,n) for(int i=1;i<=(n);++i)
using LL = long long;
using ULL = unsigned long long;

const int INF = 0x3f3f3f3f;
const double pi = acos(-1.0);

LL up[100123]{1}, a[100123];

int main()
{
    int n;
    cin >> n;
    rep(i, n+1) scanf("%lld", a+i);
    int p = n;
    rep(i, n+1) {
        if(up[i] > 1e18) {
            p = i;
            break;
        }
        if(up[i] < a[i]) {
            puts("-1");
            return 0;
        }
        up[i+1] = (up[i] - a[i]) * 2;
    }
    for(int i = n; i > p; --i) a[i-1] += a[i];
    for(int i = p; i; --i) a[i-1] = min(a[i-1] + a[i], up[i-1]);
    cout << accumulate(a, a+n+1, 0ll) << endl;
    return 0;
}


Measured memory_bytes: 5084
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
// Function to find the nCr 
ll ncr(ll n, ll r) 
{ 
    if (r == 0 || n == r) return 1;
    if (r == 1) return n;
  
    // p holds the value of n*(n-1)*(n-2)..., 
    // k holds the value of r*(r-1)... 
    ll p = 1, k = 1; 
  
    // C(n, r) == C(n, n-r), 
    // choosing the smaller value 
    if (n - r < r) r = n - r; 
  
    while (r) { 
        p *= n; 
        k *= r; 

        ll m = __gcd(p, k); 

        // dividing by gcd, to simplify product 
        // division by their gcd saves from the overflow 
        p /= m; 
        k /= m; 

        n--; 
        r--; 
    } 
  
    // k should be simplified to 1 
    // as C(n, r) is a natural number 
    // (denominator should be 1 ) . 
  
    // if our approach is correct p = ans and k =1 
    assert(k == 1);
    return p;
} 

int main() {
    int N; cin >> N;
    vector<int> A(N);
    vector<ll>  W(N+1);
    W[0] = 0;
    rep(i,N) {
        cin >> A.at(i);
        W[i+1] = W[i] + A[i];
    }
    sort(W.begin(), W.end());
    int i = 0, j = i + 1;
    ll res = 0, cnt = 0;
    while (i < N && j <= N) {
        if (W[i] == W[j]) {
            cnt++;
            j++;
        } else {
            if (cnt > 0) res += ncr(cnt+1, 2);
            cnt = 0;
            i = j;
            j = i + 1;
        }
    }
    if (cnt > 0) res += ncr(cnt+1, 2);

    cout << res << endl;
}


Measured memory_bytes: 5544
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int res = 0;
        for (int i = 0; i < n - 1; i++) {
            int counter = 0;
            String x = s.substring(0, i + 1);
            String y = s.substring(i + 1);
            boolean[] b1 = new boolean[26];
            boolean[] b2 = new boolean[26];
            for (int j = 0; j < x.length(); j++) {
                b1[x.charAt(j) - 97] = true;
            }
            for (int j = 0; j < y.length(); j++) {
                b2[y.charAt(j) - 97] = true;
            }
            for (int j = 0; j < 26; j++) {
                if (b1[j] && b2[j]) {
                    counter++;
                }
            }
            res = Math.max(res, counter);
        }
        System.out.println(res);
        sc.close();
    }
}

Measured memory_bytes: 35628
#include <stdio.h>

#define MOD 2019

int main(void) {
  	int L, R, A;
    int c = 2018;
  	scanf("%d %d", &L, &R);
    if((R - L) >= 2019) {
        printf("0\n");
        return 0;
    }
    for (int i = L; i < R; i++) {
        for(int j = i + 1; j <= R; j++) {
            A = (i % MOD) * (j % MOD) % MOD;
            if (A < c) {
                c = A;
            }
        }
    }
    printf("%d", c);
    return 0;
}

Measured memory_bytes: 128
n,k=gets.chomp.split(" ").map(&:to_i)
d=gets.chomp.split(" ").map(&:to_i)

def ans1(n, d)
  loop do
    break if n.to_s =~ (/\A[^#{d.join("")}]+?\z/)
    n += 1
  end
  n
end

p ans1(n,d)

Measured memory_bytes: 2172
#include <iostream>
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,k,a,b,db,ch[100000],ans,MOD=1000000007;
vector<ll>v[100000];
queue<P>que;
int main(void){
    cin>>n>>k;
    for(int i=0;i<n-1;i++){
        cin>>a>>b;
        v[a-1].push_back(b-1);
        v[b-1].push_back(a-1);
    }
    que.push({0,0});
    ch[0]=1;
    ll cnt=0;
    ans=k;
    while(!que.empty()){
        cnt++;
        auto q=que.front();
        que.pop();
        db=0;
        for(auto x:v[q.F]){
            if(ch[x]==1)continue;
            ch[x]=1;
            ans*=k-min(2LL,q.S+1)-db;
            ans%=MOD;
            db++;
            que.push({x,q.S+1});
        }
    }
    cout<<ans<<endl;
}


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

int main() {
    int n;
    cin >> n;
    long long a[n];
    int i;
    for(i = 0; i < n; i++) {
        cin >> a[i];
    }

    long long sum = 0;
    long long cnt1 = 0,
              cnt2 = 0;
        for(i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                while(sum <= 0) {
                    sum++;
                    cnt1++;
                }
            }
            else {
                while(sum >= 0) {
                    sum--;
                    cnt1++;
                }
            }
        }

        sum = 0;

        for(i = 0; i < n; i++) {
            sum += a[i];
            if (i % 2 == 0) {
                while(sum >= 0) {
                    sum--;
                    cnt2++;
                }
            }
            else {
                while(sum <= 0) {
                    sum++;
                    cnt2++;
                }
            }
        }
    cout << min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 4368
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n;cin>>n;
	vector<pair<ll,ll> > v;
	for(ll i=0;i<n;i++)
	{
		ll x;cin>>x;
		v.pb(mp(x,i));
	}
	sort(v.begin(),v.end());
	for(ll i=0;i<n;i++)cout<<v[i].se+1<<" ";
}


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

constexpr int64_t INF = 1'010'000'000'000'000'017LL;
constexpr int64_t MOD = 1'000'000'007LL;
constexpr double EPS = 1e-12;
constexpr double PI = 3.14159265358979323846;

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

signed main() {
  uint64_t a;
  double b;
  cin >> a >> b;
  uint64_t b100 =  (uint64_t) (b*100.0+0.5);
  
  cout << a*b100/100 << endl;

  return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxf = 400005;
const int MOD = 998244353;

ll fact[maxf], invfact[maxf];
char a[maxf], b[maxf], c[maxf], d[maxf];
ll anspref[maxf];
int n, m;

ll powmod(ll a, ll b)
{
    ll ans = 1;
    ll tmp = a;
    while (b)
    {
        if (b & 1) ans = (ans * tmp) % MOD;
        tmp = (tmp * tmp) % MOD;
        b >>= 1;
    }
    return ans;
}

ll getc(ll a, ll b)
{
    if (b < 0 || b > a) return 0;
    return fact[a] * invfact[b] % MOD * invfact[a - b] % MOD;
}

ll f3(int x, int y, int z)
{
    if (y == 0)
    {
        if (x == 0 && z == 0) return 1;
        return 0;
    }
    ll tot = getc(x + y + z, y);
    return (tot - getc(x + y + z - 1, y) + MOD) % MOD;
}

int main()
{
    fact[0] = 1;
    invfact[0] = 1;
    for (int i = 1; i < maxf; i++)
    {
        fact[i] = (fact[i - 1] * i) % MOD;
        invfact[i] = powmod(fact[i], MOD - 2);
    }
    
    scanf("%d%d", &n, &m);
    scanf("%s", a);
    scanf("%s", b);
    scanf("%s", c);
    scanf("%s", d);
    int tot = 0;
    for (int i = 0; i < n; i++)
    {
        tot += a[i] == '1';
        tot += b[i] == '1';
    }
    for (int i = 0; i < m; i++)
    {
        tot += c[i] == '1';
        tot += d[i] == '1';
    }
    if (tot == 0)
    {
        cout << 1 << endl;
        return 0;
    }
    ll answer = 0;
    for (int IT = 0; IT < 2; IT++)
    {
        int y = 0;
        for (int i = 0; i < n; i++) y += a[i] == '1';
        int x = 0;
        int z = 0;
        for (int i = 0; i < m; i++) if (c[i] == '1' || d[i] == '1')
        {
            anspref[i] = f3(x, y, z);
            if (c[i] == '1' && d[i] == '1') anspref[i] = (anspref[i] * 2) % MOD;
            
            x += c[i] == '1';
            z += d[i] == '1';
        }
        
        y = 0;
        for (int i = 0; i < n; i++) y += b[i] == '1';
        x = 0;
        z = 0;
        ll curttans = 0;
        for (int i = m - 1; i >= 0; i--) if (c[i] == '1' || d[i] == '1')
        {
            ll curans = f3(x, y, z);
            answer += anspref[i] * (curttans + curans);
            answer %= MOD;
            curttans = (curttans + curans) % MOD;
            if (c[i] == '1' && d[i] == '1') curttans = (curttans * 2) % MOD;
            
            x += c[i] == '1';
            z += d[i] == '1';
        }
        
        
        for (int i = 0; i <= max(n, m); i++) swap(a[i], c[i]);
        for (int i = 0; i <= max(n, m); i++) swap(b[i], d[i]);
        swap(n, m);
//         cout << answer << endl;
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 9984
n = gets.to_i

sp = Array.new(n){ Array.new(2) }

for i in 0...n do
  sp[i] = gets.split
  sp[i] << i+1
  sp[i][1] = sp[i][1].to_i
end

sp.sort! do |a,b,c|
  [a[0],b[1]] <=> [b[0], a[1]]
end

for i in 0...n do
  puts sp[i][2]
end

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
int n,m,q,a,b,c,d,ans{},A[10]={};
struct t{
    int a,b,c,d;
};
vector<t> e;
void f(){
    int tmp{};
    for(auto&[aa,bb,cc,dd]:e){
        if(A[bb]-A[aa]==cc) tmp+=dd;
    }
    chmax(ans,tmp);
}
void rec(int i=1){
    if(i==n){
        f();
        return;
    }
    for(int j=A[i-1];j<m;++j){
        A[i]=j;
        rec(i+1);
    }
}
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n>>m>>q;
    fr(i,q){
        cin>>a>>b>>c>>d;
        --a,--b;
        e.push_back(t{a,b,c,d});
    }
    rec();
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <sstream>
//#include <fstream>

using namespace std;

const int MAX_N = 100000000;
typedef pair<int, int> P; // shortnest city, length order

P dijkstra (vector <vector <int> > path )
{
	P res (-1, MAX_N );	// shortnest city, length order
	int i,j;

	for (i = 0; i < 10; ++i){
		vector <int>  d (10, MAX_N );
		vector <bool> v (10, false );

		d[i] = 0;
		int mind = MAX_N;
		int p;

		do{
			mind = MAX_N;

			for (int k = 0; k < 10; ++k){
				if (!v[k] && d[k] < mind ){
					mind = d[k];
					p = k;
				} // end if
			} // end for

			v[p] = true;
		
			for (int k = 0; k < 10; ++k){
				if (d[p] + path[p][k] < d[k] ){
					d[k] = d[p] + path[p][k];
				} // end if
			} // end for
		}while (mind != MAX_N );

		int sum = 0;
		for (j = 0; j < 10; ++j){
			if (j != i && d[j] != MAX_N ){
				sum += d[j];
			} // end if
		} // end for
		if (sum == 0 ){
			continue;
		} // end if

		if (res.second > sum ){
			res.first  = i;
			res.second = sum;
		} // end if
	} // end for

	return res;
}			

int main()
{
//	cut here before submit 
//	freopen ("testcase.convenientlocation", "r", stdin );
	string str = "";
	int n;

	while (getline (cin, str ) ){
		stringstream ssn(str);
		ssn >> n;

		if (n == 0 ){
			break;
		} // end if		

		vector <vector <int> > path (10, vector <int> (10, MAX_N ) ); 
		int i;
		for (i = 0; i < n; ++i){
			getline (cin, str );
			int from, to, time;
			stringstream ss(str);
			ss >> from >> to >> time;
			path[from][to] = time;
			path[to][from] = time;
		} // end for
		P res;
		res = dijkstra (path );

		cout << res.first << ' ' << res.second << endl;
	} // end loop
		
	return 0;
}

Measured memory_bytes: 0
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {

	char a;
	cin >> a;
	if (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u') {
		cout << "vowel" << endl;
	}
	else {
		cout << "consonant" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる
//時間を意識しろ
//コードテストちゃんとして
//画面とにらめっこするな書け
//WA出すたびにABCは五億円払え
//わからない問題はとばせ
//躊躇なくぐぐれ

//ここから
int main(){
    ll N,P;
    cin>>N>>P;
    vl vec(N);
    rep(i,N)cin>>vec.at(i);
    vvl dp(2,vl(N+1,0));
    rep(i,N){
        if(vec.at(i)%2==0){
            dp.at(0).at(i+1)=2*dp.at(0).at(i);
            dp.at(1).at(i+1)=2*dp.at(1).at(i);
        }else{
            dp.at(0).at(i+1)=dp.at(1).at(i)+dp.at(0).at(i);
            dp.at(1).at(i+1)=dp.at(1).at(i)+dp.at(0).at(i);
        }
        dp.at(vec.at(i)%2).at(i+1)++;
    }
    dp.at(0).at(N)++;
    cout<<dp.at(P).at(N)<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

#define vi vector<int>
#define vl vector<long long>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define vp vector<P>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPD(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define FORD(i, a, b) for (int i = (int)(a); i >= (int)(b); i--)
#define INF 1e18
#define INFTY 1e9
const int mod = 998244353;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

template<class T> bool chmax(T &a, const T & b) {
    if (a<b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> bool chmin(T &a, const T & b) {
    if (a>b) {
        a = b;
        return true;
    }
    return false;
}

//cout << fixed << setprecision(10) << y << endl;
struct edge {int to, cost;};
vector< vector<edge> > es;
const int MAX_N = 10010;

int main() {
    ll a, b, k;
    cin >> a >> b >> k;
    ll z = 0;
    a = a-k;
    if (a < 0) {
        b = max(b+a, z);
        a = 0;
    }
    cout << a << ' ' << b << endl;
    return 0;
}

Measured memory_bytes: 256
k=int(input())
from collections import deque
lunlun=deque([i for i in range(1,10)])
for i in range(10**5):
  a=lunlun.popleft()
  if not a%10==0:
    lunlun.append(a*10+a%10-1)
  lunlun.append(a*10+a%10)
  if not a%10==9:
    lunlun.append(a*10+a%10+1)
  if i==k-1:
    break

print(a)

Measured memory_bytes: 11888
#include <bits/stdc++.h>
using namespace std;
int i, k = 1, p, t, a[2040];
string s;
main()
{
    for (cin >> s, i = s.size(); i--; k = k * 10 % 2019)
        a[p = (p + k * (s[i] - 48)) % 2019]++;
    for (t = *a; ++i < 2019;)
        t += a[i]-- * a[i] / 2;
    cout << t;
}


Measured memory_bytes: 3708
N = int(input())
W = [input() for _ in range(N)]
used = [W[0]]
current = W[0]

for w in W[1:]:
    if w[0] == current[-1] and w not in used:
        current = w
        used.append(w)
    else:
        print("No")
        break
else:
    print("Yes")


Measured memory_bytes: 3060
#include<cctype>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<vector>
#include<cstdio>
#include<queue>
#include<ctime>
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
using namespace std;
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
char BB[1 << 15],*SS = BB,*TT = BB;
inline long long read()
{
	long long x = 0;int f = 1;
	char ch = getchar();
	for(;!isdigit(ch);ch = getchar())
		if(ch == '-')
			f = -1;
	for(;isdigit(ch);ch = getchar())
		x = x * 10 + (ch ^ 48);
	return x * f;
}
inline void print(long long x)
{
	if(x < 0)
	{
		putchar('-');
		x = -x;
	}
	char ch = x % 10 + '0';
	if(x > 9)
		print(x / 10);
	putchar(ch);
}

int mod;
int add(int a,int b)
{
	a += b;
	return a >= mod ? a - mod : a;
}
int qpow(long long a,int b,int p = mod)
{
	long long ans = 1;
	while(b)
	{
		if(b & 1) ans = ans * a % p;
		a = a * a % p,b >>= 1;
	}
	return ans;
}

const int N = 3010;
int n;
long long s[N][N],c[N][N],ans;

void init()
{
	c[0][0] = s[0][0] = 1;
	for(int i = 1;i <= n + 1;i++)
	{
		c[i][0] = 1;
		for(int j = 1;j <= i;j++)
			s[i][j] = (s[i - 1][j - 1] + s[i - 1][j] * j) % mod,
			c[i][j] = add(c[i - 1][j - 1],c[i - 1][j]);
	}
}

int main()
{
	n = read(),mod = read();
	init();
	
	for(int i = 0;i <= n;i++)
	{
		long long _2 = qpow(2,n - i);
		long long mul = i & 1 ? mod - 1 : 1,res = 0;
		mul = mul * c[n][i] % mod * qpow(2,qpow(2,n - i,mod - 1)) % mod;
		
		long long _2j = 1;
		for(int j = 0;j <= i;j++)
			res = (res + s[i + 1][j + 1] * _2j) % mod,
			_2j = _2j * _2 % mod;

		ans = (ans + res * mul) % mod;
	}
	fprint(ans);
}

Measured memory_bytes: 139904
#k = int(input())
import bisect
n, m, k = map(int, input().split())
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
#al=[list(input()) for i in range(h)]
acum = [0]
for i in range(n):
    acum.append(al[i]+acum[i])

bcum = [0]
for i in range(m):
    bcum.append(bl[i]+bcum[i])
ans = 0
for i in range(n+1):
    rsd = k-acum[i]
    if rsd < 0:
        break
    #if rsd == 0:
    #    ans = max(ans, i)
    #    continue
    ind = bisect.bisect_right(bcum, rsd)
    ans = max(ans, i+ind-1)
print(ans)


Measured memory_bytes: 127092
{-# OPTIONS_GHC -Wall #-}

-- foldM_ を使うとMLEするので…
foldM_' :: (Monad m) => (a -> b -> m a) -> a -> [b] -> m ()
foldM_' _ _ [] = return ()
foldM_' f z (x:xs) = do
    z' <- f z x
    z' `seq` foldM_' f z' xs

readInt :: String -> Int
readInt = read

data BST a = Empty | Node a (BST a) (BST a)
    deriving (Show)

bstFind :: (Ord a) => BST a -> a -> Bool
bstFind Empty _ = False
bstFind (Node y l r) x
    | x == y    = True
    | x <  y    = bstFind l x
    | otherwise = bstFind r x

bstInsert :: (Ord a) => BST a -> a -> BST a
bstInsert Empty x = Node x Empty Empty
bstInsert (Node y l r) x
    | x <= y    = Node y (bstInsert l x) r
    | otherwise = Node y l (bstInsert r x)

bstPreorder :: (Ord a) => BST a -> [a]
bstPreorder Empty = []
bstPreorder (Node x l r) = [x] ++ bstPreorder l ++ bstPreorder r

bstInorder :: (Ord a) => BST a -> [a]
bstInorder Empty = []
bstInorder (Node x l r) = bstInorder l ++ [x] ++ bstInorder r

doCmd :: BST Int -> [String] -> IO (BST Int)
doCmd node ("find":arg0:_) = do
    let x = readInt arg0
    putStrLn $ if bstFind node x then "yes" else "no"
    return node
doCmd node ("insert":arg0:_) = do
    let x = readInt arg0
    return $ bstInsert node x
doCmd node ("print":_) = do
    putStrLn . concatMap ((' ':) . show) $ bstInorder  node
    putStrLn . concatMap ((' ':) . show) $ bstPreorder node
    return node
doCmd _ _ = error "invalid command"

main :: IO ()
main = do
    _    <- getLine
    cmds <- fmap (map words . lines) getContents

    let bst = Empty :: BST Int

    foldM_' doCmd bst cmds



Measured memory_bytes: 78988
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int n;
    cin >> n;
    int m = 1 << n;
    aoi<int> pq;
    for (int i = 0; i < m; i++)
    {
        int a;
        cin >> a;
        pq.push(a);
    }
    akari<int> used = {pq.top()};
    pq.pop();
    for (int i = 0; i < n; i++)
    {
        akari<int> nused(used);
        aoi<int> npq;
        for (int j = 0; j < 1 << i; j++)
        {
            bool ok = 0;
            while (!pq.empty())
            {
                int b = pq.top();
                pq.pop();
                if (used[j] > b)
                {
                    ok = 1;
                    nused.push_back(b);
                    break;
                }
                else
                {
                    npq.push(b);
                }
            }
            if (!ok)
            {
                cout << "No" << endl;
                return;
            }
        }
        while (!pq.empty())
        {
            npq.push(pq.top());
            pq.pop();
        }
        swap(pq, npq);
        swap(used, nused);
        sort(used.rbegin(), used.rend());
    }
    cout << "Yes" << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 4332
#!/usr/bin/env python
# coding: utf-8

# In[6]:


import sys
#input = sys.stdin.readline
A, B = map(int, input().split())


# In[7]:


if A <=5:
    print(0)
elif A <= 12:
    print(int(B/2))
else:
    print(B)


# In[ ]:






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

int main(void){
  int n,y; cin >> n >> y;
  for(int i=0; i<=n; ++i){
    for(int j=0; j<=n-i; ++j){
      int sum = i*1000 + j*5000 + (n-i-j)*10000;
      if( sum == y){
        cout << (n-i-j) << " "<< j << " " << i << endl;
        return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll x, a, b;
  cin >> x >> a >> b;
  cout << x - a - ((x - a) / b * b) << endl;
  return 0;
}


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

int main() {
  //input
  int N, K;
  string S;
  cin >> N >> K >> S;
  //calc
  int score = 0;
  if ( S.at(0) == 'R' && N > 1 ) {
    if ( S.at(1) == 'R' ) {
      score++;
    }
  }
  int RLcount = 0;
  for(int i=1; i<N;i++) {
    if ( S.at(i) == 'L' ) {
      if ( S.at(i-1) == 'L' ) {
        score++;
      }
      else {
	    RLcount++;
      }
    }
    else if ( i < N-1 ) {
      if ( S.at(i+1) == 'R' ) {
        score++;
      }
    }
  }
  int first, last;
  int X, Y;
  first = S.at(0);
  last = S.at(N-1);
  if ( first == last ) {
    X = RLcount;
    Y = 0;
  }
  else if ( first == 'L' ) {
      X = RLcount;
      Y = 1;
  }
  else {
    X = RLcount - 1;
    Y = 1;
  }
//  cout << "(" << X << "," << Y << ")" << endl;
  if ( K >= X + Y ) {
    score += 2 * X + Y;
  }
  else if ( K >= X ) {
    score += 2 * X;
  }
  else {
    score += 2 * K;
  }
  //output
  cout << score << endl;
}

Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>

using namespace std;

#define MOD 1000000007
#define INF INT_MAX
#define ll long long

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

	vector<int> a(n);

	for (int i = 0; i < a.size(); i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	int x = 0, y;
	for (int i = 0; i < a.size(); i++) {
		if (a.size() - 1 == i) {
			cout << 0 << endl;
			return (0);
		}
		if (a[i] == a[i + 1]) {
			if (a[i] <= x) {
				y = a[i];
				break;
			}
			x = a[i];
			i++;
		}
	}
	ll res = (ll)x * (ll)y;
	cout << res << endl;
	


	return (0);
}

Measured memory_bytes: 640
n=int(input())
w=[0]*n
for _ in range(n):
  w[_]=input()
if len(w)!=len(list(set(w))):
  a="No"
else:
  for i in range(n-1):
    if w[i][len(w[i])-1]!=w[i+1][0]:
      a="No"
      break
    else:
      a="Yes"
print(a)

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include <cstdlib>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include <iomanip>
#include<stack>
#include <unordered_map>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
// #define pi acos(-1)
// #include<bits/stdc++.h>
typedef long long ll;
#define INF 0x7f7f7f7f //2139062143
#define INF1 0x3f3f3f3f //1061109567
#define INF2 2147483647
#define llINF 9223372036854775807
#define pi 3.14159265358979323846264338327950254
#define pb push_back
#define ll long long
#define debug cout << "debug\n";
#define STDIN freopen("in.txt","r",stdin); freopen("out.txt","w",stdout);
#define Quick ios::sync_with_stdio(false);cin.tie(NULL);
#define scai(x) scanf("%d", &x)
#define sca2i(x, y) scanf("%d %d", &x, &y)
#define scaf(x) scanf("%lf", &x)
#define sca2f(x, y) scanf("%lf %lf", &x, &y)
#define For(m,n) for (int i = m;  i < n; i++)
#define PII pair<int,int>
#define PLL pair<long, long>
#define lowbit(x) (x&-x)

const int maxn = 50;
#define ERR 1e-6
#define fabs(a) (a < 0 ? -(a) : a)
#define square(a) ((a) * (a))


int main()
{
    //STDIN
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
    puts("Yes");
    else puts("No");
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
int a,b; bool f;
char s[51][51],t[51][51];
using namespace std;
int main()
{
	scanf("%d%d",&a,&b);
	for(int i=1;i<=a;++i)
	for(int j=1;j<=a;++j)
	cin>>s[i][j];
	for(int i=1;i<=b;++i)
	for(int j=1;j<=b;++j)
	cin>>t[i][j];
	for(int i=1;i<=a-b+1;++i)
	for(int j=1;j<=a-b+1;++j)
	if(s[i][j]==t[1][1])
	{
		f=true;
		for(int i1=i;i1<=i+b-1;++i1)
		{
			for(int j1=j;j1<=j+b-1;++j1)
			if(s[i1][j1]!=t[i1-i+1][j1-j+1])
			{
				f=false;
				break;
			}
			if(!f)break;
		}
		if(f)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    string s;
    cin >> N >> s;
    int cntR = 0, cntB = 0;
    for (int i = 0; i < N; i++) {
        if (s[i] == 'R') cntR++; else cntB++;
    }
    if (cntR > cntB) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

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

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

    int ans = (n.size() - 1) * 9;

    bool all9 = true;
    for (int i = 1; i < n.size(); i++) {
        if (n[i] != '9') {
            all9 = false;
            break;
        }
    }

    ans += n[0] - '0';
    if (!all9) {
        ans--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

int main() {
  int N, M, Q; cin >> N >> M >> Q;
  vector<vector<LL>> p(N + 1, vector<LL>(N + 1, 0));
  for (int i = 0; i < M; ++i) {
    int L, R; cin >> L >> R;
    ++p[L][R];
  }

  vector<vector<LL>> S(N + 1, vector<LL>(N + 1, 0));
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + p[i][j];
    }
  }

  for (int i = 0; i < Q; ++i) {
    int L, R; cin >> L >> R;
    cout << S[R][R] - S[R][L-1] - S[L-1][R] + S[L-1][L-1] << endl;
  }
}


Measured memory_bytes: 7520
import java.io.PrintWriter;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		//入力
		String o = sc.nextLine();
		String e = sc.nextLine();
		sc.close();

		//処理
		String ans = "";
		for(int i = 0; i < o.length(); i++){
			if(i == e.length()){
				ans += o.charAt(i);
			}else{
				ans += o.charAt(i);
				ans += e.charAt(i);
			}
		}

		//出力	
		out.println(ans);
		out.flush();
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号  (例) par[3] = 2 : 3の親が2
    vector<ll> rank; // 木の深さ
    vector<ll> siz; // 集合のサイズを表す配列

    UnionFind(ll N) : par(N), rank(N), siz(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++){
            par[i] = i;
            rank[i] = 0;
            siz[i] = 1;
        }
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y) { // xとyの木を併合
        x = root(x);
        y = root(y);
        if (x == y) return; //xとyの根が同じ(=同じ木にある)時はそのまま

        if(siz[x] < siz[y]){
            swap(x, y);
        }

        siz[x] += siz[y];
        par[y] = x;
        if(rank[x] == rank[y]) rank[x]++;
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }

    ll size(ll x){ // xが属する集合の要素数
        return siz[root(x)];
    }
};

int main(void)
{
    ll N, M, i, p[100001], x[100001], y[100001], ans=0;

    cin >> N >> M;

    for(i=1; i<=N; i++){
        cin >> p[i];
    }

    UnionFind tree(N+1);

    for(i=1; i<=M; i++){
        cin >> x[i] >> y[i];
        tree.unite(x[i], y[i]);
    }

    for(i=1; i<=N; i++){
        if(tree.same(i, p[i])) ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4992
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

#include "bits/stdc++.h"
using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A >= 1 && A<=9 && B >= 1 && B <= 9){
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
inf=10**3
d=((-1,0),(1,0),(0,-1),(0,1))
S=[["#"]*(w+2)]
S.extend([["#"]+[s for s in input()]+["#"] for _ in range(h)])
S.append(["#"]*(w+2))
import collections
def dist(a,b):
  D=[[inf]*(w+2) for _ in range(h+2)]
  D[a][b]=0
  Visit=collections.deque()
  Visit.append(100*a+b)
  while Visit:
    v=Visit.popleft()
    va,vb=v//100,v%100
    for dx,dy in d:
      if S[va+dx][vb+dy]=="." and D[va+dx][vb+dy]==inf:
        Visit.append((va+dx)*100+(vb+dy))
        D[va+dx][vb+dy]=D[va][vb]+1
  ret=0
  for i in range(h):
    for j in range(w):
      if D[i+1][j+1]<inf:
        ret=max(ret,D[i+1][j+1])
  return ret
ans=0
for i in range(h):
  for j in range(w):
    if S[i+1][j+1]==".":
      ans=max(dist(i+1,j+1),ans)
print(ans)





Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    int a,b;
    cin >> a >> b;
    // 出力
   if(a<10&&b<10){
    cout << a*b << endl;
   }else{
     cout << -1 << endl;
   }
    return 0;
}

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

using namespace std;

#define INF ((1<<30)-1)  //int32_t
#define MOD 1000000007
#define MOD2 

#define all(a)  (a).begin(),(a).end()

#define mkp make_pair
#define pb push_back

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

int main(){

    bool flag=true;

    ll ans=0,sum=0;
    
    int n,m;
    cin >>n>>m;

    for (int i = 1; i*i <= m; i++){
        if(m % i ==0){
            if(m / i >= n)ans = max(ans,(ll)i);
            if( m/(m/i) >= n)ans = max(ans,(ll)(m/i));
        }
    }
    
    

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << ans << endl;

    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

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

using namespace std;

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

  string key = "keyence";
  bool ok = false;
  int n = s.size();
  rep(i, n) {
    rep(j, n) {
      if (s.substr(0, i) + s.substr(j, n - 1) == key) {
        ok = true;
      }
    }
  }

  std::cout << (ok ? "YES" : "NO") << std::endl;
  return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

vector<vector<int>> children(100100);
map<pair<int,int>,int> color;
int k=0;
void dfs(int now, int parent) {
    int c=1;
    for(int child : children[now]) {
        if(child == parent) continue;
        if(c==color[make_pair(min(now,parent),max(now,parent))]) c++;
        k=max(k,c);
        color[make_pair(min(now,child),max(now,child))]=c;
        c++;
        dfs(child, now);
    }
}

int main() {
    int n;
    ll k;
    cin>>n>>k;
    vector<ll> v(n+1,0);
    map<ll,vector<int>> cnt;
    cnt[0].push_back(0);
    rep(i,n) {
        ll a;
        cin>>a;
        v[i+1]=(v[i]+a)%k;
        cnt[(v[i+1]-(i+1)+300000*k)%k].push_back(i+1);
    }
    
    ll ans=0;
    for(auto p:cnt) {
        auto v=p.second;
        int s=sz(v);
        rep(i,s) {
            ans+=(s-(lower_bound(all(v),v[i]+k)-v.begin())-i);
        }
    }
    cout<<abs(ans)<<endl;
}



Measured memory_bytes: 25984
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
 
#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>
#include <bitset>
 
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define repb(i, r, l) for (int i = (r); i > (l); i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define rank qwertyuio
#define next dfghjk
#define plus fsghsf
#define minus ytryr
 
using namespace std;
 
inline bool setmin(int &x, int y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(int &x, int y) { return (y > x) ? x = y, 1 : 0; }
inline bool setmin(ll &x, ll y) { return (y < x) ? x = y, 1 : 0; }
inline bool setmax(ll &x, ll y) { return (y > x) ? x = y, 1 : 0; }
 
const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const ld eps = 1e-12;
const double pi = atan2(0, -1);
const int ABC = 26;
 
void reverse_sub(string &s, int l, int r) {
    rep(i, 0, (r - l + 1) / 2) {
        swap(s[l + i], s[r - i]);
    }
}
 
int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    string s;
    std::cin>>s;
    string M[7]={"SUN", "MON", "TUE", "WED", "THU", "FRI","SAT"};
    int i;
    for(i=0;i<7;i++){
        if(s==M[i]){
            if(i==0){
                cout<<7;
            }
            else{
                cout<<7-i;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
require 'mathn'
require 'matrix'
require 'set'

loop {
	n = gets.to_i
	break if n == 0
	cross_point = Hash.new(0)
	lines = []
	count = 1

	n.times {
		l = gets.split.map &:to_i
		x1, y1, x2, y2 = l
		crossed = Set.new
		count += 1
		lines.each{|u1, v1, u2, v2|
			mat = Matrix[[y2-y1, x1-x2], [v2-v1, u1-u2]]
			vec = Vector[x1*(y2-y1)-y1*(x2-x1), u1*(v2-v1)-v1*(u2-u1)]
			if !mat.singular?
				cp = mat.inv * vec
				next if cp[0].abs >= 100 || cp[1].abs >= 100
				crossed << cp
				count += 1
			end
		}

		crossed.each{|cp|
			count -= cross_point[cp]
			cross_point[cp] += 1
		}
			
		lines << l
	}
	p count
}

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

int main(){
	long long int n,k,a,b;
	cin >> n;
	cin >> k;
	a = n%k;
	b = k-a;
	if(a <= b){
		cout << a;
	}
	else{
		cout << b;
	}

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    ll a, b; cin >> a >> b;
    if(a > 0) {
        print("Positive");
        return 0;
    } else if(a <= 0 && 0 <= b) {
        print("Zero");
        return 0;
    }
    int flag = b - a + 1;
    if(flag % 2) {
        print("Negative");
    } else {
        print("Positive");
    }


    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main () {
    int n, x, a[10000], sum = 0;
    cin >> n >> x;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    sort (a, a + n);
    x -= sum;
    sum = x / a[0];
    cout << sum + n;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
int main()
{
     ll n,m;

     cin>>n>>m;

     ll ara[n+1];
     for(ll i=0;i<n;i++)
     {
         cin>>ara[i];
     }

     ll sum=0;
     
     sort(ara,ara+n);

     for(ll i=0;i<m;i++)
     {
         sum+=ara[i];
     }

     cout<<sum<<endl;


}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int x[15] = { 0 };
bool isOk(int c)
{
	while (c)
	{
		if (x[c % 10])
			return false;
		c /= 10;
	}
	return true;
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);

	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < k; i++)
	{
		int tmp;
		scanf("%d", &tmp);
		x[tmp] = 1;
	}
	while (!isOk(n))
	{
		n++;
	}
	printf("%d\n", n);
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <numeric>
#include <iomanip>

using namespace std;
#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;++i)
#define fast_io() ios::sync_with_stdio(false); cin.tie(nullptr)
#define fix(n) fixed << setprecision(n)

constexpr double PI = 3.14159265358979323846;

using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;


int main(void){
    fast_io();
    string s;
    cin >> s;
    rep(i,s.size()) {
        if(s[i] == '7') {
            cout << "Yes" << endl; return 0;
        }
    }


    cout << "No" << endl;

    return 0;
}


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

using namespace std;
using ll = long long;

constexpr ll MOD = 1e9 + 7;
int mx[] = {-1, 1, 0, 0}, my[] = {0, 0, -1, 1};

int main()
{
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(3 * n);
	for (int i = 0; i < m; ++i)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[3 * u].push_back(3 * v + 1);
		g[3 * u + 1].push_back(3 * v + 2);
		g[3 * u + 2].push_back(3 * v);
	}
	int s, t;
	cin >> s >> t;
	s--, t--;
	queue<pair<int, int>> q;
	q.push({3 * s, 0});
	vector<int> visited(3 * n);
	while (!q.empty())
	{
		auto now = q.front();
		for (auto nxt : g[now.first])
		{
			if (!visited[nxt])
			{
				q.push({nxt, now.second + 1});
				visited[nxt] = now.second + 1;
			}
		}
		q.pop();
	}
	if (visited[3 * t])
	{
		cout << visited[3 * t] / 3 << endl;
	}
	else
	{
		cout << -1 << endl;
	}
}

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

int main() {
  int N, K;
  string S;
  cin >> N >> K >> S;
  vector<int> V(2);
  for (int i = 0, j = 1, k = 1; i < N; i++) {
    if (S.at(i) - '0' == k) V.at(j)++;
    else V.push_back(V.at(j) + 1), k = (k) ? 0 : 1, j++;
  }
  int ans = 0, v = V.size();
  for (int i = 1; i < v; i += 2)
    ans = max(ans, V.at(min(v - 1, i + K * 2)) - V.at(i - 1));
  cout << ans << "\n";
}

Measured memory_bytes: 1020