akhauriyash/Code-Regression huggingface dataset:
//2019.7.14 by ljz
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define LL long long
#define inf 0x3f3f3f3f
#define INF 0x3f3f3f3f3f3f3f
#define eps 5.6e-8
#define RG register
#define db double
#define lb long db
#define pc(x) __builtin_popcount(x)
typedef pair<int,int> Pair;
#define mp make_pair
#define fi first
#define se second
#define pi acos(-1.0)
#define pb push_back
#define gc getchar
//inline char gc() {
//    static char buf[100000],*p1,*p2;
//    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
//}
inline int read() {
    res s=0,ch=gc();
    while(ch<'0'||ch>'9')ch=gc();
    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
    return s;
}
//inline int read() {
//    res s=0,ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc();
//    while(ch<'0'||ch>'9')ch=gc();
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s;
//}
//inline LL Read() {
//    RG LL s=0;
//    res ch=gc(),w=1;
//    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=gc();}
//    while(ch>='0'&&ch<='9')s=s*10+ch-'0',ch=gc();
//    return s*w;
//}
inline void swap(res &x,res &y) {
    x^=y^=x^=y;
}
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
namespace MAIN{
    int n;
    int a[100000+10];
    inline void MAIN(){
        n=read();
        res sum=0;
        for(res i=1;i<=n;i++)a[i]=read(),sum^=a[i];
        puts(sum==0?"Yes":"No");
    }
}
int main() {
//    srand((unsigned)time(NULL));
//    freopen("zao.in","r",stdin);
//    freopen("std.out","w",stdout);
    MAIN::MAIN();
    return 0;
}

Measured memory_bytes: 640
// in the name if Allah
// YA Ali!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll INF = 1<<30 ;
const ll N= 1e6 ;
#define f first
#define s second
#pragma GCC optimize("O1")
#pragma GCC optimize("O2")
#pragma GCC optimize("O3")
#pragma GCC optimize("O4")
#pragma GCC optimize("O5")
#pragma GCC optimize("O6")
#pragma GCC optimize("O7")
#pragma GCC optimize("O8")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
ll n , d;
vector<pair<ll,ll> > v ;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n ;
for(int i = 0 ; i < n ; i ++){
    ll x ;
    cin >> x ;
    v.push_back({x,i}) ;
}
sort(v.begin() , v.end()) ;
ll xx = v[n-1].s , va = v[n-2].f , maxx = v[n-1].f;
for(int i = 0 ; i < n ; i++){
    if(i==xx)cout << va << endl ;
    else cout << maxx << endl ;
}
    return 0;
}
 /*
              _     _   __
        /_\  (_    (_)  __)
       /   \  _) . (_) (__
 */


Measured memory_bytes: 5744
#include <bits/stdc++.h>
#define F first
#define S second
#define ll long long
#define ld long double
#define pb push_back
#define sz size

/*
author: Basel
*/

using namespace std;

const int N=1e5+5;

string s;

string f(string x)
{
    int n = x.length();
    int a[n+1][n+1];
    memset(a, 0, sizeof(a));
    string ret;
    int ret_length  = 0;
    int i, in = 0;
    for (i=1; i<=n; i++)
    {
        for (int j=i+1; j<=n; j++)
        {
            if (x[i-1] == x[j-1] &&
                a[i-1][j-1] < (j - i))
            {
                a[i][j] = a[i-1][j-1] + 1;
                if (a[i][j] > ret_length)
                {
                    ret_length = a[i][j];
                    in = max(i, in);
                }
            }
            else
                a[i][j] = 0;
        }
    }
    if (ret_length > 0)
        for (i = in - ret_length + 1; i <= in; i++)
            ret.push_back(x[i-1]);
    return ret;
}

int main()
{
    int n;
    cin >> n >> s;
    cout << f(s).length() << endl;
    return 0;
}


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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod = 1e9+7;

int n,m;
int main(){
	cin >> n >> m;
	vector<ll>a(n);
	priority_queue<ll> queue;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		queue.push(a[i]);
	}
	while(m > 0){
		ll tmp = queue.top(); queue.pop();
		tmp /= 2;
		queue.push(tmp);
		m--;
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += queue.top();
		queue.pop();
	}
	cout << ans << endl;
}

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

long long n,l,r,low,high,m;
int main() {
    // insert code here...
    cin>>n>>m;
    for (int i=0; i<m; i++) {
        cin>>l>>r;
        if (i==0) {
            high=r;
            low=l;
            continue;
        }
        low=max(low,l);
        high=min(high,r);
    }
    high=min(high,n);
    int k=(high-low)+1;
    if(k<0)cout<<0<<endl;
    else cout<<k<<endl;
    
}


Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))
ans = []
for i in range(H):
    ans.append([0] * W)
# print(ans)
now = 0
cnt = 0
for i in range(H):
    if i % 2 == 0:
        for j in range(W):
            ans[i][j] = now + 1
            cnt += 1
            if cnt == A[now]:
                now += 1
                cnt = 0
    else:
        for j in range(W - 1, -1, -1):
            ans[i][j] = now + 1
            cnt += 1
            if cnt == A[now]:
                now += 1
                cnt = 0
for row in ans:
    print(*row, sep=' ')


Measured memory_bytes: 9388
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x=0;
  	cin>>a>>b>>c;
  	if(a==b)
    {
      	if(a==c)
          x=1;
      	else 
          x=2;
    }
    else if(a==c)
    {
      if(a==b)
          x=1;
      	else 
          x=2;
    }
  	else if(b==c)
    {
      if(a==c)
          x=1;
      	else 
          x=2;
    }
    if(x==2)
      cout<<"Yes";
  	else 
      cout<<"No";
  	return 0;
}

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

using namespace std;

struct Puzzle {
    int x;
    string s;
};

map<string, int> hash;
int dx[] = {-1, 1, -4, 4};

void solve() {

    queue<Puzzle> q;
    string start = "01234567";

    hash[start] = 0;
    q.push((Puzzle){0, start});

    while(!q.empty()) {

        Puzzle now = q.front(); q.pop();

        for(int i = 0; i < 4; ++i) {
            if(now.x + dx[i] >= 0 && now.x + dx[i] < 8 && !(i == 0 && now.x == 4) && !(i == 1 && now.x == 3)) {
                Puzzle next = now;
                next.x += dx[i];
                swap(next.s[now.x], next.s[next.x]);

                if(hash.count(next.s) == 0) {
                    hash[next.s] = hash[now.s] + 1;
                    q.push(next);
                }
            }
        }

    }

}

int main() {

    solve();

    while(1) {

        char num;
        string puzzle = "";

        for(int i = 0; i < 8; ++i) {
            if(!(cin >> num)) return 0;
            puzzle += num;
        }

        cout << hash[puzzle] << endl;

    }

}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
#pragma target("unroll-loops")
#pragma target("avx")

using namespace std;

using i64 = long;
using ll = long;

signed main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; ++i){
        int j = n - i;
        if(i < j)
            ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n,m = map(int,input().split())

p = list(map(int,input().split()))

p = [0]+p
pairs = []

for i in range(m):
    pairs.append(tuple(map(int,input().split())))


U = [0]*(n+1)
for i in range(n+1):
    U[i] = i
def find(x):
    global U
    k = x
    while U[k]!=k:
        k = U[k]
    U[x] = k
    return k

def union(x,y):
    global U
    a = find(x)
    b = find(y)
    if a != b:
        U[b] = a
for x,y in pairs:
    union(x,y)
res = 0
for i in range(1,n+1):
    if find(p[i]) == find(i):
        res += 1

print(res)



Measured memory_bytes: 24992
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main(){
 int N,M,L,R,A[100001]={},ma=0;
 cin >> N >> M;
 for(int i=0; i<M; i++){
     cin >> L >> R;
     A[L]++;
     A[R+1]--;
     ma=max(ma,R);
 }
 for(int i=1; i<=ma; i++) A[i]+=A[i-1];
 int ans=0;
 for(int i=0; i<=ma; i++){
     if(A[i]==M) ans+=1;
 }
 cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

#define LNE_MAX 101

int main(){
  
  int len;	// 文字数
  int i, j;	// ループ変数
  char a[LNE_MAX] = {};	// 文字列格納
  char b[LNE_MAX] = {};	// 文字列格納
  char c[LNE_MAX] = {};	// 文字列格納
  int cnt;	    // 文字不一致の回数
  int sum = 0;  // 操作回数の合計
  
  // 入力の読み込み
  scanf("%d", &len);
  for(i=0 ; i<=len ; i++){
    scanf("%c", &a[i]);
    //printf("%c", a[i]);
  }
  for(i=0 ; i<=len ; i++){
    scanf("%c", &b[i]);
    //printf("%c", b[i]);
  }
  for(i=0 ; i<=len ; i++){
    scanf("%c", &c[i]);
    //printf("%c", c[i]);
  }  

  //printf("\n");
  
  for(i=0 ; i<=len ; i++){
    
    cnt = 0;
    if(a[i] != b[i]){
      cnt++; 
    }
    if(b[i] != c[i]){
      cnt++; 
    }
    if(c[i] != a[i]){
      cnt++; 
    }
    //printf("%c %c %c/n", a[i], b[i], c[i]);
	//printf("%d\n", cnt);    
    
	switch(cnt){
      case 0:
        break;
      case 2:
        sum+=1;
        break;
      case 3:
        sum+=2;
        break;
    }
  }
  
  printf("%d", sum);
  
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
int arr1[n];
for(int i=0;i<n;i++)
    cin>>arr1[i];
    map<int,int> mp;
    map<int,int> dp;
for(int i=0;i<n;i++)
{
    if(i%2==0)
    {
        mp[arr1[i]]+=1;
    }
    else
        dp[arr1[i]]+=1;
}
int sum=0;

vector<pair<int,int> > arr;
vector<pair<int,int> > brr;
for(auto  a:mp)
{
  arr.pb({a.ss,a.ff});
    sum+=a.ss;
}
int ans=0;

int sum1=0;

for(auto  a:dp)
{
   brr.pb({a.ss,a.ff});
    sum1+=a.ss;
}
sort(arr.begin(),arr.end());
sort(brr.begin(),brr.end());
if(arr[arr.size()-1].ss==brr[brr.size()-1].ss)
{
    if(arr.size()==1&&brr.size()==1)
    {
       ans= min(arr[arr.size()-1].ff,brr[brr.size()-1].ff);
    }
    else if(arr.size()==1&&brr.size()>1)
    {
        ans=sum1+sum-arr[arr.size()-1].ff-brr[brr.size()-2].ff;
    }
    else if(arr.size()>1&&brr.size()==1)
    {
        ans=sum1+sum-arr[arr.size()-2].ff-brr[brr.size()-1].ff;
    }
    else
        ans=sum1+sum-max(arr[arr.size()-2].ff+brr[brr.size()-1].ff,arr[arr.size()-1].ff+brr[brr.size()-2].ff);
}
else
{
    ans=sum+sum1-arr[arr.size()-1].ff-brr[brr.size()-1].ff;
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 9592
n=int(input())
e=[[] for i in range(n)]
for i in range(n-1):
  inp=list(map(int,input().split()))
  e[inp[0]-1].append((inp[1]-1,i))
  e[inp[1]-1].append((inp[0]-1,i))

col=[0 for i in range(n-1)]
fl=[0 for i in range(n)]
s=[[0,0]]
mc=0
while len(s):
  ns=[]
  for i in s:
    fl[i[0]]=1
    cc=1
    for j in e[i[0]]:
      if not(fl[j[0]]):
        if cc==i[1]:
          cc+=1
        col[j[1]]=cc
        mc=max(mc,cc)
        ns.append([j[0],cc])
        cc+=1
  s=ns

print(mc)
for i in col:
  print(i)
        

Measured memory_bytes: 45140
/*Ankon Ghosh
  KUET,ECE 2K16*/
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
///#include <ext/pb_ds/detail/standard_policies.hpp>*/
///using namespace __gnu_pbds;
using namespace std;
using ll=long long;
#define inf 1e16
#define MAX 100005
#define mod 998244353
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define Case(i) printf("Case %lld: ",i)
#define setpre(number) cout<<fixed<<setprecision(10)<<number<<endl
#define pf(a) printf("%lld ",a)
#define pff(a,b) printf("%lld %lld\n",a,b)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define LOOP(x,y) for(ll i=x;i<=y;i++)
#define RFOR(i,n) for(ll i=n-1;i>=0;i--)
#define RFOR1(i,n) for(ll i=n;i>0;i--)
#define RLOOP(x,y) for(ll i=y;i>=x;i--)
#define m_p make_pair
#define ff first
#define ss second
#define p_b push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL)
#define output freopen("output.txt","w",stdout)
map<ll,ll>mp1,mp;
vector<pair<ll,pair<ll,ll> > >vpp1;
vector<pair<ll,ll> >vpp,vp1;
vector<ll>v,v1,v2,fin;
map<pair<ll,ll>,bool>mbb;
map<ll,bool>mb,mb1;
ll a,b,c,n,d,e,f,ta,sum=0,cnt=0,m,l,req,sz,maxi,k;
priority_queue<ll>pq;

int main()
{
    fast;
    cin>>n;
    v.clear();
    FOR(i,n)
    {
        cin>>a;
        v.p_b(a);
    }
    ll now=0,ans=0;
    for(ll i=0;i<n;i++)
    {
        if(v[i]>now)
        {
            ans+=(v[i]-now);
            now=v[i];
        }
        else
        {
            now=v[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3628
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int A,B,C;
inline void solve(){
  IN3(A,B,C);
  OUT(A<=C&&C<=B?"Yes":"No");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
int main()
{
  int n,x,t; cin >> n >> x >> t;
  cout << (n + x - 1) / x * t << "\n";
  return 0;
}


Measured memory_bytes: 3620
/**
 *	@file: A.cpp
 *	@author: Huy Le
 *	@created: 07/11/2020 18:52:28
**/


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

#define ll long long

int ts;
int l,r,d;

void solve() {
	cin >> l >> r >> d;
	cout<< (r / d - l / d + (l%d?0:1));
}

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

	//cin >> s;
	//while(ts--) 
		solve();
}


Measured memory_bytes: 3608
//#include <bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int N;
    string S;
    cin >> N >> S;
    if(N%2 != 0){
        cout << "No" << endl;
        return 0;
    }
    //cout << S.substr(0,N/2) << endl;
    //cout << S.substr(N/2,N/2) << endl;
    if( S.substr(0,N/2) == S.substr(N/2,N/2)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 888
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int h, w, n, si, sj;
    string s, t;
    cin >> h >> w >> n >> si >> sj >> s >> t;
    si--;
    sj--;

    int i1 = -1, i2 = h;
    int j1 = -1, j2 = w;
    FORR(i,n-1,0){
        if (t[i] == 'D') {if (i1 != -1) i1--;}
        else if (t[i] == 'U') {if (i2 != h) i2++;}
        else if (t[i] == 'L') {if (j2 != w) j2++;}
        else {if (j1 != -1) j1--;}
        if (s[i] == 'D') i2--;
        else if (s[i] == 'U') i1++;
        else if (s[i] == 'L') j1++;
        else j2--;
        // cout << i1 << " " << i2 << "  " << j1 << " " << j2 << endl;
        if (i2 == i1 + 1 || j2 == j1 + 1){
            cout << "NO" << endl;
            return 0;
        }
    }

    if (si <= i1 || si >= i2 || sj <= j1 || sj >= j2){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }

    return 0;
}


Measured memory_bytes: 776
#include<stdio.h>
#include<cstdlib>
#include<fstream>
#include<iostream>
#include<complex>
#include<math.h>
#include<string>
#include<sstream>

using namespace std;


int main(){
    int N;
    cin>>N;
    int a[N];
    int sum=0,sum2=0;
    for (int  i = 0; i < N; i++){
        cin>>a[i];
        sum+=a[i];
        sum2+=a[i]*a[i];
    }
    int ans=(sum*sum-sum2)/2;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long;
int main(){
ll ans = 0 ,last = 0;
for(ll i = 0; i < 5; i++){
    ll a;
    cin >> a;
    ans += (a + 9) / 10 * 10;
    last = max(last, (1000 - a) % 10);
}
cout << ans - last;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define INFTY 100000000

int min(int a,int b){
        if(a<b) {return a;}
        else return b;
}
int main (){
        int i,j,n,l,k;
        int m[N+1][N+1];
        int p[N+1];
        scanf("%d",&n);
        for (i=1; i<=n; i++) {
                scanf("%d%d",&p[i-1],&p[i]);
        }
        for(i=1; i<=n; i++) {
                m[i][i]=0;
        }
        for(l=2; l<=n; l++) {
                for(i=1; i<=n-l+1;i++) {
                        j=i+l-1;
                        m[i][j]=INFTY;
                                 for(k=i; k<=j-1; k++) {
                                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
                        }
                }

        }
      //  for (i=0; i<=n; i++) {
      //          printf("%d \n",p[i]);
      //   }
        printf("%d\n",m[1][n]);
        return 0;
}

Measured memory_bytes: 636
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

#[allow(dead_code)]
pub fn p<T>(t: T)
where
    T: std::fmt::Display,
{
    println!("{}", t);
}

#[allow(dead_code)]
pub fn input_vector2d<T>(line: usize) -> Vec<Vec<T>>
where
    T: std::str::FromStr,
{
    let mut v: Vec<Vec<T>> = Vec::new();

    for _ in 0..line {
        let vec_line = input_vector();
        v.push(vec_line);
    }
    v
}

#[allow(dead_code)]
pub fn input_vector<T>() -> Vec<T>
where
    T: std::str::FromStr,
{
    let mut v: Vec<T> = Vec::new();

    let s = input_line_str();
    let split_result = s.split(SPLIT_DELIMITER);
    for z in split_result {
        let buf = match z.parse() {
            Ok(r) => r,
            Err(_) => panic!("Parse Error"),
        };
        v.push(buf);
    }
    v
}

#[allow(dead_code)]
pub fn str2vec(s: &str) -> Vec<char> {
    let mut v: Vec<char> = Vec::new();
    for c in s.chars() {
        v.push(c);
    }
    v
}
}

use input::*;

fn main() {
    let (h, w): (usize, usize);
    input!(h, w);
    let mut v = vec![];
    for _ in 0..h {
        let s = str2vec(&input_line_str());
        v.push(s);
    }

    let mut dp = vec![vec![0; w + 1]; h + 1];
    dp[1][1] = 1;
    for i in 1..h + 1 {
        for j in 1..w + 1 {
            if i == 1 && j == 1 {
                continue;
            }
            if v[i - 1][j - 1] == '.' {
                dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
                dp[i][j] %= 1_000_000_007;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    p(dp[h][w]);
}


Measured memory_bytes: 12540
import bisect
import sys
input = sys.stdin.readline

def main():
    A, B, Q = map(int, input().split())
    s = list(int(input()) for _ in range(A))
    t = list(int(input()) for _ in range(B))

    sort_s = sorted(s)
    sort_t = sorted(t)
    for _ in range(Q):
        x = int(input())
        s_near = bisect.bisect_left(sort_s, x)
        t_near = bisect.bisect_left(sort_t, x)

        s_candidate = []
        t_candidate = []

        if s_near == 0:
            s_candidate.append(sort_s[s_near])
        elif s_near == A:
            s_candidate.append(sort_s[s_near-1])
        else:
            s_candidate.append(sort_s[s_near])
            s_candidate.append(sort_s[s_near-1])
        
        if t_near == 0:
            t_candidate.append(sort_t[t_near])
        elif t_near == B:
            t_candidate.append(sort_t[t_near-1])
        else:
            t_candidate.append(sort_t[t_near])
            t_candidate.append(sort_t[t_near-1])

        ans = float('inf')
        # sを先に訪れるパターンを考える
        for i in s_candidate:
            for j in t_candidate:
                tmp = abs(x - i) + abs(i - j)
                ans = min(ans, tmp)

        # tをさきに訪れるパターンを考える
        for k in t_candidate:
            for l in s_candidate:
                tmp = abs(x - k) + abs(k - l)
                ans = min(ans, tmp)

        print(ans)

main()

Measured memory_bytes: 78652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
typedef vector<pair<int,int>> vp;
typedef pair<int,int> pii;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
#define sz(a) a.size()
const ll MOD = 1e9+7;
const int MAX = 10000000;
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
//cout << 'H' << endl;

int main(){
  int N;
  cin >> N;
  string S;
  int ans=0;
  rep(i,N) cin >> S;
  rep(i,N-2){
    if(S[i] == 'A' && S[i+1] == 'B' && S[i+2] == 'C'){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>

long double power(const long double base, const int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base;
	default: return power(base * base, exp / 2) * power(base, exp % 2);
	}
}
long double cal_estimated(const int current, const int success, std::vector<std::vector<long double>>& memo) {
	if (current == memo.size()) return 0;
	if (success >= 30) return cal_estimated(current + 1, 0, memo);
	if (memo[current][success] >= 0) return memo[current][success];
	return memo[current][success] = power(0.5, success) * (cal_estimated(current + 1, success + 1, memo) + 1) + (1 - power(0.5, success)) * cal_estimated(current + 1, 0, memo);
}

int main() {
	constexpr int max_day = 100000;
	std::vector<std::vector<long double>> memo(max_day, std::vector<long double>(30, -1));
	for (auto i = 1; i < memo.size(); i += 100) cal_estimated(max_day - i, 0, memo);
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::cout << std::setprecision(5) << std::fixed << cal_estimated(max_day - n, 0, memo) << '\n';
	}
}


Measured memory_bytes: 53380
#include <stdio.h>

int main(void){
	float xA , yA , xB , yB , xC , yC , xD , yD , a , b;
	while(scanf("%f %f %f %f %f %f %f %f" , &xA , &yA , &xB , &yB , &xC , &yC , &xD , &yD)!=EOF){
		if(yA == yB){
			if(xC == xD) printf("YES\n");
			else printf("NO\n");
		}else if(xA == xB){
			if(yC == yD) printf("YES\n");
			else printf("NO\n");
		}else{
			if(!(xC == xD)&&!(yC == yD)){
				a = (yA - yB) / (xA - xB);
				b = (yC - yD) / (xC - xD);
				if(a * b == -1) printf("YES\n");
				else printf("NO\n");
			}else printf("NO\n");
		}		
	}
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
using lint = long long;

template<class T>
vector<T> divisor(T n) {
	vector<T> res;
	for (T i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.emplace_back(i);
			if (i * i != n) res.emplace_back(n / i);
		}
	}
	sort(res.begin(), res.end());
	return res;
}


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, D;
	cin >> N >> D;

	vector<vector<int>> X(N, vector<int>(D));
	for (int i = 0; i < N; i++) for (int j = 0; j < D; j++) cin >> X[i][j];
	
	int sum, ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
				
			sum = 0;
			for (int k = 0; k < D; k++) {

				sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);

			}
			auto div = divisor(sum);
			for (const auto &e : div) if (e*e == sum) ans++;

		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import math

if sys.platform =='ios':
    sys.stdin=open('input133b.txt')

#+++++

count = 0
n, d = map(int, input().split())
anums = []
for i in range(n):
	anums.append( list(map(int, input().split())))

for i in range(n):
	for k in range(n - i -1):
		num = 0
		for j in range(d):
			num += pow(abs(anums[i][j] - anums[i + k + 1][j]),2)

		sq = math.sqrt(num)
		if sq.is_integer():
			count += 1

print(count)

Measured memory_bytes: 12384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int A[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

int main()
{
	int K;
	cin >> K;
	cout << A[K-1] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
map<char,int> tbl;
map<int,char> tbl2;
bool isnum(char c){
  return '0'<=c && c<='9';
}
int decode(string s){
  int ret = 0;
  for(int i=0;i<s.length();++i){
    int t = 1;
    if(!isnum(s[i])){
      if(i>0 && isnum(s[i-1])) t = s[i-1]-'0';
      ret+=t*tbl[s[i]];
    }
  }
  return ret;
}
string code(int x){
  string ret("");
  int c = 0;
  while(x){
    int d = x%10;
    if(d){
      ret+=tbl2[c];
      if(d>1) ret+=(char)(d+'0');
    }
    ++c;
    x/=10;
  }
  reverse(ret.begin(), ret.end());
  return ret;
}
int main(){
  int n;
  cin>>n;
  tbl['m'] = 1000;
  tbl['c'] = 100;
  tbl['x'] = 10;
  tbl['i'] = 1;
  tbl2[0] = 'i';
  tbl2[1] = 'x';
  tbl2[2] = 'c';
  tbl2[3] = 'm';
  
  while(n--){
    string a,b;
    cin>>a>>b;
    cout << code(decode(a)+decode(b)) << endl;
  }
  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include<string>
#include<algorithm>
#include<iomanip>
#include<stdlib.h>
#include<vector>



using namespace std;

int main() {
	
	while(1){
		int ma, wa;
		cin >> ma >> wa;

		if (ma == 0 && wa == 0) break;

		int counter = 0;

		for (int i = 1; i <= ma; i++) {
			for (int j = i+1; j <= ma; j++) {
				for (int k = j+1; k <= ma; k++) {
					if (i + j + k == wa)counter++;
				}
			}

		}
		cout << counter << endl;
	}
}


Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
using namespace std;

#define N 2000000

int n;
int A[N+1];

int parent(int i){
	return i/2;
}
int left(int i){
	return 2*i;
}
int right(int i){
	return 2*i+1;
}
int inside(int i){
	if(i>=1&&i<=n) return 1;
	else return 0;
}

void max_heapify(int x){
	int l = left(x);
	int r = right(x);
	int largest = x;
	if(inside(l)&&A[l]>A[largest]) largest = l;
	if(inside(r)&&A[r]>A[largest]) largest = r;
	if(largest!=x){
		int tmp = A[largest];
		A[largest] = A[x];
		A[x] = tmp;
		max_heapify(largest);
	}
}

void insert(int k){
	A[n+1] = k;
	n++;

	int x = n;
	while(inside(parent(x))){
		if(A[x]>A[parent(x)]){
			int tmp = A[x];
			A[x] = A[parent(x)];
			A[parent(x)] = tmp;
			x = parent(x);
		}else{
			break;
		}
	}
}

int extract(){
	int ret = A[1];
	A[1] = A[n];
	n--;
	max_heapify(1);
	return ret;
}

int main(){
	n = 0;
	for(;;){
		char s_[100];
		scanf("%s", s_);
		string s = s_;
		if(s=="end"){
			break;
		}else if(s=="insert"){
			int k;
			scanf("%d", &k);
			insert(k);
		}else if(s=="extract"){
			printf("%d\n", extract());
//			cout << extract() << endl;
		}

//		cout << n << endl;
		/*
		for(int i=1; i<=n; i++){
			cout << " " << A[i];
		}
		*/
	}
	/*
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> A[i];
	}
	*/
	/*
	for(int i=1; i<=n; i++){
		printf("node %d: ", i);
		printf("key = %d, ", A[i]);
		if(inside(parent(i))) printf("parent key = %d, ", A[parent(i)]);
		if(inside(left(i))) printf("left key = %d, ", A[left(i)]);
		if(inside(right(i))) printf("right key = %d, ", A[right(i)]);
		printf("\n");
	}
	*/
/*
	for(int i=n; i>=1; i--){
		max_heapify(i);
	}
	for(int i=1; i<=n; i++){
		cout << " " << A[i];
	}
	cout << endl;
*/
	return 0;
}

Measured memory_bytes: 5324
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>;
using L = vector<long long>;
using M = map<int,long long>;
using A = vector<vector<long long>>;
using Q = priority_queue<long long>;
using U = unordered_map<int,long long>; //mapとの違いはkeyの順番を保持していない

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    long long a,b,c,d,x,y,z;
    cin>>a>>b>>c>>d;
    long long g=c*d/__gcd(c,d);
    x=b/c-(a-1)/c;
    y=b/d-(a-1)/d;
    z=(-(a-1)/g+b/g);
    cout<<b-a-(x+y-z)+1<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string t;
int a[4005],s[5][4005],u[5];
 int main(){
 	int n;
 	cin>>n>>t;
 	for(int i=1;i<=n;i++)
 	{
 		if(t[i-1]=='R') a[i]=0;
 		if(t[i-1]=='G') a[i]=1;
 		if(t[i-1]=='B') a[i]=2;
	 }
	 for(int i=1;i<=n;i++)
	   {
	   	 for(int j=0;j<3;j++)s[j][i]=s[j][i-1];
	   	 s[a[i]][i]=s[a[i]][i-1]+1;
	   }
	ll ans=0;
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			if(a[i]==a[j])continue;
		
			ans+=s[3-a[i]-a[j]][n]-s[3-a[i]-a[j]][j];
			if(j-i+j<=n&&a[j-i+j]==3-a[i]-a[j])ans--;
		}
	}
 cout<<ans;
return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define tddd tuple<double,double,double>
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 200005
typedef long long int ll;
ll fact[N],inv[N],finv[N];
ll pro(ll a,ll b)
{
    return (a*b)%M;
}
void buildfact()
{
    int i,q,r;
    fill(fact,fact+N,1);
    fill(inv,inv+N,1);
    fill(finv,finv+N,1);
    for(i=2;i<N;i++)
    {
        fact[i]=pro(fact[i-1],i);
        q=M/i,r=M%i;
        inv[i]=M-pro(q,inv[r]);
        finv[i]=pro(finv[i-1],inv[i]);
    }
    return ;
}
ll dp[N];
ll ncr(int n,int r)
{
    ll x;
    x=pro(finv[r],finv[n-r]);
    return pro(x,fact[n]);
}
int main()
{
    int n,k,i,a,j;
    in2(n,k);
    vi v(n);
    read(v,i,n);
    dp[0]=1;
    rep(i,n)
    {
        a=v[i]+1;
        for(j=k-a;j>=0;j--)
            dp[j+a]-=dp[j],dp[j+a]+=M,dp[j+a]%=M;
    }
    buildfact();
    ll ans=0;
    rep(i,k+1)
        ans+=pro(ncr(n+k-i-1,k-i),dp[i]);
    ans%=M;
    outl(ans);
}











Measured memory_bytes: 5760
n,k=map(int,input().split())
def f(x):
  res=0
  while x<k:
    x*=2
    res+=1
  return res
ans=0
if n>=k:
  ans+=(n-k+1)/n
for i in range(1,min(n+1,k)):
  ans+=(1/n)*0.5**f(i)
print(ans)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] arr = new int[N+1000];
        int[] memo = new int[N+1000];

        for (int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
            memo[i]=-1;
        }

        int[] dp = new int[N+1000];
        for (int i = 0; i <dp.length ; i++) {
            dp[i] = Integer.MAX_VALUE;
        }
        dp[1] = 0;
        for (int i = 1; i <= N ; i++) {
            for (int j = i+1; j <= Math.min(i+K,N) ; j++) {
                int val  =Math.min(dp[j], dp[i] +Math.abs(arr[j-1]-arr[i-1]));
                dp[j] = val;
            }
        }
        System.out.println(dp[N]);


//        System.out.println(recur(arr,memo,N-1));

    }

    static public int recur(int[] arr,int[] memo, int idx){
        if(memo[idx]!=-1) return memo[idx];
        if(idx <=0){
            return 0;
        }

        int min = Integer.MAX_VALUE;
        if(idx-1>=0)
        min = Math.min(min, recur(arr,memo,idx-1) + Math.abs(arr[idx] - arr[idx-1]));

        if(idx-2>=0)
        min = Math.min(min, recur(arr,memo,idx-2) + Math.abs(arr[idx] - arr[idx-2]));

        memo[idx] =min;
        return min;
    }


}


Measured memory_bytes: 59564
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoders {
	class Program {
		static void Main(string[] args) {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var N = inputArray[0];
			var words = new List<string>();

			for (int i = 0; i < N; i++) {
				words.Add(Console.ReadLine());
			}

			//答えの出力
			var ans = getAns(words);
			Console.WriteLine(ans);
		}

		private static string getAns(List<string> words) {
			var dictionary = new Dictionary<string, long>();

			foreach (var word in words) {

				bool exist = dictionary.ContainsKey(word);

				//キーが存在しない場合、新しく足す
				if (!exist) {
					dictionary.Add(word, 1);
				}
				else {//キーが存在する場合、カウントを足す
					dictionary[word]= dictionary[word]+1;
				}
			}
			var maxCount = dictionary.Select(x => x.Value).Max();

			var freqWords = dictionary.Where(x => x.Value == maxCount).Select(x => x.Key).OrderBy(x => x, StringComparer.Ordinal);
			var sb = new StringBuilder();

			foreach (var word in freqWords) {
					sb.Append(word);
					sb.Append("\n");
			}
			return sb.ToString();
		}


		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray =  Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 48372
#include<iostream>
#include<cstring>
using namespace std;
int q,l,r,p[1000010],jug[100010],sum[100010];
int main()
{
	for(int i=2;i<=100000;i++){
		p[i]=1;
	}
	memset(jug,0,sizeof(jug));
	memset(sum,0,sizeof(sum));
	for(int i=2;i<=50000;i++){
		if(p[i]==1){
			int temp=i+i;
			while(temp<=100000){
				p[temp]=0;
				temp+=i;
			}
		}
	}
	for(int i=1;i<=100000;i++){
		if(p[i]==1&&p[(i+1)/2]==1){
			jug[i]=1;
		}
	}
	sum[1]=1;
	for(int i=2;i<=100000;i++){
		sum[i]=sum[i-1]+jug[i];
	}
	cin>>q;
	for(int i=1;i<=q;i++){
		cin>>l>>r;
		cout<<sum[r]-sum[l]+jug[l]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
p = list(map(int,input().split()))
ans = 0
for x in range(n-2):
  for y in range(x+1,x+2):
    for z in range(x+2,x+3):
      if p[x] >= p[y] and p[y] >= p[z]:
        ans+=1
      elif p[z] >= p[y] and p[y] >= p[x]:
        ans+=1
print(ans)

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

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N, 0);
    vector<ll> B(N-1, 0);
    rep(i,N-1) cin >> B[i];
    A[0] = B[0];
    A[N-1] = B[N-2];
    for(ll i=1;i<N-1;i++){
        A[i] = min(B[i-1], B[i]);
    }
    ll sum=0;
    rep(i,N) sum+= A[i];
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
def solve(s):
    h = int(np.sqrt(s))
    if h**2 < s:
        h += 1
    d = h**2 - s
    if d == 0:
        x, y = 0, 0
    else:
        x, y = 1, d
    return " ".join(map(str, [0,0,x,h,h,y]))

s = int(input())
print(solve(s))

Measured memory_bytes: 26992
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;


void main()
{
  auto s = readln.chomp.to!(char[]).array;
  int i, res;
  i = res = 0;
  while (i != s.length / 2) {
    //writeln(i);
    if (s[i] != s[$-i-1]) {
      if (s[i] == 'x') {
        s.insertInPlace(s.length-i, 'x');
      } else if (s[$-i-1] == 'x') {
        s.insertInPlace(i, 'x');
      } else {
        res = -1;
        break;
      }
      res++;
    } 
   /*s.writeln;
   readln();*/
   i++; 
  }
  res.writeln;
}


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

int main(){
	int n,yen;
	cin >> n >> yen;
	int res10000 = -1, res5000 = -1, res1000 = -1;
	for(int i=0;i<=n;i++){
		for(int j=0;j+i<=n;j++){
			int k = n-i-j;
			int total = 10000*i+5000*j+1000*k;
			if(total == yen){
				res10000 = i;
				res5000 = j;
				res1000 = k;
			}
		}
	}
	cout << res10000 << " " << res5000 << " " << res1000 << endl;
}

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

int main() {
    int k, x;
    cin >> k >> x;

    for (int i = 0; i < k*2-1; i++) {
        cout << x-k+1+i;
        if (i != k*2-2) cout << ' ';
        else cout << endl;
    }
}

Measured memory_bytes: 3592
#include<stdio.h>
long long R=1,C=1,H[2000010],N[2000010],id[2000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]<N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
long long CO[100010];
void dijk(int v,int e,int *fr,int *to,long long *co,int mi){
  int i,ta[100010],nt[200010],f[100010]={0};
  for(i=0;i<=v;i++)ta[i]=-1;
  for(i=0;i<=v;i++)CO[i]=1e18;
  for(i=CO[mi]=0;i<e;i++){
    nt[i]=ta[fr[i]];
    ta[fr[i]]=i;
  }
  while(f[mi]-1){
    f[mi]=1;
    for(i=ta[mi];i+1;i=nt[i]){
      if(CO[to[i]]>CO[mi]+co[i])hin(CO[id[R]=to[i]]=CO[mi]+co[i]);
    }
    while(f[mi]&&C-1)mi=id[hout()];
  }
}
long long MIN(long long a,long long b){return a<b?a:b;}
int main(){
  int n,m,a[200010],b[200010],s,t,i;
  long long e[100010],f[100010],c[200010],d[200010];
  scanf("%d %d %d %d",&n,&m,&s,&t);
  for(i=0;i<m;i++)scanf("%d %d %lld %lld",&a[i],&b[i],&c[i],&d[i]);
  for(i=0;i<m;i++){
    a[i+m]=b[i];
    b[i+m]=a[i];
    c[i+m]=c[i];
    d[i+m]=d[i];
  }
  dijk(n,m*2,a,b,c,s);
  for(i=R=C=1;i<=n;i++)e[i]=CO[i];
  dijk(n,m*2,a,b,d,t);
  f[n+1]=1e18;
  for(i=n;i;i--)f[i]=MIN(f[i+1],e[i]+CO[i]);
  for(i=0;i<n;i++)printf("%lld\n",(long long)1e15-f[i+1]);
  return 0;
}


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

int main(){
  string n;
  cin >> n;
  int a = 0;
  for (int i = 0;i < 3;i++){
    if(n[i] == '1')n[i] = '9';
    else n[i] = '1';
  }
  cout << n << endl;
 }

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[1000];

void gg(int i){
    for(int j = 2; j <= i; j++){
        if(i % j == 0){
            while(1){
                if(i % j != 0){
                    break;
                }
                i /= j;
                a[j] += 1;
            }
        }
    }
    return;
}

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

    for(int i = n; i >= 2; i--){
        gg(i);
    }

    long long ans = 1;
    for(int i = 2; i <= n; i++){
        if(a[i] != 0){
            //cout << i << " " << a[i] << endl;
            ans *= (a[i] + 1);
            ans %= 1000000007;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
f = sys.stdin

while True:
    n, m = map(int, f.readline().split())
    if n == m == 0:
        break
    circle = [i + 1 for i in range(n)]
    cnt = 0
    while len(circle) != 1:
        cnt += m - 1
        cnt %= len(circle)
        circle = circle[:cnt] + circle[cnt + 1:]
    print(circle[0])

Measured memory_bytes: 6720
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n;
  int a[SIZE], k[SIZE];

  scanf("%d",&n);

  int ans = 0;
  
  for(int i=0;i<n;i++){
    scanf("%d%d",a+i, k+i);

    int pos = a[i];
    
    while(pos%k[i]){
      int d = pos / k[i];

      if(pos - d * k[i] < d + 2)
        pos -= d + 1;
      else
        pos -= (pos - d*k[i]) / (d + 1) * (d + 1);
    }

    ans ^= pos/k[i];
  }

  if(ans){
    puts("Takahashi");
  } else {
    puts("Aoki");
  }
  
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main()
{
int a,c,i;
long int b,sum;
  sum=0;
  scanf("%d %ld %d",&a,&b,&c);
int people[a],num[c];
  for(i=0;i<a;++i)
  {
  people[i]=0;
  }
  
  for(i=0;i<c;++i)
  {
  scanf("%d",&num[i]);
  people[num[i]-1]++;
  }
 
  for(i=0;i<a;++i)
  {
  sum=sum+people[i];
  }

  for(i=0;i<a;i++)
  {
  if(sum-people[i]>=b) printf("No\n");
  else printf("Yes\n");
  }

return 0;
}

Measured memory_bytes: 1280