akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>

using namespace std;

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

int main(){
  int t;
  long a, b, c, d;
  cin >> t;
  for(int i=0;i<t;i++){
    cin >> a >> b >> c >> d;
    if(a < b || d < b){
      cout << "No" << endl;
    }else if(b <= min(c, d)){
      cout << "Yes" << endl;
    }else{
      long g = gcd(b, d);
      long max_ = b - g + a % g;
      if(max_ <= c){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }
    }
  }
}

Measured memory_bytes: 256
import itertools

n, k = map(int, input().split())

if (n-2) * (n - 1) // 2 < k:
    print(-1)
else:
    graph = list(itertools.combinations(list(range(1, n + 1)), 2))
    idx = (n - 1) + (n-2) * (n - 1) // 2 - k
    print(idx)
    for i in range(idx):
        print(graph[i][0], graph[i][1])


Measured memory_bytes: 43248
#include <stdio.h>

bool INCLUDE3(int x)
{		
	if(x % 3 == 0){
		return true;
	}
	
	while(true){
		if(x % 10 == 3){
			return true;
		}
		
		x /= 10;
		
		if(x == 0){
			break;
		}
	}
	
	return false;
}
	
int main(void)
{
	int n;
		
	scanf("%d", &n);
	
	for(int i = 1; i <= n; i++){
	
		if(INCLUDE3(i)){
			printf(" %d", i);
		}
	}
	printf("\n");
	
	return 0;
}

Measured memory_bytes: 2660
#include<stdio.h>
#include<string.h>
#include <iostream>
using namespace std;

int main()
{

	int n = 0;
	char w[100][11];

	bool isOK = true;

	cin >> n;

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

	for (int i = 1; i < n; ++i) {

		int final = 0;

		for (int j = 0; j < 100; ++j) {

			if (w[i - 1][j] == '\0') {

				final = j - 1;
				break;
			}
		}
		
		if (w[i - 1][final] != w[i][0]) {
			isOK = false;
		}
	}

	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			if (i != j && !strcmp(w[i], w[j])) {

				isOK = false;
				break;
			}
		}
	}

	if (isOK) {
		cout << "Yes";
	}
	else {
		cout << "No";

	}

    return 0;
}

Measured memory_bytes: 256
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		char[] s = ns().toCharArray();
		int ct = 0;
		for(int i = 0, j = s.length-1; i < j; i++, j--) {
			if(s[i] != s[j]) ct++;
		}
		out.println(ct);
	}

	void run() throws Exception {
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		if (!INPUT.isEmpty())
			tr(System.currentTimeMillis() - s + "ms");
	}

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

	private byte[] inbuf = new byte[1024];
	public int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	private double nd() {
		return Double.parseDouble(ns());
	}

	private char nc() {
		return (char) skip();
	}

	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 21972
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
using namespace __gnu_pbds;

#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define int ll

main(){
    std::ios::sync_with_stdio(false); cin.tie(NULL);
    int x;
    cin>>x;
    int i,j;
    f(i,-10000,10000){
    	f(j,i+1,10000){
    		if(j*j*j*j*j - i*i*i*i*i >x)
    			break;
    		if(j*j*j*j*j - i*i*i*i*i ==x){
    			cout<<j<<" "<<i<<endl;
    			return 0;
    		}
    	}
    }
    return 0;   
}


Measured memory_bytes: 3580
import static java.lang.System.*;
import java.util.*;

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

        int n = sc.nextInt();
		int k = sc.nextInt();
		char[] s = sc.next().toCharArray();
		
		ArrayList<Integer> list = new ArrayList<Integer>();
		
		char prev = '1';
		list.add(0);
		for(int i=0; i<n; i++) {
			if(s[i] == prev) {
				list.set(list.size()-1, list.get(list.size()-1)+1);
			}
			else {
				prev = s[i];
				list.add(1);
			}
		}
		for(int i=0; i<k*2; i++) list.add(0);		
			
		int ans = 0;
		int sum = 0;
		for(int i=0; i<k*2; i++) 
			sum += list.get(i);
		
		for(int i=k*2; i<list.size(); i++) {
			sum += list.get(i);			
			if(i%2==0) ans = Math.max(ans, sum);
			sum -= list.get(i-k*2);		
		}
		
        out.println(ans);
    }
}


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

vector<ll> aflg,bflg;
void flags(ll x,bool whi){
    if(whi){
        x--;
        rp(i,40){
            
            ll flgs;
            //cout << x << endl;
            ll res=x%(1ll<<(i+1))-(1ll<<i)+1ll;
            //cout << res << " ";
            flgs=(x/(1ll<<(i+1)))*(1ll<<i)+max(0ll,res);
            aflg.push_back(flgs);
        }
    }
    else{
        rp(i,40){
            ll flgs;
            ll res=x%(1ll<<(i+1))-(1ll<<i)+1ll;
            flgs=(x/(1ll<<(i+1)))*(1ll<<i)+max(0ll,res);
            bflg.push_back(flgs);
        }
    }
}
int main(){
    ll a,b;
    cin >> a >> b;
    if(a==0) a++;
    flags(a, true);
    flags(b,false);
    /*for(auto af:aflg){
        cout << af << " ";
    }
    cout << endl;
    for(auto bf:bflg){
        cout << bf <<" ";
    }*/
    ll ans=0ll;
    rp(i,40){
        ll whichflg=bflg.at(i)-aflg.at(i);
        whichflg%=2ll;
        if(whichflg==1){
            ans += 1ll<<i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
"use strict";

function main(input) {
  let A = 100;
  let B = 0;
  input = parseInt(input);
  while (true) {
    A = A + Math.floor(A / 100);
    B++;
    if (input <= A) {
      console.log(B);
      return;
    }
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf-8").trim());


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

int main(void) {
    int n1, n2, n3;

    cin >> n1;
    cin >> n2;
    cin >> n3;

    if (n1 + n2 + n3 >= 22) {
        cout << "bust";
    }
    else
        cout << "win";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 2100000000
#define MOD 1000000007

bool dbgflag = false; //debug

struct areq {
  int a;
  int b;
  int c;
  int d;
};

int point(int i, int n, int m, vector<areq>&req) {
  bitset<20>b(i);
  if (b.count() != n) return -1;
  if (dbgflag) cout << b << endl;
  vector<int> a(n);
  int z = 1, index = 0;
  for (int k = 0; k < n+m-1; k++) {
    if (dbgflag) cout << (((i >> k) & 1) ? "true" : "false") << endl;
    if (((i >> k) & 1) == 0) {z++;}
    else {
      if (dbgflag) cout << index << endl;
      a[index] = z;
      index++;
    }
  }
  if (dbgflag) cout << "ok" << endl;
  int p = 0;
  for (areq r: req) {
    if (a[r.b-1] - a[r.a-1] == r.c) p += r.d;
  }

  return p;
}

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

  int n, m, q;
  cin >> n >> m >> q;
  vector<areq> req(q);
  for (int i = 0; i < q; i++) {
    cin >> req[i].a >> req[i].b >> req[i].c >> req[i].d;
  }

  int max_p = 0;
  for (int i = 0; i < (1 << n+m-1); i++) {
    max_p = max(max_p, point(i, n, m, req));
  }

  cout << max_p << endl;
}


Measured memory_bytes: 3600
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int x, y;
  readf("%s %s\n", &x, &y);

  auto a = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]];

  bool f;
  foreach (i; 0..3) {
    if (a[i].canFind(x) && a[i].canFind(y)) {
      f = true;
    }
  }
  if (f) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int ans, n;
int main() {
	cin>>n;
	if (n > 99999) ans = 90909;
	else if (n > 9999) {
		for (int i = 10000; i <= n; i++) ans++;
		ans += 909;
	}
	else if (n > 999) {
		ans = 909;
	}
	else if (n > 99) {
		for (int i = 100; i <= n; i++) ans++;
		ans += 9;
	}
	else if (n > 9) ans = 9;
	else for (ans = 0; ans < n; ans++);
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
using namespace std;
#define LL long long
#define int long long
const int inf=2147483647;
int read(){
	int x=0,f=1;
	char ch=getchar();
	while (ch<'0' || ch>'9'){
		if (ch=='-') f=-1;
		ch=getchar();
	}
	while (ch>='0' && ch<='9'){
		x=x*10+ch-'0';ch=getchar();
	}
	return x*f;
}
#define N 450
#define M 100010
#define G 85
#define Q 325
struct edge{
	int x,y,d,nxt;LL c;
}E[M];
char op[3];
struct pt{
	int x,y;LL v;
}p[G];
struct query{
	int op,a,b;
}q[Q];
int ec[N],tot;
void addE(int x,int y,int d,LL c){
	tot++;E[tot].x=x;E[tot].y=y;E[tot].d=d;E[tot].c=c;E[tot].nxt=ec[x];ec[x]=tot;
}
void addEdge(int x,int y,int d,LL c){
	addE(x,y,d,c);addE(y,x,0,-c);
}
int n,m,S,T;
LL f[N];int pre[N];bool vis[N];
bool spfa(){
	memset(f,-63,sizeof(f));f[S]=0;
	memset(vis,0,sizeof(vis));
	queue <int> q;q.push(S);
	while (!q.empty()){
		int x=q.front();q.pop();vis[x]=false;
		for (int i=ec[x];i;i=E[i].nxt){
			int y=E[i].y;
			if (E[i].d>0 && f[x]+E[i].c>f[y]){
				pre[y]=i;f[y]=f[x]+E[i].c;
				if (!vis[y]) vis[y]=true,q.push(y);
			} 
		}
	}
	if (f[T]>0) return true;
	else return false;
}
LL ans2,ans=0;
void work(){
	int x=T;
	while (x!=S){
		ans2+=E[pre[x]].c;
		E[pre[x]].d--;E[pre[x]^1].d++;x=E[pre[x]].x;
	}
}
int lx[G],rx[G],ly[G],ry[G];
void solve(int k){
	memset(ec,0,sizeof(ec));tot=1;
	for (int i=1;i<=n;++i) addEdge(p[i].x,200+i,1,p[i].v),addEdge(200+i,100+p[i].y,1,0);
	for (int i=1;i<=k;++i) lx[i]=ly[i]=1,rx[i]=ry[i]=100;
	for (int i=1;i<=m;++i){
		if (q[i].op==0) lx[q[i].b+1]=max(lx[q[i].b+1],q[i].a+1);
		if (q[i].op==1 && k>q[i].b) rx[k-q[i].b]=min(rx[k-q[i].b],q[i].a-1);
		if (q[i].op==2) ly[q[i].b+1]=max(ly[q[i].b+1],q[i].a+1);
		if (q[i].op==3 && k>q[i].b) ry[k-q[i].b]=min(ry[k-q[i].b],q[i].a-1);
	}
	for (int i=2;i<=k;++i) lx[i]=max(lx[i],lx[i-1]),ly[i]=max(ly[i],ly[i-1]);
	for (int i=k-1;i;--i) rx[i]=min(rx[i],rx[i+1]),ry[i]=min(ry[i],ry[i+1]);
	S=200+n+2*k+1,T=S+1;
	for (int i=1;i<=k;++i){
		if (lx[i]>rx[i] || ly[i]>ry[i]) return;
		addEdge(S,200+n+i,1,0);addEdge(200+n+k+i,T,1,0);
		for (int j=lx[i];j<=rx[i];++j) addEdge(200+n+i,j,1,0);
		for (int j=ly[i];j<=ry[i];++j) addEdge(100+j,200+n+k+i,1,0);
	}
	int cnt=0;ans2=0;
	while (spfa()) cnt++,work();
	if (cnt!=k) return;
	ans=max(ans,ans2);
}
signed main(){
	n=read();for (int i=1;i<=n;++i) p[i].x=read(),p[i].y=read(),p[i].v=read();
	m=read();
	for (int i=1;i<=m;++i){
		scanf("%s",op);
		q[i].a=read();q[i].b=read();
		if (op[0]=='L') q[i].op=0;
		if (op[0]=='R') q[i].op=1;
		if (op[0]=='D') q[i].op=2;
		if (op[0]=='U') q[i].op=3;
	}	
	for (int i=1;i<=n;++i) solve(i);
	cout<<ans<<endl;
}

Measured memory_bytes: 1280
#editorial 参照
#一度見た黒マスはその隣を見なくてよいので幅優先探索でよい

from collections import deque

h,w = map(int, input().split( ))
a = []
for _ in range(h):
    a_ = input()
    A =[]
    for i in range(w):
        A.append(a_[i])
    a.append(A)

cnt = [[-1]*w for _ in range(h)]

Q = deque()

for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            Q.append((i,j))
            cnt[i][j]=0

while Q:
    i,j = Q.popleft()
    for (k,l) in [(-1,0),(1,0),(0,-1),(0,1)]:
        if 0<=i+k and 0<=j+l and i+k<=h-1 and j+l<=w-1:
            if a[i+k][j+l]==".":
                a[i+k][j+l] ="#"
                cnt[i+k][j+l]=cnt[i][j]+1
                Q.append((i+k,j+l))
ans = 0
for i in range(h):
    ans = max(ans,max(cnt[i]))


print(ans)
    

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

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; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
    int N,M;
    cin>>N>>M;
    vector<vector<int>> g(N);
    for(int i = 0; i < M; i++){
        int x,y;
        cin>>x>>y;
        g[x-1].push_back(y-1);
    }
    int S,T;
    cin>>S>>T;
    S--;
    T--;
    queue<int> bfs;
    vector<int> d(N,-1);
    d[S]=0;
    bfs.push(S);
  	bool over = false;
    while(!bfs.empty()&&!over){
        int t = bfs.front();
        bfs.pop();
        for(auto x:g[t]){
          for(auto y:g[x]){
            for(auto z:g[y]){
              if(d[z]!=-1) continue;
              d[z]=d[t]+1;
              bfs.push(z);
              if(z==T) over = true;
            }
          }
        }
    }
    cout<<d[T]<<endl;
}

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

int main() {
  int n, d;
  cin >> n >> d;
  vector<int> x(n), y(n);
  for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
  
  int ans = 0;
  for(int i = 0; i < n; i++){
    ll nx = x[i], ny = y[i];
    if(sqrt(nx*nx + ny*ny) <= d) ans++;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4844
#include<stdio.h>
#include<string.h>

int main(){
	int n;
	scanf("%d", &n);
	char str[n+1];
	scanf("%s", str);
	
	if (n%2==1){
	
	puts("No");
}
else{
	int flag = 1;
	
	for ( int i =0; i<n/2; i++){
	if(str[i]!= str[i+n/2]){
	
	flag=0;
}
}
if (flag){
	puts("Yes");
}
else{
	puts("No");
}
}
	return 0;
}

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

int main() {
    int K, S;  cin >> K >> S;
    long long ans = 0;
    for (int x = 0; x <= K; ++x) {
        for (int y = 0; y <= K; ++y) {
            if (S - x - y >= 0 && S - x - y <= K) ++ans;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 764
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    double x1, y1, x2, y2, dx, dy;
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    dx = x2 - x1;
    dy = y2 - y1;
    printf("%lf", sqrt(dx * dx + dy * dy));
    return 0;
}



Measured memory_bytes: 2724
#include <stdio.h>


int main(void){
    int po[114514]={};
    int N;
    scanf("%d",&N);
    int ans=0;
    for(int i=0;i<N;i++){
        int kari;
        scanf("%d",&kari);
        if(kari<114514)po[kari]++;
        else ans++;
    }
    for(int i=0;i<114514;i++){
        if(po[i]>=i)ans+=po[i]-i;
        else ans+=po[i];
    }
    printf("%d",ans);
    return 0;
}


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

typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	else return gcd(y, x % y);
}

ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main() {
	int n; cin >> n;	
	ll ans = 1LL;
	for (int i = 0; i < n; i++) {
		ll t; cin >> t; 
		ans = lcm(ans, t);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  long long result = 0;
  cin >> N;
    vector<int> A(N);
  vector<int> B = {};
  for(int a = 0;a < N;a++)cin >> A[a];
  sort(A.begin(),A.end());
  B.push_back(A[N-1]);
  for(int a = N-2;a >= 0;a--){
    result += B[0];
    B.erase(B.begin()); 
    B.push_back(A[a]);
    B.push_back(A[a]);
    
  }
  cout << result << endl;
}

Measured memory_bytes: 5040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  long long ans = 0;
  for (int i = 1; i < N + 1; i++) {
    if (i%3 != 0 && i%5 != 0) {
    ans += i;
    }
  }
  
  cout << ans << endl;
}


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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    
    cout << char(s1[0]-32) << char(s2[0]-32) << char(s3[0]-32) << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int a[10001]={0};
int main(){
	for(int i=0;i<10001;i++){
		int d=0,ii=i;
		while(ii>0){
			d+=ii%10;
			ii/=10;
		}
		a[i]=d;
	}
	int n,aa,b;
	while(cin >> n >> aa >> b){
		int ans=0;
		for(int i=0;i<=n;i++){
			if(a[i]>=aa&&a[i]<=b){
				ans+=i;
			}
		}
		cout << ans << "\n";
	}
} 

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 1e5 + 5;
int n , k;
int arr[N];
int main(){
    scanf("%d %d" , &n , &k);
    for(int i = 1 ; i <= n ; ++i){
        scanf("%d" , arr + i);
    }
    for(int i = 1 ; i < n ; ++i){
        if(arr[i] + arr[i + 1] >= k){
            printf("Possible\n");
            for(int j = 1 ; j < i ; ++j){
                printf("%d\n" , j);
            }
            for(int j = n - 1 ; j >= i + 1 ; --j){
                printf("%d\n" , j);
            }
            printf("%d\n" , i);
            return 0;
        }
    }
    printf("Impossible\n");
}


Measured memory_bytes: 1152
import java.util.*;
import java.lang.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int[] numP = new int[N+1];
		int[] numQ = new int[N+1];
		int ans1 = 0,ans2 = 0;
		int[] ff = new int[]{0,1,2,6,24,120,720,5040};
		for( int i=N; i>=1; i-- ){
			numP[i] = sc.nextInt();
		}
		for( int i=N; i>=1; i-- ){
			numQ[i] = sc.nextInt();
		}
		for( int i=N; i>=1; i-- ){
			int count1 = 0,count2 = 0;
			for( int j=N; j>=i; j-- ){
				if( numP[i] > numP[j] ){
					count1++;
				}
				if( numQ[i] > numQ[j] ){
					count2++;
				}
			}
			ans1 += (numP[i]-1-count1)*ff[i-1];
			ans2 += (numQ[i]-1-count2)*ff[i-1];
		}
		System.out.println(Math.abs(ans1-ans2));
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int a,b,k;
    cin >> a >> b >> k;
    vector<int>yakusu;
    
    for(int i=1; i<= min(a,b); i++){
        if(a%i == 0 && b%i == 0) yakusu.push_back(i);
    }
    cout << yakusu.at(yakusu.size()-k) << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,i,j,z=0,o=0,c,k,f,f1,d,c2=0;
	char a[101],b[101][101];
		scanf("%d",&n);
		scanf("%s",a);
		z=strlen(a);
		for(i=0;i<n;i++){
			scanf("%s",b[i]);
		}
		for(i=0;i<n;i++){
			f=0;
			o=strlen(b[i]);
			for(j=0;j<o;j++){
				for(k=1;k<o;k++){
					f1=1; c=0;
					for(d=j;c<z;d+=k){
						if(d>o){
							f1=0;
							break;
						}
						if(a[c]!=b[i][d]){
							f1=0;
							break;
						}	
					c++;	
					}
					if(f1==1){
						f=1;
						j=1000;
						k=1000;
						break;
					}					
				}	
			}
			if(f==1){
				c2++;
			}
		}
	printf("%d\n",c2);
	return 0;
}

Measured memory_bytes: 620
using System;
class c
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        var b = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            int bust = Math.Min(a[i], b[i]);
            ans += bust;
            b[i] -= bust;
            bust = Math.Min(a[i + 1], b[i]);
            ans += bust;
            a[i + 1] -= bust;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 35020
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;

    int ans = a + b + c + max({a, b, c}) * 9;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
result = 10000000
for a in 1..(n-1) do
    aa = 0
    b = n - a
    a.to_s.each_char { |s| aa += s.to_i }
    b.to_s.each_char { |s| aa += s.to_i }
    result = aa if aa < result 
end
print result

Measured memory_bytes: 1788
class Factorial():
    def __init__(self, mod=10**9 + 7):
        self.mod = mod
        self._factorial = [1]
        self._size = 1
        self._factorial_inv = [1]
        self._size_inv = 1

    def __call__(self, n):
        return self.fact(n)

    def fact(self, n):
        ''' n! % mod '''
        if n >= self.mod:
            return 0
        self._make(n)
        return self._factorial[n]

    def fact_inv(self, n):
        ''' n!^-1 % mod '''
        if n >= self.mod:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        self._make_inv(n)
        return self._factorial_inv[n]

    def comb(self, n, r):
        ''' nCr % mod '''
        if r > n:
            return 0
        t = self.fact_inv(n-r)*self.fact_inv(r) % self.mod
        return self(n)*t % self.mod

    def comb_with_repetition(self, n, r):
        ''' nHr % mod '''
        t = self.fact_inv(n-1)*self.fact_inv(r) % self.mod
        return self(n+r-1)*t % self.mod

    def perm(self, n, r):
        ''' nPr % mod '''
        if r > n:
            return 0
        return self(n)*self.fact_inv(n-r) % self.mod

    @staticmethod
    def xgcd(a, b):
        '''
        Return (gcd(a, b), x, y) such that a*x + b*y = gcd(a, b)
        '''
        x0, x1, y0, y1 = 0, 1, 1, 0
        while a != 0:
            (q, a), b = divmod(b, a), a
            y0, y1 = y1, y0 - q * y1
            x0, x1 = x1, x0 - q * x1
        return b, x0, y0

    def modinv(self, n):
        g, x, _ = self.xgcd(n, self.mod)
        if g != 1:
            raise ValueError('Modinv is not exist! arg={}'.format(n))
        return x % self.mod

    def _make(self, n):
        if n >= self.mod:
            n = self.mod
        if self._size < n+1:
            for i in range(self._size, n+1):
                self._factorial.append(self._factorial[i-1]*i % self.mod)
            self._size = n+1

    def _make_inv(self, n):
        if n >= self.mod:
            n = self.mod
        self._make(n)
        if self._size_inv < n+1:
            for i in range(self._size_inv, n+1):
                self._factorial_inv.append(self.modinv(self._factorial[i]))
            self._size_inv = n+1


n, m, k = map(int, input().split())
mod = 998244353
comb = Factorial(mod).comb
s = 0
for i in range(k+1, n):
    t = comb(n-1, i)*m % mod
    t = t*pow(m-1, n-1-i, mod) % mod
    s = (s+t) % mod
ans = (pow(m, n, mod)-s) % mod
print(ans)


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

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


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

void solve_test() {
	string s;
	cin >> s;
	int n = s.length();
	if (s[n - 1] == 's')
		cout << s << "es" << '\n';
	else
		cout << s << "s" << '\n';
}

int main() {
	int T;
	T = 1;
	for (int t = 1; t <= T; t++)
		solve_test();

	return 0;
}


Measured memory_bytes: 3628
S = input()
T = input()
Q = int(input())
qs = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(Q)]

smem = [0]
for c in S:
    if c == 'A':
        smem.append(smem[-1] + 1)
    else:
        smem.append(smem[-1] - 1)

tmem = [0]
for c in T:
    if c == 'A':
        tmem.append(tmem[-1] + 1)
    else:
        tmem.append(tmem[-1] - 1)

anss = []
for s1,s2,t1,t2 in qs:
    a = smem[s2+1] - smem[s1]
    b = tmem[t2+1] - tmem[t1]
    if a%3 == b%3:
        anss.append('YES')
    else:
        anss.append('NO')
print(*anss, sep='\n')

Measured memory_bytes: 35780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << (x) << endl

class bipartite_matching {
public:
    int n;
    std::vector<std::vector<int>> g;
    std::vector<int> match;

    bipartite_matching(int n_) : n(n_), g(n_), match(n_), used(n_) {}

    void add_edge(int u, int v) {
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int maximum_matching(void) {
        int res = 0;
        fill(begin(match), end(match), -1);
        for (int v = 0; v < n; ++v) {
            if (match[v] == -1) {
                fill(begin(used), end(used), false);
                if (dfs(v)) res++;
            }
        }
        return res;
    }

private:
    std::vector<int> used;
    bool dfs(int v) {
        used[v] = true;
        for (int u : g[v]) {
            int w = match[u];
            if (w == -1 || (!used[w] && dfs(w))) {
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
};


int main () {
    int n;

    while (cin >> n) {

        bipartite_matching bm(n + n);
        
        using P = pair<int, int>;
        // 二部マッチング!
        vector<P> as(n), bs(n);
        rep(i, n) cin >> as[i].first >> as[i].second;
        rep(i, n) cin >> bs[i].first >> bs[i].second;

        rep(i, n) rep(j, n) {
            if (as[i].first < bs[j].first && as[i].second < bs[j].second) {
                bm.add_edge(i, j + n);
            }
        }

        cout << bm.maximum_matching() << endl;
    }
}


Measured memory_bytes: 256
H ,W =map(int,input().split())
L = []
tmp = ['.' for x in range(W+2)]
L.append(tmp)
for _ in range(H):
    l =  list('.'+input()+'.')
    L.append(l)
L.append(tmp)
flag = 0
for x in range(1,H+1):
    for y in range(1,W+1):
        if L[x-1][y] == L[x][y-1] == L[x+1][y] == L[x][y+1] =='.' and L[x][y] == '#':
            flag = 1

if flag == 0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, ma, mi;
int A[100001]; 

inline bool solve() {
    if(ma - mi > 1) return false;
    if(ma == mi) {
        return (mi == N - 1) || 2 * mi <= N;
    }
    int cnt = 0;
    REP(i, N) cnt += (A[i] == mi);
    return cnt < ma && 2 * (ma - cnt) <= (N - cnt);
}

int main() {
    fastio();
    cin >> N;
    ma = 0, mi = N;
    REP(i, N) {
        cin >> A[i];
        mi = min(mi, A[i]);
        ma = max(ma, A[i]);
    }
    cout << (solve()? "Yes" : "No") << "\n";
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#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 all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define X real()
#define Y imag()
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
typedef pair<int,int> Pi;
D eps=1e-9;
bool eq(D a,D b){return abs(a-b)<eps;}
int sig(D x){return eq(x,0)?0:(x>0?1:-1);}
D dot(P a,P b){return real(conj(a)*b);}
D cro(P a,P b){return imag(conj(a)*b);}
int ccw(P a,P b,P c){
	if(sig(cro(b-a,c-a))==1) return 1;
	if(sig(cro(b-a,c-a))==-1) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	if(eq(abs(a-b)+abs(c-b),abs(a-c))) return -2;
	return 2;
}
bool ispal(L a,L b){
	return sig(cro(a.fs-a.sc,b.fs-b.sc))==0;
}
bool iLSex(L l,L s){
	return sig(cro(l.sc-l.fs,s.fs-l.fs)*cro(l.sc-l.fs,s.sc-l.fs))<0;
}
P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
int len(vector<Pi> vc){
	int N=vc.size();
	if(N==0) return 0;
	sort(all(vc));
	int ret=0;
	int l=vc[0].fs,r=vc[0].sc;
	rep(i,N){
		if(r<vc[i].fs){
			ret+=r-l;
			l=vc[i].fs;
			r=vc[i].sc;
		}else{
			chmax(r,vc[i].sc);
		}
	}
	ret+=r-l;
	return ret;
}
int N;
vector<Pi> segs[4001];
Pol pol; 
vector<D> enumxs(Pol pol,D y){
	L l=L(P(0,y),P(1,y));
	vector<D> ds;
	int N=pol.size();
	rep(i,N){
		L s=L(pol[i],(pol[(i+1)%N]));
		if(!ispal(l,s)&&iLSex(l,s)) ds.pb(intLL(l,s).X);
	}
	sort(all(ds));
	return ds;
}
int main(){
	while(true){
		cin>>N;
		if(N==0) break;
		pol.clear();
		rep(i,N){
			int x,y;
			cin>>x>>y;
			pol.pb(P(x,y));
		}
		int ans=0;
		for(int y=-2000;y<2000;y++){
			vector<D> a=enumxs(pol,y+eps*100);
			vector<D> b=enumxs(pol,y+1-eps*100);
			assert(a.size()==b.size());
			int K=a.size();
			assert(K%2==0);
			vector<Pi> segs;
			rep(i,K/2){
				int le=floor(min(a[i*2],b[i*2])+eps),ri=ceil(max(a[i*2+1],b[i*2+1])-eps);
				segs.pb(Pi(le,ri));
			}
			ans+=len(segs);
/*			if(segs.size()){
				show(y);
				for(Pi p:segs) printf("(%d,%d)  ",p.fs,p.sc);
				puts("");
			}*/
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iterator>
#include <math.h>
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#include <algorithm>
#include <cmath>
using namespace std;
pair<ll,ll> norm(ll a,ll b)
{
  if(a<0)
  {
    a*=-1;
    b*=-1;
  }
  else if ((a==0)&&(b<0))
  {
    b*=-1;
  }
  ll d=__gcd(abs(a),abs(b));
  a=(ll)(a/d);
  b=(ll)(b/d);
  pair <ll,ll> p=mp(a,b);
  return p;
}
bool decreasing(pair<ll,ll> a,pair<ll,ll> b) 
{ 
       if(a.first>b.first)
       return true;
       else if(a.first==b.first)
       {
        if(a.second<b.second)
        return false;
        else
        return true;
       } 
       else
       return false;
} 
ll expo(ll x,ll y) 
{ 
    ll res = 1;  
    while(y>0) 
    {  
        if(y&1) 
        res=(res*x)%1000000007;  
        y=y>>1;
        x=(x*x)%1000000007; 
    } 
    return res; 
}
int main()
{
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // int T,p;
    // cin>>T;
    // for(p=1;p<=T;p++)
    // {
      ll N;
      cin>>N;
      if(N==0)
      cout<<"1";
      else
      cout<<"0";
      return 0;
  }

Measured memory_bytes: 3592
#逆元

from fractions import gcd

n=int(input())

a=list(map(int,input().split()))
mod=10**9+7

b=0
for i in a:
    b+=pow(i,mod-2,mod)


L=a[0]
def lcm(x,y):
    return x//gcd(x,y)*y

for i in a:
    L=lcm(L,i)


print(L*b%mod)


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


using namespace std;


using ll = long long;


int main(void) {
    ll N, K;
    cin >> N >> K;
    vector<ll> teleport(N + 1);
    for (ll i = 1; i <= N; i++) {
        cin >> teleport[i];
    }

    ll now = 1;
    ll step = 1;
    ll loop_begin = 0;
    ll loop_len = 0;
    vector<ll> visited(N + 1, -1);

    visited[1] = 0;
    while (K-- > 0) {
        now = teleport[now];
        if (visited[now] > 0) {
            loop_begin = now;
            loop_len = step - visited[now];
            break;
        }
        visited[now] = step++;
    }

    if (loop_begin == 0) {
        cout << now << endl;
        return 0;
    }

    ll r = K % loop_len;
    while (r-- > 0) {
        now = teleport[now];
    }
    cout << now << endl;
}


Measured memory_bytes: 6400
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn=200000+10;
const int maxm=100000+10;
const int mod=(int)1e9+7;
const int INF=0x3f3f3f3f;
const ll LINF=(1LL<<62);
const double eps=1e-8;
const double PI=acos(-1.0);
#define mst(a,b) memset(a,b,sizeof(a))
#define rep(i,a,b) for (int i=(a);i<b;i++)
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define lowbit(x) x&(-x)
#define X first
#define Y second
int a[maxn],cnt[maxn];
int tot;
vector<int> b;
int main(){
#ifdef local
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif
    //ios::sync_with_stdio(false); cin.tie(0);
    int n,k; scanf("%d%d",&n,&k);
    for (int i=0;i<n;i++) {
        scanf("%d",&a[i]);
        if (!cnt[a[i]]) {
            tot++;
        }
        cnt[a[i]]++;
    }
    for (int i=1;i<=n;i++){
        if (cnt[i]){
            b.push_back(cnt[i]);
        }
    }
    sort(ALL(b));
    int ans=0;
    for (int i=0;i<b.size();i++){
        if (tot<=k) break;
        ans+=b[i];
        tot--;
    }
    printf("%d\n",ans);
    return 0;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

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

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

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

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

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

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

// 降順ソート vector<int> v;
// sort(v.begin(),v.end(),greater<int>());

signed main() {
  
  int maxNum = 100000;
  char isNotPrime[maxNum+1] = {};
  isNotPrime[0]=isNotPrime[1]=1;
  for(int i=2;i<maxNum;i++){
    if(isNotPrime[i]==1) continue;
    int num = i+i;
    while(num<=maxNum){
      isNotPrime[num]=1;
      num += i;
    }
  }

  int count2017like[maxNum+1] = {};
  int count = 0;
  for(int i=0;i<=maxNum;i++){
    if(isNotPrime[i]==0 && isNotPrime[(i+1)/2]==0){
      count++;
    }
    count2017like[i] = count;
  }
  
  int q;
  cin >> q;
  
  int l,r;
  for(int i=0;i<q;i++){
    cin >> l >> r;
    cout << count2017like[r]-count2017like[l-1] << endl;
  }
  
  return 0;
}



Measured memory_bytes: 4156
def gcd(a, b):
    while b > 0:
        tmp = a
        a = b
        b = tmp % b
    return a


def lcm(a, b):
    tmp = gcd(a, b)
    return (a//tmp) * b


n = int(input())
t = [0 for i in range(n)]
for i in range(n):
    t[i] = int(input())
t = sorted(t)
_sum = t[0]
for i in range(1, n):
    # print("sum:{} t:{} lcm:{}".format(sum, t, lcm(sum, t)))
    _sum = lcm(_sum, t[i])
    # print(sum)
print(_sum)


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

const ll MAX = 1000000;
const ll MOD = 1000000007;

ll fac[MAX];

// テーブルを作る前処理
/*
void COMinit() {
    fac[0] = fac[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
    }
}
*/

ll pow_kai(ll a,ll n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a%MOD;
    }
    a = a*a%MOD;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll tmp=1;
    for(ll i=n;i>=n-k+1;i--) tmp = (tmp*i)%MOD;

    return (tmp * pow_kai(fac[k],MOD-2)) % MOD;
}

void chmax(ll &a,const ll &b){
    if(a<b) a=b;
}
void chmin(ll &a,const ll &b){
    if(a>b) a=b;
}


int main()
{

    ll N;
    cin >>N;

    ll A[N],dp[N][N];

    rep(i,N){
        cin >> A[i];
        dp[i][i]=A[i];
    }

    for(ll h=1;h<=N-1;h++){
        rep(i,N-h){
            dp[i][i+h]=max(A[i+h]-dp[i][i+h-1],A[i]-dp[i+1][i+h]);
        }

    }

    cout << dp[0][N-1] << endl;



    return 0;


}

Measured memory_bytes: 49768
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int mod=998244353;
const int N=1e6+5;
int n,ma,Ans,a[N],ans[N],inv[N];
vector<int>g[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		g[a[i]].push_back(a[i]);
		ma=max(ma,a[i]);
	}
	inv[0]=inv[1]=1;
	for(int i=2;i<=ma;i++)inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<=ma;i++)
	{
		int sum=0;
		for(int j=i;j<=ma;j+=i)
			for(int k=0;k<g[j].size();k++)
				sum=(sum+g[j][k]);
		for(int j=i;j<=ma;j+=i)
			for(int k=0;k<g[j].size();k++)
				ans[i]=(ans[i]+g[j][k]*(sum-g[j][k]+mod)%mod)%mod;
		ans[i]=ans[i]*inv[2]%mod;
//		if(i==2)cout<<"###"<<sum<<endl;
	}
	for(int i=ma;i;i--)
		for(int j=i+i;j<=ma;j=j+i)
			ans[i]=(ans[i]-ans[j]+mod)%mod;
	for(int i=1;i<=ma;i++)
	{
		if(ans[i]==0)continue;
		ans[i]=ans[i]*inv[i]%mod;
		Ans=(Ans+ans[i])%mod;
//		cout<<ans[i]<<endl;
	}
	cout<<Ans;
}

Measured memory_bytes: 46848
#include <stdio.h>
#include <string.h>

int main(void){
    char s[11], t[12];

//入力
    scanf("%s %s", s, t);

    int len = strlen(s);

    for(int i=0 ; i < len ; i++){
        if(s[i] != t[i] || t[i+1] == '\0'){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");

    return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int array[4] = {0};
	//P=0,W=1,G=2,Y=3;
	while (n--)
	{
		char a;
		scanf("%c ",&a);
		if (a=='P')
			array[0]++;
		if (a=='W')
			array[1]++;
		if (a=='G')
			array[2]++;
		if (a=='Y')
			array[3]++;

	}
	int count=0;
	for (int i=0;i<4;i++)
	{
		if (array[i]!=0)
			count++;
	}
	if (count==3)
		cout << "Three";
	else cout << "Four";

	return 0;
}


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


void solve(long long N, long long M){
    long long ans = 0;
    if(N>1){
        ans += (N*(N-1))/2;
    }
    if(M>1){
        ans += (M*(M-1))/2;
    }
    cout << ans << endl;

}

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


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(true) {
        int M, N;
        cin >> M >> N;
        if(!M && !N) break;
        vector<int> books(N);
        for(int i = 0; i < N; ++i) {
            cin >> books[i];
        }
        int left = 0, right = 1500000;
        while(left < right) {
            int len = (left+right)>>1;
            bool ok = true;
            int pos = 1, acc = 0;
            for(int i = 0; i < N; ++i) {
                if(len < books[i]) {
                    ok = false;
                    break;
                }
                int nacc = acc + books[i];
                if(nacc > len) {
                    ++pos;
                    acc = books[i];
                } else {
                    acc = nacc;
                }
                if(pos > M) {
                    ok = false;
                    break;
                }
            }
            if(ok) right = len;
            else left = len+1;
        }
        cout << left << endl;
    }
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

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

	int c = 0;

	if (n >= 3) {	

		for (int i = 0; i < n-2; i++) {
			for (int j = i+1; j < n-1; j++) {
				if (a[i] == a[j])
					continue;

				for (int k = j+1; k < n; k++) {
					if (a[k] == a[j] || a[k] == a[i])
						continue;

					if (a[i]+a[j] > a[k] && a[i]+a[k] > a[j] && a[j]+a[k] > a[i])
						c++;
				}
			}
		}
	}


	cout << c;

	return 0;
}

Measured memory_bytes: 3632
//satyaki3794
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define MOD (99991LL)
#define LEFT(n) (2*(n))
#define RIGHT(n) (2*(n)+1)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef pair<ii, ii> i4;



vector<int> calc(int n, ll rem){
    if(rem == 1)  return vector<int> (0);
    if(rem % 2 == 0){
        vector<int> ans = calc(n-1, rem/2);
        ans.pb(n);
        return ans;
    }
    vector<int> ans = calc(n-1, rem-1);
    ans.insert(ans.begin(), n);
    return ans;
}
 
 
int main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll rem;
    cin>>rem;

    vector<int> ans = calc(100, rem+1);
    int lo = 100 - (int)ans.size() + 1;

    cout<<2*(int)ans.size()<<endl;
    for(auto it : ans)
        cout<<it<<" ";
    for(int i=lo;i<=100;i++)
        cout<<i<<" ";
     
    return 0;
}
 









Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {

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

	private void run() throws NumberFormatException, IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		Node[] nodes = new Node[n];
		for (int i = 0; i < n; i++) {
			nodes[i] = new Node();
		}
		for (int i = 0; i < n; i++) {
			int v = scanner.nextInt();
			int l = scanner.nextInt();
			int r = scanner.nextInt();
			nodes[v].l = l;
			nodes[v].r = r;
			if (l != -1)
				nodes[l].p = v;
			if (r != -1)
				nodes[r].p = v;
		}

		int root = 0;
		for (int i = 0; i < n; i++) {
			if (nodes[i].p == -1) {
				root = i;
			}
		}
		System.out.println("Preorder");
		preParse(root, nodes);
		System.out.println();
		System.out.println("Inorder");
		inParse(root, nodes);
		System.out.println();
		System.out.println("Postorder");
		postParse(root, nodes);
		System.out.println();
	}

	private void postParse(int u, Node[] nodes) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(u);
		boolean[] b = new boolean[nodes.length];
		while (!deque.isEmpty()) {
			u = deque.peek();
			int l = nodes[u].l;
			if (l != -1 && !b[l]) {
				deque.push(l);
				continue;
			}
			int r = nodes[u].r;
			if (r != -1 && !b[r]) {
				deque.push(r);
				continue;
			}
			deque.poll();
			b[u] = true;
			System.out.print(" " + u);
		}

	}

	private void inParse(int u, Node[] nodes) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(u);
		boolean[] b = new boolean[nodes.length];
		while (!deque.isEmpty()) {
			u = deque.peek();
			int l = nodes[u].l;
			if (l != -1 && !b[l]) {
				deque.push(l);
				continue;
			}
			deque.poll();
			b[u] = true;
			System.out.print(" " + u);
			int r = nodes[u].r;
			if (r != -1 && !b[r]) {
				deque.push(r);
			}

		}
	}

	private void preParse(int u, Node[] nodes) {
		Deque<Integer> deque = new ArrayDeque<Integer>();
		deque.push(u);
		while (!deque.isEmpty()) {
			u = deque.poll();
			System.out.print(" " + u);
			if (nodes[u].r != -1)
				deque.push(nodes[u].r);
			if (nodes[u].l != -1)
				deque.push(nodes[u].l);
		}

	}

	class Node {
		int p = -1, l, r;
	}
}

Measured memory_bytes: 18264