akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <set>
#include <unordered_map>
#include <limits>
#include <iterator>
#include <sstream>

using namespace std;

unordered_map<string, int> memo;

int dfs(set<int> s, vector<pair<int, vector<int>>>& keys, vector<vector<int>>& candidates) {
    if (s.empty()) return 0;
    stringstream ss;
    copy(s.begin(), s.end(), ostream_iterator<int>(ss, "-"));
    if (memo.find(ss.str()) != memo.end()) {
        return memo[ss.str()];
    }

    int target = *s.begin();
    for (int n : s) {
        if (keys[n].second.size() > keys[target].second.size()) {
            target = n;
        }
    }
    int answer = numeric_limits<int>::max();
    for (int n : candidates[target]) {
        set<int> ss(s.begin(), s.end());
        for (int m : keys[n].second) {
            ss.erase(m);
        }
        answer = min(answer, keys[n].first + dfs(ss, keys, candidates));
    }
    memo[ss.str()] = answer;
    return answer;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<int, vector<int>>> keys;
    vector<vector<int>> candidates(n);
    vector<bool> f(n, false);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        vector<int> v;
        for (int j = 0; j < b; ++j) {
            int c;
            cin >> c;
            v.push_back(c - 1);
            candidates[c - 1].push_back(i);
            f[c - 1] = true;
        }
        keys.push_back({ a, v });
    }
    for (int i = 0; i < n; ++i) {
        if (!f[i]) {
            cout << -1 << endl;
            return 0;
        }
    }
    set<int> s;
    for (int i = 0; i < n; ++i) s.insert(i);
    cout << dfs(s, keys, candidates) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ls ch[x][0]
#define rs ch[x][1]
#define ll long long
using namespace std;

inline ll read(){
	ll num=0,neg=1;char c=getchar();
	while(!isdigit(c)){if(c=='-')neg=-1;c=getchar();}
	while(isdigit(c)){num=(num<<3)+(num<<1)+c-'0';c=getchar();}
	return num*neg;
}

const ll mod=1e9+7;
ll n,ans,fac[100010],inv[100010];

inline ll qpow(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1) res=res*x%mod;
		x=x*x%mod;k>>=1;
	}return res;
}

inline ll C(ll n,ll m){
	if(n==m||m==0) return 1;
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main(){
	n=read();fac[0]=1;
	for(int i=1;i<=2*n;i++) fac[i]=fac[i-1]*i%mod;
	inv[2*n]=qpow(fac[2*n],mod-2);
	for(int i=2*n-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
	for(int i=1;i<=n;i++){
		if(n/i<3) break;
		int tmp=n-3*i;
		ans=(ans+C(i+tmp-1,i-1))%mod;
	}cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3552
fn solve() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.vec(n);
    let mut cnt = 0;
    let mut b: Vec<i64> = a.iter().map(|&x| {
        if x <= 0 {
            cnt += 1;
            return x * -1;
        }
        x
    }).collect();
    b.sort();
    let mut res:i64 = b.iter().sum();
    if cnt % 2 == 0 {
        println!("{}", res);
        return;
    }

    res -= 2 * b[0];

    println!("{}", res);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(64 * 1024 * 1024) // 64MB
        .spawn(|| solve())
        .unwrap()
        .join()
        .unwrap();
}

//snippet from kenkoooo
pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self.stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


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

int main(){
	int N;
	cin>>N;
	int color[9]={0};
	int tmp;
	for(int i=0;i<N;++i){
		cin>>tmp;
		if(tmp<400)color[0]=1;
		else if(tmp<800)color[1]=1;
		else if(tmp<1200)color[2]=1;
		else if(tmp<1600)color[3]=1;
		else if(tmp<2000)color[4]=1;
		else if(tmp<2400)color[5]=1;
		else if(tmp<2800)color[6]=1;
		else if(tmp<3200)color[7]=1;
		else color[8]++;
	}
	int ansmax=0,ansmin=0;
	for(int i=0;i<9;++i){
		ansmax+=color[i];
		if(i!=8)ansmin+=color[i];
	}
	if(ansmin==0)ansmin=1;
	cout<<ansmin<<" "<<ansmax<<endl;
}


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

using namespace std;

string affine(string s, int alpha, int beta)
{
	string aff_str;	aff_str.clear();
	for (string::iterator it = s.begin(); it != s.end(); it++) {
		if ( *it == ' ' ) aff_str.push_back(' ');
		else {
			char c = *it - 'a';
			c = (alpha * c + beta) % 26;
			aff_str.push_back(c + 'a');
		}
	}
	return aff_str;
}

int gcd(int x, int y)
{
	if (x==0) return y;
	if (y==0) return x;
	if (y>x)  return gcd(x, y%x);
	return gcd(y, x%y);
}

bool isRelPrime(int x, int y)
{
	return gcd(x, y) == 1;
}

int main()
{
	string buf;
	int n;
	cin >> n;
	
	//char dummy;
	//cin >> dummy; // discard '\n' after the input of n
	
	cin.ignore();
	
	for (int i=0; i<n; i++) {
		buf.clear();
		getline(cin, buf);
		//cout << buf.size() << " " << buf << endl;
		bool success = false;
		for (int alpha = 1; alpha < 26; alpha++) {
			if ( !isRelPrime(alpha, 26) ) continue;
			for (int beta = 0; beta < 26; beta++) {
				string decoded = affine(buf, alpha, beta);
				//cout << decoded << endl;
				if ( (decoded.find("that") != string::npos) || (decoded.find("this") != string::npos) ) {
					cout << decoded << endl; success = true; break;
				}
			}
			if (success) break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 char a, b;
  cin >> a >> b;
  if (a == 'H') {
    if (b == 'H') {
      cout << "H" << endl;
    }
    else {
      cout << "D" << endl;
    }
  }
  else {
    if (b == 'H') {
      cout << "D" << endl;
    }
    else {
      cout << "H" << endl;
    }
  }
}

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	
	cin >>n;
	VI v(n);
	rep(i, n) cin >>v[i];
	sort(all(v));
	
	double ans = v[0];
	rep2(i,1,  n){
		ans = (ans + v[i]) /2.0;
	}
	printf("%.14f\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf INT_MAX
#define sc(a) scanf("%d",&a)
#define scc(a,b) scanf("%d %d",&a,&b)
#define sccc(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pf(a) printf("%d",a)
#define pff(a,b) printf("%d %d",a,b)
#define pfff(a,b,c) printf("%d %d %d",a,b,c)
#define pb(a) push_back(a)
#define em empty()
#define fr front()
#define cl clear()
#define sz size()
#define mp(a,b) make_pair(a,b)
#define fri(b) freopen(b,"r",stdin)
#define fro(b) freopen(b,"w",stdout)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
/*
ID: uslusam1
TASK: test
LANG: C++
*/
using namespace std;

int arr[100013][4];
int dp[100013][4];
 
int main(){
	//fri("a.txt");
	//fro("b.txt");
	int n;
	sc(n);
	for(int i=1;i<=n;i++){
		sccc(arr[i][1],arr[i][2],arr[i][3]);
	}
	dp[1][1]=arr[1][1];
	dp[1][2]=arr[1][2];
	dp[1][3]=arr[1][3];
	for(int i=2;i<=n;i++){
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+arr[i][1];
		dp[i][2]=max(dp[i-1][1],dp[i-1][3])+arr[i][2];
		dp[i][3]=max(dp[i-1][2],dp[i-1][1])+arr[i][3];
	}
	int ans=0;
	ans=max(dp[n][1],dp[n][2]);
	ans=max(ans,dp[n][3]);
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
struct Edge {
  ll to;
  ll cost;
};
int main() {
  char s;
  cin >> s;
  if (isupper(s)) {
    cout << "A" << endl;
  } else {
    cout << "a" << endl;
  }
}

Measured memory_bytes: 3628
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int a[100];
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  int cnt=0;
  for(i=0;i+1<n;i++){
    if(a[i]!=a[i+1]) continue;
    cnt++;
    i++;
  }
  printf("%d\n",cnt);
}

int main(void){
  run();
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#define FIN freopen("inputs.txt", "r", stdin)
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
#define f first
#define s second

int main(){
//FIN;
    string s, t;
    cin>>s>>t;
    cout<<(t+s)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

  


  int x,a,b,c;


  cin >> a;
  cin >> b;
  cin >> c;  
  cin >> x;
  // cout << x <<endl;
  // cout << a <<endl;
  // cout << b <<endl;

  x /= 50;
  
  int ret=0;
  for(int i=0; i<= a;i++){
    for(int j=0;j<=b;j++){
      for(int k=0;k<=c;k++){
        if(10*i+2*j+k == x){
          ret+=1;
        }
      }
    }
  }
  cout << ret <<endl;
}

// int dig(int remain){
//   int count = 0;
//   if(remain >=10){
//     dig(remain -10);
//   }else if (remain >= 2){
//     dig(remain -2);
//   }else{
//     count += 1;
//   }
//   return count;
// }

// int nokori10inai(int remain){
//   if (remain
// }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x,x2;
  cin>>x>>x2;
  cout<<abs(x-x2)<<'\n';
  return(0);
}



Measured memory_bytes: 3228
#include <bits/stdc++.h>
#pragma GCC optimization ("O3")
using namespace std;

#define ll              long long
#define ld              long double
#define pii             pair <int, int>
#define piii            pair <int, pii>
#define pll             pair <ll, ll>
#define plll            pair <ll, pll>

#define fa(i, n, N)     for (ll i = n; i <= N; i++)
#define fac(i, n, b, N) for (ll i = n; i <= N && b; i++)
#define fd(i, n, N)     for (ll i = n; i >= N; i--)

#define mp              make_pair
#define pb              push_back
#define pob             pop_back
#define pf              push_front
#define pof             pop_front
#define fi              first
#define se              second
#define pb              push_back

#define all(x)          x.begin(), x.end();
#define len             length()
#define endl            '\n'

#define db(x)           cerr << ">>>>>> " << #x << " -> " << x << endl

const ll inf = 1e9;
const ll MAX = 1e5+5;
const ll MOD = 1e9+7;
const double pi = acos(-1.0);
const double EPS = 1e-9;

void init (){
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
}

map <string, int> m;

int main() {

    m["SUN"] = 0;
    m["SAT"] = 6;
    m["FRI"] = 5;
    m["THU"] = 4;
    m["WED"] = 3;
    m["TUE"] = 2;
    m["MON"] = 1;

    init();
    string s;
    cin >> s;

    cout << 7-m[s] << endl;
}


Measured memory_bytes: 256
N=int(input())
A=[]

for i in range(N):
    A.append(int(input()))

A.sort()
if N%2==0:
    A1=A[0:N//2]
    A2=A[N//2:]
    ans=(2*sum(A2)-A2[0])-(2*sum(A1)-A1[-1])
else:
    A1=A[0:N//2]
    A2=A[N//2+1:]
    ans=(2*sum(A2)-A2[0])-(2*sum(A1)-A1[-1])
    add=max(A[N//2]-A1[-1],A2[0]-A[N//2])
    ans+=add
print(ans)


Measured memory_bytes: 7764
h,n=map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
dp = [1e9]*(h+1)
dp[h]=0
for i in range(h+1):
    now=h-i
    if dp[now]==1e9:
        continue
    for j in range(n):
        now2=max(now-a[j],0)
        dp[now2]=min(dp[now2],(dp[now]+b[j]))
print(dp[0])

Measured memory_bytes: 42716
#include <cstdio>
 
int main(){
    int n, i = 1;
    scanf(" %d", &n);
     
    while(i <= n){
        int x = i;
         
        if(x % 3 == 0) {
            printf(" %d", i);
        }
        else {
            while(x){
                if(x % 10 == 3){
                    printf(" %d", i);
                    break;
                }
                else x /= 10;
            }
        }
         
        ++i;
    }
    printf("\n");
 
    return 0;
}


Measured memory_bytes: 2756
using System;
using System.Linq;

namespace arc062_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            long[] hyou = new long[] { 1, 1 };
            for (int i = 0; i < n; i++)
            {
                long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
                long j = Math.Max((hyou[0] + x[0] - 1) / x[0], (hyou[1] + x[1] - 1) / x[1]);
                hyou[0] = x[0] * j; hyou[1] = x[1] * j;
            }
            Console.WriteLine(hyou.Sum());
        }
    }
}

Measured memory_bytes: 13396
module.exports=function(e){var n={};function r(t){if(n[t])return n[t].exports;var o=n[t]={i:t,l:!1,exports:{}};return e[t].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=e,r.c=n,r.d=function(e,n,t){r.o(e,n)||Object.defineProperty(e,n,{enumerable:!0,get:t})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,n){if(1&n&&(e=r(e)),8&n)return e;if(4&n&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(r.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&n&&"string"!=typeof e)for(var o in e)r.d(t,o,function(n){return e[n]}.bind(null,o));return t},r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,"a",n),n},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.p="",r(r.s=0)}([function(e,n,r){r(1)(r(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,n,r){"use strict";e.exports=function(e){for(var n=e[0],r=n.length,t=new Map,o=0;o<r;o++)t[n[o]]||(t[n[o]]=0),t[n[o]]++;var u=0,i=0,l=0;for(var f in t){if(l>2)return void console.log("No");0==l&&(u=t[f]),1==l&&(i=t[f]),l++}2==l&&u==i?console.log("Yes"):console.log("No")}},function(e,n){e.exports=require("fs")}]);

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

#define all(a)                      a.begin(), a.end()
#define pb                          push_back
#define ll							long long
#define index(a)            		order_of_key(a)
#define value(a)					find_by_order(a)
#define count_1 					__builtin_popcount
#define mod(x, m)					((((x) % (m)) + (m)) % (m))
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
int dp[3003][3003];
string a,b,ans="";

void pr(int i,int j){
	if(i<=0 || j<=0)return ;
	
	if(a[i-1]==b[j-1]){
		ans=a[i-1]+ans;
		pr(i-1,j-1);
	}
	else if(dp[i-1][j] > dp[i][j-1]){
		pr(i-1,j);
	}
	else pr(i,j-1);
}
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	cin>>a>>b;
	
	for(int i=0;i<=a.size();i++){
		for(int j=0;j<=b.size();j++){
			if(i==0 || j==0){
				dp[i][j]=0;
			}
			else if(a[i-1]==b[j-1])
				dp[i][j]=1+dp[i-1][j-1];
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
	
	pr(a.size(),b.size());
	
	cout<<ans;
	return 0;
}

Measured memory_bytes: 35968
#include<iostream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s, t;
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    int n, res = 2000;
    cin >> n >> s >> t;
    res = s.size() + t.size();
    rep(i, n)if(s.substr(n - i - 1, i + 1) == t.substr(0, i + 1))
    res = min(res, n + n - i - 1);

    pri(res);


/*/

//*/ break;
  }
  return 0;
}


Measured memory_bytes: 256
N = int(input())
Wlist = list(map(int, input().split()))

min_diff = 10000000000
for t in range(N):
    S1 = sum(Wlist[:t + 1])
    S2 = sum(Wlist[t + 1:])
    min_diff = min(min_diff, abs(S2 - S1))

print(min_diff)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int ans1=0,ans2=0;
const int N=1e5+5;
int arr[N];
int knapSack(int W, int wt[], int val[], int n)
{
    int i, w;
    int K[n+1][W+1];

    for (i = 0; i <= n; i++)
    {
        for (w = 0; w <= W; w++)
        {
            if (i==0 || w==0)
                K[i][w] = 0;
            else if (wt[i-1] <= w)
                K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]],  K[i-1][w]);
            else
                K[i][w] = K[i-1][w];
        }
    }

//    for(i=0;i<=n;i++){
//        for(w=0;w<=W;w++){
//            cout<<K[i][w]<<" ";
//        }
//        cout<<endl;
//    }

    return K[n][W];
}
signed main()
{

    int n,w;
    cin>>n>>w;

    int wt[n],val[n];
    for(int i=0;i<n;i++){

        cin>>wt[i]>>val[i];
    }

    cout<<knapSack(w,wt,val,n)<<endl;




    return 0;
}

Measured memory_bytes: 79104
#include <iostream>
#include <utility>

using namespace std;

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

  int minN = 1;
  int maxN = N;
  
  for (int m=1; m<=M; ++m) {
    int L, R;
    cin >> L >> R;
    minN = max(minN,L);
    maxN = min(maxN,R);
  }

  cout << max(maxN - minN +1, 0) << endl;
    
  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL k,x;
  cin >> k >> x;
  REP(i,k*2-1) {
    if(i) cout << " ";
    cout << x-k+1+i;
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	string s;
	cin >> s;
	if (s[a] == '-') {
		s[a] = '1';
	}
	else {
		s[a] = 'k';
	}
	//cout << s;
	for (int i = 0; i < a + b + 1; i++) {
		if (!('0' <= s[i] && s[i] <= '9')) {
			cout << "No" << endl; break;
		}
		else if (i == a + b) {
			cout << "Yes" << endl;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int t[33]={-777,1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  scanf("%d",&k);
  printf("%d\n",t[k]);
  return 0;
}


Measured memory_bytes: 1732
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

const int maxn = 2e5 + 5;
const int64 md = 1e9 + 7;
int n;
vector <int> e[maxn];
int64 f[maxn], cnt[maxn], res[maxn], fac[maxn], p[maxn];

void input(){
    cin >> n;
    int u, v;
    for (int i = 1; i < n; i++){
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
}

int64 pw(int64 a, int64 b){
    if (b == 0) return 1;
    int64 tmp = pw(a, b / 2);
    tmp = (tmp * tmp) % md;
    if (b % 2) tmp = (tmp * a) % md;
    return tmp;
}

int64 calcC(int n, int k){
    return (((fac[n] * pw(fac[n - k], md - 2)) % md) * pw(fac[k], md - 2)) % md;
}

void dfs1(int u){
    for (int v : e[u])
    if (v != p[u]){
        p[v] = u;
        dfs1(v);
        cnt[u] += cnt[v];
    }
    int tmp = cnt[u];
    f[u] = 1;
    for (int v : e[u])
    if (v != p[u]){
        f[u] = (((f[u] * calcC(tmp, cnt[v])) % md) * f[v]) % md;
        tmp -= cnt[v];
    }
    cnt[u]++;
}

void dfs2(int u, int64 curf){
    res[u] = (((curf * calcC(n - 1, n - cnt[u])) % md) * f[u]) % md;
    for (int v : e[u])
    if (v != p[u]){
        int64 tmp = (res[u] * pw(calcC(n - 1, cnt[v]), md - 2)) % md;
        tmp = (tmp * pw(f[v], md - 2)) % md;
        dfs2(v, tmp);
    }
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    input();
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = (fac[i - 1] * i) % md;
    dfs1(1);
    dfs2(1, 1);
    for (int i = 1; i <= n; i++) cout << res[i] << endl;
    return 0;
}


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

using namespace std;

int main()
{
	char s[100100];
	scanf("%s", s);
	int len = strlen(s);
	int ans = 0;
	for(int i = len - 1; i > 0; i--)
	{
		if( s[i] != s[i-1])
			ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

int judge(int n)
{
  if(n<2)return 0;
  if(n==2)return 1;
  if(n%2==0)return 0;
  for(int i=3;i<=n/i;i+=2){
    if(n%i==0)return 0;
  }
  return 1;
}
int main()
{
  int m,a,b,prime[10000],n=0,p,q;
  double ab;
  for(int i=0;i<10000;i++){
    if(judge(i))prime[n++]=i;
  }
  while(1){
    cin>>m>>a>>b;
    if(m==0&&a==0&&b==0)break;
    ab=(double)a/b;
    p=1;q=1;
    for(int i=0;i<n;i++){
      for(int j=i;prime[i]*prime[j]<=m;j++){
	if(prime[i]*prime[j]>p*q && ab <=(double)prime[i]/prime[j]){
	  p=prime[i];
	  q=prime[j];
	}
      }
    }
    cout<<p<<" "<<q<<endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;

typedef pair<int, int> P;
vector<vector<int> > dp(3005, vector<int>(6005, 0));
vector<P> menus;
int ans;
int N, T;
int cnt;
void func(int i, int t, int score) {
  if (dp[i][t] >= score) return;
  if (t < 0) {
    //dp[i][3004] = max(dp[i][3004], score);
    _max(ans, score);
    return;
  }
  cnt ++;
  dp[i][t] = score;
  _max(ans, score);
  if (i == N) return;
  if (t != 0) {
    func(i + 1, t, score);
    func(i + 1, t - menus[i].first, score + menus[i].second);
  }
}

int main() {
  cin >> N >> T;
  menus.push_back(P(0, 0));
  P max_pair = P(0, 0);
  rep(i, N) {
    int A, B;cin >> A >> B;
    menus.push_back(P(A, B));
  }
  sort(menus.begin(), menus.end());
  int ans = 0;
  rep1(i, N) {
    int A = menus[i].first,  B = menus[i].second;
    // cout << A << " " << B << endl;
    rep1(t, T + 3001) {
      if (t - A < 0) {
        dp[i][t] = dp[i - 1][t];
      } else if (t - A < T) {
        dp[i][t] = max(dp[i - 1][t], dp[i - 1][t - A] + B);
      } else {
        dp[i][t] = max(dp[i][t - 1], dp[i-1][t]);
      }
      _max(ans, dp[i][t]);
    }
  }
   cout << ans << endl;
  return 0;
}



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

using namespace std;
 
int ctoi(const char c){
  switch(c){
    case '0': return 0;
    case '1': return 1;
    case '2': return 2;
    case '3': return 3;
    case '4': return 4;
    case '5': return 5;
    case '6': return 6;
    case '7': return 7;
    case '8': return 8;
    case '9': return 9;
    default : return -1;
  }
}

int main() {
  std::string a;
  cin >> a;
    
  char cary[10]; 
  a.copy(cary, 10);
  
  std::string str("");
  for (int i=0;i<10;i++){
    if (i != 4) {
      if (i != 7){
        str += cary[i];
      }
    }
  }
  
  int num = atoi(str.c_str());
  if(num>20190430){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		 while(true) {
		 int n=sc.nextInt();
		 int x=sc.nextInt();
		 if(n==0 && x==0) break;
		 int s=0;
		 for(int i=1;i<=n;i++) {
			 for(int j=i+1;j<=n;j++) {
				 for(int k=j+1;k<=n;k++) {
					 if(i+j+k==x)s++;
				 }
			 }
		 }
		 System.out.println(s);
}		 sc.close();
	 }
}



Measured memory_bytes: 26752
from bisect import bisect

x, n = map(int, input().split())
ls = list(map(int, input().split()))
mx = [True] * 101
for i in ls:
	mx[i - 1] = False
r = x - 1
ans1 = 101
ans2 = 0
while r < 100:
	if mx[r]:
		ans1 = r + 1
		break
	r += 1
l = x - 1
while l >= 0:
	if mx[l]:
		ans2 = l + 1
		break
	l -= 1

if x - ans2 < ans1 - x:
	print(ans2)
elif x - ans2 > ans1 - x:
	print(ans1)
else:
	print(ans2)


Measured memory_bytes: 9212
def main():
    X, N = map(int, input().split())
    P = set(map(int, input().split()))
    for i in range(51):
        if X - i not in P:
            print(X-i)
            return
        if X + i not in P:
            print(X+i)
            return


if __name__ == "__main__":
    main()


Measured memory_bytes: 61772
program main
 implicit none
 integer n,i,j,k,ans
 character*200000 C
 read(*,*) n
 read(*,*) c
 
 ans = 0
 k = n
 do i=1,n
   if(i >= k)then
     exit
   end if
   if(C(i:i)=='W')then
     do j=k,1,-1
       if(C(j:j)=='R')then
         C(i:i)='R'
         C(j:j)='W'
         k=j-1
         ans = ans + 1
         exit
       end if
       if(j<=i)then
         k = j
         exit
       end if
     end do
   end if
 end do
 
 write(*,*) ans
end program main

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

int main()
{
  string a,b;
  cin >> a >> b;
  
  int lena = a.size();
  int lenb = b.size();
  if(lena > lenb){
    cout << "GREATER" << endl;
    return 0;
  }else if(lena < lenb){
    cout << "LESS" << endl;
    return 0;
  }
  
  if(a > b){
    cout << "GREATER" << endl;
  }else if(a < b){
    cout << "LESS" << endl;
  }else{
    cout << "EQUAL" << endl;
  }
}

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

#define fio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define int long long 

using namespace std;

int32_t main()
{
	fio;
	int n;
	cin>>n;
	int sum=n*(n+1)/2;
	int div3=n/3;
	int sum3=(div3*(2*3+(div3-1)*3))/2;

	sum-=sum3;

	int div5=n/5;
	int sum5=(div5*(2*5+(div5-1)*5))/2;

	sum-=sum5;

	int div15=n/15;
	int sum15=(div15*(2*15+(div15-1)*15))/2;

	sum+=sum15;

	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3664
n, q = [parse(Int, x) for x in split(chomp(readline()))]
str = readline() |> chomp

ac = zeros(Int, n)
count = 0
for i = 1:n-1
    if str[i] == 'A' && str[i+1] == 'C'
        count += 1
    end
    ac[i+1] = count
end

val = zeros(Int, q)

for i = 1:q
    l, r = [parse(Int, x) for x in split(chomp(readline()))]
    val = ac[r] - ac[l]
    println(val)
end

Measured memory_bytes: 156576
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int inf = 1012345678;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<long long> SA(N + 1), SB(N + 1);
	for (int i = 0; i < N; ++i) {
		SA[i + 1] = SA[i] + A[i];
		SB[i + 1] = SB[i] + max(A[i], 0);
	}
	long long ans = 0;
	for (int i = 0; i <= N - K; ++i) {
		long long preval = SB[i] + (SB[N] - SB[i + K]);
		ans = max(ans, preval + max(SA[i + K] - SA[i], 0LL));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2176
N,M = map(int,input().split())
Xi = list(map(int,input().split()))

Xi.sort()

Li = [Xi[i] - Xi[i-1] for i in range(1,len(Xi))]
Li.sort()

if N == M or N > M:
    print(0)
else:
    for _ in range(N-1):
        Li.pop(-1)
    print(sum(Li))

Measured memory_bytes: 13968
a,b,c,d = map(int,input().split())

l1 = [a,b]
l2 = [c,d]

if(a<0 and 0<b):
    l1.append(0)
if(c<0 and 0<d):
    l2.append(0)

l = []
for x in l1:
    for y in l2:
        l.append(x*y)

print(max(l))




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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int n,k;
    cin>>n>>k;

    int ans=0;

    while(n>0){
        ans++;
        n/=k;
    }

    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)

	A := float64(a)
	B := float64(b)
	C := float64(c)

	S := A * math.Sin(C*math.Pi/180) * B / 2
	L := math.Sqrt(A*A+B*B-2*A*B*math.Cos(C*math.Pi/180)) + A + B
	fmt.Printf("%f\n", S)
	fmt.Printf("%f\n", L)
	fmt.Printf("%f\n", B*math.Sin(C*math.Pi/180))
}



Measured memory_bytes: 1140
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N = inp()

a = inlist()
a = sorted(a)
st = 3*N - 1
wk = 0
res = 0
for i in range(N):
    chosen = st - 1
    res += a[chosen]

    wk += 1
    st -= 2

print(res)


Measured memory_bytes: 37084
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

typedef long long ll;

const int maxn = 100010;
const int maxm = 200010;

struct Edge {
    int v, w, x;
} E[maxm*2];

int n, m, e;
int l[maxn], vis[maxn];
ll dis[maxn];

ll mind = 0, maxd = 0;

void init() {memset(l, -1, sizeof(l)); e = 0;}

inline void insert(int u, int v, int w) {E[e].v = v, E[e].x = l[u], E[e].w = w, l[u] = e++;}

ll delta[maxn];
int col[maxn];

void dfs(int u, ll d, int c) {
    if (vis[u]) return;
    vis[u] = 1; dis[u] = d; mind = min(mind, d); maxd = max(maxd, d); col[u] = c;
    for (int p = l[u]; p >= 0; p = E[p].x) {
        dfs(E[p].v, d+E[p].w, c);
    }
}

int main() {
    init();
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        int L, R, D;
        scanf("%d%d%d", &L, &R, &D);
        insert(L, R, D);
        insert(R, L, -D);
    }
    for (int i = 1; i <= n; i++) {
        if (!vis[i]) {
            dfs(i, 0, i);
            if (maxd-mind > (1e9)) {
                printf("No\n");
                return 0;
            }
            delta[i] = -mind;
        }
    }
    for (int i = 1; i <= n; i++) dis[i] += delta[col[i]];
    for (int i = 0; i < e; i++) {
        int u = E[i^1].v, v = E[i].v, w = E[i].w;
        if (dis[v]-dis[u] != w) {
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 8704
S = input()
res = [0]*(len(S)+1)

for i in range(len(S)):
  if S[i]=='<':
    res[i+1]=res[i]+1
for i in range(len(S)-1,-1,-1):
  if S[i]=='>':
    res[i]=max(res[i],res[i+1]+1)

print(sum(res))

Measured memory_bytes: 46320
#include <bits/stdc++.h>
using namespace std;
int main() {
    int  s;
    cin >> s;
    int count=0;
    int count5=0;
    while(s>4){
        while(s>499){
            s=s-500;
            count++;
        }
        if(s>0){
        s=s-5;
        count5++;}
        else break;
    }
    int sum=count*1000+count5*5;
    cout <<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"
 
int main() 
{
    FAST;
    ve<ll> v;
    map<ll,ll> m;
    for(ll i=0;i<130;i++)
    {
        v.pb(i*i*i*i*i);
        m[i*i*i*i*i]=i;
    }
    ll x;
    cin>>x;
    if(m[x]!=0)
    {
        cout<<m[x]<<' '<<0;
        return 0;
    }
    for(int i=0;i<130;i++)
    {
        if(m[x+v[i]]!=0)
        {
            cout<<m[x+v[i]]<<' '<<i;
            return 0;
        }
        if(m[x-v[i]]!=0)
        {
            cout<<m[x-v[i]]<<' '<<(-i);
            return 0;
        }
    }
    subt;
    return 0;
}

Measured memory_bytes: 3640
#!/usr/bin/env python3
import sys
from bisect import bisect_left
INF = float("inf")


def solve(N: int, A: "List[int]", B: "List[int]", C: "List[int]"):
    A.sort()
    B.sort()
    C.sort()
    count = 0
    for b in B:
        countA = bisect_left(A, b)
        countC = N-bisect_left(C, b+1)
        count += countA*countC
    print(count)

    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    B = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    C = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A, B, C)


if __name__ == '__main__':
    main()


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

using namespace std;
typedef long long ll;
const int H = 10, W = 1000;
char s[H][W];

int main() {
    int h, w, k;
    scanf("%d%d%d", &h, &w, &k);
    for (int i = 0; i < h; i++) {
        scanf("%s", s[i]);
    }
    int ans = 1e8;
    for (int m = 0; m < (1 << (h - 1)); m++) {
        int cur = __builtin_popcount(m), sz = cur + 1;
        vector<int> sum(sz), add(sz);
        bool mask_invalid = 0;
        for (int j = 0; j < w; j++) {
            bool border_req = 0;
            for (int i = 0, d = 0; i < h; i++) {
                add[d] += s[i][j] - '0';
                if (add[d] > k) {
                    mask_invalid = 1;
                    break;
                }
                if (sum[d] + add[d] > k) border_req = 1;
                if ((1 << i) & m) d++;
            }
            if (mask_invalid) break;
            if (border_req) cur++;
            for (int d = 0; d < sz; d++) {
                if (border_req) {
                    sum[d] = add[d];
                } else {
                    sum[d] += add[d];
                }
                add[d] = 0;
            }
        }
        if (!mask_invalid)
            ans = min(cur, ans);
    }
    printf("%d\n", ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
typedef long long ll;
int modpow(int x,int y,int md=mod){if(y==0)return 1;int ret=modpow(x,y>>1,md);ret=(ll)ret*ret%md;if(y&1)ret=(ll)ret*x%md;return ret;}
int n,k;
int v[105];
vector<int>tmp;
int main(){
	cin>>n>>k;
	int best=0;
	for(int i=1;i<=n;i++)cin>>v[i];
	for(int take=0;take<=min(n,k);take++){
		for(int left=0;left<=take;left++){
			int right=take-left;
			tmp.clear();
			for(int i=1;i<=left;i++)tmp.push_back(v[i]);
			for(int i=n;i>n-right;i--)tmp.push_back(v[i]);
			sort(tmp.begin(),tmp.end());
			reverse(tmp.begin(),tmp.end());
			int thr=k-take;
			for(int i=0;i<thr;i++){
				if(tmp.size()&&tmp.back()<0)tmp.pop_back();
			}
			int res=0;
			for(auto x:tmp)res+=x;
			best=max(best,res);
		}
	}
	cout<<best<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define SIZE 100333
#define MOD 1000
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef vector<vector<long long> > mat;

char str1[100111], str2[100111];
ll p1bc[100111], p1ac[100111], p2ac[100111], p2bc[100111], q;

pair<ll,ll> getNorm(ll ac, ll bc) {
	ac %= 3LL, bc %= 3LL;
	// if(ac == 0 && bc == 0)	return {0,0};
	// if(ac == 1 && bc == 0)	return {1,0};
	// if(ac == 2 && bc == 0)	return {0,1};
	// if(ac == 0 && bc == 1)	return {0,1};
	// if(ac == 1 && bc == 1)	return {0,0};
	// if(ac == 2 && bc == 1)	return {1,0};
	// if(ac == 0 && bc == 2)	return {1,0};
	// if(ac == 1 && bc == 2)	return {0,1};
	// if(ac == 2 && bc == 2)	return {0,0};



	while(ac + bc >= 2) {
		if(ac == 2)	ac-=2, bc++;
		if(bc == 2)	bc-=2, ac++;
		if(ac == 1 && bc == 1)	ac = 0, bc = 0;
		ac%=3LL, bc%=3LL;
		// printf("LOOP %lld %lld\n",ac,bc);
	}
	return {ac,bc};
}

int main () {
	scanf("%s",str1);
	scanf("%s",str2);
	scanf("%lld",&q);
	if(str1[0] == 'A')	p1ac[0] = 1;
	else			p1bc[0] = 1;
	if(str2[0] == 'A')	p2ac[0] = 1;
	else			p2bc[0] = 1;
	ll len = strlen(str1);
	for(int i=1;i<len;i++) {
		p1ac[i] = p1ac[i-1], p1bc[i] = p1bc[i-1];
		if(str1[i] == 'A')	p1ac[i]++;
		if(str1[i] == 'B')	p1bc[i]++;
	}	
	len = strlen(str2);
	for(int i=1;i<len;i++) {
		p2ac[i] = p2ac[i-1], p2bc[i] = p2bc[i-1];
		if(str2[i] == 'A')	p2ac[i]++;
		if(str2[i] == 'B')	p2bc[i]++;
	}


	for(int i=0;i<q;i++) {
		ll a,b,c,d;
		scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
		ll ac,bc,cc,dc, a2c,b2c,c2c,d2c;
		if(a == 1)	ac = 0, cc = 0;
		else		ac = p1ac[a-2], cc = p1bc[a-2];

		bc = p1ac[b-1];
		dc = p1bc[b-1];



		if(c == 1)	a2c = 0, c2c = 0;
		else		a2c = p2ac[c-2], c2c = p2bc[c-2];

		b2c = p2ac[d-1];
		d2c = p2bc[d-1];

		pair<ll, ll> chk1 = getNorm(bc-ac,dc-cc), chk2 = getNorm(b2c-a2c,d2c-c2c);
		// printf("i %d (%lld %lld) (%lld %lld)\n",i,chk1.fi,chk1.se,chk2.fi,chk2.se);
		// printf("origin %lld, %lld   %lld, %lld\n",bc-ac,dc-cc,b2c-a2c,d2c-c2c);
		// printf("%lld - %lld\n",dc,bc);
		if(chk1 == chk2)	printf("YES\n");
		else			printf("NO\n");
	}
}

Measured memory_bytes: 3840
import java.io.PrintWriter;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] cnt = new int[N];
		for(int i=0; i<N; i++) {
			A[i] = sc.nextInt()-1;
			cnt[A[i]]++;
		}
		
		long total = 0;
		for(int i=0; i<N; i++) {
			if(cnt[i]>=2) {
				total += (long)cnt[i]*(cnt[i]-1)/2;
			}
		}
		
		for(int i=0; i<N; i++) {
			long ans = total - (cnt[A[i]]>=2 ? cnt[A[i]]-1 : 0);
			pw.println(ans);
		}
		
		pw.close();
		sc.close();
	}
}


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

int main() {
  LL n, m;
  cin >> n >> m;
  LL div = 1000000007;

  if (abs(n - m) > 1) {
    cout << 0 << endl;
    return 0;
  } else {
    LL facN = 1, facM = 1;
    for (int i = 2; i <= n; i ++) {
      facN *= i;
      facN %= div;
    }
    for (int i = 2; i <= m; i ++) {
      facM *= i;
      facM %= div;
    }

    if (n == m) {
      cout << (facN * facM * 2) % div << endl;
      return 0;
    } else {
      cout << (facN * facM) % div << endl;
      return 0;
    }
  }
}


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

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

    bool can_divide = true;
    int ans = X - 1;

    while (can_divide == true)
    {
        can_divide = false;
        ans++;
        for (int d = 2; d <= pow(ans, 0.5); d++)
        {
            if (ans % d == 0)
            {
                can_divide = true;
                break;
            }
        }
    }

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

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

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string str;
	while (cin >> str)
	{
		putchar(toupper(str[0]));
	}
	puts("");
	return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 166F.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP        PIC  X(40).
01 S1         PIC  X(02).
01 S2         PIC  X(02).
01 N          PIC  9(06) COMP.
01 TBL.
   03 ABC     PIC  9(10) COMP OCCURS 3.
01 TBL1.
   03 O       PIC  X(01) OCCURS 100000.
01 I          PIC  9(6) COMP.
01 J1         PIC  9.
01 J2         PIC  9.
01 J3         PIC  9.
01 J4         PIC  9.
01 C-ABC      PIC  X(3) VALUE 'ABC'.
01 OUT        PIC  X(3).
*> 
PROCEDURE DIVISION.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ' '
       INTO N ABC(1) ABC(2) ABC(3).
*>
  MOVE 'Yes' TO OUT.
  ACCEPT S1.
  PERFORM VARYING I FROM 1 BY 1 UNTIL I > N OR OUT = 'No '
    IF (I = N) 
       MOVE '  ' TO S2
    ELSE
      ACCEPT S2
    END-IF
*>
    EVALUATE S1(1:1)
      WHEN 'A'  MOVE 1 TO J1
      WHEN 'B'  MOVE 2 TO J1
    END-EVALUATE
    EVALUATE S1(2:1)
      WHEN 'B'  MOVE 2 TO J2
      WHEN 'C'  MOVE 3 TO J2
    END-EVALUATE
*>
    EVALUATE TRUE
      WHEN (ABC(J1) = 0) AND (ABC(J2) = 0)
        MOVE 'No ' TO OUT
      WHEN (ABC(J1) < ABC(J2))
        CONTINUE
      WHEN (ABC(J1) > ABC(J2))
        MOVE J2    TO J3
        MOVE J1    TO J2
        MOVE J3    TO J1
      WHEN (ABC(J1) = 1) AND (ABC(J2) = 1)
        EVALUATE S2(1:1)
          WHEN 'A'  MOVE 1 TO J3
          WHEN 'B'  MOVE 2 TO J3
        END-EVALUATE
        EVALUATE S2(2:1)
          WHEN 'B'  MOVE 2 TO J4
          WHEN 'C'  MOVE 3 TO J4
        END-EVALUATE
*>
        EVALUATE TRUE            
          WHEN (J1 = J3)
          WHEN (J1 = J4)
            CONTINUE
          WHEN (J2 = J4)
            MOVE J1 TO J2
            MOVE J4 TO J1
          WHEN OTHER
            MOVE J1 TO J2
            MOVE J3 TO J1
        END-EVALUATE
      WHEN OTHER
        CONTINUE
    END-EVALUATE
*>
    ADD      1 TO   ABC(J1)
    SUBTRACT 1 FROM ABC(J2)
    MOVE C-ABC(J1:1) TO O(I)
    MOVE S2 TO S1
  END-PERFORM.
*>
  DISPLAY FUNCTION TRIM(OUT).
  IF (OUT = 'Yes')
    PERFORM VARYING I FROM 1 BY 1 UNTIL I > N
      DISPLAY O(I)
    END-PERFORM
  END-IF.
*>
  STOP RUN.


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

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int[] array = new int[3];
        array[0] = a;
        array[1] = b;
        array[2] = c;
        Arrays.sort(array);
        for(int i = 0; i < 3; i++){
           if(i < 2){
               System.out.print(array[i] + " ");
              }else{
               System.out.print(array[i]);
              }
        }  
        System.out.println();
        scanner.close();
    }
}


Measured memory_bytes: 26428