akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	a := SScan(n)
	x := make([][3]int, n)
	for i := 0; i < n; i++ {
		f := false
		c := 0
		m := []string{}
		for _, v := range a[i] {
			if string(v) == "." {
				f = true
			} else {
				m = append(m, string(v))
				if f {
					c++
				}
			}
		}
		y := stringToInt(strings.Join(m, ""))
		x[i] = [3]int{0, 0, c}
		for y%2 == 0 {
			x[i][0]++
			y /= 2
		}
		for y%5 == 0 {
			x[i][1]++
			y /= 5
		}
		x[i][0] = smaller(18, x[i][0])
		x[i][1] = smaller(18, x[i][1])
	}
	d := make(map[[3]int]int)
	for _, v := range x {
		d[v]++
	}
	ans := 0
	key := make([][3]int, 0, len(d))
	for k, v := range d {
		key = append(key, k)
		p := smaller(k[0]*2, k[1]*2)
		q := k[2] * 2
		if p >= q {
			ans += (v*v - v) / 2
		}
	}
	for i := 0; i < len(key); i++ {
		for j := i + 1; j < len(key); j++ {
			k := key[i]
			l := key[j]
			v := d[k]
			w := d[l]
			p := smaller(k[0]+l[0], k[1]+l[1])
			q := k[2] + l[2]
			if p >= q {
				ans += v * w
			}
		}
	}
	fmt.Println(ans)
}
func PrimeFactors(n int) (pfs []int) {
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}
	for i := 3; i*i <= n; i = i + 2 {
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}
	if n > 2 {
		pfs = append(pfs, n)
	}
	return
}


Measured memory_bytes: 29004
/**
 *    author:  otera    
**/
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void solve() {
	int n; cin >> n;
    cout << (n + 1) / 2 << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			int Q = scan.nextInt();
			int []a = new int[N];
			long []s = new long[N+1];
			
			for(int i = 0;i<N;i++) {
				a[i] = scan.nextInt();
				s[i+1] = s[i]+a[i];
			}
			long []x  = new long[Q];
			for(int i = 0;i<Q;i++)x[i] = scan.nextLong();
			
			for(int i = 0;i<Q;i++) {//最大500回
				long X = x[i];
				int right=0;
				long goukei = 0;
				for(int left = 0;left<N;left++) {
					while(right<N&&s[right+1]-s[left]<=X) {
						right++;
					}
					goukei += (right-left);
				}
				
				System.out.println(goukei);
				
				
				
				
			}
			
			
		}
		
		
	}
		

}



Measured memory_bytes: 70028
#include "bits/stdc++.h"
using namespace std;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define eb emplace_back
#define ins insert
#define ph push
#define f first
#define s second
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ll(x.size())
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
inline long long rand(long long x, long long y) { return (rng() % (y+1-x)) + x; } //inclusivesss
string inline to_string(char c) {string s(1,c);return s;} template<typename T> inline T gcd(T a,T b){ return a==0?llabs(b):gcd(b%a,a); }

typedef long long ll; 
typedef long double ld;
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
typedef pair<ll,ll>pi; typedef pair<ll,pi>spi; typedef pair<pi,pi>dpi;

#define LLINF ((long long)1e18)
#define INF int(1e9+1e6)
#define MAXN (400006)
ll n,mod=998244353,ans,p2[MAXN];
string X;
vector<pi> v;
int main(){
	FAST
	cin>>n>>X;
	p2[0]=1; FOR(i,1,MAXN-1)p2[i]=p2[i-1]*2%mod;
	auto flip=[&](char ch){
		return ch=='1' ? '0' : '1';
	};
	auto invert_range=[&](ll st,ll en){
		string res="";
		FOR(i,st,en)res+=flip(X[i]);
		return res;
	};
	auto range=[&](ll st,ll en){
		return X.substr(st,en-st+1);
	};
	FOR(i,0,n-1)X+=flip(X[i]);
	DEC(p,2*n,1){
		if((2*n)%p)continue;
		if(((2*n)/p)%2==0)continue;
		assert(p+1&1);
		ll weight=p;
		for(auto i:v){
			if(i.f%p==0){
				weight-=i.s,weight+=mod,weight%=mod;
			}
		}
		v.eb(p,weight);
		ll x=0;
		assert((2*n)%(p/2)==0);
		string res=range(0,p/2-1);
		reverse(all(res));
		FOR(i,0,siz(res)-1){
			x+=p2[i]*ll(res[i]-'0')%mod,x%=mod;
		}
		reverse(all(res));
		// cerr<<p<<": "<<res<<'\n';
		bool can=1;
		for(ll i=0;i<2*n;i+=p/2){
			ll times=i/(p/2);
			if(times&1){
				if(invert_range(0,p/2-1)<range(i,i+p/2-1)){
					break;
				}
				can&=(invert_range(0,p/2-1)<=range(i,i+p/2-1));
			}
			else {
				if(res<range(i,i+p/2-1)){
					break;
				}
				can&=(res<=range(i,i+p/2-1));
			}
			if(!can)break;
		}
		x+=can,x%=mod;
		// cerr<<p<<": "<<x<<' '<<weight<<'\n';
		ans+=x*weight%mod,ans%=mod;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 4628
import numpy as np

n = int(input())

ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda x: x[1])
ab_np = np.array(ab)

sum_t = np.cumsum(ab_np[:, 0])


if any(ab_np[:,1]-sum_t < 0):
    print('No')
else:
    print('Yes')
    

Measured memory_bytes: 65712
#include <stdio.h>

void exchange(int *a, int *b)
{
    int c;
    c = *a; *a = *b; *b = c;
}

int main(void)
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    
    if (a >= 0 && a <= 10000 &&
        b >= 0 && b <= 10000 &&
        c >= 0 && c <= 10000) {
        if (a > b) exchange(&a, &b);
        if (a > c) exchange(&a, &c);
        if (b > c) exchange(&b, &c);
        printf("%d %d %d\n", a, b, c);
    }

    return 0;
}

Measured memory_bytes: 596
/*
    A - Favorite Sound
    https://atcoder.jp/contests/abc120/tasks/abc120_a
*/
#include <bits/stdc++.h>
using namespace std;

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

    int a, b, c;

    cin >> a >> b >> c;
    if (b / a > c)
        cout << c << endl;
    else
        cout << (b / a) << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

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

    int MAX = 10e5+1;

    vector<int> prime(MAX, 1);
    prime[0] = 0;
    prime[1] = 0;
    for (int i = 2; i * i < MAX; i++)
    {
        if (prime[i])
        {
            for (int j = 2; j * i < MAX; j++)
            {
                prime[i * j] = 0;
            }
        }
    }

    vector<int> N(MAX, 0);
    for (int i = 0; i < MAX; i++)
    {
        if (prime[i] && prime[(i + 1) / 2])
        {
            N[i] = 1;
        }
    }

    vector<int> a(MAX + 1, 0);
    for (int i = 0; i < MAX; i++)
    {
        a[i + 1] = a[i] + N[i];
    }

    for (int i = 0; i < Q; i++)
    {
        int r, l;
        cin >> l >> r;
        cout << a[++r] - a[l] << endl;
    }

    return 0;
}


Measured memory_bytes: 14820
#include<stdio.h>
#include<string.h>


int main(void) {
	int a, b = 0, i;
	char s[101];

	scanf("%s", s);
	a = strlen(s) / 2;
	
	for (i = 0; i < a; i++) {
		if (s[i] != s[strlen(s) - i -1])b++;
	}
	printf("%d", b);
	
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j=0,k=1;
    char a[10000],b[10000],c[10000];
    gets(a);
    gets(b);
    for (i=0;i<strlen(a);i++)
    {
        c[j]=a[i];
        j=j+2;
        c[k]=b[i];
        k=k+2;
    }
    puts(c);
}


Measured memory_bytes: 128
#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--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

map<ll, ll> mp;

int main(){
    int n, m;
    bool flag = true;
    cin >> n;

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

    cin >> m;
    ll t[m];
    rep(j, m) cin >> t[j];

    rep(i, n) mp[d[i]]++;

    rep(j, m){
        if (mp[t[j]] > 0) mp[t[j]]--;
        else flag = false;
    }

    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		double a=sc.nextDouble();
		double b=sc.nextDouble();
		if(a<b)		System.out.println("LESS");
		else if(a>b)		System.out.println("GREATER");
		else		System.out.println("EQUAL");

	}

}

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

int main(){
    while(true){
        int n, m, k;
        int candidate[100];
        set<int> p[100];
        int ans=0;
        cin >> n;
        if(!n) break;
        for(int i=0;i<n;++i){
            candidate[i] = 1;
            cin >> m;
            for(int j=0;j<m;++j){
                int l;
                cin >> l;
                p[i].insert(l);
            }
        }
        cin >> k;
        for(int i=0;i<k;++i){
            int l;
            cin >> l;
            for(int j=0;j<n;++j){
                if(candidate[j]){
                    if(p[j].find(l)==p[j].end()){
                        candidate[j] = 0;
                    }
                }
            }
        }
        for(int i=0;i<n;++i){
            if(candidate[i] && ans == 0) ans = i+1;
            else if(candidate[i] && ans > 0){
                ans = -1;
                break;
            }
        }
        if(ans == 0) ans = -1;
        cout << ans << endl;
    }
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

bool pr[100010];
int ac[100010];

int main() {
	pr[1] = 1;
	pr[2] = 0;

	for (int i = 2; i < 100010; ++i) {
		if (pr[i]) continue;
		for (int j = i * 2; j < 100010; j += i) {
			pr[j] = 1;
		}
	}

	for (int i = 1; i < 100010; ++i) {
		ac[i] = ac[i-1] + (!pr[i-1] && !pr[i/2]);
	}

	int q;
	cin >> q;
	while (q--) {
		int l, r;
		cin >> l >> r;
		++r;
		cout << ac[r] - ac[l] << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
N = int(input())
A = list(map(int, input().split()))

def solve(A, mode=0):
  # mode = 0 : +-+-+-...
  # mode = 1 : -+-+-+...
  res = 0
  pre_a = 0
  for i, a in enumerate(A):
    a += pre_a
    if a * (-1)**(i+mode) > 0: # 符号がmatchしている
      pre_a = a
      continue
    # 符号がmatchしていない
    res += abs(a) + 1
    pre_a = (-1) ** (i + mode)
  return res
  
ans = solve(A, mode=0)
ans = min(ans, solve(A, mode=1))
print(ans)

Measured memory_bytes: 14332
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def input():
    return sys.stdin.readline()


def resolve():
    d, target_score = map(int, input().split())
    p_list = []
    c_list = []
    for i in range(d):
        p, c = map(int, input().split())
        p_list.append(p)
        c_list.append(c)

    ans_list = []

    for bit in range(1<<d):
        # bitが1のところはボーナス
        temp_score = 0
        counter = 0
        for i in range(d):
            # print(str(bit) + ":" + str(i))

            if bit & (1<<i):
                p = p_list[i]
                c = c_list[i]

                temp_score += 100 * (i+1) * p
                temp_score += c
                counter += p
                # print(counter, i, p, temp_score, target_score)
                if temp_score >= target_score:
                    ans_list.append(counter)
                    break

        # 残りは配点の高い問題から
        for i in range(len(p_list)-1, -1, -1):
            achieve_flag = False
            # コンプリートボーナスをもらった問題は飛ばす
            if bit & (1<<i):
                continue

            for j in range(p_list[i]-1):
                temp_score += 100 * (i+1)
                counter += 1
                #print(counter, i, temp_score, target_score)
                if temp_score >= target_score:
                    achieve_flag = True
                    break

            if achieve_flag:
                ans_list.append(counter)
                break

    # 結果出力
    print(min(ans_list))


if __name__ == "__main__":
    resolve()



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

int main(){

    cin.tie( nullptr );
    ios_base::sync_with_stdio(0);

    int n; cin >> n;

    vector<ll> v(n+1, 0);
    for(int i=1; i<=n; i++)
        cin >> v[i], v[i]+=v[i-1];

    vector< vector<ll> > dp;
    dp.assign(n+1, vector<ll>(n+1,1e16));

    for(int i=1; i<=n; i++) dp[i][i] = 0;
    for(int i=1, j=2; j<=n; i++, j++) dp[i][j] = v[j] - v[i-1];

    for(int len=3; len<=n; len++)
    for(int i=1, j=len; j<=n; i++, j++){
        ll tot = v[j] - v[i-1];
        for(int k=i; k<j; k++)
            dp[i][j] = min(dp[i][j], tot+dp[i][k]+dp[k+1][j]);
    }
    cout << dp[1][n] << "\n";

//    for(int i=1; i<=n; i++)
//    for(int j=1; j<=n; j++)
//        cout << dp[i][j] << " \n"[j==n];

    return 0;
}


Measured memory_bytes: 4524
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define forever for (;;)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
template<typename A> using V = std::vector<A>;
template<typename A> using F = std::function<A>;
template<typename A, typename B> using P = std::pair<A, B>;
using pii = P<int, int>;
using vi = V<int>;
using vd = V<double>;
using vs = V<std::string>;
using vpii = V<pii>;
using vvi = V<vi>;
using vvpii = V<vpii>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
template<typename T> std::istream &operator>>(std::istream &is, std::vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> std::istream &operator>>(std::istream &is, std::pair<A, B> &p) { is >> p.first; is >> p.second; return is; }
using namespace std;
// clang-format on

main {
  int n;
  cin >> n;
  vi a(n);
  cin >> a;
  sort(all(a));
  double maxi = -INF;
  loop(i, 1, n) {
    int b = a[i] - a[i - 1];
    int t;
    if (i == n - 1) t = a[n - 3] + a[n - 4];
    if (i == n - 2) t = a[n - 1] + a[n - 4];
    if (!(i == n - 1 || i == n - 2)) t = a[n - 1] + a[n - 2];
    cmax(maxi, 1.0 * t / b);
  }
  cout << prec(32) << maxi << endl;
}

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

int v[4] = {1,0,-1,0};
int u[4] = {0,1,0,-1};

int main(){
	int h,w;
    cin >> h >> w;
    string s[h];
    rep(i,h) cin >> s[i];

    bool ans = true;

    rep(i,h)rep(j,w){
        if(s[i][j] == '#'){
            bool flag = false;
            rep(k,4){
                int ik = i + v[k];
                int jk = j + u[k];
                if(0 <= ik && ik < h && 0 <= jk && jk < w){
                    if(s[ik][jk] == '#') flag = true;
                }
            }
            if(!flag) ans = false;
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<numeric>
using namespace std;
using ll = long long;
int main(){
  int x, y;
  cin >> x >> y;
  if(x * 2 <= y && x * 4 >= y && y % 2 == 0){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}

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

int main()
{
    long N,D;
    double t;
    cin>>N>>D;
    t=N/(2.0*D+1);
    if(t==(int)(t))
    cout<<t<<endl;
    else
        cout<<(int)(t+1)<<endl;
    return 0;

}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

a = sorted([aa - (i+1) for i, aa in enumerate(a)])
if n%2 == 0:
    b = (a[n//2-1] + a[n//2])//2
else:
    b = a[n//2]
    
ans = 0
for i in range(n):
    ans += abs(a[i]-b)
print(ans)


Measured memory_bytes: 26180
#include <iostream>
#include <cstdio>
#include <cctype>

using namespace std;

int main() {

  char moji;

  while(1) {

    scanf("%c",&moji);

    if(moji == '\n')break;

    if(moji == ' ') {

      printf(" ");

      continue;

    }

    if(islower (moji) ) {

      printf("%c",toupper(moji));

    } else {

      printf("%c",tolower(moji));

    }

  }

  cout << "\n";

  return 0;

}

Measured memory_bytes: 1120
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 9223372036854775807
#define ARR_MAX 288199999999999999

void debug(char * string, long long int target) {
  printf("%s", string);
  printf("%lld", target);
  printf("%c", '\n');
}

long long a[100010];
int main() {
  int n;
  scanf("%d",&n);
  rep(i, n) {
    scanf("%lld",&a[i]);
  }

  int zero = 0;
  rep(i, n) {
    if (a[i]==0) {
      zero++;
    }
  }

  if (zero > 0) {
    //a[i] contains 0
    printf("0\n");
    return 0;
  }

  long long prod = 1;
  rep(i, n) {
    if (a[i] <= 1000000000000000000 / prod) {
      // This condition is equivalent to prod * a[i] <= 10^18
      prod*=a[i];
    } else {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", prod);
  return 0;
}


Measured memory_bytes: 2500
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>

#define ll long long

using namespace std;

int main(){
    int N,K;
    cin >> N >> K;
    string S;
    cin >> S;
    if(S[K-1]=='A'){
        S[K-1]='a';
    }
    else if(S[K-1]=='B'){
        S[K-1]='b';
    }
    else if(S[K-1]=='C'){
        S[K-1]='c';
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
    Scanner sc= new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int[][] A= new int[n][m];
    int[] B =new int[m];
    
    for(int i=0;i<n;i++){
     for(int  y=0;y<m;y++){
       A[i][y]=sc.nextInt();
     }   
    }
    
    for(int y=0;y<m;y++){
        B[y]=sc.nextInt();
    }
    int[] sul= new int[n];
     for(int i=0;i<n;i++){
     for(int y=0;y<m;y++){
        sul[i]+=A[i][y]*B[y];
     }  
     }
     
     for(int i=0;i<n;i++){
         System.out.println(sul[i]);
     
    }
    
 }
}


Measured memory_bytes: 40472
S = str(input())

first = int(S[0]) * 10 + int(S[1])
second  = int(S[2]) * 10 + int(S[3])


if first >= 1 and first <= 12:
  if second >= 1 and second <= 12:
    print('AMBIGUOUS')
  else:
    print('MMYY')
else:
  if second >= 1 and second <= 12:
    print('YYMM')
  else:
    print('NA')  

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

template<class T>
class BinaryIndexedTree {
    private:
        int N;
        std::vector<T> dat;
    public:
        BinaryIndexedTree(int n) : N(n), dat(n+1, static_cast<T>(0)) {}
        // a is 1-indexed
        void add(int a, const T v) {
            while (a <= N) {
                dat.at(a) += v;
                a += (a & -a);
            }
        }
        // return sum of [1, a]
        // a is 1-indexed
        T sum(int a) {
            T res = static_cast<T>(0);
            while (a > 0) {
                res += dat.at(a);
                a -= (a & -a);
            }
            return res;
        }
        // return sum of [a. b)
        // a and b are 1-indexed
        T sum(int a, int b) {
            return sum(b-1) - sum(a-1);
        }
};

void solve() {
    int n;
    string s;
    cin >> n >> s;

    vector<BinaryIndexedTree<int>> v(26, BinaryIndexedTree<int>(n));
    for (int i=1; i<=n; ++i) {
        v.at(s.at(i-1)-'a').add(i, 1);
    }

    int q;
    cin >> q;
    vector<int> res;
    for (int i=0; i<q; ++i) {
        int t;
        cin >> t;
        if (t == 1) {
            int ind;
            char c;
            cin >> ind >> c;
            v.at(s.at(ind-1)-'a').add(ind, -1);
            v.at(c-'a').add(ind, 1);
            s.at(ind-1) = c;
        } else {
            int l, r;
            cin >> l >> r;
            int cnt = 0;
            for (int j=0; j<26; ++j) {
                if (v.at(j).sum(l, r+1) > 0) ++cnt;
            }
            res.push_back(cnt);
        }
    }

    for (int x : res) cout << x << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 53660
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;
const ll modP = 1000000007;
#define MAX_N 10000001
vector<map<int,int>> divisors;
vector<bool> isPrime(MAX_N,true);

ll myFunc(ll X,ll MAX_NUM){
	ll Y = MAX_NUM / X;
	return Y*(Y+1)*X/2;
}

void init(int N){
	for(int i = 2; i*i <= N; i++){
		for(int j = 2; i*j <= N; j++){
			isPrime[i*j] = false;
		}
	}
	map<int,int> zero;
	divisors.push_back(zero);
	map<int,int> one;
	divisors.push_back(one);
	for(int i = 2; i <= N; i++){
		map<int,int> localMap;
		if(isPrime[i] == true){
			localMap.insert(make_pair(i,1));
			divisors.push_back(localMap);
		}else if( isPrime[i] == false){
			for(int j = 2; j * j <= i; j++){
				if( i % j == 0){
					int num1 = j;
					int num2 = i / j;
					for(auto iter1 = divisors[num1].begin(); iter1 != divisors[num1].end(); iter1++){
						if( divisors[num2].count(iter1->first) == 0){
							localMap.insert(make_pair(iter1->first,iter1->second));
						}else{
							localMap.insert(make_pair(iter1->first,iter1->second + divisors[num2][iter1->first]));
						}
					}
					for(auto iter2 = divisors[num2].begin(); iter2 != divisors[num2].end(); iter2++){
						if(divisors[num1].count(iter2->first) == 0){
							localMap.insert(make_pair(iter2->first,iter2->second));
						}
					}
				}
			}
			divisors.push_back(localMap);
		}
		
	}
}

vector<ll> enum_divisors(ll N){
	vector<ll> res;
	for(ll i = 1; i * i <= N; i++){
		if( N % i == 0){
			res.push_back(i);
			if( N/i != i) res.push_back(N/i);
		}
	}
	sort(res.begin(),res.end());
	return res;
}

ll divisorsNum(ll num){
	return enum_divisors(num).size();
}


int main()
{
	ll N;
	cin>>N;
	ll ans = 0;
	for(int i = 1; i <= N; i++){
		ans += myFunc(i,N);
	}
	cout<<ans<<endl;
	return 0;
}


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

public class Main {
    static int[] color;
    static int[][] order;
    static int n,Q;
    public static void main(String[] args)throws IOException {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        n = sc.nextInt(); Q = sc.nextInt();
        order = new int[Q][2];
        color = new int[n];
        char[] s = sc.next().toCharArray();
        for(int i=0;i<n;i++) color[i]=s[i]-'A';
        for(int i=0;i<Q;i++){
            int cur = sc.next().charAt(0)-'A';
            int dir = sc.next().charAt(0)=='L'?-1:1;
            order[i][0] = cur; order[i][1] = dir;
        }
        // find the idx left
        int left;
        if(!exitFromLeft(0)) left = 0;
        else{
            if(exitFromLeft(n-1)) left = n;
            else{
                int hi = n-1, lo = 0;
                while(hi-lo>1){
                    int mid = (hi+lo)/2;
                    if(exitFromLeft(mid)) lo=mid;
                    else hi = mid;
                }
                left = hi;
            }
        }
        int right;
        if(!exitFromRight(n-1)) right = n-1;
        else{
            if(exitFromRight(0)) right = -1;
            else{
                int hi = n-1, lo = 0;
                while(hi-lo>1){
                    int mid = (hi+lo)/2;
                    if(exitFromRight(mid)) hi=mid;
                    else lo = mid;
                }
                right = lo;
            }
        }
        System.out.println(Math.max(0,right-left+1));
    }
    static boolean exitFromLeft(int idx){
        int pos = idx;
        for(int i=0;i<Q;i++){
            if(order[i][0]!=color[pos]) continue;
            pos += order[i][1];
            if(pos==n) return false;
            if(pos<0) return true;
        }
        return false;
    }
    static boolean exitFromRight(int idx){
        int pos = idx;
        for(int i=0;i<Q;i++){
            if(order[i][0]!=color[pos]) continue;
            pos += order[i][1];
            if(pos==n) return true;
            if(pos<0) return false;
        }
        return false;
    }
}

Measured memory_bytes: 80768
n=int(input())
a=list(map(int,input().split()))

ki=0
yon=0

for i in a:
  if i%2:
    ki+=1
  elif i%4==0:
    yon+=1

if n%2:
  if ki+yon==n:
    if ki<=yon+1:
      print("Yes")
    else:
      print("No")
  elif yon>=ki:
    print("Yes")
  else:
    print("No")
elif yon>=ki:
  print("Yes")
else:
  print("No")

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

int N,M;
vector<int> B[1000000];
bool C[1000000];
void update(int n){
  for(auto b:B[n]){
    if(C[b]){
      C[b]=false;
      update(b);
    }
  }
}
int main(void){
  cin>>N>>M;
  for(int i=0;i<N;i++) C[i]=true;
  for(int i=0;i<M;i++){
    int x,y,z;
    cin>>x>>y>>z;
    B[x-1].push_back(y-1);
    B[y-1].push_back(x-1);
  }
  int cost=0;
  for(int i=0;i<N;i++){
    if(C[i]){
      C[i]=false;
      update(i);
      cost++;
    }
  }
  cout<<cost<<endl;
  return 0;
}


Measured memory_bytes: 30080
//https://atcoder.jp/contests/abc117/tasks/abc117_b
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    for( auto &x : L )
    {
        cin >> x;
    }
    sort( ALL(L) );
    cout << ( L.back() < accumulate( begin(L), end(L)-1, 0 ) ? "Yes" : "No" ) << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

k = I()
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        for c in range(1,k+1):
            g = math.gcd(a,b)
            ans += math.gcd(g,c)
print(ans)

Measured memory_bytes: 68088
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}

template<typename T>
vector<int> compress(vector<T> &v) {
  vector<T> t = v;
  sort(t.begin(), t.end());
  t.erase(unique(t.begin(), t.end()), t.end());
	vector<int> r(v.size());
  for (int i = 0; i < v.size(); i++) {
    r[i] = lower_bound(t.begin(), t.end(), v[i]) - t.begin();
  }
	return r;
}

int main() {
  int n; cin >> n;
  V a(n);
  rep(i, n) cin >> a[i];
  V b = compress(a);

  multiset<int> S;

  rep(i, n) {
    auto it = S.lower_bound(b[i]);
    if (it == S.begin()) {
      S.insert(b[i]);
    }
    else {
      S.erase(--it);
      S.insert(b[i]);
    }
  }
  cout << S.size() << endl;
  return 0;
}


Measured memory_bytes: 5752
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#define pb push_back
#define ALL(a) a.begin(), a.end()
#define FOR(i, m, n) for(int i = (int)m; i < (int)n; i++)
#define REP(i, n) FOR(i, 0, n)
using ll = long long;
ll mod = 1000000007;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    int idx = -1;
    if(a[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    FOR(i, 1, n) {
        if(a[i] != i) {
            idx = i;
            break;
        }
    }
    if(idx == -1) {
        cout << 3 << endl;
        return 0;
    }
    if(a[idx] != 0) {
        cout << 0 << endl;
        return 0;
    }
    int x = idx, y = 1, z = 0;
    long long ans = 1;
    FOR(i, idx + 1, n) {
        vector<bool> v(3, false);
        int c = 0;
        if(a[i] == x) {
            v[0] = true;
            c++;
        }
        if(a[i] == y) {
            v[1] = true;
            c++;
        }
        if(a[i] == z) {
            v[2] = true;
            c++;
        }
        if(c == 0) {
            cout << 0 << endl;
            return 0;
        }
        ans *= c; ans %= mod;
        if(v[0]) {
            x++;
        } else if(v[1]) {
            y++;
        } else {
            z++;
        }
    }
    ans *= 6; ans %= mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//
//AtCoder Beginner Contest 178
//C
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

const int mod = 1000000007;
//const int mod = 998244353;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


int main()
{
    int n;
    cin >> n;
    mint ans = 10;
    mint v9 = 9;
    mint v8 = 8;   
    ans = ans.pow(n)-v9.pow(n)-v9.pow(n)+v8.pow(n);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    double n;
    cin>>n;
    double ans=2.0*PI*n;
    cout<<ans<<endl;
}/*
./problem.exe
*/

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

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	int res=1e9;
	for(int i=0; (int)s.length()-i>=(int)t.length(); i++){
		int temp=0;
		for(int j=0; j<t.length(); j++){
			temp+=(s[i+j]!=t[j]);
		}
		res=min(res, temp);
	}
	cout << res;
}

Measured memory_bytes: 3664
import java.awt.*;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int W = sc.nextInt();
        int H = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int r = sc.nextInt();
        Rectangle bigRectangle = new Rectangle(0,0,W,H);
        Rectangle rectContainCircle = new Rectangle(x-r,y-r,2*r,2*r);
        if (bigRectangle.contains(rectContainCircle)){
            System.out.println("Yes");
        }else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 27480
N = int(input())
A = list(map(int, input().split()))

ans = 0
M = 10**9 + 7
for i in range(60):
  c0 = 0
  c1 = 0
  m = 1 << i
  for a in A:
    if a & m == 0:
      c0 += 1
    else:
      c1 += 1
  ans += (c0 * c1) * m
  ans %= M
print(ans)
    
    

Measured memory_bytes: 124432
#include <climits>
#include <cmath>
#include <algorithm>
#include <array>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
int main(int, char**)
{
	int N, M;
	cin >> N >> M;
	vector<int> L(M), R(M);
	for (int i = 0; i < M; ++i)
	{
		cin >> L[i] >> R[i];
	}
	sort(L.begin(), L.end());
	sort(R.begin(), R.end());
	auto d = R.front() - L.back() + 1;
	if (d < 0)	d = 0;
	cout << d << endl;
	return 0;
}


Measured memory_bytes: 1152
#import numpy as np
# import math
# import sys
#please work

h,w = map(int, input().split())

l = []
for val in range(h):
    l.append(input())
    
    
ans = [[0 for j in range(w)] for i in range(h)]
#ans = [[0]*w]*
#print(ans)
ans[0][0] =  1

for i in range (h):
    for j in range (w):
        #print(i, j)
        if l[i][j]=="#":
            continue
        if l[i][j] == '.':
            ans[i][j] += (ans[i-1][j] % 1000000007)+(ans[i][j-1] % 1000000007)
print(ans[h-1][w-1] % 1000000007)

Measured memory_bytes: 57000
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string o, e;
    cin >> o >> e;
    int lo = o.size(), le = e.size(), length;
    for (int i = 0; i < le; i++) {
        cout << o[i] << e[i];
    }
    if (lo > le) {
        cout << o[lo - 1] << endl;
    } else {
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')

for i in range(n):
    for j in range(i + 1, n):
        if j * 2 - i >= n:
            continue
        if s[i] == s[j] or s[j] == s[2 * j - i] or s[i] == s[2 * j - i]:
            continue
        ans -= 1

print(ans)


Measured memory_bytes: 9128
# yahoo-procon2019-qualB - Path
def main():
    *A, = map(int, open(0).read().split())
    cnt = [0] * 5
    for i in A:
        cnt[i] += 1
    flg = all(0 < i < 3 for i in cnt[1:])
    print("YES" if flg else "NO")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
n = int(input())
val = list(map(int, input().split()))
min = val[0]
max = val[0]
sum = val[0]
for i in range(1, len(val)):
    if min > val[i]:
        min = val[i]
    
    if max < val[i]:
        max = val[i]
    
    sum += val[i]

print(min, max, sum)


Measured memory_bytes: 6592
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin >> n >> m;
    vi T;
    rep(_, m){
        int A; cin >> A;
        T.emplace_back(A);
    }
    sort(_all(T), greater<int>());
    vi num = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    vi dp(n+1, -1);
    dp[0] = 0;
    rep(i, n){
        int cur = dp[i];
        if(cur < 0) continue;

        for(auto& e : T){
            int ni = i + num[e];
            if(ni > n) continue;
            chmax(dp[ni], cur + 1);
        }
    }

    stringstream ss;
    int i = n;
    while(i > 0){
        int cur = dp[i];

        for(auto& e : T){
            int ni = i - num[e];
            if(ni >= 0 and dp[ni] == cur - 1){
                i = ni;
                ss << e;
                break;
            }
        }
    }

    cout << ss.str() << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define int long long
 
signed main() {
  int n;
  cin >> n ;
  int x;
  int y;
  int z;
  x = n/100;  //100の位の値
   y=(n % 100) / 10 ; //10の位の値
   z= n-(x*100+y*10); //１の位の値
  if (x==7){
    cout << "Yes" << endl;
  }
 
  else if (y==7){
    cout << "Yes" << endl;
  }
  
  else  if (z==7){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  
  } 
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    INT(n);
    VI m(5,0);
    int p[10] = {0,0,0,0,0,0,1,1,1,2};
    int q[10] = {1,1,1,2,2,3,2,2,3,3};
    int r[10] = {2,3,4,3,4,4,3,4,4,4};
    rep(i,n){
        string s; IN(s);
        if(s[0] == 'M') m[0]++;
        else if(s[0] == 'A') m[1]++;
        else if(s[0] == 'R') m[2]++;
        else if(s[0] == 'C') m[3]++;
        else if(s[0] == 'H') m[4]++;
    }
    int ans = 0;
    rep(i,10) ans += m[p[i]] * m[q[i]] *  m[r[i]];
    ANS;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

	int l=0,r=0;

	int n;
	while(cin>>n){
		if(n==0)break;
		int state=0;
		int cnt=0;

		l=0;
		r=0;

		string str;

		for(int i=0;i<n;i++){
			cin>>str;
			
			if(str=="lu"){
				l=1;
			}
			else if(str=="ru"){
				r=1;
			}
			else if(str=="ld"){
				l=0;
			}
			else if(str=="rd"){
				r=0;
			}

			if(state==0 && l==1 && r==1){
				state++;
				cnt++;
			}
			else if(state==1 && l==0 && r==0){
				state=0;
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}

	return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	long long n;
    cin >> n;
    long long a[n];
    long long sum = 0;
    map<long long, long long> cnt;
    for (long long i = 0; i < n; i++) 
	{
		cin >> a[i];
		sum += a[i];
		cnt[a[i]]++;	
	}	
    long long q;
    cin >> q;
    while (q--) 
	{
        long long b, c;
        cin >> b >> c;
        long long x = cnt[b];
        cnt[b] = 0;
        cnt[c] += x;
        sum += (x * c) - (x * b);
        cout << sum <<endl;
    }
    return 0;
}

Measured memory_bytes: 10196
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[][] a = new int[n][10];
		for(int i = 0;i < n;i++){
			for(int j = 0;j < 10;j++){
				a[i][j] = scan.nextInt();
			}
		}
		for(int i = 0;i < n;i++){
			int minb = 0;
			int minc = 0;
			boolean flag = true;
			for(int j = 0;j < 10;j++){
				if(minb == 0 && minc == 0){
					minb = a[i][j];
				}else if(minb < a[i][j] && minc < a[i][j]){
					minb = a[i][j];
				}else if(minb < a[i][j]){
					minb = a[i][j];
				}else if(minc < a[i][j]){
					minc = a[i][j];
				}else{
					flag = false;
					break;
				}
			}
			if(flag){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}

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

struct R {
    long long X;
    long long L;

    bool operator<(const R &another) const
    {
        return X < another.X;
    };
};

bool cmp(const R &a, const R &b)
{
    if (a.X == b.X) {
        return a.L < b.L;
    }
    return a.X < b.X;
}

int main()
{
    int N;
    cin >> N;
    vector<R> robots;

    long long X, L;
    for (int i = 0; i < N; i++) {
        R r;
        cin >> X >> L;
        r.X = X - L;
        r.L = X + L;
        
        robots.push_back(r);
    }
    
    sort(robots.begin(), robots.end(), cmp);
    
    long long lastX = robots[0].X;
    long long right = robots[0].L;
    int max = 1;
    for (int i = 1; i < N; i++) {
        if (robots[i].X == lastX) {
            continue;
        }
        lastX = robots[i].X;
        
        if (right <= lastX) {
            max++;
            right = robots[i].L;
        } else {
            if (right > robots[i].L) {
                right = robots[i].L;
            }
        }
    }
    
    cout << max;
    
    return 0;
}

Measured memory_bytes: 3052
n = input()
if n[0] == '9':
    hyaku = 1
else:
    hyaku = 9
if n[1] == '9':
    ten = 1
else:
    ten = 9
if n[2] == '9':
    one = 1
else:
    one = 9
print(hyaku*100+ten*10+one)


Measured memory_bytes: 2940