akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
//const int mod= int(1e9)+7;
const int mod=998244353;
using P = pair<int,int>;
using Pl= pair<ll,ll>;
using ld=long double;
using V=vector<int>;
using Vl=vector<ll>;
using VV=vector<vector<int>>;
using VVl=vector<vector<ll>>;

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) val += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};
using mint = Fp<mod>;

int main(){
    int n,k;cin >>n>>k;
    vector<mint>dp(n+1,0);
    dp[0]=1;dp[1]=-1;
    V l(k);
    V r(k);
    for (int i = 0; i < k; ++i) {
        cin >>l[i]>>r[i];
        r[i]++;
    }
    for (int i = 1; i < n; ++i) {
        dp[i]+=dp[i-1];
        for (int j = 0; j < k; ++j) {
            if(i-l[j]>=0){
                dp[i]+=dp[i-l[j]];
            }
            if(i-r[j]>=0){
                dp[i]-=dp[i-r[j]];
            }
        }
    }
    cout <<dp[n-1]<<endl;
}


Measured memory_bytes: 4836
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
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;
}
///////////////////////////////////////////////////////////////

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

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	ll N,M; cin >> N >> M;
	string S,T; cin >> S >> T;
    
	int G = gcd(N,M);
	bool ok = true;
	rep(i,G) {
		if (S[N/G*i] != T[M/G*i]) ok = false;
	}

	cout << (ok ? N/G*M : -1) << endl;
}




Measured memory_bytes: 640
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
#define pb push_back             
#define se second                
#define fi first  
#define be begin()
#define en end()
#define all(v) v.be, v.en
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
template<typename... T> void po(T... args) { ((cout << args << " "), ...); cout<<""; }
const int N = 1e5 +5;
vector<int> adj[N];
int vis[N];

void dfs(int cur){
    for(auto c : adj[cur]){
        if(vis[c]!=0)continue;
        vis[c]=1;
        dfs(c);
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
     int test=1;
     //cin>>test;
     for(int tt=1; tt<=test; tt++){
       ll n,m;
       cin>>n>>m;
       for(ll i=0; i<m; i++){
           ll u,v;
           cin>>u>>v;
           adj[u].pb(v);
           adj[v].pb(u);
       }
       ll ans=-1; 
       for(ll i=1; i<=n; i++){
           if(vis[i]==0){
            //    pp(i);
               ans++;
               vis[i]=1;
               dfs(i);
           }
       }
       pp(ans);
     //cout<<"Case #"<<tt<<": ";  
     }
 
    return 0;
}

Measured memory_bytes: 9968
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#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++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


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

  ll cnt = 0;
  while(1) {
    bool cont = false;
    for (int i = 0; i < N; i++) {
      if (A[i] >= N) {
        cont = true;
      }
    }
    if (!cont) break;
    ll ma_i = max_element(all(A)) - A.begin();
    ll ma = A[ma_i];
    cnt += ma / N;
    for (int i = 0; i < N; i++) {
      if (i == ma_i) {
        A[i] = ma % N;
      } else {
        A[i] += ma / N;
      }
    }

  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
class c
{
    static void Main()
    {
        var inp = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long a = inp[0], b = inp[1], c = inp[2], d = inp[3];
        a = a - 1;
        long x = LCM(c, d);
        long before = DIV(a, c) + DIV(a, d) - DIV(a, x);
        long after = DIV(b, c) + DIV(b, d) - DIV(b, x);
        Console.WriteLine(after - before);
    }
    public static long DIV(long a, long b)
    {
        return a - a / b;
    }
    public static long GCD(long a, long b)
    {
        if (a > b) return GCD(b, a);
        while (a != 0)
        {
            long temp = b % a;
            b = a;
            a = temp;
        }
        return b;
    }
    public static long LCM(long a, long b)
    {
        return a * b / GCD(a, b);
    }

}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
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; }
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
typedef long long ll;
int main(){
    string s;
    cin >> s;
    int cnt = 0;
    set<int> st;
    for (int i = 0; i < s.size();i++)
    {
        st.insert(s[i]);
        for (int j = i+1; j < s.size(); j++)
        {
            if(j==s.size())break;
            if(s[i]==s[j]){
                cnt++;
            }
        }
    }
    if(st.size()==2 && cnt==2){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys
def input(): return sys.stdin.readline().rstrip()
def I(): return int(input())
def Is(): return (int(x) for x in input().split())
def LI(): return list(Is())
def TI(): return tuple(Is())
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(S())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = 10**18
# ----------------------------------------------------------- #

n, k = Is()
A = LI()
if max(A) < k:
    print('IMPOSSIBLE')
    exit()
g = reduce(gcd, A)
if k % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 87532
#include<stdio.h>
int main(void)
{
	int n,a,b,c,i,x;
	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%d %d %d",&a,&b,&c);
			x=0;
			if(a==100 || b==100 || c==100)  x=1;
			else if((a+b)/2>=90)  x=1;
			else if((a+b+c)/3>=80)  x=1;
			else if((a+b+c)/3>=70)  x=2;
			else if((a+b+c)/3>=50 && (a>=80 || b>=80))  x=2;
			if(x==1)  printf("A\n");
			else if(x==2)  printf("B\n");
			else printf("C\n");
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 2596
#include<stdio.h>

int main(void){

  unsigned long long int h,w,sum;
  scanf("%llu %llu",&h,&w);
   sum=h*w;

  if(h==1 || w==1){
    printf("1");
  }

  else if(sum%2==0){
    printf("%lld",sum/2);
  }
  else if(sum%2!=0){
    printf("%lld",sum/2+1);
  }

  return 0;
}

Measured memory_bytes: 128
<?php
  
  fscanf(STDIN,"%d %d %d %d",$x1,$y1,$x2,$y2);


$x_dis = $x2-$x1;
$y_dis = $y2-$y1;

$x3=$x2-$y_dis;
$y3=$y2+$x_dis;

$x4=$x3-$x_dis;
$y4=$y3-$y_dis;

echo $x3." ".$y3." ".$x4." ".$y4."\n";


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

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int r;
  cin >> r;

  cout << r * r << endl;

  return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  string s;
  cin >> s;
  while(s.length()>0){
    if(s.length()>=5&&s.substr(s.length()-5,5)=="dream") {
      s = s.substr(0,s.length()-5);
      continue;
    }
    if(s.length()>=7&&s.substr(s.length()-7,7)=="dreamer") {
      s = s.substr(0,s.length()-7);
      continue;
    }
    if(s.length()>=5&&s.substr(s.length()-5,5)=="erase") {
      s = s.substr(0,s.length()-5);
      continue;
    }
    if(s.length()>=6&&s.substr(s.length()-6,6)=="eraser") {
      s = s.substr(0,s.length()-6);
      continue;
    }
    break;
  }
  if(s.length()>0){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
W,H,x,y,r = input().split()
W = int(W)
H = int(H)
x = int(x)
y = int(y)
r = int(r)

if x < 0 or y < 0:
    print("No")

else:
    if W - x >= r and H - y >= r:
        print("Yes")
    else:
        print("No")

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


int main(){
int A;
cin>>A;
int X = A;
vector<int> H(A);
rep(i,A)cin>>H.at(i);
int count = 0;
while (A > 0){
    int now_count = 0;
    for(int n = 0;n<A-1;n++){
        if(H.at(n)>=H.at(n+1))now_count++;
        else break;
    }
    count = max(count,now_count);
    H.erase(H.begin(),H.begin()+(now_count+1));
    A-=(now_count+1);
}
cout<<count<<endl;

}

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

int parent(int i){return i/2;
} 

int left(int i){return 2*i;
}

int right(int i){return 2*i+1;
}

int main(){
	int H,i,A[MAX+1];
	
	cin>>H;
	
	for(i=1;i<=H;i++){
		cin>>A[i];
	}
	
	for(i=1;i<=H;i++){
		cout<<"node "<<i<<": key = "<<A[i]<<", ";
		if(parent(i)>=1) cout<<"parent key = "<<A[parent(i)]<<", ";
		if(left(i)<=H) cout<<"left key = "<<A[left(i)]<<", ";
		if(right(i)<=H) cout<<"right key = "<<A[right(i)]<<", "; 
		cout<<endl;
	}
	return 0;
}

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


int main() {
	ll x;
	cin >> x;
	for (int i = x;i <= 100010;++i) {
		int cnt = 0;
		for (int j = 2;j < x;++j) {
			if (i % j == 0) {
				cnt++;
			}
			if (cnt > 0) {
				break;
			}
		}
		if (cnt == 0) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long N,A,B;
    cin>>N>>A>>B;
    long long quotient=N/(A+B);
    long long remainder=N%(A+B);

    long long bball=quotient*A;
    if(remainder>A)
        bball+=A;
    else
        bball+=remainder;
    cout<<bball;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>

#define IOS ios::sync_with_stdio(false); cin.tie(0)

using namespace std;

int main()
{
	int n;
	cin >> n;
	int xorsum=0;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		xorsum ^= a[i];
	}
	for (int i = 0; i < n; i++)
	{
		int tmp = xorsum ^ a[i];
		cout << tmp << " ";
	}
}

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

int main(){
  string s; cin >> s;
  int ans = s.size();
  int ss = 0;
  for(char i : s){
    if(i=='S') ss++;
    else if(ss){
      ss--;
      ans -= 2;
    }
  }
  cout << ans;
}


Measured memory_bytes: 640
//*********************Cr!TikaL**********************//
//*****|||||******|||||*******||||||******|||||*****//

#include<iostream>
#include<algorithm>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef double db;

typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<string> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;

#define endl "\n"
#define si(x)    scanf("%d",&x)
#define sl(x)    scanf("%lld",&x)
#define ss(s)    scanf("%s",s)
#define pi(x)    printf("%d\n",x)
#define pl(x)    printf("%lld\n",x)
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound

#define rep(qqq,ttt,www) for(int qqq = ttt; qqq < www; qqq++)
#define repe(qqq,ttt,www) for(int qqq = ttt; qqq <= www; qqq++)
#define rev(qqq,ttt,www) for(int qqq = www; qqq > 0; qqq--)
#define reve(qqq,ttt,www) for(int qqq = www; qqq >= 0; qqq--)

#define setp(x,y) cout << setprecision(x) << y << endl
#define deb(x) cout << #x << " --- " << x << endl
#define TT template<class T
#define Tt template<typename... T

Tt> void read(T&... a){((cin >> a), ... );}
Tt> void write(T&... a){((cout << a << " "), ... );cout << endl;}

ll getInt(string s){stringstream ss;ss << s;int p;ss >> p;return p;}
string getStr(long long int a){stringstream ss;ss << a;string s;ss >> s;return s;}
TT> T inline min(T& a,T& b){if( a <= b)return a;else return b;}
TT> T inline max(T& a,T& b){if( a >= b)return a;else return b;}
TT> T inline min3(T& a,T& b,T& c){if (a <= b && a <= c)return a;else if (b <= a && b <= c)return b;else return c;}
TT> T inline max3(T& a,T& b,T& c){if (a >= b && a >= c)return a;else if (b >= a && b >= c)return b;else return c;}

const int MOD = 1e9+7;
const int MX = 2e5+5;
const ll INF = 1e18;


int main()
{

    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll n;
    cin >> n;

    ll arr[n];

    ll p = 0, q = 0, r = 0;
    for(ll i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    for(int i = 1; i < n; i++)
    {
        if(arr[i] < arr[i-1])
        {
            p += arr[i-1]-arr[i];
            arr[i] += arr[i-1]-arr[i];
        }
    }
    cout << p << endl;

    return 0;

}


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

using namespace std;

#define ll long long
#define ld long double

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

	// 右の方が大きいところがk箇所
	for (int k = 0; k < n; ++k) {
		ll low = (ll)c * k - (ll)d * (n - 1 - k);
		ll up = (ll)d * k - (ll)c * (n - 1 - k);
		if (low <= (b - a) && (b - a) <= up) {
			cout << "YES" << endl;
			exit(0);
		}
	}

	cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
S = input()
MOD = 10**9 + 7

ans, C = 0, Counter(S)
for i in range(N):
    sub_ans = 1
    for x in C:
        if x != S[i]:
            sub_ans = ((C[x] + 1) * sub_ans) % MOD
    ans = (ans + sub_ans) % MOD
    C[S[i]] -= 1
print(ans)

Measured memory_bytes: 9524
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n, m;
  cin >> n >> m;
  vl a(n), b(n);
  map<ll, vl> mp;
  rep(i, n) {
    cin >> a[i] >> b[i];
    mp[a[i]].push_back(b[i]);
  }
  priority_queue<ll> que;
  ll ans = 0;
  map<ll, vl>::iterator it = mp.begin();
  REP(j, 1, m + 1) {
    while (it != mp.end() && it->first <= j) {
      // cout << "!" << endl;
      // cout << it->first << endl;
      // if (it->first == j) {
      for (auto& x : it->second) {
        que.push(x);
      }
      // }
      it++;
    }
    if (!que.empty()) {
      ll tmp = que.top();
      que.pop();
      ans += tmp;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 12416
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input()
divided_T = [[] for _ in range(K)]
for i in range(N):
    divided_T[i%K].append(T[i])
ans = 0
for target in divided_T:
    dp = [[0]*3 for _ in range(len(target))]
    dp[0][0] = R if target[0] == 's' else 0
    dp[0][1] = P if target[0] == 'r' else 0
    dp[0][2] = S if target[0] == 'p' else 0
    for i in range(1,len(target)):
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + (R if target[i] == 's' else 0)
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + (P if target[i] == 'r' else 0)
        dp[i][2] = max(dp[i-1][1],dp[i-1][0]) + (S if target[i] == 'p' else 0)
    ans += max(dp[-1])
print(ans)

Measured memory_bytes: 93344
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)

using namespace std;

int main() {
	ll n, m;
	cin >> n >> m;
	if (n >= m){cout << 0 << endl;}
	else{
	vector<ll> x(m);
	REP(i, m) {cin >> x[i];}
	sort(x.begin(), x.end());
	ll ans = *(x.end() -1) - *x.begin();
	vector<ll> d(m-1);
	REP(i, m-1){d[i] = x[i+1] - x[i];}
	sort(d.begin(), d.end());
	REP(i, n-1){ans -= d[m-2-i];}
	cout << ans << endl;
	}
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    char s;
    cin>>s;
    if(s=='A'){
        cout<<'T'<<endl;
    }
    if(s=='T'){
        cout<<'A'<<endl;
    }
    if(s=='C'){
        cout<<'G'<<endl;
    }
    if(s=='G'){
        cout<<'C'<<endl;
    }
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
  int a,b;
  cin>>a>>b;
  if(a==1||b==1){
    if(a==1&&b!=1){
      cout<<"Alice"<<endl;
    }else if(a!=1&&b==1){
      cout<<"Bob"<<endl;
    }else{
      cout<<"Draw"<<endl;
    }
  }else{
    if(a>b){
      cout<<"Alice"<<endl;
    }else if(a<b){
      std::cout << "Bob" << '\n';
    }else{
      std::cout << "Draw" << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;
static const int  MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int n;

void dfs(int u){
    V[u]=true;
    for(int i=0;i<G[u].size();i++){
        int v =G[u][i];
        if(!V[v])dfs(v);
    }
    out.push_front(u);
}

int main(){
    int s,t,q;
    
    cin>>n>>q;
    
    for(int i=0;i<n;i++)V[i]=false;
    
    for(int i=0;i<q;i++){
        cin>>s>>t;
        G[s].push_back(t);
    }
    
    for(int i=0; i<n; i++){
        if(!V[i])dfs(i);
    }
    
    for(list<int>::iterator it =out.begin();it !=out.end();it++) cout<<*it<<endl;
    
    return 0;
}


Measured memory_bytes: 6132
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n >> m;
    cout << (m*1900 + (n-m) * 100) * (int)pow(2,m) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;

int main(){
	int n;cin>>n;
	string s,t;cin>>s>>t;
	string res="";
	for(int i=0;i<n;i++){
		res+=s[i];res+=t[i];
	}	
	cout<<res;
	return 0;
}

Measured memory_bytes: 3632
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)

func main() {
	list := getStdinIntArr()
	for idx, val := range list {
		if val == 0 {
			fmt.Printf("%d\n", idx+1)
		}
	}
	fmt.Printf("\n")
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 1760
#155c
import collections
n = int(input())
s = [input() for _ in range(n)]

c = collections.Counter(s)
ret = []
tmp = []
max_v = max(c.values())

for k, v in c.most_common():
  if max_v == v:
    ret.append(k)
  else:
    break

for r in sorted(ret):
  print(r)

Measured memory_bytes: 45040
#include<bits/stdc++.h>
using namespace std;
int n,m,mx,s,t,w,k,l,p,x,y,xx,yy,b[4000],c[4000],f[21][21],d[4][2];
char a[21][21];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	d[0][0]=-1,d[0][1]=0;
	d[1][0]=1,d[1][1]=0;
	d[2][0]=0,d[2][1]=-1;
	d[3][0]=0,d[3][1]=1;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)
	    for(int j=0;j<m;j++)
	        if(a[i][j]=='.'){
				    memset(f,63,sizeof(f));p=f[1][1];
				    t=1,w=1,b[1]=i,c[1]=j;f[i][j]=0;
				    while(t<=w){
				    	x=b[t];y=c[t];
				    	for(int k=0;k<4;k++){
				    		xx=x+d[k][0];yy=y+d[k][1];
				    		if(xx>=0&&xx<n&&yy>=0&&yy<m&&a[xx][yy]=='.'&&f[x][y]+1<f[xx][yy]){
				    			w++;b[w]=xx;c[w]=yy;f[xx][yy]=f[x][y]+1;
				    		}
				    	}
				    	t++;
				    }
				    for(int k=0;k<n;k++)
				        for(int l=0;l<m;l++)
				            if(f[k][l]!=p) mx=max(mx,f[k][l]);
	            }
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 256
#動的計画法(DP)
#ブログ「けんちょんの競プロ精進記録」参考
#URL: https://drken1215.hatenablog.com/entry/2019/06/10/140000


N,M = map(int,input().split())
MOD = 1000000007
issafe = [True]*(N+1) # issafe[v]: v段目が壊れていないかどうか

for _ in range(M):
    i = int(input())
    issafe[i] = False # i 段目は壊れている

#DPテーブル
dp = [0]*(N+1)

#初期条件
dp[0] = 1
if issafe[1]:dp[1] = 1

#ループ
for n in range(2,N+1):
    if issafe[n-1]: dp[n] += dp[n-1]
    if issafe[n-2]: dp[n] += dp[n-2]
    dp[n] %= MOD

print(dp[N])


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

struct Edge {
    int to;
};
using Graph = vector<vector<Edge>>;

const int INF = 1e8;
// 幅優先探索
vector<int> dist;  // 始点からの距離を記録
vector<int> pre;
void bfs(const Graph &G, int s) {
    dist.assign((int)G.size(), INF);  // 初期化
    pre.assign((int)G.size(), -1);
    queue<int> que;
    que.emplace(s);  // sから探索する
    dist[s] = 0;
    while (que.size() != 0) {   // 幅優先探索
        int now = que.front();  // 現在の状態
        que.pop();
        for (auto e : G[now]) {
            if (dist[e.to] == INF) {  // 未探索の時のみ行う
                dist[e.to] = dist[now] + 1;
                pre[e.to] = now;
                que.emplace(e.to);
            }
        }
    }
}
/* get_path(prev, t)
    入力：dijkstra で得た prev, ゴール t
    出力： t への最短路のパス
*/
vector<int> get_path(const vector<int> &prev, int t) {
    vector<int> path;
    for (int cur = t; cur != -1; cur = prev[cur]) {
        path.push_back(cur);
    }
    reverse(path.begin(), path.end());
    return path;
}

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

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

    int V, E;
    cin >> V >> E;

    Graph G(V);
    for (int i = 0; i < E; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back({b});
        // G[b].push_back({a});
    }

    if (E == 0) {
        cout << -1 << endl;
        return 0;
    }
    int ans = INF;
    int ans_v = 0;
    int ans_i = 0;
    for (int v = 0; v < V; v++) {
        for (int i = 0; i < (int)G[v].size(); i++) {
            //cout << "ans: " << ans << endl;
            Edge e = G[v][i];
            G[v].erase(G[v].begin() + i);
            bfs(G, e.to);
            if (chmin(ans, dist[v] + 1)) {
                ans_v = v;
                ans_i = i;
            }
            G[v].insert((G[v].begin() + i), e);
        }
    }

    Edge e = G[ans_v][ans_i];
    G[ans_v].erase(G[ans_v].begin() + ans_i);
    bfs(G, e.to);
    if (dist[ans_v] == INF) {
        cout << -1 << endl;
        return 0;
    }
    cout << dist[ans_v] + 1 << "\n";
    for (auto i : get_path(pre, ans_v)) {
        cout << i + 1 << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
import math
import re
import copy

h1,m1,h2,m2,k = map(int,input().split())
w1 = h1*60 + m1
w2 = h2 * 60 + m2
w3 = (w2-w1+24*60)%(24*60)
w3 = w3 - k
print(w3)


Measured memory_bytes: 9980
#include <iostream>
#include<sstream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#define  mem memset(a,0,sizeof(a))

const int mo=1000000007;
const int inf=0x3f3f3f3f;

typedef long long ll;
using namespace std;

int main()
{
    char a[2][100];
    int n,i,j;
    cin>>n;
    cin>>a[0];
    cin>>a[1];
    int x=-1;
    ll sum=1;
    for(i=0;i<n;i++)
    {
        if(a[0][i]==a[0][i+1])
        {
            if(x==-1)
            {
                sum=sum*3*2;
                sum=sum%mo;
            }
            else if(x==1)
            {
                sum=sum*2;
                sum=sum%mo;
            }
            else if(x==0)
            {
                sum=sum*3;
                sum=sum%mo;
            }
            x=0;
        }
        else if(a[0][i]==a[1][i])
        {
            if(x==-1)
            {
                sum=sum*3;
                sum=sum%mo;
            }
            else if(x==1)
            {
                sum=sum*2;
                sum=sum%mo;
            }
            else if(x==0)
            {
                sum=sum*1;
                sum=sum%mo;
            }
            x=1;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;

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

string itob(int a) {
  string ret;
  for(int i=16; i>0; i/=2) {
    if (a>=i) {
      ret+='1';
      a-=i;
    } else
      ret+='0';
  }
  return ret;
}

int main() {
  string hoge = "ABCDEFGHIJKLMNOPQRSTUVWXYZ .,-'?";
  map<char, string> m;
  REP(i,hoge.length()) {
    //  string hage;
    // hage = hoge[i];
    m.insert(make_pair(hoge[i],itob(i)));
  }
  hoge = " ',-.?ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string hoge2[] = {"101","000000","000011","10010001","010001","000001","100101","10011010"
                 ,"0101","0001","110","01001","10011011","010000","0111","10011000"
                 ,"0110","00100","10011001","10011110","00101","111","10011111","1000"
                 ,"00110","00111","10011100","10011101","000010","10010010","10010011","10010000"};
  map<string,char> m2;
  REP(i,hoge.length())
    m2.insert(make_pair(hoge2[i],hoge[i]));
  string line;
  while(getline(cin,line)) {
    string a;
    REP(i,line.length())
      a += m[line[i]];
    string ans;
    for (int i=0; i<a.length(); i++) {
      string tmp;
      for (int j=i; j<a.length(); j++) {
        tmp += a[j];
        i = j;
        if (m2.count(tmp)) {
          ans += m2[tmp];
          break;
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
/**
 * File    : B.cpp
 * Author  : Kazune Takahashi
 * Created : 11/24/2018, 8:10:20 PM
 * Powered by Visual Studio Code
 */

#include <iostream>
#include <iomanip>   // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple>
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set>
#include <functional>
#include <random> // auto rd = bind(uniform_int_distribution<int>(0, 9), mt19937(19920725));
#include <chrono> // std::chrono::system_clock::time_point start_time, end_time;
// start = std::chrono::system_clock::now();
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end_time-start_time).count();
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <list>
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

int N, K;
ll a[1010];
ll sum[1010];
list<ll> V;

int main()
{
  cin >> N >> K;
  for (auto i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  sum[0] = 0;
  for (auto i = 0; i < N; i++)
  {
    sum[i + 1] = sum[i] + a[i];
  }
  for (auto i = 0; i <= N; i++)
  {
    for (auto j = 0; j < i; j++)
    {
      V.push_back(sum[i] - sum[j]);
    }
  }
  /*
  for (auto x : V)
  {
    cerr << x << endl;
  }
  */
  for (int i = 45; i >= 0; i--)
  {
    int cnt = 0;
    int L = V.size();
    for (auto it = V.begin(); it != V.end(); it++)
    {
      if (((*it) >> i) & 1)
      {
        cnt++;
      }
    }
    if (cnt >= K)
    {
      // cerr << "i = " << i << ", cnt = " << cnt << endl;
      auto it = V.begin();
      while (it != V.end())
      {
        ll t = *it;
        if ((t >> i) & 1)
        {
          it++;
        }
        else
        {
          it = V.erase(it);
        }
      }
    }
  }
  auto it = V.begin();
  ll ans = *it;
  for (auto i = 0; i < K; i++)
  {
    ans = ans & (*it);
    it++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 16000
n = int(input())
ans_len = 52 - n
ans = []
for i in range(4):
    for j in range(1,14):
        if i == 0:
            l = "S"
        elif i == 1:
            l = "H"
        elif i == 2:
            l = "C"
        elif i == 3:
            l = "D"
        q = "{} {}".format(l,j)
        ans.append(q)

for i in range(n):
    it = input()
    ans.pop(ans.index(it))
        
for i in range(ans_len):
    print(ans[i])


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


class UnionFind {
    vector<int> parents;

public:
    UnionFind(int N) : parents(N, -1) {}

    int find(int x) {
        if (this->parents[x] < 0)
            return x;
        return this->parents[x] = this->find(this->parents[x]);
    }

    int size(int x) {
        if(this->parents[x] >= 0) return 0;
        return -this->parents[x];
    }

    void marge(int x, int y){
        x = this->find(x);
        y = this->find(y);
        if (x == y)
            return;
        this->parents[x] += this->parents[y];
        this->parents[y] = x;
    }

    bool is_same(int x, int y) {
        return this->find(x) == this->find(y);
    }
};

int main(){
  string S;
  cin >> S;
  int N = S.size();
  S[0] = 'R';
  S[N-1] = 'L';

  UnionFind uf(N);

  for(int ii=0; ii<N; ii++){
    int jj = ii;
    jj += (S[jj]=='R') ? 1 : -1;
    jj += (S[jj]=='R') ? 1 : -1;
    uf.marge(jj, ii);
  }

  for(int ii=0; ii<N; ii++){
    if(ii!=0) cout << " ";
    cout << uf.size(ii);
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<queue>
#include<cmath>
#include<functional>
#include<vector>
#include<cstdio>
using namespace std;
double px,py,qx,qy,xx[1005],y[1005],r[1005],dist[1005];
int n;vector<pair<int,double> >x[1005];
long double dijkstra(){
	for(int i=0;i<=n+1;i++)dist[i]=9999999999.9l;dist[0]=0;
	priority_queue<pair<double,int>,vector<pair<double,int> >,greater<pair<double,int> > >Q;
	Q.push(make_pair(0.0l,0));
	while(!Q.empty()){
		int a2=Q.top().second;Q.pop();
		for(int i=0;i<(int)x[a2].size();i++){
			if(dist[x[a2][i].first]-(dist[a2]+x[a2][i].second)>=1e-6){
				dist[x[a2][i].first]=dist[a2]+x[a2][i].second;
				Q.push(make_pair(dist[x[a2][i].first],x[a2][i].first));
			}
		}
	}
	return dist[n+1];
}
int main(){
	cin>>xx[0]>>y[0]>>qx>>qy>>n;for(int i=1;i<=n;i++)cin>>xx[i]>>y[i]>>r[i];
	xx[n+1]=qx;y[n+1]=qy;
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<=n+1;j++){
			if(i==j)continue;
			long double X1=(xx[i]-xx[j])*(xx[i]-xx[j]);
			long double Y1=(y[i]-y[j])*(y[i]-y[j]);
			long double J=max(0.0l,sqrtl(X1+Y1)-r[i]-r[j]);
			x[i].push_back(make_pair(j,J));
		}
	}
	printf("%.20Lf\n",dijkstra());
	return 0;
}


Measured memory_bytes: 20592
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  string S;
  cin >> S;

  int lp = 0;
  int rp = S.size() - 1;
  int ans = 0;
  while (lp <= rp) {
    if (S[lp] != S[rp]) ans++;
    lp++;
    rp--;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
	int n,m;
	cin >> n >> m;
	std::vector<int> s(m);
	std::vector<int> c(m);
	for(int i =0;i<m;i++){
		cin >> s[i] >> c[i];
	}

	for(int num = 0; num<1000; num++){
		int flag = 1;
		string numstr = to_string(num); 

		for(int i = 0; i < m; i++){
			// printf("numstr[%d]:%x\n",s[i]-1,numstr[s[i]-1]);
			// printf("c[%d]:%x\n",i,'0'+c[i]);
			if( numstr[s[i]-1] != '0'+c[i]) flag = 0;
		}

		if(flag == 1 && numstr.length() == n){
			cout << num << endl;
			return 0;
		}
	}
	cout << -1 << endl;

	return 0;
}

Measured memory_bytes: 256
s = input().split()
n = int(s[0])
m = int(s[1])

A=[]
for i in range(n):
    row = list(map(int,input().split()))
    A.append(row)

B=[]
for i in range(m):
    B.append(int(input()))

#print(A)
#print(B)

result=[]
for i in range(n):
    sum = 0
    for j in range(m):
        #print(i,j,":",A[i][j],B[j])
        sum += A[i][j]*B[j]
    result.append(sum)

for i in range(n):
    print(result[i])


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

#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define nopos string::npos
#define fr(i,a,b) for(i=a;i<=b;i++)
#define frn(i,a,b) for(i=a;i>=b;i--)

ll n,i,j,sq,ans=100,mn=100,dig1,dig2;
int main()
{
//    debug("%d\n",ans);
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    cin>>n;
    sq=sqrt(n);
    fr(i,1,sq)
    {
        if(n%i==0)
        {
            dig1=(ll)log10(i)+1;
            ll ano=n/i;

            dig2=(ll)log10(ano)+1;

//            debug("%lld=%lld %lld=%lld\n",i,dig1,ano,dig2);

            mn=max(dig1,dig2);
            ans=min(ans,mn);
        }
    }
    cout<<ans<<'\n';

    return 0;
}

/*

If 1 + 2 + ... + t <X then you can not reach coordinate X at time t. Conversely, if 1 + 2 + ... + t ≥ X
You can show that you can reach coordinate X at time t. Indeed, let's take a subset of {1, 2, .., t} whose sum becomes X
Then, if you do so, you jump right to the subset only when it is the chosen length, otherwise do not jump
You can arrive at the coordinates X by abbreviation. Therefore, you can find such a minimum t later. This is
That one+√8X + 1
Since it becomes 2, it can be obtained by O (1) when calculated by this function. Even if we do not do that, the answer
O(√X), try t in order from the front, t (t + 1)
2 ≥ Even if you only judge X every time, the time calculation amount O (
√
X)
You can ask for an answer.
*/




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

int main() {
  int n, k;
  cin >> n >> k;
  int R, S, P;
  cin >> R >> S >> P;
  string t;
  cin >> t;
  rep(i,n-k)
    if (t[i] == t[i+k]) t[i+k] = 'n';
  int ans = 0;
  rep(i,n) {
    if (t[i] == 'r')
      ans += P;
    if (t[i] == 's')
      ans += R;
    if (t[i] == 'p')
      ans += S;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
int main(){

	int a, b, c, d, e;
	cin>>a>>b>>c>>d>>e;
	if(a < 0) cout<<(0 - a) * c + d + (b - 0) * e<<endl;
	if(a >= 0) cout<<(b - a) * e<<endl;

	return 0;
}



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

#define MAXN (200010)
#define mod (1000000007)

int n, X, Y, cnt;
int c[MAXN], w[MAXN], fact[MAXN], rfact[MAXN];
bool vis[MAXN];
std::vector<int> col[MAXN];
std::vector<int> op2;
std::vector<int> vec[MAXN];
std::map<int, int> map;

void addedge(int u, int v){
	vec[u].push_back(v);
	vec[v].push_back(u);
}

int powmod(int a, int b){
	int ret = 1;
	while(b){
		if(b & 1) ret = 1ll * ret * a % mod;
		b >>= 1;
		a = 1ll * a * a % mod;
	}
	return ret;
}

void dfs(int u){
	++ cnt;
	++ map[c[u]];
	vis[u] = true;
	for(auto v : vec[u]){
		if(vis[v]) continue;
		dfs(v);
	}
}

bool cmp(const int &a, const int &b){
	return w[a] < w[b];
}

int main(){
	scanf("%d%d%d", &n, &X, &Y);
	for(int i = 1; i <= n; ++ i){
	    scanf("%d%d", c + i, w + i);
	    col[c[i]].push_back(i);
	}
	fact[0] = 1;
	for(int i = 1; i <= n; ++ i){
		fact[i] = 1ll * fact[i - 1] * i % mod;
	}
	rfact[n] = powmod(fact[n], mod - 2);
	for(int i = n - 1; i + 1; -- i){
		rfact[i] = 1ll * rfact[i + 1] * (i + 1) % mod;
	}
	//operation 1
	for(int i = 1; i <= n; ++ i){
		if(!col[i].size()) continue;
		int sit = col[i][0];
		for(int j = 1, sz = (int)col[i].size(); j < sz; ++ j){
			if(w[sit] > w[col[i][j]]){
				sit = col[i][j];
			}
		}
		op2.push_back(sit);
		for(int j = 0, sz = (int)col[i].size(); j < sz; ++ j){
			if(sit != col[i][j] && w[sit] + w[col[i][j]] <= X){
				addedge(sit, col[i][j]);
			}
		}
	}
	//operation 2
	std::sort(op2.begin(), op2.end(), cmp);
	if(op2.size() >= 2){
		int sit1 = op2[0], sit2 = op2[1];
		if(w[sit1] + w[sit2] <= Y){
			addedge(sit1, sit2);
		}
		for(int i = 1; i <= n; ++ i){
			if(c[i] != c[sit1] && w[i] + w[sit1] <= Y){
				addedge(i, sit1);
			}
			if(c[i] != c[sit2] && w[i] + w[sit2] <= Y){
				addedge(i, sit2);
			}
		}
	}
	int ans = 1;
	for(int i = 1; i <= n; ++ i){
		if(!vis[i]){
			cnt = 0;
			map.clear();
			dfs(i);
			ans = 1ll * ans * fact[cnt] % mod;
			for(auto p : map){
				ans = 1ll * ans * rfact[p.second] % mod;
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 29940
#include <bits/stdc++.h>
using namespace std;
map<string,int> mp;
int main() {
    long test=1;
    // cin>>test;
    while(test--)
    {
	long long t,i,j,n,a,b,c,d,ans,A,B,x,y,k,one,q,l,r;
	string s,s1,s2,s3;
	cin>>n;
	int arr[125]={0},brr[125]={0};
	cin>>s;
	    for(j=0;j<s.length();j++)
	        arr[s[j]]++;
	
	for(i=1;i<n;i++)
	{
	    cin>>s;
	    for(j=0;j<s.length();j++)
	        brr[s[j]]++;
	    for(k=0;k<125;k++)
	    {
	        arr[k]=min(arr[k],brr[k]);
	    }
	    for(k=0;k<125;k++)
	    {
	        brr[k]=0;
	    }
	    cout<<" ";
	        
	}
	for(i=0;i<124;i++)
	{
	    cout<<string(arr[i],char(i));
	   //cout<<arr[i];
	}
	
	
    }

}

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

int gcd(int a,int b)
{
	return b==0?a:gcd(b,a%b);
}

int lcm(int a,int b)
{
	return a/gcd(a,b)*b;
}

int main()
{
	int a,b;
	while(cin >> a >> b)
	   cout << gcd(a,b) <<" " << lcm(a,b) <<endl;
}

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

int main(){
    int n;
    unsigned long long inp, ans = 1;
    bool minus = false;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> inp;
        if(inp == 0){
            cout << 0 <<endl;
            return 0;
        }
        if(minus)
            continue;
        if((unsigned long long)1000000000000000000 / inp < ans){
            minus = true;
        }else
            ans *= inp;
    }
    if(minus)
        cout << -1 << endl;
    else
        cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<ll>::iterator sit;
typedef map<ll,ll>::iterator mit;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	int ans = 111110;
	for(int i=-100;i<=100;i++)
	{
		int cnt=0;
		int b[3];
		b[0]=a[0]; b[1]=a[1]; b[2]=a[2];
		for(int j=0;j<3;j++)
		{
			while(b[j]<i)
			{
				b[j]+=2;
				cnt++;
			}
			while(b[j]>i)
			{
				b[j]--;
				cnt++;
			}
		}
		ans=min(ans,cnt);
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int M = 100010, N = (1 << 18) + 10, T = 100000;
int k, f[(1 << 9) + 10][M];
int w[N], v[N], n;
int dfs(int x, int t, int l){
	if (x <= k) return f[x][l] + t;
	int num = dfs(x / 2, t, l);
	if (l >= w[x]) num = max(num, dfs(x / 2, t + v[x], l - w[x]));
	return num;
}
int main(){
	read(n); 
	for (int i = 1; i <= n; i++){
		read(v[i]); read(w[i]);
	}
	k = (1 << 9) - 1;
	for (int i = 0; i < w[1]; i++) f[1][i] = 0;
	for (int i = w[1]; i <= T; i++) f[1][i] = v[1];
	for (int i = 2; i <= k; i++){
		int fa = i / 2;
		for (int j = 0; j <= T; j++)
			if (j >= w[i])
				f[i][j] = max(f[fa][j], f[fa][j - w[i]] + v[i]);
				else f[i][j] = f[fa][j];
	}
	int q, x, L;
	read(q);
	for (int i = 1; i <= q; i++){
		read(x); read(L);
		printf("%d\n", dfs(x, 0, L));
	}
    return 0;
}


Measured memory_bytes: 205492
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
bool can_make(int h, int w, const std::vector<std::vector<int>>& a_numbers, const std::vector<std::vector<int>>& b_numbers, int target, std::vector<std::vector<std::unordered_map<int, bool>>> &memo, std::vector<std::vector<std::vector<bool>>>& ensure) {
	if (h < 0 || w < 0) return false;
	if ((h + w + 1) * 80 < target) return false;
	if ((h + w) * 1.5 < a_numbers.size() + a_numbers.front().size()) return ensure[h][w][target];
	if (h == 0 && w == 0) return std::abs(a_numbers[0][0] - b_numbers[0][0]) == target;
	if (memo[h][w].find(target) != memo[h][w].end()) return memo[h][w][target];
	auto diff = std::abs(a_numbers[h][w] - b_numbers[h][w]);
	bool can = can_make(h - 1, w, a_numbers, b_numbers, std::abs(target - diff), memo, ensure) || can_make(h, w - 1, a_numbers, b_numbers, std::abs(target - diff), memo, ensure) || can_make(h - 1, w, a_numbers, b_numbers, target + diff, memo, ensure) || can_make(h, w - 1, a_numbers, b_numbers, target + diff, memo, ensure);
	return memo[h][w][target] = can;
}
int main() {
	int h, w; std::cin >> h >> w;
	std::vector<std::vector<int>> a_numbers(h, std::vector<int>(w)), b_numbers(h, std::vector<int>(w));
	std::vector<std::vector<std::vector<bool>>> forward(h, std::vector<std::vector<bool>>(w, std::vector<bool>(81 * 120, false)));
	for (auto& a_line : a_numbers) for (auto& a : a_line) std::cin >> a;
	for (auto& b_line : b_numbers) for (auto& b : b_line) std::cin >> b;
	forward[0][0][std::abs(a_numbers[0][0] - b_numbers[0][0])] = true;
	for (auto i = 0; i < h; ++i) for (auto j = 0; j < w && (i + j + 1) * 1.5 < w + h; ++j) {
		for (auto k = 0; k <= (i + j + 1) * 80; ++k) if (forward[i][j][k]) {
			if (i + 1 < h) {
				const auto diff = std::abs(a_numbers[i + 1][j] - b_numbers[i + 1][j]);
				forward[i + 1][j][k + diff] = true;
				forward[i + 1][j][std::abs(k - diff)] = true;
			}
			if (j + 1 < w) {
				const auto diff = std::abs(a_numbers[i][j + 1] - b_numbers[i][j + 1]);
				forward[i][j + 1][k + diff] = true;
				forward[i][j + 1][std::abs(k - diff)] = true;
			}
		}
	}
	std::vector<std::vector<std::unordered_map<int, bool>>> memo(h, std::vector<std::unordered_map<int, bool>>(w));
	for (auto i = 0; i <= 80; ++i) {
		if (can_make(h - 1, w - 1, a_numbers, b_numbers, i, memo, forward)) {
			std::cout << i << std::endl;
			return 0;
		}
	}
}

Measured memory_bytes: 173824