akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

long long c;
int l;
int A[1000000];
int n;
vector<int> G;


void ins(int A[],int n,int g){
  for(int i=g;i<n;i++){
    int v=A[i];
    int j=i-g;
    while(j>=0 && A[j] >v){
      A[j+g]=A[j];
      j -= g;
      c++;
    }
    A[j+g]= v;
  }
}


void she(int A[],int n){
  for(int h=1; ; ){
    if(h>n) break;
    G.push_back(h);
    h= 3*h+1;
  }

  for(int i=G.size()-1;i>=0;i--){
    ins (A,n,G[i]);
  }
}


int main(){
  cin >> n;
  for(int i=0;i<n;i++) scanf("%d",&A[i]);
  c=0;

  she(A,n);

  cout << G.size() << endl;
    for(int i= G.size()-1;i>=0;i--){
      printf("%d",G[i]);
      if(i) printf(" ");
    }
    printf("\n");
    printf("%d\n",c);
    for(int i=0;i<n;i++) printf("%d\n",A[i]);

    return 0;
}



Measured memory_bytes: 7132
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
using pii = pair<int, int>;
using vi = vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0

int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    int n, l; cin >> n >> l;
    int sumo = 0;
    int a[n]; rep(i, n) {a[i] = l + i + 1 - 1; sumo += a[i];}
    //rep(i, n) cout << a[i] << " "; cout << endl;
    
    int ans = inf;
    int kuta = 0;
    rep(i, n) {
        int sum = 0;
        rep(j, n) {
            if (i == j) continue;
            sum += a[j];
        }
        if (abs(sum - sumo) < ans) {
            ans = abs(sum - sumo);
            kuta = i;
        }
    }
    cout << sumo - a[kuta] << endl;
}
//cast caution



Measured memory_bytes: 256
use proconio::input;
// use std::collections::HashMap;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        mut Ps: [i32; N],
    }

    Ps.sort();
    Ps[N - 1] = Ps[N - 1] / 2;

    let ans: i32 = Ps.iter().sum();

    println!("{}", ans);
}


Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) cin >> a[i];
  ll m = 42;
  vector<vl> dp(m + 1, vl(2, -1));
  dp[0][0] = 0;
  rep(i, m) {
    ll cnt = 0;
    rep(j, n) if(a[j] >> (m - 1 - i) & 1) cnt++;
    if(dp[i][1] != -1) dp[i + 1][1] = dp[i][1] * 2 + max(cnt, n - cnt);
    if(k >> (m - 1 - i) & 1) {
      dp[i + 1][0] = dp[i][0] * 2 + n - cnt;
      dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] * 2 + cnt);
    } else {
      dp[i + 1][0] = dp[i][0] * 2 + cnt;
    }
  }
  cout << max(dp[m][0], dp[m][1]) << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int tab[1000005];
int main()

{
    int a,b,wynik=0;
    cin >>a;
    for(int i=0;i<a;i++){
        cin >> b;
        if(b<=a){
        tab[b]++;
        }
        else wynik++;
    }
    for (int i=0;i<100005;i++){
        if (tab[i]>0){
            if(tab[i]>i)wynik+=tab[i]-i;
            if(tab[i]<i)wynik+=tab[i];
        }
    }
    cout << wynik;
    return 0;
}


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


int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    rep(i,h)cin>>s[i];
    vector<int> res(26);
    rep(i,h)for(auto c : s[i])res[c-'a']++;
    vector<int> cnt(4);
    vector<int> cnt2(2);
    rep(i,res.size()){
        cnt[res[i]%4]++;
    }
    cnt2[0]=cnt[2];
    cnt2[1]=cnt[1]+cnt[3];
    if(h%2&&w%2){
        if(cnt2[1]<=1&&cnt2[0]<=(h-1)/2+(w-1)/2){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else if(h%2==0&&w%2==0){
        if(cnt2[0]==0&&cnt2[1]==0){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        if(w%2==1){
            if(cnt2[1]==0&&cnt2[0]<=h/2){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
        if(h%2==1){
            if(cnt2[1]==0&&cnt2[0]<=w/2){
                cout<<"Yes"<<endl;
            }
            else{
                cout<<"No"<<endl;
            }
        }
    }
}

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

int main() {
  int X, Y;
  scanf("%d %d", &X, &Y);
  int A = 0;
  int B = 0;
  
  if(Y == 2*X || Y == 4*X){
    cout << "Yes";
    return 0;
  }
  else{
    for(int i = 0; i < X; i++){
      for(int j = 0; j < X; j++){
      	if(i + j == X){
        	if(2*i + 4 * j == Y){
          		cout << "Yes";
          		return 0;
            }
        }
      }
    }
  }         
  cout << "No";
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;

int n, m, xor_lt[N];
bool visited[N];
vector<int> res;
vector<pair<int, int> > bomb, adj[N];

int dfs(int u) {
  	visited[u] = true;
  	int cur_xor = xor_lt[u];
  	for (auto &e: adj[u]) {
	    int v = e.first;
	    if (visited[v]) continue;
	    if (dfs(v)) {
	      	res.emplace_back(e.second);
	      	cur_xor ^= 1;
	    }
  	}
  	return cur_xor;
}

int main() {
  	scanf("%d%d",&n,&m);
  	for (int i = 1, a, b; i <= n; ++i) {
    	scanf("%d%d",&a,&b);
    	bomb.emplace_back(a, b);
  	}
  	sort(bomb.begin(), bomb.end());
  	for (int i = 1, l, r; i <= m; ++i) {
	    scanf("%d%d",&l,&r);
	    l = lower_bound(bomb.begin(), bomb.end(), make_pair(l, 0)) - bomb.begin() + 1;
	    r = upper_bound(bomb.begin(), bomb.end(), make_pair(r, 1)) - bomb.begin() + 1;
	    adj[l].emplace_back(r, i);
	    adj[r].emplace_back(l, i);
  	}
  	xor_lt[1] = bomb[0].second;
  	for (int i = 2; i <= n; ++i) xor_lt[i] = bomb[i - 1].second ^ bomb[i - 2].second;
  	xor_lt[n + 1] = bomb[n - 1].second;
  	for (int i = 1; i <= n; ++i) {
	    if (visited[i])
			continue;
	    if (dfs(i)) {
	      	puts("-1");
	      	return 0;
	    }
  	}
  	sort(res.begin(), res.end());
  	cout << res.size() << "\n";
  	for (int x: res)
		printf("%d\n",x);
  	return 0;
}


Measured memory_bytes: 13172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
//#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
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; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

bool isNotPrime[100005];
int nearNum[100005];
inline void solve(){

    int q;

    isNotPrime[1] = true;
    
    for(int i = 2; i < 100005; i++) {
        if(!isNotPrime[i]){
            for(int j = i+i; j < 100005; j+=i) {
                isNotPrime[j] = true;
            }
        }
    }
    
    for(int i = 3; i < 100005; i++) {
        nearNum[i] = nearNum[i-1];
        if(!isNotPrime[i] && !isNotPrime[(i+1)/2])
            nearNum[i]++;
        
    }

    cin >> q;

    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << nearNum[r] - nearNum[l-1] << endl;
    }
    

}
struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}


Measured memory_bytes: 1152
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1e9+7;
const int MAX = 200200;
template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
/*
struct Combination {
    vector<ModInt<MOD>> fact;
    Combination(int n) : fact(n+1) {
        fact[0] = 1;
        for (long long i = 1; i <= n; i++) {
            fact[i] = (fact[i-1] * i);
        }
    }
    ModInt<MOD> operator() (long long n, long long r) {
        if (r < 0 || r > n) return 0;
        return fact[n]/(fact[n-r]*fact[r]);
    }
};
*/
ModInt<MOD> com(int n, int r) {
    using mint = ModInt<MOD>;
    mint ret = 1;
    for (int i = n; i > n-r; i--) {
        ret *= i;
    }
    for (int i = 2; i <= r; i++) {
        ret /= i;
    }
    return ret;
}

int main() {
    using mint = ModInt<MOD>;
    //Combination com(MAX);
    int n, a, b;
    cin >> n >> a >> b;
    
    mint ans = 2;
    ans = ans.pow(n);
    ans -= com(n, a);
    ans -= com(n, b);
    ans -= 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
///mAAria...
#include<bits/stdc++.h>
 
using namespace std;
 
#define int long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(),v.end()
#define allr(v) v.begin(),v.end()
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pii pair<int,int>
#define pi 3.1415926535897932384626433832
#define mod 1000000007
//#define mod 998244353
#define inf 1000000000
#define pr1(a) cout << a << endl
#define pr2(a,b)cout << a <<  " " <<b<< endl
#define pr3(a,b,c) cout << a <<" " << b << " " << c << endl

const long double PI = acos(-1);

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}

int gcd(int a, int b){
    if(b==0)return a;
    gcd(b,a%b);
}
vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

set<int> divv(int n){

    set<int> s;
    if(n>1)s.insert(n);
    for(int i = 2;i*i<=n;i++){
        if(n%i==0){
            s.insert(i);
            s.insert(n/i);
        }
    }

    return s;

}

void solve(){
    int n;
    cin >> n;
    set<int>s1,s2;

    s1 = divv(n);
    s2 = divv(n-1);

    int ans = (int)s2.size();

    for(auto i:s1){
        int t = n;
        while(t%i==0){
            t/=i;
        }
        if(t%i==1){
            ans++;
        }
    }

    cout << ans << endl;

    
}

signed main() 
{   
    IOS;
    int t = 1;
    // cin >> t;
    
    for(int i = 1;i<=t;i++){
        solve();
    }
    return 0;
} 

 


Measured memory_bytes: 512
// PDF解説に倣って。
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n,a;
  cin>> n;
  vector<int> index(n);
  for (int i=0; i<n; i++){
    cin>> a;
    index[n-a]=i;
  }
  
  
  int64_t ans=0,num,le,l,r,re;
  multiset<int> s;
  s.insert(-1); s.insert(-1); s.insert(n); s.insert(n);
  for (int i=0; i<n; i++){
    num=index[i];
    auto itr=s.lower_bound(num); //イテレータの注意点。vec(ランダムアクセス可)とset(ランダムアクセス不可)は確実に使い分けましょう
    r=*itr++;
    re=*itr--;itr--;
    l=*itr--;
    le=*itr;
    ans+=(n-i)*((l-le)*(r-num)+(num-l)*(re-r));
    s.insert(num);
  }
  cout<< ans << endl;
}
/*もっと早く見つけたかった参考：https://pyteyon.hatenablog.com/entry/2019/02/20/194140#algorithm-%E3%81%AE-stdlower_bound-%E3%81%A8-stdsetlower_bound-%E3%81%AE%E8%A8%88%E7%AE%97%E9%87%8F%E3%81%AE%E9%81%95%E3%81%84
"std::lower_bound() を std::set に対して使うと O(N) で， std::set のメンバ関数の std::set::lower_bound() を行うと O(logN) になります*/

Measured memory_bytes: 5376
#include<iostream> 
#include<cstring> 
#include<algorithm>
using namespace std;

int dp[3001][3001];

int getLen(string& s, string& t, int i, int j)
{
    if(i >= s.size() || j >= t.size()) return 0;
    
    if(dp[i][j] != -1) return dp[i][j];
    
    if(s[i] == t[j]) return dp[i][j] = 1 + getLen(s,t,i+1,j+1);
                     return dp[i][j] = max(getLen(s,t,i+1,j), getLen(s,t,i,j+1));
}

string getLcs(string& s, string& t, int len)
{
    string ret; int i=0,j=0;
    
    while(len > 0)
    {
        if(s[i] == t[j])
        {
            ret.push_back(s[i]);
            ++i; ++j; --len;
        }
        
        else
        {
            if(dp[i+1][j] > dp[i][j+1]) i++;
            else j++;
        }
    }
    return ret;
}

string ans(string& s, string& t)
{
    int len = getLen(s,t,0,0);
    return getLcs(s,t,len);
}

int main()
{
    memset(dp, -1, sizeof(dp));
    string s,t; cin >> s >> t;
    cout << ans(s,t);
}
 


Measured memory_bytes: 38592
n = int(input())
a = list(map(int, input().split()))

from fractions import gcd

tl = [a[0]]
for i in range(1, n):
    tl.append(gcd(tl[i - 1], a[i]))

tr = [a[n - 1]]
for i in range(1, n):
    tr.append(gcd(tr[i - 1], a[n - 1 - i]))
tr.reverse()

ans = 1
for i in range(n):
    tmp = 1
    if i == 0: tmp = tr[i + 1]
    elif i == n - 1: tmp = tl[i - 1]
    else: tmp = gcd(tl[i - 1], tr[i + 1])
    ans = max(ans, tmp)
print(ans)

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

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

int gcd2(int x,int y,int z){
    int xy = gcd(x,y);
    return gcd(xy,z);
}

int main(void){
    int K;
    cin >> K;
    long long sum=0;
    for(int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            for(int c=1;c<=K;c++){
                sum += gcd2(a,b,c);
            }
        }
    }
    cout << sum << endl;
}

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

int main() {
    int N, K, Q; cin >> N >> K >> Q;
    vector<int> A(N, 0);
    REP(i, 0, Q) {
        int a; cin >> a;
        A[--a]++;
    }

    REP(i, 0, N) {
        if (Q - A[i] < K) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int main() {
  vector <char> a (10);
  vector <char> b (10);
  int count;
  for(int i=0;i<3;i++)
    cin >>a.at(i);
  for(int i=0;i<3;i++)
    cin >>b.at(i);
  if(a.at(0)==b.at(0))
    ++count;
  if(a.at(1)==b.at(1))
    ++count;
  if(a.at(2)==b.at(2))
    ++count;
  cout << count << endl;
}

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

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define NDEBUG
#define eprintf(...) do {} while (0)
#endif
#include<cassert>

using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}


template<class Iter> vector<int>Z_Algorithm(Iter a, Iter a_end) {
    int n = a_end - a;
    vector<int>z(n);
    int l = 0, r = 0;
    for (int i=1; i<n; i++) {
	if (i > r) {
	    l = r = i;
	    while (r<n && a[r-l] == a[r]) r++;
	    z[i] = r-l; r--;
	} else {
	    int k = i-l;
	    if (z[k] < r-i+1) z[i] = z[k];
	    else {
		l = i;
		while (r<n && a[r-l] == a[r]) r++;
		z[i] = r-l; r--;
	    }
	}
    }
    return z;
}
const int LEVEL = 100;
const LL INF = 1LL<<61;
int N;
char S[200011];
LL C[LEVEL][26];
LL len[LEVEL];
LL ans[26];

void F(LL R, int sgn) {
    for (int i=LEVEL-1; i>=2; i--) {
	if (len[i] <= R) {
	    REP (t, 26) ans[t] += C[i][t] * sgn;
	    R -= len[i];
	}
    }

    assert(R <= N);
    REP (i, R) ans[S[i]-'a'] += sgn;
}

void MAIN() {
    scanf("%s", S);
    N = strlen(S);
    N /= 2;
    VI z = Z_Algorithm(S, S+N);
    
    int pos = N;
    for (int i=1; i<N; i++) if (i + z[i] == N) {
	pos = i;
	break;
    }

    len[0] = pos;
    len[1] = N;
    REP (i, N) {
	if (i < pos) C[0][S[i]-'a']++;
	C[1][S[i]-'a']++;
    }
    for (int i=2; i<LEVEL; i++) {
	len[i] = min(INF, len[i-1] + len[i-2]);
	REP (t, 26) C[i][t] = C[i-1][t] + C[i-2][t];
    }
//    puts(S);

    LL l, r;
    scanf("%lld%lld", &l, &r);
    assert(len[LEVEL-1] > r);
    F(r, 1);
    F(l-1, -1);

    //puts(S);
    //printf("%d %d\n", sep, pos);
    rprintf("%lld", ans, ans+26);
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



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

typedef long long ll;

ll m1[10][10] =
{
	{},
	{1},
	{111, 10},
	{11111, 1110, 100},
	{1111111, 111110, 11100, 1000},
	{111111111, 11111110, 1111100, 111000, 10000},
	{11111111111, 1111111110, 111111100, 11111000, 1110000, 100000},
	{1111111111111, 111111111110, 11111111100, 1111111000, 111110000, 11100000, 1000000},
	{111111111111111, 11111111111110, 1111111111100, 111111111000, 11111110000, 1111100000, 111000000, 10000000},
	{11111111111111111, 1111111111111110, 111111111111100, 11111111111000, 1111111110000, 111111100000, 11111000000, 1110000000, 100000000}
};
ll m2[10][10] =
{
	{},
	{11},
	{1111, 110},
	{111111, 11110, 1100},
	{11111111, 1111110, 111100, 11000},
	{1111111111, 111111110, 11111100, 1111000, 110000},
	{111111111111, 11111111110, 1111111100, 111111000, 11110000, 1100000},
	{11111111111111, 1111111111110, 111111111100, 11111111000, 1111110000, 111100000, 11000000},
	{1111111111111111, 111111111111110, 11111111111100, 1111111111000, 111111110000, 11111100000, 1111000000, 110000000},
	{111111111111111111, 11111111111111110, 1111111111111100, 111111111111000, 11111111110000, 1111111100000, 111111000000, 11110000000, 1100000000},
};

ll calc2[20][2];
ll va[9];
ll ans;
ll d;

ll calc(int n)
{
	ll tot = 1;
	for (int i = 0;i < n;i++) tot *= calc2[va[i]+9][i==0];
	return tot;
}

void slv(int at)
{
	ll tot = 0;
	if (at > 0)
	{
		ll numways = calc(at);
		tot = 0;
		for (int i = 0;i < at;i++) tot += va[i]*m1[at][i];
		if (tot == d)
			ans += numways;
		tot = 0;
		for (int i = 0;i < at;i++) tot += va[i]*m2[at][i];
		if (tot == d)
			ans += 10*numways;
	}
	tot = 0;
	for (int i = 0;i < at;i++) tot += va[i]*m1[at][i];
	if (at < 9 && tot >= 0 && tot <= d)
	{
		for (int i = -9;i <= 9;i++)
		{
			va[at] = i;
			slv(at+1);
		}
	}
}

int main()
{
	for (int i = 0;i <= 9;i++) for (int j = 0;j <= 9;j++)
	{
		calc2[i-j+9][0]++;
		if (j) calc2[i-j+9][1]++;
	}
	scanf("%lld", &d);
	if (d%9) printf("0\n");
	else
	{
		d /= 9;
		slv(0);
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>

int main(void) {
	int a,point[1001];
	double heikin=0,bunsan=0,hensa=0;
	for (int i = 0; i < 1002; i++) {
		point[i] = 0;
	}
	while (1) {
		double heikin = 0, bunsan = 0, hensa = 0;
		scanf("%d", &a);
		if (a == 0) {
			break;
		}else{
			for (int i = 0; i < a; i++) {
				scanf("%d", &point[i]);
				heikin += point[i];
			}
			heikin = heikin / a;
			for (int i = 0; i < a; i++) {
				bunsan += pow(point[i] - heikin, 2);
			}
			bunsan = bunsan / a;
			hensa = sqrt(bunsan);
		}
		printf("%lf\n", hensa);
	}


}


Measured memory_bytes: 2080
#include <algorithm>
#include <iostream> 
#include <cstdio>
#include <cmath>
using namespace std;
int a[21];
int main()
{
	int n,m,c;
	scanf("%d%d%d",&n,&m,&c);
	for (int i=1;i<=m;i++)
	{
		scanf("%d",&a[i]);
	}
	int q;
	int sum=0;
	for (int j=1;j<=n;j++)
	{
		int s=0;
		for (int i=1;i<=m;i++)
		{
			scanf("%d",&q);
			s+=(q*a[i]);
		}
		if (s+c>0)
		{
			sum++;
		}
	}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
#include <string.h>
#include <vector>
#define se second
#define fi first
using namespace std;
const int maxN = 1e5 + 9, MOD = 1e9 + 7;

typedef long long ll;
typedef pair<int, int> ii;

int main() {
  ios::sync_with_stdio(false);
  
  int n, k;
  cin >> n >> k;
  if(n % k == 0){
    cout << "0\n";
  }
  else{
    cout << "1\n";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=500+5,M=1e4+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("D.in","r",stdin);
	freopen("D.out","w",stdout);
#endif
}
int n;
int vis[M],l[M];
void input()
{
	n=read<int>();
}
void init(int Max)
{
	For(i,2,Max)
	{
		if(!vis[i])l[++l[0]]=i;
		for(int j=1;j<=l[0]&&i*l[j]<=Max;j++)
		{
			vis[l[j]*i]=1;
			if(i%l[j]==0)break;
		}
	}
}
ll mp[N][N];
map<ll,bool>used;
int x[N<<1],y[N<<1];
ll lcm(ll x,ll y)
{
	if(!x||!y)return x|y;
	return x/__gcd(x,y)*y;
}
void work()
{
	if(n==2)
	{
		printf("4 7\n23 10\n");
		return;
	}
	int t1=1,t2=1000;
	For(i,1,n)For(j,1,n)if((i+j)&1)
	{
		if(!x[j-i+n])x[j-i+n]=l[t1++];
		if(!y[i+j])y[i+j]=l[t2--];
		mp[i][j]=x[j-i+n]*y[i+j];
	}
	For(i,1,n)For(j,1,n)if(!mp[i][j])
	{
		mp[i][j]=lcm(mp[i][j],mp[i-1][j]);
		mp[i][j]=lcm(mp[i][j],mp[i+1][j]);
		mp[i][j]=lcm(mp[i][j],mp[i][j-1]);
		mp[i][j]=lcm(mp[i][j],mp[i][j+1]);
		mp[i][j]++;
		assert(used[mp[i][j]]==0);
		used[mp[i][j]]=1;
	}
	For(i,1,n)For(j,1,n)
	{
		//cerr<<mp[i][j]<<endl;
		assert(mp[i][j]<=1e15);
		if(j>1)assert(max(mp[i][j],mp[i][j-1])%min(mp[i][j],mp[i][j-1])==1);
		if(i>1)assert(max(mp[i][j],mp[i-1][j])%min(mp[i][j],mp[i-1][j])==1);
	}
	For(i,1,n)For(j,1,n)write(mp[i][j],j==n?'\n':' ');
}
int main()
{
//	file();
	input();
	init(1e4);
	work();
	return 0;
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
int dp[110][110];
int main() { 
  string s, t;
  cin >> s;
  t = s;
  reverse(t.begin(), t.end());
  int n = s.size(), cat = 0;
  for(int i = 0; i < n/2; i++) {
    if(s[i] != t[i]) cat++;
  }
  cout << cat << endl;
} 

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;
using namespace std;

int main(){
    int n, x;
    cin>>n>>x;
    int sum=0, ans=n, min_value=INF, m;
    for(int i=0; i<n; i++){
        cin>>m;
        sum+=m;
        min_value=min(min_value, m);
    }
    while(sum<=x){
        sum+=min_value;
        ans++;
    }
    cout<<ans-1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int a,b;
	cin >> a >> b;
	if(b>0){
		if(a>b){
			cout << a-b+2 << endl;
		}else{
			if(a>=0){
				cout << b-a << endl;
			}else if(abs(a)<b){
				cout << b-abs(a)+1 << endl;
			}else{
				cout << abs(a)-b+1 << endl;
			}
		}
	}else{
		if(a<=b){
			cout << b-a << endl;
		}else{
			if(a<0){
				cout << a-b+2 << endl;
			}else if(a>abs(b)){
				cout << a-abs(b)+1 << endl;
			}else{
				cout << abs(b)-a+1 << endl;
			}
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
/***
        ***Fresher***
    Md Mahfujur Rahman Khan(So..a;)
    Dept. of CSE
    CSE-28 Batch
    JU-48 Batch
    Jahangirnagar University

    FSTREAM

***/
#include<iostream>
#include<fstream>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<array>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
using namespace std;
/***PAIR***/
#define pll pair<ll,ll>
#define pcl pair<char,ll>
#define psl pair<string, ll>
#define pls pair<ll,string>
#define plc pair<ll, char>
/***MAP***/
#define mll map<ll,ll>
#define msl map<string, ll>
#define mls map<ll, string>
#define mlb map<ll,bool>
#define msb map<string,bool>
#define mcl map<char, ll>
/***VECTOR***/
#define vl vector<ll>
/*** FAST ***/
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
/***FUNCTIONS AND MACROS***/
#define IT_ ::iterator
#define F first
#define S second
#define M_P(x, y) make_pair(x, y)
#define PB(v,x) v.push_back(x)
#define PP(x) push(x)
#define RSZ(a , n) a.resize(n)
#define POB pop_back()
#define P_ pop()
#define CL_ clear()
#define LEN(s,cst) (cst)s.length()
#define SZ(s, a) (ll)s.size()
#define CNT(x) count(x)
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second
#define B_ begin()
#define E_ end()
#define F_ front()
#define t_ top()
#define IN(s, a) s.insert(a)
#define ER_  erase
#define GT(x) getline(cin , x)
#define NL_   "\n"
#define SP_ " "
#define R_0 return 0
#define R_ return

#define ul unsigned long long int
#define ll long long int
/***
//bit prime
#define most_prime_loop 1001
#define most_prime_number 1000010
#define prime_MAX_arr 1000010/64 +1
ll PRIME[prime_MAX_arr];
void Set(ll n){ll m= n%64;n/=64;ll x = 1;x <<=m;PRIME[n] |=x;return ;}
bool check(ll n){if(n==2) return true;if(n%2==0) return false;ll m= n%64;n/=64;ll x = 1;x <<=m;return !(x&PRIME[n]);}
void seivee(){fa(x, PRIME)x = 0;Set(2);for(ll i= 3; i <=most_prime_loop; i+=2){if(check(i)){for(ll j = i*i; j <=most_prime_number; j+=i){Set(j);}}}}
***/
#define TEST      ll test; cin >> test; while(test--)

/**template<typename T>inline T POW(T b, T p){T res = 1;while(p){if(p%2)res*=b;b*=b;p/=2;}return res;}**/

#define lcm(a, b) (a/__gcd(a,b))*b
#define INT(dp, v) memset(dp,v, sizeof(dp))
#define all(v) v.B_,v.E_
#define rall(v) v.rbegin(),v.rend()

#define fr(i ,a,  n) for( ll i = a; i <= n; i++)
#define fe(x, n) for( ll i = x; i <= n; i++)
#define fa(x,a)    for(auto &x : a)

#define mod(a) a%1000000007
#define pi acos(-1)


int main()
{
    FAST;
  ll x, a, b;
  cin >> x >> a>> b;
  if(a>=b) cout << "delicious";
  else if(b-a <= x) cout << "safe";
  else cout << "dangerous";
    R_0;
}



Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,found=0,len,a1=0,b1=0;
    char s[20];
    scanf("%d %d",&a,&b);
    scanf("%s",s);
    len=strlen(s);
    for(int i=0;i<len;i++)
    {
        if(s[i]=='-')
        {
            found=1;
        }
        if(found==0)
        {
            if(s[i]>='0'&&s[i]<='9')
                a1++;
        }
        else
        {
            if(s[i]>='0'&&s[i]<='9')
                b1++;
        }
    }
    if(a1==a&&b1==b)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;


}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> matrix;

void solve() {
  ll n, p;
  cin >> n >> p;
  ll ret = 1;
  for(ll i = 2; i * i <= p; i++) {
    int amt = 0;
    while(p%i==0) {
      p/=i;
      amt++;
    }
    while(amt >= n) {
      ret *= i;
      amt -= n;
    }
  }
  if(n == 1) {
    ret *= p;
  }
  cout << ret << endl;
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int h,n;
int a[1005],b[1005];
int dp[1005][20005];
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin>>h>>n;
    memset(dp,0x3f,sizeof(dp));
    dp[0][0]=0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        for(int j=0;j<=h+10000;j++){//由于可能伤害不是正好杀死，一定要预留一点伤害的量
            dp[i+1][j]=dp[i][j];
            if(j+a[i]<=h+10000)dp[i][j+a[i]]=min(dp[i][j+a[i]],dp[i][j]+b[i]);
        }
    }
    int ans=0x3f3f3f3f;
    for(int i=h;i<=h+10000;i++){
        ans=min(ans,dp[n][i]);
    }
    cout<<ans<<endl;
 
    return 0;
}

Measured memory_bytes: 78848
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		String s = scan.next();
		
		String[] data = s.split("");
		
		if(a >= data.length ) {
			System.out.println(s);
		}
		if(a < data.length){
			for(int i = 0; i < a; i++) {
				System.out.print(data[i]);
			}
			System.out.print("...");
		}
		
		

}
}


Measured memory_bytes: 35772
#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>

using namespace std;

int top=0,s[100];

void push(int x){
  s[++top]=x;
}

int pop(){
  top--;
  return s[top+1];
}

int pow2(int n){
  if(!n)return 1;
  int tmp = 1;
  while(n-->0)
    tmp *= 2;
  return tmp; 
}

int main() {
  for(;;){
    top=0;
    int c = getchar();
    if(c=='#') break;
    if(c=='w') push(90);
    if(c=='n') push(-90);

    int count = 1;
    while((c=getchar())!=('\n')){
      if(c=='w'){
	push(90);
	count++;
      }
      if(c=='n'){
	push(-90);
	count++;
      }
    }
  
    int num=pop();
    if(num<0)num=0;
  
    int popped;
    int i=1;
    for(i=1;i<count;i++){
      popped=pop();
      num = num * 2 + popped;
    }
    
    int den = pow2(i-1);

    if(num%2==0&&den>1)    
      while(num%2==0){
	num/=2;
	den/=2;
      }
    
    if(den == 1 || den == 0)
      cout << num << endl;
    else
      cout << num << "/" << den << endl;
  }

}

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

int main() {
    string str;
    int numup[100] = {}, numlow[100] = {};

    while (getline(cin, str)) {
        for (int i = 0; i < str.size(); ++i) {
            if (str[i] >= 'A' && str[i] <= 'Z') {
                ++numup[str[i] - 'A'];
            }
            else if (str[i] >= 'a' && str[i] <= 'z') {
                ++numlow[str[i] - 'a'];
            }
        }
    }
    for (int i = 0; i < 26; ++i) {
        cout << (char)('a' + i) << " : " << numup[i] + numlow[i] << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3136
// 2011/02/27 Tazoe

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

struct player{
	int num;
	int sco;
};

int main()
{
	while(true){
		string str;
		getline(cin, str);
		istringstream ist(str);
		int m;
		ist >> m;
		if(m==0)
			break;

		struct player ply[40];
		for(int i=0; i<m; i++){
			getline(cin, str);
			istringstream ist2(str);

			ist2 >> ply[i].num;
			int pin[21];
			for(int j=0; ist2 >> pin[j]; j++)
				;

			ply[i].sco = 0;
			int k = 0;
			for(int j=1; j<=9; j++){
				ply[i].sco += pin[k++];
				if(pin[k-1]==10){
					ply[i].sco += (pin[k]+pin[k+1]);
					continue;
				}
				ply[i].sco += pin[k++];
				if(pin[k-2]+pin[k-1]==10){
					ply[i].sco += pin[k];
					continue;
				}
			}
			ply[i].sco += pin[k++];
			ply[i].sco += pin[k++];
			if(pin[k-2]==10||pin[k-2]+pin[k-1]==10)
				ply[i].sco += pin[k];

		}

		for(int i=0; i<m-1; i++)
			for(int j=i+1; j<m; j++)
				if(ply[i].sco<ply[j].sco||(ply[i].sco==ply[j].sco&&ply[i].num>ply[j].num)){
					struct player tmp = ply[i];
					ply[i] = ply[j];
					ply[j] = tmp;
				}

		for(int i=0; i<m; i++)
			cout << ply[i].num << ' ' << ply[i].sco << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  cin >> n;
  if(n[0]==n[2]) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[[int(i) for i in input().split()]for j in range(n)]
cd=[[int(i) for i in input().split()]for j in range(m)]

for a,b in ab:
    check=float('inf')
    for i in range(m):
        if abs(a-cd[i][0])+abs(b-cd[i][1]) < check:
            ans=i
            check=abs(a-cd[i][0])+abs(b-cd[i][1])
    print(ans+1)

Measured memory_bytes: 3064
// include
#include <cstdint>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <array>

int main() {
  std::string name;
  std::cin >> name;
  const char* s = name.c_str();
  std::cout << s[0] << s[1] << s[2] << std::endl;
  
  return 0;
}

Measured memory_bytes: 3128
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n = ri()
li = [0]*10**5
for x in range(1, 100):
  for y in range(1, 100):
    for z in range(1, 100):
      a = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if a > 10**4 + 10:
          continue
      li[a-1] += 1
for ans in li[0:n]:
  print(ans)



Measured memory_bytes: 27968
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (ll i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (ll r = (aa)-1; r >= (bb); r--)
#define be(x) (x.begin(), x.end())
#define pb(t) push_back(t)
#define ll long long
int main()
{
	int c=0;
	string a,b;
	cin>>a>>b;
	rep(i,0,3)
	{
		if(a[i]==b[i])c++;
	}
	cout<<c<<endl;
}


Measured memory_bytes: 256
using namespace std;
#include <iostream>
#include <string.h>
#include <algorithm>

int main()
{

    int n,m,i,x, v[1010],ok,smax=-1,s,j,st,dr,mij;

    cin>>n>>m;

    while(n!=0 && m!=0)
    {
        smax=-1;
        for(i=1; i<=n; i++)
        cin>>v[i];

        sort(v+1, v+1+n);

        ok=1;
        for(i=1; i<=n && ok; i++)
        {
            x=m-v[i];
            if(x<=0) ok=0;
            st=i+1;
            dr=n;

            while(st<=dr && ok)
            {
                mij=(st+dr)/2;

                if(v[mij]==x && i!=mij)
                {
                    smax=m;
                    ok=0;
                }
                else if(v[mij]>x) dr=mij-1;
                else
                {
                    if(v[mij]+v[i]>smax && i!=mij) smax=v[mij]+v[i];
                    st=mij+1;
                }

            }


        }

        if(smax!=-1) cout<<smax<<'\n';
        else cout<<"NONE\n";

        cin>>n>>m;

    }





    return 0;
}



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

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, N) FOR(i, 0, N)

#define MOD 1000000007
#define INF 1000000000

using ll = long long int;
using namespace std;

typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

//pyteyonさんのものを拝借
// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int main() {
    int n, m; cin >> n >> m;
    vi a(m),b(m);
    rep(i,m) cin >> a[i] >> b[i];

    int ans = 0;
    rep(i,m){
        UnionFind tree(n);
        rep(j,m){
            if(i == j) continue;
            tree.merge(a[j]-1, b[j]-1);
        }
        if(tree.size(0) != n) ans++;
    }

    cout << ans;
    return 0;
}


Measured memory_bytes: 3612
#include <stdio.h>
int main(void){
	char*r="",t[8][18];
	int i=0,j,a,b,c;
	for(;~scanf("%s",t[i++&7]);)
		if(i%8==0){
			for(j=0;j<8;j++){
				a=strtol(t[j],0,2);
				if(a){
					b=a&-a;
					c=strtol(t[j+1],0,2)*2/b;
					switch(a/b){
						case 1:
							switch(c){
								case 2:r="B";break;
								case 3:r="F";break;
								case 6:r="D";break;
							}
							break;
						case 3:
							switch(c){
								case 6:r="A";break;
								case 3:r="E";break;
								case 12:r="G";break;
							}
							break;
						case 15:r="C";break;
					}
					puts(r);
					break;
				}
			}
		}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int l, r;
int ans;

signed main() {
    cin >> l >> r;
    ans = INF;
    if (r - l >= 2019) ans = 0;
    else {
        l %= 2019;
        r %= 2019;
        if (r < l) ans = 0;
        else {
            for (int j=l+1;j<=r;j++) {
                for (int i = l; i < j; i++) {
                    int cnd = (i * j) % 2019;
                    ans = min(ans, cnd);
                }
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const int INF = 7777777;

vector< vector<int> > G;
vector<int> b_size, b_dist, w_size, w_dist;
int n;


void Dfs(int v, int p, int depth = 0) {
  if(v == p) {
    return;
  }
  else {
    if(v == n) {
      depth = INF;
    }
    b_dist[v] = depth;
    b_size[v] = 1;
    for(int i = 0; i < G[v].size(); ++i) {
      if(G[v][i] != p) {
        Dfs(G[v][i], v, depth + 1);
        b_size[v] += b_size[ G[v][i] ];
      } 
    }
  }
}


void Dfs1(int v, int p, int depth = 0) {
  if(v == p) {
    return;
  }
  else {
    if(v == 1) {
      depth = INF;
    }
    w_dist[v] = depth;
    w_size[v] = 1;
    for(int i = 0; i < G[v].size(); ++i) {
      if(G[v][i] != p) {
        Dfs1(G[v][i], v, depth + 1);
        w_size[v] += w_size[ G[v][i] ];
      }
    }
  }
}

int main() {
  #ifdef _OFFLINE_
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  cin >> n;
  G.resize(n+1);
  for(int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  b_dist.resize(n + 1);
  w_dist.resize(n + 1);
  b_size.resize(n + 1);
  w_size.resize(n + 1);

  fill(b_dist.begin(), b_dist.end(), 10 * n);
  fill(w_dist.begin(), w_dist.end(), 10 * n);

  Dfs(1, -1);
  Dfs1(n, -1);

  int not_cnt = 0;
  for(int i = 2; i <= n - 1; ++i) {
    if(b_dist[i] < INF && w_dist[i] < INF &&
        b_dist[i] <= w_dist[i] && n - w_size[i] < w_size[i]) {
      cout << "Fennec";
      return 0;
    }
    if(b_dist[i] >= INF || w_dist[i] >= INF) {
      ++not_cnt;
    }
  }

  if(not_cnt == n - 2) {
    int a = 0, b = 0;
    for(int i = 1; i <= n; ++i) {
      if(b_dist[i] < INF) {
        ++a;
      }
      else {
        ++b;
      }
    }
    if(a > b) {
      cout << "Fennec";
    }
    else {
      cout << "Snuke";
    }
    return 0;
  }

  cout << "Snuke";
}

Measured memory_bytes: 13568
import math

isPrime = [True] * 60001
primes = []
def eratos(n):
    isPrime[0] = isPrime[1] = False
    for i in range(2,int(math.sqrt(n))):
        if isPrime[i]:
            j = 2 * i
            while j <= n:
                isPrime[j] = False
                j = j + i
    for i in range(2,60000):
        if isPrime[i]:
            primes.append(i)
eratos(60000)

while True:
    try:
        p = int(input())
        min = list(filter(lambda x: x < p,primes))
        max = list(filter(lambda x: x > p,primes))
        print(min[-1],max[0])
    except:
        break


Measured memory_bytes: 6408
#2019/09/29
# open(0)で再チャレンジ
input_line = open(0).readlines()
N = int(input_line[0])
s = [i.rstrip("\n") for i in input_line[1:1+N]]
M = int(input_line[1+N])
t = [i.rstrip("\n") for i in input_line[2+N:2+N+M]]

s_set = set(s)
cnt_list = []
for i in range(len(s_set)):
    ele_cnt = max(s.count(list(s_set)[i])-t.count(list(s_set)[i]), 0)
    cnt_list.append(ele_cnt)

print(max(cnt_list))

Measured memory_bytes: 3064
#if 0
2020.03.22

如果已知 A ，考虑 P 会长什么样。
对于一个 A[i] ，划分为若干极大的以左端点为最大值的区间，称为块。
一个显而易见的性质是一个块一定连续出现在 P 中。
进一步可以得到把所有块按左端点升序后拼接起来就能得到 P 。

那么问题就是统计有多少排列 P 能够被划分为若干块，这些块能够构成 A 。
首先块长不能超过 3 ，其次块长为 2 的块数不能超过块长为 1 的块数，
后者保证了这些块能够组成长为 3 的序列 A 。

接着考虑确定了 P 是由什么样的块构成的，统计 P 的方案数。
具体地，设 P 由 k 个块组成，第 i 个块的大小为 b[i] ，b 的前缀和为 s 。
那么满足这个分块方式的 P 有 n!/prod(s) 。

证明：
考虑从左到右确定排列 P 的相对权值，把块的最大值定在块的右端点。
不考虑块限制时第 i 个位置有 i 种选数方案，考虑块限制，事实上块限制只会影响到块的右端点，
这些点在选数时必须选当前最大值，那么用 n! 除掉这些点的位置乘积即可。

于是可以对于分母进行 DP ，设 f[i][j] 表示当前块长和为 i ，块长为 1 与块长为 2 的块数差为 j ，
这种情况下的分母的和，转移枚举最后一个块的大小即可。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
} read;

const int maxn = 6005;
ll f[maxn][maxn << 1];
ll inv[maxn];

int main () {
	int n = read * 3, mod = read;

	inv[1] = 1;
	for (int i = 2; i <= n; i ++)
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;

	f[0][maxn + 0] = 1;
	f[1][maxn + 1] = inv[1];
	f[2][maxn + 2] = inv[2];
	f[2][maxn - 1] = inv[2];
	for (int s = 3; s <= n; s ++)
		for (int i = maxn - s; i <= maxn + s; i ++)
			f[s][i] = (f[s - 1][i - 1] + f[s - 3][i] + f[s - 2][i + 1]) * inv[s] % mod;

	ll ans = 0;
	for (int i = maxn; i <= maxn + n; i ++)
		ans += f[n][i];
	ans %= mod;
	for (int i = 1; i <= n; i ++)
		(ans *= i) %= mod;
	printf("%lld\n", ans);
}


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

using namespace std;
typedef long long ll;
const int maxn = 100005;
ll cost[maxn],dp[maxn];

int N,K;

int main(){
    scanf("%d %d", &N, &K);
    for(int i = 0; i < N; i++){
        scanf("%lld", &cost[i]);
        dp[i] = maxn*10000;
    }
    dp[0] = 0;
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= K; j++){
            if(i-j >= 0){
                dp[i] = min(dp[i], dp[i-j] + abs(cost[i] - cost[i-j]));
            }
        }
    }
    printf("%lld", dp[N-1]);
    return 0;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

// Problem Specific Parameter:
const ll mod=1000000007LL;
const int limit=100010;
ll x[limit],y[limit];

int main(void){
	int n,m;
	cin >> n >> m;
	rep(i,n) cin >> x[i];
	rep(i,m) cin >> y[i];

	ll xaxis=0LL,yaxis=0LL;
	
	rep(i,n-1){
		ll a=i+1,b=n-a;
		ll total=1LL*a*b%mod;
		xaxis+=total*(x[i+1]-x[i])%mod;
		xaxis%=mod;
	}

	
	rep(i,m-1){
		ll a=i+1,b=m-a;
		ll total=1LL*a*b%mod;
		yaxis+=total*(y[i+1]-y[i])%mod;
		yaxis%=mod;
	}

	
	const ll ans=1LL*xaxis*yaxis%mod;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
program prob47
    implicit none
    integer :: a,b,c,d
    read(*,*) a,b,c,d

    if(a + b > c + d)then
        write(*,*) "Left"
    else if(a + b == c + d) then
        write(*,*) "Balanced"
    else    
        write(*,*) "Right"
    end if

    stop
contains
end program prob47


Measured memory_bytes: 2780