akhauriyash/Code-Regression huggingface dataset:
# 逆元
# a^{-1} mod を計算する
def mod_inv(a, m):
    return pow(a, m-2, m)


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)

    # 10C3 = (10*9*8)/(3*2*1)
    # 10*9*8 -> ans_mul
    # 3*2*1 -> ans_div
    ans_mul = 1
    ans_div = 1
    for i in range(b):
        ans_mul *= a - i
        ans_div *= i + 1
        ans_mul %= MOD
        ans_div %= MOD
    # ans_mul / ans_div をやりたい
    # ans_div の逆元を使って求める
    ans = ans_mul * mod_inv(ans_div, MOD)
    return ans


N, M = map(int, input().split())
MOD = 10**9+7
# M を素因数分解
rest = M
ans = 1
for i in range(2, int(M ** 0.5) + 1):
    cnt = 0
    while rest % i == 0:
        cnt += 1
        rest //= i
    # cnt が 2^X 1とか 3^X の X の部分
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD
if rest != 1:
    cnt = 1
    ans *= combination(N+cnt-1, N-1)
    ans %= MOD

print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vvi				vector< vi > 
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define loop(i,n)		for(int i=0;i<n;i++)
#define Loop(i,n)		for(int i=1;i<=n;i++)
#define sz(a)			(a.size())
#define all(c) 			c.begin(),c.end()
#define tr(c,i) 		for(auto i = c.begin(); i != c.end(); i++)
#define present(c,x) 	(c.find(x) != c.end())
#define cpresent(c,x) 	(find(all(c),x) != c.end())
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
 
void Gur27()
{
    ios::sync_with_stdio(0); cin.tie(0); 

}
 
int32_t main()
{
    Gur27();
    int n,k;
    cin>>n>> k;
    int v[n+1];
    Loop(i,n)
        cin>>v[i];
    int dp[n+1];
     dp[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        dp[i] = INT_MAX;
        for(int j = 1; j <= k && i-j > 0; j++)
            dp[i] = min(dp[i], dp[i-j] + abs(v[i] - v[i-j]));
    }
 
    cout << dp[n];

    
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	ll n;
	cin>>n;
	char a[n+1];
	char b[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	rp(i,1,n)cin>>b[i];
	for(int i=1;i<=n;i++){
		cout<<a[i]<<b[i];
	}cout<<endl;
	return 0;
}/*『你强归你强，我永不示弱』*/





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

using namespace std;

int main(){
    long long int N,ren=1,ans=0;
    cin >> N;
    vector<long long int> A(N),sum(N+1);
    sum[0] = 0;
    for(int i=0;i<N;i++){
        cin >> A[i];
        sum[i+1] = sum[i] + A[i];
    }

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

    for(int i=1;i<=N;i++){
        if(sum[i]==sum[i-1]){
            ren++;
        }else{
            ans += ren*(ren-1)/2;
            ren = 1;
        }
    }

    ans += ren*(ren-1)/2;

    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    string s, t;
    cin >> s >> t;

    vector<vector<int>> dp(s.length()+1, vector<int>(t.length()+1, 0));

    REP(i, s.size()){
        REP(j, t.size()){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j] + 1;
            }else{
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            }
        }
    }

    string ans = "";

    int d = dp.back().back();
    int x = s.size(), y = t.size();
    while(d > 0){
        if(dp[x][y-1] == d){
            y--;
        }else if(dp[x-1][y] == d){
            x--;
        }else{
            ans += s[x-1];
            x--;
            y--;
            d--;
        }
    }

    reverse(all(ans));
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 35584
import java.util.*;


public class Main {
    static int max = 1000000;
    static int[] queue = new int[max];
    static int tail = 0; static int head = 0;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        HashMap<Integer,HashSet<Integer>> graph = new HashMap<>();
        for (int i=1;i<=n;i++)graph.put(i,new HashSet<>());
        int[] A = new int[n];
        int[] B = new int[n];
        for (int i=1;i<n;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            graph.get(a).add(b);
            graph.get(b).add(a);
            A[i]=a;
            B[i]=b;
        }
        boolean[] seen = new boolean[n+1];
        int[] color = new int[n+1];
        color[1]=0;
        for (int i=1;i<=n;i++)seen[i]=false;
        enqueue(1);
        seen[1]=true;
        HashMap<String,Integer> ans = new HashMap<>();
        int max = 0;
        while (!isEmpty()){
            int v = dequeue();
            int count = 1;
            for (int i : graph.get(v)){
                if (!seen[i]){
                    seen[i]=true;
                    enqueue(i);
                    if (count==color[v])count++;
                    color[i]=count;
                    ans.put(v+"+"+i,count);
                    count++;
                }
            }
            max = Math.max(max,count);
        }
        System.out.println(max-1);
        for (int i=1;i<n;i++){
            if (!ans.containsKey(A[i]+"+"+B[i])){
                System.out.println(ans.get(B[i]+"+"+A[i]));
            }else {
                System.out.println(ans.get(A[i]+"+"+B[i]));
            }
        }
    }
    static void init(){head = 0; tail = 0;}
    static boolean isEmpty(){return (head==tail);}
    static boolean isFull(){return (head == (tail+1)%max);}
    static public void enqueue(int v){
        if (isFull()){
            System.out.println("error: queue is full.");
            return;
        }
        queue[tail++] = v;
        if (tail == max) tail = 0;
    }
    static public int dequeue(){
        if (isEmpty()){
            System.out.println("error: queue is empty");
            return -1;
        }
        int res = queue[head];
        ++head;
        if (head == max) head = 0;
        return res;
    }

}


Measured memory_bytes: 119728
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define sd second
#define ll long long

using namespace std;

const int maxn = 100100;
const ll oo = 1e18;

int n;
pair<ll, ll> x[maxn];
ll f[maxn][3],c;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
  //  freopen("in.txt","r",stdin);
    cin>>n>>c;
    for (int i=1;i<=n;i++) cin>>x[i].fi>>x[i].sd;
    sort(x+1,x+n+1);
    ll now=0;
   // for (int i=1;i<=n;i++) cout<<x[i].fi<<" "<<x[i].sd<<endl;
    for (int i=1;i<=n;i++) {
        now += x[i].sd;
        for (int j=1;j<=2;j++) f[i][j] = max(f[i-1][j], now - 1ll*j*x[i].fi);
    }


    ll ans = f[n][1];
    now =0;
    for (int i=n;i>=1;i--) {
        now += x[i].sd;
       // cout<<x[i].sd<<endl;
        ans = max(ans,f[i-1][1] + now - 2*(c-x[i].fi));
       // cout<<i<<" "<<ans<<" "<<f[i][1]<<endl;
        ans = max(ans,f[i-1][2] + now - (c-x[i].fi));
      //  cout<<i<<" "<<ans<<" "<<f[i][2]<<endl;
    }

    cout<<ans<<endl;

}


Measured memory_bytes: 4224
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const ll mod = 1e9+7;
const int N = 2e5+6;
void solve(){
	map<ll,ll>mp;
	int n; 
	cin>>n; 
	for(int i=0;i<n;i++){
		ll x; 
		cin>>x; 
		mp[x]++;
	}
	int m; 
	cin>>m; 
	for(int i=0;i<m;i++){
		int x; 
		cin>>x; 
		mp[x]--;
		if(mp[x]<0){
			cout<<"NO"<<endl;
			return ;
		}
	}
	cout<<"YES"<<endl;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int t=1; 
//	cin>>t; 
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 16048
#include <iostream>
#include <string>
using namespace std;
int main(){

  string S;
  cin>>S;

  int ans=0;
  if(S[0]=='R'){
  
    if(S[1]=='R'){
    
      if(S[2]=='R'){
      
        ans=3;
      }
      else{
      
        ans=2;
      }
    }
    else{
    
      ans=1;
    }
  }
  else{
  
    if(S[1]=='R'){
    
      if(S[2]=='R'){
      
        ans=2;
      }
      else{
      
        ans=1;
      }
    }
    else{
    
      if(S[2]=='R'){
      
        ans=1;
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int sum,n,minn=5000,a,b;
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	
	{
		int j=n-i;
		
		
			a=i/100000+i%100000/10000+i%10000/1000+i%1000/100+i%100/10+i%10;
			b=j/100000+j%100000/10000+j%10000/1000+j%1000/100+j%100/10+j%10;
			sum=a+b;
	        if(minn>=sum) minn=sum;
		
	}
	cout<<minn;
	return 0;
}

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

int memo[100001 * 2];

int main() {
    int N, C;
    cin >> N >> C;

    for(int i = 0; i < N; i++) {
        int s, t, c;
        cin >> s >> t >> c;
        s *= 2;
        t *= 2;
        memo[s-1]++;
        memo[t]--;
    }

    for(int i = 1; i < 100001 * 2; i++) {
        memo[i] += memo[i-1];
    }

    int ans = -1e9;
    for(int i = 0; i < 100001 * 2; i++) {
        ans = max(ans, memo[i]);
    }
    ans = min(ans, C);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    print(sum(map(lambda ai:ai-1, a)))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


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

using namespace std;
int main() {
#ifndef ONLINE_JUDGE
//	freopen("input.in", "r", stdin);
//	freopen("output.out", "w", stdout);
#endif
    int n;
    scanf("%d", &n);
    int cnt = 0;
    for(int i=0; i<n; i++){
        int cur;
        scanf("%d", &cur);
        if(cur != i+1){
            cnt++;
        }
    }
    if(cnt > 2){
        puts("NO");
    } else{
        puts("YES");
    }
    return 0;
}


Measured memory_bytes: 256
while True:
    m,f,r = map(int,input().split())

    if m == -1 and f == -1 and r == -1:
        break
    
    else:
        if m == -1 or f == -1:
            print("F")
        else:    
            s = m+f
            if s >= 80:
                print("A")
            elif s>=65:
                print("B")
            elif s>=50:
                print("C")
            elif s>=30:
                if r >= 50:
                    print("C")
                else:
                    print("D")

            else:
                print("F")


Measured memory_bytes: 5596
module IntMap = Map.Make (struct
  type t = int
  let compare = compare
end)

let rec factorize acc i n =
  if n <= 1 then acc
  else if n < i * i then n :: acc
  else if n mod i = 0 then factorize (i :: acc) i (n / i)
  else factorize acc (i + 1) n
let factorize = factorize [] 2

let rec solve x = function
  | [] -> if x = 1 then 1 else 0
  | n :: rest ->
      Array.fold_left ( + ) 0 @@
      Array.init (n + 1) @@ fun i ->
        if x mod (i + 1) <> 0 then 0
        else solve (x / (i + 1)) rest
let solve = solve 75

let () = Scanf.scanf "%d" @@ fun n ->
  Printf.printf "%d\n" @@
  solve @@
  List.map snd @@
  IntMap.bindings @@
  Array.fold_left (List.fold_left (fun pf p ->
    IntMap.add p (1 + try IntMap.find p pf with Not_found -> 0) pf)) IntMap.empty @@
  Array.init n @@ fun i -> factorize @@ i + 1


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int n, k, q;
  cin >> n >> k >> q;
  int N[100005];

  rep(i, n){
    N[i] = q;
  }

  rep(i, q){
    int a;
    cin >> a;
    N[a-1]--;
  }

  rep(i, n){
    if(N[i] < k) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
}


/*





















*/


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<iomanip>
#include<vector>
#define rep(i,a,b) for(ll i=a;i<b;i++)
using namespace std;
using ll = long long;
const int M = 100010;


int main() {
	int g=0,p=0,ans=0;
	string s;
	cin>>s;
	rep(i,0,s.size()){
		if(s[i]=='g'){
			if(g>p)p++,ans++;
			else g++;
		}
		else if(s[i]=='p')
			if(g>p)p++;
			else g++,ans--;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
n = int(input())
s = [input() for _ in range(n)]
dic = {}
for i in range(n):
    if s[i] not in dic.keys():
        dic[s[i]] = 1
    else:
        dic[s[i]] += 1
max_v = max(dic.values())
mv_str = []
for k, v in dic.items():
    if v == max_v:
        mv_str.append(k)
ans = sorted(mv_str)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 37264
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define sz size()
#define mp make_pair
#define p(x) cout<< x << " ";
#define pe(x) cout<< x << endl ;
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define el endl
#define MOD 1000000007 
#define int long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROR(i,a,b) for(int i=a;i>=b;i--)
const int N = 4e5 + 5;


int32_t main() 
{ 
    FAST;
    int n,x,y;
    cin>>n;
    vector<pair<int,int> > v(n);
    FOR(i,0,n)
    {
        cin>>x>>y;
        v[i].ff=y;
        v[i].ss=x;
    }
    sort(v.begin(),v.end());
    int sum=0,flag=0;
    FOR(i,0,n)
    {
       if(sum+v[i].ss<=v[i].ff)
       sum+=v[i].ss;
       else
       {
           flag=1;
           break;
       }
    }
    if(flag)
    cout<<"No";
    else
    cout<<"Yes";
}

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

int main(){
    int a, b, c;
    
    cin >> a >> b >> c;
    
    if((a < b) && (b < c)){
        cout << "Yes" <<endl;
    }
    else{
        cout << "No" <<endl;
    }
    
    return 0;
}


Measured memory_bytes: 3076
#include<stdio.h>
#include<stdlib.h>
struct node{
  int key;
  struct node *parent;
  struct node *right;
  struct node *left;
};
typedef struct node *Node;
Node T;
#define NIL NULL;
void Insert(int);
Node Find(int);
Node Successor(Node);
Node Minimun(Node);
void Delete(int);
void Preorder(Node);
void Inorder(Node);
int main()
{
  int n,i,key;
  char S[7];
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",S);
    if(S[0]=='i'){
      scanf("%d",&key);
      Insert(key);
    }
    else if(S[0]=='f'){
      scanf("%d",&key);
      if(Find(key)!=NULL)printf("yes\n");
      else printf("no\n");
    }
    else if(S[0]=='d'){
      scanf("%d",&key);
      Delete(key);
    }
    else{
      Inorder(T);
      printf("\n");
      Preorder(T);
      printf("\n");

    }
  }
  return 0;
}

void Insert(int key)
{
  Node y,x,z;
  y=NIL;
  x=T;
  z=malloc(sizeof(struct node));
  z->key=key;
  z->left=NIL;
  z->right=NIL;
  while(x!=NULL){
    y=x;
    if( z->key < x->key )x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NULL){
    T=z;
  }
 else if(z->key<y->key){
      y->left=z;
  }
  else{
    y->right=z;
  }
}

Node Find(int key)
{
  Node TT;
  TT=T;
  while(TT!=NULL && TT->key!=key){
    if(key<TT->key)TT=TT->left;
    else TT=TT->right;
  }
  if(TT==NULL)return NULL;
  else return TT;
}

Node Minimum(Node TT)
{
  while(TT->left!=NULL){
    TT=TT->left;
  }
  return TT;
}

Node Successor(Node Z)
{
  Node X;
  if(Z->right!=NULL)return Minimum(Z->right);
  X=Z->parent;
  while(X!=NULL && Z==X->right){
    Z=X;
    X=X->parent;
  }
  return X;
}

void Delete(int key)
{
  Node X,Y,Z=Find(key);  

  if(Z->left==NULL||Z->right==NULL)Y=Z;
  else{
     Y=Successor(Z);
  } 
  if(Y->left!=NULL)X=Y->left;
  else{
     X=Y->right;
  }
  
  if(X!=NULL)X->parent=Y->parent;
  if(Y->parent==NULL)T=X;
  else if(Y==Y->parent->left)Y->parent->left=X;
  else Y->parent->right=X;
 
  if(Y!=Z)Z->key=Y->key;
}


void Preorder(Node T)
{
  printf(" %d",T->key);
  if(T->left!=NULL){
    Preorder(T->left);
  }
  if(T->right!=NULL){
    Preorder(T->right);
  }

}

void Inorder(Node T)
{
  if(T->left!=NULL && T->right!=NULL){
    Inorder(T->left);
    printf(" %d",T->key);
    Inorder(T->right);

  }
  if(T->left!=NULL && T->right==NULL){
   Inorder(T->left);
     printf(" %d",T->key);
  }

  if(T->right!=NULL && T->left==NULL){
  printf(" %d",T->key);
 Inorder(T->right);

  }
  if(T->left==NULL && T->right==NULL)printf(" %d",T->key);

}



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

int main()
{
	int a,b;
	int sum=0,cnt=0;
	while(cin>>a>>b)
	{
		sum=0,cnt=0;
		sum=a+b;
		while(sum)
		{
			sum=sum/10;
			cnt++;
		}
		cout<<cnt<<endl;
	}
	return 0;
}

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

int main(){
    using namespace std;

    constexpr unsigned long N{200000}, reg(150);

    const auto& cmp = [](unsigned long i, unsigned long j, unsigned long k) -> void {
        cout << "< " << i << " " << j << " " << k << endl;
    };
    const auto& add = [](unsigned long i, unsigned long j, unsigned long k) -> void {
        cout << "+ " << i << " " << j << " " << k << endl;
    };
    const auto& bit_and_add = [&cmp, &add](unsigned long i, unsigned long j, unsigned long k) -> void {
        cmp(i, j, reg);
        cmp(j, i, reg + 1);
        add(reg, reg + 1, reg + 1);
        add(i, j, reg);
        cmp(reg + 1, reg, reg);
        add(k, reg, k);
    };
    const auto& binary_mul = [&bit_and_add](unsigned long i, unsigned long i_len, unsigned long j, unsigned long j_len, unsigned long k) -> void {
        for(unsigned long i_ofs{0}; i_ofs < i_len; ++i_ofs)for(unsigned long j_ofs{0}; j_ofs < j_len; ++j_ofs)bit_and_add(i + i_ofs, j + j_ofs, k + i_ofs + j_ofs);
    };
    const auto& bin_to_int = [&add](unsigned long beg, unsigned long len, unsigned long k) -> void {
        for(unsigned long i{len}; i--; ) {
            if(i + 1 != len)add(k, k, k);
            add(beg + i, k, k);
        }
    };
    const auto& zero_clear = [&cmp](unsigned long i) -> void {
        cmp(i, i, i);
    };
    const auto& one_clear = [&cmp](unsigned long i) -> void {
        cmp(2, 1, i);
    };
    const auto& bit_shift = [&add](unsigned long i, unsigned long s) -> void {
        for(unsigned long itr{0}; itr < s; ++itr)add(i, i, i);
    };
    const auto& int_to_bin = [&bin_to_int, &bit_shift, &zero_clear, &one_clear, &cmp](unsigned long idx, unsigned long i, unsigned long len) -> void {
        one_clear(reg + 2);
        for(unsigned long itr{1}; itr <= len; ++itr){
            zero_clear(reg);
            one_clear(i + len - itr);
            bin_to_int(i + len - itr, itr, reg);
            bit_shift(reg, len - itr);
            cmp(idx, reg, reg + 1);
            cmp(reg + 1, reg + 2, i + len - itr);
        }
    };

    cout << 8431 << endl;
    int_to_bin(0, 10, 30);
    int_to_bin(1, 40, 30);
    binary_mul(10, 30, 40, 30, 70);
    bin_to_int(70, 60, 2);
    return 0;
}

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

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define read()          freopen("fibsubseq.in","r",stdin)
#define write()         freopen("fibsubseq.out","w",stdout)
#define sf(n)           scanf("%d",&n)
#define sfd(n)          scanf("%lf",&n)
#define sl(x)           scanf("%I64d",&x)
#define sfl(n)          scanf("%lld", &n)
#define sfc(n)          scanf(" %c",&n)
#define sful(n)         scanf("%llu",&n)
#define ull             unsigned long long int
#define endll           pf("\n")
#define pf              printf
#define pi              acos(-1.0)
#define eps             1e-10
#define mem(a,b)        memset(a,b,sizeof(a))
#define pb              push_back
#define xx              first
#define yy              second
#define pii             pair<int, int>
#define pll             pair<ll, ll>
#define MP make_pair
#define ll              long long
#define uniq(a)      a.erase(unique(a.begin(), a.end()), a.end())

bool Check(unsigned int  N,int pos){return (bool)(N & (1LL<<pos));}
ll  Set(unsigned int N,int pos){    return N=N | (1LL<<pos);}
#define cnd tree[idx]
#define lnd tree[idx<<1]
#define rnd tree[(idx<<1)+1]
#define lndp (idx<<1),(b),((b+e)>>1)
#define rndp ((idx<<1)+1),(((b+e)>>1)+1),(e)
#define inf 1999999999
#define MX 100005
#define mod  1000000007
#define mod1 1000000009
#define var    int ii,i,j,n,k,m,z=0,c=0,t,x,y,l,r,mid
//int dx[8]={0,0,1,1,-1,-1,1,-1};  //8 direction
//int dy[8]={1,-1,1,-1,1,-1,0,0};
//int dx[4]={1,-1,0,0};  //4 direction
//int dy[4]={0,0,1,-1};

ll a[100005],dp[100005][4],b[100005],d[100005];

ll fn(ll pos,ll k,ll n)
{
    if(pos==n+1)
    {
        return 0;
    }
    ll &z=dp[pos][k];
    if(z!=-1)return z;
    z=0;
    if(k!=1)
    {
        z=max(z,a[pos]+fn(pos+1,1,n));
    }
    if(k!=2)
    {
        z=max(z,b[pos]+fn(pos+1,2,n));
    }
    if(k!=3)
    {
        z=max(z,d[pos]+fn(pos+1,3,n));
    }
    return z;
}

int main()
{
    SPEED;
    ll var;
    mem(dp,-1);
    sfl(n);
    for(i=1;i<=n;i++)sfl(a[i]),sfl(b[i]),sfl(d[i]);
    z=fn(1,0,n);
    cout<<z<<endl;
}


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

signed main()
{
  int list[3][10] = {
    {1, 3, 5, 7, 8, 10, 12},
    {4, 6, 9, 11},
    {2}
  };
  int size[3] = {7, 4, 1};
  int x, y;
  cin >> x >> y;

  for (int i = 0; i < 3; i++) {
    bool xflag = false, yflag = false;
    for (int j = 0; j < size[i]; j++) {
      if (x == list[i][j]) {
        xflag = true;
      } else if (y == list[i][j]) {
        yflag = true;
      }
    }
    if (xflag && yflag) {
      cout << "Yes" << endl;
      break;
    }
    if (i == 2) {
      cout << "No" << endl;
    }
  }

  return (0);
}

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

using namespace std;

int main(){
	long long int n,k,a,b;
	cin>>n>>k>>a>>b;
	long long int ans=0;
	if(n<=k){
		ans=n*a;
	}else{
		ans=k*a+(n-k)*b;
	}
	cout<<ans<<endl;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define f(i,x,n) for(int i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
const int MOD = 1e9 + 7, N = 2e5 + 10;
const int LINF = LLONG_MAX;

int sub(int x, int y) {
    x -= y;
    if (x < 0) return x + MOD;
    return x;
}
int add(int x, int y) {
    x += y;
    if (x >= MOD) return x - MOD;
    return x;
}
int multiply(int a,int b){
    return (a*b)%MOD;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin >> n >> k;

    int ans = 0;
    int n1 = n+1;
    f(i,k,n+2){
        int a = multiply(i,sub(n1,i));
        a = add(a,1);
        ans = add(a,ans);

    }
    ans = add(ans,MOD);
    cout << ans << "\n";

    return 0;
}
 

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

int main(){
    int n;
    cin >> n;
    vector<int> d(n);
    for(int i = 0;i < n;i ++){
        cin >> d[i];
    }
    sort(d.begin(),d.end());
    cout << d[n/2] - d[n/2-1] << endl;
    return 0;
}

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

const int INF = 0x7f7f7f7f;

int n,a[100005],k;
int f[100005];

int main()
{
	memset(f,INF,sizeof(f));
	cin>>n>>k;
	for(int i=1;i<=n;cin>>a[i++]);
	f[1] = 0;
	for(int i=2;i<=n;i++)
		for(int j=i-1;j>=i-k&&j>=1;j--)
			f[i] = min(f[i],f[j]+abs(a[j]-a[i]));
	cout<<f[n]<<endl;
	
	return 0;
}

Measured memory_bytes: 1152
#!/usr/bin/env python3
import sys


def solve(N: int, D: int):
    supervize = 1 + 2 * D
    if N % supervize:
        print(N // supervize + 1)
    else:
        print(N // supervize)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    solve(N, D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.util.*;

public class Main {
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        String s = sc.next();
        int n = s.length();
        if(!isPalindrome(s)) {
            System.out.println("No");
        } else if(!isPalindrome(s.substring(0, (n - 1) / 2))) {
            System.out.println("No");
        } else if(!isPalindrome(s.substring((n + 3) / 2 - 1, n))) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }

    static boolean isPalindrome(String s) {
        for(int i = 0, f = s.length(); i < f; ++i) {
            if(s.charAt(i) != s.charAt(f - 1 - i)) {
                return false;
            }
        }

        return true;
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	vector<int> beki(10000,1);
	for(int i=1;i<beki.size();i++){
		beki[i] = mod(beki[i-1]*2);
	}
	
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	vector<vector<int>> dp(N,vector<int>(N,0));
	vector<vector<int>> last(N,vector<int>(N,0));
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(A[i]<A[j])dp[i][j]++;
		}
	}
	
	for(int i=0;i<Q;i++){
		int x,y;
		cin>>x>>y;
		x--;y--;
		vector<int> X(N),Y(N);
		for(int j=0;j<N;j++){
			dp[x][j] = mod(dp[x][j] * beki[i-last[x][j]]);
			last[x][j]=i+1;
			X[j] = dp[x][j];
		}
		for(int j=0;j<N;j++){
			dp[y][j] = mod(dp[y][j] * beki[i-last[y][j]]);
			last[y][j]=i+1;
			Y[j] = dp[y][j];
		}
		
		for(int j=0;j<N;j++){
			if(x!=j)dp[x][j] = mod(dp[x][j] + Y[j]);
			if(y!=j)dp[y][j] = mod(dp[y][j] + X[j]);
		}
		
		for(int j=0;j<N;j++){
			if(j==y)continue;
			dp[j][x] = mod(dp[j][x] * beki[i-last[j][x]]);
			last[j][x]=i+1;
			X[j] = dp[j][x];
		}
		for(int j=0;j<N;j++){
			if(j==x)continue;
			dp[j][y] = mod(dp[j][y] * beki[i-last[j][y]]);
			last[j][y]=i+1;
			Y[j] = dp[j][y];
		}
		
		for(int j=0;j<N;j++){
			if(x!=j)dp[j][x] = mod(dp[j][x] + Y[j]);
			if(y!=j)dp[j][y] = mod(dp[j][y] + X[j]);
		}
		
		
		dp[x][y] = mod(dp[x][y] + Y[x]);
		dp[y][x] = mod(dp[y][x] + X[y]);

		/*
		for(int j=0;j<N;j++){
			for(int k=0;k<N;k++){
				cout<<dp[j][k] * beki[(i+1)-last[j][k]]<<',';
			}
			cout<<endl;
		}
		*/
	}
	
	int ans = 0;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			dp[i][j] = mod(dp[i][j] * beki[Q-last[i][j]]);
			if(i>j){
				ans = mod(ans + dp[i][j]);
			}
			//cout<<dp[i][j]<<',';
		}
	//	cout<<endl;
	}
	
	cout<<ans<<endl;
	
	return 0;
}


Measured memory_bytes: 73912
def main():
  h,w = map(int, input().split())
  ans = []
  p = []
  for _ in range(h):
    s = input()
    if '#' in s:
      ans.append(list(s))
  for i in range(len(ans[0])):
    for j in range(len(ans)):
      if ans[j][i] == '#':
        break
      if j == len(ans)-1:
        p.append(i)
  p.sort(reverse=True)
  for i in p:
    for j in range(len(ans)):
      ans[j].pop(i)
  for i in range(len(ans)):
    s = ''
    for j in range(len(ans[0])):
      s += ans[i][j]
    print(s)

if __name__ == '__main__':
  main()

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


int main() {
    long long a, b, k;
    int flag =0;
    cin>>a>>b>>k;
     while(k --){
        if(!flag){
             if(a & 1){
           a--;
           a = a/2;
           b = a+b;
           }
           else if(a%2==0){
              a=a/2;
              b=a+b;
           }
           flag =1;
        }else{
        if(b & 1){
           b--;
           b = b/2;
           a = a+b;
        }
        else if(b%2==0){
            b=b/2;
            a=a+b;
         }
         flag =0;
        }



     }
     cout<<a<<" "<<b<<endl;

    return 0;

}


Measured memory_bytes: 256
using ll = long long;
const ll INF = 1LL << 50;

#include <iostream>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M ;

    const int NMAX = 1000;
    const int MMAX = 2000;
    int a[MMAX], b[MMAX];
    ll c[MMAX];

    for (int i = 0; i < M ; ++i){
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    ll dist[NMAX];

    for (int i = 0; i < N; ++i){
        dist[i] = INF;
    }

    dist[0] = 0;


    for (int loop = 0; loop < N-1; ++ loop){
        for (int i = 0; i < M; ++i){
            if (dist[a[i]-1] == INF) continue;

            if (dist[b[i]-1] > dist[a[i] - 1] + c[i]){
                dist[b[i]-1] = dist[a[i]-1] + c[i];
            }
        }
    }

    ll ans = dist[N-1];

    bool negative[MMAX];

    for (int i = 0; i < N; ++i){
        negative[i] = false;
    }

    for (int loop = 0; loop < N; ++loop){
        for (int i = 0; i < M; ++i){
            if (dist[a[i]-1] == INF) continue;

            if (dist[b[i]-1] > dist[a[i]-1] + c[i]){
                dist[b[i]-1] = dist[a[i]-1] + c[i];
                negative[b[i]-1] = true;
            }

            if (negative[a[i]-1] == true){
                negative[b[i]-1] = true;
            }
        }
    }


    if (negative[N-1])
        cout << "inf" << endl;
    else
    {
        cout << -ans << endl;
    }
    return 0;
}

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

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

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

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

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


int main(){
  int n;
  int counter = 0;
  string s;
  
  cin >> n;

  for(int i=0;i<n;i++){
    cin >> s;
    if(s == "A") counter++;
    else counter--;

    if(counter < 0){
      puts("NO");
      return 0;
    }
  }

  puts(counter == 0 ? "YES" : "NO");
  
  return 0;
}



Measured memory_bytes: 3152
function myOut(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.split(" ");
	input = input.split("\n");
	//input = input.split(" ").map((a)=>Number(a));
	//input = input.split("\n").map((a)=>Number(a));
  var len = parseInt(input[0]);
  var plus = input[1].split(" ").map((a)=>Number(a));
  var minus = input[2].split(" ").map((a)=>Number(a));
  var output = 0;
  for(var i = 0; i < len; i++){
    if(plus[i] > minus[i]){
       output += (plus[i] - minus[i]);
       }
  }
  myOut(output);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}

int main(){
    ll N, K;
    string S,T;
    cin >> N >> K;
    vector<ll> x(N),d(N);
    rep(i,N){
        cin >> x[i];
    }
    rep(i,N-1){
        d[i+1] = x[i+1] - x[i];
    }
    ll cur = 0;
    rep(i,K){
        cur += d[i];
    }
    ll M = cur + min(abs(x[0]), abs(x[0+K-1]));
    rep(i,N-K){
        cur -= d[i+1];
        cur += d[i+K];
        ll tmp = cur + min(abs(x[i+1]), abs(x[i+K]));
        cmin(M,tmp);
    }
    cout << M << endl;
    /*
    ll cur = 0;
    if(x[0] < 0 && x[K-1] < 0){
        cur -= x[0];
    }else if(x[0] < 0 && x[K-1] >= 0){
        cur = min(x[K-1] - 2*x[0], 2*x[K-1]-x[0]);
    }else{
        cur = x[K-1];
    }
    ll M = cur;
    rep(i,N-K+1){
        if(x[i] < 0){

        } && x[i+K] < 0){
            cur += x[i];
            cur -=
        }
        
    }
    cout << "Yes" << endl;*/
}

Measured memory_bytes: 1792
#include <stdio.h>

typedef struct card1
{
	char moji;
	int kazu;
	
} card;


void bubblesort(card *A,int N)
{
	int i,j;
	card t;
	
	for(i=0; i<N; i++)
	{
		for(j=N-1; j>=1; j--)
		{
			if(A[j].kazu<A[j-1].kazu)
			{
				t=A[j];
				A[j]=A[j-1];
				A[j-1]=t;
				
			}
		}
		
	}
    	
	for(i=0; i<N; i++)
	{
		printf("%c%d",A[i].moji,A[i].kazu);
		
		if(i!=N-1)
		{
			printf(" ");
		}
	}
	
	printf("\n");
	
}

void selectionsort(card *B,int N)
{
		int minj,i,j;
		card t;
	
	
	for(i=0; i<N; i++)
	{
		minj=i; //最小値が入っているものをA[minj]とする
		
		for(j=i; j<N; j++)
		{
			if(B[j].kazu<B[minj].kazu)
			{
				minj=j;
			}
		}
		
		
		
		if(i!=minj)
		{
			t=B[i];
			B[i]=B[minj];
			B[minj]=t;
		}
	}
	
	
	for(i=0; i<N; i++)
	{
		printf("%c%d",B[i].moji,B[i].kazu);
		if(i!=N-1)
		{
			printf(" ");
		}
		
	}
	
	printf("\n");
	
}


int main(void)
{
	int N,i,c;
	card A[36];
	card B[36];
	
	c=0;
	
	scanf("%d",&N);
	
	for(i=0; i<N; i++)
	{
		scanf(" %c%d",&A[i].moji,&A[i].kazu);
		B[i].moji=A[i].moji;
		B[i].kazu=A[i].kazu;
		
	}
	
	
	
	bubblesort(A,N);
	printf("Stable\n");
	selectionsort(B,N);
	
	for(i=0; i<N; i++)
	{
		if(A[i].moji!=B[i].moji)
		{
			c++;
		}
	}
	if(c!=0)
	{
		printf("Not stable\n");
	}
	else{printf("Stable\n");}
	
	
	return 0;
}




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

int main(){

  int x;
  cin>>x;

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  
  cout<<h<<":"<<m<<":"<<s<<endl;

  return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> h(n);

    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }

    const int inf = 2e9;

    vector<int> dp(n, inf);

    dp[0] = 0;

    for (int i = 0; i < n - 1; i++) {
        for (int j = 1; j <= k; j++) {
            if (i + j < n) {
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
            }
        }
    }

    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <tuple>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <string>
#include <climits>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <bitset>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (n); ++i)
#define InitRep(i, begin, n) for (int i = (begin); i < (n); ++i)
#define RepItr(it, begin, end) for (auto it = (begin); it != (end); ++it)
using int64 = long long;
using vint = vector<int>;
using vint64 = vector<int64>;
const static double PI = ::acos(-1);

constexpr int64 MOD = 1000000007;




int main()
{
    int n;
    cin >> n;
    vint a(n);
    Rep(i, n)
    {
        cin >> a[i];
    }

    int next = 1;
    Rep(i, n)
    {
        if (a[i] == next)
        {
            ++next;
        }
    }

    if (next == 1)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << (n - next + 1) << endl;
    }

    return 0;
}


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

using namespace std;

int main()
{
	int n,l;
	cin>>n>>l;
	string a[n];
	for(int i=0;i<n;i++)
	{
	cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++)
	cout<<a[i];
	
	return 0;
 } 

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

namespace ABC143A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B;
            var word = Console.ReadLine().Split(' ');
            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
            if (A<=B*2)
            {
             Console.WriteLine(0);
            }
            else if (A>B*2)
            {
             Console.WriteLine(A - B * 2);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
using namespace std;
int gcd(int a,int b){
    if(a < b){
        int c = a;
        a = b;
        b = c;
    }
    if(a%b == 0) return b;
    else return gcd(b,a%b);
}
signed main(){
    
    int n;
    cin >> n;
    int a,b;
    cin >> a >> b;
    int ans = gcd(a,b);
    for(int i = 2;i<n;i++){
        int c;
        cin >> c;
        ans = gcd(ans,c);
    }
    
    cout << ans << endl;

    return 0;
}
//g++ -std=c++14 code1.cpp


Measured memory_bytes: 256
#include <atcoder/lazysegtree>
#include <atcoder/modint>
#include <cstdio>

using namespace std;
using namespace atcoder;

using mint = modint998244353;

#define ll long long int
#define ld long double
#define yorn(f) std::cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) std::cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) std::cout << x << endl;
#define println(x) std::cout << x << endl;
template<typename T>bool mins(T& x,const T&y){if(x>y){x=y;return true;}else return false;}
template<typename T>bool maxs(T& x,const T&y){if(x<y){x=y;return true;}else return false;}
using mint = modint998244353;

struct S{
    mint a;
    mint base;
};

S op(S l, S r) { 
    return S{ l.a + r.a, l.base + r.base };
}

S e(){ return { 0, 0 }; }
S mapping(int f, S x){
    if(f != 0) return S{x.base * f, x.base };
    return x;
}
int composition(int f, int g){ 
    if (f == 0) return g;
    if (g == 0) return f;
    return f; // fが最後に適用されるっぽい
}
int id(){ return 0; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);

    vector<S> a(n);
    mint j = 1;
    for (int i = n-1; i >= 0; i--) {
        a[i] = S{ j, j };
        j *= 10;
    }

    lazy_segtree<S, op, e, int, mapping, composition, id> seg(a);

    for (int i = 0; i < q; i++) {
        ll l, r, d;
        cin >> l >> r >> d;
        l--;
        seg.apply(l, r, d);
        ll res = seg.all_prod().a.val();
        put(res);
    }
}

Measured memory_bytes: 9884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    ll X,K,D; cin >> X>>K>>D;
    if(X<0) X*=-1;
    ll t = X/D;
    if(t>K) {
        AA(X-D*K);
        return 0;
    }
    if((K-t)%2==0) {AA(X-t*D);}
    else AA(D - X + t*D);
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N); for (int i = 0; i < N; ++i) cin >> A[i];
    vector<long long>  D(100100); for (int i = 0; i < 100100; ++i) D[i] = 0;
    map<long long, int> D1;
    for (int i = 0; i < M; ++i) {
        int b, c; cin >> b >> c;
        D.push_back(c);
        D1[c] += b;
    }


    sort(A.begin(), A.end());
    set<long long> D2(D.begin(), D.end());
    vector<long long> D3(D2.begin(), D2.end());

    sort(D3.begin(), D3.end(), greater<int>());

    long long res = 0;
    int count = 0;
    for (long long i: D3) {
        if (D1[i] == 0) continue;
        int j = lower_bound(A.begin(), A.end(), i) - A.begin();
        int change = min(D1[i], max(0, j - count));
        res += i * change;
        count += change;
    }
    for (int i = count; i < N; ++i) res += A[i];
    cout << res << endl;
}


Measured memory_bytes: 13936
from collections import deque

# 双方向連結リストの実装
N = int(input())
commands = [input() for _ in range(N)]

d = deque()

for c in commands:
    if c == "deleteFirst":
        if d:
            d.popleft()

    elif c == 'deleteLast':
        if d:
            d.pop()

    elif 'delete ' in c:
        _, key = c.split()
        key = int(key)
        if key in d:
            d.remove(key)

    elif 'insert ' in c:
        _, key = c.split()
        key = int(key)
        d.appendleft(key)

print(*d)



Measured memory_bytes: 188560
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

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

void SOE(ll N, vi & p) {
    int m = int(floor(sqrt(N))) + 1;
    int s[m];
    REP(i ,m) s[i] = i;

    FOR (i, 2, m) {
        if (s[i] != i) continue;

        p.pb(i);

        for (int j = i+i; j <= m; j += i) {
            s[j] = i;
        }
    }
}

void solve(int n, vll& a) {
    ll g = a[0];
    REP(i, n) g = __gcd(g, a[i]);

    vector<int> prime;
    SOE(1e6, prime);

    map<int, int> l, m;

    REP(i, n) {
        for(auto &e: prime) {
            if (a[i] % e != 0) continue;

            int cnt = 0;
            while(a[i] % e == 0) {
                a[i] /= e;
                cnt++;
            }

            m[e] += cnt;
            l[e] = max(l[e], cnt);
        }

        if (a[i] > 1) {
            m[a[i]] += 1;
            l[a[i]] = max(l[a[i]], 1);
        }
    }

    bool f = false;
    if (l.size() == m.size()) {
        f = true;
        for(auto &p: l) {
            f &= l[p.fi] == m[p.fi];
        }
    }

    if (f) {
        print("pairwise coprime");
    } else {
        if (g == 1) {
            print("setwise coprime");
        }
        else print("not coprime");
    }
}

int tle(int n, vll &a) {
    ll g = a[0];
    REP(i, n) g = __gcd(g, a[i]);

    bool f = true;
    REP(i, n) FOR(j, i + 1, n) {
        f &= __gcd(a[i], a[j]) == 1;
//        debug(a[i], a[j], __gcd(a[i], a[j]))
    }

    if (f) {
        return  1;
    } else {
        if (g == 1) return 2;
        return 3;
    }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);


    int n;
    cin >> n;

    vll a(n); REP(i, n) cin >> a[i];

    solve(n, a);
}


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

int main(){
    ios_base::sync_with_stdio(0);
    string s;
    cin>>s;
    string t;
    cin>>t;
    int count=0;
    for(int i=0;i<3;i++){
        if(s[i]==t[i])
        count++;
    }
    cout<<count;
}

Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var a = nexts(n);
  var ok = n, ng = 0;
  while(ok-ng > 1){
    var m = ok+ng >> 1, f = 1;
    var b;
    if(a[0] > 1)b = [1,1,a[0],1]; else b = [1,1];
    for(var i = 1; i < n && f; i++){
      if(b[b.length-2] < a[i]){
        b.push(a[i],1);
      }else{
        if(m === 1){
          f = 0;
          break;
        }
        while(b[b.length-2] > a[i])b.length -= 2;
        if(b[b.length-2] < a[i])b.push(a[i],2);
        else{
          var t = b[b.length-2];
          for(var j = b.length-1; j > 0; j -= 2){
            if(b[j-1] < t){
              b.push(t,2,a[i],1);
              break;
            }
            if(b[j] < m){
              b[j]++;
              if(b[j-1] < a[i])b.push(a[i],1);
              break;
            }
            b.length -= 2;
            t--;
          }
          if(j < 0)f = 0;
        }
      }
    }
    if(f)ok = m; else ng = m;
  }
  return ok;
}

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

int main() {
  int n,m,p,ac=0,pe=0;
  string s;
  cin >> n >> m;
  vector<int> wa(n+1,0);
  vector<bool> ok(n+1,false);
  for(int i=0;i<m;i++){
    cin >> p >> s;
    if (!ok[p] && s == "WA") wa[p]++;
    else if (!ok[p] && s == "AC") {ac++;pe += wa[p];ok[p] = true;}
  }
  cout << ac << " " << pe << endl;
}


Measured memory_bytes: 640