akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>

using namespace std;

typedef long long ll;

#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())

int main() {

	int ans = 0;
	vector<int> a(5);
	vector<pair<int, int>> b(5);
	FOR(i, 5) {
		cin >> a[i];
		if (a[i] % 10 == 0)b[i].first = 0;
		else b[i].first = 10 - a[i] % 10;
		b[i].second = i;
	}
	SORT(b);
	FOR(i, 4) {
		if (b[i].first == 0)ans += a[b[i].second];
		else ans += (a[b[i].second] / 10 + 1) * 10;
	}
	ans += a[b[4].second];
	cout << ans << endl;

	return 0;
}


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

using namespace std;

unsigned long factorial(unsigned long n)
{
	unsigned long result = 1;
	for (unsigned long i = n; i > 0; --i) {
		result *= i;
	}
	return result;
}

int main()
{
	unsigned long value = 0;
	cin >> value;
	cout << factorial(value) << endl;

	return 0;
}

Measured memory_bytes: 1156
N = int(input())
lis_X = list(map(int, input().split()))

lis_X_sorted = sorted(lis_X)

def calc_dif_sq(a,b):
    return (a-b)**2

if N == 1:
    ans = 0
elif min(lis_X_sorted)==max(lis_X_sorted):
    ans = 0
else :
    res = []
    for p in range(lis_X_sorted[0],lis_X_sorted[-1]):
        tmp = sum(list(map(lambda x:calc_dif_sq(x, p), lis_X_sorted)))
        res.append(tmp)
    ans = min(res)
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>



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

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

#define REP(i, n) for(ll i = 0; i < n; i++)














int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 1; i <= n; i++){
        ll cnt = 0, t = i;
        while(t > 0){
            cnt++;
            t /= 10;
        }
        if(cnt % 2 == 1) ans++;
    }
    cout << ans << endl;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	int num=0;
	for(int i=A; i<=B; ++i){
	    if((i-i%10000)/10000==i%10 && (i%10000-i%1000)/100==i%100-i%10) ++num;
	}
	cout << num << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list()

A = [n for n in map(int, raw_input().split())]
    
st = 1
num_brk = 0

for a in A:
    if a == st:
        st += 1
    else:
        num_brk += 1

if num_brk == N and st == 1:
    print '-1'
else:
    print '{}'.format(num_brk)


Measured memory_bytes: 20008
n = gets.to_i
h = gets.split.map(&:to_i)
ans = 0
f = true
while f
  f = false
  m = true
  0.upto(n - 1) do |i|
    if h[i] > 0
      h[i] -= 1
      ans += 1 if m
      f = true
      m = false
    else
      m = true
    end
  end
end
puts ans

Measured memory_bytes: 1788
//Tanuj Khattar
#include<bits/stdc++.h>

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
const int MOD = int(1e9)+7;
const int N = int(1e6)+10;
int add(int a,int b){
  a = (a + b)%MOD;
  if(a > MOD)a -= MOD;
  return a;
}
int sub(int a,int b){
  a = (a - b);
  if(a < 0)a += MOD;
  return a;
}
int mul(int a,int b){
  a = (a*1ll*b)%MOD;
  return a;
}
int fact[N],inv[N],f[N];
int nCr(int n,int r){
  if(n < r)return 0;
  return mul(fact[n],mul(inv[r],inv[n-r]));
}
int power(int a,int p){
  int ret=1;
  while(p){
    if(p&1)ret = mul(ret,a);
    a = mul(a,a);
    p/=2;
  }
  return ret;
}
int main()
{
  fact[0]=inv[0]=1;
  for(int i=1;i<N;i++)
    fact[i] = mul(fact[i-1],i);
  for(int i=1;i<N;i++)
    inv[i] = power(fact[i],MOD-2);
  int n,m,k;
  si(n);si(m);si(k);
  int ans = power(3,m+k); f[0] = 1;
  for(int s = 1;s <= m+k;s++){
    f[s] = add(f[s-1],f[s-1]);
    if(s > m)
      f[s] = sub(f[s],nCr(s-1,m));
    if(s >= k)
      f[s] = sub(f[s],nCr(s-1,k));
    ans = add(ans,mul(mul(f[s],nCr(n+s-1,s)),power(3,m+k-s)));
  }
  dout(ans);
	return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPLL(i, n) for (ll i = 0; i < (ll)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string S; cin >> S;
  int ans = 0;
  REP(i, 4){
    if(S[i] == '+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <stdexcept>
#include <cassert>
#include <cmath>
#include <vector>
#include <string>
using namespace std;


int main() {
  string N;
  cin >> N;

  int sum = 0;
  for (char c : N) {
    sum += (int) (c - '0');
  }

  if (sum % 9 == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3684
#include<iostream>
#include<cmath>
#include<stdlib.h>
using namespace std;

int D;
int cl[26];
int sl[400][26];

int scores(int tl[]) {
    int s = 0;
    int last[26];
    for(int i=0;i<26;i++){
        last[i] = 0;
    }
    for(int d=0;d<D;d++){
        int t = tl[d] - 1;
        last[t] = d+1;

        int ss = sl[d][t];
        for(int i=0;i<26;i++){
            int c = cl[i];
            ss -= c*(d+1-last[i]);
        }
        s += ss;
    }
    return s;
}

int main(){
    cin>>D;
    for(int i=0;i<26;i++){
        cin>>cl[i];
    }
    for(int i=0;i<D;i++){
        for(int j=0;j<26;j++){
            cin>>sl[i][j];
        }
    }
    double beta = 1.0;

    int tl[400];
    for(int i=0;i<400;i++){
        tl[i] = rand()%26+1;
    }
    int s = scores(tl);
    for(int i=0;i<10000;i++){
        int d = rand()%D+1;
        int x = tl[d-1];

        int e[26];
        for(int j=0;j<26;j++){
            int q = j+1;
            int x = tl[d-1];
            tl[d-1] = q;
            e[j] = scores(tl);
            tl[d-1] = x;
        }

        double esum = 0.0;
        double es[26];
        for(int j=0;j<26;j++) {
            es[j] = -log(e[j])/beta;
            esum += exp(es[j]);
        }
        double p = rand()/RAND_MAX;
        double ps = 0.0;
        for(int j=0;j<26;j++){
            ps += es[j]/esum;
            if(ps>p){
                tl[d-1] = j+1;
                break;
            }
        }

    }

    for(int i=0;i<D;i++){
        cout<<tl[i]<<endl;
    }
    return 0;
}

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

int main () {
  int N;
  cin >> N;
  vector<vector<int>> data(N, vector<int>(26,0));
 
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    for (int j = 0; j < S.size(); j++) {
      int M = S.at(j) - '0';
      data.at(i).at(M-49)++;
    }
  }
  
  vector<int>A(26);
  for (int i = 0; i < 26; i++) {
    int MIN = 50;
    for (int j = 0; j < N; j++) {
      if (MIN > data.at(j).at(i)){
        MIN = data.at(j).at(i);
      }
      if (j == N-1){
        A.at(i) = MIN;
      }
    }
    for (int k = 0; k < A.at(i); k++) {
      printf("%c", i + 'a');
    }
  }
  cout << endl;
}
  

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using ld=long double;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

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


int main(){
    int N; cin >> N;
    vi H(N);
    for(auto &x : H) cin >> x;
    int mx=0, ans=0;
    for(int i=0; i<N; i++){
        if(H[i] >= mx) ans++;
        chmax(mx, H[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

bool DEBUG = false;

int main(){
    int n, k;
    cin >>n >>k;
    if(k > (n-2)*(n-1)/2){
        cout <<-1 <<endl;
    }
    else{
        cout <<n-1 + (n-2)*(n-1)/2 - k <<endl;
        for(int i=2; i<=n; i++){
            cout <<1 <<" " <<i <<endl;
        }
        
        bool done = false;
        int currK = (n-2)*(n-1)/2;
        for(int i=n; !done && i>=3; i--){
            for(int j=i-1; !done && j>=2; j--){
                if(currK <= k){
                    done = true;
                }
                else{
                    cout <<i <<" " <<j <<endl;
                    currK--;
                }
            }
        }
    }
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    string r = s;
    reverse(r.begin(), r.end());
    string sub1 = s.substr(0, (s.size()-1)/2);
    string rub1 = sub1;
    reverse(rub1.begin(), rub1.end());
    string sub2 = s.substr((s.size() + 3) / 2 - 1);
    string rub2 = sub2;
    reverse(rub2.begin(), rub2.end());
    if(s == r) {
        if(sub1 == rub1) {
            if(sub2 == rub2) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

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

#define mod 1000000007

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

using namespace std;
typedef long long ll; 
 
int main(void){
	
	ll N, a[5];
	
	cin >> N;
	
	rep(i, 5)
		cin >> a[i];
	
	sort(a, a + 5);
	
	ll ans = ceil((N - 1) / a[0]) + 5; 
	
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let mut s:Vec<char> = read::<String>().chars().collect();

    if s.len() == 3 {
        let tmp = s[0];
        s[0] = s[2];
        s[2] = tmp;
        println!("{}{}{}", s[0],s[1],s[2]);
    } else {
        println!("{}{}",s[0],s[1]);
    }

}


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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

bool hasLoop(vector<vector<int>> &G) {
    int N = G.size();
    vector<int> cnt(N);
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < G[i].size(); j++) {
            cnt[G[i][j]]++;
        }
    }
    vector<int> S;
    for (int i = 0; i < N; i++) {
        if (!cnt[i]) S.push_back(i);
    }
    if (!S.size()) return true;

    vector<int> L;
    while(!S.empty()) {
        int n = S.back(); S.pop_back();
        L.push_back(n);
        for(int i = 0; i < G[n].size(); i++) {
            cnt[G[n][i]]--;
            if (!cnt[G[n][i]]) {
                S.push_back(G[n][i]);
            }
        }
    }
    return L.size() != N;
}

void solve() {
    int N, M;
    cin >> N >> M;
    string s;
    cin >> s;

    vector<vector<int>> G(4 * N);
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        if (s[a] == 'A' && s[b] == 'A') {
            G[a * 4].push_back(b * 4 + 1);
            G[b * 4].push_back(a * 4 + 1);
        } else if (s[a] == 'B' && s[b] == 'B') {
            G[a * 4 + 2].push_back(b * 4 + 3);
            G[b * 4 + 2].push_back(a * 4 + 3);
        } else if (s[a] == 'A' && s[b] == 'B') {
            G[a * 4 + 1].push_back(b * 4 + 2);
            G[b * 4 + 3].push_back(a * 4);
        } else {
            G[a * 4 + 3].push_back(b * 4);
            G[b * 4 + 1].push_back(a * 4 + 2);
        }
    }
    if (hasLoop(G)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 36160
import math
from math import gcd,pi,sqrt
INF = float("inf")
MOD = 10**9 + 7

import sys
sys.setrecursionlimit(10**6)
import itertools
import bisect
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    n = i_input()
    a = i_list()

    cnt = 1
    for i in a:
        if i == cnt:
            cnt += 1
    if cnt == 1:
        print(-1)
    else:
        print(n - cnt + 1)


if __name__=="__main__":
    main()


Measured memory_bytes: 103568
#include<stdio.h>

int ma[8][8];

int main(){
	int n,data=0,i,j,x,y,a,b;
	
	scanf("%d",&n);
	
	for(;n>0;--n){
		++data;
		for(i=0;i<8;++i){
			for(j=0;j<8;j++){
				scanf("%1d",&ma[i][j]);
			}
		}
		scanf("%d%d",&x,&y);
		--x;
		--y;
		ma[y][x]=0;
		for(i=x-3;i<=x+3;i++){
			if(0<=i && i<8 ){
				if(ma[y][i]==1){
					ma[y][i]=2;
				}else{
					ma[y][i]=0;
				}
			}
		}
		
		for(i=y-3;i<=y+3;++i){
			if(0<=i && i<8){
				if(ma[i][x]==1){
					ma[i][x]=2;
				}else{
					ma[i][x]=0;
				}
			}
		}
		
		int flag=1;
		while(flag){
			flag=0;
			
			for(a=0;a<8;a++){
				for(b=0;b<8;b++){
					if(ma[a][b]==2){
						y=a;
						x=b;
						
						ma[y][x]=0;
						for(i=x-3;i<=x+3;i++){
							if(0<=i && i<8 ){
								if(ma[y][i]>0){
									ma[y][i]=2;
									flag=1;
								}else{
									ma[y][i]=0;
								}
							}
						}
						
						for(i=y-3;i<=y+3;++i){
							if(0<=i && i<8){
								if(ma[i][x]>0){
									ma[i][x]=2;
									flag=1;
								}else{
									ma[i][x]=0;
								}
							}
						}
					}
				}
			}
		}
		
		printf("Data %d:\n",data);
		for(i=0;i<8;i++){
			for(j=0;j<8;j++){
				printf("%d",ma[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        int inta = Integer.parseInt(a);
        int intb = Integer.parseInt(b);
        
        if(inta <= intb) {
            for(int i = 0; i < intb; i++) {
                System.out.print(a);
            }
            System.out.println("");
        }else {
            for(int i = 0; i < inta; i++) {
                System.out.print(b);
            }
            System.out.println("");
        }
        
        }
}

Measured memory_bytes: 21716
// template version 1.11
using namespace std;
#include <iostream>
#include <bits/stdc++.h>

// varibable settings {{{
#define infile "../test/sample-1.in"
#define int long long
const int INF=1e18;
const int MOD=1e9+7;
// }}}

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;
#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#endif
//}}}

const int MAX = 510000;/*{{{*/

ll fac[MAX], finv[MAX], inv[MAX];

// 前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
ll C(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}/*}}}*/

int solve(){
  COMinit();
  int n,m,k;cin>>n>>m>>k;
  int L = n*m;
  if (m>n) swap(n,m);

  int res=0;
  rep(d, 1, 2e5+1){
    if (m>d) res+=d*(m-d)%MOD*(n*n)%MOD*C(L-2, k-2)%MOD;
    if (n>d) res+=d*(n-d)%MOD*(m*m)%MOD*C(L-2, k-2)%MOD;
    res %= MOD;
  }
  cout << res << endl;
  return 0;
}

signed main() { //{{{
#ifdef INPUT_FROM_FILE
  std::ifstream in(infile);
  std::cin.rdbuf(in.rdbuf());
#endif
  solve();
  return 0;
} //}}}


Measured memory_bytes: 12160
m, n = input().split()
str1 = m
str2 = n
if str1 * int(n) < str2 * int(m):
	print(str1 * int(n))
elif str1 * int(n) == str2 * int(m):
	print(str1 * int(n))  
else:
	print(str2 * int(m))


Measured memory_bytes: 9128
class SegmentTree: #1-indexed
    def __init__(self,list,f=lambda x,y:x+y,inf=0):
        self.height=(len(list)-1).bit_length()+1 #木の高さ
        self.id=inf #単位元
        self.tree=[self.id]*(2**self.height) #木を単位元で初期化
        self.f=f
        for i in range(len(list)):
            self.tree[2**(self.height-1)+i]=list[i]
        for i in range(2**(self.height-1)-1,0,-1):
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
        
    def update(self,i,x): #i番目の要素をxに変更
        i+=2**(self.height-1)
        self.tree[i]+=x
        while i>1:
            i//=2
            self.tree[i]=self.f(self.tree[2*i],self.tree[2*i+1])
    
    def query(self,l,r):
        l+=2**(self.height-1)
        r+=2**(self.height-1)
        lf,rf=self.id,self.id
        while l<r:
            if l&1:
                lf=self.f(lf,self.tree[l])
                l+=1
            if r&1:
                r-=1
                rf=self.f(self.tree[r],rf)
            l//=2
            r//=2
        return self.f(lf,rf)

n,q=map(int,input().split())
x=list(map(int,input().split()))
S=SegmentTree(x)
for i in range(q):
    a,b,c=map(int,input().split())
    if a==0:
        S.update(b,c)
    else:
        print(S.query(b,c))

Measured memory_bytes: 137060
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t[] = new int[10];
        
        for(int i=0; i<10; i++){
            t[i] = scanner.nextInt();
        }
        
        for (int i = 0; i < 9; i++) {
            for (int j = 0; j < 9 - i; j++) {
                if (t[j] < t[j + 1]) {
                    int temp = t[j];
                    t[j] = t[j + 1];
                    t[j + 1] = temp;
                }
            }
        }

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



Measured memory_bytes: 26036
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int main()
{
    while (1) {
        int h, w;
        cin >> h >> w;

        if (h == 0 && w == 0) {
            break;
        }

        for (int j = 0; j < w; j++) {
            cout << "#";
        }
        cout << endl;

        for (int i = 1; i < h - 1; i++) {
            cout << "#";
            for (int j = 1; j < w - 1; j++) {
                cout << ".";
            }
            cout << "#" << endl;
        }

        for (int j = 0; j < w; j++) {
            cout << "#";
        }
        cout << endl << endl;
    }

    return 0;
}

Measured memory_bytes: 1152
#include <iostream> 
using namespace std;
int a,b,c;
int main(){
	cin>>a>>b;
	if(a+b>a-b){
		c=a+b;
	}
	else {
		c=a-b;
	}
	if(c>a*b){
		cout<<c;
	}
	else cout<<a*b;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}

int s[100] = {};
int main() {
	string s;
	cin >> s;
	s[3] = '8';
	cout << s << endl;
}



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

int main() {
    int n;
    cin >> n;
    int s[n];
    int i;
    for(i = 0; i < n; i++) {
        cin >> s[i];
    }

    int cnt = 0;
    if (n < 3) {
        cout << 0 << endl;
    }
    else {
        int j, k;
        for(i = 0; i < n; i++) {
            for(j = 0; j < n; j++) {
                for(k = 0; k < n; k++) {
                    if (i == j || j == k || i == k) {
                        continue;
                    }
                    else if (s[i] == s[j] || s[j] == s[k] || s[i] == s[k]) {
                        continue;
                    }
                    else {
                        if (s[i] + s[j] > s[k] && s[i] + s[k] > s[j] && s[j] + s[k] > s[i]) {
                            cnt++;
                        }
                    }
                }
            }
        }
        cout << cnt/6 << endl;
    }
}


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

int main() {
    long long a, v, b, w, t;
    scanf("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);
    // if(a > b) {
        // printf("YES\n");

    // }
    // else {
        long long dis = abs(b - a);
        long long d = v * t - w * t;
        if(d - dis >= 0) {
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    // }
    return 0;
}

Measured memory_bytes: 3804
import java.io.IOException;

public class Main {

	public static void main(String[] args) {
		while (true) {
			int x = nextInt();
			if (x == 0) {
				break;
			}
			int y = nextInt();
			int s = nextInt();

			int max = 0;

			for (int i = 1; i <= 100; i++) {
				// iを片方の商品の税抜き価格として考える
				int a = i * (100 + x) / 100;// x税込価格
				int j = (s - a) * 100 / (100 + x) - 1;

				if (j <= 0) {
					break;
				}

				for (int j2 = j; j2 <= j + 3; j2++) {
					int b = j2 * (100 + x) / 100;
					if (a + b == s) {
						int ay = i * (100 + y) / 100;
						int by = j2 * (100 + y) / 100;
						max = Math.max(ay + by, max);
					}
				}

			}

			System.out.println(max);
		}

	}

	static int nextInt() {
		int c;
		try {
			c = System.in.read();
			while (c != '-' && (c < '0' || c > '9'))
				c = System.in.read();
			if (c == '-')
				return -nextInt();
			int res = 0;
			while (c >= '0' && c <= '9') {
				res = res * 10 + c - '0';
				c = System.in.read();
			}
			return res;
		} catch (IOException e) {
			e.printStackTrace();
		}
		return -1;
	}

}

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

int main(){
  int a, b, c, ans = 0;
  cin >> a >> b >> c;
  if ( (a | b | c) & 1 ) {
    cout << 0 << endl;
    return 0;
  }
  if ( a == b && b == c) {
    cout << -1 << endl;
    return 0;
  }
  while(!((a|b|c)&1)){
    int ta, tb, tc;
    ta = (a + b) / 2;
    tb = (b + c) / 2;
    tc = (a + c) / 2;
    a = ta;
    b = tb;
    c = tc;
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for(int i = 1, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
using namespace std;
#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)

// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int N;
  cin >> N;
  // p[0]: mod 4 == 0
  // p[1]: mod 4 == 2
  // p[2]: mod 4 == 1,3
  vector<int> p = vector<int>(3);
  REP(i, N) {
    int a;
    cin >> a;
    if(a % 4 == 0) {
      p[0]++;
    } else if(a % 4 == 2) {
      p[1]++;
    } else {
      p[2]++;
    }
  }

  if(p[0] + 1 < p[2]) {
    cout << "No" << endl;
    return 0;
  } else if(p[0] + 1 == p[2]) {
    if(p[1] >= 1) {
      cout << "No" << endl;
      return 0;
    } else {
      cout << "Yes" << endl;
      return 0;
    }
  } else {
    cout << "Yes" << endl;
    return 0;
  }
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n,a,b int
  	fmt.Scan(&n,&a,&b)
  	
  	ans := (n / (a + b)) * a

	if n % (a+b) != 0 {
      if n % (a+b) <= a {
          ans += n % (a+b)
      } else {
          ans += a
      }
    }
    fmt.Println(ans)
}

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

using namespace std;

int main()
{
int s,n,i,j,k,counter=0;
scanf("%d %d",&s,&n);
for(i=0;i<=s;++i){
    for(j=0;j<=s;++j){
            if((n-(i+j))>=0&&(n-(i+j))<=s){
                counter++;
                }
    }
}
printf("%d",counter);

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int x,n;cin >> x >> n;
    vector<int> p(n);
    REP(i,n) cin >> p[i];

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

    vector<int> res;
    res.push_back(0);

    for(int i=1; i<=100; i++){
        bool can = false;
        for(auto a: p){
            if(a==i) can = true;
        }
        if(!can) res.push_back(i);
    }

    res.push_back(101);

    int nun;
    int ans = 1000;
    for(auto a: res){
        if(abs(x-a) < ans){
            ans = abs(a-x);
            nun = a;
        }
    }

    cout << nun << endl;
}

Measured memory_bytes: 3696
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int a, b, c;
	scanf("%d/%d/%d", &a, &b, &c);
	if (a * 10000 + b * 100 + c <= 20190430) puts("Heisei");
	else puts("TBD");
	return 0;
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
  //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

  ll n,a,b;
  cin>>n>>a>>b;
  ll runs = n/(a+b);
  ll ans = runs*a + min(n-runs*(a+b),a);
  cout<<ans<<endl;
  
  

  return 0;
}
// don't forget to read in the input :^)


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();

        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < n; i++) {
            sb.append(i == k - 1 ? Character.toLowerCase(s.charAt(i)) : s.charAt(i));
        }

        System.out.println(sb.toString());
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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


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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m,x;
    cin >> n >> m >> x;
    int c[n];
    int a[n][m];
    for(int i = 0; i < n; i++) {
        cin >> c[i];
        for(int j = 0; j < m; j++) {
            cin >> a[i][j];
        }
    }

    bool can=false;
    int rcost=INT32_MAX;
    for(int bit = 0; bit < (1<<n); bit++) {
        int skill[m]={};
        int cost=0;
        for(int i = 0; i < n; i++) {
            if(bit & (1<<i)){
                cost+=c[i];
                for(int j = 0; j < m; j++) {
                    skill[j]+=a[i][j];
                }
            }
        }
        bool jud=true;
        for(int j = 0; j < m; j++) {
            if(x>skill[j]) jud=false;
        }
        if(jud){
            if(can==false) can=true;
            rcost=min(rcost,cost);
        }
    }
    if(can) cout << rcost << "\n";
    else    cout << "-1" << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <math.h>

int main(){
	int h,w;
	while(1){
		scanf("%d %d",&h,&w);
		if(h==0 && w==0) break;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(i==0||i==h-1||j==0||j==w-1) printf("#");
				else printf(".");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2596
#include<stdio.h>

int main(void)
{
	int n,i,number[100];
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&number[i]);
	}
	for(i=1;i<=n;i++)
	{
		printf("%d",number[n-i]);
		if(i!=n)
		{
			printf(" ");
		}
	}
	printf("\n");
	return 0;
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 n;
    cin >> n;
    i64 sum = 0;
    for (i64 i = 0; i < n; i++) {
        i64 a;
        cin >> a;
        sum ^= a;
    }

    cout << (sum == 0 ? "Yes" : "No") << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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


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

    if (n <= (2*d + 1)) {
        cout << "1" << endl;
    }

    if (n > (2*d + 1)){
        if (n % (2*d + 1) == 0){
            cout << n / (2*d + 1) << endl;
        }
        if (n % (2*d + 1) != 0){
            cout << (n / (2*d + 1)) + 1 << endl;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N, ans = 0;
    cin >> N;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        ans += (a - 1);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pii(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define iso ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int gcd(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
  
int main()
{    iso;
      int n;cin>>n;
      ll ans=0;
      f(i,1,n+1){
      	f(j,1,n+1){
      		f(k,1,n+1){
      		 ans+=gcd(i,gcd(j,k));	
			  }
		  }
	  }
	  cout<<ans;
}


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

using namespace std;

typedef long long ll;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  string lf, rg;
  int q;
  cin >> q;
  int rev = 0;
  while (q--) {
    int t;
    cin >> t;
    if (t == 1) {
      rev ^= 1;
    } else {
      int f;
      cin >> f;
      char c;
      cin >> c;
      f--;
      f ^= rev;
      if (f == 0) {
        lf += c;
      } else {
        rg += c;
      }
    }
  }
  reverse(lf.begin(), lf.end());
  s = lf + s;
  s += rg;
  if (rev) reverse(s.begin(), s.end());
  cout << s << endl;
  return 0;
}

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

long long max(long long a, long long b)
{
	return a > b ? a : b;
}
long long result(long long w[], long long v[], long long n, long long k)
{
	long long dp[n+1][k+1];
	for (long long i = 0; i < n+1; ++i)
	{
		for (long long j = 0; j < k+1; ++j)
		{
			if(i == 0 || j==0)
				dp[i][j] = 0;
			else if(j >= w[i-1])
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	return dp[n][k];
}
int main()
{
	long long n,k;
	cin >> n >> k;
	long long w[n], v[n];
	for (long long i = 0; i < n; ++i)
	{
		cin >> w[i] >> v[i];
	}
	long long res = result(w, v, n, k);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 79104
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
constexpr int INF = 1e18;

int dp[101][101];

signed main(){
	int H,W;
	cin >> H >> W;
	vector<string>s(H);
	REP(i,H)cin >> s[i];
	REP(i,H)REP(j,W)REP(k,2)if(i || j)dp[i][j] = INF;
	REP(i,H){
		REP(j,W){
			if(i + 1 != H)CHMIN(dp[i + 1][j],dp[i][j] + (s[i][j] == '.' && s[i + 1][j] == '#'));
			if(j + 1 != W)CHMIN(dp[i][j + 1],dp[i][j] + (s[i][j] == '.' && s[i][j + 1] == '#'));
		}
	}
	cout << dp[H - 1][W - 1] + (s[0][0] == '#') << endl;
}

Measured memory_bytes: 384
n, m, l = map(int, input().split())
A, B = [], []
for _ in range(n):
    A.append(list(map(int, input().split())))
for _ in range(m):
    B.append(list(map(int, input().split())))
 
C = []
B_T = list(zip(*B))
for a_row in A:
    C.append([sum(a * b for a, b, in zip(a_row, b_column)) for b_column in B_T])
for row in C:
    print(' '.join(map(str, row)))

Measured memory_bytes: 9052
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using ll = unsigned long long;

using mymap = std::map<std::pair<char, int>, std::vector<std::string>>;
mymap memo;

std::vector<std::string> f(char c, char max_c, int depth)
{
	if (depth == 1)
	{
		std::string s;
		s.push_back(c);
		return std::vector<std::string>{s};
	}
	//else
	//{
	//	auto it = memo.find(std::make_pair(c, depth));
	//	if (it != memo.end())
	//	{
	//		return it->second;
	//	}
	//}

	std::vector<std::string> v;
	max_c = std::max<int>(max_c, c + 1);
	for (char i = 'a'; i <= max_c; i++)
	{
		for (std::string s : f(i, max_c, depth - 1))
		{
			v.push_back(c + s);
		}
	}

	return v;
}

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

	std::vector<std::string> ans = f('a', 'a', N);
	for (const std::string &s : ans)
	{
		std::cout << s << std::endl;
	}
}



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

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;

#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<(n);i++)
#define all(x) (x).begin(),(x).end()
constexpr auto INF = 5000000000000000;
constexpr auto MOD = 1000000007;

int gcd(int i, int j) {
	if (i < j) swap(i, j);
	while (i % j) {
		int k;
		k = i % j;
		i = j;
		j = k;
	}
	return j;
}

int main() {
	int k;
	cin >> k;
	ll ans = 0;

	rep(a, k)rep(b, k)rep(c, k) ans += gcd(gcd(a + 1, b + 1), c + 1);

	cout << ans << endl;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		while(true) {
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H*W==0) {
				System.exit(0);
			}
			int max=0;
			int[][] imos=new int[H+2][W+2];
			int[] omote=new int[W];
			for(int i=0; i<=H+1; i++) {
				Arrays.fill(imos[i], 0);
			}
			for(int i=0; i<H; i++) {
				for(int j=0; j<W; j++) {
					imos[i+1][j+1]=sc.nextInt();
				}
			}
			int zentan=1;
			for(int i=0; i<H; i++) {
				zentan*=2;
			}
			for(int i=0; i<zentan; i++) {
				Arrays.fill(omote, 0);
				int tmp=i;
				for(int j=1; j<=H; j++) {
					imos[j][W+1]=0;
					imos[j][0]=0;
					if(tmp%2==1) {
						imos[j][W+1]--;
						imos[j][0]++;
					}
					else {
						imos[j][W+1]=0;
						imos[j][0]=0;
					}
					tmp/=2;
				}
				for(int j=1; j<=H; j++) {
					for(int k=1; k<=W; k++) {
						imos[j][k]=(imos[j][k]+imos[j][0])%2;
						if(imos[j][k]==1) {
							omote[k-1]++;
						}
					}
				}
				int tmpose=0;
				for(int j=0; j<W; j++) {
					tmpose+=Math.max(omote[j], H-omote[j]);
				}
				max=Math.max(tmpose, max);
				for(int j=1; j<=H; j++) {
					for(int k=1; k<=W; k++) {
						imos[j][k]=(imos[j][k]+imos[j][0])%2;
					}
				}
			}
			pl(max);
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}


Measured memory_bytes: 51964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
ll inf = LLONG_MAX;
long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  ll r, g, b;
  cin >> r >> g >> b;
  if ((100 * r + 10 * g + b) % 4 == 0) YES();
  else NO();
}

Measured memory_bytes: 256
//10
#include<iostream>

using namespace std;

int h(int i){
  return i*(i+1)*(i+2)/6;
}

int main(){
  bool c[151201]={};
  for(int i=0;i*i*i<=151200;i++){
    c[i*i*i]=true;
  }
  bool ct[151201]={};
  for(int i=0;h(i)<=151200;i++){
    for(int j=0;j+h(i)<=151200;j++){
      ct[j+h(i)]|=c[j];
    }
  }
  for(int n;cin>>n,n;){
    for(;!ct[n];n--);
    cout<<n<<endl;
  }
  return 0;
}

Measured memory_bytes: 1460
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      String[] nyu=sc.nextLine().split(" ");
   //  String nyu=sc.nextLine();

int A=Integer.parseInt(nyu[0]);
int B=Integer.parseInt(nyu[1]);


System.out.println((A*3+B)/2);

	}
}

Measured memory_bytes: 21844
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        
        int n = sc.nextInt();
        for (int i = 3; i <= n; i++) {
            if (i%3 == 0) {
                sb.append(" ").append(i);
            } 
            else  {
                int j = i;
                while (j != 0) {
                    if (j%10 == 3) {
                        sb.append(" ").append(i);
                        break;
                    }
                    j /= 10;
                }
            }
        }
        System.out.println(sb);
    }
}

Measured memory_bytes: 27620
#include<iostream>
using namespace std;
int main()
{
	int n,flag=0;
	cin >> n;
	string s ;
	int f1=0,f2=0,f3=0;
	for(int i=0;i<n;i++) {
		cin >> s;
		if(s[0]=='B'&&s[s.size()-1]=='A') f3++;
		else if(s[0]=='B') f2++;
		else if(s[s.size()-1]=='A') f1++;
		for(int j=0;j<s.size()-1;j++) {
			if(s[j]=='A'&&s[j+1]=='B') {
				flag++;
			}
		}
	}
	if(f1==0) {
		if(f2>0) flag+=f3;
		else if(f3>0) flag+=f3-1; 
	}
	else flag+=f3+min(f1,f2) ;
	cout << flag;
 	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String args[] ) throws Exception {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        if (A - B >= 0) {
            System.out.println("delicious");
        } else if (B - A <= X) {
            System.out.println("safe");
        } else {
            System.out.println("dangerous");
        }
    }    
}


Measured memory_bytes: 23380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define pb push_back
typedef long long ll;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;

int main(){
  int a, b;
  cin >> a >> b;
  if(a<b){
    rep(i,b){
      cout << a;
    }
  }else{
    rep(i,a){
      cout << b;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256