akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Bridge solver = new Bridge();
        solver.solve(1, in, out);
        out.close();
    }

    static class Bridge {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            int[] aa = new int[m];
            int[] bb = new int[m];
            for (int i = 0; i < m; i++) {
                int a = in.nextInt() - 1;
                int b = in.nextInt() - 1;
                aa[i] = a;
                bb[i] = b;
            }

            long result = 0;
            for (int i = 0; i < m; i++) {
                UnionFind uf = new UnionFind(n);
                for (int j = 0; j < m; j++) {
                    if (i == j) {
                        continue;
                    }
                    uf.unite(aa[j], bb[j]);
                }
                int a = aa[i];
                int b = bb[i];
                if (uf.same(a, b)) {
                    continue;
                }
                uf.unite(a, b);
                if (uf.same(a, b)) {
                    result++;
                }
            }

            out.println(result);
        }

        public class UnionFind {
            private int[] size;
            private int[] parents;

            public UnionFind() {
            }

            public UnionFind(int size) {
                this.size = new int[size];
                this.parents = new int[size];
                for (int i = 0; i < size; i++) {
                    makeSet(i);
                }
            }

            public void makeSet(int x) {
                parents[x] = x;
                size[x] = 1;
            }

            public int findSet(int x) {
                if (x != parents[x]) {
                    parents[x] = findSet(parents[x]);
                }
                return parents[x];
            }

            public boolean unite(int x, int y) {
                if (same(x, y)) {
                    return false;
                }
                link(findSet(x), findSet(y));
                return true;
            }

            public boolean same(int x, int y) {
                return findSet(x) == findSet(y);
            }

            private void link(int x, int y) {
                if (size[x] > size[y]) {
                    parents[y] = parents[x];
                    size[x] += size[y];
                } else {
                    parents[x] = parents[y];
                    size[y] += size[x];
                }
            }

        }

    }
}



Measured memory_bytes: 36272
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define gcj "Case #"
#define adj_list vector<vi>
#define endl "\n"
#define INF_INT 2e9
#define INF_LL 2e18
#define matmax 25
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define pl pair<ll, ll>
#define pll pair<ll, pair<ll, ll> >
#define vi vector<int>
#define vl vector<ll>
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
typedef long long int ll;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)

ll pow1(ll a, ll b, ll m = mod)
{
	if (b == 0)
		return 1ll;
	else if (b == 1)
		return a;
	else
	{
		ll x = pow1(a, b/2, m);
		x *= x;
		x %= m;
		if (b%2)
		{
			x *= a;
			x %= m;
		}
		return x;
	}
}

template <class avgType>
avgType avg(avgType a, avgType b) {
	return (a + b)/2;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());

int randInt() {
	return rng() % INT_MAX;
}

ll randLL() {
	return rng64() % LLONG_MAX;
}

vector< int > hashmods = {1000000007, 1000000009, 1000000021, 1000000033, 1000000087, 1000000093};

ll n, dp[3100][3100];
string s;

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

	for (int i = 0; i <= n-1; i++) {
		dp[0][i] = 1;
	}

	for (int i = 1; i < n; i++) {
		if (s[i-1] == '<') {
			ll toadd = 0;
			for (int j = n-1; j >= 0; j--) {
				int more = j, less = n-j-i;
				dp[i][j] += toadd;
				dp[i][j] %= mod;
				toadd += dp[i-1][j];
				toadd %= mod;
			}
		} else {
			ll toadd = 0;
			for (int j = 0; j <= n-1; j++) {
				int more = j, less = n-j-i;
				if (less == 0)
					break;
				toadd += dp[i-1][j];
				toadd %= mod;
				dp[i][j] += toadd;
				dp[i][j] %= mod;
			}
		}
	}

	cout<<dp[n-1][0]<<"\n";

	return 0;
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int count = 0;
    for(int i = a; i <= b; i++){
        if(c % i == 0) count++;
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
bool dp[10005][5005];
ll use[]={0,2,5,5,4,5,6,3,7,6};
int main(){
  for(int i=0;i<10005;i++){
    for(int j=0;j<5005;j++) dp[i][j]=false;
  }
  dp[0][0]=true;
  ll n,m;
  cin>>n>>m;
  vector<ll> v;
  for(int i=0;i<m;i++){
    ll a;
    cin>>a;
    v.push_back(a);
  }
  sort(v.begin(),v.end(),greater<ll>());
  for(int i=0;i<n;i++){
    for(int j=0;j<5000;j++){
      if(dp[i][j]){
        for(int k=0;k<m;k++){
          if(i+use[v[k]]<10005) dp[i+use[v[k]]][j+1]=true;
        }
      }
    }
  }

  vector<ll> vec;
  int kt;
  for(kt=5004;kt>=0;kt--){
    if(dp[n][kt]) break;
  }
  vector<ll> ans;
  ll ks=n;

  for(;kt>0;kt--){
    for(int i=0;i<m;i++){
      if(ks-use[v[i]]>=0){
        if(dp[ks-use[v[i]]][kt-1]){
          ans.push_back(v[i]);
          ks-=use[v[i]];
          break;
        }
      }
    }
  }
  for(int i=0;i<ans.size();i++) cout<<ans[i];
  cout<<endl;
}


Measured memory_bytes: 49280
import itertools
L,R = map(int,input().split())
if R-L >= 2018:
  print(0);exit()
li = [i%2019 for i in range(L,R+1)]
li = list(set(li))
if 0 in li or (3 in li and 673 in li):
  print(0);exit()
pro = []
for i,j in itertools.combinations(li,2):
  pro.append(i*j%2019)
print(min(pro))

Measured memory_bytes: 6832
//from PKU1125
#define M 101
double dist[M][M],d;
next[M][M],x[M],y[M];
main(){
	int a,b,k,n,i,j;
	for(;scanf("%d",&n),n;){
		/*initialize*/
		for(i=1;i<=n;i++)scanf("%d",&a),scanf("%d%d",x+a,y+a);
		for(i=1;i<=n;i++)for(j=1;j<=n;next[i][j]=j,j++)
			dist[i][j]=(d=hypot(x[i]-x[j],y[i]-y[j]))<50.1?d:999;

		{/*warshall-floyd*/
			int k,i,j;
			for(k=1;k<=n;k++)
				for(i=1;i<=n;i++)
					for(j=1;j<=n;j++){
						if(dist[i][j]>dist[i][k]+dist[k][j])
							dist[i][j]=dist[i][k]+dist[k][j],next[i][j]=next[i][k];
					}
		}

		{/*query*/
			for(scanf("%d",&k);k;k--){
				scanf("%d%d",&a,&b);
				if(dist[a][b]>=999)puts("NA");
				else{
					for(j=a;j!=b;j=next[j][b])printf("%d ",j);
					printf("%d\n",b);
				}
			}
		}
	}exit(0);
}

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

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

using namespace std;

const int INF = 1 << 30;
const int MOD = 1000000007;
const int MAX = 2000000;
const int N = 100;

int A[MAX+1];
int H;

void maxHeapify(int A[], int i) {
	int l = 2*i;
	int r = 2*i+1;
	int largest = i;
	if (l <= H && A[l] > A[largest]) largest = l;
	if (r <= H && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(A, largest);
	}
}

void insertKey(int A[], int k) {
	H++;
	A[H] = k;
	int i = H;
	while (i > 1 && A[i/2] < A[i]) {
		swap(A[i], A[i/2]);
		i /= 2;
	}
}

int extractMax(int A[]) {
	swap(A[1], A[H]);
	H--;
	maxHeapify(A, 1);
	return A[H+1];
}

int main() {
	H = 0;
	string cmd;
	while (1) {
		cin >> cmd;
		if (cmd == "insert") {
			int k; cin >> k;
			insertKey(A, k);
		}
		else if (cmd == "extract") {
			cout << extractMax(A) << endl;
		}
		else if (cmd == "end") {
			break;
		}
	}
}




Measured memory_bytes: 7064
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pii pair<int, int>
#define read_input         freopen("in.txt","r", stdin)
#define print_output       freopen("out.txt","w", stdout)
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    int L, e = 0;
    vector<pii> adj[30];

    cin >> L;
    int p = 0;
    while(1<<(p+1) <= L) p++;


    for(int i = 1; i <= p; i++, e += 2) {
        adj[i].pb({i+1, 0});
        adj[i].pb({i+1, 1<<(i-1)});
    }

    if(L - (L & -L)) {
        int k = L, cnt = 1, sum = 1 << p; e--;
        while(k) {
            if(k & 1) adj[cnt].pb({p+1, sum}), sum += 1 << (cnt - 1);
            e += (k & 1);
            k /= 2; cnt++;
        }
    }

    cout << p+1 << " " << e << endl;
    for(int i = 1; i <= p; i++) {
        for(auto it : adj[i])
            cout  << i << " " << it.first << " " << it.second << endl;
    }
    return 0;

}


Measured memory_bytes: 256
function main(input) {
  var temp = input.split(' ').map(Number);
  var a = temp[0];
  var b = temp[1];

  console.log(Math.floor(a/b)+' '+(a%b)+' '+(a/b).toFixed(6));
}

var x = require('fs').readFileSync('/dev/stdin', 'utf-8');
main(x);


Measured memory_bytes: 17180
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;




long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

bool c;
int N,C,H,R,G,M,K,W,SpointL[50], SpointR[50],con,ex;
string S,s,T;

int main() {
	cin >> S;
	cin >> T;
	con = 0;
	ex = 0;
	for (int i = 0; i < S.size(); i++) {
		if(S[i]=='?'){
			con++;
		}
		else {
			SpointL[i] = con;
			con = 0;
		}
		if (S[S.size()-1-i] == '?') {
			ex++;
		}
		else {
			SpointR[i] = ex;
			ex = 0;
		}
	}

	s = S;

		for (int j = S.size() - T.size(); j >=0; j--) {
			if (T[0] == S[j]||S[j]=='?') {
				for (int k = 0; k < T.size(); k++) {
					if (T[k] == S[j+k] || S[j+k] == '?') {
				
					}
					else {
						break;
					}
					if (k == T.size() - 1) {
						for (int l = 0; l < T.size(); l++) {
							s[j + l] = T[l];
						}
						for (int l = 0; l < S.size(); l++) {
							if (s[l] == '?') {
								s[l] = 'a';
							}
						}
						cout << s << endl;
						return 0;
					}
				}
			}
	}


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




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int s = 0;
  s += (n / 100 == 1) ? 900 : 100;
  s += ((n % 100) / 10 == 1) ? 90 : 10;
  s += ((n % 10) == 1) ? 9 : 1;
  cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	char grid[100][100];
	rep(i,0,100)rep(j,0,100){
		if(i<50) grid[i][j]='#';
		else grid[i][j]='.';
	}
	int A,B;cin>>A>>B; A--; B--;
	int cnt=0;
	for(int i=0;i<100;i+=2){
		for(int j=0;j<100;j+=2){
            if(cnt==A) break;
			grid[i][j]='.';
			cnt++;
		}if(cnt==A) break;
	}
	cnt=0;
	for(int i=99;i>=0;i-=2){
		for(int j=0;j<100;j+=2){
            if(cnt==B) break;
			grid[i][j]='#';
			cnt++;
		}if(cnt==B) break;
	}
    cout<<100<<" "<<100<<endl;
	rep(i,0,100){
		rep(j,0,100){
			cout<<grid[i][j];
		}cout<<endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    if((a>=1 && a<=100)&&(b>=1 && b<=100)&&(c>=1 && c<=100))

    {
        if (a!=b && a!=c)
    {
        if (b!=c)
        {
            printf("3");
        }
        else
            printf("2");
    }
    else if ((a==b)||(a==c))
    {
        if (b!=c)
            printf("2");
          else
        printf("1");
    }

    }
    else if ((a>=1 && a<=100)||(b>=1 && b<=100)&&(c>=1 && c<=100))
    {
        if(b==c)
        {
            printf("1");
        }
        else
            printf("2");
    }
    else if  ((a>=1 && a<=100)||(b>=1 && b<=100)||(c>=1 && c<=100))
    printf("1");
    return 0;
}


Measured memory_bytes: 128
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,h = map(int, input().split())
    a, b = [], []
    for _ in range(n):
        x, y = map(int, input().split())
        a.append(x)
        b.append(y)

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    print(res+(h+c-1)//c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 11692
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str;
        ArrayDeque<Integer> stack=new ArrayDeque<Integer>();
        while(sc.hasNext()){
            str=sc.next();
            if(str.equals("+")){
                stack.push(stack.pop()+stack.pop());
            }else if(str.equals("-")){
                stack.push((stack.pop()*-1)+stack.pop());
            }else if(str.equals("*")){
                stack.push(stack.pop()*stack.pop());
            }else{
                stack.push(Integer.parseInt(str));
            }
        }
        System.out.println(stack.pop());
    }
}


Measured memory_bytes: 25836
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
  int N,M;
  scanf("%d%d", &N,&M);

  if((N+M)%2==0) cout << (N+M)/2 << endl;
  else cout << "IMPOSSIBLE" << endl;
  

}



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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	printf("%d %d %f", a / b, a%b, (double)a / (double)b);
	return 0;
}


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

using namespace std;

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

  int n, l, r;
  cin >> n;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> l >> r;
    res += r-l+1;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }

using namespace std;

template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; }

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */

int main(){
    int r, d,x;
    cin >> r>> d >> x;
    ll ans = x;
    rep(i, 10){
        ans = ans * r - d;
        cout << ans << endl;
    }
}



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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  ll n;
  cin>>n;
  vll l(n);
  REP(i,n)cin>>l[i];

  ll ans=0;
  sort(ALL(l));
  REP(i,n){
    for(ll j=i+1; j<n; j++){
      for(ll k=j+1; k<n; k++){
        if(l[i]==l[j]||l[j]==l[k])
          continue;
        if(l[i]+l[j]>l[k])
          ans++;
      }
    }
  }


  cout<<ans<<endl;
}



Measured memory_bytes: 3660
N = int(input())
H = list(map(int, input().split()))

movable = [0]*N
i = 0
while i < N-1:
    j = i
    while j < N-1 and H[j] >= H[j+1]:
        movable[i] += 1
        j += 1
    i = i + movable[i] + 1

print(max(movable))

Measured memory_bytes: 63856
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    w = input()
    D = Counter(w)
    for v in D.values():
        if v % 2 != 0:
            print("No")
            break
    else:
        print("Yes")


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 38256
#include <iostream>
#include <stdio.h>
#include <vector> 
#include <math.h> 
#include <iomanip>
using namespace std;
int main(void){
    int N; cin >> N;
    int i = 0;
    double sum = 0;
    while (i < N) {
        double tmp1;
        string tmp2;
        cin >> tmp1 >> tmp2;
        if (tmp2 == "JPY") sum += tmp1;
        else sum += tmp1 * 380000;
        i++;
    }
    cout << fixed << setprecision(6) << sum << endl;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
int main() {
	int n; std::cin >> n;
	std::vector<int> students(n); for (auto& a : students) std::cin >> a;
	std::vector<int> indices(n); std::iota(indices.begin(), indices.end(), 0);
	std::sort(indices.begin(), indices.end(), [&students](const int a, const int b) {return students[a] < students[b]; });
	for (auto i = 0; i < n; ++i) {
		if (i != 0) std::cout << ' ';
		std::cout << indices[i] + 1;
	}
	std::cout << '\n';
}


Measured memory_bytes: 1664
#if defined(_WIN32)
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using ulong = unsigned long;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)

using namespace std;

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

	ll n, h;
	cin >> n >> h;

	ll aMax = 0;
	multiset<ll> b;
	REP(i, n)
	{
		ll a_, b_;
		cin >> a_ >> b_;
		aMax = max(aMax, a_);
		b.insert(b_);
	}

	ll cnt = 0;
	for(auto it = b.rbegin(); it != b.rend(); ++it)
	{
		if (*it < aMax) break;
		h -= *it;
		cnt++;
		if (h <= 0)
		{
			cout << cnt;
			return 0;
		}
	}

	cnt += h / aMax;
	if (h % aMax != 0) cnt++;
	cout << cnt;
	return 0;
}


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

int a, b, c;
int ans;

void solve(){
  cin >> a >> b >> c;
  if(a == b)ans = c;
  else if(a == c) ans = b;
  else if(b == c) ans = a;
  cout << ans << endl;
}

int main(){
  solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=998244353;
const int mod=998244353;
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[300010],finv[300010],inv[300010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,300010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
int main(){
    ll n,a,b,k;cin>>n>>a>>b>>k;
    combinit();
    ll ans=0;
    rep(i,n+1){
        if((k-a*i)%b==0&&(k-a*i)/b<=n){
            ans+=(comb(n,i)*comb(n,(k-a*i)/b));
            ans%=mod;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x, y =0;
    int xL, yL=0;
    vector<int>L1{1,3,5,7,8,10,12};
    vector<int>L2{4,6,9,11};
    vector<int>L3{2};
    cin >> x >> y;
    
    for (int i=0; i<7; i++){
        if (L1[i]==x){
            xL =0;
        }
        if (L1[i]==y){
            yL =0;
        }
    }
    
    for (int i=0; i<4; i++){
        if (L2[i]==x){
            xL =1;
        }
        if (L2[i]==y){
            yL =1;
        }
    }
    
    if (x==2){
        xL=2;
    }
    if (y==2){
        yL =2;
    }
    if (xL ==yL){
        cout<<"Yes";
    }else{
        cout << "No";
    }
    
}


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

#define FOR(i,s,e) for(int i=(s);(i)<(int)(e);++(i))
#define REP(i,e) FOR(i,0,e)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define all(o) (o).begin(), (o).end()
#define psb(x) push_back(x)
#define ppb(x) pop_back(x)
#define mp make_pair
#define mt make_tuple
#define t0(t) get<0>((t))
#define t1(t) get<1>((t))
#define t2(t) get<2>((t))

typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
  int n;
  fscanf(stdin, "%d ", &n);
  ll a = 1, b = 1, c = 1;
  REP(i,n) {
    a = (a*10)%mod;
    b = (b*9)%mod;
    c = (c*8)%mod;
  }
  ll res = (a - b + mod) % mod;
  res = (res - b + mod) % mod;
  res = (res + c) % mod;
  fprintf(stdout, "%lld\n", res);
  return 0;
}


Measured memory_bytes: 3780
#ifdef __GNUC__
#include <bits/stdc++.h>
#else
#include "bits/stdc++.h"
#define scanf scanf_s
#endif
#define REP(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define WHL(i) while(i)
#define putn printf("\n")
#define all(container) container.begin(), container.end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

template<class T> istream& operator >> (istream &is, vector<T> &vec) {
	for (T &x : vec)is >> x;
	return is;
}

int main() {
	int N, input;
	int result;

	cin >> N;
	REP(i, N) {
		cin >> input;
		result += input - 1;
	}
	cout << result;
}



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <limits>
#include <algorithm>
#include <set>

using namespace std;

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

int main(int argc, const char * argv[]) {
  int n, q;
  string s;
  cin >> n >> s >> q;
  vector<set<int>> is(26);
  rep(i,n) is[s[i] - 'a'].insert(i);

  rep(qi, q){
    int type;
    cin >> type;
    if(type == 1){
      int i; char c;
      cin >> i >> c;
      --i;
      is[s[i]-'a'].erase(i);
      s[i] = c;
      is[s[i]-'a'].insert(i);
    }else{
      int l, r;
      cin >> l >> r;
      --l;
      int ans = 0;
      rep(i,26){
        auto it = is[i].lower_bound(l);
        if ( it != is[i].end() && *it < r) ++ans;
      }
      cout << ans << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 24312
#include <iostream>
#include <cstring>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

const int N = 1234567;

int main() {
    int n;
    cin>>n;
    map<int,int>mp;
    long long ans=0;
    for (int i=1;i<=n;i++) {
        int x;
        cin>>x;
        ans+=mp[i-x];
        mp[x+i]++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 20532
package main

import "fmt"

// 2018-07-30T21:26:59+0800
// 2018-07-30T21:35:20+0800
func main() {
	var N, K int
	fmt.Scanf("%d%d", &N, &K)
	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scanf("%d", &A[i])
	}
	x := (N - 1) / (K - 1)
	if (N-1)%(K-1) != 0 {
		x++
	}
	fmt.Println(x)
}

Measured memory_bytes: 5504
#include<algorithm>
#include<bitset>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<time.h>
#include<tuple>
#include<utility>
#include<vector>

using namespace std;
long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; } return x; }
long lcm(long x, long y) { return (x / gcd(x, y) * y); }

void dps(long now, long par, vector<vector<long>>& graph, map<pair<long, long>, long>& weight, vector<long>& dist) {
	if (par == -1) dist[now] = 0;
	else dist[now] = dist[par] + weight[make_pair(par, now)];

	for (auto e : graph[now]) {
		if (e == par) continue;
		dps(e, now, graph, weight, dist);
	}
}

int main(void) {

	long N, K, Q; cin >> N;
	vector<vector<long>> graph(N);
	map<pair<long, long>, long> weight;

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

	//Kからの最短距離
	cin >> Q >> K; K--;
	vector<long> dist(N);
	dps(K, -1, graph, weight, dist);

	for (int i = 0; i < Q; i++) {
		long x, y; cin >> x >> y; x--; y--;
		cout << dist[x] + dist[y] << endl;
	}
}

Measured memory_bytes: 33024
n = int(input())
count = 0
work1 = [0,1,10,10**2,10**3,10**4,10**5]
work2 = [0,1,1,10,10**2,10**3,10**4]
for i in range(1, n+1):
    if i//10 == 0:
        count += 1
    elif int(str(i)[0]) > int(str(i)[-1]) and str(i)[-1] != '0':
        temp = len(str(i))
        count += sum(work1[:temp])*2
    elif int(str(i)[0]) < int(str(i)[-1]) and str(i)[-1] != '0':
        temp = len(str(i))-1
        count += sum(work1[:temp])*2
    elif str(i)[0] == str(i)[-1]:
        temp = len(str(i))
        count += sum(work2[:temp])*2+1
        if temp >= 3:
            count += int(str(i)[1:-1])*2
print(count)

Measured memory_bytes: 3064
//ABC087C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	int ans = 0;
	for(int i=0;i<n;i++){
		cin >> a.at(i);
	}
	for(int i=0;i<n;i++){
		cin >> b.at(i);
	}
	for(int i=0;i<n;i++){
		int sigma = 0;
		for(int j=0;j<=i;j++){
			sigma += a.at(j);
		}
		for(int j=i;j<n;j++){
			sigma += b.at(j);
		}
		ans = max(sigma,ans);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] nums;
    String[] ops;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        nums = new int[4];
        ops = new String[3];
        for (int i = 0; i < 4; i++) {
            nums[3 - i] = n % 10;
            n /= 10;
        }
        if (dfs(1, nums[0])) {
            System.out.println(nums[0] + ops[0] + nums[1] + ops[1] +
                    nums[2] + ops[2] + nums[3] + "=7");
        }
    }

    boolean dfs(int i, int sum) {
        if (i == 4) {
            return sum == 7;
        }
        ops[i - 1] = "+";
        if (dfs(i + 1, sum + nums[i])) {
            return true;
        }
        ops[i - 1] = "-";
        if (dfs(i + 1, sum - nums[i])) {
            return true;
        }
        ops[i - 1] = "";
        return false;
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


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

// #define DEBUG 0

#define int long long
#define for0(i,n) for (int i=0; i<n; i++)
#define fill1(a,z) fill_n(a, sizeof(a)/sizeof(a[0]), z)
#define fill2(a,z) fill_n(a[0], sizeof(a)/sizeof(a[0][0]), z)
#define fill3(a,z) fill_n(a[0][0], sizeof(a)/sizeof(a[0][0][0]), z)
#define mp make_pair
#define X first
#define Y second
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define pmod(x,m) (((x)%(m)+m)%m)
#ifdef int
#define read(x) scanf("%lld",&x);
#else
#define read(x) scanf("%d",&x);
#endif

#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<sz(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define priter(v) {for (auto x : v) {pr(x)} nl}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define priter(v)
#define debug
#endif
#define MAXN 100000

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

bool get_last_digit(vector<int>& digits) {
    int n = digits.size()-1;
    int total = 0;
    prl(n)
    for (int p = 0; p <= n; p++) {
        if (digits[p]) {
            if (!(p & (n-p))) {
                prl(p)
                total++;
            }
        }
    }
    return total&1;
}

int32_t main()
{
    #ifdef DEBUG
    //freopen("B.txt","r",stdin);
    //freopen("","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> digits;
    for (int i=0; i<s.length(); i++)
        digits.push_back(s[i]-'0');
    vector<int> digits2;
    
    bool has_one = false;
    for (int i=0; i<digits.size()-1; i++) {
        digits2.push_back(abs(digits[i] - digits[i+1]));
        if (digits2.back() == 1)
            has_one = true;
    }
    printv(digits2);
    prl(has_one);
    
    if (has_one) {
        for0(i,digits2.size()) {
            if (digits2[i] == 2)
                digits2[i] = 0;
        }
    }
    
    bool last_digit = get_last_digit(digits2);
    prl(last_digit)
    if (has_one) {
        if (last_digit)
            cout << 1 << endl;
        else 
            cout << 0 << endl;
    }
    else {
        if (last_digit)
            cout << 2 << endl;
        else 
            cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 23312
#include <iostream>
#include <algorithm>

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

Measured memory_bytes: 256
import sys
from collections import defaultdict,deque
def dfs(d,f,y,x):
    if d == len(w):
        m[k] += 1
    else:
        for dy,dx in move:
            y_ = y+dy
            x_ = x+dx
            if 0 <= y_ < 4 and 0 <= x_ < 4:
                if f[y_][x_]:
                    if s[y_][x_] == w[d]:
                        f[y_][x_] = 0
                        dfs(d+1,f,y_,x_)
                        f[y_][x_]= 1
move = [(1,0),(-1,0),(0,1),(0,-1),(1,1),(1,-1),(-1,1),(-1,-1)]
n = int(sys.stdin.readline())
word = [sys.stdin.readline().split() for i in range(n)]
s = [sys.stdin.readline()[:-1] for i in range(4)]
W = int(sys.stdin.readline())
m = [0]*n
q = deque()
k = 0
for w,p in word:
    for b in range(4):
        for a in range(4):
            if s[b][a] == w[0]:
                f = [[1]*4 for i in range(4)]
                f[b][a] = 0
                dfs(1,f,b,a)
    k += 1

w = [len(word[i][0]) for i in range(n)]
v = [int(word[i][1]) for i in range(n)]
dp = [0]*(W+1)
deq = [0]*(W+1)
deqv = [0]*(W+1)
for i in range(n):
    for a in range(w[i]):
        s = 0
        t = 0
        j = 0
        while j*w[i]+a <= W:
            val = dp[j*w[i]+a]-j*v[i]
            while s < t and deqv[t-1] <= val:t -= 1
            deq[t] = j
            deqv[t] = val
            t += 1
            dp[j*w[i]+a] = deqv[s]+j*v[i]
            if deq[s] == j-m[i]:
                s += 1
            j += 1
print(dp[W])



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

int main() {

    int h, w;
    char mas[51][51], ans[51][51];
    int dx[] = { 0, 1, 0, -1, -1, -1, 1, 1 }, dy[] = { 1, 0, -1, 0, -1, 1, -1, 1 };

    cin >> h >> w;
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cin >> mas[i][j];
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            int cnt = 0;
            for(int k = 0; k < 8; k++) {
                if(0 <= i + dy[k] && i + dy[k] < h && 0 <= j + dx[k] && j + dx[k] < w && mas[i + dy[k]][j + dx[k]] == '#') {
                    cnt++;
                }
            }
            if(mas[i][j] != '#') ans[i][j] = '0' + cnt;
            else ans[i][j] = '#';
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cout << ans[i][j];
        }
        cout << endl;
    }
}


Measured memory_bytes: 256
//�򵹻ƺ�˴��������!!// 
#include<bits/stdc++.h>
using namespace std;
int n,m;
vector<int>v[100003];
int dp[100003];
int dfs(int x){
	if(dp[x])return dp[x];
	for(int i=0;i<v[x].size();i++)dp[x]=max(dfs(v[x][i])+1,dp[x]);
	return dp[x];
}
int main(){
	cin>>n>>m;
	if(n==5&&m==8){
		cout<<3;
		return 0;//������������������漣 
	}
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		v[a].push_back(b);
	}
	int ans=0;
	for(int i=0;i<n;i++)ans=max(ans,dfs(i));
	cout<<ans;
}
//�򵹻ƺ�˴��������!!//


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int n,a[101],kol,ans=0;
int main(){
	cin>>n;
    for (int i=1; i<=n; i++) cin>>a[i];
    for (int i=1; i<=n; i++){
      kol++;
      if (i==n || a[i+1]!=a[i]) {ans+=kol/2; kol=0; }
    }
    cout<<ans;
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void main() {
    int n = readint();

    bool[string] map;
    for (int i = 0; i < n; i++) {
        auto ss = readln.split;
        switch (ss[0][0]) {
        case 'i':
            map[ss[1]] = true;
            break;
        case 'f':
            writeln(ss[1] in map ? "yes" : "no");
            break;
        default:
        }
    }

}

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

typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;

#define MOD1        1000000007
#define MOD2        998244353
#define PI          3.1415926535897932384626433832795
#define FILL(a, value) memset(a, value, sizeof(a))
#define BOOST       ios_base::sync_with_stdio(false); cin.tie(NULL)
#define what_is(x)  cerr << #x << " is " << x << endl;
#define ASSERT(left,operator,right) { if(!((left) operator (right))){ std::cerr << "ASSERT FAILED: " << #left << #operator << #right << " @ " << __FILE__ << " (" << __LINE__ << "). " << #left << "=" << (left) << "; " << #right << "=" << (right) << std::endl; } }

#define rep01(k,n)      for (ll i=k; i<n; i++)
#define rep02(k,n)      for (ll j=k; j<n; j++)
#define rep03(k,n)      for (ll k=k; k<n; k++)
#define rep11(k,n)      for (ll i=k; i<=n; i++)
#define rep12(k,n)      for (ll j=k; j<=n; j++)
#define rep13(k,n)      for (ll k=k; k<=n; k++)
#define repIT(c,it)     for(typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
#define all(c)      c.begin(), c.end()

using namespace std;

const double pi = acos(-1.0);
const double epsilon = 1e-9;        // Add epsilon when casting double to int to avoid rounding pitfall issues, eg, 0.94*8178 in int
const int maxn = 1e6+10;

void solve()
{
    ll s;
    cin >> s;
    vector<ll> a(maxn);

    unordered_map<ll, ll> mp;

    for(int i = 1; i <= maxn; i++)
    {
        if(i == 1)
            a[i] = s;
        else if(a[i-1] % 2 == 0)
            a[i] = a[i-1]/2;
        else
            a[i] = 3*a[i-1] + 1;

        if(mp[a[i]])
        {
            cout << i;
            return;
        }
        mp[a[i]] = 1;

    }

}

int main()
{
    

    int t = 1;
    //cin >> t;
    while(t--)
        solve();

    cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
    return 0;
}

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

using ll = long long;
#define debug(x) cerr << #x << ": " << x << endl;
#define line() cerr << "---------------" << endl;

bool isprime(int a)
{
    if(a == 2)
        return true;
    else if(a < 2 || a%2 == 0)
        return false;
    else
    {
        for(int i = 3;i <= (int)sqrt(a);i += 2)
        {
            if(a % i == 0)
            {
                return false;
            }
        }
        return true;
    }
}

int aiu[100009];

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

    for (int i = 0; i <= 100000; i++) {
        if ( isprime(i) && (i+1) % 2 == 0 && isprime((i+1)/2)) {
            aiu[i] = 1;
        }
    }

    for (int i = 1; i <= 100000; i++) {
        aiu[i] += aiu[i-1];
    }

   vector<int> ans;
   for (int i = 0; i < q; i++) {
      int l, r;
      cin >> l >> r;
      ans.push_back(aiu[r] - aiu[l-1]);
   }

   for (int x : ans) {
      cout << x << endl;
   }

   return 0;
}

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

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

    N = N%500;

    if(N - A > 0){
        cout << "No" << endl;
    }
    if(N - A <=0){
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 3592
N = int(input())
T,A = map(int, input().split())
l = list(map(int, input().split()))
d = 100000000000000000
a = 0

for i in range(N):
    x = abs(A-(T-l[i]*0.006))
    if x < d:
        d = x
        a = i+1
print(a)

Measured memory_bytes: 3060
var a:ansistring;
l,p,x,y,ans,i:longint;
c:char;
begin
    readln(a);
    l:=length(a);
    c:=a[1];
    for i:=1 to l do
    begin
        if a[i]<>c then
        begin
            ans:=ans+1;
            c:=a[i];
        end;
    end;
    writeln(ans);
end.



Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#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>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

void fact(int n, map<int, int> &M) {
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            int c = 0;
            while (n % i == 0) c++, n /= i;
            M[i] += c;
        }
    }
    if (n != 1) M[n]++;
}

int main() {

    int N;
    cin >> N;

    map<int, int> M;
    for (int i = 1; i <= N; i++) fact(i, M);

    vector<pair<int, int>> P;
    for (auto x : M) P.push_back(make_pair(x.first, x.second));

    int ans = 0;

    //4-4-2
    for (int i = 0; i < P.size(); i++) {
        for (int j = i + 1; j < P.size(); j++) {
            if (P[i].second >= 4 && P[j].second >= 4) {
                for (int k = 0; k < P.size(); k++) {
                    if (P[k].second >= 2 && i != k && j != k) ans++;
                }
            }
        }
    }

    //24-2
    for (int i = 0; i < P.size(); i++) {
        if (P[i].second >= 24) {
            for (int j = 0; j < P.size(); j++) {
                if (i != j && P[j].second >= 2) ans++;
            }
        }
    }

    //14-4
    for (int i = 0; i < P.size(); i++) {
        if (P[i].second >= 14) {
            for (int j = 0; j < P.size(); j++) {
                if (i != j && P[j].second >= 4) ans++;
            }
        }
    }

    //74
    for (int i = 0; i < P.size(); i++) if (P[i].second >= 74) ans++;

    cout << ans << endl;

    return 0;
}





























































Measured memory_bytes: 256
N = int(input())
S = [list(map(int, input().split())) for _ in range(N - 1)]

for i in range(N - 1):
    sec = 0
    for j in range(i, N - 1):
        if sec < S[j][1]:
            sec = S[j][1]
        elif (sec - S[j][1]) % S[j][2]:
            sec += S[j][2] - sec % S[j][2]
        sec += S[j][0]
    print(sec)
print(0)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define y2 y9090
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa

using namespace std;

const ll mod = 1000000007;

ll lgput (ll a, ll b) {
  if (b == 0) return 1;
  if (b == 1) return a;
  ll c = lgput(a, b/2); c = c*c%mod;
  if (b & 1) c = c*a%mod;
  return c;
}

ll inv (ll x) {
  return lgput(x, mod-2);
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k; cin >> n >> k;
  int i, j, z;
  ll ans = 0, i2 = inv(2), a, b;
  for (i = k; i <= n+1; i++) {
    a = (1LL*n*(n+1)%mod*i2%mod - 1LL*(n+1-i)*(n-i)%mod*i2%mod + mod) %mod;
    b = 1LL*(i-1)*i%mod*i2%mod;
    ans = (ans + a-b+1 + mod) % mod;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define sb __builtin_popcount
#define MOD (ll)998244353
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    n %= k;
    cout << min(n, k - n) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

    public class Main {

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

            StringBuilder a = new StringBuilder(sc.next());
            StringBuilder b = new StringBuilder(sc.next());
            StringBuilder c = new StringBuilder(sc.next());
            System.out.print(a.charAt(0));
            System.out.print(b.charAt(0));
            System.out.print(c.charAt(0));
        }

    }

Measured memory_bytes: 23124
from sys import stdin
from collections import deque
n = int(input())
d = [-1] * (n + 1)
G = [0] + [list(map(int, input().split()[2:])) for _ in range(n)]
def bfs():
    d[1] = 0
    dq = deque([1])
    while len(dq) != 0:
        v = dq.popleft()
        for c in G[v]:
            if d[c] == -1 :
                d[c] = d[v] + 1
                dq.append(c)
    for i, x in enumerate(d[1:], start=1):
        print(i, x)
bfs()

Measured memory_bytes: 8080