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

using namespace std;

const static int MAX_N = 10000;

int N;
int a[MAX_N];

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }

  int a_i;
  int cnt;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    a_i = a[i];
    cnt = 0;
    while (a_i % 2 == 0) {
      a_i /= 2;
      cnt += 1;
    }
    ans += cnt;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
import sys
# sys.setrecursionlimit(100000)


def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


def input_int_list():
    return [int(i) for i in input().split()]


def main():
    n, m = input_int_list()
    max_gcd = m // n
    while max_gcd > 1:
        if (m - max_gcd) % max_gcd == 0 and (m - max_gcd) // max_gcd >= n - 1:
            print(max_gcd)
            return
        else:
            max_gcd -= 1
    print(1)
    return


if __name__ == "__main__":
    main()


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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long N, long long K, std::vector<long long> h){
    REP(i, N) h[i] = (h[i] >= K ? 1 : 0);
    cout << accumulate(ALL(h), 0) << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> h(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&h[i]);
    }
    solve(N, K, std::move(h));
    return 0;
}


Measured memory_bytes: 1024
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
   fastio;
   string s,t;
   cin>>s>>t;
   ll c=0;
   for( int i=0;i<s.size();i++)
   {
       if(s[i]!=t[i])
        c++;
   }
   cout<<c<<endl;

}


Measured memory_bytes: 3792
n=input()
l=list(map(int,input().strip().split()))
ans=0
for i in range(1,len(l)-1):
  gc=0;
  lc=0;
  if(l[i] >l[i-1] or l[i]>l[i+1]):
    gc=1
  if(l[i] <l[i-1] or l[i]<l[i+1]):
    lc=1
  ans+=(gc & lc)
  #print(gc,lc,l[i])
print(ans)

Measured memory_bytes: 3064
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include <numeric>
using namespace std;
typedef unsigned long long int ulint;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=(int)1e9+7;
const llint big=(llint)(2.19e15+1)*18;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
template<class T,class U> auto LB(T& ve,U in){return lower_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto UB(T& ve,U in){return upper_bound(ve.begin(),ve.end(),in);}
template<class T,class U> auto LBI(T& ve,U in){return LB(ve,in)-ve.begin();}
template<class T,class U> auto UBI(T& ve,U in){return UB(ve,in)-ve.begin();}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
int main(void){
	int q,w,e,a,s,d,z,x,c;cin>>q>>w>>e>>a>>s>>d>>z>>x>>c;
	if(q+s!=a+w){cout<<"No"<<endl;RE;}
	if(q+d!=a+e){cout<<"No"<<endl;RE;}
	if(q+x!=z+w){cout<<"No"<<endl;RE;}
	if(s+c!=d+x){cout<<"No"<<endl;RE;}
	cout<<"Yes"<<endl;RE;
}


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

vector<pair<long long, long long> > prime_factorize(long long N) {
	vector<pair<long long, long long> > res;
	for (long long a = 2; a * a <= N; ++a) {
		if (N % a != 0) continue;
		long long ex = 0; // 指数

		 // 割れる限り割り続ける
		while (N % a == 0) {
			++ex;
			N /= a;
		}

		// その結果を push
		res.push_back({ a, ex });
	}

	// 最後に残った数について
	if (N != 1) res.push_back({ N, 1 });
	return res;
}

int main() {
	
	ll n; cin >> n;
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (i % 2 == 0) continue;
		vector<pair<long long, long long>> a_prime;  // a^x ならば { a, x }
		a_prime = prime_factorize(i);
		ll tmp = 1;
		for (int j = 0; j < a_prime.size(); j++) {
			tmp *= a_prime[j].second + 1;
		}
		if (tmp == 8) ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3548
def main():
    n = int(input())
    x = [int(xn) for xn in input().split()]
    x_sorted = sorted(x)
    idx_median = n // 2
    median_low = x_sorted[idx_median - 1]
    median_high = x_sorted[idx_median]
    for xn in x:
        print(median_high if xn <= median_low else median_low)


if __name__ == '__main__':
    main()


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


int main() {
    int N, M; cin >> N >> M;
    vector<pair<int, int>> gate_conditions(M);
    for (int i = 0; i < M; i++) {
        int L, R; cin >> L >> R;
        gate_conditions[i] = make_pair(L, R);
    }

    pair<int, int> ans_range = make_pair(0, 1e5 + 1);
    for (auto cond : gate_conditions) {
        if (ans_range.first < cond.first) {
            ans_range.first = cond.first;
        }
        if (ans_range.second > cond.second) {
            ans_range.second = cond.second;
        }
    }

    int ans;
    if (ans_range.second - ans_range.first < 0) ans = 0;
    else ans = ans_range.second - ans_range.first + 1;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007ll
using namespace std;
int n,a[100005],d[100005],c[100005],cnt[100005],f[100005],s[100005];
ll ans=1,dp[100005];
void get(int x){
    int t=0;
    ll res=1;
    cnt[x]=1;
    while(cnt[x]<2){
        x=a[x];
        ++cnt[x],++t;
        if(f[x]){
            if(t<f[x])res=0;
            else if(t>f[x])res=res*2%orz;
            t=0;
        }
    }
    (ans*=res)%=orz;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d",a+i),++d[a[i]],c[i]=1;
    queue<int> q;
    for(int i=1;i<=n;++i)if(!d[i])q.push(i);
    while(!q.empty()){
        int x=q.front();
        q.pop();
        c[x]=0;
        ++cnt[a[x]];
        if(cnt[a[x]]==d[a[x]])q.push(a[x]);
    }
    for(int i=1;i<=n;++i){
        if(d[i]-c[i]>1){
            puts("0");
            return 0;
        }
    }
    for(int i=1;i<=n;++i){
        if(!d[i]){
            int x=i,t=0;
            while(!c[x])x=a[x],++t;
            f[x]=t;
        }
    }
    memset(cnt,0,sizeof(cnt));
    for(int i=1;i<=n;++i)if(!cnt[i]&&c[i]&&f[i])get(i);
    for(int i=1;i<=n;++i){
        if(!cnt[i]&&c[i]){
            int x=i,sum=0;
            while(!cnt[x])cnt[x]=1,++sum,x=a[x];
            ++s[sum];
        }
    }
    for(int i=1;i<=n;++i){
        dp[0]=1;
        if(!s[i]) continue;
        int o;
        if(i>1&&(i&1))o=2;
        else o=1;
        for(int j=1;j<=s[i];++j){
            dp[j]=dp[j-1]*o%orz;
            if(j>1)(dp[j]+=dp[j-2]*(j-1)%orz*i)%=orz;
        }
        (ans*=dp[s[i]])%=orz;
    }
    printf("%lld\n",ans);
    //system("pause");
    return 0;
}


Measured memory_bytes: 2560
class Integer
    def !
        return 1 if self == 0
        (1..self).inject(:*)
    end
    
    def c(i)
        return 1 if i == 0
        (self-i+1..self).inject(:*) / i.!
    end
end

N, M = gets.split.map(&:to_i)
p N.c(2) + M.c(2)

Measured memory_bytes: 1788
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int descending_compare(const void *a, const void *b){
    if (*(int*)a > *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}

int ascending_compare(const void *a, const void *b){
    if (*(int*)a < *(int*)b){
        return -1;
    }else if (*(int*)a == *(int*)b){
        return 0;
    }else{
        return 1;
    }
}


int lower_bound(int *a, int n, int key){
    int left, mid, right;
    left = 0, right = n;
    mid = (left + right)/2;
    while ((left+1 != mid || mid+1 != right) && mid != left){
        if (key > a[mid]){
            left = mid;
        }else{
            right = mid+1;
        }
        mid = (left + right)/2;
    }
    if (a[left] >= key)return left;
    if (a[mid] >= key)return mid;
    if (a[right] >= key)return right;
    return n;
}

//greatest common divisor
unsigned long  gcd(unsigned long x, unsigned long y){
    if (y == 0){ 
        return x;
    }else if (x > y){
        return gcd(y, x % y);
    }else{
        return gcd(x, y % x);
    }
}



long long factorial(int x){
    long long rtn = 1;
    int i;
    for (i = x; i > 1; i--){
        rtn = (rtn*i);
    }
    return rtn;
}

char a[105];
char b[105];

int main(void){
    scanf("%s %s", a, b);
    int alen = strlen(a);
    int blen = strlen(b);
    if (alen > blen){
        printf("GREATER\n");
        return 0;
    }else if (alen < blen){
        printf("LESS\n");
        return 0;
    }else{
        for (int i = 0; i < alen; i++){
            if (a[i] > b[i]){
                printf("GREATER\n");
                return 0;
            }else if (a[i] < b[i]){
                printf("LESS\n");
                return 0;
            }
        }
        printf("EQUAL\n");
        return 0;
    }

    return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<int> h(n);
  REP(i, n) cin >> h[i];
  int ans = 0;
  int cur = 0;
  while(1){
    int i = 0;
    int count = 0;
    while(i < n){
      int j = i;
      while(i < n && h[i] > cur)i++;
      if(j != i)count++;
      while(i < n && h[i] <= cur)i++;
    }
    if(!count) break;
    ans += count;
    cur++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b[a];
  for(int i=0;i<a;i++)
    cin>>b[i];
  sort(b,b+a);
  for(int i=0;i<a-1;i++){
      if(b[i]==b[i+1]){
        cout<<"NO"<<endl;
        return 0;
      }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define N 100001

int Partition( int A[], int p, int r );

int main(){
  int A[N];
  int n, i, q;
  
  scanf("%d", &n);
  
  for( i=0 ; i<n ; i++ ) scanf("%d", &A[i]);
  
  q = Partition( A, 0, n-1 );
  
  for( i=0 ; i<n ; i++ ){
    if( i==q ){
      printf("[%d] ", A[i]);
    }
    else if( i!=n-1 ) {
      printf("%d ", A[i]);
    }
    else printf("%d", A[i]);
  }
  printf("\n");
  
  return 0;
}

int Partition( int A[], int p, int r ){
  int i, j, x, y, z;
  
  x = A[r]; 
  i = p-1;

  for( j=p ; j<r ; j++ ){
    if( A[j]<=x ){
      i++;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }
  
  z = A[i+1];
  A[i+1] = A[r];
  A[r] = z;
  
  return i+1;
}

Measured memory_bytes: 992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/

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

	string s;
	cin >> s;

	s[3] = '8';

	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long y = sc.nextLong();
		for(long i = 0 ; i <= n ; i++) {
			for(long j = 0 ; i + j <= n ; j++) {
				for(long k = 0 ; i + j + k <= n ; k++) {
					if(i * 10000 + j * 5000 + k * 1000 == y && i + j + k == n) {
						System.out.println(i + " " + j + " " + k);
						return;
					}
				}
			}
		}
		System.out.println(-1 + " " + -1 + " " + -1);
	}
}


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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "H"
#define FALSE__ "D"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif

int n;

signed main()
{
	init();
	solve();
}

void init()
{
	cin >> n;
}

void solve()
{
	int res = n * 800 - (n / 15) * 200;
	cout << res << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
int main()
{
  char a[10];
  int i, max,len;

    scanf("%s", a);
  int count[10];
  for(i=0;i<10;i++){
    if(a[i]=='A' || a[i]=='G' || a[i]=='T' || a[i]=='C'){
      count[i]=1;
    } else {
      count[i]=0;
    }
  }
  
  
  for(i=1;i<10;i++){
    if(count[i]!=0){
      count[i]=count[i-1]+1;
    }
  }
  /*
    for(i=0;i<10;i++){
    printf("%d",count[i]);
  }*/
  
  max=0;
  for(i=0;i<10;i++){
    if(count[i]>max){
      max=count[i];
    }
  }
  
    printf("%d",max);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<=0){
		cout<<"No"<<endl;
	}else{
		c=c-a-b;
		if(c*c>4*a*b){
			cout<<"Yes"<<endl;
		}else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 256
/*..............................................*\
Author:Kishor Kumar Paroi
Dept:CSE-1703053
email.kishor.josephite@gmail.com
RUET,BANGLADESH
\*---------------------------*/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include<bits/stdc++.h>
#include<iostream>
#include<iterator>

#define max(a,b) ((a>b)?a:b)                        //finding max
#define min(a,b) ((a<b)?a:b)                        //finding min
#define Max(a,b,c) max(a,max(b,c))                  //finding max between 3 numbers
#define Min(a,b,c) min(a,min(b,c))                  //finding min between 3 numbers
#define Pi acos(-1.0)                               //defining Pi for mathematical uses
#define Clear(a) memset(a,0,sizeof(a))              //clearing memory of an array
#define setfalse(a) memset(a,false,sizeof(a))       //setting the array into false
#define settrue(a) memset(a,true,sizeof(a))         //setting the array into true
#define clrstr(a) memset(a,'\0',sizeof(a))          //setting string array to null
#define open freopen("input.txt","r",stdin)         //opening input file
#define close freopen ("output.txt","w",stdout)     //opening output file
#define Case(a) printf("Case %d: ",a)               //printing case number
#define caseh(a) printf("Case #%d: ",a)             //printing case number having '#'
#define getcase(a) scanf("%d",&a)                   //scanning case number
#define caseloop(a,b) for(a=1;a<=b;a++)             //making case loop
#define EPS 1e-9                                    //small value for avoiding preccesion error
#define LL long long                                //long long short form
#define fori(i,n) for(int i=1;i<=n;++i)
#define forn(i,n) for(int i=0;i<n;++i)
#define sz(x) int(x.size())
#define error(x) cout<<#x<<" "<<x<<endl
#define IOS  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

//const int N=100*1000;
//const int mod=1e9+7;

//# define int min3(int a,int b,int c){return min(a,min(b,c));}
//#define int max3(int a,int b,int c){return max(a,max(b,c));}
//#define int min4(int a,int b,int c,int d){return min(min(a,b),min(c,d));}
//#define int max4(int a,int b,int c,int d){return max(max(a,b),max(c,d));}

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int a,b;cin>>a>>b;
    //int sml(a,b);
    if(a%b==0 || b%a==0)
        cout<<a+b<<endl;
    else
        cout<< abs(b-a)<<endl;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    A = list(map(int,input().split()))
    Q = int(input())
    B = [0 for i in range(Q)]
    C = [0 for i in range(Q)]
    
    A_num = [0 for i in range(10**5+1)]
    ans = 0
    for a in A:
        ans += a
        A_num[a] += 1
    
    for q in range(Q):
        b,c = map(int,input().split())
        if A_num[b] != 0:
            ans += (c-b)*A_num[b]
            A_num[c] += A_num[b]
            A_num[b] = 0
            
        print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 103112
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<vector>
#include<string>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC diagnostic error "-std=c++14"

#define isNum(a) (a>='0'&&a<='9')
#define SP putchar(' ')
#define EL putchar('\n')
#define ri register int

template<class T>
inline void in(T&);
template<class T>
inline void out(const T&);

typedef long long ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
using namespace std;

int q,n,t[500005][35],f;
char s[500005];

inline int lowbit(int x)
{
	return x&(-x);
}

inline void ud(int x,int y,int j)
{
    for (ri i=x;i<=n;i+=lowbit(i)) t[i][j]+=y;
}

inline int gs(int x,int j)
{
    int sum=0;
    for (ri i=x;i>0;i-=lowbit(i)) sum+=t[i][j];
    return sum;
}

int main()
{
	in(n);
	scanf("%s",s+1);
	for (ri i=1;i<=n;++i) ud(i,1,s[i]-'a'+1);
	in(q);
	while(q--)
	{
		in(f);
		if (f==1)
		{
			int x;char c;
			in(x);scanf("%c",&c);
			ud(x,-1,s[x]-'a'+1);
			s[x]=c;
			ud(x,1,s[x]-'a'+1);
		}
		else
		{
			int l,r,sum=0;
			in(l);in(r);
			for (ri i=1;i<=26;++i) if (gs(r,i)>gs(l-1,i)) ++sum;
			out(sum);EL;
		}
	} 
	return 0;
}

template<class T>
void in(T &Re)
{
    T k=0;
    char ch=getchar();
    int flag=1;
    while (!isNum(ch))
	{
        if (ch=='-')
		{
            flag=-1;
        }
        ch=getchar();
    }
    while (isNum(ch))
	{
        k=(k<<1)+(k<<3)+ch-'0';
        ch=getchar();
    }
    Re=flag*k;
}

template<class T>
void out(const T &Wr)
{
    if (Wr<0)
	{
        putchar('-');
        out(-Wr);
    }
	else
	{
        if (Wr<10)
		{
            putchar(Wr+'0');
        }
		else
		{
            out(Wr/10);
            putchar((Wr%10)+'0');
        }
    }
}

Measured memory_bytes: 69120
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}

template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

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

signed main(void) {
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	bool pairwise = true;

	set<int>div;
	rep(i,n){
		if(!pairwise)break;
		for (int j = 1; j * j <= a[i]; ++j) {
        	if (a[i] % j == 0) {
				auto it = div.find(j);
		   		if(it!=div.end())pairwise=false;
           		if(j!=1)div.insert(j);
		   		if(a[i]/j != j ){
					auto it2 = div.find(a[i]/j);
					if(it2!=div.end())pairwise=false;
					if(a[i]/j!=1) div.insert(a[i]/j);
				}
			}
        }
    }

	if(pairwise){
		print("pairwise coprime");
		return 0;
	}
	int pairgcd=a[0];
	rep1(i,n){
		pairgcd=gcd(pairgcd,a[i]);
	}
	if(pairgcd==1){
		print("setwise coprime");
		return 0;
	}else print("not coprime");
}

Measured memory_bytes: 11088
#include <bits/stdc++.h>
#ifdef __DEBUG__
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const deque<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const set<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll X,K,D;
void input(){
    fast_io();
    cin >> X >> K >> D;
}

int solve(){
    X = abs(X);
    if(X/D>K){
        X -= K*D;
    }
    else{
        K -= X/D;
        X %= D;
        K %= 2;
        X = min(abs(X-D*K),abs(X+D*K));
    }
    cout << X << endl;
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 3644
N = int(input())

if N <= 2:
    print(0)
    exit()
if N <= 5:
    print(1)
    exit()

A = [1,1,1]
for i in range(N - 5):
    A += A[i] + A[i+2],
ans = A[N-6] + A[N-4]
ans %= 10**9 + 7
print(ans)

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x;
  cin >> x;
  cout << 360 / gcd(360, x) << '\n';
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b;
    cin>>a>>b;
    if (a>b)
        cout<<"a > b"<<endl;
    else if (a<b)
        cout<<"a < b"<<endl;
    else
        cout<<"a == b"<<endl;
}


Measured memory_bytes: 3100
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val n = sc.nextInt()
    val k = sc.nextInt()
    val r = sc.nextInt()
    val s = sc.nextInt()
    val p = sc.nextInt()

    val t = sc.next()

    var sum = 0
    for (i in 0 until k) {
        sum += solve(n, k, i, listOf(p, s, r), t)
    }
    println(sum)
}

val dp = Array(1e5.toInt()) { Array(3) { 0 } }

fun solve(n: Int, k: Int, i: Int, sc: List<Int>, t: String): Int {


    val a = "rps"

    dp[i][a.indexOf(t[i])] = sc[a.indexOf(t[i])]

    var last = i
    for (j in i + k until n step k) {
        last = j
        for (q in 0..2) {
            var best = -1
            for (prev in 0..2) {
                if (q == prev) continue
                if (best < dp[j - k][prev]) best = dp[j - k][prev]
            }

            if (a.indexOf(t[j]) == q) best += sc[q]
            dp[j][q] = best
        }
    }

    var ans = -1
    for (q in 0..2) {
        if (ans < dp[last][q]) ans = dp[last][q]
    }
    return ans
}


class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}


Measured memory_bytes: 48088
#include <bits/stdc++.h>
#include <iomanip>
#include<algorithm>
#define ll long long
using namespace std;

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> A(M);
  for(ll i = 0; i < M; i++) {
    cin >> A.at(i);
    N -= A.at(i);
  }
  if(N >= 0) cout << N << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 3676
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(read())

def main(N):
    A = [1]
    for _ in range(100):
        A.append(A[-1] * 26)
    for n in range(1, 100):
        # n 文字のは全て使い終わった
        if N > A[n]:
            N -= A[n]
            continue
        # n 文字の中で勝負をつける
        N -= 1
        ret = []
        for _ in range(n):
            N, r = divmod(N, 26)
            ret.append(r)
        break
    ret = [chr(ord('a') + x) for x in ret]
    return ''.join(reversed(ret))

print(main(N))

Measured memory_bytes: 9108
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int main(){
  int A,B,C,D;cin>>A;
  D=A%10;
  C=A/10%10;
  B=A/100%10;
  A=A/1000;
  if(A+B+C+D==7){
    printf("%d+%d+%d+%d=7",A,B,C,D);
    return 0;
  }
  if(A+B+C-D==7){
    printf("%d+%d+%d-%d=7",A,B,C,D);
    return 0;
  }
  if(A+B-C+D==7){
    printf("%d+%d-%d+%d=7",A,B,C,D);
    return 0;
  }
  if(A-B+C+D==7){
    printf("%d-%d+%d+%d=7",A,B,C,D);
    return 0;
  }
  if(A+B-C-D==7){
    printf("%d+%d-%d-%d=7",A,B,C,D);
    return 0;
  }
  if(A-B+C-D==7){
    printf("%d-%d+%d-%d=7",A,B,C,D);
    return 0;
  }
  if(A-B-C+D==7){
    printf("%d-%d-%d+%d=7",A,B,C,D);
    return 0;
  }
  if(A-B-C-D==7){
    printf("%d-%d-%d-%d=7",A,B,C,D);
    return 0;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
using namespace std;
 
int main(){
    int K;
    int A,B;

    cin >> K;
    cin >> A >> B;

    if (B - A >= K || K == 1 ){
        cout<<"OK"<<endl;
    }
    else{
        for(int i = A; i <= B ; i++){
            if(i % K == 0){
                cout << "OK" << endl;
                return 0;
            }
        }
        cout<<"NG"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N, K;
	cin >> N >> K;
	vector<int> sum(N);
	for (auto i = 0; i < K; ++i)
	{
		int d;
		cin >> d;
		for (auto j = 0; j < d; ++j)
		{
			int A;
			cin >> A;
			--A;
			++sum[A];
		}
	}

	auto ans = 0;
	for (auto i = 0; i < N; ++i)
	{
		if (sum[i] == 0)
		{
			++ans;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
import sys
import bisect
from functools import lru_cache
from collections import defaultdict
inf = float('inf')
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**6)
def input(): return sys.stdin.readline().rstrip()
def read():
  return int(readline())
def reads():
  return map(int, readline().split())
d=read()
c=list(reads())
s=[[]for i in range(d)]
for i in range(d):
    s[i]=list(reads())
contestcount=26
last=[0 for i in range(contestcount)]
maxscore=0
backup=()
maxscore=0
for i in range(d):#日にち
  dele=0
  maxscore=-inf
  for j in range(contestcount):	
        dele-=c[j]*(i+1-last[j])
  for j in range(contestcount):#貪欲法
    hoge=0
    hoge+=s[i][j]
    hoge-=dele
    hoge+=c[j]*(i+1-last[j])
    if hoge>maxscore:
      backup=(j,last[j])
      maxscore=hoge  
    #print(score,backup)
  #maxscore=score
  last[backup[0]]=backup[1]
  print(backup[0]+1)


Measured memory_bytes: 75004
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string a[100], b[100];
	int n, m;
	cin >> n >> m;
	REP(i, n) cin >> a[i];
	REP(i, m) cin >> b[i];
	REP(i, n - m + 1) {
		REP(j, n - m + 1) {
			bool v = {};
			REP(k, m) {
				REP(l, m) {
					if (a[i + k][j + l] != b[k][l]) v = true;
				}
			}
			if (!v) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, k;
  cin >> n >> k;
  int ans = INF;
  REP(i, 1<<n){
    int m = 1;
    REP(j, n){
      if(i>>j&1) m*= 2;
      else m += k;
    }
    chmin(ans, m);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  long long i,j,k,n,m,l,a,b,c;
  long long A[101][101] = {0};
  long long B[101][101] = {0};
  long long C[101][101] = {0};

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

  for(j=0; j<n; j++) {
    for(i=0; i<m; i++) {

      scanf("%lld", &a);
      A[j][i] = a;
    
    }
  }

  for(j=0; j<m; j++){
    for(i=0;i<l;i++){
      scanf("%lld",&b);
      B[j][i] = b;
    }
  }

    for(i=0 ;i<n; i++) {
      for(j=0; j<l; j++){
	C[i][j] = 0;
	for(k=0;k<m; k++) {
	   C[i][j] += A[i][k]*B[k][j];  
	   /*    printf("%d ",C[i][j]); */
	}
	/* printf("\n"); */
      }
    }


     for(i=0; i<n; i++) {
      for(j=0; j<l; j++) {
	printf("%lld",C[i][j]);
	if(j !=l-1) {
	  printf(" ");
	}
      }
      printf("\n");
      } 

    return 0;

  }


Measured memory_bytes: 2140
H, W = map(int, input().split())
P = [input() for i in range(H)]

result = ""
vektor = [
    [-1, -1],
    [-1, 0], 
    [-1, 1], 
    [0, -1], 
    [0, 1],
    [1, -1],
    [1, 0], 
    [1, 1]
    ]

for i in range(H):
    for j in range(W):
        if P[i][j] == "#":
            result += "#"
        else:
            count = 0
            for k in range(8):
                try:
                    if i+vektor[k][0] >= 0 and j+vektor[k][1] >= 0 and P[i+vektor[k][0]][j+vektor[k][1]] == "#":
                        count += 1
                except IndexError:
                    pass
            result += str(count)

start = 0
for i in range(0, H*W+1, W):
    print(result[start:i])
    start = i

Measured memory_bytes: 3064
using System.Linq;
using System;

public class hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        string[] line2 = Console.ReadLine().Trim().Split(' ');
        var b = Array.ConvertAll(line2, int.Parse);
        Console.WriteLine(Math.Max(a.Sum(), b.Sum()));
    }
}

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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

int op(int a, int b) { return max(a, b); }

int e() { return 0; }

int target;

void solve(long long N, long long K, std::vector<long long> A){
    int MAX_A = 300000 + 1;
    vector<int> a(MAX_A);
    atcoder::segtree<int, op, e> seg(MAX_A);
    rep(i,0,N) {
        int maxLen = seg.prod(max<int>(0,A[i]-K), min<int>(MAX_A, A[i]+K+1));
        seg.set(A[i], maxLen+1);
    }
    cout << seg.all_prod() << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, K, std::move(A));
    return 0;
}


Measured memory_bytes: 11992
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10 , P = 1e9 + 7;
inline void pp(int &x,int d) {if((x+=d)>=P) x-=P;}
inline int mul(int a,int b) {return ll(a)*b%P;}
int n , m , s , t;
vector<pii> g[N];

vector<pair<ll,int> > getdis(int s) {
  vector<pair<ll,int> > res(n , mp(1ll<<62 , 1));
  res[s] = mp(0 , 1);
  priority_queue<pair<ll,int> > Q;
  Q.push(mp(0 , s));
  while(sz(Q)) {
    ll d = -Q.top().fi;
    int c = Q.top().se;
    Q.pop();
    if(res[c].fi == d) {
      for(auto e : g[c]) {
        ll nd = d + e.se;
        int t = e.fi;
        if(nd < res[t].fi)
          res[t] = mp(nd , res[c].se) ,
            Q.push(mp(-res[t].fi , t));
        else if(nd == res[t].fi)
          pp(res[t].se , res[c].se);
      }
    }
  }
  return res;
}

int main(){
  scanf("%d%d",&n,&m);
  scanf("%d%d",&s,&t);
  --s;--t;
  rep(i,0,m) {
    int u , v , d;
    scanf("%d%d%d",&u,&v,&d);
    --u;--v;
    g[u].pb(mp(v,d));
    g[v].pb(mp(u,d));
  }
  vector<pair<ll,int> > fs(getdis(s)) , ft(getdis(t));
  ll mindis = fs[t].fi;
  int ans(mul(fs[t].se , fs[t].se));
  vi ok(n , 0);
  rep(i,0,n) ok[i] = fs[i].fi + ft[i].fi == mindis;
  rep(i,0,n) if(ok[i] && fs[i].fi * 2 == mindis)
    pp(ans , P - mul(mul(fs[i].se , fs[i].se) , mul(ft[i].se , ft[i].se)));
  rep(i,0,n) if(ok[i] && fs[i].fi < mindis / 2) {
    for(auto e : g[i]) {
      int j = e.fi;
      if(ok[j] && fs[i].fi + e.se == fs[j].fi && fs[j].fi > mindis / 2)
        pp(ans , P - mul(mul(fs[i].se , fs[i].se) , mul(ft[j].se , ft[j].se)));
    }
  }
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 15060
# ABC 116 D
import heapq

N, K = map(int, input().split())
sushi = []
for _ in range(N):
    t, d = map(int, input().split())
    sushi.append((d, t))
sushi = sorted(sushi, reverse=True)

# 貪欲にとる.
keep = []  # 各種類のsushiでおいしさ最大のものを保存
exchange = []  # 取り替える用 (種類がかぶっているものが入る). priority queue
types = set() # keepに入っているsushiの種類
for i in range(K):
    d, t = sushi[i]
    if t not in types:
        keep.append(d)
        types.add(t)
    else:
        heapq.heappush(exchange, d)

basic_point_1 = sum(keep)
basic_point_2 = sum(exchange)
types_bonus = len(types)
ans = basic_point_1 + basic_point_2 + types_bonus**2

# 種類が増えるようにおいしさ最大のものから交換していく.
for i in range(K, N):
    if len(exchange) == 0:  # 取り替えると種類が減るので終了.
        break
    d, t = sushi[i]
    if t in types:
        continue
    types.add(t)
    basic_point_1 += d
    basic_point_2 -= heapq.heappop(exchange) # おいしさ最小のものと交換.
    types_bonus += 1
    ans = max(ans, basic_point_1 + basic_point_2 + types_bonus**2)

print(ans)

Measured memory_bytes: 19584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mx *max_element
#define mn *min_element
#define fo(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define rfo(i,n) for(ll i=n-1;i>=0;i--)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define precision cout<<fixed<<setprecision(10)
#define mem(x,p) memset(x,p,sizeof(x))
#define w(t) ll t;cin>>t;while(t--)
#define kk "\n"
#define setbits(x) __builtin_popcountll(x)
const double pi=3.1415926535897932384626;
//const ll mod = 998244353;
const ll mod=1e9+7;
int main()
{
  IOS
  string s;
  cin>>s;
  ll n=s.length();
  for(ll i=0;i<n;i++)
  {
  	if(s[i]=='?')
  	cout<<"D";
  	else
  	cout<<s[i];
  }
  return 0;
}

Measured memory_bytes: 3788
#include <stdio.h>
int main(){
  int m=0,n,cnt=0,i=0,j;
  scanf("%d",&n);
    j=n;
   while(n!=0){
    n = n / 10;
    ++cnt;
  }
    while(cnt>0){
      m=j/10;
      i=m*10;
      if(j-i==7){
        printf("Yes\n");
        return 0;
      }
        cnt--;
        j=m;
    }

        printf("No\n");
}


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

int main() {
    int n;
    cin >> n;
    
    vector<string> s(n);
    int cnt = 0; 
    rep(i, n){
        cin >> s[i];
        if(s[i] == "Y"){
            cout << "Four" << endl;
            break;
        }
        cnt++;
    }
    if(cnt == n) cout << "Three" << endl;
    
}

Measured memory_bytes: 3640
a,b,c,d = [int(s) for s in input()]

def f(a,b,op):
	if op:return a+b
	else:return a-b

t=False
for i in range(2):
	for j in range(2):
		for k in range(2):
			if f(f(f(a,b,i),c,j),d,k) == 7:
				t=True
				break
		if t:break
	if t:break

dic={0:'-', 1:'+'}
for u,v in zip([a,b,c],[i,j,k]):
	print(u,dic[v],sep='',end='')
print(d,'=7',sep='')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES 
#include<iomanip> 
#include<cmath>  
#include<iostream>
#include<fstream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<queue>
#include<deque>
#include<stack>
using namespace std;
typedef long long ll;
#define repi(i,a,b) for(ll i = (ll)(a) ; i < (ll)(b) ; i++)
#define repd(i,a,b) for(ll i = (ll)(a) ; i > (ll)(b) ; i--)
#define rd(x) cin >> x
#define wr(x)  cout << x
#define wrln(x) cout << x << endl
#define wl() cout << endl
const ll MAX_10p5 = 100010;
const ll MAX_10p9 = 1000000010;
const ll MAX_10p18 = 1000000000000000010;
const ll MOD = 1000000007;
const ll m4x[4] = { 1,0,-1,0 };
const ll m4y[4] = { 0,1,0,-1 };
const ll m8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const ll m8y[8] = { 0,1,1,1,0,-1,-1,-1 };
const ll m9x[9] = { 1,1,0,-1,-1,-1,0,1,0 };
const ll m9y[9] = { 0,1,1,1,0,-1,-1,-1,0 };

struct edge {
	ll from, to, cost;
	bool operator<(const edge& right) const {
		return cost < right.cost;
	}
};
struct point {
	ll x, y;
	bool operator<(const point& right) const {
		return x == right.x ? y < right.y : x < right.x;
	}
};

///////////////////////////////////////////////////////////////////////////////////////

ll N, M;
ll c[30];
ll dp[MAX_10p5];

int main() {
	cin >> N >> M;
	repi(i, 0, M) rd(c[i]);
	repi(i, 0, N + 1) dp[i] = MAX_10p18;
	dp[0] = 0;

	repi(i, 0, N) {
		repi(j, 0, M) {
			dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
		}
	}

	wrln(dp[N]);

	return 0;
}



Measured memory_bytes: 3560
n=int(input())
a=list(map(int,input().split()))
ans=[]
if n%2==0:
    for i in range(n//2):
        ans.append(a[n-1-2*i])
    for i in range(n//2):
        ans.append(a[2*i])
else:
    for i in range(n//2+1):
        ans.append(a[n-1-2*i])
    for i in range(n-n//2-1):
        ans.append(a[1+2*i])

ans = map(str,ans)
print(' '.join(ans))

Measured memory_bytes: 29764
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int N,K,P;
	cin>>N;
	for (int A=0;A<N;A++){
		cin>>K>>P;
		if (K<P) cout<<K<<endl;
		else{
			if (K%P==0) cout<<P<<endl;
			else cout<<K%P<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define fd(i,a,b)for(int i=b,_e=a;i>=_e;--i)
#define ll long long
using namespace std;
int n,k,d,p[55],sz[55],w[55],su,ans;
ll m[55],f[125100],g[125100],dl[125100];
vector<int>e[55];
void dfs(int x){
	sz[x]=1;
	for(int i:e[x])dfs(i),sz[x]+=sz[i],m[x]+=m[i];
}
bool cmp(int x,int y){
	ll a=m[x]*sz[y],b=m[y]*sz[x];
	return a<b||a==b&&sz[x]<sz[y];
}
int main(){
	cin>>n>>k>>d;
	fo(i,1,n){
		cin>>m[i];
		if(i>1)cin>>p[i],e[p[i]].push_back(i);
		w[i]=i;
	}
	dfs(1);
	sort(w+1,w+n+1,cmp);
	fo(i,1,n)su+=min(n,i==1?n:d)*sz[i];
	fo(i,1,su)f[i]=1e18;
	fo(i,1,n){
		if(i==1){
			fo(j,sz[i],su)f[j]=min(f[j],f[j-sz[i]]+m[i]);
		}else{
			int lim=min(n,d),s=sz[i];
			fo(k,0,s-1){
				int l=1,r=0;
				fo(j,0,su/s-(su%s<k)){
					for(;l<=r&&f[j*s+k]-f[dl[r]*s+k]<=m[i]*(j-dl[r]);)--r;
					dl[++r]=j;
					if(j-dl[l]>lim)++l;
					g[j*s+k]=f[dl[l]*s+k]+m[i]*(j-dl[l]);
				}
			}
			memcpy(f,g,8*(su+1));
		}
	}
	fo(i,0,su)if(f[i]<=k){
		int cnt=i,a=k-f[i];
		fo(j,1,n){
			int x=w[j],g=x==1?1e9:d-min(n,d);
			if(a<=m[x]*g){
				cnt+=a/m[x]*sz[x];
				break;
			}
			cnt+=g*sz[x];a-=m[x]*g;
		}
		ans=max(ans,cnt);
	}
	cout<<ans;
}

Measured memory_bytes: 1792