akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
int n,a,d,t[1000003],maxa=-(1<<30);
//maxa保存a的最大值，也是因子的最大值，t[i]表示因子i有多少个，d为n个数的最大公因数
int gcd(int x,int y){
    if(!y) return x;
    return gcd(y,x%y);
}
void fj(int x){//分解质因数
    for(int i=2;i*i<=x;){
        if(!(x%i)){
            ++t[i];//用桶记下来
            while(!(x%i)) x/=i;
        }
        else ++i;
    }
    if(x>1) ++t[x];//不要忘了这一句
}
int main(){
    scanf("%d%d",&n,&a);
    d=a;//d初始值为a
    for(int i=2;i<=n;i++){
        scanf("%d",&a);
        if(maxa<a) maxa=a;//更新maxa
        d=gcd(d,a);//求n个数的公因数可以这么做
        fj(a);//对a分解质因数
    }
    if(d==1){
        for(int i=2;i<=maxa;i++)
            if(t[i]>1) return puts("setwise coprime"),0;
            //t[i]>1说明有几个数有相同的因子，则肯定有一对数不互质
        return puts("pairwise coprime"),0;
    }
    else return puts("not coprime"),0;
    return 0;
}


Measured memory_bytes: 5520
#include <stdio.h>
 
int main () {
int i,j;
char n[100000] = {0};
int  x[1001] = {0};
 
i = 0;
j = 0;
 
 
while(1) {
scanf("%c",&n[i]);
if(n[i] == '0' && n[i-1] == '\n'|| n[0] == '0') {break;}
 
if(n[i] >= '1' && '9' >= n[i] && n[i] != '\n') {
x[j] += n[i]-48;
}
  if(n[i] == '\n') {
j = j + 1;
}
 
i= i+1;
 
}
 
for(i=0; i < j;i++) {
printf("%d",x[i]);
printf("\n"); 
 
} 
 
return 0;
 
}



Measured memory_bytes: 2060
import java.util.Scanner;
import java.util.TreeSet;

public class Main {

    public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int n = cin.nextInt();

        TreeSet<Integer> allPrimes = primes(55555);
        String[] result = new String[n];
        for (int i = 0; i < n; i++) {
            int x;
            do {
                x = allPrimes.pollFirst();
            } while (x % 5 != 1);
            result[i] = Integer.toString(x);
        }
        System.out.println(String.join(" ", result));
    }

    static TreeSet<Integer> primes(int max) {
        TreeSet<Integer> result = new TreeSet<>();
        TreeSet<Integer> seeds = new TreeSet<>();
        int limit = (int)Math.sqrt((double)max);
        result.add(2);
        for (int i = 3; i <= max; i+=2) {
            seeds.add(i);
        }
        while (seeds.size() > 0 && seeds.first() <= limit) {
            int seed = seeds.pollFirst();
            result.add(seed);
            for (int x = seed + seed; x <= max; x+=seed) {
                seeds.remove(x);
            }
        }
        if (seeds.size() > 0) {
            result.addAll(seeds);
        }
        return result;
    }
}


Measured memory_bytes: 27988
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var N = Number(tmp[0]);
	var A = Number(tmp[1]);
	var B = Number(tmp[2]);
	var ans = A*N <= B ? A*N : B;
	console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;
const string YES = "Yes";
const string NO = "No";

ll N;
vl A;
vl B;

void solve();

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> N;
    A = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> A[i];
    }
    B = vl(N);
    for(int i = 0; i < N; ++i){
        cin >> B[i];
    }
    solve();
}

// 2 ≦ N ≦ 10^5
// 1 ≦ A_i,B_i ≦ 10^9

// ll N, vl A, vl B
// 可能な場合は Yes を、不可能な場合は No を出力せよ。
void solve(){
    vp a,b;
    rep(i,N){
        a.emplace_back(A[i],i);
        b.emplace_back(B[i],i);
    }
    sort(all(a));
    sort(all(b));

    rep(i,N){
        if(a[i].first>b[i].first){
            cout<<NO<<endl;
            return;
        }
    }

    vl mp(N);
    rep(i,N)mp[a[i].second]=i;
    ll idx=mp[0];
    set<ll> st;
    rep(i,N){
        st.insert(mp[idx]);
        idx=b[mp[idx]].second;
    }
    if(st.size()<N){
        cout<<YES<<endl;
        return;
    }

    rep(i,N-1){
        if(b[i].first>=a[i+1].first){
            cout<<YES<<endl;
            return;
        }
    }
    cout<<NO<<endl;
}


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

int main() {
	int n, a[100];
	while(1){
		cin >> n;
		if(n==0) break;
		int min, max, sum, avg;
		for(int i=0; i<n; i++)
			cin >> a[i];
			min = max = sum = a[0];
		for(int j=1; j<n; j++){
			sum += a[j];
			if(min>a[j]) min = a[j];
			if(max<a[j]) max = a[j];
		}
		avg = (sum-max-min)/(n-2);
		cout << avg << endl;
	}
	return 0;
}


Measured memory_bytes: 3008
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}


int main()
{
	int A=0,B=0,C=0,D=0;
	
	scanf("%d %d %d %d", &A,&B,&C,&D);
	
	
	while(A>0&&C>0){
		
		C-=B;
		if(C<=0){break;}
		
		A-=D;
		
	}
	
	if(A<=0){
		printf("No");
	}
	else{
		printf("Yes");
	}
	

	return 0;
}


Measured memory_bytes: 1708
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/3/ALDS1_3_B


from queue import Queue


def solve():
    q = Queue()
    n, time = map(int, input().split())
    for _ in range(n):
        row = list(map(str, input().split()))
        q.put([row[0], int(row[1])])

    elapsed = 0
    while len(q.queue) > 0:
        elem = q.get()

        if elem[1] <= time:
            elapsed += elem[1]
            print(elem[0], elapsed)
        else:
            elapsed += time
            elem[1] -= time
            q.put([elem[0], elem[1]])


if __name__ == '__main__':
    solve()



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

int main() {
    int n;
    cin >> n;
    double sum = 0;
    rep(i, n) {
        double a;
        cin >> a;
        sum += 1 / a;
    }
    printf("%12f", 1 / sum);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = 53;
const int oo = int(1e9) + 7;

int a[N], b[N], n, vis[N];
vector<int> g[N];
queue<int> q;
ll res = 0;

bool BFS(int s, int t) {
    fill(vis, vis + N, 0);
    while(q.size()) q.pop();
    vis[s] = 1, q.push(s);
    while(q.size()) {
        s = q.front(); q.pop();
        if(s == t) return 1;
        for(int v: g[s]) if(!vis[v]) vis[v] = 1, q.push(v);
    }
    return 0;
}

bool Need(int k) {
    for(int i = 0; i <= 50; ++i) g[i].clear();
    for(int i = 50; i >= 1; --i) {
        if((res >> i & 1) || i < k)
            for(int j = i; j <= 50; ++j) g[j].pb(j % i);
    }
    for(int i = 1; i <= n; ++i) if(!BFS(a[i], b[i])) return 1;
    return 0;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) cin >> b[i];
    if(Need(51)) return cout << -1, 0;
    for(int i = 50; i >= 1; --i) if(Need(i)) res += (1ll << i);
    cout << res;
}


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

#define rep(i, x, n) for (int i = x; i < n; i++)
typedef long long ll;

const int INF = 1e9 + 7;

using namespace std;

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

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

    vector<int> tmp = p;
    sort(tmp.begin(), tmp.end());

    int count = 0;

    rep (i, 0, n) {
	if (tmp[i] != p[i])
	    count++;
	if (count > 2) {
	    cout << "NO" << endl;
	    return 0;
	}
    }

    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time
sys.setrecursionlimit(10**7)
inf = 10**20

N = input()
a = list(map(int,input().split()))
answer = inf
for goal in range(-100,101):
    squaredSum = sum(map(lambda x: (x-goal)**2, a))
    answer = min(answer, squaredSum)
print(answer)

Measured memory_bytes: 5424
n=int(input())
MOD=10**9+7
c=list(map(int,input().split()))
c.sort(reverse=True)
x=1
for i in range(n-1):
    x=(x*2)%MOD
x=(x*x)%MOD

ans=0
for i in range(n):
    tmp=(c[i]*(i+2))%MOD
    ans+=(tmp*x)%MOD
    ans%=MOD
print(ans)

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    int n;
    cin >> n;
    map<string,int> list;
    REP(i,n){
        string t;
        cin >> t;
        sort(t.begin(),t.end());
        list[t]++;
    }
    ll count = 0;
    for(const auto& i:list){
        ll num = i.second;
        count += ((num-1)*num)/2;
    }
    COUT(count);
    return 0;
}  

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

int main(void)
{
	ios_base::sync_with_stdio(0);
	long long r, d, x;
	cin >> r >> d >> x;
	for(int i = 0; i < 10; i++) {
                x = x * r - d;
                cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <math.h>
using namespace std;

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


int N, K;
vector<int> d;
bool check(int n){
	while (n > 0){
		if (find(d.begin(), d.end(), n % 10) != d.end()) return false;
		n /= 10;
	}
	return true;
}

int main(){

	cin >> N >> K;
	for (int i = 0; i < K; i++){
		int tmp;
		cin >> tmp;
		d.push_back(tmp);
	}

	for (int n = N;; n++){
		if (check(n)){
			cout << n << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(a,b,n) for(int a=b;a<=b;a++)
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("d",&a,&b)
#define sccc(a,b,c) scanf("d%d",&a,&b,&c)
#define sccs(s) scanf("%s",s)
#define pccs(s) printf("%s",s)
#define debug printf("---debug---");
#define pcc(a,b) printf("d",a,b)
#define pccc(a,b,c) printf("d%d",a,b,c)
#define pb push_back
typedef long long ll;
const int MAXN_1e5=1e5+5;
const int MAXN_2e5=2e5+5;
const int MAXN_3e5=3e5+5;
const int MAXN_4e5=4e5+5;
const int MAXN_5e5=5e5+5;
const int INF_INT=0x3f3f3f3f;
const long long INT_LL=2e18;
ll arr[MAXN_1e5];
int main()
{
    ll n,m;
    cin>>n>>m;
    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin>>a;
        if(a>=m)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}


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

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    char t='o';
    for (int i = 0; i < s.size(); ++i) {
        if(t=='x'&&s[i]=='x'){cout<<i<<endl;return 0; }
        else t=s[i];
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 3336
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007

const ll mod = 998244353;

ll power(ll a, ll b) { //a^b
	ll res = 1;
	a = a % MOD;
	while (b > 0) {
		if (b & 1) {res = (res * a) % MOD; b--;}
		a = (a * a) % MOD;
		b >>= 1;
	}
	return res;
}

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

int main() {
#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n, k;
	cin >> n >> k;
	vector <pair<ll, ll> >v(k);
	for (ll i = 0; i < k; i++)
		cin >> v[i].ff >> v[i].ss;
	vl dp(n + 1, 0);
	dp[1] = 1;
	for (ll i = 2; i <= n; i++) {
		for (ll j = 0; j < k; j++) {
			ll l = v[j].ff;
			ll r = v[j].ss;
			if (l >= i)
				continue;
			r = min(r, i - 1);
			ll rr = i - l;
			ll lli = i - r;
			dp[i] = (dp[i] + dp[rr] - dp[lli - 1] + mod) % mod;
		}
		if (i == n) {
			cout << dp[i] << "\n";
			return 0;
		}
		dp[i] = (dp[i] + dp[i - 1]) % mod;
	}
}


Measured memory_bytes: 4776
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    set<int> s;
    for(ll i=0;i<3;++i){
        ll x;
        cin>>x;
        s.insert(x);
    }
    if(s.size()==2){cout<<"Yes";}
    else{cout<<"No";}

    return (0);
}


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

int main(void) {
    int N, M;
    cin >> N >> M;

    int cnt = 0;
    for (int i = 0; i < M; i++) {
        int A;
        cin >> A;
        cnt += A;
    }

    if ((N - cnt) < 0) {
        cout << -1 << endl;
    } else {
        printf("%d\n", (N - cnt));
    }
    return 0;
}

Measured memory_bytes: 3760
S = input()
N = len(S)

T = [None]*N
X = []
for i in range(N):
    if S[i]=='R':
        X.append(i)
    else:
        for x in X:
            T[x] = i
        X = []

X = []
for i in range(N-1,-1,-1):
    if S[i]=='L':
        X.append(i)
    else:
        for x in X:
            T[x] = i
        X = []
      	
Z = [0]*N
for i in range(N):
    if (T[i]-i)%2==0:
      	g = T[i]
    elif S[i]=='R':
        g = T[i]-1
    else:
        g = T[i]+1
    Z[g]+=1

print(*Z)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
typedef long long ll;

int main() {
    int h,w; cin >> h >> w;
    
    char b[h+2][w+2];
    rep(i,h+2){
        rep(j,w+2){
            b[i][j] = '#';
        }
    }
    char a[h][w];
    rep(i,h){
         rep(j,w){
            cin >> a[i][j];
            b[i+1][j+1] = a[i][j];
        }
    }

    rep(i,h+2){
        rep(j,w+2){
            cout << b[i][j];
        }
        cout << endl;
    }
    
}

Measured memory_bytes: 256
N, A, B, C, D = map(int, input().split())
S = input()
flag = 0
for i in range(A, max(C, D)):
    if S[i-1] == "#" and S[i] == '#' and flag == 0:
        print("No")
        flag = 1
    #print(S[i-1], S[i])

if flag == 0:

    if A > B:
        ab = 1
    else:
        ab = 0
    if C > D:
        cd = 1
    else:
        cd = 0

    if ab != cd:
        for i in range(B - 1, min(C, D)):
            if S[i-1] == "." and S[i+1] == "." and S[i] == "." and flag == 0:
                print("Yes")
                flag = 1
            #print(S[i-1],S[i] , S[i+1])
        if flag == 0:
            print("No")

    else:
        print("Yes")

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		String w = scanner.next();
		
		int cnt = 0;
		for(;;)
		{
			String t = scanner.next();
			if(t.equals("END_OF_TEXT"))
			{
				break;
			}
			else if(w.compareToIgnoreCase(t) == 0)
			{
				cnt++;
			}
		}
		
		System.out.println(cnt+"");
	}
}

Measured memory_bytes: 26112
k, n = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

r = []

for i in range(n-1):
    r.append(a[i+1] - a[i])
r.append(k - a[n-1] + a[0])

ind = r.index(max(r))

if ind == n-1:
    print(a[n-1] - a[0])
else:
    print(k - a[ind+1] + a[ind])


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

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;

	int a = 100000;

	for( int i = 0; i < n; ++i ) {
		a += (a * 5 / 100 + 999) / 1000 * 1000;
	}

	cout << a << endl;
}



Measured memory_bytes: 3024
n, k, q = map(int, input().split())
a = [input() for i in range(q)]
point = []
ans = []

for z in range(n):
  point.append(0)

for j in range(q):
  point[int(a[j])-1] += 1
  
for x in range(n):
  if point[x] > q-k:
    ans.append('Yes')
  else:
    ans.append('No')
  print(ans[x])

Measured memory_bytes: 11840
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
#include<boost/operators.hpp>
#include<boost/dynamic_bitset.hpp>

namespace adaptor = boost::adaptors;
using index_t = std::size_t;

void Main()
{
	int K, X;
	std::cin >> K >> X;
	for (int i = X - K + 1; i < X + K; ++i)
	{
		std::cout << i << " ";
	}
	std::cout << std::endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<string>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 100005

int n;
pair<int,int> v[NMAX];
long long cost;

int main (){
    
    scanf("%d",&n);
    for(int i = 1; i <= n; i++){
        scanf("%d%d",&v[i].x,&v[i].y);
    }
    for(int i = n; i >= 1; i--){
        int rest = ((long long)v[i].x + cost) % v[i].y;
        if(rest){
            cost += v[i].y - rest;
        }
    }
    
    printf("%lld\n", cost);
    
    return 0;
}

Measured memory_bytes: 1024
def main():
  M = list(map(str,input().split()))[0]
  N = int(M[-1])
  if N == 3:
    ans = "bon"
  elif N == 0 or N == 1 or N == 6 or N == 8:
    ans = "pon"
  else:
    ans = "hon"

  return ans
if __name__ == '__main__':
  print(main())

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;	
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

const ll INF = 1LL << 61;

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

const ll mod = 1000000007;

vector<vector<ll>> g;
vector<ll> dp;
ll n;
vector<ll> as;
vector<ll> ans;

void dfs(int index, int from) {
	auto low = lower_bound(dp.begin(), dp.end(), as[index]);
	auto prev = *low;
	*low = as[index];
	ll length = lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
	ans[index] = length;
	for (auto p : g[index]) {
		if (p == from) continue;
		dfs(p, index);
	}
	*low = prev;
}


int main() {
	cin >> n;
	as.resize(n);
	ans.resize(n);
	dp.resize(n + 1, INF);
	rep(i, n) {
		cin >> as[i];
	}
	g.resize(n);
	rep(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(0, -1);
	for (auto p : ans) {
		cout << p << endl;
	}
	return 0;
}

Measured memory_bytes: 30300
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

int main(){
  int n,k;
  int ans=0;
  cin >> n >> k;
  vector<int> h(n);
  for(int i=0;i<n;i++)cin >> h[i];

  for(int i=0;i<n;i++){
    if(h[i] >= k)ans++;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 640
x,y = gets.chomp.split.map(&:to_i)

if y.odd?
  puts 'No'
  exit
end

k = (y.to_f)/2 - x

if k < 0
  puts 'No'
  exit
end

t = x-k

if t < 0
  puts 'No'
  exit
end

puts 'Yes'


Measured memory_bytes: 14388
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

vector<string> dfs(string s, ll depth, vector<char> symbol)
{
    vector<string> ret;
    if (depth == 0)
    {
        ret.push_back(s);
        return ret;
    }

    for (ll i = 0; i < symbol.size(); i++)
    {
        auto vec = dfs(s + symbol[i], depth - 1, symbol);
        for (auto &&e : vec)
        {
            ret.push_back(e);
        }
    }
    return ret;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return b;
    }
    return gcd(b, a % b);
}

enum Tenki
{
    Sunny,
    Cloudy,
    Rainy
};

int main()
{
    string N;
    cin >> N;
    cout << "ABC" + N << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    int train = n * a, taxi = b;
    int ans = min(train, taxi);
    cout << ans << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
#define track(); cout<<"#############"<<endl;
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

typedef struct node{
  struct node *l=NULL;
  struct node *r=NULL;
  int key=0;
  int pri=0;
}Node;

Node* RightRotate(Node *t){
  Node *s=t->l;
  t->l=s->r;
  s->r=t;
  return s;
}

Node* LeftRotate(Node *t){
  Node *s=t->r;
  t->r=s->l;
  s->l=t;
  return s;
}

Node* ins(Node* t,int key,int pri){
  if(t==NULL){
    t=(Node*)malloc(sizeof(Node));
    t->l=NULL;
    t->r=NULL;
    t->key=key;
    t->pri=pri;
    return t;
  }
  if(key==t->key)return t;
  if(key<t->key){
    t->l = ins(t->l,key,pri);
    if(t->pri < t->l->pri)t=RightRotate(t);
  }
  else {
    t->r = ins(t->r,key,pri);
    if(t->pri < t->r->pri)t=LeftRotate(t);
  }
  return t;
}

bool find(Node *t,int key){
  if(t==NULL)return false;
  if(t->key==key)return true;
  if(key<t->key)return find(t->l,key);
  return find(t->r,key);
}

Node* del(Node *t,int key){
  if(t==NULL)return NULL;
  if(key==t->key){
    if(t->l==NULL && t->r==NULL){
      return NULL;
    }
    else if(t->l==NULL){
      t=LeftRotate(t);
    }
    else if(t->r==NULL){
      t=RightRotate(t);
    }
    else {
      if(t->l->pri >t->r->pri)
        t=RightRotate(t);
      else 
        t=LeftRotate(t);
    }
    return del(t,key);
  }

  if(key<t->key)
    t->l = del(t->l,key);
  else 
    t->r = del(t->r,key);
  return t;
}

void inorder(node *t){
  if(t->l != NULL)inorder(t->l);
//  cout<<" "<<t->key;
  printf(" %d",t->key);
  if(t->r != NULL)inorder(t->r);
}

void preorder(node *t){
  printf(" %d",t->key);
  //cout<<" "<<t->key;
  if(t->l != NULL)preorder(t->l);
  if(t->r != NULL)preorder(t->r);
}

int main()
{
  int n,a,b;
  string s;
  Node *t=NULL;
  cin>>n;
  FOR(i,0,n){
    cin>>s;
    if(s=="insert"){
      cin>>a>>b;
      t=ins(t,a,b);
    }
    else if(s=="find"){
      cin>>a;
      if(find(t,a))cout<<"yes"<<endl;
      else cout<<"no"<<endl;
    }
    else if(s=="delete"){
      cin>>a;
      t=del(t,a);
    }
    else {
      inorder(t);
      cout<<endl;
      preorder(t);
      cout<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 9496
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){

    int n, r = 1, place = 1;
    bool fl = false;
    LL int k, p;
    vector<int> a;
    vector<int> v;

    cin >> n >> k;
    FOR(i,0,n){
        cin >> p;
        a.push_back(p);
        v.push_back(0);
    }

    LL int j;
    for(j = 0; j < k; j++){
        place = a[place - 1];
        if(v[place] == 0 && !fl){
            v[place] = r;
            r++;
        } else if(!fl){
            fl = true;
            LL int rp = (LL int)(r - v[place]);
            k %= rp;
            // k -= v[place];
            while(k <= j){
                k += rp;
            }
        }
    }

    cout << place << endl;

    return 0;
}


Measured memory_bytes: 5108
A,B,C=map(int,input().split())

#A*N=B*p+C
#N=(B*p +C)/A
condition=0

for i in range(1000):
  if (B*i +C)%A==0:
    print('YES')
    condition=1
    break
 
if condition==0:
  print('NO')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(),x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define sz(x) (int)x.size()
#define re return


template<typename T> T sgn (T x)      {re x<0? -1:(x>0? 1:0); }
template<typename T> T gcd (T a, T b) {re a ? gcd (b % a, a) : b; }
template<typename T> T abs (T x)      {re x < 0 ? -x : x; }
template<typename T> T sqr (T x)      {re x*x;}

#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define ins insert
#define y second
#define x first
#define endl "\n"
#define MOD (int)1e9+7
#define N (int)2e5+123

string str;
void solve(){
	cin >> str;
	if(str == "ABC"){
		cout << "ARC" << endl;
	}else{
		cout << "ABC" << endl;
	}

}
int main(){_
    solve();
}

Measured memory_bytes: 3492
n = int(input())
t=[0]
x=[0]
y=[0]
z = 1
for j in range(n):
    [a,b,c] = [int(i) for i in input().split()]
    t.append(a)
    x.append(b)
    y.append(c)

for i in range(1,len(t)):
    tmp = abs(x[i] - x[i - 1])+abs(y[i] - y[i - 1])
    if (tmp <= (t[i] - t[i - 1])) and ((t[i] - t[i - 1] + tmp) % 2 == 0):
        z = z
    else:
        z = 0

if z == 1:
    print("Yes")
else:
    print("No")


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

int main() {
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int tmp=0;
  int world=1;
  vector<bool> yn(n,0);
  rep(i,n){
    if(s[i]=='a'){
      yn[i]=1;
      tmp++;
    }else if(s[i]=='b' && world<=b){
      yn[i]=1;
      tmp++;
      world++;
    }
    if(tmp==(a+b)){
      break;
    }
  }
  rep(i,n){
    if(yn[i]){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 896
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main(void)
{
  int N, index;
  char S[101], T[101];
  scanf("%d", &N);
  scanf("%s %s", &S, &T);

  for (index = 0; index < N; ++index)
  {
    printf("%c%c", S[index], T[index]);
  }
  printf("\n");
  
return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<string> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    bool yellow = false;
    rep(i,N){
        if (vec[i] == "Y"){
            yellow = true;
        }
    }
    if (yellow){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }
}



Measured memory_bytes: 256
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout<< lcs; 
} 

/* Driver program to test above function */
int main() 
{ 

string X,Y;
cin>>X>>Y;


lcs(X, Y, X.size(), Y.size()); 
return 0; 
} 


Measured memory_bytes: 35456
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;


void main() {
    int r, g;
    scan(r);
    scan(g);

    writeln(2*g - r);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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 <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int a[210000];
int b[210000];

int main()
{
  int i,j,k,cnt,n,tot,ans,tmp;
  vector<pair<int,int> > aa;
  vector<pair<int,int> > bb;
  scanf("%d",&n);
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  for (i=0;i<n;i++)
    scanf("%d",&b[i]);
  ans=0;
  for (i=0;i<30;i++)
  {
    tmp=0;
    aa.clear();
    tot=0;
    for (j=0;j<n;j++)
    {
      aa.push_back(make_pair(a[j]&((1<<i)-1),((a[j]>>i)&1)));
      if (((a[j]>>i)&1)==1)
        tot++;
    }
    sort(aa.begin(),aa.end());
    bb.clear();
    for (j=0;j<n;j++)
      bb.push_back(make_pair(b[j]&((1<<i)-1),((b[j]>>i)&1)));
    sort(bb.begin(),bb.end());
    reverse(bb.begin(),bb.end());
    cnt=0;
    k=0;
    for (j=0;j<bb.size();j++)
    {
      while ((k<aa.size())&&(aa[k].first+bb[j].first<(1<<i)))
      {
        if (aa[k].second==1) cnt++;
        k++;
      }
      //cout<<"tot: "<<tot<<" j: "<<j<<" k: "<<k<<" cnt: "<<cnt<<endl;
      if (bb[j].second==0)
      {
        tmp+=cnt;
        tmp+=(n-k)-(tot-cnt);
      }
      else
      {
        tmp+=k-cnt;
        tmp+=tot-cnt;
      }
      tmp%=2;
    }
    if (tmp==1) ans|=(1<<i);
  }
  printf("%d\n",ans);
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	for (int i = 0; i < n; i++)cin >> a.at(i);
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		if (a.at(i) >= 2) {
			ans += a.at(i) / 2;
			a.at(i) %= 2;
		}
		if (i!=n-1&&a.at(i) == 1 && a.at(i + 1) >= 1) {
			ans++;
			a.at(i) = 0;
			a.at(i + 1)--;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include<stdio.h>


main()
{

  int x,y,d;

  scanf("%d%d",&x,&y);
  while((d = x%y) !=0)
    {  

	  x = y; 
	  y = d;  
	}
	 
    
     	 printf("%d\n",y);
	
  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
    int x1, x2, y1, y2;
    cin>>x1>>y1>>x2>>y2;
    int ans = 0;

    cout<<x2 + y1 - y2<<" "<<y2 + x2 - x1<<" "<<x1 + y1 - y2<<" "<<y1 + x2 - x1<<endl;

    return 0;
}


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

class dice {
public:
	int getTopFace(void);
	void rotate(char dir);
	void setFaceNumber(int *number);
private:
	int face[6];
};

int dice::getTopFace(void) {
	return face[0];
}

void dice::rotate(char dir) {
	int temp;
	switch(dir) {
	case 'N' :
		temp=face[0];
		face[0]=face[1];
		face[1]=face[5];
		face[5]=face[4];
		face[4]=temp;
		break;
	case 'S' :
		temp=face[0];
		face[0]=face[4];
		face[4]=face[5];
		face[5]=face[1];
		face[1]=temp;
		break;
	case 'W' :
		temp=face[0];
		face[0]=face[2];
		face[2]=face[5];
		face[5]=face[3];
		face[3]=temp;
		break;
	case 'E' :
		temp=face[0];
		face[0]=face[3];
		face[3]=face[5];
		face[5]=face[2];
		face[2]=temp;
		break;
	}
}

void dice::setFaceNumber(int *number) {
	for(int i=0; i<6; ++i) {
		face[i]=*(number+i);
	}
}

int main() {
	int num[6];
	string str;
	dice d;
	cin >> num[0] >> num[1] >> num[2] >> num[3] >> num[4] >> num[5] >> str;
	d.setFaceNumber(num);
	for(int i=0; i<(int)str.length(); ++i) {
		d.rotate(str[i]);
	}
	cout << d.getTopFace() << endl;
	return 0;
}

Measured memory_bytes: 3160
from itertools import combinations

n,m,x = [int(i) for i in input().split()]
data = [input() for _ in range(n)]
data = [[int(i) for i in d.split()] for d in data]

min_total = -1
for m_comb in range(1, n+1):
    for comb in combinations(data, m_comb):
        c_totals = [sum([c[i] for c in comb]) >= x for i in range(1, m+1)]
        if all(c_totals):
            if min_total == -1:
                min_total = sum([c[0] for c in comb])
            if sum([c[0] for c in comb]) < min_total:
                min_total = sum([c[0] for c in comb])
print(min_total)

Measured memory_bytes: 9232
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int binaryExponentiation(int x, int n) //function to calculate x raise to power n
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x;
		x = x * x;
		n = n / 2;
	}
	return result;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-______________________________________________________________________________


	int r;
	cin >> r;
	cout << fixed << setprecision(15) << 2 * (pi)*r << en;

	return 0;
}


Measured memory_bytes: 3800
#include<stdio.h>

int main(){
	int A=0;
	int B=0;
	int C=0;
	int X=0;
	int Y=0;
	scanf("%d %d %d %d %d",&A,&B,&C,&X,&Y);
	int C_MAX=2*(X+Y);
	int min_val=0;
	for(int c=0;c<=C_MAX;c++){
		int val=0;
		int a=0;
		int b=0;
		//C
		a=c/2;
		b=c/2;
		val+=C*c;
		//A
		while(X>a){
			val+=A;
			a++;
		}
		//B
		while(Y>b){
			val+=B;
			b++;
		}
		
		if((val<min_val) || (c==0)){
			min_val=val;
		}
	}
	printf("%d\n",min_val);
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,t;
    scanf("%d%d",&n,&t);
    int x,pre;
    int minn,maxx=-999;
    int cnt=1;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(i)
        {
            if(x>pre)
                if(x-minn>maxx)
                    maxx=x-minn,cnt=1;
                else if(x-minn==maxx)
                    cnt++;
            if(minn>x)
                minn=x;
        }
        else
            minn=x;
        pre=x;
    }
    printf("%d\n",cnt);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int cards[4][13] = {{0}};
	int n,i,j,k,rank;
	char m[4] = {'S','H','C','D'};
	char mark;
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf(" %c %d",&mark,&rank);
                if(mark == 'S'){cards[0][rank - 1] = 1;}
		if(mark == 'H'){cards[1][rank - 1] = 1;}
		if(mark == 'C'){cards[2][rank - 1] = 1;}
		if(mark == 'D'){cards[3][rank - 1] = 1;}
	}
	for(j = 0;j < 4;j++){
		for(k = 0;k < 13;k++){
			if(cards[j][k] == 0){
				printf("%c %d\n",m[j],k + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    ll n;
    cin >> n;
    //vector<ll> a(n);
    vector<ll> occupied(200030,0);
    ll ans=0ll;
    rp(i,n) {
        ll a;
        cin >> a;
        if(a>=n) continue;
        if(i+a<=200005)
        occupied[i+a]++;
        if(i-a>=0){
            ans+=occupied[i-a];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4840
a = int(input())
b = int(input())
c = int(input())
x = int(input())
count = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500*i+100*j+50*k == x:
                count += 1
print(count)

Measured memory_bytes: 3064
#include<iostream>

using namespace std;

#define N 1000000
#define INF 2147483647
int d[2*N-1];
int n;

void update(int i, int x){
  int ith = i+n-1;
  d[ith] = x;
  while(ith > 0){
    ith = (ith-1)/2;
    d[ith] = min(d[ith*2+1],d[ith*2+2]);
  }
}

int query(int a, int b, int k, int l, int r){
  int vl, vr;
  
  if (r <= a || b <= l) return INF;
  if (a <= l && r <= b) return d[k];
  
  vl = query(a, b, k*2 + 1, l,(l+r)/2);
  vr = query(a, b, k*2 + 2,(l+r)/2, r);
  
  return min(vl,vr);
}

int find(int s, int t){
  return query(s, t+1, 0, 0, n);
}



int powi(int x , int i){
  if (i == 0) return 1;
  return powi(x,i-1) * x;
}

void init(){
  int i = 1;
  while (i < n) i *= 2;
  n = i;
  for(i=0; i < 2*n-1; i++){
    d[i] = INF;
  }
}

void printTree(){
  int level = 1;
  for(int i=0; i < 2*n-1; i++){
    if (powi(2,level)-1 == i){
      cout << endl;
      level++;
    }
    if(d[i] == INF){
      printf("X ");
    }else{
      printf("%d ",d[i]);
    }
  }
  cout << endl;
}

int main(){
  int q;
  int c, s, t;
  cin >> n >> q;
  init();
  for(int i = 0;i < q;i++){
    cin >> c >> s >> t;
    if(c == 0) update(s,t);
    if(c == 1) printf("%d\n",find(s,t));
  }
  
  // printTree();
  return 0; 
}



Measured memory_bytes: 4200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int d;
double v[10];
double rec(vector<pair<double,double> >vec,double x){
	double ret = 0;
	for(int i=0;i<vec.size();i++){
		double add = vec[i].sc;
		for(int j=0;j<vec.size();j++){
			if(i == j) continue;
			add *= (x-vec[j].fi);
			add /= (vec[i].fi-vec[j].fi);
		}
		ret += add;
	}
	return ret;
}
int main(){
	while(1){
		cin>>d;
		if(d==0) return 0;
		for(int i=0;i<=d+2;i++) cin>>v[i];
		for(int i=0;i<=d+2;i++){
			for(int j=0;j<=d+2;j++){
				if(i == j) continue;
				vector<pair<double,double> >vec;
				for(int k=0;k<=d+2;k++) {
					if(i == k || j == k) continue;
					vec.pb(mp((double)(k),v[k]));
				}
				double act = rec(vec,(double)(j));
				if(abs(act-v[j]) >1e-1) goto fail;
			}
			cout<<i<<endl; break;
			fail:;
		}
	}
}


Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,int> pr;
vector<pr>v;
bool cmp(pr& x,pr& y){
    if(x.first * y.second == y.first * x.second)
        return x.first < y.first;
    return x.first * y.second < y.first * x.second;
}
int K;
int main(){
    cin>>K;
    // #(9)
    for(int i=0;i<16;i++){
        long long digit=1,sum=0;
        for(int j=0;j<i;j++,digit*=10){
            sum+=digit*9;
        }
        for(int j=0;j*digit<1'000'000'000'000'000LL&&j<10000;j++){
            int x=0;
            int tmp = j;
            while(tmp){
                x+=tmp%10;
                tmp/=10;
            }
            v.push_back({j*digit+sum,x+9*i});
        }
    }
    sort(v.begin(),v.end(),cmp);
    long long high=0;
    for(auto &p:v){
        if(p.first>high){
            cout<<p.first<<'\n';
            high=p.first;
            K--;
            if(K==0)return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 2420
#include <iostream>

using namespace std;

int main() {
    int n, ans = 0;
    cin >> n;
    while (n > 0) {
        ans += (n % 10);
        n /= 10;
    }
    if (ans == 1) ans = 10;
    cout << ans << endl;
    return 0;
}


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

#define mod 1000000007

long long solve();

int main()
{
    printf("%lld\n", solve());

    return 0;
}

long long solve()
{
    int n, m;
    scanf("%d%d", &n, &m);

    if (n > m) std::swap(n, m);
    if (n < m - 1) return 0;

    long long ans{1};
    if (n == m) ans = 2;
    for (int i = 1; i <= n; i++)
    {
        ans = ans * i % mod * i % mod;
    }
    for (int i = n + 1; i <= m; i++)
        ans = ans * i % mod;

    return ans;
}

Measured memory_bytes: 256
N,M,P = map(int,input().split())
ABC = [tuple(map(int,input().split())) for i in range(M)]

es = [[] for _ in range(N)]
bs = [[] for _ in range(N)]
for a,b,c in ABC:
    a,b = a-1,b-1
    es[a].append((b,c-P))
    bs[b].append((a,c-P))

go_set = set([0])
stack = [0]
while stack:
    v = stack.pop()
    for to,_ in es[v]:
        if to in go_set: continue
        go_set.add(to)
        stack.append(to)

bk_set = set([N-1])
stack = [N-1]
while stack:
    v = stack.pop()
    for to,_ in bs[v]:
        if to in bk_set: continue
        bk_set.add(to)
        stack.append(to)

use = go_set & bk_set
K = len(use)
INF = float('inf')
d = [INF] * N
d[0] = 0
for i in range(K):
    for v in range(N):
        if v not in use: continue
        for to,c in es[v]:
            if to not in use: continue
            if d[to] > d[v] - c:
                d[to] = d[v] - c
                if i==K-1:
                    print(-1)
                    exit()
print(max(0, -d[-1]))

Measured memory_bytes: 55128
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VVI vector<VI>
#define VL vector<LL>
#define VVL vector<VL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define all(x) x.begin(),x.end()
#define watch(x) cout<<(#x)<<" = "<<(x)<<'\n'
#define mset(a,v) memset(a,v,sizeof(a))
#define setp(x) cout<<fixed<<setprecision(x)
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 1e9 + 7;
const LL MX = 1e9;
const LL INF = 1e9;

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    string s;
    cin>>s;
    int ans;
    if(s[0] == 'R' && s[1] == 'R' && s[2] == 'R') ans = 3;
    else if(s[0] == 'R' && s[1] == 'R') ans = 2;
    else if(s[1] == 'R' && s[2] == 'R') ans = 2;
    else if(s[0] == 'R' || s[1] == 'R' || s[2] == 'R') ans = 1;
    else ans = 0;

    cout<<ans<<'\n';

    /*
    int t,n;
    cin>>t;
    while(t--)
    {
        cin>>n;
        int a[n];
        loop(i,0,n)
        {
            cin>>a[i];
        }
    }
    */

    /*
    int n;
    cin>>n;
    int a[n];
    loop(i,0,n)
    {
        cin>>a[i];
    }
    */

    /*
    cout<<ans<<'\n';

    if(f) cout<<"YES\n";
    else cout<<"NO\n";

    if(f) cout<<"Yes\n";
    else cout<<"No\n";
    */

    return 0;
}


Measured memory_bytes: 3632