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

int main() {
  ll x,k,d=0;
  cin>>x>>k>>d;
  
  x=abs(x);
  
  if(x==0){
    if(k%2==0){
      cout<<x;
      return 0;
    }
    if(k%2==1){
      cout<<d;
      return 0;
    }
  }
  
  if(x/d>=k){
    cout<<x-d*k;
    return 0;
  }
  
  if(x/d<k){
    k-=x/d;
    x=x%d;
  }
  /*if(k==0){
    cout<<x;
    return 0;
  }
  if(x>abs(d-x)){
    x-=d;
    k--;
  }
  if(k==0){
    cout<<x;
    return 0;
  }*/
  if(k%2==0){
    cout<<x;
    return 0;
  }
  if(k%2==1){
    cout<<abs(x-d);
    return 0;
  }
}

Measured memory_bytes: 3616
#include<iostream>
#define ll long long
using namespace std;
ll int min(ll int a,ll int b){
	if(a>b)return b;
	return a;
}
ll int abs(ll int a){
	if(a>0)return a;
	return -a;
}
ll int x[200000];
int main(){
	int a;
	cin>>a;
	int b[a+6];
	for(int i=0;i<a;i++)cin>>b[i];
	x[1]=abs(b[1]-b[0]);
	for(int i=2;i<a;i++)
	x[i]=min(x[i-2]+abs(b[i]-b[i-2]),x[i-1]+abs(b[i]-b[i-1]));
	cout<<x[a-1];
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    int K = scanner.nextInt();
    char[][] S = new char[H][W];
    for (int i = 0; i < H; i++) {
      S[i] = scanner.next().toCharArray();
    }

    int min = 1_000_000;
    for (int i = 0; i < 1 << (H - 1); i++) {
      int hcount = Integer.bitCount(i);
      int wcount = 0;
      int[] sum = new int[H];
      for (int j = 0; j < W; j++) {
        int[] next = new int[H];
        int ih = 0;
        for (int k = 0; k < H; k++) {
          if (S[k][j] == '1') next[ih]++;
          if ((i >> k & 1) == 1) ih++;
        }
        for (int k = 0; k < H; k++) if (next[k] > K) wcount = 1_000_000;
        for (int k = 0; k < H; k++) {
          if (sum[k] + next[k] > K) {
            wcount++;
            System.arraycopy(next, 0, sum, 0, H);
            break;
          } else {
            sum[k] += next[k];
          }
        }
      }
      min = Math.min(min, hcount + wcount);
    }
    System.out.println(min);
  }
}


Measured memory_bytes: 39168
/*
 _____ _             _              _           _ 
|_   _| |__   ___   / \   _ __  ___| |__  _   _| |
  | | | '_ \ / _ \ / _ \ | '_ \/ __| '_ \| | | | |
  | | | | | |  __// ___ \| | | \__ \ | | | |_| | |
  |_| |_| |_|\___/_/   \_\_| |_|___/_| |_|\__,_|_|                                                

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define	endl		'\n'
#define mii         map<ll,ll>
#define msi         map<string,ll>
#define mis         map<ll, string>
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repr(i,a,b) for(ll i=b-1;i>=a;i--)
#define trav(a, x) 	for(auto& a : x)
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pair<ll, ll>>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define max(a,b)	(a>b?a:b)
#define min(a,b)	(a<b?a:b)

/*	For Debugging	*/
#define DEBUG 		cerr<<"\n>>>I'm Here<<<\n"<<endl;
#define display(x) trav(a,x) cout<<a<<" ";cout<<endl;
#define what_is(x)  cerr << #x << " is " << x << endl;

std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace __gnu_pbds;
using namespace std;
#define PI 3.141592653589793
#define N  100005

void solve()
{
	ll n;
	cin>>n;
	long double ans=n*n*n*1.0;
	ans=ans/27.0;
	cout<<ans<<endl;
	return;
}
int main()
{
	DECIMAL(10)
	FAST
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	TIME
	return 0;
}

Measured memory_bytes: 256
table = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8],
         [0, 4, 8], [2, 4, 6]]
check = ->(field, type) {
  table.each do |pat|
    return true if pat.map {|i| field[i] == type}.all?
  end
  false
}

$<.readlines.map(&:chomp).map(&:chars).each do |field|
  result = if check.(field, "o")
    "o"
  elsif check.(field, "x")
    "x"
  else
    "d"
  end
  puts result
end


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/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; }



int main(){

    int n, q;
    string s;
    cin >> n >> s >> q;
    V<set<int>> idx(26);
    rep(i,n) {
        idx[s[i]-'a'].insert(i+1);
    }

    rep(qi,q) {
        int d;
        cin >> d;
        if(d == 1) {
            int i;
            char c;
            cin >> i >> c;
            idx[s[i-1]-'a'].erase(i);
            idx[c-'a'].insert(i);
            s[i-1] = c;
        }
        else {
            int l, r;
            cin >> l >> r;
            int ans = 0;
            rep(ci,26) {
                auto it_l = idx[ci].lower_bound(l);
                auto it_r = idx[ci].lower_bound(r+1);
                ans += (it_r != it_l);
            }
            cout << ans << endl;
        }
    }
}

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

int main(){
	
	long long int x,k,d;
	cin >> x >> k >> d;
	x=abs(x);
	long long int straight=min(x/d,k);
	x-=straight*d;
	k-=straight;
	if(k%2==0)
		cout << x<<endl;
	else
		cout <<d-x <<endl;
	
	return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <cmath>
#include <string>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
const int MOD = 1000000007;

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    ll l,r;
    cin>>l>>r;
    ll lmod = l%2019;
    ll rmod = r%2019;
    ll diff = abs(r-l);
    if(diff < 2019 && lmod<rmod){
        ll ans=10001;
        for(ll i=lmod;i<rmod;++i){
            for(ll j=i+1;j<=rmod;++j){
                ans = min(ans,(i*j%2019));
            }
        }
        cout<<ans;
    }
    else cout<<0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;
const ll INF=-10000000000;

ll maxx(ll x,ll y,ll z){
	return max(max(x,y),z);
}
ll minn(ll x,ll y,ll z){
	return min(min(x,y),z);
}
ll gcd(ll x,ll y){
	if(x%y==0) return y;
    else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x*(y/gcd(x,y));
}

//a,b x
int main(){
	ll A,B; cin>>A>>B;
	cout<<(A+B+1)/2;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#define int long long
#define double long double
#define oku7 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用

using namespace std;
std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

vector<vector<int>> ansvec;
int a[501][501], x[100001],ballNum[100001];
bool can[100001];
unsigned euclidean_gcd(unsigned a, unsigned b) {
	if (a < b) euclidean_gcd(b, a);
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}

signed main() {
	int N, X;
	cin >> N >> X;

	for (int i = 0; i < N; i++) {
		cin >> x[i];
		x[i] -= X;
		if (x[i] < 0) x[i] *= -1;
	}
	if (N == 1) {
		cout << x[0]<<"\n";
		return 0;
	}

	int ans = euclidean_gcd(x[0], x[1]);
	for (int i = 0; i < N; i++) {
		ans = euclidean_gcd(ans, x[i]);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void){
 int a;
 int b;
 int c;
 scanf("%d %d %d",&a,&b,&c);
 if(a<=b&&b<=c) printf("%d %d %d\n",a,b,c);
 else if(a<=c&&c<=b) printf("%d %d %d\n",a,c,b);
 else if(b<=a&&a<=c) printf("%d %d %d\n",b,a,c);
 else if(b<=c&&c<=a) printf("%d %d %d\n",b,c,a);
 else if(c<=a&&a<=b) printf("%d %d %d\n",c,a,b);
 else if(c<=b&&b<=a) printf("%d %d %d\n",c,b,a);











    return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
    int n, l;
    cin >> n >> l;
    int mem=abs(l), res=0;
    for(int i=0; i<n; ++i){
        if(abs(l)<abs(mem)) mem = l;
        res += l;
        ++l;
    }
    res -= mem;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    int p[11];
    int mx=0;
    int sum=0;
    for(int i=0;i<N;i++) {
        cin>>p[i];
        mx=max(mx,p[i]);
        sum+=p[i];
    }
    sum-=mx/2;
    cout<<sum<<endl;
    
    return 0;
}



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

using namespace std;

int main() {
  int H, N;
  cin >> H >> N;

  vector<int> A(N);
  vector<int> B(N);

  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }

  vector<vector<int>> dp(N, vector<int>(H+1, 1000000000));

  for (int i = 0; i < N; i++) {
    dp[i][0] = 0;
    for (int h = 1; h <= H; h++) {
      if (i > 0) {
        dp[i][h] = min(dp[i][h], dp[i-1][h]);
      }
      dp[i][h] = min(dp[i][h], dp[i][max(h - A[i], 0)] + B[i]);
    }
  }

  cout << dp[N-1][H] << endl;

  return 0;
}


Measured memory_bytes: 39424
#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>
*/

#define int long long
#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define showp(n) cerr<<n.fs<<", "<<n.sc<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl
#define showsp(n) for(auto z:n){cerr<<z.fs<<" "<<z.sc<<", "}cerr<<endl

#define yes printf("Yes\n")
#define no printf("No\n")
#define case(i) printf("Case #%lld: ",i)

using namespace std;

using ull=unsigned long long;
using vi=vector<int>;
using pint=pair<int,int>;

const int INF = (1LL << 55);

int n, x;
vi vec;
int ans=0;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>x;
    int a;
    rep(i,n){
         cin>>a;
         vec.pb(a);
         x -= a;
    }

    ans = n;
    int mn = INF;
    rep(i,n){
        mn = min(vec[i], mn);
    }
    while(x >= mn){
        x -= mn;
        ans++;
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define MOD 100000

int solve(int n, int m, int s){

  vector<vector<int>> dp(n*n+1, vector<int>(s+1, 0));
  dp[0][0] = 1;
  repl(i,1,m+1){
    vector<vector<int>> nxt(n*n+1, vector<int>(s+1, 0));
    rep(j,n*n+1) rep(k,s+1) if(dp[j][k]>0){
      (nxt[j][k] += dp[j][k])%=MOD;
      if(j+1<=n*n && k+i<=s) (nxt[j+1][k+i] += dp[j][k]) %= MOD;
    }
    swap(dp, nxt);
  }
  return dp[n*n][s];
}

int main(){
  int n,m,s;
  while(cin>>n>>m>>s, n){
    cout << solve(n,m,s) << endl;
  }

  return 0;
}

Measured memory_bytes: 4040
import std.stdio, std.conv, std.string;
import std.algorithm, std.array, std.container, std.typecons;
import std.numeric, std.math;
import core.bitop;

T RD(T = string)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T)(in string str) { return str.split.to!(T[]); }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool INSIDE(T)(T x, T b, T e) { return x >= b && x < e; }

long mod = pow(10, 9) + 7;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

struct UnionFind
{
	void init(long n) { par = new long[](n); foreach (i; 0..n) par[i] = i; }
	long root(long i) { return par[i] == i ? i : (par[i] = root(par[i])); }
	bool same(long i, long j) { return root(i) == root(j); }
	void unite(long i, long j) { i = root(i); j = root(j); if (i == j) return; par[i] = j; }
	long[] par;
}

void main()
{
	auto H = RD!long;
	auto W = RD!long;
	string[] s;
	foreach (i; 0..H)
	{
		s ~= RD!string;
	}

	long[3][] open;
	open ~= [0, 0, 1];
	auto close = new long[][](H, W);
	long[2][4] dir = [[-1, 0], [1, 0], [0, -1], [0, 1]];
	long cost = -1;
	while (!open.empty)
	{
		auto node = open.front;
		open.popFront;
		if (node[0] == H - 1 && node[1] == W - 1)
		{
			cost = node[2];
			break;
		}
		foreach (d; dir)
		{
			auto y = node[0] + d[0];
			auto x = node[1] + d[1];
			if (!INSIDE(y, 0, H) || !INSIDE(x, 0, W)) continue;
			if (close[y][x] == 1 || s[y][x] == '#') continue;
			open ~= [y, x, node[2] + 1];
			close[y][x] = 1;
		}
	}
	if (cost == -1)
	{
		writeln("-1");
	}
	else
	{
		long ans;
		foreach (e; s)
		{
			foreach (ee; e)
			{
				if (ee == '.') ++ans;
			}
		}
		ans -= cost;
		writeln(ans);
	}

	stdout.flush();
}

Measured memory_bytes: 636
# AOJ 0097 Sum of Integers II
# Python3 2018.6.15 bal4u

dp = [[0 for s in range(1001)] for n in range(11)]
dp[0][0] = 1
for k in range(101):
	for n in range(9, -1, -1):
		for s in range(1001-k):
			dp[n+1][s+k] += dp[n][s]

while True:
	n, s = list(map(int, input().split()))
	if n == 0: break
	print(dp[n][s])


Measured memory_bytes: 5832
#include <bits/stdc++.h>
using namespace std;
int n;
long long c, z;
long long a[100020];
long long b[100020];
long long f[100020];
long long g[100020];
long long p[100020];
long long q[100020];
int main() {
	scanf("%d%lld", &n, &c);
	for (int i = 1; i <= n; i++) {
		scanf("%lld%lld", &p[i], &a[i]);
		q[i] = c - p[i];
		b[i] = a[i];
		a[i] += a[i - 1];
		f[i] = max(f[i - 1], a[i] - 2 * p[i]);
	}
	for (int i = n; i >= 1; i--) {
		b[i] += b[i + 1];
		g[i] = max(g[i + 1], b[i] - 2 * q[i]);
	}
	for (int i = 1; i <= n; i++) {
		z = max(z, a[i] - p[i] + g[i + 1]);
		z = max(z, b[i] - q[i] + f[i - 1]);
	}
	printf("%lld\n", z);
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
ll max_val = 1e5;
int main(){
	ios::sync_with_stdio();
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll n = s.length();
	ll m = t.length();
	ll dp[n+1][m+1];
	for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i==0 || j==0)
                dp[i][j]=0;
            else if(s[i-1]==t[j-1])
                dp[i][j]=dp[i-1][j-1]+1;
            else
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
        }
	}
	ll len = dp[n][m];
	int i=n,j=m;
	string ans="";
	while(i>0 && j>0){
        if(s[i-1]==t[j-1]){
            ans.push_back(s[i-1]);
            i--;
            j--;
        }
        else if(dp[i-1][j]>dp[i][j-1])
            i--;
        else
            j--;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<endl;
  	return 0;
}


Measured memory_bytes: 73912
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  int N ;
  cin >> N ;
  vector<pair<string,int>> P ;
  vector<pair<string,int>> Q ;
  rep(i,N){
    string S ;
    int M ;
    cin >> S >> M ;
    P.push_back(make_pair(S,M*-1));
    Q.push_back(make_pair(S,M));
  }
  int ans = 1 ; 
  sort(P.begin(),P.end()) ;
  //rep(i,N) cout << P.at(i).first << " " << P.at(i).second << endl;
  rep(i,N){
    rep(j,N){
	  if(P.at(i).first == Q.at(j).first && P.at(i).second *( -1)== Q.at(j).second ){
        cout << j+1 << endl;
      }
    }
  }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;
const int MAX_N=2*1e5+3;
int cnt[MAX_N];

int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int x;
    cin>>x;
    cnt[x]=cnt[x-1]+1;
  }
  int ma=0;
  for(int i=0;i<n+1;i++){
    if(ma<cnt[i])ma=cnt[i];
  }
  cout<<n-ma<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<climits>
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp> 
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define endl '\n'
#define SIZE 1000002
#define w(t) int t;cin>>t;while(t--)
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define value_at_idx find_by_order
#define idx order_of_key
#define MOD 1000000007
#define mem(name,value) memset(name,value,sizeof(name))
#define pi 3.14159265358979323846
#define IOS ios::sync_with_stdio(0);cin.tie(0);
typedef long long int ll;
using namespace std;
using namespace __gnu_pbds;
const int p1 = 31;

int main() { IOS

	//Use long long
    int n,k;
    cin>>n>>k;
    int a[n];
    int ans =0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];        
    }
    sort(a,a+n);
    for(int i=0;i<k;i++)
        ans+=a[i];
    cout<<ans;


 	return 0;
            
}

Measured memory_bytes: 3624
n, q = map(int, input().split())
s = input()

acc = [0] * (n+5)

for i in range(1, n):
    if s[i] == "C" and s[i-1] == "A":
        acc[i] = acc[i-1] + 1
    else:
        acc[i] = acc[i-1]
        
for i in range(q):
    r, l = map(int, input().split())
    print(acc[l - 1] - acc[r-1])

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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;


#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}
int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

vector<int> t, v;

double maxs(int i, int a, int b) {
    // printf("[%d %d %d]\n", i, a, b);
    if (a > v[i] || b > v[i]) return -1;
    int w = t[i];
    if (abs(a - b) > w) return -1;
    double m = 0.5 * (b - a + w);
    double h = a + m;
    // t:0 -> m -> w
    // v:a -> h -> b
    if (h <= v[i]) {
        double S = (0.5 * (a + h) * m) + (0.5 * (h + b) * (w - m));
        // cout << S << endl;
        return S;
    }
    else {
        double u1 = v[i] - a, u2 = v[i] - b, mid = w - (u1 + u2);
        // printf("w=%d, u1=%g, u2=%g, mid=%g\n", w, u1,u2,mid);
        double S = (0.5 * (a + v[i]) * u1) + (v[i] * mid) + (0.5 * (b + v[i]) * u2);
        // cout << S << endl;
        return S;
    }
}

double solve(int N) {
    vector<double> d(101, -1);
    d[0] = 0;

    rep(i, N) {
        vector<double> d2(101, -1);
        rep(a, 101) {
            if (d[a] < 0) continue;
            rep(b, 101) {
                double f = maxs(i, a, b);
                if (f < 0) continue;
                d2[b] = max(d2[b], d[a]+f);
            }
        }
        /// cout << i << d2 << endl;
        d = d2;
    }
    return d[0];
}


int main() {
    int N = loadint();
    t.resize(N); v.resize(N);
    loadvec(t, N);
    loadvec(v, N);
    double ans = solve(N);
    printf("%.6f\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,m[6],k[6][4]={0,1,5,4,0,3,5,2,0,2,5,3,0,4,5,1,1,2,4,3,1,3,4,2};
char r[6]={'N','E','W','S','R','L'};
int main(){
	while(true){
		cin>>n;
		if(!n)break;
		rep(i,6)m[i]=i+1;
		int ans=1,t,e;
		string s;
		rep(i,n){
			cin>>s;
			rep(j,6)if(r[j]==s[0])e=j;
			t=m[k[e][0]];
			rep(j,3)m[k[e][j]]=m[k[e][j+1]];
			m[k[e][3]]=t;
			ans+=m[0];
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 3172
#include <bits/stdc++.h>
typedef long long int LL;
using namespace std;

// 插入此處
namespace Number {
    typedef long long int LL;
    // 求取 a, b 的最大公因數
    LL gcd(LL a, LL b) {
        if (a % b == 0) {
            return b;
        }
        return gcd(b, a % b);
    }
    // 求取 a, b 的最大公因數 gcd
    // 以及 x, y 使得 a*x + b*y = gcd
    LL gcd_extend(LL a, LL b, LL *x, LL *y) { 
        if (a == 0) { 
            *x = 0, *y = 1; 
            return b; 
        } 
    
        LL x1, y1; // To store results of recursive call 
        LL gcd = gcd_extend(b%a, a, &x1, &y1); 
    
        *x = y1 - (b/a) * x1; 
        *y = x1; 
    
        return gcd; 
    }
    // 求 a_inv 使得 (a * a_inv) % m = gcd(a, m)
    // 若 a, m 互質，即求 a 在 mod m 群的反元素 a_inv 
    LL mod_inv(LL a, LL m) { 
        LL x, y; 
        LL g = gcd_extend(a, m, &x, &y); 
        // 處理 x 爲負的情形 
        LL a_inv = (x%m + m) % m; 
        return a_inv;
    }
    // 求 x^n % m
    LL mod_pow(LL x, LL n, LL m) {
        if (n == 0) {
            return 1;
        } else if (n & 1) {
            LL half = mod_pow(x, n/2, m);
            return (half * half % m) * x % m;
        } else {
            LL half = mod_pow(x, n/2, m);
            return half * half % m;
        }
    }
    // 連乘
    LL mul(LL from, LL to, LL m) {
        LL ret = 1;
        for (LL i = from; i <= to; i++) {
            ret *= i;
            ret %= m;
        }
        return ret;
    }
    // 求 (C n 取 k) % m
    LL mod_comb(LL n, LL k, LL m) {
        LL mi = k < n-k ? k : n-k;
        LL up = mul(n - mi + 1, n, m);
        LL down = mul(1, mi, m);
        return (up * mod_inv(down, m)) % m;
    }
}
  

const int MAXN = 100001 + 2;
const int MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s; cin >> s;
	int n = s.size();
	LL ans = 0;
	LL dp[MAXN];
	dp[0] = 1;
	dp[1] = 3;
	for (int i = 2; i < MAXN; ++i) {
		dp[i] = dp[i-1] * 3 % MOD;
	}
	int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		ans += (s[i] - '0') * dp[n-1-i] * Number::mod_pow(2, cnt, MOD) % MOD;
		ans %= MOD;
		if (s[i] == '1')  ++cnt;
	}
	ans += Number::mod_pow(2, cnt, MOD) % MOD;
	ans %= MOD;
	cout << ans << endl;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair <ll,ll> pii;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rept(i,x,y) for(int i=x;i<=y;i++)
#define per(i,x,y) for(int i=x;i>=y;i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define fi first
#define se second
#define mes(a,b) memset(a,b,sizeof a)
#define mp make_pair
#define dd(x) cout<<#x<<"="<<x<<" "
#define de(x) cout<<#x<<"="<<x<<"\n"
#define debug() cout<<"I love Miyamizu Mitsuha forever.\n"
const int inf=0x3f3f3f3f;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int ans;
	rept(i,1,5)
	{
		int x;
		cin>>x;
		if(!x) ans=i;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif
string s;
cin>>s;
int c=0;
if(s=="SSS"){
    cout<<c<<endl;
}else{
    c++;
    forn(i,0,2){
        if(s[i]=='R' && s[i+1]=='R') c++;
    }
    cout<<c<<endl;
}

}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int L, R, d;
  cin >> L >> R >> d;
  int ans = 0;
  for (int i = L; i <= R; ++i) {
    if (i%d==0) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3164
//2018.09.15 8min

#include <iostream>
using namespace std;

int main() {

    int N;
    cin >> N;

    int i,j,ans=0;
    int a[N];
    int exist[N];
    for(i=0;i<N;i++){
        cin >> a[i];
        exist[i]=0;
    }

    bool fast = true;
    for(i=0;i<N;i++){
        for(j=0;j<i;j++){
            if(a[i]==exist[j])fast=false;
        }
        if(fast){
            exist[i]=a[i];
            ans++;
        }
        fast=true;
    }

    cout << ans << endl;

    return 0;
}

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

#define MOD 998244353

string S, R;
long long two[200005];
long long dp[200005], fp[200005];

vector< pair<long long, long long> > X;

long long solve(int pos, int period)
{
    if(pos == period)
    {
        R.clear();

        for(int i=0; i<period; i++)
            R.push_back(S[i]);
        
        for(int i=period; i<S.size(); i++)
        {
            int x = R[i-period] - '0';
            x ^= 1;
            R.push_back((char)(x + '0'));
        }

        return (R <= S);
    }

    if(dp[pos] != -1)
        return dp[pos];
    
    long long ans = solve(pos + 1, period);

    if(S[pos] == '1')
        ans += two[period - pos - 1];

    return dp[pos] = ans % MOD;
}

long long func(int pos)
{
    if(pos == X.size())
        return 0;
    
    if(fp[pos] != -1)
        return fp[pos];
    
    long long ans = X[pos].second;

    for(int i=pos+1; i<X.size(); i++)
        if(X[i].first % X[pos].first == 0)
            ans += MOD - func(i);

    return fp[pos] = ans % MOD;
}

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

    int N;
    cin >> N >> S;

    two[0] = 1;

    for(int i=1; i<=N; i++)
        two[i] = two[i-1] * 2 % MOD;

    long long curr = 0, num = 0;

    for(int j=3; j<=N; j+= 2)
    {
        if(N % j)
            continue;
        
        int y = N / j;

        for(int i=0; i<=y; i++)
            dp[i] = -1;

        X.push_back({j, solve(0, y)});
    }

    memset(fp, -1, sizeof(fp));

    for(int i=0; i<X.size(); i++)
    {
        num += func(i);
        curr += func(i) * (N / X[i].first) * 2 % MOD;
    }

    long long ans = 0;

    for (auto s : S)
        ans = (ans * 2 + s - '0') % MOD;
    
    num %= MOD, curr %= MOD;
    ans = (ans + 1 - num + MOD) * N * 2 % MOD + curr;

    cout << ans % MOD << "\n";
    return 0;
}


Measured memory_bytes: 8724
#include<iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <limits>
using namespace std;

int main(){
  cout << fixed << setprecision(10);
  int a,b,h,m;
  cin>>a>>b>>h>>m;
  double H=h*30;
  double M=m*5.5;
  double theta;
  if(abs(H-M)<=180) theta=abs(H-M)/180*M_PI;
  else theta=(360-abs(H-M))/180*M_PI;
  double ans=a*a+b*b-2*a*b*cos(theta);

  double ans2=sqrt(ans);
  cout<<ans2<<endl;
  return 0;
}

Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class MainClass : Scanner
{
    static void Main()
    {
        int N = RInt();
        var a = RInts();
        var dp = new int[a.Max()+2];
        for (int i = 0; i < N; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (a[i] + j >= 0)
                {
                    dp[a[i] + j]++;
                }
            }
        }
        WriteLine(dp.Max());
    }
}

class Scanner
{
    public static int RInt() => int.Parse(Console.ReadLine());
    public static long RLong() => long.Parse(Console.ReadLine());
    public static string RString() => Console.ReadLine();
    public static double RDouble() => double.Parse(Console.ReadLine());

    public static int[] RInts() => Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
    public static int[] RInts(Func<string, int> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static long[] RLongs() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
    public static long[] RLongs(Func<string, long> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static double[] RDoubles() => Array.ConvertAll(Console.ReadLine().Split(), double.Parse);
    public static double[] RDoubles(Func<string, double> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static string[] RStrings() => Console.ReadLine().Split();
    //public static string[] RStrings(Func<string, string> func) => Console.ReadLine().Split().Select(func).ToArray();
    public static T1 ReadStream<T1>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        return r1;
    }
    public static (T1, T2) ReadStream<T1, T2>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        return (r1, r2);
    }
    public static (T1, T2, T3) ReadStream<T1, T2, T3>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        return (r1, r2, r3);
    }
    public static (T1, T2, T3, T4) ReadStream<T1, T2, T3, T4>()
    {
        var r = RStrings();
        var r1 = (T1)Convert.ChangeType(r[0], typeof(T1));
        var r2 = (T2)Convert.ChangeType(r[1], typeof(T2));
        var r3 = (T3)Convert.ChangeType(r[2], typeof(T3));
        var r4 = (T4)Convert.ChangeType(r[3], typeof(T4));
        return (r1, r2, r3, r4);
    }
}

Measured memory_bytes: 36392
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

int main(){
  int a,b,c,k; cin>>a>>b>>c>>k;
  
  
  
  if(k<=a) cout<<k;
  else if(k-a<=b) cout<<a;
  else cout<<a-(k-a-b);
  
  
  return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// gp_hash_table<int, int> mapka;

using namespace std;
#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define LD long double
#define FI first
#define SE second
#define st FI
#define nd SE
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

template<class C> void mini(C &a4, C b4) { a4 = min(a4, b4); }
template<class C> void maxi(C &a4, C b4) { a4 = max(a4, b4); }

template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}

template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int MAX = 401;
const int P = 998244353;
void add(int &a, int b){
  a += b;
  if(a >= P)
    a -= P;
}
int mul(int a,int b){
  return a * b % P;
}
int n;
int t[MAX];
int p2[MAX];
int dwu[MAX][MAX];
vector<int> licz(int po,int ko,int dod){
  if(po == ko)return {1};
  int gd = po;
  for(int i = po; i < ko; i++){
    if(t[gd] > t[i])
      gd = i;
  }
  vector<int> a = licz(po,gd,t[gd]);
  vector<int> b = licz(gd+1,ko,t[gd]);
  vector<int> res(ko-po+1);
  R(i,SZ(a))R(j,SZ(b)){
    add(res[i+j],mul(a[i],b[j]));
  }
  debug(res);
  R(_,t[gd] - dod){
    
    debug("-------------",_);
    vector<int> dp;
    dp.PB(1);
    for(int i = po; i < ko; i++){
      vector<int> ak(SZ(dp)+1);
      R(j,SZ(dp)){
        debug(t[i],t[gd],j,SZ(ak));
        add(ak[j], mul(dp[j], p2[t[i] - t[gd] + _] - 1));
        add(ak[j+1], dp[j]);
      }
      swap(ak, dp);
    }
    debug(dp);
    R(i,SZ(res))R(j,i+1){
      int mn = p2[ko-po-i];
      if(j == i) mn--;
      add(dp[j], mul(res[i], mul(mn, dwu[i][j])));
    }
    swap(res,dp);
    debug(res);
  }
  debug(po,ko,dod,res);
  return res;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  cerr << fixed << setprecision(6);
  cin >> n;
  R(i,n){
    cin >> t[i];
  }
  p2[0] = 1;
  R(i,MAX-1){
    p2[i+1] = p2[i];
    add(p2[i+1],p2[i]);
  }
  R(i,MAX)R(j,i+1){
    if(j == 0){
      dwu[i][j] = 1;
    }else{
      dwu[i][j] = dwu[i-1][j];
      add(dwu[i][j], dwu[i-1][j-1]);
    }
  }
  cout << licz(0,n,0)[0] << "\n";
}


Measured memory_bytes: 1664
using System;

class aaaa
{
    static void Main(String[] args){
        for(int i=1; i<=9; i++){
            for(int j=1; j<=9; j++){
                int ans = i*j;
                Console.WriteLine("{0}x{1}={2}",i,j,ans);
            }
        }
    }
};

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

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; ++i)
    {
        cin >> A[i];
    }

    long long money = 1000;
    long long stock = 0;
    bool is_down = true;
    for(int i = 0; i < N - 1; ++i)
    {
        if(is_down && (A[i] < A[i + 1]))
        {
            stock += money / A[i];
            money -= stock * A[i];
            is_down = false;
        }
        else if(!is_down && (A[i] > A[i + 1]))
        {
            money += stock * A[i];
            stock = 0;
            is_down = true;
        }
    }
    money += stock * A[N - 1];
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3600
function main(input) {
    const [n,k,q] = input.split('\n')[0].split(' ').map(v => parseInt(v, 10));
    const participants = [...Array(n)].fill(k - q);
    let questions = input.split('\n');
    questions.shift();
    questions.forEach(q => participants[q-1]++);
    participants.forEach(v => v > 0 ? console.log("Yes") : console.log("No"));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 49664
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    int x = sc.nextInt();
    if(k*500>=x){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 20052
#include<stdio.h>

int main(){
int N1=0,N2=0,M1=0,M2=0;
int A[5]={},B[5]={};

while(scanf("%d.%d %d.%d",&N1,&N2,&M1,&M2)!=EOF)
{
if(N1>=2)A[0]++;
else if(N1==1&&N2>=1)A[0]++;
else if(N1==1&&N2<1)A[1]++;
else if(N1==0&&N2>=6)A[1]++;
else if(N1==0&&N2>=2)A[2]++;
else if(N1==0&&N2<2)A[3]++;

if(M1>=2)B[0]++;
else if(M1==1&&M2>=1)B[0]++;
else if(M1==1&&M2<1)B[1]++;
else if(M1==0&&M2>=6)B[1]++;
else if(M1==0&&M2>=2)B[2]++;
else if(M1==0&&M2<2)B[3]++;
}
for(int i=0;i<4;i++)
printf("%d %d\n",A[i],B[i]);


return 0;
}

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

int main(void)
{
	int l, l1, n, m[300], m1[15], m2, m3=0, m4, n1=1, n2=3;
	scanf("%d", &l);
	while (n2<=l)
	{
		n2*=3;
		n1++;
	}
	for (int i = 0; i < n1-1; i++)
	{
		m[9*i]=n1-i;
		m[9*i+1]=n1+1-i;
		m[9*i+2]=0;
		m[9*i+3]=n1-i;
		m[9*i+4]=n1+1-i;
		m[9*i+5]=(int)pow(3,i);
		m[9*i+6]=n1-i;
		m[9*i+7]=n1+1-i;
		m[9*i+8]=(int)pow(3,i)*2;
	}
	for (int i = 0; i < 15; ++i)
	{
		m1[i]=0;
	}
	l1=l;
	m2=(int)pow(3,n1-1);
	for (int i = 0; i < n1; ++i)
	{
		while (l1>=m2)
		{
			m1[i+2]++;
			l1-=m2;
		}
		m2/=3;
	}
	m4=9*(n1-1);
	for (int i = 0; i < n1; ++i)
	{
		while (m1[n1+1-i]>0)
		{
			m[m4]=1;
			m[m4+1]=n1+1-i;
			m[m4+2]=m3;
			m4+=3;
			m3+=(int)pow(3,i);
			m1[n1+1-i]--;
		}
	}
	printf("%d %d\n", n1+1, m4/3);
	for (int i = 0; i < m4; i+=3)
	{
		printf("%d %d %d\n", m[i], m[i+1], m[i+2]);
	}
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

class VariableObj {

    // たこ焼きの数
    public static int num_tako;

}

public class Main {
    public static void main(String... args){

        // 入力の受け取り
        Scanner scanner = new Scanner(System.in);

        VariableObj.num_tako = scanner.nextInt();
        // 美味しさの数値
        ArrayList<Integer> arr_oishisa = new ArrayList<Integer>();
        for(int i = 0; i < VariableObj.num_tako; i++){
            arr_oishisa.add(scanner.nextInt());
        }

        // ２個選びその回復量を計算
        //      ansに蓄積していく
        long ans = 0;
        for(int i = 0; i < VariableObj.num_tako; i++){
            for(int j = i; j < VariableObj.num_tako; j++){
                // 同じもの同士はパス
                if (i == j){ continue;}
                ans += arr_oishisa.get(i) * arr_oishisa.get(j);
            }
        }
        
        System.out.println(ans);

    }
}


Measured memory_bytes: 20948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); i++)
int main()
{
    int x;
    cin >> x;
	
  	if(x == 5 || x == 7 || x == 3)
    	cout << "YES" << endl;
	else
        cout << "NO" << endl; 
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val a = Array(n) { sc.nextInt() }
    println(if (a.count { it % 2 == 1 } % 2 == 0) "YES" else "NO")
}

fun main() {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 48000
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

#define MOD 1000000007

int main() {
    int n;
    cin >> n;
    VI x(n), f(200100);
    VL a(n);
    REP(i,n){
        scanf("%d", &x[i]);
        x[i]--;
    }
    x[0] = 0;
    FOR(i,1,n-1){
        if (x[i-1] < x[i] - 1) x[i] = x[i-1] + 2;
    }
    REP(i,n) f[x[i]] = 1;
    // REP(i,2*n) cout << f[i];
    // cout << endl;
    int p = 0, q = 0;
    a[0] = 1;
    FOR(i,1,n-1){
        a[p]++;
        if (x[i-1] < x[i] - 2)
            x[i] -= q;
        else
            q = 0;
        // REP(j,n) cout << x[j] << " ";
        // cout << "   " << i << endl;
        if (x[i-1] == x[i] - 1){
            p++;
            q++;
            x[i]--;
        }
    }
    ll ans = 1, s = 0;
    REP(i,n){
        s += a[i];
        ans = (ans * s) % MOD;
        s--;
    }
    // REP(i,n) cout << a[i];
    // cout << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    ll A, B; cin >> A >> B;
    char C; cin >> C;
    int D; cin >> D;
    B *= 100; B += D;
    ll X = A*B; X /= 100;
    cout << X << nl;
	
	return 0;
}
 
 

Measured memory_bytes: 3644
let rec g a b = if b = 0 then a else g b (a mod b)
let f n = let rec f a c d m = if d > m || d * d > n then if c > 0 then (d, c) :: a else if m > 1 then (m, 1) :: a else a else if m mod d = 0 then f a (c + 1) d @@ m / d else f (if c > 0 then (d, c) :: a else a) 0 (d + 1) m in f [] 0 2 n
let _ = Scanf.scanf "%d %d" @@ fun a b -> List.(map (fun (p, _) -> p) @@ f (g a b) |> sort_uniq (-) |> length) |> succ |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(k,i,n) for(long long i=k;i<n;++i)
using namespace std;
typedef long long ll;
int main(void){
    // Your code here!
    ll N,K;
    cin>>N>>K;
    string S,A[N];
    cin>>S;
    rep(0,i,N)A[i]=S.substr(i,1);
    ll uc=0;
    rep(0,i,N){
        if(i==0){
            if(A[i]=="L"){
                ++uc;
            }else{
                if(A[i+1]=="L")++uc;
            }
        }else if(i==N-1){
            if(A[i]=="R")++uc;
            else if(A[i-1]=="R")++uc;
        }else{
            if(A[i]=="L"){
                if(A[i-1]=="R")++uc;
            }else if(A[i]=="R"){
                if(A[i+1]=="L")++uc;
            }
        }
    }
    rep(0,i,K){
        if(uc==2)--uc;
        else uc-=2;
        if(uc<1){
            uc+=2;
            break;
        }
    }
    cout<<N-uc<<endl;
}


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

typedef long long ll;
const ll INF = 1e9, MOD = 1e9 + 7;
const double EPS = 1e-9, PI = 3.141592653589793;
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define All(v) (v).begin(), (v).end()
#define Pb(i) push_back(i)

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

    ll a,b,x,ans=0;
    cin >> a >> b >> x;
    if(a==0) ans = b/x+1;
    else ans = b/x+1 - ((a-1)/x+1);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#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 all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = ~(1<<31);
const int MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};
 
class Comb{
private:
	vector<ll> fact;
	vector<ll> pow_mod;

public:
	Comb(int n){
		fact = vector<ll>(n+10);
		pow_mod = vector<ll>(n+10);
		for(int i = 0; i < n+10; i++) calc(i);
	}
	void calc(int i){
		if(i == 0) fact[i] = 1;
		else fact[i] = fact[i-1] * i % MOD;

		ll mod = MOD-2,res = 1,ti = i;
		while(mod > 0){
			if(mod&1) res = res*ti%MOD;
			ti = ti * ti % MOD;
			mod >>= 1;
		}
		if(i == 0) pow_mod[i] = 1;
		else pow_mod[i] = pow_mod[i-1]*res%MOD;
	}
	ll nCr(int n,int r){
		if(n < r) return 0;
		ll a1 = fact[n],a2 = pow_mod[n-r],a3 = pow_mod[r];
		return a1*a2%MOD*a3%MOD;
	}
};

int main(){
	int n,m,tmp;
	cin >> n >> m;

	map<int,int> mp;
	tmp = m;
	for(int i = 2; i * i <= m; i++){
		while(tmp%i == 0){
			mp[i]++;
			tmp /= i;
		}
	}
	if(tmp != 1) mp[tmp]++;

	ll ans = 1;
	Comb comb(n+100000);
	for(auto x: mp){
		ans *= comb.nCr(x.second-1+n,x.second);
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

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



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


    vector<long> h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
    }

    vector<int> result(n,0);
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(h.at(a-1)>h.at(b-1)){
            if(result.at(a-1)!=-1)
                result.at(a-1)=1;
            result.at(b-1)=-1;
        }else if(h.at(a-1)<h.at(b-1)){
            result.at(a-1)=-1;
            if(result.at(b-1)!=-1)
               result.at(b-1)=1;
        }else{
            result.at(a-1)=-1;
            result.at(b-1)=-1;
        }
    }

    int cnt=0;
    for(int i=0;i<n;i++){
        if(result.at(i)==0||result.at(i)==1)
            cnt++;
    }

    cout<<cnt<<endl;

    return 0;
}

Measured memory_bytes: 4580