akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str = sc.next();
            String[] str2 = str.split("");
            int count = 0;
            for(int i = 0; i < str2.length; i++){
              if("+".equals(str2[i])){
                count++;
              } else {
                count--;
              }
      }
      System.out.println(count);
          }
}

Measured memory_bytes: 21588
import java.util.*; 

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

        while(true){ 
            int a = sc.nextInt(); 
            int b = sc.nextInt(); 
            int c = sc.nextInt(); 
            int sum = a + b; 
            if(a == -1 && b == -1 && c== -1){ 
                break; 
            }else if(a == -1 || b == -1){ 
                System.out.println("F"); 
            }else{ 
                if(sum<30){ 
                    System.out.println("F"); 
                }else if(sum<50){ 
                    if(c<50){ 
                        System.out.println("D"); 
                    }else{ 
                        System.out.println("C"); 
                    } 
                }else if(sum<65){ 
                    System.out.println("C"); 
                }else if(sum<80){ 
                    System.out.println("B"); 
                }else{ 
                    System.out.println("A"); 
                } 
            } 
        } 
        sc.close(); 
    } 
}


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

using namespace std;

typedef long long ll;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

ll get(ll x) {
  return (x * (x - 1)) / 2ll;
}

int main() {
  int n; cin >> n;
  vector <int> a(n);
  vector <ll> cnt(n + 1, 0);
  for(auto &x : a) {
    cin >> x;
    cnt[x]++;
  }
  ll ans = 0;
  for(int i = 1; i <= n; i++) {
    ans += get(cnt[i]);
  }
  for(int i = 0; i < n; i++) {
    cout << ans - (cnt[a[i]] - 1) * 1ll << '\n';
  }
  return 0;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    a.push_back(0);
    int c = 1;
    int res = 0;
    for (int i = 1; i < a.size(); ++i) {
        if (a[i] == a[i - 1]) {
            ++c;
        }
        else {
            res += c / 2;
            c = 1;
        }
    }
    cout << res << endl;
}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
   int K,i;
   char S[100];
   scanf("%d",&K);
   scanf("%s",S);
   if(K>=strlen(S)){
      printf("%s",S);
   }else{
      for(i=0;i<K;i++){
         printf("%c",S[i]);
      }
      printf("...");
   }
   return 0;
}
   


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

using namespace std;
typedef long long Int;

Int bit[1080000];

void setval(Int pos, Int val){
	pos++;
	while(pos < 1080000){
		bit[pos] = max(bit[pos], val);
		pos += pos & -pos;
	}
}

Int getval(Int pos){
	pos++;
	Int res = 0;
	while(pos){
		res = max(bit[pos], res);
		pos -= pos & -pos;
	}
	return res;
}

int main(){
	Int n, x, res = 0;
	cin >> n;
	for(Int i = 0;i < n;i++){
		cin >> x;
		setval(x, x + getval(x));
		res = max(res, getval(x));
	}
	cout << n*(n+1)/2-res << endl;
	return 0;
}

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

int n, x[101], p=0, mn=100000000;

int main()
{
	cin >> n;
	for(int i=0; i<n; i++)
		cin >> x[i];
		
	for(int j=-100; j<=100; j++)
	{
		for(int i=0; i<n; i++)
		{
			p += (x[i]-j)*(x[i]-j);
		}
		
		mn = min(mn,p);
		p=0;
	}
	
	cout << mn << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
    int a,b,depth;
    char ans[10000]={0};
    void s(int x,int y,int depth){
        if(x==a && y==b){
            cout<<ans<<endl;
            return;
        }
        if(x==5 && y<4)return;
        if(y==5 && x<4)return;
        if(x==y && x==5)return;

        else{
            if(x<=a){
                if(depth==a+b)return;
                ans[depth]='A';
                s(x+1,y,depth+1);
            }
            if(y<=b){
                if(depth==a+b)return;
                ans[depth]='B';
                s(x,y+1,depth+1);
            }
        }

    }
int main(){
    cin>>a>>b;
    s(0,0,0);
    return 0;
}

Measured memory_bytes: 3052
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 1001001001;

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

    sort(A.begin(),A.end());
    ll med;
    if(N%2 == 0){
        med = (A[N/2-1]+A[N/2])/2;
    }
    else{
        med = A[(N-1)/2];
    }

    ll ans = 0;
    for(int i=0;i<N;i++){
        ans += abs(A[i]-med);
    }
    cout << ans << endl;
}


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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1e9 + 7;


int main() {
    int s;
    scanf("%d", &s);
    bool flag = false; //falseになったら答え
    vector<int> data = {s};
    int count = 1;
    int last = s;
    int now = s;
    while (1) {
        count ++;
        if (last % 2 == 0) {
            now = last/2;
        } else {
            now = 3 * last + 1;
        }
        flag = binary_search(data.begin(), data.end(), now);
        if (flag) {
            printf("%d\n", count);
            return 0;
        } else {
            auto it = lower_bound(data.begin(), data.end(), now);
            it = data.insert(it, now);
            last = now;
        }
    }

} 





Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <string>
#include <limits.h>
#include <iomanip>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <set>
#include <bitset>
#include <unordered_map>
#include <string.h>
#define fastIo                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL)
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define MOD 1000000007

using namespace std;
int main()
{
    fastIo; 

    int t;
    t=1;

    while(t--){
        string s;
        cin>>s;

        int ct =0;
        int nct = 0;

        for(int i=0;i<3;i++){
            if(s[i]=='R'){
                nct++;
            }
            else{
                nct=0;
            }
            ct = max(ct,nct);
        }
        cout<<ct<<endl;

       


    }



    return 0;
}

Measured memory_bytes: 3608
n, m = map(int,input().split())
l_ls = []
r_ls = []

for _ in range(m):
    l,r = map(int,input().split())
    l_ls.append(l)
    r_ls.append(r)

count = 0
small = max(l_ls)
big = min(r_ls)

print(max(big-small+1,0))

Measured memory_bytes: 55896
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
a=get_i
flag=false
ans=0
while true
  n.times do|i|
    unless (a[i]%2).zero?
      flag=true
      break
    end
    a[i]/=2
  end
  if flag
    break
  end
  ans+=1
end
puts ans

Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define N 5000005
using namespace std;
char v[N];
int n,st;
void addone(){
	int p=n;
	while(v[p]=='9') v[p]='0',p--;
	v[p]++;
}
int main(){
	scanf("%s",v+1);n=strlen(v+1);st=1;
	int ans=1;int same=1;
	while(st<n){
		if(v[st+1]<v[st]) {
			while(v[st+1]<v[st]&&same>0){
				same--,addone(),ans++;
			}
		}
		if(v[st+1]==v[st]) same++;
		else same=1;
		v[st]='0';st++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 768
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define INF 1000000000
#define next(a) (( (a) + 1 )%SIZE) 

#define SIZE 100000

//int queue[SIZE];
int front;
int rear;

typedef struct pro
{
	char name[11];
	int time;
}pro;

pro* queue[SIZE];

void swap(int* x, int* y)
{
	int t;

	t = *x;
	*x = *y;
	*y = t;
}

int binary_search(int p[], int n, int key)
{
	int left, right, middle;

	left = 0;
	right = n - 1;


	while (left <= right)
	{
		middle = (left + right) / 2;

		if (p[middle] == key)
			return middle;
		else if (p[middle] > key)
		{
			right = middle - 1;
		}
		else if (p[middle] < key)
		{
			left = middle + 1;
		}
	}

	return -1;

}

void bubble_sort(int p[], int n)
{
	int i, j;

	for (i = 0; i < n - 1; i++)
	{
		for (j = 0; j < n - i - 1; j++)
		{
			if (p[j] > p[j + 1])
				swap(&p[i], &p[i + 1]);
		}
	}
}

void insertion_sort(int* p, int N)
{
	int i, j;

	for (i = 1; i < N; i++)
	{
		j = i;

		while (j >= 0 && p[j] < p[j - 1])
		{
			swap(&p[j], &p[j - 1]);
			j--;
		}
	}
}

static int cnt = 0;

void insertion_sort2(int p[], int N, int g)
{
	int i, j;

	for (i = g; i < N; i++)
	{
		j = i;

		while (p[j] < p[j - g] && j - g >= 0)
		{
			swap(&p[j], &p[j - g]);
			j -= g;
			cnt++;
		}
	}
}

void shell_sort(int p[], int n)
{
	int i, j;
	int m = 1;

	cnt = 0;

	int G[100];

	G[0] = 1;

	//	if (n >= 4)
		//{
	for (i = 1; G[i - 1] * 3 + 1 < n; i++)
	{
		G[i] = G[i - 1] * 3 + 1;
		m++;
	}
	//	}

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

	for (i = m - 1; i >= 0; i--)
	{
		insertion_sort2(p, n, G[i]);
		printf("%d", G[i]);
		if (i != 0)
			printf(" ");
	}


	printf("\n%d\n", cnt);
}




void init()
{
	front = rear = 0;
}

void enqueue(pro* x)
{
	if (next(rear) == front)
		printf("ERROR\n");

	queue[rear] = x;
	rear = next(rear);
}

pro* dequeue()
{
	pro* x;

	if (front == rear)
		printf("NO DATA\n");

	x = queue[front];
	front = next(front);

	return x;
}

int empty()
{
	return front == rear;
}

int main()
{
	int n, q;
	int now = 0;

	//pro pro2[100000];

	init();

	scanf("%d%d", &n, &q);

	int i, j;
	char temp[11];
	int num;

	pro s[SIZE];

	for (i = 0; i < n; i++)
	{
		scanf("%s%d", s[i].name, &(s[i].time));
		//scanf("%s%d", temp,&num);
		//strcpy(s[i].name, temp);
		//s[i].time = num;
		enqueue(&s[i]);
	}

	pro* t;

	while (1)
	{
		t = dequeue();
		if ((*t).time - q <= 0)
		{
			now += (*t).time;
			printf("%s %d\n", (*t).name, now);

			if (empty())
				break;
		}
		else
		{
			(*t).time -= q;
			now += q;

			enqueue(t);
		}
	}
	return 0;
}


Measured memory_bytes: 3288
#include <cstdio>
#include <cstdlib>
#include <string>
#include <iostream>
using namespace std;

struct Node {
	int key;
	Node* right, * left, * parent;
};

Node* root, * NIL;

void insert(int k) {
	Node* y = NIL;
	Node* x = root;
	Node* z;

	z = (Node*)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while (x != NIL) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		}
		else {
			x = x->right;
		}
	}
	z->parent = y;
	if (y == NIL) {
		root = z;
	}
	else {
		if (z->key < y->key) {
			y->left = z;
		}
		else {
			y->right = z;
		}
	}
}

void inorder(Node* u) {
	if (u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}
void preorder(Node* u) {
	if (u == NIL) return;
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
}
int main() {
	int N, i, X;
	string com;
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> com;
		if (com == "insert") {
			cin >> X;
			insert(X);
		}
		else if (com == "print") {
			inorder(root);
			cout << endl;
			preorder(root);
			cout << endl;
		}
	}
}


Measured memory_bytes: 26600
#include<stdio.h>
int main(void)
{
	int a,s,d,i,f,g,max,h;
	scanf("%d",&a);
		while(a!=0){
		max=-1;
		for(i=1;i<=a;i++){
			scanf("%d %d %d",&s,&d,&f);
			g=d+f;
			if(max<g){
				max=g;
				h=s;
			}
		}

	printf("%d %d\n",h,max);
	scanf("%d",&a);
	}
	
	return 0;
}

	
	

Measured memory_bytes: 1028
//C++14 (Clang 3.8.0)

#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;


int main(){
    string s;
    cin>>s;
    if(s.size()==1 or s.size()==1 ){cout<<"-1 -1"<<endl; return 0;}
    if(s[0]==s[1]){cout<<1<<" "<<2<<endl;return 0;}
    for(int i=0;i<s.size()-2;i++){
        if(s[i]==s[i+1] or s[i]==s[i+2] ) {cout<<i+1<<" "<<i+3<<endl;return 0;}
        }
    cout<<"-1 -1"<<endl;
    return 0;
};


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

ll rec(int ix, ll cur, ll sum, vector<int>& D)
{
  int n = D.size();
  if (ix >= n) { return cur + sum; }
  return rec(ix + 1, cur * 10 + D[ix], sum, D) + rec(ix + 1, D[ix], sum + cur, D);
}

int main()
{
  string S; cin >> S;
  vector<int> D;
  int n = S.size();
  for (int i = 0; i < n; ++i) {
    D.push_back(S[i] - '0');
  }
  ll ans = rec(1, D[0], 0, D);
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
import math
n=int(input())
#li=input().split()
li=list(map(int,input().split()))
#n=input()
A=0
for i in range(n):
    A+=li[i]
x=A/n
a=math.ceil(x)-x
b=x-math.floor(x)
if a-b>=0:
    N=math.floor(x)
else:
    N=math.ceil(x)
ans=0
for i in range(n):
    ans+=(N-li[i])**2

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,a) REP(i,0,a)
using namespace std;

int par[101]; // parent
int ranks[101]; // depth of tree

void init(int n) {
    rep(i, n) {
        par[i] = i;
        ranks[i] = 0;
    }
}

int find(int x) {
    if (par[x] == x) {
        return x;
    }
    else {
        return par[x] = find(par[x]);
    }
}

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    
    if (ranks[x] < ranks[y]) {
        par[x] = y;
    }
    else {
        par[y] = x;
        if (ranks[x] == ranks[y]) ranks[x]++;
    }
}

bool same(int x, int y) {
    return find(x) == find(y);
}

struct edge {int u; int v; int cost; };

bool comp(const edge& e1, const edge& e2) {
    return e1.cost < e2.cost;
}

// Entry point
int main(void){
    while (1) {
        int N,M;
        cin >> N >> M;
        if (N == 0) break;
        
        edge es[M];
        rep(i,M) cin >> es[i].u >> es[i].v >> es[i].cost;
        sort(es, es+M, comp);
        
        init(N);
        int ans = 0;
        rep(i,M) {
            edge e = es[i];
            if (!same(e.u, e.v)) {
                unite(e.u, e.v);
                ans += e.cost;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>

int main() {
    long long int n, t, ma = 0, mi = 1000000001;
    std::cin >> n;
    for (long long int i = 0; i < n; i++) {
        std::cin >> t;
        if (t > ma) ma = t;
        if (mi > t) mi = t;
    }
    std::cout << ma - mi << std::endl;
    return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    cout << s[0] << s[1] << s[2] << endl;
}

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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int>a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = k; i < n; i++) {
    if (a.at(i) > a.at(i-k)) {
      cout << "Yes" << endl;
    }
    else cout << "No" << endl;
  }
}

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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
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; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int A, B; cin >> A >> B;
  //main
  
  
  // output
  if(B%A == 0){cout << A+B << endl;}
  else{cout << B-A << endl;}

  return 0;
}


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

using namespace std;

const int N=1005;
int n,m,a[15][N],k,dem[15];
bool fin[15];

int calc(int mask)
{
    for(int i=1;i<=n;i++) fin[i]=false;
    for(int i=0;i<n;i++) if(mask>>i&1) fin[i+1]=true;
    int j=1,res=0;
    while(j<=m)
    {
        res++;
        for(int i=1;i<=n;i++) dem[i]=0;
        int j1=j;
        while(j1<=m)
        {
            int cnt=1,mx=0;
            for(int i=1;i<=n;i++)
            {
                dem[cnt]+=a[i][j1];
                mx=max(mx,dem[cnt]);
                if(fin[i]) cnt++;
            }
            if(mx>k) break;
            j1++;
        }
        if(j1==j) return 1e9;
        j=j1;
    }
    return res-1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m>>k;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            char c;
            cin>>c;
            a[i][j]=c-'0';
        }
    }
    int res=m*n;
    for(int i=0;i<(1<<(n-1));i++) res=min(res,__builtin_popcount(i)+calc(i));
    cout<<res;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int limit = 2e5;

using namespace std;

vector<ll> h(limit,0);
vector<ll> b(limit,0);
vector<ll> tree(4*limit,0);

ll max(ll a,ll b){
  if(a>b)
    return a;
  return b;
}

void updateTree(ll node,ll l,ll r,ll height,ll val){
	if(l==r){
		tree[node] = max(tree[node],val);
		return;
	}
	ll mid=(l+r)/2;
	if(mid>=height)
		updateTree(2*node,l,mid,height,val);
	else
		updateTree(2*node+1,mid+1,r,height,val);

	tree[node] = max(tree[2*node],tree[2*node+1]);
}

ll queryTree(ll node,ll l,ll r,ll ql,ll qr){
	if(ql<=l && qr>=r)
		return tree[node];
	
	if(qr<l || ql>r)
		return 0;

	ll mid = (l+r)/2;
	ll left = queryTree(2*node,l,mid,ql,qr);
	ll right = queryTree(2*node+1,mid+1,r,ql,qr);
	return max(left,right);
}


int main(){
	ll n,i,m=0;
	cin>>n;

	for(i=0;i<n;i++)
		cin>>h[i];
	for(i=0;i<n;i++)
		cin>>b[i];

	vector<ll> dp(n,0);
	//memset(tree,0,sizeof(tree));
	dp[0]=b[0];
	m=max(m,dp[0]);
	updateTree(1,1,n,h[0],dp[0]);

	for(i=1;i<n;i++){
		dp[i]=b[i]+queryTree(1,1,n,0,h[i]-1);
		m=max(m,dp[i]);
        updateTree(1,1,n,h[i],dp[i]);
	}

	cout<<m<<endl;

}

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

using namespace std;

#define int long long

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

int a,b;

signed main(){
	cin>>a>>b;
	int c=gcd(a,b);
	cout<<a*b/c<<endl;
}










Measured memory_bytes: 256
//
// Created by yamunaku on 2019/08/24.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int m,d;
    cin >> m >> d;
    int ans=0;
    repl(i,1,m+1){
        repl(j,10,d+1){
            int x=j%10;
            int y=j/10;
            if(x>=2&&y>=2&&x*y==i) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
let z=(-1);;let rec g()=Scanf.scanf"%d %d %d
"(fun m f r->if m>z||f>z||r>z then g(print_endline(if m=z||f=z then"F"else let x=m+f in if x>79then"A"else if x>64then"B"else if x>49||x>29&&r>49then"C"else if x>29then"D"else"F")));;g()

Measured memory_bytes: 2348
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair < int, int >;

const int mod = 1e9 + 7;
void add_self (int & a, int b) {
	a += b;
	if (a >= mod) a -= mod;
}
int add (int a, int b) {
	int c = a + b;
	if (c >= mod) c -= mod;
	return c;
}
int sub (int a, int b) {
	int c = a - b;
	if (c < 0) c += mod;
	return c;
}
int mul (int a, int b) {
	return (ll) a * b % mod;
}

int main() {
	int n; string s;
	cin >> n >> s;
	assert ((int)s.length() == n - 1);
	vector < int > dp (n + 1);
	dp[1] = 1;
	for (int element = 2; element <= n; element++) {
		vector < int > dp_new (n + 1);
		vector < int > P (n + 2);
		for (int i = 1; i < n + 2; i++) {
			P[i] = add (P[i - 1], dp[i - 1]);
		}
		for (int prev = 1; prev <= element; prev++) {
			int start, end;
			if (s[element - 2] == '<') {
				start = 1, end = prev - 1;
			} else {
				start = prev, end = element - 1;
			}
			add_self (dp_new[prev], sub (P[end + 1], P[start]));
			//for (int j = start; j <= end; j++) {
				//add_self (dp_new[prev], dp[j]);
			//}
		}
		dp = dp_new;
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		add_self (ans, dp[i]);
	}
	printf ("%d\n", ans);
	return 0;
}



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



int main() {
    

    
    int temp;
    int Kx;

    
    int N ;
    int M ;
    cin >> N >> M ;
    vector<int> vec(M);
    for (int x=0 ; x<N ; x++){
        cin >> Kx ;
        for (int y=0 ; y<Kx ; y++){
            cin >> temp ;
            vec.at(temp-1) += 1;
        }
    }
    int sum = 0;
    for (int p=0 ; p<M ; p++){
        if(vec.at(p)==N){
        sum += 1;
        }
    }
    cout << sum << endl;
}


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

struct FenwickTree{
  int n;
  vector<int> bit;
  FenwickTree(int x=0):n(x){bit = vector<int>(x+1,0);}

  inline void add(int i, int x){
    while(i<=n){
      bit[i] += x;
      i += i & -i;
    }
  }

  inline int sum(int i){
    int res = 0;
    while(i > 0){
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }

  inline int partial_sum(int l, int r){ return sum(r) - sum(l-1); }
};

int n,k;
vi r;

bool compare_sa(int i, int j){
  if(r[i]!=r[j]) return r[i] < r[j];
  int ri = i+k<=n ? r[i+k] : -1;
  int rj = j+k<=n ? r[j+k] : -1;
  return ri < rj;
}

void construct_sa(string &s, vi &sa){
  n = s.size();
  r.resize(n+1);
  vi tmp (n+1);
  sa.resize(n+1);
  
  rep(i,n+1){
    sa[i] = i;
    r[i] = i<n ? s[i] : -1;
  }

  for(k=1;k<=n;k*=2){
    sort(sa.begin(), sa.end(), compare_sa);

    tmp[sa[0]] = 0;
    for(int i=1;i<=n;i++){
      tmp[sa[i]] = tmp[sa[i-1]] + (compare_sa(sa[i-1], sa[i]) ? 1 : 0);
    }
    rep(i,n+1)r[i] = tmp[i];
  }
}

int find(const vi &sa, const string &T, const string &S){
  int a = 0, b = sa.size();
  while(b - a > 1){
    int c = (a+b)/2;
    if(S.compare(sa[c], T.size(), T) < 0) a = c;
    else b = c;
  }
  return b;
}


int main(){
  string s;
  int q;
  cin >> s >> q;

  vi sa;
  construct_sa(s,sa);

  vector<pii> query;
  rep(i,sa.size()){
    query.push_back( pii(sa[i], -i-1) );
  }

  vector<pii> LR(q);
  rep(i,q){
    string M;
    int L, R;
    cin >> L >> R >> M;
    R -= M.size() - 1;

    int A = find(sa, M, s);
    int B = find(sa, M+"|", s);
    
    LR[i] = pii(A,B);
    query.push_back( pii(L-1, 2*i) );
    query.push_back( pii(R, 2*i+1) );
  }

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

  vector<int> ans(q,0);
  FenwickTree bit(sa.size());
  for(pii p : query){
    if(p.second < 0){
      bit.add(-p.second, 1);
    }else{
      int lq = LR[p.second/2].first, rq = LR[p.second/2].second;
      int num = bit.partial_sum(lq+1, rq);
      
      if(p.second & 1){
	ans[p.second/2] += num;
      }else{
	ans[p.second/2] -= num;
      }
    }
  }

  for(int i=0;i<q;i++){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 9240
#include <stdio.h>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long Int;

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        int a[3];
        rep (i, 3) scanf("%d", a+i);
        sort(a, a+3);
        bool ans = ((Int)a[0]*a[0]+(Int)a[1]*a[1] == (Int)a[2]*a[2]);
        puts(ans ? "YES" : "NO");
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n) cin >> a[i];
    int cnt[n + 1] = {};
    cnt[0] = 3;
    ll ans = 1;
    rep(i, 0, n) {
        ans *= cnt[a[i]];
        ans %= MOD;
        cnt[a[i]]--;
        cnt[a[i] + 1]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
int fibonacci(int);
int main(void)
{
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}
int fibonacci(int n)
{
  int i;//counter
  int *F=(int*)malloc(sizeof(int)*(n+1));
  F[0]=F[1]=1;
  for(i=2;i<=n;i++) F[i]=F[i-2]+F[i-1];
  return F[n];
}



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

int main() {
  int n,m;
  cin >> n >> m;
  vector<vector<int>> s(m);
  for(int i = 0; i < m; i++){
    int k;
    cin >> k;
    for(int j = 0; j < k; j++){
      int temp;
      cin >> temp;
      temp--;
      s[i].push_back(temp);
    }
  }
  vector<int> p(m);
  for(int i = 0; i < m; i++) cin >> p[i];

  ll ans = 0;
  for(int bit = 0; bit < (1 << n); bit++){
    bool flg = true;
    for(int i = 0; i < m; i++){
      int cnt = 0;
      for(int v : s[i]){
        if(bit & (1<<v)) cnt++;
      }
      if(cnt % 2 != p[i]) flg = false; 
    }
    if(flg) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using pii=std::pair<int,int>;
using namespace std;

const int maxn = 2e5 + 5;

int n, k, a[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    for(int i = k; i < n; i++)
        if(a[i] > a[i - k])
            cout << "Yes\n";
        else
            cout << "No\n";
    return 0;
}

Measured memory_bytes: 5200
# -*- coding: utf-8 -*-
N, K = map(int, input().split(' '))
points = [list(map(int, input().split(' '))) for i in range(N)]

X = list(set([x for x, y in points]))
Y = list(set([y for x, y in points]))

X.sort()
Y.sort()

ans = float('inf')
for i, min_x in enumerate(X):
    for max_x in X[i+1:]:
        for j, min_y in enumerate(Y):
            for max_y in Y[j + 1:]:
                m = (max_x - min_x) * (max_y - min_y)
                internal_points = [(x, y) for x, y in points if min_x <= x <= max_x and min_y <= y <= max_y]
                if len(internal_points) >= K:
                    ans = min(ans, m)

print(ans)

Measured memory_bytes: 59272
#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i > (b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod=1000000007;
//ll mod=67280421310721;
//ll mod=998244353;
ll INF=1e18;
ll po(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2==1)
		{
			res*=a;
			res%=mod;
		}
		a*=a;
		a%=mod;
		b>>=1;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
//	cin>>test;
	while(test--)
	{
		int n;
		cin>>n;
		ll a[n];
		FOR(i,0,n)
		cin>>a[i];
		if(n==1)
		cout<<0;
		else if(n%2==0)
		{
			ll s=0,g=0;
			FOR(i,0,n)
			{
				if(i%2==0)
				s+=a[i];
			}
			ll ma=s;
			for(int i=n-1;i>0;i-=2)
			{
				s-=a[i-1];
				g+=a[i];
				ma=max(ma,(s+g));
			}
			cout<<ma;
		}
		else
		{
			ll dp[n+1][3];
			dp[0][0]=a[0];
			dp[0][1]=(-1*INF);
			dp[0][2]=(-1*INF);
			dp[1][0]=(-1*INF);
			dp[1][1]=a[1];
			dp[1][2]=(-1*INF);
			dp[2][0]=a[0]+a[2];
			dp[2][1]=(-1*INF);
			dp[2][2]=a[2];
			FOR(i,3,n)
			{
				dp[i][0]=dp[i-2][0]+a[i];
				dp[i][1]=max(dp[i-3][0],dp[i-2][1])+a[i];
				dp[i][2]=max( (i>3 ? dp[i-4][0] : 1),max(dp[i-3][1],dp[i-2][2])) +a[i];
			}
			cout<<max(dp[n-1][2],max(dp[n-2][1],dp[n-3][0]));
//			FOR(i,0,n)
//			{
//				cout<<dp[i][0]<<' '<<dp[i][1]<<' '<<dp[i][2]<<'\n';
//			}
		}
		
	}
	return 0;
}

Measured memory_bytes: 9904
n = int(input())
a = list(map(int, input().split()))
b = []
cnt = 0

for x in a:
    if x % 2 == 0:
        b.append(x)

for j in range(len(b)):
    while(b[j] % 2 == 0):
        cnt += 1
        b[j] /= 2

print(cnt)


Measured memory_bytes: 4148
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

const int MOD = 1000000007;

long long solve(const string& s)
{
    int n = s.size() / 2;
    int tmp = 0;
    long long ans = 1;
    for(int i=0; i<2*n; ++i){
        if((s[i] == 'B') ^ (tmp % 2 == 0)){
            if(tmp == 0)
                return 0;
            ans *= tmp;
            ans %= MOD;
            -- tmp;
        }
        else{
            ++ tmp;
        }
    }
    if(tmp != 0)
        return 0;

    for(int i=1; i<=n; ++i){
        ans *= i;
        ans %= MOD;
    }
    return ans;
}

int main()
{
    int n;
    string s;
    cin >> n >> s;

    cout << solve(s) << endl;

    return 0;
}


Measured memory_bytes: 644
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	X := getInt()
	ans := 1
	for i := 2; i*i <= X; i++ {
		n := i
		for n*i <= X {
			n *= i
		}
		ans = max(ans, n)
	}
	out(ans)
}


Measured memory_bytes: 1776
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
#define endl "\n";
int main() {
#ifndef ONLINE_JUDGE
	freopen("i.txt", "r", stdin);
	freopen("o.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	int cnt = 0, best = 0;
	for (int i = 0; i < n; i++) {
		int t, s;
		cin >> t >> s;
		if (t == s) {
			cnt++;
			best = max(best, cnt);
		}
		else {
			cnt = 0;
		}
	}
	if (best >= 3) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
}

Measured memory_bytes: 3640
// Aaradhya Beri
#pragma GCC optimze("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef long double f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define w(x) int x; cin>>x; while(x--)
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;

int powm(int a, int b) {
    int res=1;
    while(b) {
        if(b&1)
            res=(res*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return res;
}
 

signed main() {
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    cout<<fixed<<setprecision(8);
    ll x;cin>>x;
   ll res=(x%11<=6)? ((x%11==0)? (x/11)*2:(x/11)*2+1):(x/11)*2+2;
   cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
inf = float('inf')
dp = [inf]*N
dp[0] = 0
for i in range(0,N-1):
    dp[i+1] = min(dp[i+1],dp[i]+abs(H[i]-H[i+1]))
    if i>=N-2:
        continue
    dp[i+2] = min(dp[i+2],dp[i]+abs(H[i]-H[i+2]))
print(dp[-1])


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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

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

bool hikaku(P a, P b)
{
    return a.second < b.second;
}
int main()
{
    int n,m;cin >> n >> m;
    vector<P> vc(m);
    rep(i,m)
    {
        int a,b;cin >> a >> b;
        vc[i] = P(a,b);
    }

    sort(vc.begin(),vc.end(), hikaku);
    int counter = 0;
    int temp = 0;
    rep(i,m)
    {
        if (i==0)
        {
            counter++;
            temp = vc[i].second;
        }

        if(vc[i].first < temp) continue;
        counter++;
        temp = vc[i].second;
        
    }
    cout << counter << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>   
using namespace std;
int n, ans = 0;
int qwq[600010];

int qw(int x)
{
	if (qwq[x]) return qwq[x];
	int j;
	for (j = 1; x / j; j *= 10);
	return qwq[x] = j * 10;
}

int zgw(int x) 
{
	int j;
	for (j = 1; x / j; j *= 10);
	return x / (j / 10);
}

int zdw(int x) {return x % 10;}

int main()
{
	scanf("%d", &n);
	
	for (int i = 1; i <= n; ++i)
	{
		int zd = zgw(i), zg = zdw(i);
		if (!zg) continue;
		if (zd == zg) ans++;
		for (int j = 0; ; j++)
		{
			if (zd + qw(j) * zg + j * 10 > n) break;
			for (int k = qw(j); zd + k * zg + j * 10 <= n; k *= 10) ans++;
			
			//cout << i << " " << zd + qw(j) * zg + j * 10 << endl;
		}
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


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

	ll N,n=2;
	cin >> N;
	if(N==1||N==2){
		cout << 1 << endl;
		return 0;
	}
	vector<ll> C,dp(N+3,0),sum(N+3,0);
	C.push_back(0);
	FOR(i,0,N){
		ll k;
		cin >> k;
		if(C.size()==1){
			C.push_back(k);
		}else if(k!=C[n-1]){
			C.push_back(k);
			n++;
		}
	}
	N = n;
	dp[1] = 1;
	sum[C[1]] = 1;
	FOR(i,2,N+1){
		dp[i] = (dp[i-1] + sum[C[i]])%MOD;
		sum[C[i]] = dp[i];
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 5620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int, char>> sc(m);
    rep(i,m){
        int s;
        char c;
        cin >> s >> c;
        s--;
        sc[i] = make_pair(s, c);
    }


    rep(i, pow(10,n)){
        bool ok = true;
        string iStr = to_string(i);
        if (iStr.size() < n) continue;
        for(auto& scc : sc){
            if (iStr[scc.first] != scc.second) ok = false;
        }
        if (ok){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
su = sum(a)
res = 0
for x in a:
    res += su*x
    res -= x*x
print(res//2%mod)


Measured memory_bytes: 97440
import java.util.*;

public class Main{
    public static void main(String[] args){
         Scanner sc = new Scanner(System.in);
	        int number = sc.nextInt();
	        int a[] = new int[number];
	        for(int i = 0; i < number;i++){
	            a[i] = sc.nextInt();
	        }
	        for(int j = number-1;j >= 0;j--) {
	        	System.out.print(a[j]);
	        	if(j != 0){
	        	    System.out.print(" ");
	        	}
	        }
	        System.out.println();
    }
}


Measured memory_bytes: 26196
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main() {
	int n;
	double sum=0;
	int a[107];
	scanf("%d", &n);
	for (int i = 0;i < n;i++) {
		scanf("%d", &a[i]);
		sum += (double)1 / a[i];
	}
	printf("%f", 1 / sum);
	
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>

typedef long long int ll;

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

    return gcd(b,a%b);
}

int main(){

    int K;
    scanf("%d",&K);

    int sum=0ll;
    for(int i=1;i<=K;i++)
        for(int j=1;j<=K;j++)
            for(int k=1;k<=K;k++)
                sum+=gcd(gcd(j,k),i);

    printf("%lld\n",sum);

    return 0;
}


Measured memory_bytes: 1720
s = input()
n = len(s)
mod = 10**9+7
DP = [[0 for i in range(13)] for j in range(n+1)]
DP[0][0] = 1
for i in range(n):
    if s[i] != "?":
        x = int(s[i])
        for j in range(13):
            DP[i+1][(j*10+x)%13] = (DP[i+1][(j*10+x)%13]+DP[i][j])%mod
    else:
        for j in range(13):
            for k in range(10):
                DP[i+1][(j*10+k)%13] = (DP[i+1][(j*10+k)%13]+DP[i][j])%mod
print(DP[n][5])

Measured memory_bytes: 66396
import static java.lang.Math.*;
import static java.util.Arrays.*;
import java.util.*;
import java.io.*;

public class Main {
	
	final long INF = 1001001001;
	void solve() {
		int N = sc.nextInt();
		int[][] p = new int[N][2];
		for (int i = 0; i < N; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();
			p[i][0] = min(x, y);
			p[i][1] = max(x, y);
		}
		sort(p, new Comparator<int[]>(){
			@Override
			public int compare(int[] a, int[] b) {
				if (a[0] != b[0]) return Integer.compare(a[0], b[0]);
				return Integer.compare(a[1], b[1]);
			}
		});
		long Rmax = 0, Bmax = 0;
		long Rmin = INF, Bmin = INF;
		for (int i = 0; i < N; i++) {
			Rmax = max(Rmax, p[i][0]);
			Rmin = min(Rmin, p[i][0]);
			Bmax = max(Bmax, p[i][1]);
			Bmin = min(Bmin, p[i][1]);
		}
		long ans = (Rmax - Rmin) * (Bmax - Bmin);
		
		long Gmax = max(Rmax, Bmax);
		long Gmin = min(Rmin, Bmin);

		ans = min(ans, (Gmax - Gmin) * f(p));
		out.println(ans);
	}
	
	long f(int[][]p) {
		TreeSet<Long> st = new TreeSet<>();
		for (int i = 0; i < p.length; i++) {
			st.add( ((long)p[i][0] << 20) + i );
		}
		long res = d(st);
		for (int i = 0; i < p.length; i++) {
			st.remove(((long) p[i][0] << 20) + i);
			st.add(((long) p[i][1] << 20) + i);
			res = min(res, d(st));
		}
		return res;
	}
	
	long d(TreeSet<Long> st) {
		long mi = (st.first() >> 20);
		long ma = (st.last() >> 20);
		return ma - mi;
	}
	
	static void tr(Object... os) { System.err.println(deepToString(os)); }
	static void tr(int[][] as) { for (int[] a : as) tr(a); }

	void print(int[] a) {
		out.print(a[0]);
		for (int i = 1; i < a.length; i++) out.print(" " + a[i]);
		out.println();
	}

	public static void main(String[] args) throws Exception {
		new Main().run();
	}

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 73312
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 inf = 10^^9 + 7;

void main() {
    int n, k;
    scan(n, k);
    auto h = readln.split.to!(int[]);

    auto dp = new int[](n);

    foreach (i ; 1 .. n) {
        dp[i] = inf;
        foreach (j ; max(0, i - k) .. i) {
            dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
        }
    }

    writeln(dp[n-1]);
}







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: 4260
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;

int n,m,s1,s2,c[100005];
bool AC[100005];

int main()
{
    scanf("%d%d",&n,&m);
    while(m--)
    {
        int p;
        char s[5];
        scanf("%d%s",&p,s);
        if(*s=='A'&&!AC[p])++s1,AC[p]=true;
        else if(*s=='W'&&!AC[p])++c[p];
    }
    for(int i=1;i<=n;++i)if(AC[i])s2+=c[i];
    printf("%d %d\n",s1,s2);
    return 0;
}


Measured memory_bytes: 768