akhauriyash/Code-Regression huggingface dataset:
/*
    2014.07.04 1230~1243
    C language Lecture week ∞
*/

#include <stdio.h>

int leap_chk ( int year );

int main (void) {
    
    int init;
    int last;
    
    int rcode = 0;
    
    int count;
    
    while (1) {
        
        count = 0;
        
        scanf ( "%d", &init );
        scanf ( "%d", &last );
        
        if ( init == 0 && last == 0 ) {
            break;
        }
        
        if ( rcode == 0 ) {
            rcode = 1;
        } else {
            printf ( "\n" );
        }
        
        for ( int ly = init; ly <= last; ly ++ ) {
            if ( leap_chk ( ly ) ) {
                printf ( "%d\n", ly );
                count ++;
            }
        }
        
        if ( count == 0 ) {
            printf ( "NA\n" );
        }
        
    }
    
    return 0;
    
}

int leap_chk ( int year ) {
    
    if ( year % 4 == 0 ) {
        if ( year % 100 == 0 ) {
            if ( year % 400 == 0 ) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return 1;
        }
    } else {
        return 0;
    }
    
}

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


int main(){
  int n,y;
  cin >> n >> y;
  REP(a,n+1){
    REP(b,n+1){
      if (((y-10000*a-5000*b)%1000 == 0) && (n-a-b >= 0) && ((y-10000*a-5000*b)/1000 == n-a-b)){
	cout << a << " " << b << " " << n-a-b << endl;
	return 0;
      }
    }
  }
  cout << "-1 -1 -1" << endl;
  return 0;
}


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


int main()
{
	int l, N, X = 1, i = 0, a[20];
	cin >> N;
	while (cin >> l) {
		a[i] = l;
		i++;
		if (i >= N) {
			break;
		}
	}
	

	for (i = 1; i < N; i++) {
		int max = a[0];
		for (int j = 1; j < i+1; j++) {
			if (a[j] >= max) {
				max = a[j];
			}
		}
		if (a[i] >= max) {
			X = X + 1;
		}	
	}

	cout << X << endl;
}

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

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
//constexpr  int MOD=1000000007;
constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>N;
	string s;
	cin>>s;
	vector<int>num(256);
	for(int i=0;i<N;i+=2)num[s[i]]++;
	vector<int>fig(10);
	for(int i=0;i<256;i++){
		fig[num[i]]++;
	}
	int ans=0;
	for(int i=1;i<10;i++){
		if(fig[i]==0)continue;
		if(i==1){
			ans+=fig[i]*2;
		}
		if(i>1){
			if(fig[i]==1)ans+=4;
			else{
				ans+=2+2+fig[i]*2;
			}
		}
	}
	cout<<ans-1<<endl;
}


Measured memory_bytes: 3224
def main():
    N = int(input())
    S = input()
    
    cnt = 0
    for i in range(10):
        idx_i = S.find(str(i))
        if(idx_i == -1):
            continue
        for j in range(10):
            idx_j = S.find(str(j), idx_i+1)
            if(idx_j == -1):
                continue
            for k in range(10):
                idx_k = S.find(str(k), idx_j+1)
                if(idx_k == -1):
                    continue
                cnt += 1
    print(cnt)
main()

Measured memory_bytes: 3188
use std::io::Read;

fn trans(a: usize, dp: &mut [bool]) {
    for i in (a..dp.len()).rev() {
        dp[i] |= dp[i - a];
    }
}

fn calc(a: &[usize], dp: &Vec<bool>) -> usize {
    if a.len() == 1 {
        return if dp.iter().rposition(|b| *b).unwrap() + a[0] >= dp.len() {
            0
        } else {
            1
        };
    }
    let n = a.len();
    let m = n / 2;
    let mut next = dp.clone();
    for &a in &a[..m] {
        trans(a, &mut next);
    }
    let ans = calc(&a[m..], &next);
    let mut next = dp.clone();
    for &a in &a[m..] {
        trans(a, &mut next);
    }
    ans + calc(&a[..m], &next)
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let k: usize = it.next().unwrap().parse().unwrap();
    let a: Vec<usize> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let mut dp = vec![false; k];
    dp[0] = true;
    let ans = calc(&a, &dp);
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define SQR(x) ((x) * (x))
 
struct Bipartite_Matching
{
  vector< vector< int > > graph;
  int *match;
  bool *used;
  
  Bipartite_Matching(int n)
  {
    graph.resize(n);
  }
  void add_edge(int u, int v)
  {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  bool dfs(int v)
  {
    used[v] = true;
    for(int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i], w = match[u];
      if(w == -1 || (!used[w] && dfs(w))) {
        match[v] = u;
        match[u] = v;
        return(true);
      }
    }
    return(false);
  }
  int bipartite_matching()
  {
    int ret = 0;
    match = new int[graph.size()];
    used = new bool[graph.size()];
    memset(match, -1, sizeof(int) * graph.size());
    for(int i = 0; i < graph.size(); i++) {
      if(match[i] == -1) {
        memset(used, 0, sizeof(bool) * graph.size());
        ret += dfs(i);
      }
    }
    return(ret);
  }
};
int main()
{
  long long N, M, X[100], Y[100], V[100];
  long long x[100], y[100];
   
  while(cin >> N >> M, N) {
    for(int i = 0; i < N; i++) {
      cin >> X[i] >> Y[i] >> V[i];
    }
    for(int i = 0; i < M; i++) {
      cin >> x[i] >> y[i];
    }
 
    double low = 0, high = 1e9;
    for(int i = 0; i < 60; i++) {
      double mid = (low + high) / 2.0;
      Bipartite_Matching graph(N + M);
      for(int j = 0; j < N; j++) {
        for(int k = 0; k < M; k++) {
          if(sqrt(SQR(X[j] - x[k]) + SQR(Y[j] - y[k])) <= mid * V[j]) {
            graph.add_edge(j, N + k);
          }
        }
      }
      if(graph.bipartite_matching() == M) high = mid;
      else low = mid;
    }
    cout << fixed << setprecision(10) << low << endl;
  }
}

Measured memory_bytes: 1988
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    int count=b/a;
    if(c>count)
    {
        cout<<count;;
    }
    else
    {
        cout<<c;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <set>
#include <sstream>
#include <bitset>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

typedef long long ll;

using namespace std;

int main() {
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    
    vector<int> cnt(n-1,0);
    
    FOR(i, 1, n){
        string l = s.substr(0,i);
        string r = s.substr(i,n-i);
        for(char c='a';c<='z';c++){
            if ((l.find(c) != string::npos)&&(r.find(c) != string::npos)) {
                cnt[i-1]++;
            }
        }
    }
    
    int max = *max_element(cnt.begin(),cnt.end());
    
    cout << max << endl;
    
    return 0;
}



Measured memory_bytes: 256
/*Infor {{{
    > File Name: c.cpp
    > Author: samcompu
    > Mail: a1592710567@126.com
    > Website: https://www.samcompu.com
    > Created Time: 2018年08月25日 星期六 20时08分42秒
}}}*/
#include <bits/stdc++.h>

using namespace std;

/*Abbreviation {{{ */
#define FOR(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define ROF(i,a,b) for (int i = (int)(a); i >= (int)(b); i--)
#define FORLINE(i, t) for (int i = fi[t]; i; i = ne[i])
typedef long long ll;
typedef unsigned long long int ull;
/*}}}*/

/*Constant {{{*/
const int MAXN = 100000;
/*}}}*/

/*Class {{{*/
/*}}}*/

/*Variable {{{*/
int x[MAXN + 1];
/*}}}*/

/*Declare {{{*/
/*}}}*/

/*Main {{{*/
int main() {
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  FOR(i, 1, n) cin >> x[i];
  ll ans = -1;
  FOR(i, 1, n) {
    int l = i, r = i + k - 1;
    if (r > n) continue;
    ll tAns = x[r] - x[l] + min(abs(x[r]), abs(x[l]));
    if (ans == -1 || tAns < ans) ans = tAns;
  }
  cout << ans << endl;
  return 0;
}
/*}}}*/

/*Define {{{*/
/*}}}*/


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

//type
#define ll long long
typedef pair<int, int> P;
//定数
#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
//略記
#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素
#define Z class
// OTHER
// xの二乗を返す (関数テンプレート版)
template <typename T>
T square(T x) { return x * x; }
template <class T>
T GCD(T a, T b)
{
    T r;
    while (a)
        r = b, b = a, a = r % a;
    return b;
}
template <class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))
// loop
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repe(i, n) for (ll i = 0; i <= (n); i++)
#define repd(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (b); i--)
#define FORA(i, I) for (const auto &i : I)

// vector
#define ALL(x) x.begin(), x.end()
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<ll> vl;
#define ERASE(x) x.erase(unique(ALL(x)), x.end()); // erase same elements
#define VEC(type, c, n)     \
    std::vector<type> c(n); \
    for (auto &i : c)       \
        std::cin >> i;

// input
#define INIT                          \
    std::ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define VAR(type, ...) \
    type __VA_ARGS__;  \
    MACRO_VAR_Scan(__VA_ARGS__);
template <typename T>
void MACRO_VAR_Scan(T &t)
{
    std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First &first, Rest &... rest)
{
    std::cin >> first;
    MACRO_VAR_Scan(rest...);
}

// output
template <typename T>
void MACRO_OUT(const T t) { std::cout << t; }

#define OUT(...) MACRO_OUT(__VA_ARGS__);
#define SP std::cout << " ";
#define TAB std::cout << "\t";
#define BR std::cout << "\n";
#define ENDL std::cout << std::endl;

#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n", (x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define yes() printf("yes\n")
#define no() printf("no\n")
#define ln cout << '\n'
template <Z A>
void pr(A a)
{
    cout << a;
    ln;
}
template <Z A, Z B>
void pr(A a, B b)
{
    cout << a << ' ';
}

bool check = 0;
bool boo = 0;
ll min = INF, maxx = 0;
int ans = 0;
string s, t;

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
// cout << (conditon ? (result:  == 1 ): (==0)) << endl; <- output result of if
// long long 型が表せる値の上限はおよそ 9 × 10＾18 です．
int main()
{
    INIT;
    int r, d, x, ans = 0;
    cin >> r >> d >> x;
    rep(i, 10)
    {
        x = r * x - d;
        pr(x);
    }
    return 0;
}


Measured memory_bytes: 3576
#ここまでテンプレ
from sys import stdin
from sys import setrecursionlimit
setrecursionlimit(10 ** 7)

s = stdin.readline().rstrip()
t = stdin.readline().rstrip()

ma = 10**10

for i in range(len(s)-len(t)+1):
    point = 0
    for j in range(len(t)):
        if s[i+j] != t[j]:
            point += 1
    ma = min(ma,point)

print(ma)

Measured memory_bytes: 9124
n = int(input())
M = []
for _ in range(n):
    M.append([int(i) for i in input().split()])

def martixChainMultipication(M):
    n = len(M)
    m = [[0 for _ in range(n)] for _ in range(n)]
    for l in range(2, n+1):
        for i in range(1, n-l+2):
            j = i + l - 1
            m[i-1][j-1] = 1000000
            for k in range(i, j):
                cost = m[i-1][k-1]+m[k][j-1]+M[i-1][0]*M[k-1][1]*M[j-1][1]
                m[i-1][j-1] = min(m[i-1][j-1], cost)
    return m

print(martixChainMultipication(M)[0][n-1])


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

int main(){
    int n; cin >> n;
    vector<int> d(n, 0);
    ll ans = 1;
    int a; cin >> a;
    if(a != 0){cout << 0 << endl; return 0;}
    for(int i = 1; i < n; i++){
        int mid; cin >> mid;
        d[mid]++;
    }
    ll count = 1;
    ll pre = 1;
    for(int i = 1; i < n; i++){
        if(pre == 0 && count < n){
            cout << 0 << endl;
            return 0;
        }
        for(int l = 0; l < d[i]; l++){
            ans = (ans * pre) % div;
        }
        pre = d[i];
        count += d[i];
        if(count == n){
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
package main
 
import (
  "fmt"
)

func main() {
 
  var a,b int
  fmt.Scan(&a,&b)
  
  if (a + b) % 2 == 0 {
    fmt.Println((a + b) / 2)
  } else {
    fmt.Println("IMPOSSIBLE")
  }
}

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

int main() {
  int N, M;

  cin >> N;
  vector<string> blue(N);

  for (int i = 0; i < N; i++){
    cin >> blue.at(i);
  }

  cin >> M;
  vector<string> red(M);

  for (int i = 0; i < M; i++){
    cin >> red.at(i);
  }

  int count = 0, temp = 0;
  string str;

  for (int i = 0; i < N; i++){
      str = blue.at(i);

      for (int j = 0; j < N; j++){
        if (str == blue.at(j)){
          temp++;
        }
      }

      for (int j = 0; j < M; j++){
        if (str == red.at(j)){
          temp--;
        }
      }

      if(temp > count){
        count = temp;
      }
      temp = 0;
  }

  cout << count <<endl;
}


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

int main() {
  ll n, a, b;
  cin >> n >> a >> b;

  ll ans = 0;
  ll tmp = n / (a + b);
  ans += tmp * a;
  if (n - tmp * (a + b) > 0) {
    ans += min(a, n - tmp * (a + b));
  }

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

Measured memory_bytes: 256
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
# from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n=int(input())
	A=list(map(int,input().split()))
	ans=[0]*(n+1)
	
	for i in range(n,0,-1):
		ans[i]=(sum(ans[::i])%2) ^ A[i-1]
	
	print(sum(ans))
	print(*[i for i,x in enumerate(ans) if x==1])
	
	
if __name__ == '__main__':
	main()


Measured memory_bytes: 69616
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int n;
    string s,t;
    cin>>n>>s>>t;
    for(int i=0;i<s.length();i++){
        cout<<s[i]<<t[i];
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;
int n,m;//n--rows m--cols
const int maxn=105;
char g[maxn][maxn];
bool vis[maxn][maxn];
int dis[4][2]={{1,0},{-1,0},{0,-1},{0,1}};

void dfs(int x,int y,char c)
{
    vis[x][y]=1;
    for(int i=0;i<4;i++)
    {
        int xx=x+dis[i][0],yy=y+dis[i][1];
        if(xx>=0&&xx<n&&yy>=0&&yy<m&&g[xx][yy]==c&&!vis[xx][yy])
        {
            dfs(xx,yy,c);
        }
    }

}


int main()
{
    while(~scanf("%d%d",&n,&m)&&(n+m))
    {
        memset(vis,0,sizeof vis);
        for(int i=0;i<n;i++)
        {
            getchar();
            for(int j=0;j<m;j++)
            {
                scanf("%c",&g[i][j]);
            }
        }

        int ans=0;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(!vis[i][j])
                {
                    dfs(i,j,g[i][j]);
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }


    return 0;
}

Measured memory_bytes: 3212
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define all(c) begin(c),end(c)
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
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;}
void print(vec v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vecll v){for(auto e:v)cout<<e<<" ";cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const int INF=1e6;
const ll int MOD=998244353;

main(){
    string s;cin>>s;
    cin>>s;
    cout<<"A"<<s[0]<<"C";
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{

    static void Main(string[] args)
    {
        label:
        WriteLine(d());
        //goto label;
    }

    static int d()
    {
        var sp = ReadLine().Split();
        int sCount = Parse(sp[0]);
        int HP = Parse(sp[1]);
        int furuD = 0;
        var nageD = new List<int>();
        foreach (int i in Enumerable.Range(0, sCount))
        {
            sp = ReadLine().Split();
            furuD = Max(furuD, Parse(sp[0]));
            nageD.Add(Parse(sp[1]));
        }
        nageD = nageD.FindAll(n => furuD < n);
        nageD.Sort();
        for (int i = nageD.Count - 1; 0 <= i; --i)
        {
            HP -= nageD[i];
            if (HP <= 0) return nageD.Count - i;
        }
        return nageD.Count + (HP + furuD - 1) / furuD;
    }
}


Measured memory_bytes: 17232
N, C = map(int, input().split())

tt = [[0] * (10 ** 5 + 1) for _ in range(C)]
for _ in range(N):
    s, t, c = map(int, input().split())
    ttc = tt[c - 1]
    for i in range(s - 1, t):
        ttc[i] = 1

ct = [0] * (10 ** 5 + 1)
for i in range(C):
    tti = tt[i]
    for j in range(10 ** 5 + 1):
        ct[j] += tti[j]

print(max(ct))


Measured memory_bytes: 27380
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

const ll MD = 1e9+7;
const int MN = 5050;

int n, k, f;
ll fact[MN];
ll x[MN];
int dp[MN][MN], sm[MN][MN];
void init() {
	f = n/(2*k);
	fact[0] = 1;
	for (int i = 1; i < MN; i++) {
		fact[i] = fact[i-1] * f;
		fact[i] %= MD;
	}
	dp[0][0] = 1;
	for (int j = 1; j <= 2*k; j++) {
		ll s = sm[0][j-1];
		s += dp[0][j-1];
		s %= MD;
		sm[0][j] = s;
//		sm[0][j] = sm[0][j-1] + dp[0][j-1];
	}
	for (int i = 1; i < MN; i++) {
		for (int j = 0; j < k; j++) {
			ll s = sm[i-1][j+1];
			s += sm[i-1][2*k];
			s -= sm[i-1][j+k+1];
			s %= MD;
			s = (s+MD) % MD;
			dp[i][j] = s;
//			dp[i][j] = sm[i-1][j+1] + sm[i-1][2*k] - sm[i-1][j+k+1];
		}
		for (int j = k; j < 2*k; j++) {
			ll s = sm[i-1][j+1];
			s -= sm[i-1][j-k+1];
			s %= MD;
			s = (s+MD) % MD;
			dp[i][j] = s;
//			dp[i][j] = sm[i-1][j+1] - sm[i-1][j-k+1];//dp[i-1][j]+dp[i-1][j-1]+dp[i-1][j-2]..dp[i-1][j-k+1]
		}
		for (int j = 1; j <= 2*k; j++) {
			ll s = sm[i][j-1];
			s += dp[i][j-1];
			s %= MD;
			s = (s+MD) % MD;
			sm[i][j] = s;
//			sm[i][j] = sm[i][j-1] + dp[i][j-1];
		}
	}
}

int main() {
	int m, q;
	cin >> n >> m >> k >> q;
	init();
	for (int i = 0; i < q; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		c = (c - a + n) % n;
		if (b == 0) {
			if (c == 0) {
				printf("1\n");
			} else {
				printf("0\n");
			}
			continue;
		}
		c %= 2*k;
		printf("%lld\n", fact[b-1]*dp[b][c] % MD);
	}
    return 0;
}

Measured memory_bytes: 199624
k = int(input())

dp = [[[] for j in range(11)] for i in range(11)]


for i in range(10):
    dp[1][i].append(i)
    dp[0][i].append(0)


if k<=9:
    print(k)
    exit()

k-=9

for i in range(2, 11):
    for j in range(1, 10):
        if j==1:
            for z in range(i):
                for x in dp[z][j]:
                    dp[i][j].append(j*10**(i-1)+x)
                    k-=1
                    if k==0:
                        print(dp[i][j][-1])
                        exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
        else:
            for x in dp[i-1][j-1]:
                dp[i][j].append(j*10**(i-1)+x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()
            for x in dp[i - 1][j + 1]:
                dp[i][j].append(j * 10 ** (i-1) + x)
                k-=1
                if k==0:
                    print(dp[i][j][-1])
                    exit()




Measured memory_bytes: 40304
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k,t;
  cin >> k >> t;
  int m=0;
  for(int i=0;i<t;i++){
    int a;
    cin >> a;
    m=max(m,a);
  }
  cout << max(m-1-k+m,0) << endl;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr = input.trim().split("\n");
var q=arr.shift()-0;
var str="";
var map = new Map();
for(var i=0;i<q;i++){
   var [a,b,c]=arr[i].split(" ");
   if(a=="0")map.set(b,c);
   else str+=map.get(b) + "\n";
}
console.log(str.trim());


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

using namespace std;

int a[100000];

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    cin>>a[i];
    sort(a+1,a+n+1);
    int sum=0;
    for(int i=n;i>=n-m+1;i--)
    sum+=a[i];
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		int A = sc.nextInt();
		int B = sc.nextInt();
		String U = sc.next();

		if(U.equals(S)) {
			A=A-1;
		}else if(U.equals(T)){
			B=B-1;
		}

		System.out.println(A+" "+B);

		sc.close();
	}
}

Measured memory_bytes: 22740
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    int N;R(N);
    LL an=0,sum=0;
    FOR(i,1,N){
        int x;R(x);
        sum+=x;
        an-=x*x;
    }
    an+=sum*sum;
    W(an/2);
    return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define endl            "\n"
#define pb              push_back
#define ppb              pop_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define all(x)          (x).begin(), (x).end()
#define mii             map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             1e18
#define sp(x,y)         fixed << setprecision(y) << x
#define w(x)            int x; cin >> x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
const int M = 1e9 + 7;
inline int ceili(int x, int y) { return (x + y - 1) / y; }
inline int mod(int x) { return ((x % M + M) % M); }
inline int add_mod(int a, int b) { return mod(mod(a) + mod(b)); }
inline int mul_mod(int a, int b){ return mod(mod(a) * mod(b)); }
 
void solve()
{
    int n; cin >> n;
    vector<int> a(n);

    for(auto &it : a) cin >> it;

    vector<int> suf(n + 1);
    for(int i = n - 1; i >= 1; --i) {
        suf[i] = suf[i + 1] + a[i];
    }

    int ans = 0;
    for(int i = 0; i < n; ++i) {
        ans = add_mod(ans, mul_mod(a[i], suf[i + 1]));
    }

    cout << ans << endl;
}
 
int32_t main()
{
    FIO;

    solve();

    return 0;
}

Measured memory_bytes: 6388
#include<iostream>

using namespace std;
//X+Y+Z = S, K

int main(){
  int K,S,count=0; cin >> K >> S;

  for(int i=0; i<=K; i++){
      for(int j=0; j<=K; j++){
      int Z = S -(i+j);
        if(Z >= 0 && Z <= K){
          count += 1;
        }
      }
  }

cout << count<< endl;

return 0;

}







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


void solve(long long N, std::string S, long long K){
  char target = S.at(K - 1);
  for(int i = 0; i < N; ++i){
    if(S.at(i) != target){
      S.at(i) = '*';
    }
  }
  cout << S << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::string S;
    std::cin >> S;
    long long K;
    scanf("%lld",&K);
    solve(N, S, K);
    return 0;
}


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

int main(){
    int n,x,t;
    cin >> n >> x >> t;
    if(n%x == 0) cout << (n/x) * t << endl;
    else cout << (n/x + 1)*t << endl;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define re register
#define IL inline
using namespace std;
const int maxn=1e5+10;
const ll mod=1e9+7;
template<typename T> void read(T &x){
	T f=1;x=0;
	char s=getchar();
	while(s<'0' || s>'9'){if(s=='-') f=-1;s=getchar();}
	while(s>='0' && s<='9'){x=(x<<3)+(x<<1)+s-48;s=getchar();}
	x*=f;
}
int n;
vector<int> son[maxn];
ll f[maxn][2];
bool book[maxn];
void dfs(int st){
	if(!son[st].size())	return;
	for(re int i=0;i<son[st].size();i++){
		int j=son[st][i];
		if(!book[j]){
			book[j]=true;
			dfs(j);
			f[st][0]=(f[st][0]*(f[j][0]+f[j][1]))%mod;
			f[st][1]=(f[st][1]*f[j][0])%mod;
		}
	}
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	read(n);
	for(re int i=1;i<n;i++){
		f[i][0]=f[i][1]=1;
		int x,y;
		read(x);read(y);
		son[x].push_back(y);
		son[y].push_back(x);
	}
	f[n][0]=f[n][1]=1;
	book[1]=1;
	dfs(1);
	cout<<(f[1][0]+f[1][1])%mod<<endl;
	return 0;
}


Measured memory_bytes: 12928
unittest
{
	assert( [ "2", "2 2", "9 1" ].parse.expand.solve == 3 );
	assert( [ "3", "1 1", "0 8", "7 1" ].parse.expand.solve == 9 );
	
	assert( [ "2", "4 6", "9 1" ].parse.expand.solve == 9 );		// 追加ケース
	assert( [ "2", "4 7", "9 1" ].parse.expand.solve == 11 );		// 追加ケース
	assert( [ "2", "4 8", "9 1" ].parse.expand.solve == 12 );		// 追加ケース
	assert( [ "200000" ].chain( "9 5000000000".repeat( 200000 ) ).parse.expand.solve == 1999999999999998 );		// 追加ケース
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto m = input.front.to!( long );
	auto dcs = new long[ 2 ][ m ];
	foreach( ref dc; dcs )
	{
		input.popFront;
		dc = input.front.split.to!( long[] );
	}
	return tuple( dcs );
}

auto solve( long[ 2 ][] dcs )
{
	auto ans = 0L;
	long[] ds;
	foreach( dc; dcs )
	{
		// 同じdの桁を足し算
		auto r = solve2( dc[ 0 ], dc[ 1 ] );
		ds ~= r[ 0 ];
		ans += r[ 1 ];
		
		// 違うdの桁を足し算
		while( 2 <= ds.length )
		{
			auto dt = ds[ 0 ] + ds[ 1 ];
			ds.popFront;
			
			if( dt < 10 )
			{
				ds.front = dt;
				ans++;
			}
			else
			{
				ds.front = dt % 10 + 1;
				ans += 2;
			}
		}
	}
	return ans;
}

Tuple!( long[], long ) solve2( long d, long c )
{
	long[] ds;
	auto t = 0L;
	
	// 10 <= d * c になる最小の c
	auto u = ( d == 0 ) ? long.max : 10 / d + ( 0 < 10 % d );
	
	if( c < u )
	{
		// 繰り上がりなしの場合
		
		// 全桁足し算する
		ds ~= d * c;
		t += c - 1;
	}
	else
	{
		// 繰り上がりありの場合
		
		// 繰り上がりが発生する分を1桁になるまで足し算する
		{
			auto r = solve2( ( d * u ) % 10 + 1, c / u );
			ds ~= r[ 0 ];
			t += r[ 1 ] + ( c - c % u );
		}
		
		// 繰り上がりが発生しない分を1桁になるまで足し算する
		if( 0 < c % u )
		{
			auto r = solve2( d, c % u );
			ds ~= r[ 0 ];
			t += r[ 1 ];
		}
	}
	
	return tuple( ds, t );
}


Measured memory_bytes: 5884
// inputに入力データ全体が入る
function Main(input) {
  input = input.replace('\n', '');
  var input = input.split(' ');
  var X = parseInt(input[0]);
  var Y = parseInt(input[1]);
 
  console.log('%d', X + Y / 2);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>
#include <string>
using namespace std;
int main() {
	string x; int y,AC=0,WA=0,TLE=0,RE=0;
	cin >> y;
	for (int i = 0; i < y; i++){
		cin >> x;
		if (x == "AC") {
			AC++;
		}
		else if (x == "WA") {
			WA++;
		}
		else if (x == "TLE") {
			TLE++;
		}
		else if (x == "RE") {
			RE++;
		}
	}
	cout << "AC x " << AC << "\nWA x " << WA << "\nTLE x " << TLE << "\nRE x " << RE;
	return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int ans = 0;
    for(unsigned int i = 1; i < s.size(); i++){
        if((s[i-1] == 'B' && s[i] == 'W') || 
           (s[i-1] == 'W' && s[i] ==  'B')) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end


class Dice
  attr_accessor:node,:top,:s,:e,:num
  def initialize(arr)
    @node=Array.new(6){|i| i+1}
    @num=arr
    @top=1
    @s=2
    @e=3
  end

  def reverse_num(x)
    return 7-x
  end

  def S()
    top=@top
    s=@s
    e=@e
    @top=reverse_num(s)
    @s=top
  end

  def E()
    top=@top
    s=@s
    e=@e
    @top=reverse_num(e)
    @e=top
  end

  def W()
    top=@top
    s=@s
    e=@e
    @top=e
    @e=reverse_num(top)
  end

  def N()
    top=@top
    s=@s
    e=@e
    @top=s
    @s=reverse_num(top)
  end
end

a=get_i
dice=Dice.new(a)
q=gets.to_i
q.times do
  top,s=get_i
  4.times do
    4.times do
      break if dice.num[dice.s-1]==s
      dice.S
    end
    4.times do
      break if  dice.num[dice.top-1]==top
      dice.W
    end
    break if dice.num[dice.s-1]==s and dice.num[dice.top-1]==top
    dice.W
    dice.S
  end
  puts dice.num[dice.e-1]
end


Measured memory_bytes: 6884
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <utility>
#include <cstdlib>
#include <memory>
#include <queue>
#include <cassert>
#include <cmath>
#include <ctime>
#include <complex>
#include <bitset>
#include <fstream>
#include <unordered_map>
#include <unordered_set>
#include <numeric>

using namespace std;

#define ws ws_____________________
#define y1 y1_____________________
#define y0 y0_____________________
#define left left_________________
#define right right_______________
#define next next_________________
#define prev prev_________________
#define hash hash_________________

#define pb push_back
#define fst first
#define snd second
#define mp make_pair 
#define sz(C) ((int) (C).size())
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define ford(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(C) begin(C), end(C)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef long double ld;
typedef complex<double> cd;

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define FILE_NAME "a"

int a, b, c, d, e, f;

bool read() {
	if  (scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f) < 6) {
		return 0;
	}
	return 1;
}

void solve() {
	vi can_water(f + 1, 0);
	for (int x = 0; x * 100 * a <= f; ++x) {
		for (int y = 0; x * 100 * a + y * 100 * b <= f; ++y) {
			can_water[x * 100 * a + y * 100 * b] = 1;
		}
	}

	vi can_sugar(f + 1, 0);
	for (int x = 0; x * c <= f; ++x) {
		for (int y = 0; x * c + y * d <= f; ++y) {
			can_sugar[x * c + y * d] = 1;
		}
	}

	int best_nom = 0;
	int best_denom = 1;
	int best_sum = 0;
	int best_sug = 0;
	forn(w, f + 1) {
		forn(s, f + 1 - w) {
			assert(s + w <= f);
			if  ((w || s) && can_water[w] && can_sugar[s] && s * 100 <= w * e) {
				const int nom = s;
				const int denom = s + w;
				if  (nom * best_denom >= best_nom * denom) {
					best_nom = nom;
					best_denom = denom;
					best_sum = s + w;
					best_sug = s;
				}
			} 
		}
	}

	printf("%d %d\n", best_sum, best_sug);
}

int main() {
#ifdef LOCAL
	freopen(FILE_NAME ".in", "r", stdin);
	// freopen(FILE_NAME ".out", "w", stdout);
#endif

	while (read()) {
		solve();
	}

#ifdef LOCAL
	cerr.precision(5);
	cerr << "Time: " << fixed << (double) clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}


Measured memory_bytes: 256
use std::io::stdin;
fn main() {
    let mut st = String::new();
    stdin().read_line(&mut st).unwrap();
    let s:Vec<char> = st.trim().chars().collect();
    let mut ten = 1;
    let mut c:usize = 0;
    let mut r:[i64;2020] = [0;2020];
    let m = s.len() as usize;
    for i in 1..m+1 {
        let x = (s[m-i] as usize)-48;
        c = (c+x*ten)%2019;
        r[c] += 1;
        ten = (ten*10)%2019;
    };
    let mut result:i64 = 0;
    for i in 0..2019 {
        if &1 < &r[i] {
            result += (r[i]-1)*r[i]/2
        };
    };
    result += r[0];
    println!("{}", result);
}

Measured memory_bytes: 2948
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var n=Arr.shift();
   if(n=="0")break;
   var arr=(Arr.shift()).split(" ").map(Number);
   var k=0;
   var S=[];
   while(true){
      for(var i=0;i<arr.length;i++){
         var cnt=0;
         for(var j=0;j<arr.length;j++){
            if(arr[i]==arr[j])cnt++;
         }
         S.push(cnt);
      }
      if(S.join(" ")==arr.join(" "))break;
      arr=S.slice();
      S=[];
      k++;
   }
   console.log(k);
   console.log(S.join(" "));
}

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

int main(){

  int n;

  while(cin >> n){
    int m = 0;

    for(int i=0;i<n;i++){
      m++;
      if(m == 40) m = 1;
    }

    printf("3C%02d\n",m);

  }
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
int color[9], n, a, res;
int main(void){
    // Your code here!
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a < 3200) color[a / 400]++;
        else color[8]++;
    }
    for (int i = 0; i < 8; i++) {
        if (color[i]) res++;
    }
    cout << max(res, 1) << ' ' << res + color[8] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int N; cin >>N;
  vector<ll> A(N); rep(i, N) cin >>A[i];
  map<ll,ll> S;
  rep(i, N) S[i - A[i]]++;
  ll res = 0;
  rep(i, N){
    S[i - A[i]]--;
    res += S[A[i] + i];
  }
  cout <<res <<endl;
}

/*
i < j について、
j - i = Ai + Aj
Ai + i = j - Aj

*/

Measured memory_bytes: 27456
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static int[] w = new int[100010];
    static int[] v = new int[100010];
    static int[][] dp = new int[110][100010];
    static int k;

    static int chmin(int a, int b) {
        if (a > b) {
            a = b;
            return a;
        }
        return a;
    }

    static int chmax(int a, int b) {
        if (a < b) {
            a = b;
            return a;
        }
        return a;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        System.out.println(a + b >= c ? "Yes" : "No");

    }
}


Measured memory_bytes: 78804
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int n;
    cin >> n;
    int w[n];
    int a[n+1];
    a[0]=0;
    for(int i=0; i<n; i++) {
        cin >> w[i];
        a[i+1] = a[i] + w[i];
    }
    
    int min=50000;
    for(int i=0; i<n; i++) {
        if(abs(a[n]-2*a[i])<min) min = abs(a[n]-2*a[i]);
    }
    
    cout << min << endl;

    return 0;
    
}

Measured memory_bytes: 256
def main():
    N = int(input())
    S = list(map(int, input().split()))
    INF = float('inf')

    S.sort()

    parents = [S[-1]]
    S[-1] = INF

    for _ in range(N):
        checking = 2
        parents.sort(reverse=True)
        for i in parents[:]:
            while True:
                if S[-checking] < i:
                    parents.append(S[-checking])
                    S[-checking] = INF
                    break
                else:
                    checking += 1
                if checking == 2 ** N + 1:
                    print('No')
                    exit()
    else:
        print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 34676
import sys
N,X = map(int,input().split())
l = list(map(int,input().split()))
for i in range(N-1):
  l[i+1] += l[i]
  
for i in range(N):
  if l[i] > X:
    print(i+1)
    sys.exit()
    
print(N+1)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n=I()
u=[I() for i in range(5)]
ans=5-1+ceil(n/min(u))
#print(min(u))
print(ans)

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

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	bool f = false;
	for (int i = 0; i <= A; i++) {
		if ((B*i + C) % A == 0) {
			f = true;
			break;
		}
	}
	if (f)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define _rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define SF scanf
#define PF printf
using namespace std;
int a,b,c,k;
int main(){
	SF("%d%d%d%d",&a,&b,&c,&k);
	while(1){
		if(!k)break;
		while(b<=a){
			if(!k)break;
			b<<=1;k--;
		}
		while(c<=b){	
			if(!k)break;
			c<<=1;k--;		
		}
		if(c>b&&b>a)break;
	}
	if(c>b&&b>a)PF("Yes");else PF("No");
	return 0;
}

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

const int N = 1 << 18, mod = 998244353;
typedef long long LL;
int n, s, lim, a[N];

void reduce(int &x) { x += x >> 31 & mod; }
int pow(int x, int y, int ans = 1) {
	for (; y; y >>= 1, x = (LL) x * x % mod)
		if (y & 1) ans = (LL) ans * x % mod;
	return ans;
}
void fwt(int *A) {
	for (int i = 1; i < lim; i <<= 1)
		for (int j = 0; j < lim; j += i << 1)
			for (int k = 0; k < i; ++k) {
				const int x = A[k + j], y = A[k + j + i];
				reduce(A[k + j] += y - mod), reduce(A[k + j + i] = x - y);
			}
}
int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, lim = 1 << n;
	for (int i = 0; i < lim; ++i) std::cin >> a[i], s += a[i];
	s = pow(s, mod - 2);
	for (int i = 0; i < lim; ++i) a[i] = (LL) a[i] * s % mod;
	fwt(a), s = a[0] = 0;
	for (int i = 1; i < lim; ++i)
		a[i] = pow(mod + 1 - a[i], mod - 2), reduce(s += a[i] - mod);
	fwt(a), a[0] = 0;
	for (int i = 1; i < lim; ++i)
		reduce(a[i] = s - a[i]);
	for (int i = 0; i < lim; ++i)
		std::cout << a[i] << '\n';
	return 0;
}

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

int main(void){
	char list[26];
	list[0]='a';
	for(int i=1;i<26;i++)
		list[i]=list[i-1]+1;
	string S;
	while(true){
		getline(cin,S);
		if(cin.eof())
			break;
		for(int i=0;i<26;i++){
			for(string ::iterator it=S.begin() ;it!=S.end();it++)
				if(islower(*it))
					*it=list[(*it-'a'+1)%26];
			if(S.find("this")!=-1||S.find("that")!=-1||S.find("the")!=-1)
				break;
		}
		cout << S <<endl;
	}
	return 0;
}

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

int main(void)
{
  int n;
  string s, t;
  cin >> n;
  cin >> s >> t;
  for(int i = 0; i < n; i++)
  {
    cout << s.at(i) << t.at(i);
  }
  cout << endl;
}

Measured memory_bytes: 256
from collections import deque
n = int(input())
a =deque([3,5,7])
s = 0
while  len(a)!=0 :
  b = a.popleft()
  if b<=n:
    a.append(10*b+3)
    a.append(10*b+5)
    a.append(10*b+7)
    if len(set([j for j in str(b)]))==3:
      s += 1
print(s)
    


Measured memory_bytes: 6132
#include "iostream"

using namespace std;

int c;

void marge(int s[500000], int head, int mid, int tail) {

	int x[500000];
	int m = mid;

	for (int i = head; i < tail; i++) {
		x[i] = s[i];
	}

	for (int i = head; i < tail; i++ ) {
		if (mid == tail) {
			s[i] = x[head];
			head++;
		}
		else if (head == m) {
			s[i] = x[mid];
			mid++;
		}
		else if (x[head] <= x[mid]) {
			s[i] = x[head];
			head++;
		}
		else {
			s[i] = x[mid];
			mid++;
		}
		c++;
	}

}

//head 0???????????????
//tail ?????????????´???????????¬?????????????n = 10?????????tail = 10

void msort(int s[500000], int head, int tail) {

	if ( tail - head <= 1) return;

	int mid = head + (tail - head)/2;

	msort(s, head, mid);
	msort(s, mid, tail);

	marge( s, head, mid, tail );
}

int main() {

	int s[500000];
	int n;

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

	msort( s, 0, n );

	for (int i = 0; i < n; i++) {
		cout << s[i];
		if (i < n - 1) {
			cout << " ";
		}
	}

	cout << endl << c << endl;

	return 0;
}

Measured memory_bytes: 5064
n, k = map(int, input().split())
d = list(map(int, input().split()))
w = [False] * 10
for i in d:
	w[i] = True
def check(n):
	while n:
		if w[n % 10]:
			return False
		n //= 10
	return True
ans = n
while not check(ans):
	ans += 1
print(ans)

Measured memory_bytes: 9176