akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cstdlib>
#include <iomanip>
#define rep(i,x) for(ll i=0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
using ld = long double;
using ll = long long;
const ll INF = 10010010010;
typedef pair<ll, ll> P;
using graph = vector<vector<ll>>;
const ll mod = 1000000007;
ll gcd(ll a, ll b) {//a>b
    if (a < b)swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}/*フィボナッチテンプレ
ll memo[50];
ll fibo(ll n) {
    if (memo[n] != 0)return memo[n];
    if (n <= 1)return memo[n] = n;
    else return memo[n] = fibo(n - 1) + fibo(n - 2);
}
*/
bool isp(ll n) {
    bool res = true;
    for (ll i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            res = false;
            break;
        }
    }
    return res;
}
ll ctoi(char c) {
    if (c == '0')return 0;
    else if (c == '1')return 1;
    else if (c == '2')return 2;
    else if (c == '3')return 3;
    else if (c == '4')return 4;
    else if (c == '5')return 5;
    else if (c == '6')return 6;
    else if (c == '7')return 7;
    else if (c == '8')return 8;
    else if (c == '9')return 9;
    else return -1;
}int main() {
    ll N;
    cin >> N;
    vector<ll> garden(N);
    rep(i, N)cin >> garden[i];
    bool ok = true;
    ll ans = 0;
    while (ok) {
        ok = false;
        ll cnt = 0;//0janai
        rep(i, N) {
            if (garden[i] == 0) {
                if (cnt)ans++;
                cnt = 0;
            }
            else {
                garden[i]--;
                cnt++;
                ok = true;
            }
        }
        if (cnt)ans++;
        /*rep(i, N)cout << garden[i] << " ";
        cout << endl;*/
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100000
#define NIL -1

struct Type{ 
  int p, l, r;
};
struct Type A[MAX];

int n,D[MAX];

int getDegree(int u){
  if(A[u].l!=NIL && A[u].r!=NIL) return 2;
  else if(A[u].l==NIL && A[u].r==NIL) return 0;
  else return 1;
}
 
int getDepth(int u){
  int d=0;
  while(A[u].p!=NIL){
    u=A[u].p;
    d++;
  }
  return d;
}


int getHeight(int u,int count){
  int height1=0,height2=0;
  count++;
  if(A[u].l!=NIL){
    height1=getHeight(A[u].l,count);
  }
  if(A[u].r!=NIL){
    height2=getHeight(A[u].r,count);
  }
  if(A[u].l==NIL && A[u].r==NIL){
    return count;
  }
  if(height1<height2)return height2;
  else return height1;
}

int getSibling(int u){
  int p;
  if(A[u].p==NIL)return -1;
  p=A[u].p;
  if(A[p].l==u)return A[p].r;
  if(A[p].r==u)return A[p].l;
}

void print(int u){
  int i;
  printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ",u,A[u].p,getSibling(u),getDegree(u),D[u],getHeight(u,-1));
  if(A[u].p==NIL)printf("root\n");
  else if(A[u].l==NIL && A[u].r==NIL) printf("leaf\n");
  else if(A[u].l!=NIL || A[u].r!=NIL )printf("internal node\n");
}

main(){
  int i, j,v,l,r;
  scanf("%d", &n);
  for(i=0;i<n;i++) {
    A[i].p=NIL;
    A[i].l=NIL;
    A[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    A[v].l=l;
    A[v].r=r;
    A[l].p=v;
    A[r].p=v;
  }
  for(i=0;i<n;i++){
    D[i]=getDepth(i);
  }
  for(i=0;i<n;i++) print(i);
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	cout<<(b%a==0 ? a+b : b-a)<<'\n';
	return 0;
}


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

using namespace std;

//#define int long long
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<int, P> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[] = { 0, 0, 1, -1 };
const int dx[] = { 1, -1, 0, 0 };

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dp[1001];

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

    string t, b;
    cin >> t >> b;
    dp[0] = 1;
    for(int i = 0; i < t.size(); ++i) {
        for(int j = b.size() - 1; j >= 0; --j) {
            if(t[i] == b[j]) {
                dp[j + 1] += dp[j];
                dp[j + 1] %= MOD;
            }
        }
    }
    cout << dp[b.size()] << endl;
    return 0;
}



Measured memory_bytes: 3228
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	long N;
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		N=sc.nextLong();
		long min=Long.MAX_VALUE/2;
		for(int i=1;i<=Math.sqrt(N);i++){
			if(N%i==0){
				long digit=Math.max(i, N/i);
				min=Math.min(min, digit);
			}
		}
		String s=String.format("%d", min);
		System.out.println(s.length());
	}
}

Measured memory_bytes: 23760
n = int(input())
plst = list(map(int,input().split()))
plst_sort = sorted(plst)
cnt = 0
for i in range(len(plst)):
    if plst[i] != plst_sort[i]:
        cnt += 1
if cnt == 2 or cnt == 0:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

#define MAX 100

void sort(int *, int);

int main(){
  int n, a[MAX], alice, bob;
  int i;
  scanf("%d", &n);
  if(n < 1 || MAX < n)
    return 1;

  for(i = 0; i < n; i++){
    scanf("%d", &a[i]);
    if( a[i] < 1 || 100 < a[i])
      return 1;
  }
  sort(a, n);
  alice = 0;
  bob = 0;

  for(i = 0; i < n; i++){
    if(!(i%2)){
      alice += a[i];
    }else{
      bob += a[i];
    }
  }
  printf("%d\n", alice - bob);
  
  return 0;
}

void
sort(int *array, int length){
  int i, j;
  int temp;
  
  for(i = 0; i < length -1; i++){
    for(j = length -2; i <= j; j--){
      if (array[j] < array[j+1]){
        temp = array[j];
        array[j] = array[j+1];
        array[j+1] = temp;
      }
    }
  }
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
bool pr[50001];
int prime[114514];
int length = 0; 
void insert(int p) { prime[length] = p; pr[p] = true; length++; return; }
int main() {
	insert(2);
	for (int i = 3; i <= 50000; i += 2) {
		for (int j = 0; j < length; j++)
			if (i%prime[j] == 0)goto cont;
			else if (prime[j] > sqrt(i))break;
			insert(i);
		cont:;
	}
	int n;
	while (cin >> n){
		if (!n)return 0;
		int sum = 0;
		for (int i = 2; i <= n / 2; i++)
			if (pr[i] && pr[n - i])
				sum++;
		cout << sum << endl;
	}
}

Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, m=0,tmp=0,ax=0,k=0,t[500000],p[500000],x,y,res[5000],a,b,c,GCD,two=1,kisuu=0;
	string str, str2[5000];
	cin >> n>>k;
	
	for (int i = 0; i < n; i++) {
		cin >> t[i];
		if (t[i] % 2 == 0) { two *= 2; }
		if (kisuu != 0 && t[i] % 2 == 1) { kisuu *= 2; }
		if (kisuu == 0 && t[i]%2==1) { kisuu = 1; }
		
		
	}
	if (k == 0&&kisuu==0) { cout << two ; }else{ cout << two * kisuu; }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> C(n);
    vector<vector<int>> A(n, vector<int>(m));
    rep(i, n) {
        cin >> C[i];
        rep(j, m) {
            cin >> A[i][j];
        }
    }


    int res = INF;
    rep(i, 1 << n) {
        int tot = 0;
        vector<int> X(m, 0);
        rep(j, n) {
            if(i >> j & 1) {
                tot += C[j];
                rep(k, m) {
                    X[k] += A[j][k];
                }
            }
        }
        bool check = true;
        rep(j, m) {
            if(X[j] < x) check = false;
        }
        if(check) res = min(res, tot);
    }
    if(res == INF) cout << -1 << endl;
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;
using ll = long long;



int main() {
	string  n;
	cin >> n;
	if (n[0] == '7' || n[1] == '7' || n[2] == '7') cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <array>

int f(int n) {
    return (n % 2 == 0) ? (n / 2) : (3 * n + 1);
}

int main() {
    int s;
    std::cin >> s;

    constexpr int maxA = 1000000;

    std::array<bool, maxA + 1> used;
    used.fill(false);

    int term = s;
    for (int m = 1; ; m++) {
        if (used[term]) {
            std::cout << m << std::endl;
            break;
        }

        used[term] = true;
        term = f(term);
    }

    return 0;
}

Measured memory_bytes: 1280
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

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

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

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

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func reverse(s string) string {
	b := []byte(s)
	for i, j := 0, len(b)-1; i < j; i, j = i+1, j-1 {
		b[i], b[j] = b[j], b[i]
	}
	return string(b)
}

func main() {
	defer stdout.Flush()

	s := readString()
	t := readString()

	rsb := []byte(reverse(s))
	rtb := []byte(reverse(t))

	for i := 0; i+len(rtb) <= len(rsb); i++ {
		matched := true
		for j := 0; j < len(rtb); j++ {
			if rsb[i+j] != '?' && rsb[i+j] != rtb[j] {
				matched = false
				break
			}
		}
		if matched {
			b := append(rsb[0:i], rtb...)
			b = append(b, rsb[i+len(rtb):]...)
			println(strings.Replace(reverse(string(b)), "?", "a", -1))
			return
		}
	}
	println("UNRESTORABLE")

}


Measured memory_bytes: 640
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}
    
let ab = readInts()
let a = ab[0]
let b = ab[1]
if (a+b)%2==0{
  print(Int((a+b)/2))
}else{
  print("IMPOSSIBLE")
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[n],l[n+1],r[n+1];
	for(int i=0;i<n;i++)
		cin>>a[i];
	//vector<pair<int,int>>v;
	l[0]=0;
	r[0]=0;
	l[1]=a[0];
	r[1]=a[n-1];
	for(int i=2;i<=n;i++){
		l[i]=__gcd(a[i-1],l[i-1]);
		r[i]=__gcd(a[n-i],r[i-1]);
	}
	int max_gcd=INT_MIN;
	for(int i=1;i<=n;i++){
		max_gcd=max(max_gcd,__gcd(l[i-1],r[n-i]));
	}
	cout<<max_gcd;
	return 0;
}

Measured memory_bytes: 1408
L,R=map(int,input().split())
l,r=L%2019,R%2019
x,y=L//2019,R//2019
if x<y:
  print(0)
else:
  ans=10**9
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans=min(ans,(i*j)%2019)
  print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
typedef long long LL;

LL fac[20];
char response[3];

int main()
{
	/*string s1 = "123";
	string s2 = "1230";
	if (s1 >= s2) printf("s1 is bigger\n");
		else printf("s2 is bigger\n");*/
	fac[0] = 1;
	for (int i = 1; i <= 10; i++) fac[i] = fac[i - 1] * 10;	
	LL L = 0, R = 10;
	while (L < R - 1) {
		LL mid = (L + R) >> 1;
		printf("? %lld\n", fac[mid]);
		fflush(stdout);
		scanf("%s", response);
		if (response[0] == 'Y') L = mid; 
			else R = mid;
	}
	//printf("L : %lld\n", L);
	if (L == 9) {
		int ans = 0;
		for (int i = 0; i <= 9; i++) {
			printf("? %lld\n", fac[i] + 1);
			fflush(stdout);
			scanf("%s", response);
			if (response[0] == 'Y') {
				ans = i;
				break;
			}
		}
		printf("! %lld\n", fac[ans]);
		fflush(stdout);
	}
	else {
		L = fac[L] - 1; R = (L + 1) * 10 - 1;
		while (L < R - 1) {
			LL mid = (L + R) >> 1;
			printf("? %lld0\n", mid);
			fflush(stdout);
			scanf("%s", response);
			if (response[0] == 'Y') R = mid;
			else L = mid;
		}
		printf("! %lld\n", R);
		fflush(stdout);
	}
	return 0;	
}

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

typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int n = s.size();
    int ans1 = 0;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0 && s[i] == '1') ans1++;
        else if (i%2 != 0 && s[i] == '0') ans1++;
    }
    int ans2 = 0;
    for (int i = 0; i < n; i++) {
        if (i%2 == 0 && s[i] == '0') ans2++;
        else if (i%2 != 0 && s[i] == '1') ans2++;
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <cassert>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

const int M = 1e9 + 7;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

const int N = 16;
ll f[1 << N], s[1 << N];
int a[N][N];

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int n; cin >> n;
	rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
	rep(S, 0, 1 << n)
		rep(i, 0, n)
			if (S & 1 << i)
				rep(j, 0, i)
					if (S & 1 << j)
						s[S] += a[i][j];
	rep(S, 0, 1 << n) {
		f[S] = s[S];
		for (int x = S; x; --x &= S)
			ckmax(f[S], s[x] + f[S & ~x]);
	}
	cout << f[(1 << n) - 1];
}


Measured memory_bytes: 1280
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
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; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
template<typename V> constexpr typename V::value_type sum(const V &v) { return accumulate(all(v), 0); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vs v;
  string s;
  while (cin >> s) transform(all(s), s.begin(), ::tolower), v.pb(s);
  map<string, int> m;
  int freq = 0, len = 0;
  string freqs, lens;
  rep(i, v.size()) {
    if (cmax(freq, ++m[v[i]])) {
      freqs = v[i];
    }
    if (cmax(len, v[i].size())) {
      lens = v[i];
    }
  }
  cout << freqs << ' ' << lens << endl;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using ull = unsigned long long;
using ul = unsigned;
using ll = long long;
#define mod 10e+7+7
#define rep(i,a,b) for (int i =a;i<b;++i)
using namespace std;
void solve();
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int t=1;
	//cin>>t;
	while(t--)
	{
	solve();
	 cout<<"\n";
	}
	
	cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
	return 0;

}
double p[3000];
double dp[3000][3000];
void solve()
{
	int n;
	cin>>n;
	rep(i,0,n)
	cin>>p[i];

	dp[0][0]=1-p[0];
	dp[0][1]=p[0];
	for(int i=1;i<n;i++)
		
	{
		for(int j=0;j<3000;j++)
		{
			//tails
			dp[i][j]+=(1-p[i])*dp[i-1][j];
			//heads
			if(j>0)
			dp[i][j]+=p[i]*dp[i-1][j-1];
		}		

	}
	// n/2 > ka sum
	double an=0;
	for(int i=n/2+1;i<3000;i++)
	{
		an+=dp[n-1][i];
	}
	std::cout << std::fixed;
    std::cout << std::setprecision(9);
	cout<<an;

}

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

using namespace std;

int main() {
    char c;
    
    long long int ca = 0, cab = 0, cabc = 0;
    long long int q3 = 1;
    int z = 1e9 + 7;
    while (cin >> c) {
        if (c == 'A') {
            ca = (ca + q3) % z;
        } else if (c == 'B') {
            cab = (cab + ca) % z;
        } else if (c == 'C') {
            cabc = (cabc + cab) % z;
        } else if (c == '?') {
            cabc = (cabc * 3 + cab) % z;
            cab = (cab * 3 + ca) % z;
            ca = (ca * 3 + q3) % z;
            q3 = q3 * 3 % z;
        }
    }

    cout << cabc << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	s := nextInt()

	a := (s / 1000) % 10
	b := (s / 100) % 10
	c := (s / 10) % 10
	d := s % 10

	if a+b+c+d == 7 {
		fmt.Printf("%d+%d+%d+%d=7", a, b, c, d)
		return
	}
	if a+b+c-d == 7 {
		fmt.Printf("%d+%d+%d-%d=7", a, b, c, d)
		return
	}
	if a+b-c+d == 7 {
		fmt.Printf("%d+%d-%d+%d=7", a, b, c, d)
		return
	}
	if a+b-c-d == 7 {
		fmt.Printf("%d+%d-%d-%d=7", a, b, c, d)
		return
	}
	if a-b+c+d == 7 {
		fmt.Printf("%d-%d+%d+%d=7", a, b, c, d)
		return
	}
	if a-b+c-d == 7 {
		fmt.Printf("%d-%d+%d-%d=7", a, b, c, d)
		return
	}
	if a-b-c+d == 7 {
		fmt.Printf("%d-%d-%d+%d=7", a, b, c, d)
		return
	}
	if a-b-c-d == 7 {
		fmt.Printf("%d-%d-%d-%d=7", a, b, c, d)
		return
	}

}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    cout << fixed << setprecision(10);
    
    ll A, B; cin >> A >> B;
    A -= 1;
    int C, D; cin >> C >> D;
    ll cd_lcm = lcm(C, D);

    ll div_num = ((B/C + B/D) - B/cd_lcm) - ((A/C + A/D) - A/cd_lcm);
    ll ans = (B-A) - div_num;
    cout << ans << endl;
    return 0;
}

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

string s;

int main(){

    char ch;
    while(cin>>s){
        string s2;

        for(int i=0;i<s.size();i++)
            if(s[i]=='B' && s2.size()>0)
             s2.pop_back();
            else if(s[i]!='B')
             s2.push_back(s[i]);

        cout<<s2<<endl;

    }

return 0;
}


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

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    ll n,a,b;
    cin>>n>>a>>b;
    ll acount,rem;
    acount = n/(a+b) * a;
    rem = n%(a+b);
    acount += min(rem,a);
    cout<<acount;

    return 0;
}

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

vector<int> par;
vector<int> siz;
int maxi=1;

int root(int x){
  if(par.at(x)==-1) return x;
  return par.at(x) = root(par.at(x));
}

int size(int x){
  return siz.at(x);
}

void unite(int x, int y){
  x = root(x);
  y = root(y);
  
  if(x==y) return;
  if(size(x) < size(y)) swap(x, y);
  par.at(y) = x;
  siz.at(x) += size(y);
  maxi = max(maxi, size(x));
}

int main() {
  int N, M;
  cin >> N >> M;
  par.assign(N, -1);
  siz.assign(N, 1);
  int a, b;
  rep(i, M){
    cin >> a >> b;
    --a; --b;
    unite(a, b);
  }
  
  cout << maxi << endl;
  
  return 0;
}




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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};

ll mod_div(ll a,ll b){
  ll tmp=MOD-2,c=b,ret=1;
  while(tmp>0){
    if(tmp&1){
      ret*=c;ret%=MOD;
    }
    c*=c;c%=MOD;tmp>>=1;
  }
  return a*ret%MOD;
}
 
#define MAX_K 200100
vector<ll> kaijo(MAX_K);
ll combination(ll n, ll r){
  if(n<r||n<0||r<0)
    return 0;
  if(kaijo[0]!=1){
    kaijo[0]=1;
    for(ll i=1;i<MAX_K;i++)kaijo[i]=(kaijo[i-1]*i)%MOD;
  }
  ll ret=kaijo[n];
  long long tmp = (kaijo[r] * kaijo[n-r]) % MOD;
  return mod_div(ret,tmp);
}

void modadd(ll &a, ll b){
  a+=b;
  a%=MOD;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w,a,b;cin>>h>>w>>a>>b;
  ll ans=0;
  for(ll i=b;i<w;i++){
    ans+=(combination(h-a-1+i,min(h-a-1,i))*combination(a-1+w-i-1,min(a-1,w-i-1)))%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>


#define REP(i, n) for(int i = 0; (i) < (n); ++(i))
#define FOR(i, n) for(int i = 1; (i) <= (n); ++(i))
#define dump(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define int long long
//#define lint long long

const int INF = 1e18;
const int MOD = 1e9 + 7;
// const lint LINF = 1e18;
const double eps = 0.000000001;  //もとの値の10^(-16)まで

using namespace std;

// typedef pair<int, int> P;
// priority_queue< P, vector<P>, greater<P> > q;//ダイクストラの時、greaterで小さい順

int a[82][82];
int b[82][82];
int c[82][82];
int dp[82][82][13000];
signed main() {
  int h, w;
  cin >> h >> w;
  REP(i, h) {
    REP(j, w) {
      cin >> a[i][j];
    }
  }
  REP(i, h) {
    REP(j, w) {
      cin >> b[i][j];
    }
  }
  REP(i, h) {
    REP(j, w) {
      c[i][j] = max(a[i][j] - b[i][j], -a[i][j] + b[i][j]);
    }
  }
  dp[0][0][c[0][0]] = 1;
  REP(i, h) {
    REP(j, w) {
      REP(k, 13000) {
        if(dp[i][j][k]==0) continue;
        dp[i+1][j][k+c[i+1][j]] = 1;
        dp[i+1][j][max(k-c[i+1][j],c[i+1][j]-k)] = 1;
        dp[i][j+1][k+c[i][j+1]] = 1;
        dp[i][j+1][max(k-c[i][j+1],c[i][j+1]-k)] = 1;
      }
    }
  }
  REP(i,13000){
    if(dp[h-1][w-1][i]==1){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 674432
<?php
$templete = array(
    '(%d %s %d %s %d) %s %d',
    '((%d %s %d) %s %d) %s %d',
    '(%d %s (%d %s %d)) %s %d',
    '(%d %s %d) %s %d %s %d',
    '(%d %s %d) %s (%d %s %d)',
    '%d %s (%d %s %d %s %d)',
    '%d %s ((%d %s %d) %s %d)',
    '%d %s (%d %s %d) %s %d',
    '%d %s %d %s (%d %s %d)',
    '%d %s %d %s %d %s %d',
);
$operators = array(
    '+ + +',
    '+ + -',
    '+ + *',
    '+ - +',
    '+ - -',
    '+ - *',
    '+ * +',
    '+ * -',
    '+ * *',
    '- + +',
    '- + -',
    '- + *',
    '- - +',
    '- - -',
    '- - *',
    '- * +',
    '- * -',
    '- * *',
    '* + +',
    '* + -',
    '* + *',
    '* - +',
    '* - -',
    '* - *',
    '* * +',
    '* * -',
    '* * *',
);
while($line = trim(fgets(STDIN))){
    if($line == '0 0 0 0'){
        break;
    }
    $data_ary = explode(" ",$line);
    foreach($templete as $temp){
        $flg = false;
        if(getAnswer($data_ary,$operators,$temp)){
            $flg = true;
            break;
        }
    }
    if(!$flg){
        echo "0\n";
    }
}
function getAnswer($data_ary,$opes,$temp){
    for($a = 0;$a < 4;$a++){
        for($b = 0;$b < 4;$b++){
            for($c = 0;$c < 4;$c++){
                for($d = 0;$d < 4 ;$d++){
                    if($a != $b && $b != $c && $c != $d && $a != $c && $a != $d && $b != $d){
                        foreach($opes as $ope){
                            $op = explode(" ",$ope);
                            $math = sprintf($temp,$data_ary[$d],$op[0],$data_ary[$c],$op[1],$data_ary[$b],$op[2],$data_ary[$a]);
                            eval('$ans = '.$math.';');
                            if($ans == 10){
                                echo "(".$math.")\n";
                                return true;
                            }
                        }
                    }
                }            
            }
        }
    }
    return false;
}


Measured memory_bytes: 9680
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))


ans = sum(b)

for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans +=  c[a[i]-1]
print(ans)





Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>

using namespace std;

bool isKaibun(string s)
{
    string reversed = s;
    reverse(s.begin(), s.end());
    int axis = (int)(ceil(0.5 * s.size()));
    for(int i = 0; i < axis; i++)
    {
        if(s[i] != reversed[i])
        {
            return false;
        }
    }
    return true;
}

int c()
{
    string s;
    cin >> s;
    int l, r;
    l = 0;
    r = s.size() - 1;
    int count = 0;
    while (r - l > 0)
    {
        if(s[l] == s[r])
        {
            l++;
            r--;
        }else if(s[l] == 'x')
        {
            count++;
            l++;
        }else if(s[r] == 'x')
        {
            count++;
            r--;
        }else{
            return -1;
        }
    }
    return count;
}

int main() {
    cout << c() << endl;
    return 0;
}


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

public class Main {

    private static int N;
    private static String A, B;
    private static int rank = 0;
    private static Map<String, Integer> mp = new HashMap<>();

    private static void permutation(String s, int len) {
        if(len == N) {
            mp.put(s, rank++);
        } else {
            for(int i = 1;i <= N;i++) {
                if(!s.contains(Integer.toString(i))) {
                    permutation(s + Integer.toString(i), len+1);
                }
            }
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();scanner.nextLine();
        A = scanner.nextLine().replaceAll(" ", "");
        B = scanner.nextLine().replaceAll(" ", "");

        permutation("", 0);
        System.out.println(Math.abs(mp.get(A) - mp.get(B)));
    }
}


Measured memory_bytes: 49240
def c_bugged():
    N = int(input())
    S = [int(input()) for _ in range(N)]

    total = sum(S)
    if total % 10 != 0:
        return total

    s = sorted(S)
    for i in s:
        if i % 10 != 0:
            return total - i
    return 0

print(c_bugged())

Measured memory_bytes: 3060
// finish date: 2018/07/22
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<double> vd;
typedef vector<vector<double>> vvd;
typedef vector<vector<vector<double>>> vvvd;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, pair<int, int>> plii;
const int bigmod = 1000000007;
const int INF = 1050000000;
const long long INFll = 100000000000000000;


//最大公約数
int gcd(int a, int b) {
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    if (a < b) {
        swap(a, b);
    }
    int r = 1; //0以外であれば何でも
    while (r != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main() {
    int N, K;
    cin >> N >> K;
    vi A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    int G = A[0];
    FOR(i, 1, N) {
        G = gcd(G, A[i]);
    }
    if (K % G != 0 || A[N - 1] < K) {
        cout << "IMPOSSIBLE" << endl;
    } else {
        cout << "POSSIBLE" << endl;
    }

    return 0;
}



Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
#define MAX 100

bool check( string target, string s ){
  for ( int i = 0; i < target.size(); i++ ){
    if ( target[i] == '*' ) continue;
    if ( target[i] != s[i] ) return false;
  }
  return true;
}

main(){
  int n, m;
  string code;
  pair<string, int> R[MAX];
  while( cin >> n >> m && n &&m ){
    for ( int i = 0; i < n; i++ ){
      cin >> R[i].first >> R[i].second;
    }
    int sum = 0;
    for ( int i = 0; i < m; i++ ){
      cin >> code;
      for ( int j = 0; j < n; j++ ){
	if ( check(R[j].first, code) ) sum += R[j].second;
      }
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 0
fun main(args: Array<String>) = abc162c()

fun abc162c() {
    val n = readLine()!!.toLong()

    var answer = 0L

    for (i in 1..n) {
        for (j in 1..n) {
            for (k in 1..n) {
                answer += gcd(i, gcd(j, k))
            }
        }
    }

    println(answer)
}

private tailrec fun gcd(a: Long, b: Long): Long {
    return if (b == 0L) a else gcd(b, a % b)
}


Measured memory_bytes: 34548
#include<bits/stdc++.h>
#define maxn 500010
#define ll long long
using namespace std;
ll n,m;
int main()
{
	scanf("%lld%lld",&n,&m);
	if(n<m) swap(n,m);
	if(m==1&&n==1) cout<<1;
	else if(m==1) cout<<n-2;
	else cout<<n*m-2*(n+m)+4;
	return 0;
 } 

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 1<<30
#define MOD 1000000007
#define mod 10007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //------------------------------
    int n;cin>>n;
    while(n){
        V<int>s(n);
        for(int i=0;i<n;i++)cin>>s[i];
        double a=0;
        int sum=0;
        for(int i=0;i<n;i++)sum+=s[i];
        double ave=(double)sum/(double)n;
        for(int i=0;i<n;i++){
            a+=(double)((double)s[i]-ave)*((double)s[i]-ave);
        }
        a/=(double)n;
        printf("%.10lf\n",pow(a,0.5));

        cin>>n;
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------


































Measured memory_bytes: 3384
#include<cstdio>
#include<algorithm>
using namespace std;
int t[100005],x[100005],y[100005];
int main() {
	int n;
	scanf("%d",&n);
	for (int i=1; i<=n; i++) 
		scanf("%d%d%d",&t[i],&x[i],&y[i]);
	for(int i=1; i<=n; i++) {
		if (abs(x[i]-x[i-1])+abs(y[i]-y[i-1])<=t[i]-t[i-1]) 
		{
			if ((abs(x[i]-x[i-1])+abs(y[i]-y[i-1]))%2!=((t[i]-t[i-1])%2)) 
			{
				printf("No\n");
				return 0;
			}
		}
		else
        {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}



Measured memory_bytes: 1408
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
from collections import Counter

def factorization(n):
    p=2
    fcr=[]
    while p*p<=n:
        while n%p==0:
            fcr.append(p)
            n//=p
        p+=1
    if n>1:
        fcr.append(n)
    return fcr

n=int(input())

mod=10**9+7

l=[]
for i in range(1,n+1):
  l+=factorization(i)

c=Counter(l)
ans=1
for i in c:
  ans*=(c[i]+1)
  ans%=mod

print(ans)

Measured memory_bytes: 9480
#include <stdio.h>
#include <stdlib.h>

#define INFTY 1000000009
#define N 500005
int count;

void merge(int A[],int left,int mid, int right){
  int i,j,k,n1,n2,*L,*R;
  n1 = mid - left;
  n2 = right - mid;
  L = (int *)malloc((n1+1) * sizeof(int));
  R = (int *)malloc((n2+1) * sizeof(int));
  for(i=0; i<n1; i++) L[i] = A[left + i];
  for(i=0; i<n2; i++) R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k=left; k<right; k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
  } 

  free(L);
  free(R);
}


void mergeSort(int A[],int left,int right){
  int mid;
  if(left+1 < right){
    mid = (left + right) / 2;
    mergeSort(A,left,mid);
    mergeSort(A,mid,right);
    merge(A,left,mid,right);
  }
}


int main(){
  int i,n,A[N];
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);

  mergeSort(A,0,n);

  for(i=0; i<n; i++) {
    printf("%d",A[i]);
    if(i==n-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",count);

  return 0;

}

Measured memory_bytes: 4480
import sys, math,os
from io import BytesIO, IOBase
#from bisect import bisect_left as bl, bisect_right as br, insort
#from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write(' '.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


def main():

    n=int(data())
    A=mdata()
    A.sort()
    ans=1
    l=10**18
    for i in A:
        ans*=i
        if ans>l:
            out(-1)
            exit()
    out(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 22668
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    string s;
    cin >> s;
    int cnt = 1;
    vector< LL > v;
    for( int i = 1; i < s.size(); ++i ) {
        if( s[i] != s[i - 1] ) {
            if( s[i - 1] == '<' ) v.pb( cnt );
            else v.pb( -cnt );
            cnt = 0;

        }
        ++cnt;

    }
    if( s[s.size() - 1] == '<' ) v.pb( cnt );
    else v.pb( -cnt );

    LL res = 0;
    if( v[0] < 0 ) res += (v[0] * (v[0] - 1) / 2);

    for( int i = 1; i < v.size(); ++i ) {
        if( v[i - 1] > 0 ) {
            res += (v[i - 1] * (v[i - 1] - 1) / 2) + (v[i] * (v[i] + 1) / 2);
            res += max( v[i - 1], -v[i] );

        }
    }

    if( v[v.size() - 1] > 0 ) res += v[v.size() - 1] * (v[v.size() - 1] + 1) / 2;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3352
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int N, K;
	cin >> N >> K;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) cin >> vec.at(i);
	sort(vec.begin(), vec.end());
	int ans=0;
	for (int i = 0; i < K; i++) {
		ans += vec.at(i);
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

constexpr ll MOD = 1000000007;

int h, w;
char grid[1005][1005];
ll dp[1005][1005];

ll solve(int i, int j) {
  if (i < 0 || j < 0) {
    return 0;
  }
  if (i == 0 && j == 0) {
    return 1;
  }
  if (grid[i][j] == '#') {
    return 0;
  }
  ll& res = dp[i][j];
  if (res != -1LL) {
    return res;
  }
  return res = (solve(i - 1, j) + solve(i, j - 1)) % MOD;
}

int main() {
  fill(&dp[0][0], &dp[0][0] + 1005 * 1005, -1LL);
  cin >> h >> w;
  for (int i = 0; i < h; i++) {
    cin >> grid[i];
  }
  cout << solve(h - 1, w - 1) << '\n';
  return 0;
}


Measured memory_bytes: 9216
#include"bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> 
using namespace __gnu_pbds; 
using namespace std;

#define double long double
#define int long long
#define pb push_back 
#define eb emplace_back
#define Z(c) (int)(c).size()
#define L(c) c[Z(c)-1]
#define F first
#define S second
#define nl "\n"
#define mii map<int,int>
#define sp fixed<<setprecision 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);++(i))
#define FO fflush(stdout) 
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define tr(it,ct) for(auto &(it) : (ct))
#define pi acos(-1)
#define prt(ct) for(auto &(it) : (ct)) cerr<<it<<" "; cerr<<nl
#define prtp(ct) for(auto &(it) : (ct)) cerr<<it.F<<" "<<it.S<<nl; cerr<<nl

typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef pair<pii,pii> ppp;
typedef vector< pii > vp;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, 
             tree_order_statistics_node_update> baap;

template<typename T> 
void swap(T &a,T &b)
{ auto tm=a; a=b; b=tm; }

template<typename T> 
void mina(T& a, T b) { 
    a = min(a, b); 
}
template<typename T>
void maxa(T& a, T b) { 
    a = max(a, b); 
}

  const int mod=1000000009;
  const int mod2=998244353;
  const int INF=1e18;
  const int N=2e5+25;  
  const int M=1e5+1;           


 void doit()
 { 
   int a,b; cin>>a>>b; cout<<a*b;
 }

signed main()
{ 
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

   int tc=1;                         
   // cin>>tc;

  rep(i,1,tc+1)
  { // cout<<"Case #"<<i<<": ";
  
   doit();
   if(i<tc)
   cout<<nl;
  }
  
 return 0; 
}


Measured memory_bytes: 3660
#include <bits/stdc++.h> 
using namespace std; 
  
int countDivisibles(int A, int B, int M) 
{ 
    int counter = 0; 
    for (int i = A; i <= B; i++) 
        if (i % M == 0) 
            counter++; 
  
    return counter; 
} 
  
int main() 
{ 
    int A,B,M;
    cin >> A >> B >> M;
  
    cout << countDivisibles(A, B, M) << endl; 
  
    return 0; 
} 

Measured memory_bytes: 3588
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

int N,M;
int G[100][100];
void warshall() {
	REP(i, N) {
		REP(j, N) {
			REP(k, N) {
				G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
			}
		}
	}
}
signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	REP(i, 100) {
		REP(j, 100)G[i][j] = INF;
	}
	cin >> N >> M;
	VI a(M);
	VI b(M);
	VI c(M);
	REP(i, M) {
		cin >> a[i] >> b[i] >> c[i];
		a[i]--;
		b[i]--;
		//if (b[i] > a[i])swap(a[i], b[i]);
		G[a[i]][b[i]] = c[i];
		G[b[i]][a[i]] = c[i];
	}
	warshall();
	
	int ans = 0;
	REP(k, M) {
		bool F = true;
		REP(i, N) {
			REP(j, N) {
				//if (i >= a[k] || b[k] >= j || i >= j)continue;
				if (G[i][a[k]] + c[k] + G[b[k]][j] == G[i][j] )//&& i < a[k] && b[k] < j && i != j)
					F = false;
				if (c[k] == G[i][j] && i==a[k] && j==b[k])F = false;
				
			}
		}
		if (F) {
			ans++;
			//cout << a[k] << " " << b[k] << endl;
		}
	}

	cout << ans << endl;
	return 0;
}



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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, K;
  scanf("%d %d", &N, &K);
  vector<int> sticks(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &sticks[i]);
  }
  sort(sticks.begin(), sticks.end(), greater<int>());
  int ans = accumulate(sticks.begin(), sticks.begin() + K, 0);
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       int[] a = new int[3];
       for (int i = 0; i < 3; i++) { a[i] = sc.nextInt(); }
       System.out.println(a[2] + " " + a[0] + " " + a[1]);
       sc.close();
    }
}

Measured memory_bytes: 25172