akhauriyash/Code-Regression huggingface dataset:
def main():
    N = int(input())
    retval = 0
    expected = set([3, 5, 7])
    stack = [(0, set())]
    while len(stack):
        current, used = stack.pop()
        if current <= N and used == expected:
            retval += 1
        for i in [3, 5, 7]:
            next_val = current * 10 + i
            if next_val > N:
                continue
            next_used = set(used)
            next_used.add(i)
            stack.append((next_val, next_used))
    print(retval)


if __name__ == "__main__":
    main()


Measured memory_bytes: 42732
#include <bits/stdc++.h>
    constexpr int INF = 2147483647;
    constexpr long long int INF_LL = 9223372036854775807;
    constexpr int MOD = 1000000007;
    using namespace std;
    typedef long long int ll;
    typedef unsigned long long int ull;
     
    //      debug shrine
    //
    // #######################
    //     ##           ##
    //   ###################
    //     ##           ##
    //     ##           ##
    //     ##           ##
    //     ##           ##
    //     ##           ##
     
     
    int main(int argc, char *argv[]) {
      int N;
      string S;
      cin >> N >> S;
      int a = 0;
      for(int i = 0; i < N; i++){
        if(S[i] == 'B')a++;
      }
      if(a < N-a) cout << "Yes" << endl;
      else cout << "No" << endl;
     
    	return 0;
    }

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

int main() {
    int n;cin>>n;
    int num = 0;
    repd(i,1,n+1){
        string s = to_string(i);
        if(s.size()%2!=0)num++;
    }
    cout<<num<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); i++)
 
int main() {
 int x,y,z,ans;
  cin>>x>>y>>z;
  ans=(x-z)/(y+z);
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
char apple[]={"apple"},peach[]={"peach"};

int ap(char a[]){
  int i;
  for(i=0;i<5;i++)if(a[i]!=apple[i])return 0;
  return 1;
}

int pe(char a[]){
  int i;
  for(i=0;i<5;i++)if(a[i]!=peach[i])return 0;
  return 1;
}

int main(){
  char a,b,c[10000];
  int i=0,j=0,k=0,m=0;
  while(scanf("%c",&a)!=EOF)c[m++]=a;
  c[m]='\0';
  for(i=0;i<m;i++){
    if(ap(&c[i]))for(j=i,k=0;i<j+5;i++)c[i]=peach[k++];
    else if(pe(&c[i]))for(j=i,k=0;i<j+5;i++)c[i]=apple[k++];
  }
  printf("%s",c);
  return 0;
}



Measured memory_bytes: 2032
#include<iostream>
#include<vector>
#include<string>
int main() {
	int n, m;
	int s = 0;
	std::vector<int> y;
	while (true)
	{
		std::cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n / 4; ++i) {
			std::cin >> m;
			s += m;
		}
		y.push_back(s);
		s = 0;
	}
	for (int i = 0; i < y.size();++i)
	std::cout << y[i] << std::endl;
	return 0;
}

Measured memory_bytes: 1216
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iomanip>
using namespace std;

int main() {
	int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int X = x2 - x1, Y = y2 - y1;
	int x3, y3, x4, y4;
	x3 = x2 - Y;
	y3 = y2 + X;
	x4 = x1 - Y;
	y4 = y1 + X;
	cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
	return 0;
}

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

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K<=A){cout << K << endl;}
    else if (K<= (A+B)) {cout << A << endl;}
    else {cout << A-(K-(A+B)) << endl;}

    return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
import sys
input = sys.stdin.readline

n = int(input())
total = (1 + n) * n // 2
ans = 0
for i in range(n):
    ans += (1 + (n - i)) * (n - i) // 2
for _ in range(n-1):
    u, v = map(int, input().split())
    if u > v:
        u, v = v, u
    u -= 1; v -= 1
    ans -= (u + 1) * (n - v)

print(ans)

Measured memory_bytes: 8996
// Enter Source:
#include <bits/stdc++.h>
#define MOD (1000000000+7)

typedef long long int lli;

using namespace std;

lli F(vector<int>& vec, string str)
{
	lli count = 0;
	for(lli i = 0; i < vec.size(); i++)
	{
		if(str[i]-'0' != vec[i]) count++;
	}
	return count;
}

int main()
{
	string str;
	cin >> str;
	lli N = str.size();
	
	vector<int> a,b; 
	for(lli i = 0; i < N; i++) a.push_back(i%2);
	for(lli i = 0; i < N; i++) b.push_back((i+1)%2);
	
	cout << min(F(a,str),F(b,str)) << endl;
	return 0;
}



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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll A, B;
    cin >> A >> B;

    if (A > 8 || B > 8) {
        cout << ":(" << endl;
    } else {
        cout << "Yay!" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;
  cin>>N>>M;
  int a[M];
  int sum=0;
  for(int i=0;i<M;i++){
  	cin>>a[i];
  	sum=sum+a[i];
  }
  if(sum<=N){
  	cout<<N-sum<<endl;
  }
  else{
  	cout<<-1<<endl;
  }
  
  return 0;
} 

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

int main(){

  uint64_t N;
  cin >> N;
  vector<uint64_t> A(N);
  for(uint64_t i=0;i<N;i++)
    cin >> A[i];

  uint64_t sum=0;
  uint64_t max = A[0];
    
  for(uint64_t i=0;i<N;i++){
    if(max > A[i]){
      sum += (max - A[i]);
    }else{
      max = A[i];
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
 
int main ()
{
  int K, X;
  cin >> K >> X;
  
  for (int i = X - K + 1; i <= X + K - 1; i++) {
    cout << i;
    if (i != X + K - 1) {
      cout << " ";
    }
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N = int(input())
s = list(input())[: -1]
cs = [0] * (N + 1)
for i in range(N): cs[i + 1] = cs[i] + (s[i] == "#")
res = float("inf")
for i in range(N + 1):
  r = cs[-1] - cs[i]
  l = i - cs[i]
  res = min(res, N - i - r + i - l)
print(res)

Measured memory_bytes: 63856
const Debug = function () {
    const stdin = function (text) {

    };

    return stdin;
};


const Release = function () {
    const fs = require('fs');
    const stdin = function (text) {
        if (text) console.log(text);
        return fs.readFileSync('/dev/stdin', 'utf8');
    }
    return stdin;
};


const debug = false;

const stdin = debug ? Debug() : Release();
const input = stdin().split('\n').map(x => parseInt(x));

const X = input[0];
const A = input[1];
const B = input[2];

const c = (X - A) % B;
console.log(c);

Measured memory_bytes: 21192
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXN 3506
using namespace std;
long long n;
long long gcd(long long a,long long b)
{
	if(b==0) return a;
	return gcd(b,a%b);
}
int main()
{
	scanf("%I64d",&n);
	for(long long i=1;i<=MAXN;i++)
		for(long long j=1;j<=MAXN;j++)
		{
			long long p=i+j;
			long long q=i*j;
			if(p*n>=4*q) continue ;
			long long g=q*n;
			long long o=4*q-p*n;
			long long r=gcd(g,o);
			if(gcd(o,r)==o)
			{
				printf("%I64d %I64d %I64d",i,j,g/o);
				return 0;
			}
		}
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
    
    private void solv() {
        Scanner input = new Scanner(System.in);
        double x1 = input.nextDouble();
        double x2 = input.nextDouble();
        double y1 = input.nextDouble();
        double y2 = input.nextDouble();
        System.out.println(Math.sqrt(Math.pow(Math.abs(y1-x1), 2)+Math.pow(Math.abs(y2-x2), 2)));
    }
}

Measured memory_bytes: 18504
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 1000000;

struct Node{
  int data;
  Node* left = NULL;
  Node* right = NULL;
};

Node** nodes = new Node*[N_MAX];
int* used = new int[N_MAX];
int* parent = new int[N_MAX];

void preorder(Node* root){
  if(root != NULL){
    cout << " " << root->data;
    preorder(root->left);
    preorder(root->right);
  }
}

void inorder(Node* root){
  if(root == NULL) return;
  inorder(root->left);
  cout << " " << root->data;
  
  inorder(root->right);
}

void postorder(Node* root){
  // cout << "id: " << root->data << ", obj:" << root << endl;
  // cout << root->left << endl;
  // cout << root->right << endl;
  if(root == NULL) return;
  postorder(root->left);
  postorder(root->right);
  cout << " " << root->data ;
}

int main(){
  int n;
  cin >> n;
  memset(used, 0, N_MAX*sizeof(used[0]));
  memset(parent, -1, N_MAX*sizeof(parent[0]));
  
  rep(i, 0, n){
    int node, left, right;
    cin >> node >> left >> right;
      
    Node* cur_node = NULL;
    Node* left_node = NULL;
    Node* right_node = NULL;
    
    if(!used[node]){
      cur_node = new Node;
      cur_node->data = node;
      nodes[node] = cur_node;
      used[node] = 1;
    }
    else{
      cur_node = nodes[node];
    }
    
    if(left != -1){
      if(!used[left]) left_node = new Node;
      else left_node = nodes[left];
      
      left_node->data = left;
      cur_node->left = left_node;
      nodes[left] = left_node;

      used[left] = 1;
      parent[left] = node;
    }
    
    if(right != -1){
      if(!used[right]) right_node = new Node;
      else right_node = nodes[right];
      
      right_node->data = right;
      cur_node->right = right_node;
      nodes[right] = right_node;

      used[right] = 1;
      parent[right] = node;
    }
  }
  int root_id = -1;
  rep(i, 0, n) root_id = parent[i] == -1 ? i : root_id;
  Node* root_node = nodes[root_id];
  
  cout << "Preorder" << endl;  
  preorder(root_node);
  cout << endl;
  /*rep(i, 0, n){
    cout << pre[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
    }*/
  
  cout << "Inorder" << endl;
  inorder(root_node);
  cout << endl;
    /*rep(i, 0, n){
    cout << in[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
    }*/

  
  cout << "Postorder" << endl;
  postorder(root_node);
  cout << endl;
  /*rep(i, 0, n){
    cout << post[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
    }*/
  
  delete[] nodes;
  return 0;
}



Measured memory_bytes: 10908
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		long S = 0;
		int a = 0;
		int[] num = new int[100005];
		for (int i = 0; i < N; i++) {
			a = scan.nextInt();
			num[a]++;
			S += a;
		}

		int Q = scan.nextInt();
		int b = 0;
		int c = 0;
		long[] ans = new long[Q];

		for (int i = 0; i < Q; i++) {
			b = scan.nextInt();
			c = scan.nextInt();
			S += num[b] * (c-b);
			num[c] += num[b];
			num[b] = 0;
			ans[i] = S;
		}

		for (int i = 0; i < Q; i++) {
			System.out.println(ans[i]);
		}

	}

}

Measured memory_bytes: 61412
#include<bits/stdc++.h>
#define pb emplace_back
#define ll long long
#define mp make_pair
#define PI acos(-1)
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll i,j,k,x,y,z,m,n,t,a,b,c,l,r;
    cin>>n>>m>>k;
    string s[8];
    for(i=0; i<n; i++)
        cin>>s[i];
    ll cnt,ans=0;
    for(i=0; i<(1<<n); i++)
    {
        for(j=0; j<(1<<m); j++)
        {
            cnt=0;
            for(a=0; a<n; a++)
            {
                for(b=0; b<m; b++)
                {
                    if(i & (1<<a) && j &(1<<b) && s[a][b]=='#')
                        cnt++;
                }
            }
            if(cnt==k)
                ans++;
        }
    }
    cout<<ans<<'\n';
}





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

int main(){
  int a,b,sum;
  while(1){
    cin >> a >> b;
    if(a==0&&b==0)break;
    sum=0;
    for(int i=1;i<a;i++){
      if(i==2)sum+=29;
      else if(i==4||i==6||i==9||i==11)sum+=30;
      else sum+=31;
    }
    sum+=b;
    if(sum%7==1)cout <<"Thursday"<<endl;
    else if(sum%7==2)cout <<"Friday"<<endl;
    else if(sum%7==3)cout <<"Saturday"<<endl;
    else if(sum%7==4)cout <<"Sunday"<<endl;
    else if(sum%7==5)cout <<"Monday"<<endl;
    else if(sum%7==6)cout <<"Tuesday"<<endl;
    else if(sum%7==0)cout <<"Wednesday"<<endl;
  }
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  VI xs(N);
  cin >> xs;

  VI ys = xs;
  SORT(ys);

  for(int x: xs){
	if(ys[N/2] <= x)
	  cout << ys[N/2-1] << endl;
	else
	  cout << ys[N/2] << endl;
  }

  return 0;
}


Measured memory_bytes: 3840
import java.util.*;
import java.io.*;

class Main {
  public static void main(String args[]) {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] n;
    int sum;
    try {
      while (true) {
        sum = 0;
        n = br.readLine().split("(?<=.)");
        if (Integer.parseInt(n[0]) == 0) break;
        for (int i = 0; i < n.length; i++) {
          sum += Integer.parseInt(n[i]);
        }
        System.out.println(sum);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Measured memory_bytes: 19348
from collections import  deque
import sys
import bisect
import math
import itertools
from queue import deque
from math import gcd

INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())
 
def inp_list(): return list(map(int, sys.stdin.readline().split()))

def lcm(x, y): return (x * y) // gcd(x, y)

N, K = inp_list()
ans = 0
for k in range(K, N + 2):
    # M => 和の最大値, m => 和の最小値, k について和としてありえるものの個数は M - m + 1
    M = ( N * (N + 1) // 2 - (N - k) * (N + 1 - k) // 2 )
    m = k * (k - 1) // 2
    ans += (M - m + 1)

print(ans % mod)


Measured memory_bytes: 9828
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int D;
    ll G,n[12],c[12];
    cin>>D>>G;
    for(int i=0;i<D;i++){
        cin>>n[i]>>c[i];
        c[i]+=(100)*(i+1)*n[i];
    }
    ll ans=1100000;
    for(int S=0;S<(1<<D);S++){
        ll sum=0,temp=0,now=0;
        for(int i=0;i<D;i++){
            if(bit(S,i)){
                sum+=c[i];
                temp+=n[i];
            }else now=i;
        }
        if( (G-sum  + (100)*(now+1) -1  )/( (100)*(now+1) )<=n[now] ){
            ans=min(ans,temp+ max(0LL,(G-sum  + (100)*(now+1) -1  )/( (100)*(now+1) )) );
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

enum lim = 2 * 10^^5;

void main() {
    auto s = eratos(lim);
    auto t = new bool[](lim);
    foreach (i ; 3 .. lim) {
        if (s[i] && s[(i + 1) / 2]) {
            t[i] = true;
        }
    }

    auto ts = new int[](lim + 1);
    foreach (i ; 1 .. lim + 1) {
        ts[i] = ts[i - 1] + t[i - 1];
    }

    int q;
    scan(q);

    foreach (i ; 0 .. q) {
        int li, ri;
        scan(li, ri);
        ri++;
        int ans = ts[ri] - ts[li];
        writeln(ans);
    }
}

bool[] eratos(int n) {
    auto s = new bool[](n);
    s[] = true;
    s[0] = s[1] = false;

    for (int p = 2; p*p < n; p++) {
        if (s[p]) {
            for (int d = p*p; d < n; d += p) {
                s[d] = false;
            }
        }
    }

    return s;
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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


int main()
{
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    int maxd = 0;
    for (int i = 0; i < N - 1; i++) maxd = max(maxd, A[i+1] - A[i]);
    maxd = max(maxd, K - A[N-1] + A[0]);
    cout << K - maxd << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
using namespace std;
int  main()
{
    char a[110];
    int l;
    scanf("%s",a);
    l=strlen(a);
    if(l>=3)
    {
        if(a[0]=='Y'&&a[1]=='A'&&a[2]=='K'&&a[3]=='I')printf("Yes\n");
        else printf("No\n");
    }
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iomanip>
using namespace std;
//---------------------------------------
//---------------------------------------

int main(void)
{
	double len_a, len_b, angle_c;
	cout << fixed <<setprecision(4);  //???????°???°????¬¬4????????§??¨?????????(iomanip)
	
	cin >> len_a;
	cin >> len_b;
	cin >> angle_c;
	
	//??¢???S
	cout << len_a * len_b * sin(angle_c * M_PI / 180) * 1 / 2 << endl;
	
	//??¨?????????L
	cout << sqrt(pow(len_a, 2) + pow(len_b, 2)
	             - 2 * len_a * len_b * cos(angle_c * M_PI / 180)) + len_a + len_b
	     << endl;
	
	//??????h
	cout << len_b * sin(angle_c * M_PI / 180) << endl;
	
	
	return 0;
	
}

Measured memory_bytes: 3556
import os, sys, re, math

(N, K) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

if 0 in x:
    K -= 1
nx = list(filter(lambda i: i < 0, x))
px = list(filter(lambda i: i > 0, x))
nx.reverse()

result = 0
if K > 0:
    result = sys.maxsize
    if len(nx) > K - 1:
        result = min(result, -nx[K - 1])
    if len(px) > K - 1:
        result = min(result, px[K - 1])
    for i in range(len(px)):
        j = K - i - 2
        if 0 <= j < len(nx):
            result = min(result, px[i] * 2 - nx[j])
    for i in range(len(nx)):
        j = K - i - 2
        if 0 <= j < len(px):
            result = min(result, px[j] - nx[i] * 2)

print (result)


Measured memory_bytes: 15116
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int MOD=1e9+7;
const long long INF = 1LL << 60;
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

signed main(){
  int A,B;
  cin >> A >> B;
  cout << max(0LL,A-2*B) << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
S=input()
n=len(S)
if n>1:
    for i in range(n//2):
        s=S[2*i]
        if s=="L":
            print("No")
            sys.exit()
        s=S[2*i+1]
        if s=="R":
            print("No")
            sys.exit()
if n%2==1:
    s=S[-1]
    if s=="L":
        print("No")
        sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
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; }
typedef long long ll;
const int INF = 1e9;
const int MAX = 100001;

int Q;

int main(){
    cin >> Q;
    vector<ll> a(Q,0),s(Q+1,0);
    REP(i,Q) cin >> a[i];

    REP(i,Q) s[i+1] = s[i] + a[i];

    map<ll,ll> m;
    REP(i,s.size()) ++m[s[i]];
    ll ans = 0;
    for(auto itr : m){
        ll num = itr.second;
        ans += num * (num - 1) / 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
INF = 10 ** 10

a,b,q = gets.split.map(&:to_i)
A = Array.new(a + 2)
B = Array.new(b + 2)
Q = Array.new(q)
a.times{|i| A[i + 1] = gets.to_i }
b.times{|i| B[i + 1] = gets.to_i }
q.times{|i| Q[i] = gets.to_i }

A[0] = B[0] = -INF
A[a + 1] = B[b + 1] = 2 * INF

ans = Q.map do |t|
  i = A.bsearch_index{|pos| pos >= t }
  j = B.bsearch_index{|pos| pos >= t }
  [ [A[i],B[j]].max - t,
    t - [A[i - 1], B[j - 1]].min,
    B[j] - A[i - 1] + t - A[i - 1],    
    B[j] - A[i - 1] + B[j] - t,
    A[i] - B[j - 1] + A[i] - t,
    A[i] - B[j - 1] + t - B[j - 1]].min
end
puts ans

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

# define F first    
# define S second
# define mp make_pair
// everything go according to my plan      
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right  

using namespace std;

typedef pair <int, int> pii; 
typedef long long ll;
typedef long double ld;

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {   
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") { 
  if (fopen (in, "r"))
    freopen (in, "r", stdin);
  else
    cerr << "Warning: Input file not found" << endl;
}    
int f[Sz];
  
ll binpow (ll a, ll b) {
  ll res = 1;
  while (b) {
    if (b & 1)
      res = (res * a) % Mod;
    b >>= 1;
    a = (a * a) % Mod;
  }
  return res;
}      
ll inv (ll a) {
  return binpow (a, Mod-2);
}
ll C (ll n, ll k) {
  return (f[n] * inv ((f[k] * 1ll * f[n - k]) % Mod)) % Mod;
}
int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();       
  int n, m, a, b; cin >> n >> m >> a >> b;

  f[0] = 1;                      
  for (int i = 1; i <= n + m; i++)
    f[i] = (f[i - 1] * 1ll * i) % Mod;

  int ans = 0;  
  for (int i = 1; i <= b; i++) {
    ans = (ans + C (n-a-1 + i-1, i-1) * C (m-i + a-1, m-i)) % Mod;
  }    
  ans = C (n + m - 2, n - 1) - ans;
  if (ans < 0)  ans += Mod;
               
  cout << ans;

  return 0;
}






// Coded by Z..


Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  read::<String>().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
  (0..n).map(|_| read_vec()).collect()
}

fn main() {
  let s: String = read();
  let s: &str = &s;

  let wd = ["SUN","MON","TUE","WED","THU","FRI","SAT"];

  let mut index: usize = 0;
  for (i, val) in wd.iter().enumerate() {
    if s == wd[i] {
      index = i;
      break;
    }
  }

  println!("{}", 7-index);
}

Measured memory_bytes: 4352
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main{

	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);

		String b = scanner.next();

		Map<String, String> enki = new HashMap<>();
		enki.put("A", "T");
		enki.put("T", "A");
		enki.put("C", "G");
		enki.put("G", "C");

		System.out.println(enki.get(b));
	}
}


Measured memory_bytes: 21716
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
const ll INF = 1e18+1;

//集める中央値の個数はN(N-1)/2 + N
//したがって集めた中央値の配列の[N(N+1)/4]の値が答え

//幅1でスキャンしたとき...
//配列のすべての要素が追加される

//幅2でスキャンしたとき...
//配列の隣り合ってる要素の大きいほうが計(N-1)個追加される

//幅3でスキャンしたとき...
//3つのうち中央値が計(N-2)個追加される

//最小値が中央値になる見込み 幅1の場合のみ 従って1こだけ追加される

/*
中央値の性質 配列の要素数Mとして
・その数以上の要素が(M + 1)/2 (切り上げ)
コ以上含まれる
・そのような中で最大

なので、中央値を求めるにはにぶたんが最適
したがって、二部たんに用いる判定は、あるkに対して
「k以上の要素が配列の中に  [(N(N+1) + 1)/4]コ以上含まれるかどうか 」
ただしこの時の配列とは(l,r)中央値を集めた配列

k以上の要素が中央値になるカウントのやり方は?


aの連続部分列a[l,r]のうち、k以上の要素を((r-l+1)+1 / 2)コ含む
ものが[(N(N+1) + 1)/4]通りあるか?





*/
ll N;
ll bit[300000], n;

int sum(int i) {
    int s = 0;
    while (i > 0) {
        s += bit[i];
        i -= i & -i;
    }
    return s;
}
void add(int i, int x) {
    while (i <= n) {
        bit[i] += x;
        i += i & -i;
    }
}

bool f(int x, vector<int> a) {
    vector<int> b, S(N,0);
    for (int i = 0; i < a.size(); i++) {
        if (a[i] >= x) b.push_back(1);
        else b.push_back(-1);
    }
    S[0] = b[0];
    for (int i = 1; i < b.size(); i++) {
        S[i] = S[i-1] + b[i];
    }
    for (int i = 0; i < n; i++) bit[i] = 0;
    ll ans = 0;
    add(100001,1);//
    for (int i = 0; i < N; i++) {
        ans += sum(S[i]+100001);
        add(S[i]+100001,1);
        //ans += sum(S[i]+100001);
    }
    //for (int i = 0; i < N; i++) cout << S[i] << " ";
    //cout << endl;
    //for (int i = 100001; i < n; i++) cout << bit[i] << " ";
    
    if (ans >= ((N*(N+1)/2) + 1) / 2 ) {
        return true;
    } else {
        return false;
    }

}

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

    int lb = -1, rb = 1e9+1;
    while (rb - lb > 1) {
        int mid = (rb+lb)/2;
        if (f(mid,a)) lb = mid;
        else rb = mid;
    }
    cout << lb << endl;
}


Measured memory_bytes: 3936
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define double long double
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define print(v) cout<<v<<endl
#define printyes cout<<"Yes"<<endl
#define printno cout<<"No"<<endl
#define printYES cout<<"YES"<<endl
#define printNO cout<<"NO"<<endl
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas x,ddatas y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

int main(){
  // startupcpp();
  // ll test;cin>>test;while(test--){
  ll i,j,H,W,N,ans=0;
  cin>>W>>H;
  N=H+W;
  pvec v(N);
  rep(i,N){
    cin>>v[i].first;
    v[i].second=i<W;
  }
  vsort(v);
  ++H;++W;
  rep(i,N){
    if(v[i].second){
      --W;
      ans+=H*v[i].first;
    }else{
      --H;
      ans+=W*v[i].first;
    }
  }
  print(ans);
}

Measured memory_bytes: 3328
M, K = map(int, input().split())

if 2**M <= K:
    print(-1)
elif M == 1:
    if K == 0:
        print("1 1 0 0")
    else:
        print(-1)
else:
    X = list(range(K)) + list(range(K+1, 2**M))
    ans = " ".join(map(str, X + [K] + X[::-1] + [K]))
    print(ans)


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


int main(){
    int n;
    cin >> n;
    int d[101];
    int ans = 0;

    rep(i, n-1)cin >> d[i];

    ans += d[0];

        // cout << "ans : " << ans << endl;


    rep(i, n-2){
        int a = d[i];
        int b = d[i+1];
        ans += min(a, b);
        // cout << "ans : " << ans << endl;
    }

    ans += d[n-2];

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)


//階乗,二項係数
ll fact[10010];
ll invfact[10010];
void makefact(int n,ll m){
	fact[0]=1;
	rep(i,0,n)fact[i+1]=fact[i]*(i+1)%m;
	invfact[n]=invp(fact[n],m);
	for(int i=n;i>0;i--)invfact[i-1]=invfact[i]*i%m;
}
ll choose(int n,int r,int m){return n<0||r<0||n-r<0?0:fact[n]*invfact[r]%m*invfact[n-r]%m;}


typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	ll vcnt,ecnt;
	E  e[10010];//適宜変える
	ll id[5010];//適宜変える
}G;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}

G g;
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld",&n);
	rep(i,0,n-1){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[2*i].s=x;
		g.e[2*i].g=y;
		g.e[2*i+1].s=y;
		g.e[2*i+1].g=x;
	}
	g.vcnt=n;
	g.ecnt=2*n-2;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

//*
int csize[5010];
int ccnt;
int Gc[2];
void Gcenter_dfs(int v,int pre){
	int flag=1;
	csize[v]=1;
	rep(i,g.id[v],g.id[v+1])if(g.e[i].g!=pre){
		int s=g.e[i].g;
		Gcenter_dfs(s,v);
		csize[v]+=csize[s];
		flag&=csize[s]<=g.vcnt/2;
	}
	if(flag&&g.vcnt-csize[v]<=g.vcnt/2)Gc[ccnt++]=v;
}
int Gcenter(int root){
	Gcenter_dfs(root,-1);
	return ccnt;
}
//*/

ll dp[5010][5010];
int main(){
	makefact(10005,MOD);
	readgraph();
	Gcenter(0);
	if(ccnt==2){
		printf("%lld",fact[g.vcnt/2]*fact[g.vcnt/2]%MOD);
		return 0;
	}
	Gcenter(Gc[0]);
	ll K=g.id[Gc[0]+1]-g.id[Gc[0]];
	ll N=g.vcnt;
	dp[0][0]=1;
	dp[0][1]=0;
	rep(k,0,K)rep(x,0,N+1){
		ll Tk=csize[g.e[g.id[Gc[0]]+k].g];
		rep(y,0,min(x,Tk)+1)dp[k+1][x]=(dp[k+1][x]+choose(Tk,y,MOD)*choose(Tk,y,MOD)%MOD*fact[y]%MOD*dp[k][x-y])%MOD;
	}
	ll ans=0;
	rep(x,0,N+1)ans=(ans+(x%2?-1:1)*fact[N-x]*dp[K][x])%MOD;
	printf("%lld",(ans+MOD)%MOD);
}

Measured memory_bytes: 196240
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author silviase
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AHitachiString solver = new AHitachiString();
        solver.solve(1, in, out);
        out.close();
    }

    static class AHitachiString {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next();
            StringBuilder hi = new StringBuilder("hi");
            while (hi.length() <= s.length()) {
                if (hi.toString().equals(s)) {
                    out.println("Yes");
                    return;
                }
                hi.append("hi");
            }
            out.println("No");
        }

    }
}



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

using ll = int64_t;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)

#define rng(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
  for (auto val : array)
    std::cout << val << ", ";
  std::cout << "\n";
}

const int MOD = 998'244'353;
const int INF = 1'000'000'000 + 5;

const int DMAX = 100'005;
ll cnt[DMAX];

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

	int n; std::cin >> n;
	vi d(n);
	rep(i, n) {
		std::cin >> d[i];
		cnt[d[i]]++;
	}
	if (d[0] != 0 || cnt[0] > 1) {
		std::cout << 0 << "\n";
		return 0;
	}
	ll rest = n - 1, ans = 1;
	for (int i = 1; rest != 0; i++) {
		if (d[i] == 0 && rest > 0) {
			std::cout << 0 << "\n";
			return 0;
		}
		rep(j, cnt[i]) ans = (ans * cnt[i - 1]) % MOD;
		rest -= cnt[i];
	}
	std::cout << ans << "\n";
}


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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const int64 infll = (1LL << 61) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

inline int64 count1_2(int n, int k) {
  if(n > k) return (0);
  int64 ret = 1;
  while(n--) (ret *= k--) %= mod;
  return (ret);
}

int main() {
  int N, K;
  cin >> N >> K;
  cout << count1_2(N, K) << endl;
}






Measured memory_bytes: 3168
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long  int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

class Add_Segment_Tree {
	vector<long long int>v;
	vector<int>l;
	vector<int>r;
	long long int ret;
	int num;
	long long int Update(int place) {
		if (place >= v.size() / 2) {
			return v[place];
		}
		v[place] = Update(place * 2) + Update(place * 2 + 1);
		return v[place];
	}
	void Sum(int a, int b, int place) {
		if (l[place] >= a && r[place] <= b) {
			ret += v[place];
			return;
		}
		if (l[place] > b || r[place] < a) return;
		Sum(a, b, place * 2);
		Sum(a, b, place * 2 + 1);
		return;
	}
public:
	void Left(int place) {
		if (place >= v.size() / 2) {
			l[place] = place - v.size() / 2;
			return;
		}
		Left(place * 2);
		Left(place * 2 + 1);
		l[place] = l[place * 2];
		return;
	}
	void Right(int place) {
		if (place >= v.size() / 2) {
			r[place] = place - v.size() / 2;
			return;
		}
		Right(place * 2);
		Right(place * 2 + 1);
		r[place] = r[place * 2 + 1];
		return;
	}
	Add_Segment_Tree(int n) {
		n++;
		num = 1;
		while (num < n * 2)num *= 2;
		l.resize(num);
		r.resize(num);
		v.resize(num, 0);
		Left(1);
		Right(1);
	}
	void Add(int place, long long int num, bool update) {
		place += v.size() / 2;
		v[place] += num;
		if (!update)return;
		place /= 2;
		while (place) {
			v[place] = v[place * 2] + v[place * 2 + 1];
			place /= 2;
		}
	}
	void TopDown() {
		Update(1);
	}
	long long int Sum(int a, int b) {
		ret = 0;
		Sum(a, b, 1);
		return ret;
	}
};

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

	cin >> N;
	vector<pair<int,int>>v(N+2);
	vector<int>rM(N + 2, 0);
	vector<int>lm(N + 2, MOD);
	map<int, int>m;
	v.back() = { MOD,MOD };
	for (int i = 1; i <= N; i++) {
		cin >> v[i].first >> v[i].second;
		m[v[i].second]++;
	}
	sort(v.begin(), v.end());
	K = 1;
	for (auto &i : m)i.second = K++;
	for (int i = 1; i <= N; i++)v[i].second	 = m[v[i].second];
	for (int i = 1; i <= N; i++) {
		lm[i] = rM[i] = v[i].second;
		rM[i] = max(rM[i], rM[i - 1]);
	}
	for (int i = N; i >= 1; i--) {
		lm[i] = min(lm[i], lm[i + 1]);
	}
	Add_Segment_Tree asg(K);
	asg.Add(0, 1, true);
	for (int i = 1; i <= N; i++) {
		long long int add = asg.Sum(lm[i] - 1, rM[i]);
		long long int nx = add + asg.Sum(rM[i], rM[i]);
		add -= nx - (nx%MOD);
		asg.Add(rM[i], add,true);
	//	cout << lm[i] << " " << rM[i] << endl;
	}
	cout << asg.Sum(N, N) << endl;
	return 0;
}

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

int main(){
    string s; cin>>s;
    int ans=0;
    int a=0;
    rep(i,s.length()){
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G') a++;
        else a=0;
        ans=max(a,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n = int(input())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
ans = [0,0]
for pq in range(2):
    l = q if pq % 2 else p
    #print(l)
    for i in range(n-1):
        # p[i:]の中でp[i]はしたから何番目か
        k = sorted(l[i:]).index(l[i])
        ans[pq] += k*math.factorial(n-i-1)
print(abs(ans[0]-ans[1]))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	string sd, t;
	cin >> sd >> t;
	if (sd.size() < t.size()) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	vector<int> c;
	for (int i = 0; i <= sd.size() - t.size(); i++) {
		int length = 0;
		for (int j = 0; j < t.size(); j++)
			if (sd[i + j] == t[j] || sd[i + j] == '?')
				length++;
		if (length == t.size())
			c.push_back(i);
	}
	//c : tが入りうる場所の先頭のイテレータ
	vector<string> ans;
	for (int i = 0; i < c.size(); i++) {
		string s = sd;
		for (int j = c[i]; j < c[i] + t.size(); j++)
			s[j] = t[j - c[i]];
		for (int j = 0; j < s.size(); j++)
			if (s[j] == '?')
				s[j] = 'a';
		ans.push_back(s);
	}
	if (ans.size()) {
		sort(ans.begin(), ans.end());
		cout << ans[0] << endl;
	}
	else
		cout << "UNRESTORABLE" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <numeric>

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

using namespace std;
using ll = long long int;
using ull = unsigned long long;

float myPower(int a, int n) { // aのn乗の計算
	float x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	float r;
	cin >> r;
  const float pi = 3.141592653589793;
	cout << (float)(2.0f * r * pi) << endl;
	return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int rec[100][100] = {0};

void paint(int x, int w, int y, int h) {
        for (int i = x; i < w; i++)
                for (int j = y; j < h; j++)
                        rec[j][i] = 1;
}

int cnt(int w, int h) {
        int ret = 0;
        for (int i = 0; i < w; i++)
                for (int j = 0; j < h; j++)
                        if (rec[j][i] == 0)
                                ret++;
        return ret;
}

int main() {
        int w, h, n;
        int x, y, a;
        cin >> w >> h >> n;
        while (n-->0) {
                cin >> x >> y >> a;
                switch (a) {
                        case 1:
                                paint(0, x, 0, h);
                                break;
                        case 2:
                                paint(x, w, 0, h);
                                break;
                        case 3:
                                paint(0, w, 0, y);
                                break;
                        case 4:
                                paint(0, w, y, h);
                                break;
                }
        }
        cout << cnt(w, h) << endl;
        return 0;
}


Measured memory_bytes: 256
local n=io.read("n")

local function lower_bound()
    local max=n+1
    local min=0
    while 1<max-min do
        mid=(max+min)//2
        if mid*(mid+1)//2>=n then
            max=mid
        else
            min=mid
        end
    end
    return max
end

local x=lower_bound()
for i=1,x do
    if i~=x*(x+1)//2-n then
        print(i)
    end
end

Measured memory_bytes: 376
#include <iostream>
#include <vector>
#include <string>
typedef long long ll;
using namespace std;

int main() {
    int N; cin >> N;
    int a[4];
    a[0] = N / 1000; N = N % 1000;
    a[1] = N / 100; N = N % 100;
    a[2] = N / 10; N = N % 10;
    a[3] = N;

    vector<int> res;
    for (int bit = 0; bit < (1<<3); ++bit) {
        int sum = a[0];
        vector<int> s;
        for (int i = 0; i < 3; ++i) {
            if (bit & (1<<i)) {
                sum += a[i+1];
                s.push_back(1);
            } else {
                sum -= a[i+1];
                s.push_back(0);
            }
        }
        if (sum == 7) {
            cout << a[0];
            for (int i = 0; i < 3; ++i) {
                if (s[i] == 1) cout << '+' << a[i+1];
                else cout << '-' << a[i+1];
            }
            cout << "=7" << endl;
            break;
        }
    }

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll A, B, ans = 1;

int main() {
	cin >> A >> B;
	for (ll i = 2; i * i <= A; i++) {
		if (A % i)continue;
		if (B % i == 0)ans++;
		while (A % i == 0)A /= i;
	}
	if (A != 1 && B % A == 0)ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256