akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
template<typename T> T pow(T a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
const int mod = 1000000007;
ll modpow(ll a, int b) { return b ? modpow(a * a % mod, b / 2) * (b % 2 ? a : 1) % mod : 1; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> inline void add(T &a, int b) { a += b; if (a >= mod) a -= mod; }



void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
      solve();
  }
}

// 0 indexed
int n;
int bit[26][500005];
void add(int a, int w, int i) {
  for (int x = a; x < n; x |= x + 1) {
    bit[i][x] += w;
  }
}
int sum(int a, int i) { // [0, a)
  int ret = 0;
  for (int x = a - 1; x >= 0; x = (x & (x + 1)) - 1) {
    ret += bit[i][x];
  }
  return ret;
}
void out() {
  cout << endl; rep(i, 26) { rep(j, 10) cout << bit[i][j] << " "; cout << endl; }
}
void solve() {
  // int n; debuged
  cin >> n;
  string s;
  cin >> s;
  rep(i, sz(s)) {
    add(i, 1, s[i] - 'a');
  }
  // cout << endl; rep(i, 26) { rep(j, 10) cout << bit[i][j] << " "; cout << endl; }
  // return;
  int q;
  cin >> q;
  while (q--) {
    int key;
    cin >> key;
    if (key == 1) {
      int i;
      char c;
      cin >> i >> c;
      i--;
      add(i, -1, s[i] - 'a');
      add(i, 1, c - 'a');
      s[i] = c;
      continue;
    }

    int l, r;
    cin >> l >> r;
    l--; r--;
    int ans = 0;
    rep(i, 26) {
      ans += (sum(r + 1, i) - sum(l, i) ? 1 : 0); // debuged
      // cout << i << " " << sum(r, i) << " " << sum(l - 1, i) << " " << ans << endl;
    }
    // out();
    cout << ans << endl;
  }
}


Measured memory_bytes: 51740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T> >;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif


vector<pair<char, int>> RLE(string s){
    vector<pair<char, int>> ret;
    int ns = SZ(s);
    int cnt = 0;
    rep(i, ns){
        cnt++;
        if((i < ns-1 && s[i] != s[i+1]) || i == ns-1){
            ret.emplace_back(s[i], cnt);
            cnt = 0;
        }
    }
    return ret;
}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    cout << RLE(s).size() << endl;
    return 0;
}

Measured memory_bytes: 1608
#include<iostream>
#include <cmath>
#include <set>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;
typedef unsigned long ul;
typedef pair<ul, ul> P;

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

int a,b,c;
int Num[3];
string s;

int main(){
  REP(i,3){
    cin >> Num[i];
  }

   sort(Num, Num + 3, greater<int>()); 

  cout << Num[0]*10+Num[1]+Num[2] <<endl;


  return 0;
}


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

using namespace std;


int n,m,q;
int a[100],b[100],c[100],d[100];
int ans = 0;

void dfs(vector<int> A) {
    if(A.size() == n+1) {
        int counter = 0;
        for(int i = 0; i < q; i++) {
            if(A[b[i]] - A[a[i]] == c[i]) {
                counter += d[i];
            }
        }
        ans = max(ans,counter);
        return;
    }
    A.push_back(A.back());
    while(A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main() {
    cin >> n >> m >> q;
    for(int i = 0; i < q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << "\n";
    return 0;
}

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

int main(void){
    int h,n;
    cin >> h >> n;
    int a[n],b[n];
    for(int i = 0;i < n;i++)cin >> a[i] >> b[i];
    
    int dp[n+1][h+1];
    for(int i = 0;i <= n;i++){
        for(int j = 0;j <= h;j++)dp[i][j] = 1e9;
    }
    
    dp[0][0] = 0;
    
    for(int i = 0;i < n;i++){
        for(int j = 0;j <= h;j++){
            dp[i+1][j] = min(dp[i][j],dp[i+1][max(0,j-a[i])]+b[i]);
        }
    }
    
    cout << dp[n][h] << endl;
}

Measured memory_bytes: 42692
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Deque<String> deque = new ArrayDeque<String>();
		Map<String, Integer> map = new HashMap<String, Integer>();
		deque.push("01234567");
		map.put(deque.getFirst(), 0);
		int count = 1;
		while (!deque.isEmpty()) {
			int size = deque.size();
			while (size-->0) {
				String str = deque.pop();
				for (int i = 0; i < 4; i++) {
					String newStr = slove(str, i);
					if (!newStr.isEmpty() && !map.containsKey(newStr)) {
						map.put(newStr, count);
						deque.offer(newStr);
					}
				}
			}
			count++;
		}
		Scanner scanner = new Scanner(System.in);
		while(scanner.hasNext()){
			System.out.println(map.get(scanner.nextLine().replace(" ", "")));
		}
	}

	private static String slove(String str, int i) {
		int index = str.indexOf("0");
		switch (i) {
		case 0:
			if (index != 3 && index != 7) {
				String rep = String.valueOf(str.charAt(index + 1));
				return rep(str, rep);

			} else {
				return "";
			}
		case 1:
			if (index != 0 && index != 4) {
				String rep = String.valueOf(str.charAt(index - 1));
				return rep(str, rep);
			} else {
				return "";
			}
		case 2:
			if (index < 4) {
				String rep = String.valueOf(str.charAt(index + 4));
				return rep(str, rep);
			} else {
				return "";
			}
		default:
			if (index > 3) {
				String rep = String.valueOf(str.charAt(index - 4));
				return rep(str, rep);
			} else {
				return "";
			}
		}
	}

	private static String rep(String str, String rep) {
		return str.replace("0", "9").replace(rep, "0").replace("9", rep);
	}
}

Measured memory_bytes: 89612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    string S,T; cin >> S>>T;
    int i,ans = 0;
    rep(i,S.size()){
        if(S[i]!=T[i]) ans++;
    }
    AA(ans);
    return 0;
}

Measured memory_bytes: 3916
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF (long long) 1e18//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos(-1))
#define MAXN (300006)
#define MAXK 26
#define MAXX 15000006
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < ee; ii++)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll(x)
#define p2(x) (1LL<<(x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, q;
string A;
pair <char,char> Q[MAXN];
int main()
{
	FAST
	// freopen("10.in","r",stdin);
	// freopen("10.out","w",stdout);
	cin >> n >> q >> A;
	for(ll i=0;i<q;i++) cin>>Q[i].f>>Q[i].s;
	ll st = -1, en = n, mid = 0;
	while(en-st>1) {
		mid = (st+en)>>1;
		ll co = mid; bool can = 0;
		for(ll i=0;i<q;i++) {
			if(co >= n||co<0) break;
			if(Q[i].f == A[co]) {
				co -= (Q[i].s == 'L');
				co += (Q[i].s == 'R');
			}
		}
		if(co==-1) can = 1;
		if(can) st=mid;
		else en=mid;
	}
	ll tmp = st+1; // cerr << tmp << '\n';
	st = -1, en = n, mid = 0;
	while(en-st>1) {
		mid = (st+en)>>1ll;
		ll co = mid; bool can = 0;
		for(ll i=0;i<q;i++) {
			if(co >= n||co<0) break;
			if(Q[i].f == A[co]) {
				co -= (Q[i].s == 'L');
				co += (Q[i].s == 'R');
			}
		}
		if(co>=n) can = 1;
		if(can) en = mid;
		else st = mid;
	}
// 	cerr << en << '\n';
	ll out = tmp + (n-en);
	cout << n-out << '\n';
}

Measured memory_bytes: 976
#include <bits/stdc++.h>
using namespace std;
long long n,m,w[101],v[101],f[101][100001];
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    scanf("%lld%lld",&n,&m);
    for (int i=1; i<=n; i++)
        scanf("%lld%lld",&w[i],&v[i]);
    for (int i=1; i<=n; i++)
        for (int j=1; j<=m; j++)
        {
            if (j-w[i]>=0)
                f[i][j]=max(f[i-1][j],f[i-1][j-w[i]]+v[i]);
            else
                f[i][j]=f[i-1][j];
        }
    printf("%lld",f[n][m]);
}


Measured memory_bytes: 78464
#スペース区切りの整数の入力
N,M = map(int, input().split())

ans_n = 0
if(N < 2):
  ans_n = 0
else:
  for i in range(N-1):
    ans_n = (i+1) + ans_n
    #print(ans_n)
  
ans_m = 0
if(M < 2):
  ans_m = 0
else:
  for i in range(M-1):
    ans_m = (i+1) + ans_m
    #print(ans_m)
  
print(ans_n+ans_m)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n; cin >> n;
    ll ans = 0;
    REP(i, n){
        int a; cin >> a;
        while(!(a%2)){
            ++ans;
            a >>= 1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int x;
  cin >> x;
  int a;
  a = x % 500;
  int t = 0;
  t += (x / 500) * 1000;
  t += (a / 5) * 5;
  cout << t << endl;
}


Measured memory_bytes: 3616
//#include "bits/stdc++.h"
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <complex>
#include <bitset>
#include <functional>
#include <stack>
#include <regex>
#include <tuple>
#include <iomanip>


#define int long long
#define REP(i,l,r) REPEAT(i,l,r,true) // [l, r)
#define rep(i,n) REP(i,0,n)           // [0, n)
#define REPEAT(i,l,r,condition) for(int i=(condition)?l:r-1;(condition)?i<r:i>=l;(condition)?++i:--i) // false<-[l, r)->true
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define fs first
#define sc second
#ifdef LOCAL
#define show(...) cerr<<#__VA_ARGS__<<" = ";_DEBUG(__VA_ARGS__)
#define showlr(n,l,r) cerr<<#n<<" = ";for(int i=l;i<r;i++){cerr<<n[i]<<", ";}cerr<<endl // [l, r)
#else
#define show(...)
#define showlr(n,l,r)
#endif

#define YN(condition) puts((condition)?"YES":"NO")
#define Yn(condition) puts((condition)?"Yes":"No")
#define yn(condition) puts((condition)?"yes":"no")
#define YES puts("YES")
#define Yes puts("Yes")
#define yes puts("yes")
#define NO  puts("NO")
#define No  puts("No")
#define no  puts("no")

#define case(i) printf("Case #%lld: ",i)

using namespace std;

using vi=vector<int>;
using pint=pair<int,int>;

struct io{io(){cin.tie(0);ios::sync_with_stdio(false);cout.tie(0);cout<<fixed<<setprecision(20);}}io;

template<class T> istream& operator >>(istream &is, vector<T> &v){for(T &e:v)is>>e;return is;}
template<class T> ostream& operator <<(ostream &os, vector<T> v){os<<"{";for(T &e:v)os<<e<<(v.size()-(int)(&e-&v[0])>1?", ":"");os<<"}";return os;}

void _DEBUG(){}
template<typename H,typename... T> void _DEBUG(H a,T...b){cerr<<a<<(sizeof...(b)?",":"\n");_DEBUG(b...);}

inline void in(){}
template<typename H,typename... T>void in(H &a, T&... b){cin>>a;in(b...);}
inline void out(){}
template<typename H,typename... T> void out(H a, T... b){cout<<a<<(sizeof...(b)?" ":"\n");out(b...);}

template<class T> void resz(int n,T& v){v.resize(n);}
template<class H,class... T> void resz(int n,H& a,T&... b){a.resize(n);resz(n,b...);}

template<typename V,typename H> void resize(vector<V>& v,const H a){v.resize(a);}
template<typename V,typename H,typename... T> void resize(vector<V>& v,const H& a,const T... b){v.resize(a);for(auto &v:v) resize(v,b...);}

const int INF=1LL<<55;
const int MOD=1000000007;
const double EPS=1e-8;
/*------------end of definitions------------*/

string S;

signed main(){

    in(S);
    for(auto e:S){
        if(e==',') cout<<' ';
        else cout<<e;
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 888
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency : generator = Generator, yield;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


immutable string YES = "Yes";
immutable string NO = "No";


auto solve(long N, string S) {
    return S[0 .. N / 2] == S[N / 2 .. $];
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    string S;
    S = input.front.to!string;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N, S);
    else {
        auto ans = solve(N, S);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100005
#define LL long long
LL n;
LL a[MAXN],b[MAXN];
int main()
{
	LL ans=0;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
		scanf("%lld %lld",&a[i],&b[i]);
	for(int i=n;i>=1;i--)
	{
		a[i]+=ans;
		LL j;
		for(j=a[i]/b[i];;j++)
			if(j*b[i]>=a[i])
				break;
		LL t=b[i]*j-a[i];
		ans+=t;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	const int M = 10000;
	vector<int> ans(M + 1);
	inc1(x, 200) {
	inc1(y, 200) {
	inc1(z, 200) {
		int v = x*x + y*y + z*z + x*y + y*z + z*x;
		if(v <= M) { ans[v]++; }
	}
	}
	}
	
	IN(int, n);
	inc1(i, n) { OUT(ans[i]); }
}


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

public class Main {
	final static int Mod = 1000000007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int m = Integer.parseInt(sc.next());
		int[] a = new int [n+1];
		int[] b = new int [m+1];

		for(int i=0;i<n;i++) {a[i] = Integer.parseInt(sc.next());}
		for(int i=0;i<m;i++) {b[i] = Integer.parseInt(sc.next());}
		sc.close();

		Arrays.sort(a);
		Arrays.sort(b);

		//反転
		for(int i=0,j=n,e;i<j;i++,j--) {
			e = a[i];
			a[i] = a[j];
			a[j] = e;
		}
		for(int i=0,j=m,e;i<j;i++,j--) {
			e = b[i];
			b[i] = b[j];
			b[j] = e;
		}

		long res = 1;
		int biggerX_a = 0, biggerX_b = 0;

		for (int x = n*m; x >= 1; x--) {
	        if (a[biggerX_a] > x) {System.out.println(0); return;}
	        if (b[biggerX_b] > x) {System.out.println(0); return;}

	        long tmp = 1;
	        if (a[biggerX_a] == x && b[biggerX_b] == x) {
	            tmp = 1;
	            biggerX_a++; biggerX_b++;
	        }
	        else if (a[biggerX_a] == x) {
	            tmp = biggerX_b;
	            biggerX_a++;
	        }
	        else if (b[biggerX_b] == x) {
	            tmp = biggerX_a;
	            biggerX_b++;
	        }
	        else {
	            tmp = biggerX_a * biggerX_b - (n * m - x);
	            if (tmp <= 0){System.out.println(0); return;}
	        }
	        res = (res * tmp) % Mod;
		}

		System.out.println(res);

	}

}

Measured memory_bytes: 25812
import java.io.*;
import java.lang.*;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.BigInteger;

public class Main {
    static InputReader in = new InputReader(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int n = in.nextInt();
        long sum = 0;
        for(int i = 1; i<=n; i++){
            for(int j = 1; j<=n; j++){
                for(int k = 1; k<=n; k++){
                    sum+=gcd(i,(gcd(j,k)));
                }
            }
        }
        out.print(sum);
        out.close();
    }
    static long gcd(long a, long b){
    	if(b==0){
    	    return a;
    	}
        return gcd(b, a%b);
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(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 (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        public boolean hasNext() {
            String next = null;
            try {
                next = reader.readLine();
            } catch (Exception e) {
            }
            if (next == null) {
                return false;
            }
            tokenizer = new StringTokenizer(next);
            return true;
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }
    }
}



Measured memory_bytes: 32924
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <deque>
#include <map>
#include <set>

#define ll long long
#define inf 0x3f3f3f3f
#define il inline

namespace io {

    #define in(a) a=read()
    #define out(a) write(a)
    #define outn(a) out(a),putchar('\n')

    #define I_int ll
    inline I_int read() {
        I_int x = 0 , f = 1 ; char c = getchar() ;
        while( c < '0' || c > '9' ) { if( c == '-' ) f = -1 ; c = getchar() ; }
        while( c >= '0' && c <= '9' ) { x = x * 10 + c - '0' ; c = getchar() ; }
        return x * f ;
    }
    char F[ 200 ] ;
    inline void write( I_int x ) {
        if( x == 0 ) { putchar( '0' ) ; return ; }
        I_int tmp = x > 0 ? x : -x ;
        if( x < 0 ) putchar( '-' ) ;
        int cnt = 0 ;
        while( tmp > 0 ) {
            F[ cnt ++ ] = tmp % 10 + '0' ;
            tmp /= 10 ;
        }
        while( cnt > 0 ) putchar( F[ -- cnt ] ) ;
    }
    #undef I_int

}
using namespace io ;

using namespace std ;

#define N 100010

int n = read(), k = read();

int main() {
	int cnt = 0;
	for(int i = 1; i <= n; i += 2) ++cnt;
	if(cnt >= k) puts("YES");
	else puts("NO");
}

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

int H, W, K;

bool judge(int bit, vector<vector<char>> c) {
	rep(i, H + W) {
		if(!(bit & (1 << i))) continue;

		if(i < H) {
			rep(j, W) c[i][j] = '.';
		} else {
			rep(j, H) c[j][i - H] = '.';
		}
	}

	int res = 0;
	rep(i, H) {
		rep(j, W) {
			if(c[i][j] == '#') res++;
		}
	}

	if(res == K)
		return true;
	else
		return false;
}

int main() {
	cin >> H >> W >> K;
	vector<vector<char>> c(H, vector<char>(W));
	rep(i, H) {
		rep(j, W) cin >> c[i][j];
	}

	int cnt = 0;
	rep(bit, 1 << H + W) {
		if(judge(bit, c)) cnt++;
	}

	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;
#define MAXN 100001
string S[MAXN];

int main(){
    int N;
    cin >> N;
    long long ans = 0;
    map<string,int> MA;
    for(int i=0;i<N;i++){
        cin >> S[i];
        sort(S[i].begin(),S[i].end());
        MA[S[i]]++;
        ans += MA[S[i]]-1; 
    }

    
    
        cout << ans << endl;

    return 0;
}

Measured memory_bytes: 18176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b-1; i >= a; i--)
typedef pair<int,int> pii;
typedef pair<long long, long long> pll;

signed main(){
    ll N; cin >> N;
    ll cnt = 0;
    if(N%2 == 1){
        cout << 0 << endl;
        return 0;
    }
    N/=2;
    while(N > 0){
        cnt += N/5;
        N /= 5;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef struct{
    int H;
    vector<int> next;
    bool flag;
}TENBO;
int main(){
    int N,M,a,b;
    cin >> N >> M;
    TENBO dai[N];
    for(int i=0; i<N; i++){
        cin >> dai[i].H;
        dai[i].flag=1;
    }
    for(int i=0; i<M; i++){
        cin >> a >> b;
        a--;b--;
        if(dai[a].H==dai[b].H){
            dai[a].flag=0;
            dai[b].flag=0;
        }else if(dai[a].H>dai[b].H){
            dai[b].flag=0;
        }else{
            dai[a].flag=0;
        }
    }
    int ans=0;
    for(int i=0; i<N; i++){
        if(dai[i].flag==1) ans++;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 7536
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>


/* ---------- Namespace ---------- */

using namespace std;


/* ---------- Type Abbreviation ---------- */

template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

using ll = long long;
using PL = P<ll, ll>;
using PS = P<string, ll>;

using VI = V<int>;
using VVI = V<VI>;
using VL = V<ll>;
using VVL = V<VL>;
using VS = V<string>;
using VB = V<bool>;
using VVB = V<VB>;
using VPL = V<PL>;
using VPS = V<PS>;

#define fst first
#define snd second


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)


/* ---------- container ---------- */

#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define GSORT(c) sort(ALL(c), greater<decltype((c).front())>())
#define SZ(x) (LL((x).size()))


/* ---------- repetition ---------- */

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)

#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// Usual REP runs from 0 to n-1 (R: n to 0)
// Natural REP runs from 1 to n (R: n to 1)


/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = 3.14159265358979;
// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};


/* ---------- Short Functions ---------- */

template <typename T>
T square(T a) {
    return a * a;
}


/* ---------- Debug ---------- */
#define GET_VAR_NAME(variable) #variable

#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;
#define testP(p) cout << GET_VAR_NAME(p) << " = (" << (p).fst << ", " << (p).snd << ")" << endl;


/* ^^^^^^^^^^^^^^^ Settting Part ^^^^^^^^^^^^^^^ */

/* ---------- Variances ---------- */


/* ---------- Functions ---------- */


/* ---------- Main Function ---------- */

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

    int N;
    cin >> N;

    VI L(N * 2);
    REP(i, N * 2) {
        cin >> L[i];
    }

    GSORT(L);

    int ans = 0;
    REP(i, N) {
        ans += L[i * 2 + 1];
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  int c = abs(a - b);
  if (abs(a - b) % 2 == 0) {
    cout << (a > b ? a - c / 2 : b - c / 2) << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
x = map(int,raw_input().split())
n=x[0]
k=x[1]
q=x[2]

z=[k-q]*n



for i in range(q):
    y=int(raw_input())
    z[y-1]=z[y-1]+1


for i in range(n):
    if z[i]>0:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 8448
N=int(input())
C=[]
dic={}
ans=0
for i in range(N):
  a=str(input())
  C.append(a)
for i in C:
  ab=[j for j in i]
  ab.sort()
  aaa="".join(ab)
  #print(aaa)
  if aaa in dic:
    ans+=dic[aaa]
    dic[aaa]+=1
  else:
    dic[aaa]=1
print(ans)
#print(dic)

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

#define FOR(i,a,n) for (int i = a; i < (int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { \
    return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
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;}

using ll = long long;

constexpr ll INF = (1e9);
constexpr ll MOD = (1e9+7);

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


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

using namespace std;

void solve()
{
	vector<int> b(3);
	for (int i = 0; i < 3; ++i)
	{
		cin >> b[i];
	}
	if ((b[0] == 1 && b[1] == 1 && b[2] == 0) || (b[0] == 0 && b[1] == 0 && b[2] == 1))
	{
		cout << "Open" << endl;
	}
	else
	{
		cout << "Close" << endl;
	}
}

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

Measured memory_bytes: 1184
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static class Process {
		private String name;
		private int time;

		public Process(String name, int time) {
			this.name = name;
			this.time = time;
		}

		public void setTime(int time) {
			this.time = time;
		}

		public String getName() {
			return this.name;
		}

		public int getTime() {
			return this.time;
		}
	}

	public static class Queue {
		private Process[] data;
		private int head;
		private int tail;
		private int max;

		public Queue (int processNum) {
			this.data = new Process[processNum + 1];
			this.head = 0;
			this.tail = 0;
			this.max = processNum + 1;
		}

		public void enqueue(Process process) {
			this.data[this.tail] = process;
			if(this.tail + 1 == this.max) {
				this.tail = 0;
			} else {
				this.tail++;
			}
		}

		public Process dequeue() {
			Process process = this.data[this.head];
			if(this.head + 1 == this.max) {
				this.head = 0;
			} else {
				this.head++;
			}
			return process;
		}

		public boolean isEmpty() {
			if(this.tail == this.head) {
				return true;
			}
			return false;
		}
	}

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] premise = br.readLine().split(" ");

		int processNum =Integer.parseInt(premise[0]);

		Queue queue = new Queue(processNum);

		int q = Integer.parseInt(premise[1]);

		for(int i = 0; i < processNum; i++) {
			String[] processString = br.readLine().split(" ");
			Process process = new Process(processString[0], Integer.parseInt(processString[1]));
			queue.enqueue(process);
		}

		int progressTime = 0;
		while(!queue.isEmpty()) {
			Process process = queue.dequeue();

			if(process.getTime() <= q) {
				progressTime += process.getTime();
				System.out.println(process.getName() + " " + progressTime);
			} else {

				// ?????????????????????1??\???????????´???
				int processingTime = process.getTime() - q;

				progressTime += q;

				process.setTime(processingTime);
				queue.enqueue(process);
			}
		}
	}
}

Measured memory_bytes: 60472
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=1000002;
struct Uzi{
	int x,y;
	bool operator<(const Uzi &k)const{
		if(k.x!=x)return k.x<x;
		return k.y<y;
	}
}g[N];
int n,m,p,s,a,b,i,j,f[10];
void init(){
	scanf("%d%d%d",&n,&m,&p);
	while(p--){
		scanf("%d%d",&a,&b);
		for(i=a;i<=a+2&&i<=n;i++)
			for(j=b;j<=b+2&&j<=m;j++)
				if(i>=3&&j>=3)
				g[++s]=(Uzi){i,j};
	}
	sort(g+1,g+s+1);
}
void work(){
	for(i=1;i<=s;i++){
		for(j=i;g[j+1].x==g[j].x&&g[j+1].y==g[j].y;j++);
		f[j-i+1]++;
		i=j;
	}
	for(i=1;i<=9;i++)
		f[0]+=f[i];
	printf("%lld\n",1ll*(n-2)*(m-2)-f[0]);
	for(i=1;i<=9;i++)
		printf("%d\n",f[i]);
//	while(1);
}
int main(){
	init();
	work();
	return 0;
}


Measured memory_bytes: 7168
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.MathContext;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.TreeMap;
import java.util.TreeSet;

import static java.util.Comparator.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        Solver solver = new Solver(System.in, out);
        solver.solve();
        out.close();
    }
}
class Solver {
	Scanner sc;
	PrintWriter out;
    public Solver(InputStream in, PrintWriter out) {
    	sc = new Scanner(in);
    	this.out = out;
    }
    // ==================================================================
    public void solve() {
    	int N = ni();
    	int Y = ni();
    	for (int i = 0; i <= N; i++) {
    		for (int j = 0; j <= N; j++) {
				if((N-i-j) >= 0 &&
					(Y - i*10000 - 5000*j - (N-i-j)*1000) == 0) {
					out.println(i + " " + j + " " + (N-i-j));
					return;
				}
			}
		}
    	out.println("-1 -1 -1");
    }
    // ------------------------------------------
    // 入力
    // ------------------------------------------
    public int ni() {
    	return Integer.parseInt(sc.next());
    }
    public long nl() {
    	return Long.parseLong(sc.next());
    }
    public String ns() {
    	return sc.next();
    }
    public char[] nc() {
    	return sc.next().toCharArray();
    }
    public int[] ndi(int N) {
    	int[] ans = new int[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ni();
		}
    	return ans;
    }
    public long[] ndl(int N) {
    	long[] ans = new long[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = nl();
		}
    	return ans;
    }
    public String[] nds(int N) {
    	String[] ans = new String[N];
    	for (int i = 0; i < N; i++) {
			ans[i] = ns();
		}
    	return ans;
    }
    public char[][] ndc(int N) {
    	char[][] ans = new char[N][];
    	for (int i = 0; i < N; i++) {
			ans[i] = nc();
		}
    	return ans;
    }
    public int[][] ndii(int N, int S) {
    	int[][] ans = new int[N][S];
    	for (int i = 0; i < N; i++) {
			for (int j = 0; j < S; j++) {
				ans[i][j] = ni();
			}
		}
    	return ans;
    }
}


Measured memory_bytes: 21972
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define PII pair<LL,LL>
#define FOR(i,a,b) for (LL i=(a);i<=(b);++i)
#define ROF(i,b,a) for (LL i=(b);i>=(a);--i)
typedef long long LL;
inline LL read(){
	LL x=0,f=1; char ch=getchar();
	while (ch<'0'||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	while (ch>='0'&&ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	return x*f;
}

const LL MAXN=300005,Mo=1000000007;
struct list{
	LL l,lt[MAXN],nt[MAXN*2],x[MAXN*2],y[MAXN*2];
	void clear(){ l=1; memset(lt,0,sizeof(lt)); }
	void addedge(LL a,LL b,LL c){ l++; nt[l]=lt[a]; lt[a]=l; x[l]=b; y[l]=c; }
}E;
LL n,m,q,l,b[MAXN],c[MAXN],a[MAXN],r[MAXN],t[MAXN],ans[MAXN];
int main(){
	n=read();
	m=read(); r[0]=0;
	FOR(i,1,m) r[i]=read();
	q=read();
	FOR(i,1,q) { t[i]=read(); a[i]=read(); }
	b[1]=0; c[1]=0; b[2]=n; c[2]=n;
	l=1;
	FOR(i,1,q) {
		while (l<=m&&r[l]<=t[i]) {
			LL T=r[l]-r[l-1];
			if (T<=min(c[1],c[2])) c[1]=n-(c[1]-T),c[2]=n-(c[2]-T);
			else if (T>=max(c[1],c[2])) c[1]=c[2]=b[1]=b[2]=n;
			else {
				if (c[1]<T) {
					b[1]+=T-c[1];
					c[1]=n; c[2]=n-(c[2]-T);
				}
				else {
					b[2]-=T-c[2];
					c[2]=n; c[1]=n-(c[1]-T);
				}
			}
			l++;
		}
		//printf("%d:%d %d %d %d\n",l,b[1],c[1],b[2],c[2]);
		LL T=t[i]-r[l-1],tmp;
		if (a[i]<=b[1]) tmp=c[1];
		else if (a[i]>=b[2]) tmp=c[2];
		else {
			if (c[1]<c[2]) tmp=c[1]+a[i]-b[1];
			else tmp=c[1]-a[i]+b[1];
		}
		if (tmp>T) tmp-=T; else tmp=0;
		printf("%lld\n",(l&1)?tmp:n-tmp);
	}
	return 0;
}

/*
*/


Measured memory_bytes: 13440
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
cnt = 0
for i in range(n):
    total = c
    a = list(map(int,input().split()))
    for j in range(m):
        total += a[j]*b[j]
    
    if total > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s; cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') s[i] = '9';
        else if(s[i] == '9') s[i] = '1';
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
 
using namespace std;
 
auto main() -> int
{
  int Monster, waza; cin >> Monster >> waza;
  vector<int> HP(Monster);
  
  REP(i, Monster)
  	cin >> HP[i];
  
  if (waza >= Monster) cout << 0 << endl;
  else
  {
    sort(ALL(HP), greater<int>());

    long long int n = accumulate(HP.begin() + waza, HP.end(), 0LL);

    cout << n << endl;
  } 

}

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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
   int x,n;
    cin >> x >> n;
    
    set<int> st;
    
    for(int i=1;i<=n;i++)
    {
        int g;
        cin >> g;
        st.insert(g);
    }
    
    for(int i=0;;i++)
    {
        int g1 = x - i;
        int g2 = x + i;
        
        if(st.find(g1) == st.end())
        {
            cout << g1; return;
        }
        
        
        if(st.find(g2) == st.end())
        {
            cout << g2; return;
        }
    }
        
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 3664
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
int n;
vector<ll> a;
multiset<ll> cur;
int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    a.assign(n, 0);
    F0R(i, n) cin >> a[i];
    cur.insert(a[n - 1]);
    for(int i = n - 2; i >= 0; --i)
    {
        auto itx = cur.upper_bound(a[i]);
        if(itx == cur.end()) cur.insert(a[i]);
        else
        {
            cur.erase(itx);
            cur.insert(a[i]);
        }
    }
    cout << sz(cur);
    return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
double eps=1e-9;
int main(){
	while(true){
		int N,a[256],R[257],cnt[256];
		cin>>N;
		if(N==0) break;
		rep(i,N) cin>>a[i];
		double mx=1e10;
		int ss,aa,cc;
		rep(S,16) rep(A,16) rep(C,16){
			R[0]=S;
			rep(i,N) R[i+1]=(A*R[i]+C)%256;
			rep1(i,N) R[i]=(R[i]+a[i-1])%256;
			double H=0;
			rep(i,256) cnt[i]=0;
			rep1(i,N) cnt[R[i]]++;
			rep(i,256){
				if(cnt[i]>0){
					H-=(double)cnt[i]/N*log((double)cnt[i]/N);
				}
			}
			if(H<mx-eps) mx=H,ss=S,aa=A,cc=C;
		}
		cout<<ss<<" "<<aa<<" "<<cc<<endl;
	}
}

Measured memory_bytes: 1208
/****************************************************************************************
   *  Md. Abdulla Al Mamun (Nayon)
   *  ID: 1306001
   *  Session: 2013-2014
   *  Department of Computer Science and Engineering
   *  Begum Rokeya University, Rangpur (BRUR)
   *
   *  Project Name:			factorial n
   *  File Created:			Monday, 2015-10-26-22.20.20
   *  Current File:			D:\My Codes\C and C++\Code-Blocks Projects\factorial n\main.cpp
   *  Language:				English (U.S.)
   *  Encoding:				windows-1252
*****************************************************************************************/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <math.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <ios>
#include <set>
#include <map>

using namespace std;

#define PI acos(-1.0)
#define EPS 1e-9
#define INF 1 << 28
#define all(x) (x).begin(), (x).end()
#define pb() push_back()
#define ppb pop_back
#define mp(a, b) make_pair(a, b)
#define endl '\n'
#define MAX 100000

typedef pair<int, int> pii;

//#define isValid(a, b) ((a >= 0 && a < b) ? 1 : 0)
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

int main()
{
	//freopen("in.txt", "r", stdin);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
    unsigned long long fact = 1, n;
    cin >> n;
    if(n == 0)
        cout << 1 << endl;
    else{
        for(unsigned long long i = 1; i <= n; i++)
            fact *= i;
        cout << fact << endl;
    }
	return 0;
}

Measured memory_bytes: 1192
import java.io.*;
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner x=new Scanner(System.in);
    	int a=x.nextInt();
		int b=x.nextInt();
		int c=a+b;
		int d=a-b;
		int e=a*b;
		if(c>=d && c>=e)
		{
			System.out.println(c);
			return;
		}
		if(d>=c && d>=e)
		{
			System.out.println(d);
			return;
		}
		if(e>=d && e>=c)
		{
			System.out.println(e);
			return;
		}
	}
}

Measured memory_bytes: 21844
h, w = map(int, input().split())
s = [input() for _ in range(h)]
d = [[1000000] * w for _ in range(h)]
d[0][0] = 0
for i in range(h):
    for j in range(w):
        if i < h - 1:
            d[i + 1][j] = min(d[i + 1][j], d[i][j] +
                              (1 if s[i][j] != s[i + 1][j] else 0))
        if j < w - 1:
            d[i][j + 1] = min(d[i][j + 1], d[i][j] +
                              (1 if s[i][j] != s[i][j + 1] else 0))
ans = d[h - 1][w - 1]
if s[0][0] == '#':
    ans += 1
if s[h - 1][w - 1] == '#':
    ans += 1
print(ans // 2)


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

const int long long INF=1LL<<60;
const int MAX_N=110;
const int MAX_V=100010;

int N;
long long W, weight[MAX_N], value[MAX_N];

long long dp[MAX_N][MAX_V];

int main(){
    cin>>N>>W;
    for(int i=0;i<N;i++){
        cin>>weight[i]>>value[i];
    }
    for(int i=0;i<MAX_N;i++){
        for(int j=0;j<MAX_V;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    for(int i=0;i<N;i++){
        for(int sum_v=0;sum_v<MAX_V;sum_v++){
            if(sum_v-value[i]>=0){
                dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v-value[i]]+weight[i]);
            }
            dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }
    long long res=0;
    for(int sum_v=0; sum_v<MAX_V;sum_v++){
        if(dp[N][sum_v]<=W)res=sum_v;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 86144
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split(" ").map(Number);
var ab=arr[0]+arr[1];
console.log((ab+"").length);
}

Measured memory_bytes: 8780
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {

  while (1) {

    int n;

    cin >> n;
    if (n == 0) break;

    vector<int> income(n, 0);
    
    int tmp = 0;
    int sum = 0;
    double ave;

    for (int i = 0; i < n; i++) {
      cin >> tmp;
      sum += tmp;
      income[i] = tmp;
    }
    ave = sum / n;

    sort(income.begin(), income.end());
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (income[i] > ave)
        break;
      else
        ans += 1;
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 3152