akhauriyash/Code-Regression huggingface dataset:
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)

'''

#a = list(map(int, input().split()))



h,w,d = list(map(int, input().split()))

info = []
for i in range(h):
    info.append(list(map(int, input().split())))
    
n = int(input())
qs = []
for i in range(n):
    qs.append(list(map(int, input().split())))
    
place = [[-1,-1] for i in range(h*w+1)]

for i in range(h):
    for j in range(w):
        place[info[i][j]] = [i,j]

lines = [[0] for i in range(d)]

for i in range(d):
    now = i
    dist = 0
    for j in range((h*w-i)//d):
        now += d
        p1 = place[now]
        p2 = place[now-d]
        dist += abs(p1[0]-p2[0])+abs(p1[1]-p2[1])
        lines[i].append(dist)

for i in range(n):
    k = qs[i][0]%d
    ll = qs[i][0]//d
    rr = qs[i][1]//d
    print(lines[k][rr]-lines[k][ll])














Measured memory_bytes: 120024
import java.util.*;

public class Main {
    private static final long MOD = 1_000_000_007;

    private Map<String, Long> map = new HashMap<>();

    public void main(Scanner sc) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        sc.close();

        System.out.println(f(n, m));
    }

    private long f(int n, int m) {
        String key = n + ":" + m;
        if (map.containsKey(key)) {
            return map.get(key);
        }

        if (n == 1 || m == 1) {
            return 1;
        }

        long cnt = 0;
        for (int i = 1; i * i <= m; i++) {
            if (m % i == 0) {
                long tmp = (f(n / 2, i) * f((n + 1) / 2, m / i) % MOD);
                if (i * i != m) {
                    tmp += (f(n / 2, m / i) * f((n + 1) / 2, i) % MOD);
                }

                cnt += tmp;
                cnt %= MOD;
            }
        }

        map.put(key, cnt);

        return cnt;
    }

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


Measured memory_bytes: 108988
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

string S;
int K;

int main(void) {
    cin >> S >> K;
    set<string> se;
    REP(i, S.size()) {
        REP(j, 5) {
            if (i + j < S.size()) {
                se.emplace(S.substr(i, j + 1));
            }
        }
    }
    auto itr = se.begin();
    REP(i, K - 1) itr++;
    cout << *itr << endl;

}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}
int main(){
  int N;cin>>N;
  ll ans=0;
  for(int i=1; i<=N;i++){
    if(i%2==1&&yakusu_num(i)==8){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <tuple>
#include <climits>

using namespace std;


int main() {
    string s;
    cin>>s;
    if (s.substr(0, 4) == "YAKI") cout<<"Yes\n";
    else cout<<"No\n";
}

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


int main() {
	
	int N, k;
	cin >> N >> k;
	multiset<int> s;
	set<int> t;
	for(int i=0; i<N; i++){
		int a;
		cin >> a;
		s.insert(a);
		t.insert(a);
	}
	
	vector<int> pi(t.size());
	int cnt = 0;
	for(int i=1; i<=N; i++){
		if(s.count(i)){
			pi.at(cnt) = s.count(i);
			cnt++;
		}
	}
	sort(pi.begin(),pi.end());
	int sum = 0;
	if (t.size() >= k){
		for(int i=0; i<t.size()-k; i++) sum += pi.at(i);
		cout << sum << endl;
	}
	else cout << 0 << endl;
	
	return 0;
}

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

int main(void) {
  int k, s;
  cin >> k >> s;

  int result = 0;
  for (int i = max(0, s - 2 * k); i <= k; i++) {
    for (int j = max(0, s - k - i); j <= min(k, s - i); j++) {
      result++;
    }
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dp[1005][1005];
int main(){
string s,t;
cin>>s>>t;
int n=s.size(),m=t.size();
for(int i=0;i<=n;i++)dp[i][0]=i;
for(int i=0;i<=m;i++)dp[0][i]=i;
for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
        int cost=!(s[i-1]==t[j-1]);
        dp[i][j]=min({dp[i-1][j]+1,dp[i][j-1]+1,dp[i-1][j-1]+cost});
    }
}
cout<<dp[n][m]<<endl;
}



Measured memory_bytes: 7132
#include <stdio.h>
using namespace std;
#define repeq(i,r) for (int i = 1; i <= r; i++)
#define isc(n) scanf("%d", &n)

int gcd(int a, int b) {
  return a % b == 0 ? b : gcd(b, a % b);
}

int main() {
  int K; isc(K);
  long res = 0;
  repeq(i,K) repeq(j,K) repeq(k,K) res += gcd(gcd(i,j),k);
  printf("%ld", res);
  return 0;
}


Measured memory_bytes: 1736
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder0802
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] ND = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = ND[0];
            int D = ND[1];
            int ans = 0;
            int[] XY = new int[2];
            int X;
            int Y;
            var list = new List<int[]>();

            for (var i = 0; i < N; i++)
            {
                XY = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                list.Add(XY);
            }

            for (var i = 0; i < N; i++) {
                int[] array = list[i].ToArray();
                 X = array[0];
                 Y = array[1];
                if(Math.Pow(X,2) + Math.Pow(Y, 2) <= Math.Pow(D, 2))
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 50756
n = gets.to_i
p = []
(n-1).times do |i|
  p[i] = gets.split[0].to_i
end
p.concat gets.split.map &:to_i
m = Array.new(n){ Array.new(n, 1000000) }
n.times do |i|
  m[i][i] = 0
end
(1...n).each do |j|
  (0...n-j).each do |k|
    last = k+j
    a = []
    (k...last).each do |l|
      a << m[k][l] + m[l+1][last] + p[k] * p[l+1] * p[last+1]
    end
    m[k][last] = a.min
  end
end
puts m[0][n-1]

Measured memory_bytes: 10256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
constexpr long double EPS = 1e-11;
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;
}
int main(){
    ll h, w;
    cin >> h >> w;
    char grid[h][w];
    for (ll i = 0; i < h;i++){
        for (ll j = 0; j < w;j++){
            cin >> grid[i][j];
        }
    }
    bool flagh[h];
    for (ll i = 0; i < h; i++) flagh[i] = false;
    bool flagw[w];
    for (ll i = 0; i < w; i++) flagw[i] = false;
    for (ll i = 0; i < h;i++){
        for (ll j = 0; j < w;j++){
            if (grid[i][j] == '#'){
                flagh[i] = true;
                flagw[j] = true;
            }
        }
    }
    for (ll i = 0; i < h;i++){
        if(flagh[i]){for (ll j = 0; j < w;j++){
            if (flagw[j]) cout << grid[i][j];
        }
        cout << endl;}
    }
}

Measured memory_bytes: 3580
from bisect import bisect_left
while 1:
    d = input()
    if d == 0: break
    n = input()
    m = input()
    s = [input() for i in range(n-1)]
    s += [0]
    s.sort()
    ans = 0
    for i in range(m):
        t = input()
        j = bisect_left(s, t)
        if j == n: ans += min(t-s[n-1], d-t)
        elif j == 0: continue
        else: ans += min(t-s[j-1], s[j]-t)
    print ans

Measured memory_bytes: 12984
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,s,d,j,k;
  cin>>a>>s>>d;
  if(a>=s) j=a-s;
  else j=s-a;
  if(a>=d)k=a-d;
  else k=d-a;
  if(j>k)cout<<"B"<<endl;
  else cout<<"A"<<endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,0,-1,1,-1,-1,1};
const int dy[]={0,1,-1,0,1,1,-1,-1};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define reps(i,j,k) for(int i = (j); i < (k); ++i)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define DEBUG 0
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> Pii;
typedef pair<int,vi > P;
typedef long long ll;
int main(){
	int N,M;
	int A[5001], B[5001];
	int dp[2][5001] = {{0}};
	scanf("%d %d", &N, &M);
	rep(i,N){
		scanf("%d" ,&A[i]);
	}
	rep(i,M){
		scanf("%d" ,&B[i]);
	}
	int now = 0;
	int prev = 1;
	int ans = -INF;
	rep(i,M){ //B
		rep(j,N){ //A
			if(B[i] == A[j]){
				dp[now][j] = 1;
				rep(k,j){
					if(dp[prev][k]){
						dp[now][j] = max(dp[now][j],dp[prev][k] + 1);
					}
				}
			}

			ans = max(ans,dp[now][j]);
		}
		memset(dp[prev],0,sizeof(dp[prev]));
		/*rep(j,N){
			printf("%d ",dp[now][j]);
		}
		puts("");*/
		swap(now,prev);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1276
#include <iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<sstream>
#include<vector>
#include<stack>
#include<set>
#include<map>
using namespace std;

struct List{
	int a;
	int b;
};

int main(void){
    List l,p;
	cin>>l.a>>l.b;
	vector<List> list;
	int o=0;
	while(cin>>p.a>>p.b){
		if(p.b<=l.b){
			list.push_back(p);
			o++;
		}
	}
	if(o==0){
		cout<<"TLE";
		exit(0);
	}
	int min=list[0].a;
	for(auto it=list.begin();it!=list.end();it++){
		if(it->a<min)
			min = it->a;
	}
	cout<<min;
    return 0; 
}


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

int main()
{
    ll N, K;
    string S;
    cin >> N >> K >> S;
    ll cng = -1;
    char now = '-';
    for (char c : S)
    {
        if (c != now)
            cng++;
        now = c;
    }
    cng = max(0LL, cng - 2 * K);
    cout << N - cng - 1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<map>
#include<vector>
using namespace std;
typedef pair<int,int> pii;

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

int main(){
  int n;
  int houkou,num;
  while(cin>>n,n){
    vector<pii> ans(n);
    pii tmp;
    ans[0] = make_pair(0,0);
    for(int i=1;i<n;i++){
      cin>>num>>houkou;
      tmp=ans[num];
      ans[i] =  make_pair(tmp.first+dx[houkou],tmp.second+dy[houkou]) ;
    }
    int MaxX=0,MaxY=0,MinX=0,MinY=0;
    for(int i=0;i<n         ;i++){
      if(ans[i].first>MaxX) MaxX=ans[i].first;
      if(ans[i].first<MinX) MinX=ans[i].first;
      if(ans[i].second>MaxY) MaxY=ans[i].second;
      if(ans[i].second<MinY) MinY=ans[i].second;
      //cout << ans[i].first << " " << ans[i].second << endl;
    }
    cout<<MaxX-MinX+1<<" "<<MaxY-MinY+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a = [0] * 100005

isp = [1] * 100005
isp[0] = isp[1] = 0
for i in range(2, 100005):
    if isp[i]:
        for j in range(i*i, 100005, i):
            isp[j] = 0
for i in range(3, 100005, 2):
    if isp[i] and isp[(i+1)//2]:
        a[i] = 1
for i in range(1, 100004):
    a[i+1] += a[i]

q = ni()
for i in range(q):
    l, r = na()
    print(a[r] - a[l-1])


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

int main(){
      int n;cin >> n;
      string s;cin >> s;
      int t = s.length();
      for(int i = 0;i < t;i++){
            s[i] = 'A' + (s[i] - 'A' + n) % 26;
      }
      cout << s;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
    vector<int> x(3);
    cin>>x[0]>>x[1]>>x[2];
    sort(all(x));
    if(x[2]-x[1]==x[1]-x[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
//using
using namespace std;
/*using vi = vector<int>;
using vs = vector<string>;
using vc = vector<char>;*/
//define
#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
//グローバル変数宣言
int a=0,b=0,c=0;

signed main(){
    cin>>a>>b;
    a-=1;//+a
    b-=1;//b+
    if(b%a==0)cout<<b/a<<endl;
    else cout<<b/a+1<<endl;
}

Measured memory_bytes: 3644
def main
  # min = ARGV[0].to_i
  # max = ARGV[1].to_i
  # multiple = ARGV[2].to_i
  min, max, multiple = gets.split(' ')
  min = min.to_i
  max = max.to_i
  multiple = multiple.to_i
  
  return puts 0 if multiple == 0
  min_multi = (min / multiple) * multiple
  min_multi = min_multi + multiple if min_multi < min
  max_multi = (max / multiple) * multiple

  return puts 0 if max_multi == 0

  count = (max_multi - min_multi) / multiple + 1
  

  return puts count
end

main

Measured memory_bytes: 14256
N = int(input())
V = [[] for _ in range(N+1)]
check = [0]*(N+1)
color = [0]*(N+1)
d = dict()
for _ in range(N-1):
    u, v, w = map(int, input().split())
    V[u].append((v, w))
    V[v].append((u, w))

color[1] = 1
check[1] = 1
queue = []
for u, w in V[1]:
    queue.append((u, w))
    d[u] = color[1]
while queue:
    u, w = queue.pop()
    check[u] = 1
    if w % 2:
        if d[u]:
            color[u] = 0
        else:
            color[u] = 1
    else:
        color[u] = d[u]
    for next_u, next_w in V[u]:
        if check[next_u] == 0:
            queue.append((next_u, next_w))
            d[next_u] = color[u]

for i in range(1, N+1):
    print(color[i])

Measured memory_bytes: 83232
#include <iostream>


using namespace std;

int main()
{
int n ,x ,mx= -1;
scanf("%d",&n);
char s;
for(int i=0;i<=n;i++){
	scanf("%c",&s);
	if(s=='I'){
	x++;
	}
mx= max(x,mx);
	 if(s=='D'){
	x--;
	} }
printf("%d",mx);}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>


using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;


int main(void)
{
	int n, h, w;

	while(scanf("%d%d%d", &n, &h, &w)==3)
	{
		printf("%d\n", (n-h+1)*(n-w+1));
	}

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int N, M, C; cin >> N >> M >> C;
  vi B(M); rep(i,M) cin >> B.at(i);
  vvi A(N,vi(M));
  rep(i,N) rep(j,M) cin >> A.at(i).at(j);
  
  int ans = 0;
  rep(i,N) {
    int x = C;
    rep(j,M) {
      x += A.at(i).at(j)*B.at(j);
    }
    if (x>0) ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split(" "))

ans = 0
for n in range(N):
    s = n+1
    p = 1/N #ダイスの確率
    
    if s>=K:
        ans += p
    else:
        count = 0
        while s < K:
            count += 1
            s = s*2
            p = p/2
        ans += p
print(ans)



Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll; //long longをllとして簡略

int main(){
  string n;
  cin >> n;
  int max = n.size();
  int ans=0;
  rep(i,max){
    if(n[i]!=n[max-i-1] && max/2 > i){
      ans++;
    }
  }
  cout << ans <<endl;
  return 0;
}

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

const int DIM = 1e5 + 5;

int box[DIM];
bitset<DIM> oki;

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    oki[1] = true;
    fill( box + 1, box + n + 1, 1 );
    
    for( int i = 1; i <= m; i ++ ) {
        int x, y;
        cin >> x >> y;
    
        if( oki[x] == true )
            oki[y] = true;
        
        box[x] --; box[y] ++;
        
        if( box[x] == 0 )
            oki[x] = false;
    }
    
    cout << oki.count() << endl;
    return 0;
}

Measured memory_bytes: 768
N, X, M = [int(v) for v in input().split()]

def f(a):
    return a * a % M

a = X

map = {}
ary = [a]
map[a] = 0

sub = [0, a]
last_sub = a

count = 1
for i in range(1, N):
    a = f(a)
    if a == 0:
        break
    if a in map:
        break
    else:
        map[a] = i
    count += 1
    last_sub += a
    sub.append(last_sub)

if a == 0:
    print(sub[-1])
    exit()


def naive(a):
    total = a
    ary = [a]
    for i in range(1, N):
        a = f(a)
        ary.append(a)
    return ary
    
#n_ary = naive(X)
#print(n_ary)
#print(sum(n_ary))

j = map[a]

#print(sub)
#print(j)

unit = sub[-1] - sub[j]
#print(unit)

l = count
i = (N - j) % (l - j)
d = (N - j) // (l - j)

#i = N % l
#d = N // l

#print(len(sub), i, j)
print(unit * d + sub[i + j])

#print(sub[-1] * (d + 1) * d // 2 + sub[i])


Measured memory_bytes: 17396
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc  = new Scanner(System.in);
		int n = sc.nextInt();
		int []R = new int[n];
		
		for (int i = 0; i<n; i++) {
			R[i] = sc.nextInt();
		}
		
		int min = R[0];
		int ans = -Integer.MAX_VALUE;
		
		for (int i = 1; i < n; i++) {
			ans = Math.max(ans, R[i] - min);
			min = Math.min(min, R[i]);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 100440
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int N, K;
	cin >> N >> K;
	vector<int> vx, vy;
	int x[N], y[N];
	rep(i, 0, N) {
		cin >> x[i] >> y[i];
		vx.push_back(x[i]);
		vy.push_back(y[i]);
	}

	vsort(vx);
	vsort(vy);

	ll rsl = 1ll * abs(vx[N - 1] - vx[0]) * abs(vy[N - 1] - vy[0]);

	rep(xi, 0, N) rep(xj, xi + 1, N) {
		rep(yi, 0, N) rep(yj, yi + 1, N) {
			int count = 0;

			ll lx = vx[xi], rx = vx[xj];
			ll by = vy[yi], uy = vy[yj];

			rep(i, 0, N) {
				if(lx <= x[i] and x[i] <= rx and by <= y[i] and y[i] <= uy) count++;
			}

			if(count >= K) rsl = min(rsl, 1ll * abs(rx - lx) * abs(uy - by));
		}
	}

	cout << rsl << endl;


}


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

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

    int n, m;
    cin >> n >> m;
    int as, k;
    vector<int> cnt(m, 0);

    rep(i, 0, n)
    {
        cin >> k;
        rep(j, 0, k)
        {
            cin >> as;
            cnt[as - 1]++;
        }
    }
    int ans = 0;

    rep(i, 0, m)
    {
        // cout << cnt[i] << endl;/
        if (cnt[i] == n)
        {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=100;
int x;
int main()
{
	scanf("%d",&x);
	int a=x/500;x%=500;
	int b=x/5;
	long long ans=1000*a*1LL+5*b;
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  int A[N], B[N], C[N];
  rep(i,N){
    cin >> A[i] >> B[i] >> C[i];
  }

  int dp[N][3];
  dp[0][0] = A[0]; dp[0][1] = B[0]; dp[0][2] = C[0];
  for(int i=1;i<N;i++){
    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + A[i];
    dp[i][1] = max(dp[i-1][0], dp[i-1][2]) + B[i];
    dp[i][2] = max(dp[i-1][1], dp[i-1][0]) + C[i];
  }
  cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
const int MAXN=2e5+10;
int n;
ll k;
int a[MAXN];
int f[MAXN];
bool cmpl(int a,int b)
{
    return a<b;
}
bool cmpb(int a,int b)
{
    return a>b;
}
bool check(ll v)
{
    ll need=0;
    for(int u=1;u<=n;u++){
        ll w=(ll)a[u]*f[u];
        if(w>v){
            need+=a[u]-v/f[u];
        }
    }
    return need<=k;
}
int main()
{
    // freopen("in.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin>>n>>k;
    for(int u=1;u<=n;u++)cin>>a[u];
    for(int u=1;u<=n;u++)cin>>f[u];
    sort(a+1,a+1+n,cmpl);
    sort(f+1,f+1+n,cmpb);
    ll l=0,r=1e12,ans=-1;
    while(l<=r){
        ll mid=(l+r)>>1;
        if(check(mid)){
            r=mid-1;
            ans=mid;
        }
        else l=mid+1;
    }
    if(ans==-1){
        for(int u=1;u<=n;u++)ans=max(ans,(ll)a[u]*f[u]);
    }
    cout<<ans;
}

Measured memory_bytes: 1792
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

class AtCoder
{
    const int MOD = 1000000007;
    public void Slove()
    {
        var lst = new List<int>();
        var n = int.Parse(Console.ReadLine());
        foreach(int i in Enumerable.Range(0, n))
        {
            var num = int.Parse(Console.ReadLine());
            if(lst.Any())
            {
                int index = 0;
                for (int start = 0, end = lst.Count - 1; start <= end;)
                {
                    int mid = (start + end) / 2;

                    if (lst[mid] >= num)
                    {
                        end = mid - 1;
                    }
                    else
                    {
                        index = mid;
                        start = mid + 1;
                    }
                }
                if(lst[index] < num)
                    lst[index] = num;
                else
                    lst.Insert(0, num);
            }
            else
                lst.Add(num);
        }
        Console.WriteLine(lst.Count);
    }
    static void Main()
    {
        var ac = new AtCoder();
        ac.Slove();
    }
}

Measured memory_bytes: 18140
for i in range(4):
    t,n=map(int,input().split())
    if t==1:
        print(6000*n)
    elif t==2:
        print(4000*n)
    elif t==3:
        print(3000*n)
    elif t==4:
        print(2000*n)
    else:
        break


Measured memory_bytes: 5592
import sys
sys.setrecursionlimit(10**7)
N = int(input())

Graph = [[] for _ in range(N+1)]
dist  = [1000000000000]*(N+1)

for i in range(N-1):
	u,v,w = map(int,input().split())
	u-=1
	v-=1
	Graph[u].append((v,w))
	Graph[v].append((u,w))


def func(fromE,now,length):
	dist[now] = length
	for i in range(len(Graph[now])):
		target = Graph[now][i][0]
		lengt  = Graph[now][i][1]

		if target == fromE:
			continue

		func(now,target,dist[now]+lengt)

func(-1,0,0)

for i in range(N):
	if dist[i]%2 == 0:
		print(0)
	else:
		print(1)

Measured memory_bytes: 86500
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int MAXN = 5e2 + 5;

struct Node
{
	int x,y;
};

int s[MAXN],t[MAXN];
ull u[MAXN],v[MAXN];

ull ans[MAXN][MAXN];

int main(void)
{
	int n;
	scanf("%d",&n);
	for(int i=1; i<=n; ++i) scanf("%d",&s[i]);
	for(int i=1; i<=n; ++i) scanf("%d",&t[i]);
	for(int i=1; i<=n; ++i) scanf("%llu",&u[i]);
	for(int i=1; i<=n; ++i) scanf("%llu",&v[i]);
	
	try
	{
		for(int k=0; k<64; ++k)
		{
			static int p[MAXN],q[MAXN];
			for(int i=1; i<=n; ++i)
				p[i] = (u[i]>>k)&1,
				q[i] = (v[i]>>k)&1;
			
			static int a[MAXN][MAXN];
			static bool must[MAXN][MAXN];
			static bool delr[MAXN], delc[MAXN];
			static queue<Node> que;
			
			memset(must,0,sizeof(must));
			memset(delr,0,sizeof(delr));
			memset(delc,0,sizeof(delc));
			
			for(int i=1; i<=n; ++i)
			{
				if(s[i] == p[i]) continue;
				for(int j=1; j<=n; ++j)
				{
					if(must[i][j] && a[i][j]!=p[i]) throw 114514;
					a[i][j]=p[i]; must[i][j]=1;
					que.push((Node){i,j});
				}
				delr[i]=1;
			}
			for(int j=1; j<=n; ++j)
			{
				if(t[j] == q[j]) continue;
				for(int i=1; i<=n; ++i)
				{
					if(must[i][j] && a[i][j]!=q[j]) throw 114514;
					a[i][j]=q[j]; must[i][j]=1;
					que.push((Node){i,j});
				}
				delc[j]=1;
			}
			
			while(!que.empty())
			{
				int x=que.front().x, y=que.front().y;
				que.pop();
				
				if(!delr[x])
				{	
					if(!must[x][y])
					{
						a[x][y] = p[x];
						must[x][y]=1;
					}
					if(p[x] == a[x][y])
					{
						for(int j=1; j<=n; ++j)
							que.push((Node){x,j});
						delr[x]=1;
					}
				}
				if(!delc[y])
				{
					if(!must[x][y])
					{
						a[x][y] = q[y];
						must[x][y]=1;
					}
					if(q[y] == a[x][y])
					{
						for(int i=1; i<=n; ++i)
							que.push((Node){i,y});
						delc[y]=1;
					}
				}
			}
			
			int r=0,c=0;
			for(int i=1; i<=n; ++i)
				if(!delr[i]) ++r;
			for(int i=1; i<=n; ++i)
				if(!delc[i]) ++c;
			
			if(r==1)
			{
				for(int i=1; i<=n; ++i)
					for(int j=1; j<=n; ++j)
					{
						if(!must[i][j])
							a[i][j] = q[j];
					}
			}
			if(c==1)
			{
				for(int i=1; i<=n; ++i)
					for(int j=1; j<=n; ++j)
					{
						if(!must[i][j])
							a[i][j] = p[i];
					}
			}
			if(r>1 && c>1)
			{
				for(int i=1,tmp=0; i<=n; ++i) if(!delr[i])
				{
					for(int j=1,now=tmp; j<=n; ++j) if(!delc[j])
					{
						a[i][j] = now;
						now^=1;
					}
					tmp^=1;
				}
			}
			
			for(int i=1; i<=n; ++i)
			{
				int ann=1, orr=0;
				for(int j=1; j<=n; ++j)
					ann&=a[i][j], orr|=a[i][j];
				if(s[i]==0 && ann!=p[i]) throw 114514;
				if(s[i]==1 && orr!=p[i]) throw 114514;
			}
			for(int j=1; j<=n; ++j)
			{
				int ann=1, orr=0;
				for(int i=1; i<=n; ++i)
					ann&=a[i][j], orr|=a[i][j];
				if(t[j]==0 && ann!=q[j]) throw 114514;
				if(t[j]==1 && orr!=q[j]) throw 114514;
			}
			
			for(int i=1; i<=n; ++i)
				for(int j=1; j<=n; ++j)
					ans[i][j] |= ((ull)a[i][j]<<k);
		}
	}
	catch(...)
	{
		printf("-1");
		return 0;
	}
	
	for(int i=1; i<=n; ++i,putchar('\n'))
		for(int j=1; j<=n; ++j) printf("%llu ",ans[i][j]);
	return 0;
}

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

const int MOD = 1e9 + 7;
int N;
const int MAX_N = 2e5;
vector<vector<int> > G;
vector<int> K[MAX_N];

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}//modinv(i,mod)でi^-1のmodをとる。

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// 返り値で自分が根である部分木の要素数を返す
int dfs(int idx, int par){
    int sum = 1;
    for(int &to: G[idx]){
        if(to == par) continue;
        int tmp = dfs(to, idx);
        K[idx].push_back(tmp);
        sum += tmp;
    }
    if(par != -1){
        K[idx].push_back(N-1-(sum - 1));
    }
    return sum;
}

int main(){
    cin >> N;
    G.resize(N);
    rep(i, 0, N - 1){
        int a, b; cin >> a >> b; a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, -1);
    ll sum = 0;

    rep(i, 0, N){
        ll tmp = 1;
        for(auto j: K[i]){
            tmp += modpow(2, j, MOD) -1;
            tmp %= MOD;
        }
        sum += modpow(2, N- 1, MOD) - tmp;
        sum = ( sum + MOD ) % MOD;
    }
    cout << sum * modinv(modpow(2,N,MOD), MOD) % MOD << endl;
}

Measured memory_bytes: 35456
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;

    int smallest_c = 1e9;
    for (int route = 0; route < N; route++)
    {
        int c, t;
        cin >> c >> t;

        if (t <= T)
            smallest_c = min(smallest_c, c);
    }

    if (smallest_c >= 1e8)
        cout << "TLE";
    else
        cout << smallest_c;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main() {
  int n;
  char suits[52];
  int ranks[52];
  int i, j;
 
  int cards[4][14] = {{}};
 
  scanf("%d ", &n);
  for(i = 0; i < n; ++i) {
    scanf("%c %d ", &suits[i], &ranks[i]);
 
    if(suits[i] == 'S') {
      cards[0][ranks[i]] = 1;
    } else if(suits[i] == 'H') {
      cards[1][ranks[i]] = 1;
    } else if(suits[i] == 'C') {
      cards[2][ranks[i]] = 1;
    } else if(suits[i] == 'D') {
      cards[3][ranks[i]] = 1;
    }
  }
 
  for(i = 0; i < 4; ++i) {
    for(j = 1; j <= 13; ++j) {
      if(cards[i][j] == 0) {
    if(i == 0) printf("S ");
    else if(i == 1) printf("H ");
    else if(i == 2) printf("C ");
    else if(i == 3) printf("D ");
    printf("%d\n", j);
      }
    }
  }
 
  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  int64_t K, M = 1000;
  int64_t maxM = 0;
  for (int i = 0; i < N - 1; i++) {
    if (K == 0 && A.at(i) < A.at(i + 1)) {
      K = M / A.at(i);
      M -= (K * A.at(i));
    }
    else if (K != 0 && A.at(i) > A.at(i + 1)) {
      M += (K * A.at(i));
      K = 0;
    }
    if (K == 0) {
      maxM = max(M, maxM);
      M = maxM;
    }
  }
  M += K * A.at(N - 1);
  cout << M << endl;
}

Measured memory_bytes: 3632
import numpy as np
H,W,A,B=map(int,input().split())
P=np.concatenate([np.ones((H-B,W-A)),np.zeros((B,W-A))])
Q=np.concatenate([np.zeros((H-B,A)),np.ones((B,A))])
ans = np.concatenate([P,Q],1)
for j in ans:
    print(''.join(map(str,map(int,j))))

Measured memory_bytes: 29744
import queue
def main():
    n = int(input())
    g = [[] for _ in range(n)]
    for _ in range(n-1):
        a, b = map(int, input().split())
        g[a-1].append(b-1)
        g[b-1].append(a-1)
    c = list(map(int, input().split()))
    c.sort(reverse=True)
    ans = [None]*n
    a = [i for i in range(n)]
    a.sort(key=lambda x: len(g[x]), reverse=True)
    f = [True]*n
    f[a[0]] = False
    q = queue.Queue()
    q.put(a[0])
    ans[a[0]] = c[0]
    x = 1
    while not q.empty():
        target = q.get()
        for v in g[target]:
            if f[v]:
                f[v] = False
                ans[v] = c[x]
                q.put(v)
                x += 1
    score = 0
    f = [True]*n
    f[0] = False
    q = queue.Queue()
    q.put(0)
    while not q.empty():
        target = q.get()
        for v in g[target]:
            if f[v]:
                f[v] = False
                score += min(ans[target], ans[v])
                q.put(v)
    print(score)
    for i in range(n):
        print(ans[i], end="")
        if i < n-1:
            print(" ",end="")
        else:
            print("")

if __name__ == "__main__":
    main()


Measured memory_bytes: 7340
import std.stdio, std.array, std.conv, std.string;

void main() {
  string[] input = split(readln());
  int a = to!int(input[0]);
  int b = to!int(input[1]);

  writef("%d %d %.10f\n", a / b, a % b, cast(double)a / cast(double)b);
}

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c,k;cin>>a>>b>>c>>k;ll sum=0;
  if(a>=k)  cout<<k<<endl;
  else if(a+b>=k)cout<<a<<endl;
   else if(a+b+c>=k)
   {
     cout<<(b-k)+2*a<<endl;
   }
}


Measured memory_bytes: 3636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""050-b"""

import sys
import pprint
import re

import itertools
pp = pprint.PrettyPrinter(indent=2)

def main():
    """Main function."""
    N = int(input())
    Ts = list(map(int, input().split(' ')))
    M = int(input())
    sum_ = sum(Ts)
    for _ in range(M):
        p, x = list(map(int, input().split(' ')))
        print(sum_ - Ts[p-1] + x)

if __name__ == '__main__':
    sys.exit(main())

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

ll N, ans=0;
void dfs(ll num, int thr, int fiv, int sev){
  if(num>N)return;
  if(thr&&fiv&&sev)ans++;
  
  dfs(10*num+3, 1, fiv, sev);
  dfs(10*num+5, thr, 1, sev);
  dfs(10*num+7, thr, fiv, 1);
}

int main(){
  cin>>N;
  
  dfs(3, 1, 0, 0);
  dfs(5, 0, 1, 0);
  dfs(7, 0, 0, 1);
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class T
{
    static void Main()
    {
        string[] l = Console.ReadLine().Split(' ');
        int N = int.Parse(l[0]);
        int A = int.Parse(l[1]);
        int B = int.Parse(l[2]);
        Console.WriteLine((N * A) > B ? B : N * A);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;

//深さ優先
vector<int> seen;
vector<ll> h;

//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み

    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }

    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}

int main(){
    /*
    int n,m;
    cin>>n>>m;

    h.assign(n,0);
    rep(i,0,n) cin>>h[i];

    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    seen.assign(n,-1);

    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }

    int sum=accumulate(all(seen),0);

    cout<<sum<<endl;*/

    ll n; cin>>n;

    map<ll,ll> L,R;
    ll A[n];

    rep(i,0,n){
        ll a; cin>>a;
        A[i]=a;
        L[i+a]++;
        R[i-a]++;
    }

    ll ans=0;
    for(ll i=0;i<n;i++){
        ll l=A[i]+i;
        R[i-A[i]]--;
        ans+=R[l];
    }

    cout<<ans<<endl;


}

Measured memory_bytes: 39304
def main
  n,t = gets.chomp.split.map(&:to_i)
  poly = []
  poly = gets.chomp.split('+')
  sum = 0
  poly.each do |mono|
    num = mono.split('^')[1].to_i
    sum += n ** num
  end
  total_time = sum * t
  if total_time > 1_000_000_000
    puts 'TLE'
  else
    puts total_time
  end
end

main

Measured memory_bytes: 6124
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: u64,
    }
    if n % 2 == 1 {
        println!("{}", 0);
        return;
    }
    let max_n: u64 = 1_000_000_000_000_000_000;
    let mut i: u64 = 2 * 5;
    let mut ans: u64 = 0;
    while i <= max_n {
        ans += n / i;
        i *= 5;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
int d[3][101],a[3][101];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            cin >> a[i][j];
    for(int i=1;i<=2;i++)
        for(int j=1;j<=n;j++)
            d[i][j] = max(d[i-1][j],d[i][j-1])+a[i][j];
    cout << d[2][n] << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstdio>

using namespace std;

#define int long long

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

    string in;

    cin >> in;

    vector<int> v(26, 0);

    for (auto x : in)
    {
        const auto i = x - 'a';
        v[i]++;

        if (v[i] > 1)
        {
            cout << "no" << endl;
            return 0;
        }
    }
    cout << "yes" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

// ユークリッドの互除法
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(){
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  
  ll LCM = lcm(c,d);
  ll diff=b-a, ans=0;
  
  ll ac=a%c, ad=a%d, alcm=a%LCM;
  if(ac==0) ac = c;
  if(ad==0) ad = d;
  if(alcm==0) alcm = LCM;
  ans += (ac + diff)/c;
  ans += (ad + diff)/d;
  ans -= (alcm + diff)/LCM;
  ans = diff - ans + 1;
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{

    long long a, b, c, d, e, max, min, sum, i;

    scanf("%lld %lld", &a, &b);
    
    d = e = b;

    for(i = 1; i < a; i++){
	scanf("%lld", &c);
	if(c > b) b = c;
        if(c < d) d =c;
        e += c;
	}
    max = b;
    min = d;
    sum = e;

    printf("%d %d %lld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 1976
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    if n == 2 {
        println!("{}", max(a[0], a[1]));
        return;
    }

    let mut g = a[0];
    for i in 1..n {
        g = gcd(g, a[i]);
    }
    
    let mut divs = a.iter().map(|&v| v / g).collect_vec();
    divs.sort();

    let mut g2 = divs[0];
    let mut skipped = false;
    for i in 0..n {
        let gtemp = gcd(g2, divs[i]);
        if gtemp == 1 {
            if skipped {
                g2 = 1;
                break;
            } else {
                skipped = true;
            }
        } else {
            g2 = gtemp;
        }
    }

    let mut g3 = divs[n-1];
    let mut skipped = false;
    for i in (0..n).rev() {
        let gtemp = gcd(g3, divs[i]);
        if gtemp == 1 {
            if skipped {
                g3 = 1;
                break;
            } else {
                skipped = true;
            }
        } else {
            g3 = gtemp;
        }
    }
    let ans = g * max(g2, g3);
    println!("{}", ans);
}

#[allow(dead_code)]
pub fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

Measured memory_bytes: 4900
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception{
		new Main(new Scanner(System.in), System.out, System.err).exec();
	}
	private final Scanner sc;
	private final PrintStream out, err;
	public Main(final Scanner sc, final PrintStream out, final PrintStream err) {
		this.sc = sc;
		this.out = out;
		this.err = err;
	}

	public void exec() throws Exception{
		final int A = sc.nextInt();
		final int B = sc.nextInt();
		final int diff = A - B*2;
		if(diff < 0	) {
			out.println(0);
		}else {
			out.println(diff);
		}
	}
}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstdlib>
#define INF 100000000
#define _INF -100000000
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

string s;
vector<ll> digits;

ll dfs(ll focus, ll keep) {
	if (focus == s.length()) return 0;
	else return (keep * 10 + digits[focus]) * max((ll)1, (ll)pow(2, s.length() - focus - 2)) + dfs(focus + 1, 0)
		+ dfs(focus + 1, keep * 10 + digits[focus]);
}

void solve() {
	Loop(i, s.length()) {
		digits.push_back(s[i] - '0');
	}
	cout << dfs(0, 0) << endl;
}

int main() {
	cin >> s;
	solve();
	return 0;
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    string s;
    cin >> n >> s;
    set<ll> r;
    set<ll> g;
    set<ll> b;
    for(i = 0;i < n;++i){
        if(s.at(i) == 'R'){
            r.insert(i);
        }else if(s.at(i) == 'G'){
            g.insert(i);
        }else if(s.at(i) == 'B'){
            b.insert(i);
        }
    }
    ll ans = 0;
    for(auto x:r){
        for(auto y:g){
            ll mi = min(x,y);
            ll ma = max(x,y);
            ll tmp1 = mi - (ma-mi);
            ll tmp2 = ma + (ma-mi);
            ll tmp3 = -1;
            if((tmp2-tmp1)%2 == 0){
                tmp3 = (tmp2 + tmp1)/2;
            }
            ans += b.size();
            if(b.count(tmp1)) --ans;
            if(b.count(tmp2)) --ans;
            if(b.count(tmp3)) --ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3756