akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,j,n) for (int i = j; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
    int a,b;
    cin >> a >> b;
    if(a>9 || b >9){
        cout<<"-1"<<endl;
        return 0;
    }
    cout<<a*b<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;

#define N 100010
int par[N];
int rnk[N];
int weight[N];

void init(int n){
    for(int i=0;i<n;i++){
        par[i] = i;
        weight[i] = 1;
        rnk[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(rnk[x] < rnk[y]){
        weight[find(y)] += weight[find(x)];
        par[x] = y;
    }
    else{
        weight[find(x)] += weight[find(y)];
        par[y] = x;
        if(rnk[x] == rnk[y]) rnk[x]++;
    }
}

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

//----------------------------------------------------------------
signed main(){

	ll n,m;
	cin >> n >> m;
	priority_queue<ll> p;
	rep(i,n){
		ll a;cin >> a;
		p.push(a);
	}

	rep(i,m){
		ll a = p.top();
		p.pop();
		p.push(a/2);
	}
	
	ll ans = 0;
	rep(i,n){
		ans += p.top();
		p.pop();
	}
	cout << ans << endl;


	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc141.contest.atcoder.jp/tasks/abc141_b

Measured memory_bytes: 1400
/*
    Life Before Death, Strength Before Weakness, Journey Before Destination
    ------------------------------------------------------------------------
    You don't become great by trying to be great.
    You become great by wanting to do something,
    and then doing it so hard that you become great in the process.
    */

    //#pragma comment(linker, "/stack:200000000")
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
    #include <bits/stdc++.h>
    using namespace std;
    
    #define TRACE
    
    #ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
      cerr << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
      const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
    #else
    #define trace(...)
    #endif
    
    #define rep(i, n)    for(int i = 0; i < (n); ++i)
    #define repA(i, a, n)  for(int i = a; i <= (n); ++i)
    #define repD(i, a, n)  for(int i = a; i >= (n); --i)
    #define trav(a, x) for(auto& a : x)
    #define all(x) x.begin(), x.end()
    #define sz(x) (int)(x).size()
    #define fill(a)  memset(a, 0, sizeof (a))
    #define fst first
    #define snd second
    //#define mp make_pair
    #define pb push_back
    #define PI           3.141592653589793238462643383279502884197169399  /* pi */
    #define te  ll ti;   cin >> ti;  while(ti--) solve();  
    typedef long double ld;
    typedef long long ll;
    typedef pair<ll, ll> pii;
    typedef vector<ll> vi;
    const int maxN = 200500;

    void solve() {
      ll n;
      cin >> n;
      ll a[n], sum = 0, mi = 1e10, nc = 0;
      rep(i, n) cin >> a[i], sum+=abs(a[i]), mi = min(mi, abs(a[i])), (a[i] < 0 ? nc++:0);
      ll ans = ((mi == 0 || nc%2 == 0) ? sum : sum - 2 * mi);
      cout << ans << endl;
    }

    int main() {
      cin.sync_with_stdio(0); cin.tie(0);
      cin.exceptions(cin.failbit);
      //te
      solve();
      return 0;
    }       

Measured memory_bytes: 1024
n, l = map(int, input().split())
s = []
for i in range(1, n+1):
    s.append(l+i-1)
a = 10**19
h = 0
for i in range(n):
    # 誤差が小さい。
    if a > abs(s[i]):
        a = abs(s[i])
        h = s[i]
print(sum(s)-h)

Measured memory_bytes: 9188
N,K =map(int,input().split())
result = [0]*(10**5+1)
for i in range(N):
  a,b = map(int,input().split())
  result[a] += b
count = 0
for j in range(len(result)):
  count += result[j]
  if count >= K:
    print(j)
    break

Measured memory_bytes: 5748
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

struct UnionFind {
	vector<int> data;
	UnionFind(int sz) { data.assign(sz, -1); }
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return false;
		if (data[x] > data[y]) swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	int find(int k) {
		if (data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
	int size(int k) { return -data[find(k)]; }
};

int main() {
	int N, M, K; cin >> N >> M >> K;
	vector<vector<int>> fri(N), blo(N);
	UnionFind uf(N);
	while (M--) {
		int a, b; cin >> a >> b;
		--a, --b;
		fri[a].push_back(b);
		fri[b].push_back(a);
		uf.unite(a, b);
	}
	while (K--) {
		int c, d; cin >> c >> d;
		--c, --d;
		blo[c].push_back(d);
		blo[d].push_back(c);
	}
	for (int i = 0; i < N; ++i) {
		int res = uf.size(i) - 1;
		res -= fri[i].size();
		for (auto ng : blo[i])
			if (uf.find(i) == uf.find(ng))
				--res;
		cout << res << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 12152
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <math.h>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> P;
#define M 1000000007
#define F first
#define S second
#define PB push_back
char s[100005];
int n,ans;
int main(void){
    cin>>s;
    n=strlen(s);
    for(int i=0;i<n;i++){
        if(i%2==1&&s[i]=='g')ans++;
        if(i%2==0&&s[i]=='p')ans--;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    REP(i, X - K + 1, X + K - 1) {
        if(i != X - K + 1) cout << " ";
        cout << i;
    }
    cout << endl;

    return 0;
}


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

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using pli=pair<ll,int>;

#define fi first
#define se second
#define pb push_back
#define sz(x) int((x).size())
#define fast ios_base::sync_with_stdio(0); cin.tie(0);
#define testcase int _;cin>>_;while(_--)
#define all(x) ((x).begin(),(x).end())

/*A-*/
void Solve(){
	int x;
	cin>>x;
	if(x>=30)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}

int main(){
	fast
	//testcase
		Solve();
	return 0;
}

Measured memory_bytes: 3632
package main

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

func main() {
	var n int
	fmt.Scanf("%d", &n)

	var list [][]int

	b := true
	scanner := bufio.NewScanner(os.Stdin)

	for b {
		b = scanner.Scan()
		t := scanner.Text()
		if b == false {
			break
		}
		stringSplited := strings.Split(t, " ")
		var l []int
		for i := range stringSplited {
			var iparam int
			iparam, err := strconv.Atoi(stringSplited[i])
			if err != nil {
				return
			}
			l = append(l, iparam)
		}
		list = append(list, l)
	}

	//fmt.Printf("%v", list)

	// calc
	var point int
	for i := 0; i < n; i++ {
		point += list[1][i]

		if (i < n - 1) {
			if (list[0][i]+1 == list[0][i+1]) {
				point += list[2][list[0][i]-1]
              	//fmt.Printf(" %d ", list[0][i]-1)
			}
		}
	}
	fmt.Printf("%d", point)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    ll N;
    cin >> N;
    bool can = false;
    REP(i, 28) {
        REP(j, 15) {
            if ( i*4+j*7 == N) can = true;
        }
    }
    if (can) cout << "Yes\n";
    else cout << "No\n";
}


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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long long> a(N);
    vector<long long> x(N);
    vector<long long> n(N);

    long long x_whole = 0;
    for (int i = 0; i < N; i++){
        cin >> a[i];
    }
    for (int i = 0; i < N; i++)
    {
        x[i] = (a[i] ^ a[(i + 1) % N]);
        if((i % 2) == 0){
            x_whole = (x_whole ^ x[i]);
        }
    }
    for (int i = 0; i < N; i++){
        n[i] = (a[(i + 1)%N] ^ x_whole ^ x[i]);
        printf("%ld ", n[i]);
    }
    printf("\n");
}   

Measured memory_bytes: 8012
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define ALL(x) x.begin(),x.end()

void solve(){
  int n; string s; cin >> n >> s;
  if(n>=3200) cout << s << '\n';
  else cout << "red" << '\n';
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

bool solve(vector<int> a) {
	int n = a.size();
	if (n % 2 == 0) {
		int res = 0;
		for (int x : a) {
			res = (res ^ x) & 1;
		}
		return res;
	}

	int s = 0;
	for (int x : a) {
		s += x % 2;
	}
	if (s > 1 || *min_element(all(a)) == 1) {
		return (s % 2 != n % 2);
	} else {
		if (s % 2 != n % 2) {
			return 1;
		}
		int g = 0;
		for (int& x : a) {
			x -= x % 2;
			g = __gcd(g, x);
		}
		for (int& x : a) {
			x /= g;
		}
		return !solve(a);
	}
}

int main(){

	int n = nxt();
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		a[i] = nxt();
	}

	cout << (solve(a) ? "First" : "Second") << "\n";

	return 0;
}

Measured memory_bytes: 9984
from collections import Counter
n = int(input())
cnt = Counter(list(map(int, input().split())))
cnt_2 = 0
for v in cnt.values():
    if v == 1: continue
    if v % 2: n -= v - 1
    else:
        n -= v - 2
        cnt_2 += 1
print(n-(cnt_2+1)//2*2)

Measured memory_bytes: 18656
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int k;
  cin >> k;

  int ans = ((k % 2 == 0) ?
      (k / 2) * (k / 2) : (k / 2) * (k / 2 + 1));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// unihernandez22
// https://atcoder.jp/contests/abc153/tasks/abc153_a
// math

use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();

    let words: Vec<i64> = s
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();

    let h = words[0];
    let a = words[1];

    println!("{}", (h + a-1) / a);
}


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

long long ans = 0, x;

int main(){
	cin>>x;
  	ans += 1000 * (x/500);
  	x -= (x/500) * 500;
  	ans += 5 * (x/5);
  	cout<<ans<<endl;
  	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll n;
vector<ll> sgs;

bool ok(ll x){
	int seven = 0;
	int five = 0;
	int three = 0;

	while(x > 0){
		if(x % 10 == 7) seven++;
		else if(x % 10 == 5) five++;
		else if(x % 10 == 3) three++;
		x /= 10;
	}

	return (seven > 0) && (five > 0) && (three > 0);
}

void dfs(ll x, ll d){
	if(ok(x) && x <= n){
		sgs.push_back(x);
	}
	if(d == 0) return;

	dfs(x * 10 + 7, d - 1);
	dfs(x * 10 + 5, d - 1);
	dfs(x * 10 + 3, d - 1);
}

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

	cin >> n;
	dfs(0LL, 9LL);
	cout << sgs.size() << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define loop(i,N) for(ll (i)=0; (i)<(N);++(i))
struct _OMAZINAI_ { _OMAZINAI_() { std::ios::sync_with_stdio(false); std::cin.tie(0); } } __omazinai_instance__;
#define INF (1LL<<61 + 1<<29)
typedef long long int ll;

int main() {
	int R;
	cin >> R;
	if (R < 1200)
		cout << "ABC" << endl;
	else if (R < 2800)
		cout << "ARC" << endl;
	else
		cout << "AGC" << endl;
}

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

namespace Sample101
{
    struct Card
    {
        public char suit;
        public char value;
    }

    class Program
    {
        static void BubbleSort(Card[] C)
        {
            for (int i = 0; i < C.Length; i++)
            {
                for (int j = C.Length - 1; j >= i + 1; j--)
                {
                    if (C[j].value < C[j - 1].value)
                    {
                        var temp = C[j];
                        C[j] = C[j - 1];
                        C[j - 1] = temp;
                    }
                }
            }
        }

        static void SelectionSort(Card[] C)
        {
            for (int i = 0; i < C.Length; i++)
            {
                int minj = i;
                for (int j = i; j < C.Length; j++)
                {
                    if (C[j].value < C[minj].value)
                    {
                        minj = j;
                    }
                }
                var temp = C[i];
                C[i] = C[minj];
                C[minj] = temp;
            }
        }

        static void Print(Card[] C)
        {
            for (int i = 0; i < C.Length; i++)
            {
                Console.Write(C[i].suit.ToString() + C[i].value.ToString());
                if (i != C.Length -1)
                {
                    Console.Write(" ");
                }
            }
            Console.WriteLine();
        }

        static bool isStable(Card[] C1, Card[] C2)
        {
            for (int i = 0; i < C1.Length; i++)
            {
                if (C1[i].suit != C2[i].suit)
                {
                    return false;
                }
            }
            return true;
        }

        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var line = Console.ReadLine().Split(' ');

            // ソート対象のカードの束を二つ用意する
            Card[] cards1 = new Card[N];
            Card[] cards2 = new Card[N];
            for (int i = 0; i < N; i++)
            {
                cards1[i].suit = line[i][0];
                cards1[i].value = line[i][1];
                cards2[i].suit = line[i][0];
                cards2[i].value = line[i][1];
            }

            // それぞれソートする
            BubbleSort(cards1);
            SelectionSort(cards2);

            // バブルソートの結果
            Print(cards1);
            Console.WriteLine("Stable");
            // 選択ソートの結果
            Print(cards2);
            if (isStable(cards1, cards2))
            {
                Console.WriteLine("Stable");
            } else
            {
                Console.WriteLine("Not stable");
            }

        }
    }
}


Measured memory_bytes: 15996
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> list = new ArrayList<Integer>();
        while(true){
            int a = sc.nextInt();
            if(a==0){
                break;
            }
            list.add(a);
        }
        for(int i=1;i<=list.size();i++){
            System.out.println("Case "+i+": "+list.get(i-1));
        }
    }
}



Measured memory_bytes: 43744
"use strict"
function main(arg) {
    let a = arg.trim().split("\n")[1].split(" ").map(Number)
    let N = a.length
    let ans = 0
    for (let i = 0; i < N; i++) {
        if ((i+1) % 2 === 0) {
            continue
        }
        if (a[i] % 2 === 0) {
            continue
        }
        ans++
        // console.log(i)
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 29672
#include<queue>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#define F(i,n,v) for(register int i=1;i<=n;i+=v)
#define R(i,n,v) for(register int i=n;i>=1;i-=v)
#define LL long long
#define mod 1000000007
#define inf 0x7ffffff
using namespace std;
inline int read();
inline int read()
{
	char c;
	while((c=getchar())<'0'||c>'9');
	int res=c-48;
	while((c=getchar())>='0'&&c<='9')
	   res=res*10+c-48;
	return res;
}const int MAXN=100+5; 
struct Road
{
	int c,t;
	#define c(i) r[i].c
	#define t(i) r[i].t
}r[MAXN]; 
bool cmp(Road a,Road b)
{return a.t<b.t;}
int main()
{
    int n,t;
	scanf("%d%d",&n,&t);
	for(int i=1;i<=n;i++)
	   scanf("%d%d",&c(i),&t(i));
	sort(r+1,r+1+n,cmp);
	int maxc=inf;
	for(int i=1;i<=n;i++)
	{
		if(t(i)>t)
		{
		    if(i==1)
			{printf("TLE");exit(0);}
			else break;
	    }
		if(maxc>c(i))maxc=c(i);
	}printf("%d\n",maxc);
	return 0;
}

Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <cstdlib>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional> 
#include <iomanip>
#include <unordered_map>
#include <memory.h>
#include <cstring>
#include <fstream>

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k, t;
	int res = 0;

	cin >> n >> k;

	for (int i = 0; i < n; i++)
	{
		cin >> t;
		res += (t >= k);
	}

	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

vector<pair<ll, int>> fac;
void PrimeFactorInit(ll x){ // 素因数と個数のペアを返す.
    if(x >= 2){
        for(ll i = 2; i <= x; i++){
            if(i * i > x)break;
            if(x % i == 0){
                int cnt = 0;
                while(x % i == 0){
                    cnt++;
                    x /= i;
                }
                pair<ll, int> p;
                p.first = i;
                p.second = cnt;
                fac.push_back(p);
            }
        }
        if(x > 1){
            pair<ll, int> p;
            p.first = x;
            p.second = 1;
            fac.push_back(p);
        }
    }
}

// ax + by = gcd(a, b) となるような (x, y) を求める
// a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰
    y -= a / b * x;
    return d;
}


// 負の数に対応した mod
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}


// 逆元計算 (a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // x % m だが、x が負かもしれないので
}

ll cnt[1001001] = {};

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

    ll a[n];
    rep(i,n)cin >> a[i];

    ll MOD = 1000000007;

    

    rep(i,n){
        fac.clear();
        PrimeFactorInit(a[i]);
        rep(j,fac.size()){
            cnt[fac[j].first] = max(cnt[fac[j].first], (ll)fac[j].second);
        }
    }

    ll ans = 0;

    ll mul = 1;
    rep(i,1001001){
        if(cnt[i] == 0)continue;
        rep(j,cnt[i]){
            mul = mul * i % MOD;
        }
    }

    rep(i,n){
        ans += modinv(a[i], MOD);
        ans %= MOD;
    }
    
    ans *= mul;
    ans %= MOD;

    cout << ans << endl;
    return 0;
}
//a * b + c * b = (a+c)*b mod でなくても一緒



Measured memory_bytes: 7404
n,c[1<<17],a,i,t,s;
main(){
	for(scanf("%*d");~scanf("%d",&a);)c[a]++;
	for(;++i<1<<17;){
		s+=!!c[i];
		while(c[i]>2)c[i]=c[i]/3+c[i]%3;
		t+=c[i]==2;
	}
	printf("%d\n",s-t%2);
}


Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN=2e5;
ll a[MAXN+5],b[MAXN+5],f[MAXN+5];
ll n,k,tot,ans;
bool cmp(ll a,ll b)
{
	return a>b;
}
bool Check(ll x)
{
	for(int i=1;i<=n;i++)
		b[i]=x/f[i];
	ll res=0;
	for(int i=1;i<=n;i++)
		res+=max(0ll,a[i]-b[i]);
	return res<=k;
}
ll BS()
{
	ll l=0,r=(ll)1e12;
	while(l+1<=r)
	{
		ll mid=(l+r)>>1;
		//printf("l:%lld r:%lld mid:%lld\n",l,r,mid); 
		if(Check(mid))
			r=mid;
		else
			l=mid+1;
	}
	return r;
}
int main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		tot+=a[i];
	}
	for(int i=1;i<=n;i++)
		scanf("%lld",&f[i]);
	if(tot<=k)//个人值可被减完 
	{
		printf("0\n");
		return 0;
	}
	sort(a+1,a+n+1);
	sort(f+1,f+n+1,cmp);
	printf("%lld\n",BS());
	return 0;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<string>
#include<iostream>
#include<vector>
#include<cstdlib>
#include<stdio.h>
#include<cmath>
#include<limits>
#include<iomanip>

using namespace std;

template <class T> using V = vector<T>;

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 long long INF = 1LL << 60;

using ll = long long;
using db = long double;
using st = string;
using ch = char;
using bl = bool;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;
using vbl = V<bl>;
using graph = V<V<int>>;
using pq = priority_queue<ll>;



#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define rFOR(i,a,b) for(ll i=(a);i>=(b);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define pb(a) push_back(a);



ll Sum(ll n) {
ll m=0;
  while(n){
    m+=n%10;
    n/=10;
  }
  return m;
}



const int MAX = 510000;
const int MOD = 1000000007;
 
long long fac[MAX], finv[MAX], inv[MAX];
 
void Comuse() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


#define comuse Comuse()

ll combi(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll perm(int n,int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] % MOD) % MOD;
}


ll lcm(ll a,ll b){
  ll n;
  n=a/gcd(a,b)*b;
  return n;
}


vll div(ll n){
  vll ret;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0){
      ret.push_back(i);
      if(i*i!=n){
        ret.push_back(n/i);
      }
    }
  }
  SORT(ret);
  return (ret);
}

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

    a=a*a%mod;
    
    n>>=1;
  }

  return ans;
}

void Solve();


const int MAX_N = 131072;
//segment tree 
int NN;
int seg[MAX_N*2-1];
void seguse(){
  for(int i=0;i<2*NN-1;i++){
    seg[i]=INT_MAX;
  }
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;
  Solve();
}




/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/
//segtreeの葉の先頭の添え字はn-1
void Solve(){
  //vll segtree(524287);
  //ll N=262144;
  ch c;
    cin>>c;
  c++;
  cout<<c<<"\n";
}

Measured memory_bytes: 384
N = int(input())
ans = 0
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))

for i in range(N - 1, -1, -1):
    mod = (ans + AB[i][0]) % AB[i][1]
    if mod == 0:
        continue
    else:
        ans += AB[i][1] - mod

print(ans)


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

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

  if ( (a+b) > (c+d) ) {
    cout << "Left" << endl;
  }else if ( (a+b) < (c+d) ){
    cout << "Right" << endl;
  }else{
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <cstring>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <vector>
#include <fstream>
#include <list>
#include <iomanip>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(s) memset(s, 0, sizeof(s))
const int inf = 0x3f3f3f3f;
//#define LOCAL

struct fPoint
{
	float x;
	float y;
};

float sign (fPoint p1, fPoint p2, fPoint p3)
{
    return (p1.x - p3.x) * (p2.y - p3.y) - (p2.x - p3.x) * (p1.y - p3.y);
}

bool PointInTriangle (fPoint pt, fPoint v1, fPoint v2, fPoint v3)
{
    bool b1, b2, b3;

    b1 = sign(pt, v1, v2) < 0.0f;
    b2 = sign(pt, v2, v3) < 0.0f;
    b3 = sign(pt, v3, v1) < 0.0f;

    return ((b1 == b2) && (b2 == b3));
}


int main(int argc, char * argv[]) 
{
	#ifdef LOCAL
	freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.in", "r", stdin);
	//freopen("/Users/huangjiaming/Documents/Algorithm/oj/data.out", "w", stdout);
	#endif

	fPoint x1, x2, x3, xp;

	while (~scanf("%f %f %f %f %f %f %f %f", &x1.x, &x1.y, &x2.x, &x2.y, &x3.x, &x3.y, &xp.x, &xp.y))
	{
		if (PointInTriangle(xp, x1, x2, x3))
			puts("YES");
		else
			puts("NO");
	}

    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
struct node
{
	int to,dis;
	node(){}
	node(int x,int y):to(x),dis(y){}
};
#define INF 1000000000
int n,m,f[100005],b[100005];
vector<node> a[100005];
void spfa(int x)
{
	queue<int> p;
	p.push(x);
	b[x]=1;
	f[x]=0;
	while (!p.empty())
	{
		int v=p.front();
		p.pop();
		for (int i=0;i<a[v].size();i++)
		{
			if (f[a[v][i].to]==INF)
			{
				f[a[v][i].to]=f[v]+a[v][i].dis;
				b[a[v][i].to]=1;
				p.push(a[v][i].to);
			}
			else if (f[a[v][i].to]!=f[v]+a[v][i].dis)
			{
				cout<<"No";
				exit(0);
			}
		}
	}
}
int main()
{
	cin>>n>>m;
	for (int i=1;i<=n;i++)
	{
		f[i]=INF;
	}
	int x,y,z;
	for (int i=1;i<=m;i++)
	{
		scanf("%d %d %d",&x,&y,&z);
		a[x].push_back(node(y,z));
		a[y].push_back(node(x,-z));
	} 
	for (int i=1;i<=n;i++)
	{
		if (b[i]==0)
		{
			spfa(i);
		}
	}
	cout<<"Yes";
} 

Measured memory_bytes: 9728
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
	int x;
	cin >> x;
	cout<<(x < 1200 ? "ABC" : "ARC")<<endl;
}


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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX / 100;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<char> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;
const int mod = 1000000007;

const double PI = 3.14159265358979323846;

int main() {
    double r;
    cin >> r;
    printf("%.20f %.20f\n", PI * r * r, PI * 2 * r);
}


Measured memory_bytes: 3160
import sys
from collections import deque

sys.setrecursionlimit(10 ** 9)
input = sys.stdin.readline

######################################################

H, W = [int(_) for _ in input().split()]

G = [list(input()) for _ in range(H)]
INF = 1e10
G2 = [[INF] * W for _ in range(H)]

lst = deque()
lst.append((0, 0, 0))
while lst:
    y, x, v = lst.popleft()
    if G2[y][x] < INF: continue
    G2[y][x] = v
    if y == H - 1 and x == W - 1:
        break

    for a, b in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
        ny = y + a
        nx = x + b
        if 0 <= ny < H and 0 <= nx < W:
            if G[ny][nx] == '.':
                lst.append((ny, nx, v + 1))
if G2[H - 1][W - 1] == INF:
    print(-1)
    exit()

white_cnt = 0
for i in range(H):
    for j in range(W):
        white_cnt += G[i][j] == '.'
print(white_cnt - G2[H-1][W-1]-1)


Measured memory_bytes: 3316
line1 = list(map(lambda x: int(x), input().split()))
N = line1[0]
M = line1[1]
X = list(map(lambda x: int(x), input().split()))

if N >= M or M == 1:
  print(0)
else:
  X.sort(key=lambda x:x, reverse=False)

  diff = list(map(lambda x: x[0]-x[1], zip(X[1:],X[:-1])))
  diff.sort(key=lambda s:s, reverse=False)

  if N == 1:
    print(sum(diff))
  else:
    print(sum(diff[:-(N-1)]))


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

int main(){
  int N,M;
  cin >> N >> M;
  vector<int> X(M),Y(M-1);
  for(int i=0;i<M;i++)cin >> X[i];
  sort(X.begin(),X.end());
  for(int i=0;i<M-1;i++){Y[i]=X[i+1]-X[i];}
  //vector<pair<int,int>> a(N);
  //for(int i=0;i<M-1;i++){a[i]=make_pair(Y[i],i);}
  sort(Y.begin(),Y.end());
  int ans=X[M-1]-X[0];
  if(N==1){cout << ans << endl;}
  else if(N>=M){cout << 0 << endl;}
  else{
    for(int i=M-2;i>=M-N && i>=0;i--){
      ans-=Y[i];
    }
    cout << ans << endl;
  }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N, K;
  IN(N,K);

  ll ans = 1;
  while(N>=K){
    ans++;
    N/=K;
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 256
using System;

class main {
  static void Main() {
    int[] c = new int[10000];
    for (int i = 0; i < 10000; i++) {
      c[i] = 0;
    }

    for (int i = 0, x; i < 10000; i++) {
      x = int.Parse(Console.ReadLine());
      if (x == 0) {
        break;
      } else {
        c[i] = x;
      }
    }

    for (int i = 0; i < 10000; i++) {
      if (c[i] != 0) {
        Console.WriteLine("Case {0}: {1}", i+1, c[i]);
      } else {
        break;
      }
    }
  }
}

Measured memory_bytes: 9400
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<pair<string, int>> st(n);
  rep(i, n){
    string s;
    cin >> s;
    int t;
    cin >> t;
    st.at(i) = {s, t};
  }
  string x;
  cin >> x;
  int ans = 0;
  bool f = false;
  for(auto [s, t] : st){
    if(f == true){
      ans += t;
    }else if(s == x){
      f = true;
    }
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;

int main () {
	string s;
  	cin >> s;
  	if (s.at(0) == s.at(1) && s.at(0) == s.at(2)) {
    cout << "No" << endl;
    }
  	else {
    cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std::literals;
using namespace std;

namespace xmaho
{
  inline namespace input
  {
    template<typename T>
    T get_value(std::istream& is = std::cin);
    template<typename C>
    C get_container(std::istream& is = std::cin, typename C::size_type length = std::numeric_limits<typename C::size_type>::max());
  }
}
using namespace xmaho;

int main()
{
    double r;
      cin >> r;
        cout << 2. * r * 3.14159 << endl;
          return 0;
}

class initalization
{
    class custom_numpunct: public std::numpunct<char>
      {
          public:
              using numpunct::numpunct;
                protected:
                    std::string do_truename() const override { return "Yes"; }
                        std::string do_falsename() const override { return "No"; }
                          };

                          public:
                            initalization()
                              {
                                    std::ios_base::sync_with_stdio(false);
                                        std::cin.tie(nullptr);
                                            std::cout.imbue(std::locale(std::cout.getloc(), new custom_numpunct{}));
                                                std::cout << std::boolalpha << std::fixed << std::setprecision(15);
                                                  }
} initalize;

template<typename T>
T xmaho::input::get_value(std::istream& is)
{ T v {}; is >> v; return v; }

template<typename C>
C xmaho::input::get_container(std::istream& is, typename C::size_type length)
{
    C v {};
      if (length != std::numeric_limits<typename C::size_type>::max())
            v.reserve(length);
              typename C::value_type e {};
                for (auto i {length}; i != 0 && is >> e; --i)
                      v.push_back(std::move_if_noexcept(e));
                        return v;
}



Measured memory_bytes: 3848
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int x;
    cin>>x;
    long long int h1=(x/500)*1000;
    int a5=x%500;
    long long int h2=(a5/5)*5;
    long long int h=h1+h2;
    cout<<h<<endl;
    return 0;
}

Measured memory_bytes: 256
//ABC140 A
import java.util.Scanner;
public class Main{
  public static void main(String[]args){
    Scanner sc=new Scanner(System.in);
    int N;
    N=sc.nextInt();
    int ans=1;
    int n=1;
    while(n<=3){
      ans=ans*N;
      n++;
    }
    System.out.println(ans);

  }
}


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

int main()
{
    int n;
    string str;
    cin >> n;
    vector<vector<int> > num(26, vector<int>(n, 0));

    for (int i = 0; i < n; i++) {
        cin >> str;
        for (int j = 0; j < str.size(); j++) {
            num[str[j]-97][i]++;
        }
    }

    for (int i = 0; i < 26; i++) {
        int mini = 50;
        for (int j = 0; j < n; j++) {
            mini = min(mini, num[i][j]);
        }
        for (int j = 0; j < mini; j++) {
            cout << char('a'+ i);
        }
    }

	return 0;
}


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

typedef pair<int, int> P;

const int INF = 10000000;

int H, W, N;
char maze[1000][1000];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
P cheeze[10];
int **d;

int main(){
	cin >> H >> W >> N;
	for (int i = 0; i<H; i++){
		for (int j = 0; j<W; j++){
			cin >> maze[i][j];
			if (maze[i][j] == 'S') cheeze[0] = make_pair(i, j);
			int n = maze[i][j] - '0';
			for (int k = 1; k <= N; k++){
				if (n == k) cheeze[n] = make_pair(i, j);
			}
		}
	}
	int ans = 0;
	int num = 1;
	while (num <= N){
		queue<P> que;
		int sx = cheeze[num - 1].first;
		int sy = cheeze[num - 1].second;
		int gx = cheeze[num].first;
		int gy = cheeze[num].second;
		
		d = new int*[H];
		for (int i = 0; i < H; i++){
			d[i] = new int[W];
		}
		for (int i = 0; i < H; i++){
			for (int j = 0; j < W; j++){
				d[i][j] = INF;
			}
		}
		que.push(P(sx, sy));
		d[sx][sy] = 0;
		
		while (que.size()){
			P p = que.front();
			que.pop();
			if (p.first == gx&&p.second == gy) break;

			for (int i = 0; i < 4; i++){
				int nx = p.first + dx[i];
				int ny = p.second + dy[i];
				if (0<=nx&&nx < H&&ny >= 0 && ny < W&&d[nx][ny] == INF&&maze[nx][ny] != 'X'){
					d[nx][ny] = d[p.first][p.second] + 1;
					que.push(P(nx, ny));
				}
			}
		}
		ans += d[gx][gy];
		for (int i = 0; i < H; i++){
			delete[] d[i];
		}
		delete[] d;
		num++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6020
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int dp[1<<9][100010];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi v(n),w(n);
    rep(i,n) cin >> v[i] >> w[i];
    rep(i,1<<9) rep(j,100010) dp[i][j] = -inf;
    dp[0][0] = 0;
    rep2(i,1,min(1<<9,n+1)) rep(j,100010) {
        int par = i/2;
        chmax(dp[i][j],dp[par][j]);
        if(j >= w[i-1]) chmax(dp[i][j],dp[par][j-w[i-1]]+v[i-1]);
    }
    rep(i,1<<9) rep(j,100009) chmax(dp[i][j+1],dp[i][j]);
    int q;
    cin >> q;
    rep(_,q) {
        int u,l;
        cin >> u >> l;
        if(u < 1<<9) {
            cout << dp[u][l] << "\n";
            continue;
        }
        vi can;
        while(u >= 1<<9) {
            can.pb(u);
            u /= 2;
        }
        int ans = 0;
        int sz = can.size();
        rep(bit,1<<sz) {
            int nw = 0,nv = 0;
            rep(i,sz) if(bit>>i&1) {
                nw += w[can[i]-1];
                nv += v[can[i]-1];
            }
            if(nw > l) continue;
            chmax(ans,nv+dp[u][l-nw]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 205396
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Scanner in = new Scanner(System.in);
		int[] char_count = new int[26];


		while(in.hasNextLine()){

			String str = in.nextLine();


			if(str.length() == 0){
				break;
			}else{

				// str = in.next();
				// ??????????°????????????????
				String lower_case = str.toLowerCase();
				// ????????????1????????????????????????????????????????´?
				// char[] charArray = lower_case.toCharArray();

				for (int i = 0; i < lower_case.length(); i++) {

					if(lower_case.charAt(i) == 'a'){

						char_count[0]++;

					}else if(lower_case.charAt(i) == 'b'){

						char_count[1]++;

					}else if(lower_case.charAt(i) == 'c'){

						char_count[2]++;

					}else if(lower_case.charAt(i) == 'd'){

						char_count[3]++;

					}else if(lower_case.charAt(i) == 'e'){

						char_count[4]++;

					}else if(lower_case.charAt(i) == 'f'){

						char_count[5]++;

					}else if(lower_case.charAt(i) == 'g'){

						char_count[6]++;

					}else if(lower_case.charAt(i) == 'h'){

						char_count[7]++;

					}else if(lower_case.charAt(i) == 'i'){

						char_count[8]++;

					}else if(lower_case.charAt(i) == 'j'){

						char_count[9]++;

					}else if(lower_case.charAt(i) == 'k'){

						char_count[10]++;

					}else if(lower_case.charAt(i) == 'l'){

						char_count[11]++;

					}else if(lower_case.charAt(i) == 'm'){

						char_count[12]++;

					}else if(lower_case.charAt(i) == 'n'){

						char_count[13]++;

					}else if(lower_case.charAt(i) == 'o'){

						char_count[14]++;

					}else if(lower_case.charAt(i) == 'p'){

						char_count[15]++;

					}else if(lower_case.charAt(i) == 'q'){

						char_count[16]++;

					}else if(lower_case.charAt(i) == 'r'){

						char_count[17]++;

					}else if(lower_case.charAt(i) == 's'){

						char_count[18]++;

					}else if(lower_case.charAt(i) == 't'){

						char_count[19]++;

					}else if(lower_case.charAt(i) == 'u'){

						char_count[20]++;

					}else if(lower_case.charAt(i) == 'v'){

						char_count[21]++;

					}else if(lower_case.charAt(i) == 'w'){

						char_count[22]++;

					}else if(lower_case.charAt(i) == 'x'){

						char_count[23]++;

					}else if(lower_case.charAt(i) == 'y'){

						char_count[24]++;

					}else if(lower_case.charAt(i) == 'z'){

						char_count[25]++;

					}

				}
			}

			/*}else{

					break;



			}*/
		}


		// ??¢????????????????????????????????????????????¨?????°?????¨???
		char a = 'a';

		for(int i = 0; i < 26; i++){

			System.out.println(a++ + " : " + char_count[i]);

		}
	}
}

Measured memory_bytes: 26096
#include<stdio.h>
#include<string.h>
int main(){
	int n,a,b,i,j,k,m,c=0;
	char s[26],w[101];
	scanf("%d %s",&n,s);
	a=strlen(s);
	for(i=0;i<n;i++){
		scanf("%s",w);
		b=strlen(w);
		for(j=0;j<b;j++){
			for(k=1;k<b;k++){
				for(m=0;m<a&&m*k+j<b;m++){
					if(s[m]!=w[m*k+j])break;
					if(m==a-1)++c,k=b,j=b;
				}
			}
		}
	}
	printf("%d\n",c);
	return 0;
}


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

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  string S;
  cin >> N >> S;
  int white_array[N];
  int black_array[N];
  int white_count=0,black_count=0;
  for (int i = 0; i < N; i++) {
    if(S[i]=='.'){
      white_count++;
      if(i==0){
        white_array[0]=1;
        black_array[0]=0;
      }else{
        white_array[i]=white_array[i-1]+1;
        black_array[i]=black_array[i-1];
      }
    }
    else {
      black_count++;
      if(i==0){
        black_array[0]=1;
        white_array[0]=0;
      }else{
        white_array[i]=white_array[i-1];
        black_array[i]=black_array[i-1]+1;
      }
    }
  }

  int reverse_count = 2000000;
  for (int i = 0; i < N+1; i++) {
    if(i==0){
      reverse_count = min(reverse_count,white_count);
    }else if(i==N){
      reverse_count = min(reverse_count,black_count);
    }else{
      reverse_count = min(reverse_count,black_array[i-1]+white_count-white_array[i-1]);
    }
  }
  cout << reverse_count <<endl;
}


Measured memory_bytes: 2180