akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    ll p[n+1];
    vector<pll> v;
    rep(i,1,n+1){
        cin>>p[i];
        v.push_back({p[i],i});
    }
    multiset<ll> st;
    sort(v.begin(),v.end(),greater<pll>());
    st.insert(v[0].second);
    st.insert(v[1].second);
    
    ll ans=(n-1)*(n+1-max(v[1].second,v[0].second))*(min(v[1].second,v[0].second));
    st.insert(0);
    st.insert(n+1);
    st.insert(0);
    st.insert(n+1);
    rep(i,2,n){
        //cout<<ans<<endl;
        auto itr=st.lower_bound(v[i].second);
        ll f=*itr;itr++;
        ll ff=*itr;
        itr--;
        itr--;
        ll g=*itr;
        itr--;
        ll gg=*itr;
        ll sum=0;
        sum+=(ff-f)*(v[i].second-g);
        sum+=(f-v[i].second)*(g-gg);
        sum*=(n-i);
        ans+=sum;
        //if(i==3)cout<<f<<" "<<ff<<" "<<g<<" "<<gg<<endl;
        st.insert(v[i].second);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 7280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <atcoder/dsu>

using ll = long long;

using namespace std;

int main() {
    int n, q;
    cin >> n >> q;
    atcoder::dsu d(n);
    for (int i=0, t, u, v; i<q; i++) {
        cin >> t >> u >> v;
        if (t == 0) {
            d.merge(u, v);
        } else {
            cout << d.same(u, v) << '\n';
        }
    }
    return 0;
}

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

using PP = pair<long, long>;

int n, m;
PP p[100000];
int main() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> p[i].first >> p[i].second;
  sort(p, p + n);
  
  long sum = 0;
  for (int i = 0; i < n; ++i) {
    if (p[i].second >= m) {
      sum += p[i].first * m;
      break;
    } else {
      sum += p[i].first * p[i].second;
      m -= p[i].second;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1792
import sys
import fractions
N,K=map(int,input().split())
A=sorted(list(set(map(int,input().split()))))
N=len(A)
if N==1:
  print("POSSIBLE" if A[0] == K else "IMPOSSIBLE")
  sys.exit(0)
g=A[1]-A[0]
for i in range(1,len(A)-1):
  g = fractions.gcd(A[i+1]-A[i], g)
if K <= A[N-1] and (K-A[0]) % g == 0:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 21976
#include <iostream>
#include <vector>
#include <map>

using namespace std;

int main(){

int n, k;

cin>> n >> k;


vector <long long> a(n), sa(n+1);

sa[0] = 0;

map<long long, int> amap;
amap[0] = 1;
long long ans = 0;

for(int i=0; i<n; i++){
int tmp;
cin >> tmp;
a[i] = tmp - 1;
sa[i+1] = (sa[i] + a[i]) % k;
ans += amap[sa[i+1]];
amap[sa[i+1]] += 1;
if(i-k+2>=0) amap[sa[i-k+2]]--;
}
  
  
if(k==1) ans = 0;

cout << ans << endl;
}


Measured memory_bytes: 15872
words = lambda t : list(map(t, input().split()))

n = int(input())
xs = []
for i in range(n):
    a,b = words(int)
    xs.append((b,a))

xs.sort()

ttl = 0
succeed = True
for b,a in xs:
    ttl += a
    if ttl > b:
        succeed = False
        break

if succeed:
    print("Yes")
else:
    print("No")


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

int main() {
  int K, N;
  std::cin >> K >> N;
  int x, a;
  std::cin >> x >> a;
  int m = a-x;
  for(int i = 2; i < N; ++i) {
    int b; std::cin >> b;
    m = std::max(m, b-a); a = b;
  }
  m = std::max(m, x+K - a);
  std::cout << K - m << std::endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vll2 = vector<vector<ll>>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, n;
    cin >> h >> n;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        sum += a;
    }
    if (sum >= h) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) (a).begin(), (a).end()
#define AALL(a, n) (a), ((a) + (n))
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define MODNUM (static_cast<int>(1e9 + 7))
#define MOD(x) ((x) % MODNUM)

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

const int INF = 2e9;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

template <typename T>
int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T>
T square(T x) {
	return x * x;
}

inline int toInt(string s) {
	int v;
	istringstream sin(s);
	sin >> v;
	return v;
}

// lcm ここから
// gcd ここから
template <typename T>
T gcd(T a, T b) {
	if(a < b) {
		swap(a, b);
	}

	T r = a % b;
	while(r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}
// gcd ここまで

template <typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b; // オーバーフロー注意
}
// lcm ここまで

int main() {
	ll a, b;
	scanf("%lld %lld", &a, &b);
	printf("%lld\n", lcm(a, b));
	return 0;
}

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

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

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

    int n;
    cin >> n;

    vector<long long int> a(n), b(n), c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    vector<pair<int, int>> idx(n);

    long long int sum = 0;

    rep(i, n) {
        long long int itr_a = lower_bound(a.begin(), a.end(), b[i])-a.begin();

        long long int itr_c = c.end()-upper_bound(c.begin(), c.end(), b[i]);

        sum += itr_a * itr_c;
    }

    cout << sum << endl;
}

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

int n, pre[50], in[50], post[50], p = 0, cnt = 0;

void reconstruction(int left, int right){
  
  if(left >= right) return ;
  
  int c = pre[p++], m;
  for(int i = 0;;i++){
    if(c == in[i]){
      m = i;
      break;
    }
  }
  
  reconstruction(left, m);
  reconstruction(m + 1, right);
  
  post[cnt++] = c;
}

int main(){
  
  cin >> n;
  for(int i = 0;i < n;i++) cin >> pre[i];
  for(int i = 0;i < n;i++) cin >> in[i];
  
  reconstruction(0, n);
  
  for(int i = 0;i < n;i++){
    cout << (i?" ":"");
    cout << post[i];
  }
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3092
#include <iostream>

using namespace std;

int main()
{
    const long long MOD=1000000007;
    int h,w;
    cin >> h >> w;
    string s[h];
    for(int i=0;i<h;i++) cin >> s[i];
    long long dp[h][w];
    dp[h-1][w-1]=(s[h-1][w-1]=='.')?1:0;
    for(int i=h-2;i>=0;i--)
    {
        if(s[i][w-1]=='.') dp[i][w-1]=dp[i+1][w-1];
        else dp[i][w-1]=0;
    }
    for(int i=w-2;i>=0;i--)
    {
        if(s[h-1][i]=='.') dp[h-1][i]=dp[h-1][i+1];
        else dp[h-1][i]=0;
    }
    for(int o=h-2;o>=0;o--)
    {
        for(int i=w-2;i>=0;i--)
        {
            dp[o][i]=0;
            if(s[o+1][i]=='.') dp[o][i]+=dp[o+1][i];
            if(s[o][i+1]=='.') dp[o][i]+=dp[o][i+1];
            if(dp[o][i]>=MOD) dp[o][i]%=MOD;
        }
    }
    cout << dp[0][0] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int n;
int a[252521];
int b[252521];

int main(){
  scanf("%d",&n);
  REP(i,n)scanf("%d",a+i),--a[i];
  REP(i,n)b[a[i]]=i;
  set<int> S,T;   // p, n-p
  S.insert(n);
  T.insert(n-(-1));
  ll ans = 0;
  REP(i,n){
    int p = b[i];
    ll k = i+1;
    int r = *S.lower_bound(p);
    int l = n-*T.lower_bound(n-p);
    ll sz = r-l-1;
    ll lf = p-l-1;
    ll rg = r-p-1;
    ll add = sz*(sz+1)/2ll - lf*(lf+1)/2ll - rg*(rg+1)/2ll;
    ans += k * add;
    S.insert(p);
    T.insert(n-p);
  }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline 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;}



signed main() {

    int a[] = {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 k;
    cin >> k;
    cout << a[k-1] << endl;
  
    return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")

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

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'

using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 1e5+5, LG = 17, MOD = 1e9+7;
const int SQ = 320;
const long double EPS = 1e-7;
int n, k;
ll ans;
vector<int>adj[N];
void dfs(int node, int par){
  int cur = k - 1 - (node!=1);
  for(auto v : adj[node])if(v!=par){
    ans=ans*cur%MOD;  --cur;
    dfs(v,node);
  }
}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
  cin>>n>>k;
  f(i,1,n){
    int u, v;
    cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  ans=k;
  dfs(1,1);
  cout<<ans<<'\n';


  return 0;
}


Measured memory_bytes: 7936
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#include <set>
#include <iomanip>
#include <map>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<double> a(n);
    rep(i, n) cin >> a[i];
    double sum = 0;

    rep(i, n){
        sum += 1.0 / a[i];
    }
    cout << 1.0/sum << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
  	Scanner in = new Scanner(System.in);
    
    int n = in.nextInt();
    while (n != 0) {
      if (n % 10 == 7) {
      	System.out.println("Yes");
        break;
      }
      n /= 10;
    }
    
    if (n == 0) {
      System.out.println("No");
    }
  }
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define ff first
#define sc second
#define all(x) x.begin(), x.end()
#define sz(x) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	vector<int> nums(n);
	for(int& x : nums) cin>>x;
	int ans=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			ans+=nums[i]*nums[j];
		}
	}
	cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

int main(){
	int N,answer=1;
	cin>>N;
	string S;
	cin>>S;
	for(int i=1;i<N;i++){
		if(S[i]!=S[i-1]){
			answer++;
		}
	}
	cout<<answer;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using ll = long long int;

int main(){
    ll N; cin >> N;
    vi h(N);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }
    ll dp[N+1];
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=1; i<N-1; i++){
        dp[i+1] = min(dp[i]+abs(h[i+1]-h[i]),dp[i-1]+abs(h[i+1]-h[i-1]));
    }
    cout << dp[N-1];
}

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

int main(void)
{
    int n, a[5000];
    while (cin >> n && n!=0) {
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        int max = -1e6;
        for (int i = 0; i < n; ++i) {
            int sum = 0;
            for (int j = i; j < n; ++j) {
                sum += a[j];
                if (sum > max)
                    max = sum;
            }
        }
        cout << max << endl;
    }
    return 0;
}



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

int a[200005];

int main(void){
    int n,x;cin>>n;
    for(int i=0;i<n-1;i++){
        cin>>x;a[x]++;
    }
    for(int i=1;i<=n;i++){
        cout<<a[i]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 4416
#include "cstdio"
#include "algorithm"

struct drink
{
    double L;
    long long V;
};
drink M[4];

bool cmp(const drink& x,const drink& y)
{
    return  x.V * y.L <= y.V * x.L;
}
int main()
{
    long long N;
    while (scanf ("%lld%lld%lld%lld",&M[0].V,&M[1].V,&M[2].V,&M[3].V) != EOF)
    {
        scanf ("%lld",&N);
        for (int i=0;i<4;i++)
        {
             M[i].L = (1<<i)*0.25;
        }
        std::sort(M,M+4,cmp);
        long long a = (long long)(N/M[0].L) * M[0].V;
        if (int(M[0].L) == 2 && N&1)
        {
            a += M[1].V * (long long)(1.0 / M[1].L);
        }
        printf ("%lld\n",a);
    }
    return 0;
}


Measured memory_bytes: 128
S = input()

for i in range(1 << len(S)-1):
    f = ''
    for j in range(len(S)-1):
        f += S[j]
        if ((i >> j) & 1):
            f += '+'
        else:
            f += '-'
    f += S[-1]
    if eval(f) == 7:
        ans = f + '=7'
        print(ans)
        break


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

using namespace std;

vector<pair<long,long>>v;

int main()
{

    long long n,m;
    long long x,y;

    scanf("%lld%lld",&n,&m);

    for(int i=0;i<n;i++){
        scanf("%lld%lld",&x,&y);

        v.push_back(pair<long,long>(x,y));
    }



    sort(v.begin(),v.end());

//printf("%d %d\n",n,m);

    long long sum=0;
    long long take = 0;
    for(int i=0;i<v.size();i++){

        if(v[i].second<abs(take-m)){
            take += v[i].second;
            sum += (v[i].first*v[i].second);
        }else{
            sum = sum + (abs(take-m)*v[i].first);
            break;
        }
    }
    printf("%lld\n",sum);

    return 0;
}


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

int main(){
  int m, f, r;
while(m != -1 || f != -1 || r != -1){
  cin >> m >> f >> r;

  int s = m + f;

  if(m ==-1 && f == -1){
    break;
  }else if(m == -1 || f == -1){
    cout << "F" << endl;
  } else if(s >= 80){
    cout << "A" << endl;
  }else if(s >= 65){
    cout << "B" << endl;
  }else if(s >= 50){
    cout << "C" << endl;
  }else if(s >= 30){
    if(r >= 50){
      cout << "C" << endl;
    }else{
      cout << "D" << endl;
    }
  }else if(0 < s < 30){
    cout << "F" << endl;
  }
}
  return 0;
}



Measured memory_bytes: 3084
import java.util.*;
 
public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        String[] sp = S.split("");
        int n = sp.length;
        int[] s = new int[n];
        for(int i=0; i<n; i++) {
            s[i] = Integer.parseInt(sp[i]);
        }
        long sum = 0;
        StringBuilder sb = new StringBuilder();
        for(int i=0; i<Math.pow(2, n-1); i++) {
            sb = new StringBuilder(String.valueOf(s[0]));
            for(int j=0; j<n-1; j++) {
                if((1 & i >> j) == 1) {
                    sum += Long.parseLong(String.valueOf(sb));
                    sb = new StringBuilder();
                }
                sb.append(s[j+1]);
            }
            sum += Long.parseLong(String.valueOf(sb));
        }
        System.out.println(sum);
    }
    
    
}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rep1(i,n) for(int i = 1; i < (n); i++)

int main(){
    int n, k, p;
    cin >> n >> k;
    multiset<int> q;
    rep(i,n){
        cin >> p;
        q.insert(p);
    }
    int sum = 0;
    auto itr = q.begin();
    rep(i,k){
        sum += *itr;
        itr++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
const ll INF = 1145141919;
const ll MOD = 1000000007;
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
typedef pair<ll, P>LP;


ll cost[330][330];
ll cost2[330][330];
ll N, M, L;


int main(){

    rep(i, 330)rep(j, 330)cost[i][j] = INF;
    rep(i, 330)rep(j, 330)cost2[i][j] = INF;
    cin >> N >> M >> L;
    rep(i, M){
        ll a, b, c;
        cin >> a >> b >> c;
        cost[a][b] = c;
        cost[b][a] = c;
    }
    rep1(i, N)rep1(j, N)rep1(k, N){
        chmin(cost[j][k], cost[j][i] + cost[i][k]);
    }
    rep1(i, N)rep1(j, N)if(cost[i][j] <= L)cost2[i][j] = 1;
    rep1(i, N)rep1(j, N)rep1(k, N){
        chmin(cost2[j][k], cost2[j][i] + cost2[i][k]);
    }
    ll Q;
    cin >> Q;
    rep(q, Q){
        ll s, t;
        cin >> s >> t;
        if(cost2[s][t] == INF)cout << -1 << endl;
        else cout << cost2[s][t] - 1<< endl;
    }


    return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main(){
	int H, W, N, res;
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &N);
	if(H>W){
		res = N/H;
		N%H > 0? res+=1 : res=res; 
	}
	else{
		res = N/W;
		N%W > 0? res+=1 : res=res; 
	}
	printf("%d\n", res);
	
	return 0;
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int di(int N) {
    int ans = 0;
    string S = to_string(N);
    for(char c : S) {
        ans += c-'0';
    }
    return ans;
}

int main() {
    int N; cin >> N;
    cout << (N%di(N) == 0? "Yes":"No") << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<int> v(n);
    for(auto & a : v) cin>>a;
    int count = 0;
    for(int i=0;i<n;++i)for(int j=i+1;j<n;++j)for(int k=j+1;k<n;++k){
        if(!(v[i] + v[j] > v[k] and v[i] + v[k] > v[j] and v[j] + v[k] > v[i]) or v[i] == v[j] or v[i] == v[k] or v[j] == v[k])continue;
        {
            count++;
        }
    }
    cout << count << endl;
    return 0;
    
}

Measured memory_bytes: 3660
#include <stdio.h>
int chan(int x,int y){
    if(x==y)
        return 0;
    else
        return 1;
}

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int s = chan(a, b) + chan(a, c) + chan(b, c);
    if(s==0)
        s++;
    printf("%d\n",s);

    return 0;
}

Measured memory_bytes: 128
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int cmp(int a,int b){
	return abs(a)<abs(b);
}
int main(){
	int n,l;
	while(~scanf("%d%d",&n,&l)){
//		printf("%d %d\n",n,l);
		int a[205]={0},sum=0;
		for(int i=0;i<n;i++){
			a[i]=l+i;
			sum+=a[i];
//			printf("%d\n",a[i]);
		}
		sort(a,a+n,cmp);
//		printf("%d\n",a[0]);
		sum-=a[0];
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
import math
n,m,k=map(int,input().split())
num=210000
mod=998244353
fact=[0]*num
invfact=[0]*num
fact[0]=1
for i in range(1,num):
    fact[i]=fact[i-1]*i%mod
invfact[num-1]=pow(fact[num-1],mod-2,mod)
for i in range(num-2,-1,-1):
    invfact[i]=invfact[i+1]*(i+1)%mod
def nck(n,k):
    if n<k or k<0:
        return 0
    return fact[n]*invfact[k]*invfact[n-k]
ans=0
for i in range(k+1):
    #print(nck(n-1,i)*m*pow(m-1,n-i-1,mod)%mod)
    ans+=nck(n-1,i)*m*pow(m-1,n-i-1,mod)%mod
    ans%=mod
print(ans)

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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a % 2 != 0 && b % 2 != 0 ){
    cout << "Odd" << endl;
  }
  
  else {
    cout << "Even" <<endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int dx[]={1,0,-1,0,1,-1,-1,1,2,0,-2,0};
const int dy[]={0,1,0,-1,1,1,-1,-1,0,2,0,-2};
const int INF = 1<<30;
const double EPS = 1e-8;
#define PB push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define reps(i,j,k) for(int i = (j); i < (k); i++)
#define rep(i,j) reps(i,0,j)
#define MOD 1000000007
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
typedef pair<int,int> Pii;
typedef pair<Pii,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
bool compare(string a,string b){
    if(b.size() > a.size())return true;
    if(b.size() < a.size())return false;
    rep(i,a.size()){
        if(b[i] > a[i])return true;
        if(b[i] < a[i])return false;
    }
    return false;
}
string long_calc_p(string a,string b){
    string ans = "";
    reverse(a.begin(),a.end());
    reverse(b.begin(),b.end());
    int sz;
    int mi;
    if(a.size() > b.size()){
        sz = a.size();
        mi = b.size();
    }
    else{
        sz = b.size();
        mi = a.size();
    }
    int carry = 0;
    rep(i,sz){
        if(i >= mi){
            if(mi == a.size()){
                int tmp = b[i]-'0'+carry;
                if(tmp > 9){
                    carry = 1;
                    ans += tmp-10+'0';
                }
                else{
                    carry = 0;
                    ans += tmp+'0';
                }
            }
            else{
                int tmp = a[i]-'0'+carry;
                if(tmp > 9){
                    carry = 1;
                    ans += tmp-10+'0';
                }
                else{
                    carry = 0;
                    ans += tmp+'0';
                }
            }
        }
        else{
            int tmp = a[i]-'0'+b[i]-'0'+carry;
            if(tmp > 9){
                carry = 1;
                ans += tmp-10+'0';
            }
            else{
                carry = 0;
                ans += tmp+'0';
            }
        }
    }
    if(carry)ans+="1";
    reverse(ans.begin(),ans.end());
    return ans;
}
void getX(string str, vi &a){
	rep(i,str.size()){
		if(str[i] == 'X'){
			a.PB(i);
		}
	}
	return ;
}
string setNum(string str,vi a,int n){
	
	rep(i,a.size()){
		str[a[i]] = n+'0';
	}
	return str;
}
int main(){
	string str;
	while(cin >> str){
		string s1="",s2="",s3="";
		int index = 0;
		for( ; str[index] != '+' ; index++){
			s1 += str[index];
		}
		index++;
		for( ; str[index] != '=' ; index++){
			s2 += str[index];
		}
		index++;
		for( ; index < str.size() ; index++){
			s3 += str[index];
		}

		vi a,b,c;

		getX(s1,a);
		getX(s2,b);
		getX(s3,c);

		int ans = -1;
		rep(i,10){
			if(long_calc_p(setNum(s1,a,i),setNum(s2,b,i)) == setNum(s3,c,i)){
				ans = i;
				break;
			}
		}
		if(ans == -1)puts("NA");
		else printf("%d\n",ans);
	}
    return 0;
}

Measured memory_bytes: 1232
a = list(input())
if a[2] == a[3]:
    result_1 = True
else:
    result_1 = False
if a[4] == a[5]:
    result_2 = True
else:
    result_2 = False
if result_1 and result_2:
    print("Yes")
else:
    print("No")


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

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


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


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



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
    #endif


    int l,r,d;
    cin>>l>>r>>d;
    int ans = (r/d) - (l/d) + (!(l%d));
    cout<<ans;



    return 0;
}


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

int main(){
    int x1,x2,x3,x4,x5;
    cin>>x1>>x2>>x3>>x4>>x5;
    if(x1==0)cout<<1<<endl;
    if(x2==0)cout<<2<<endl;
    if(x3==0)cout<<3<<endl;
    if(x4==0)cout<<4<<endl;
    if(x5==0)cout<<5<<endl;
	return 0;
}


Measured memory_bytes: 3620
x = int(input())
tmp = []
for j in range(1,20):
    a = [i for i in range(100*j,105*j)]
    tmp=tmp+a

for k in range(1,20):
    b = 105*k
    tmp.append(b)

if x >= 2000:
    print(1)
else:
    if x in tmp:
        print(1)
    else:
        print(0)

Measured memory_bytes: 3060
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 100050
using namespace std;
LL read(){
	LL nm=0,fh=1; char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
LL gcd(LL x,LL y){return y==0?x:gcd(y,x%y);}
LL n,p[M],G[M],F[M],sq[31];
void win(LL x){puts(x?"Second":"First");exit(0);}
void solve(LL now){
	LL pos=0,sum=0,m=0,tot=0;
	for(LL i=1;i<=n;i++) sum+=p[i],m+=(p[i]&1),pos+=(p[i]&1)*i;
	if((sum&1)^(n&1)) win(now);
	else if(p[1]==1||m>1) win(now^1);
	for(LL i=1;i<=n;i++) tot=gcd(tot,p[i]-(p[i]&1));
	for(LL i=1;i<=n;i++) p[i]=(p[i]-(p[i]&1))/tot;
	solve(now^1);
}
int main(){
	n=read(),sq[0]=1;
	for(LL i=1;i<31;i++) sq[i]=sq[i-1]*2ll;
	for(LL i=1;i<=n;i++) p[i]=read();
	sort(p+1,p+n+1),solve(0);
	return 0;
}

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

bool go() {
  int a, b, c;
  cin >> a >> b >> c;
  if (a == b && a == c) return false;
  if (a == b || a == c || b == c) return true;
  return false;
}

int main() {
  if (go()) {
    cout << "Yes\n";
  } else {
    cout << "No\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(x...)
#endif
#define endl "\n"
#define int long long int
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define loop(i,c) for(auto i=(c).begin();i!=(c).end();i++)
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define F first
#define S second
const int mod = 1e9 + 7;

void solving() {
	int a[5];
	for (int i = 0; i < 5; i++) {
		cin >> a[i];
		if (a[i] == 0) {
			cout << i + 1 << endl;
			return;
		}
	}
}

int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// int t{}; cin >> t; while (t--)
	solving();
	return 0;
}

Measured memory_bytes: 3620
n=int(input())
a=[]
m=0
for i in range(n):
	a.append(list(map(int,input().split())))
c = [[0,0,0] for i in range(n+1)]

for i in range(n):
	for j in range(3):
		for k in range(3):
			if j == k:
				continue
			else:
				c[i+1][k] = max(c[i+1][k],c[i][j]+a[i][k])
print(max(c[n]))

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

typedef vector<int> vi; 
typedef pair<int,int> p;
typedef long long ll;
#define F first 
#define S second 
#define PB push_back 
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pmod 1000000007
#define INF 1000000000000000000
#define pi atan(1)*4
#define modi 1000000

ll res = 0; 

vector<ll> fun(200010,0);

void solve(){
	
	ll n;
	
	string s;
	
	cin >> n;
	cin >> s;
	
	ll count = 0, count1, count2; 
	
	ll me = 1;
	
	for(ll i = 0; i < n; i++){
		if(s[i] == '1')	count++;
	}
	
	count1 = count-1; count2 = count+1;
	
	ll me1 = 1, me2 = 1;
	
	ll total1 = 0, total2 = 0;
	
	ll val[n];
	
	
	for(ll i = n-1; i >= 0; i--){
		
		if(s[i] == '1'){
			
			if(count1 != 0) val[i] = me1%count1;
			if(count1 != 0) total1 = (total1 + me1%count1);
			total2 = (total2+me2%count2)%count2;
		}
		else{
			val[i] = -1*( me2%count2 );
		}
		
		if(count1 != 0) me1 = (me1+me1)%count1;
		me2 = (me2+me2)%count2; 
		
	}
		
	for(ll i = 0; i < n; i++){
		
		if(s[i] == '1'){
		
			if(count1 != 0){
				cout << fun[ (total1-val[i] + count1 )%count1 ] + 1 << endl;
			}
			else{
				cout << 0 << endl;
			} 
			
		}
		else{
			cout << fun[ (total2-val[i] + count2 )%count2 ] + 1 << endl;
		}
		
	}
	
}

int main(){
	
	ifstream fin ("text.in");
    ofstream fout ("text.out");   
	
	ll t = 1;
	
	ll count = 0,me;
	
	for(ll i = 1; i < 200000; i++){
		
		count = 0, me = i;
		
		while(me){
			
			if(me&1) count++;
			me = (me >> 1);
		}
		
		fun[i] = fun[i%count] + 1;
		
	}
			
	while(t--) solve();
	
	return 0;
}

Measured memory_bytes: 6748
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();
		
		System.out.println(count(B, C, D) - count(A-1, C, D));
		sc.close();
	}
	
	static long gcd(long a, long b) {
		return a==0 ? b : gcd(b%a, a);
	}
	
	static long lcm(long a, long b) {
		return a*b/gcd(a,b);
	}
	
	static long count(long x, long c, long d) {
		return x - x/c - x/d + x/lcm(c,d);
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


int main()
{
    int n;
    cin >> n;
    int k = n;
    int cnt = n / 100;
    cnt += 2;

    n %= 100;
    bool can = false;

    if(k > 10001){
        cout << 1;
        return 0; 
    }

    for(int a = 0; a < cnt; a++){
        for(int b = 0; b < cnt-a; b++){
            for(int c = 0; c < cnt-a-b; c++){
                for(int d = 0; d < cnt-a-b-c; d++){
                    if(100 * a + 101 * b + 102 * c + 103 * d > k) break;
                    for(int e = 0; e < cnt-a-b-c-d; e++){
                        if(100 * a + 101 * b + 102 * c + 103 * d + 104 * e > k) break;
                        for(int f = 0; f < cnt-a-b-c-d-e; f++){
                            if((b + 2 * c + 3 * d + 4 * e + 5 * f) != n) continue;
                            if((100 * a + 101 * b + 102 * c + 103 * d + 104 * e + 105 * f) == k ){
                                cout << 1 << endl;
                                return 0;
                            }
                        }
                    }
                }
            }
        }
    }
    cout << 0 << endl;



}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

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

ll n,m;
vector<pll> G[100005];
ll dist[100005];

void dijikstra(ll s){
  fill(dist,dist+n,LINF);
  dist[s]=0;
  priority_queue<pll, vector<pll>, greater<pll>> q;
  q.emplace(0,s);
  while(!q.empty()){
    pll v=q.top(); q.pop();
    if(dist[v.second]<v.first) continue;
    for(auto nv: G[v.second]){
      if(dist[nv.first]>dist[v.second]+nv.second){
        dist[nv.first]=dist[v.second]+nv.second;
        q.emplace(dist[nv.first],nv.first);
      }
    }
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll r; cin>>n>>m>>r;
  rep(i,m){
    ll a,b,c; cin>>a>>b>>c;
    G[a].emplace_back(b,c);
  }
  dijikstra(r);
  rep(i,n){
    if(dist[i]!=LINF) cout<<dist[i]<<endl;
    else cout<<"INF"<<endl;
  }
}


Measured memory_bytes: 19480
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int price = sc.nextInt();
        
        if(1000 >= price) {
            System.out.println(1000 - price);
        } else {
            int surplus = price % 1000;
            int change  = 0;
            if(0 != surplus) {
                change = 1000 - surplus;
            }
            System.out.println(change);
        }
    }
}

Measured memory_bytes: 35824
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

const int MAX_N = (1 << 17) + 1;

struct SegmentTree{
	int n;
	ll data[MAX_N*2 - 1],datb[MAX_N*2 - 1];;
	void init(int n_){
		n = 1;
		while(n<n_)n*=2;
		REP(i,2*n-1)data[i] = 0;
		REP(i,2*n-1)datb[i] = 0;
	}
	//[a,b)???x????????????
	void add(int a,int b,int x,int k,int l,int r){
		if(a <= l && r <= b){//?????????????????????[l,r)????????¨???????????´???
			data[k] += x;
		}else if(l<b && r>a){//?????????????????´???
			datb[k] += (min(r,b) - max(l,a)) * x;
			add(a,b,x,k*2+1,l,(r+l)/2);
			add(a,b,x,k*2+2,(r+l)/2,r);
		}
	}
	//[a,b)???????°?????????????????????????????????????????????\?????????????????????
	//?????????query(a,b,0,0,n)??§?????????????????????????§???????????????£??????????????????
	ll sum(int a,int b,int k,int l,int r){
		if(r <= a||b <= l)return 0;//???????????????
		if(a <= l && r <= b)return datb[k] + data[k]*(r-l);//?????????????????????[l,r)????????¨?????????
		//??¨???????????????
		ll res = data[k]*(min(r,b)-max(l,a));
		res += sum(a,b,k*2+1,l,l+(r-l)/2);
		res += sum(a,b,k*2+2,l+(r-l)/2,r);
		return res;
	}
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
	int n,q;
	cin >> n >> q;
	SegmentTree seg;
	seg.init(n);
	REP(i,q){
		int o;
		cin >> o;
		if(!o){
			int a,b,c;
			cin >> a >> b >> c;
			a--;
			seg.add(a,b,c,0,0,n);
		}else{
			int a,b;
			cin >> a >> b;a--;
			cout << seg.sum(a,b,0,0,n) << endl;
		}
	}
  return 0;
}

Measured memory_bytes: 7268
def main():
    from itertools import product, zip_longest

    s = input()

    for prod in product(['+', '-'], repeat=3):
        formula = ''
        for x, op in zip_longest(s, prod, fillvalue=''):
            formula += x + op
        if eval(formula) == 7:
            print(formula + '=7')
            return


if __name__ == '__main__':
    main()


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

struct Edge {
  int to, weight;
  Edge(int t, int w) :to(t), weight(w) {}
};

struct Tree {
  int N;
  vector<vector<Edge>> edges;

  void addEdge(int a, int b) { addEdge(a, b, 1); }
  void addEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }

  Tree(int N) :N(N), edges(N) {}

  vector<int> parent, dep;
  void setParent(int n) {
    parent = vector<int>(N, -2);
    dep = vector<int>(N, 0);
    queue<int> q;
    parent[n] = -1;
    q.push(n);
    while (!q.empty()) {
      int v = q.front(); q.pop();
      for (Edge e : edges[v]) {
        if (parent[e.to] != -2) continue;
        parent[e.to] = v;
        dep[e.to] = dep[v] + 1;
        q.push(e.to);
      }
    }
  }
};

int main() {
  int N; cin >> N;
  Tree G(N);
  rep(i, N - 1) {
    int x, y; cin >> x >> y;
    x--; y--;
    G.addEdge(x, y);
    G.addEdge(y, x);
  }

  int M; cin >> M;
  vector<int> u(M), v(M); 
  rep(i, M) {
    cin >> u[i] >> v[i];
    u[i]--; v[i]--;
  }

  vector<long long> X(N);
  vector<set<int>> S(M);
  G.setParent(0);

  rep(i, M) {;
    int a = u[i], b = v[i];
    if (G.dep[a] < G.dep[b]) swap(a, b);
    while (G.dep[a] != G.dep[b]) {
      S[i].insert(a);
      a = G.parent[a];
    }
    while (a != b) {
      S[i].insert(a);
      S[i].insert(b);
      a = G.parent[a];
      b = G.parent[b];
    }
  }

  rep(i, N) {
    for (int j = M - 1; j >= 0; j--) {
      X[i] *= 2;
      if (S[j].count(i) == 1) X[i]++;
    }
  }

  vector<long long> dp(1 << M, 0);
  dp[0] = 1;

  rep(i, N) {
    for (int bit = (1 << M) - 1;  bit >= 0;  bit--) {
      dp[bit | X[i]] += dp[bit];
    }
  }

  cout << dp[(1 << M) - 1] / 2 << endl;
}


Measured memory_bytes: 8448
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
using namespace std;

int main() {
    int N;
    cin >> N;
    map<multiset<char>, int> strMap;
    for(int i = 0; i < N; ++i)
    {
        string str;
        cin >> str;

        multiset<char> charSet;
        for(auto c : str)
        {
            charSet.insert(c);
        }
        auto it = strMap.find(charSet);
        if(it == strMap.end())
        {
            strMap[charSet] = 1;
        }
        else
        {
            ++(it->second);
        }
    }

    unsigned long long result = 0;
    for(const auto& pair : strMap)
    {
        if(pair.second > 1)
        {
            unsigned long long num = pair.second;
            result += num * (num - 1) / 2;
        }
    }
    cout << result;
}


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

ll n,m;
Vi v;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n>>m;
    ll l,r;
    v.resize(n+2);
    v[0]=0;
    rep(i,m){
        cin>>l>>r;
        v[l]++; v[r+1]--;
    }
    ll ans = 0;
    rep(i,n+1){
        v[i+1] += v[i];
    }
    rep(i,n+2){
        if(v[i+1]==m)ans++;
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define M 1000000007
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long int
#define mem(x) memset(x,0,sizeof(x))
#define setbits(x)  __builtin_popcount(x)
#define ull unsigned long long int
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define rep1(i,b,a) for(int i=b;i>a;i--)
#define all(c) (c).begin(),(c).end()
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define cps CLOCKS_PER_SEC
#define complex cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / cps << '\n';
#define db double
#define endl "\n"
#define  fbo(x) find_by_order(x)
#define  ook(x) order_of_key(x)

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os1;
typedef tree<int, null_type, greater<int>, rb_tree_tag,
            tree_order_statistics_node_update>
    os2;
inline void fast()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
 
const ll mod=(ll)(1e9)+7;
ll pmod(ll x,ll n){
  ll r=1;
  while(n)
  {
    if(n&1LL)
      r=(r*x)%mod;
    x=(x*x)%mod;
    n=n/2;
  }
  return r;
}

//think recursively also

void solve()
{  
  ll n;
  cin>>n;
  map<ll,ll>p;
  ll ans=0;
  for(ll i=1;i<=n;i++)
  {
    ll x;
    cin>>x;
    ll d=i-x;
    if(p.find(d)!=p.end())
      ans+=p[d];
    p[(i+x)]+=1;
  }
  cout<<ans;
}
int main()
{
   fast();
   // int t;
   // cin>>t;
   // for(int casee=1;casee<=t;casee++)
  { //cout<<"Case #"<<casee<<": ";
    solve();
  }
 
 
 
}

Measured memory_bytes: 16144
primes = [0, 0] + [1]*9999
for i in range(2, 101):
    if primes[i]:
        for j in range(i*i, 10001, i):
            primes[j] = 0
while True:
    n = int(input())
    if n == 0:
        break
    m = n
    while not primes[m]:
        m -= 1
    pnum = [i for i in range(m+1) if primes[i]]
    ans = 0
    for i in range(len(pnum)):
        tmp = 0
        for j in range(i, len(pnum)):
            tmp += pnum[j]
            if tmp == n:
                ans += 1
                break
            if tmp > n:
                break
    print(ans)

Measured memory_bytes: 7716