akhauriyash/Code-Regression huggingface dataset:
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define mkp(a,b) make_pair(a,b)
const long long MOD = 1000000007;
const long long inf = 1ll<<61;
typedef pair<int, int> P;
typedef pair<int ,P> PP;
struct edge { int to; int to2; int cost; };
int x[55], y[55];
int a[100006];
int modpow(int x, int n, int mod) {
	if (!n)return 1;
	int res = modpow(x*x%mod, n / 2, mod);
	if (n & 1)res = res*x%mod;
	return res;
}
int dp1[10006],dp2[25200005];
signed main() {
	int n; cin >> n;
	int ga, sa, ba, gb, sb, bb; cin >> ga >> sa >> ba >> gb >> sb >> bb;
	
	rep(i, n) {
		dp1[i + ga] = max(dp1[i + ga], dp1[i] + gb);
		dp1[i + sa] = max(dp1[i + sa], dp1[i] + sb);
		dp1[i + ba] = max(dp1[i + ba], dp1[i] + bb);
	}
	rep(i, n) {
		dp1[n] = max(dp1[n], dp1[i] + n - i);
	}
	//cout << dp1[n] << endl;
	rep(i, dp1[n]) {
		dp2[i + gb] = max(dp2[i + gb], dp2[i] + ga);
		dp2[i + sb] = max(dp2[i + sb], dp2[i] + sa);
		dp2[i + bb] = max(dp2[i + bb], dp2[i] + ba);
	}
	rep(i, dp1[n]) {
		dp2[dp1[n]] = max(dp2[dp1[n]], dp2[i] + dp1[n] - i);
	}
	cout << dp2[dp1[n]] << endl;
}

Measured memory_bytes: 196992
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var array = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = new int[N];
            for (var i = 0; i < N; i++)
            {
                ans[i] = array[i] - i;
            }

            Array.Sort(ans);
            var center = ans[N / 2];
            var total = 0L;

            for (var i = 0; i < N; i++)
            {
                total += Math.Abs(array[i] - (center + i));
            }

            Console.WriteLine(total);
        }
    }
}

Measured memory_bytes: 30940
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <fstream>
#include <float.h>
#include <cmath>
#include <cstring>

using namespace std;
#define int long long

signed main() {
	int N, M;
	cin >> N >> M;
	int ans = 0;
	if (N >= M / 2) {
		ans = M / 2;
		cout << ans << endl;
		return 0;
	}
	else {
		ans = N;
		M -= N * 2;
		ans += (M / 4);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n, a[200001], b[200001];
int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i){
        scanf("%d", &a[i]);
        b[i] = a[i];
    }
    sort(a + 1, a + n + 1);
    int sz = a[n / 2], sz1 = a[n / 2 + 1];
    for (int i = 1; i <= n; ++i){
        if (b[i] <= sz) printf("%d\n", sz1);
        else if (b[i] >= sz1) printf("%d\n", sz);
    }
    return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>
#define MAX 44

int Fib(int);
int A[MAX];

int main(){ 
  
  int i,n; 
  for(i=0;i<MAX;i++){
    A[i]=0;
  }
  scanf("%d",&n);
  printf("%d\n",Fib(n));
  return 0;
}

int Fib(int n){

  int u,v;

  if(A[n]!=0){
    return A[n];
  }
  else{
    if(n==0 || n==1){
      A[n]=1;
    }
    else {
      u=Fib(n-1);
      v=Fib(n-2);
      A[n]=u+v;
    }
    return A[n];
  } 
}

Measured memory_bytes: 596
K = int(input())

def S(n):
    return sum(map(int, list(str(n))))

def norm(n):
    return n/S(n)

snk = 1
order = 0
for i in range(K):
    print(snk)
    nxt1 = snk + 10 ** order
    nxt2 = snk + 10 ** (order + 1)
    if norm(nxt2) < norm(nxt1):
        order += 1
        snk = nxt2
    else:
        snk = nxt1


Measured memory_bytes: 3188
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 

using namespace std;

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

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	vector<string> S;
	int q;
	string r;
	cin >> q;

	rep(i,q){
		cin >> r;
		S.pb(r);

	}
	rep(i,q){
		int ans = 0;
		string s = S[i];
		while(s.size() != 1){
			int ab_max = 0;
			stringstream max_s;
			rep(j, s.size() - 1){
				stringstream ssa, ssb;
				string as, bs;
				int a, b;
				as = s.substr(0, j + 1);
				bs = s.substr(j + 1, s.size() - j - 1);
				ssa << as;
				ssb << bs;
				ssa >> a;
				ssb >> b;
				if(a * b > ab_max){
					ab_max = a * b;
				}
			}
			max_s << ab_max;
			s = max_s.str();
			ans++;
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1232
#include "bits/stdc++.h"
using namespace std;
#define int long long

int h,w,hh,ww;
vector<int> p;
signed main() {
	cin >> h >> w >> hh >> ww;

	int ans = 0;
	ans = (h - hh) * (w -ww);

	//p.resize(n);
	//for (size_t i = 0; i < m; i++)
	//{
	//	cin >> p[i];
	//}
	


	cout << ans << endl;
}




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

int main(){
  int n;

  while(cin >> n){
    if(n == 0){
      break;
    }

    int c[n];
    int score[n];

    for(int i = 0; i < n; i++){
      cin >> c[i];
      score[i] = 0;

      for(int j = 0; j < 4; j++){
        int m, s;
        cin >> m >> s;
        score[i] += s + m * 60;
      }
    }

    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        if(score[i] > score[j]){
          swap(c[i], c[j]);
          swap(score[i], score[j]);
        }
      }
    }

    cout << c[0] << endl;
    cout << c[1] << endl;
    cout << c[n - 2] << endl;
  }
}

Measured memory_bytes: 1196
//2008dC
I;int parse(char *p){switch(*p){
	case'F':return 0;
	case'T':return 1;
	case'-':return !parse(p+1);
	case'(':{
		int x=0;
		char*q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		switch(*(++p)){
			case'*':return parse(q)&parse(p+1);
			case'+':return parse(q)|parse(p+1);
			case'-':return !parse(q)|parse(p+2);
		}
	}
}return(I>>(*p-97))&1;}
char p[1001],*q;main(){for(;scanf("%s",p),*p-'#';puts(I==2048?"YES":"NO")){for(q=strchr(p,'=')+1,I=0;I<2048;I++)if(parse(p)!=parse(q))break;}exit(0);}

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

typedef long long ll;
typedef pair<int,int> ii;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string s; cin>>s;
	for (char ch : s) {
		if(ch=='9') ch='1';
		else if(ch=='1') ch='9';
		cout << ch;
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main() {
  int N,X,Y;
  cin >> N >> X >> Y;
  int d[2010][2010];
  int i,j;
  for(i=0;i<N-1;i++) {
    for(j=i+1;j<N;j++) {
      d[i][j] = j-i;
    }
  }
  for(i=0;i<N-1;i++) {
    for(j=i+1;j<N;j++) {
      d[i][j] = min(d[i][j],abs(X-i-1)+abs(Y-j-1)+1);
    }
  }
  vector<int> cnt(2010,0);
  for(i=0;i<N-1;i++) {
    for(j=i+1;j<N;j++) {
      cnt[d[i][j]]++;
    }
  }
  for(i=1;i<N;i++) {
    cout << cnt[i] << endl;
  }
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
vector<pair<int, int>> adj[MAXN];
int ans[MAXN];
int cnt;

void dfs(int u, int c, int p = -1){
	bool flag = false;
	for (auto x : adj[u]){
		int v = x.first, idx = x.second;
		if (v != p){
			flag = true;
			ans[idx] = c;
			c = (c + 1) % cnt;
			dfs(v, c, u);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; ++i){
		int u, v;
		cin >> u >> v;
		adj[u].push_back({v, i});
		adj[v].push_back({u, i});
	}
	for (int i = 1; i <= n; ++i){
		cnt = max(cnt, (int)adj[i].size());
	}
	dfs(1, 0);
	cout << cnt << "\n";
	for (int i = 0; i < n - 1; ++i){
		cout << ans[i] + 1 << "\n";
	}
	return 0;
}



Measured memory_bytes: 7552
#include<bits/stdc++.h>
#include<math.h>
#include <string.h>

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back

const int N = 2e5 + 10;





using namespace std;

int main()
{



  IOS;

  int a, b;
  cin >> a >> b;

  cout << a*b;


  return 0;
}



Measured memory_bytes: 3668
import sys
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
read = sys.stdin.read

N, M, *abc = map(int, read().split())
a, b, c = zip(*zip(*[iter(abc)] * 3))

graph = csr_matrix((c, (a, b)), shape=(N + 1, N + 1))
distance = dijkstra(graph, directed=False).astype(int)

answer = 0

for i, j, k in zip(a, b, c):
    if k != distance[i][j]:
        answer += 1

print(answer)

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

int main(){
    int q;
    cin >> q;
    rep(ss,q){
        string x,y;
        cin >> x >> y;
        int xlen = x.size();
        int ylen = y.size();
        int dp[1001][1001];//dp[i][j]xi,yjまででのlcs
        memset(dp,0,sizeof(dp));
        rep(i,xlen)rep(j,ylen){
            if(x[i]==y[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j]+1);
            }
            else{
                dp[i+1][j+1] = max(dp[i+1][j],dp[i][j+1]);
            }
        }
        cout << dp[xlen][ylen] << endl;
    }
}


Measured memory_bytes: 7096
#include <iostream>
#include <vector>
int main()
{
    int N;
    std::cin >> N;
    // long long ls[N];
    std::vector<long long> ls(N);
    long long xor_sum = 0;
    for (int i=0; i<N; i++)
    {
        std::cin >> ls[i];
        xor_sum ^= ls[i];
    }
    for (int i=0; i<N; i++)
    {
        // std::cout << (xor_sum^ls[i]) << std::endl; 
        std::cout << (xor_sum^ls[i]) << " "; 
    }
    
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i(a); i <= (b); ++i)

#define gc getchar()
struct Reader {
	template <class T> inline operator T() {
		T w; char c, p = 0;
		for(; !isdigit(c = gc); c == '-' && (p = 1));
		for(w = c & 15; isdigit(c = gc); w = w * 10 + (c & 15));
		return p ? -w : w;
	}
} rd;

template <class T> inline bool smin(T&x, const T&y) { return y < x ? x = y, 1 : 0; }
template <class T> inline bool smax(T&x, const T&y) { return x < y ? x = y, 1 : 0; }

typedef long long ll;
#define int ll
const int N(2e5 + 5);
namespace SGT {
ll add[N << 2], max[N << 2];
#define ls o << 1
#define rs o << 1 | 1
inline void update(int o, int l, int r, int x, int y, int z) {
	if (x <= l && r <= y) return max[o] += z, add[o] += z, void();
	int mid = l + r >> 1;
	if (x <= mid) update(ls, l, mid, x, y, z);
	if (y > mid) update(rs, mid + 1, r, x, y, z);
	max[o] = add[o] + std::max(max[ls], max[rs]);
}
inline ll ask(int o, int l, int r, int x, int y) {
	if (x <= l && r <= y) return max[o];
	int mid = l + r >> 1;
	if (y <= mid) return add[o] + ask(ls, l, mid, x, y);
	if (x > mid) return add[o] + ask(rs, mid + 1, r, x, y);
	return std::max(ask(ls, l, mid, x, y), ask(rs, mid + 1, r, x, y)) + add[o];
}
#undef ls
#undef rs

}
#define ALL 1, 0, n
#define add(a, b, c) SGT::update(ALL, a, b, c)
#define ask(a, b) SGT::ask(ALL, a, b)
std::vector<std::pair<int, int>> g[N];
signed main() {
	int n = rd, m = rd;
	while (m--) {
		int l = rd, r = rd, w = rd;
		g[r].push_back({l, w});
	}
	REP(i, 1, n) {
		add(i, i, ask(0, i - 1));
		for (auto &u : g[i]) add(u.first, i, u.second);
	}
	std::cout << std::max(0ll, ask(0, n));
	return 0;
}


Measured memory_bytes: 22912
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using Vl = vector<ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;

//bit全探索
vector<ll>bitSearch(int bit,int n){
    vector<ll>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    S.push_back(1e9);
    return S;
}

ll dp1[3010][2], dp2[3010][2];
int main(){
    ll r, g, b, n;
    cin >> r >> g >> b >> n;
    ll res = 0;
    rep(i, 3001){
        rep(j, 3001){
            int rem = n - r * i - g * j;
          ll k = rem / b;
          	if(rem < 0)continue;
            if(rem % b != 0)continue;
          if(r * i + g * j + b *k == n)res++;
         //cout << i << " " << j << " " << k << endl;
            //res++;
        }
    }
    cout << res << endl;
}



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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, T;
	cin >> N >> T;
	int MAX = 1 << 30;
	vector<pair<int, int>> p(N);

	for (int i = 0; i < N; i++)
	{
		int a, b;
		cin >> a >> b;
		p[i] = make_pair(a, b);
		
	}
	int ans = MAX;
	sort(p.begin(), p.end());

	for (int i = 0; i < N; i++) {
		if (p[i].second <= T) {
			ans = min(ans, p[i].first);
		}
	}
	if (ans < MAX) {
		cout << ans << endl;
	}
	else {
		cout << "TLE" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

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 < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, x;
    int l = 0;
    int r = 0;
    cin >> n >> m >> x;
    vector<int> a(n + 1);
    rep(i, m) {
      int pay;  cin >> pay;
      a[pay] = 1;
    }
    rep(i, x) {
      l += a[i];
    }
    FOR(i, x + 1, n + 1) {
      r += a[i];
    }

    cout << min(r, l) << '\n';

    return 0;
}


Measured memory_bytes: 256
/*BY-ADITYA OJHA
  LEARN DSA SINCERELY*/
#include <bits/stdc++.h>
#define ll long long int
#define forin for(int i=0;i<n;i++)
#define forjn for(int j=0;j<n;j++)
#define pb push_back
#define vx vector<ll> x
#define fas1  ios_base::sync_with_stdio(false)
#define fas2   cin.tie(NULL)
using namespace std;


int main()
{
    string s,s1,s2;
    cin>>s>>s1;
    ll a,b;
    cin>>a>>b;
    cin>>s2;
    if(s2==s)
        cout<<a-1<<" "<<b<<endl;
    else
        cout<<a<<" "<<b-1<<endl;



}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int,int> pa;
#define w1 first
#define w2 second
#define ls (x<<1)
#define rs (x<<1|1)
#define pb push_back
#define mp make_pair
#define mid ((l+r)>>1)
#define SZ(x) ((x).size())
#define All(x) (x).begin(),(x).end()
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep2(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define per(i,a,b) for(int (i)=(a);(i)>=(b);(i)--)
#define Rep(p,x) for(int (p)=head[(x)];(p);(p)=nxt[(p)])
template<class T>void read(T&num){
	num=0;T f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')num=num*10+ch-'0',ch=getchar();
	num*=f;
}
int power(int x,int k,int p){int res=1;for(;k;k>>=1,x=1ll*x*x%p)if(k&1)res=1ll*res*x%p;return res;}
int getgcd(int x,int y){return !x?y:getgcd(y%x,x);}
const int maxn=1e5+5;
int n,ans;
int a[maxn];
void check(){
	int cnt=0;
	rep(i,1,n)cnt+=!(a[i]&1);
	if(!(cnt&1)){
		ans^=1;
		if(cnt+1==n){
			rep(i,1,n)if(a[i]&1){
				if(a[i]==1)return;
				a[i]--;
			}
			int d=0;
			rep(i,1,n)d=getgcd(d,a[i]);
			rep(i,1,n)a[i]/=d;
			check();
		}
	}
}
int main(){
	read(n);
	rep(i,1,n)read(a[i]);
	check();
	if(ans)puts("Second");
	else puts("First");
	return 0;
}

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

using namespace std;

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

  string s;
  cin >> s;
  int n = s.size() - 2;

  int ans = 10000;
  for (int i = 0; i < n; ++i) {
    int a = abs((s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0') -
                753);
    ans = min(ans, a);
  }

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 41
using namespace std;
typedef long long ll;
ll n,m,a,b,p,q,d[N];
vector<ll> v[2],x[2];

int main(){
  cin>>n>>m>>a>>b>>p>>q;
  ll ans=m;
  if(a==1&&b==1){
    ll ti=min(n,m/(p+q));
    ans=min(ans,min(m-ti*(p+q),abs(min(ti+1,n)*(p+q)-m)));
  }
  ll A=1,B=1,T=min((ll)N,n);
  for(int i=0;i<T;i++){
    d[i]=p*A+q*B;
    if(i<T/2)v[0].push_back(d[i]);
    else v[1].push_back(d[i]);
    if(d[i]>m)break;
    A*=a,B*=b;
  }
  int len[2]={v[0].size(),v[1].size()};
  for(int i=0;i<2;i++){
    v[i].push_back(0);
    for(int j=0;j<(1<<len[i]);j++){
      ll sum=0;
      for(int k=0;k<len[i];k++)
	if((j&(1<<k)))sum+=v[i][k];
      x[i].push_back(sum);
    }
    sort(x[i].begin(),x[i].end());
  }
  for(int i=0;i<x[0].size();i++){
    ll S=m-x[0][i];
    vector<ll>::iterator r=lower_bound(x[1].begin(),x[1].end(),S);
    if(r!=x[1].end())ans=min(ans,(*r)-S);
    if(r!=x[1].begin())ans=min(ans,S-(*(r-1)));
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 27608
#include<iostream>
#include<algorithm>
#include<cstdint>

int const MAXN = 1e5;
int64_t const MOD = 1e9+7;
int N, M;

int64_t fib[MAXN+1];
int last_ix;

int64_t calc_fib(int ix) {
  if(last_ix >= ix) return fib[ix];
  while(last_ix < ix) {
    fib[last_ix+1] = (fib[last_ix] + fib[last_ix-1])%MOD;
    ++last_ix;
  }
  return fib[ix];
}

int main() {
  int last_broken = -1;
  fib[1] = 0; fib[2] = 1;
  last_ix = 2;
  std::cin >> N >> M;
  int64_t ans = 1;
  for(int i = 0; i < M; ++i) {
    int a;
    std::cin >> a;
    (ans *= calc_fib(a-last_broken)) %= MOD;
    last_broken = a;
  }
  (ans *= calc_fib(N+1-last_broken)) %= MOD;
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
  int n,m,l,count;
  while(cin>>n,n){
    string s,ans="I";
    cin >> m >> s;
    l = - 1;
    count = 0;
    for(int i=0;i<n;i++) ans += "OI";
    while(s.find(ans,l+1)!=-1){
      count++;
      l = s.find(ans,l+1);
      //cout << l << endl;
    }
    cout << count << endl;
  }
  return 0;
}

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

#define EPS 0.0002

struct Point{double x,y,z;};
double getDistance(Point p1,Point p2)
{
  return sqrt(pow(p1.x-p2.x,2.0)+pow(p1.y-p2.y,2.0)+pow(p1.z-p2.z,2.0));
}

int main()
{
  int n,m,P,Q,R;
  double original[3],x,y,z;
  int i,j,k;
  cin>>n;
  while(n-->0){
    for(i=0;i<3;i++)cin>>original[i];

    cin>>m;
    vector<Point>v(m);
    for(i=0;i<m;i++){
      cin>>x>>y>>z;
      Point p={x,y,z};
      v[i]=p;
    }

    P=0;
    for(i=0;i<m;i++){
      for(j=0;j<m;j++){
	if(i==j)continue;
	for(k=0;k<m;k++){
	  if(i==k||j==k)continue;
	  Point p[3]={v[i],v[j],v[k]};
	  bool ok=true;
	  double d[3]={getDistance(p[1],p[2]),getDistance(p[2],p[0]),getDistance(p[0],p[1])};
	  for(int s=0;s<3;s++){
	    if(original[s]/original[(s+1)%3]-d[s]/d[(s+1)%3]>EPS)ok=false;
	  }
	  if(ok){
	    P=i+1;
	    Q=j+1;
	    R=k+1;
	  }
	  if(P)break;
	}
	if(P)break;
      }
      if(P)break;
    }

    cout<<P<<" "<<Q<<" "<<R<<endl;
  }
}

Measured memory_bytes: 968
#!/usr/bin/env python3
from itertools import product
n, m = map(int, input().split())
a = [int(input()) for _ in range(m)]
mod = 10**9+7


def mat2_mul(X, Y):
    z = [[0, 0], [0, 0]]
    for (i, j, k) in product(range(2), range(2), range(2)):
        z[i][j] += X[i][k] * Y[k][j]
    return z


def mat2_pow(X, n):
    if n == 0:
        return [[1, 0], [0, 1]]
    elif n % 2:
        return mat2_mul(X, mat2_pow(X, n - 1))
    else:
        half_pow = mat2_pow(X, n / 2)
        return mat2_mul(half_pow, half_pow)


def fib(n):
    if n == 0:
        return 0
    else:
        f = [[0, 1], [1, 1]]
    return mat2_pow(f, n - 1)[1][1]


ans, start = 1, 0

for i in a:
    ans *= fib(i - start)
    ans %= mod
    start = i + 1

ans *= fib(n - start + 1)
print(ans % mod)


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

typedef long long ll;
typedef pair<ll,ll> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
#define f first
#define s second
#define FOR(i,s,e) for(ll i=s;i<=ll(e);++i)
#define DEC(i,s,e) for(ll i=s;i>=ll(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0)

typedef long double ld;

ll X;

int main(){
	fast;
	
	cin>>X;
	
	ll cur = 100;
	
	int cnt = 0;
	while (cur < X){
		cur = cur * (1.01);
		cnt++;
	}
	cout<<cnt;
}



Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>

using namespace std;

set<string> S[100];
map<string, int> mp;
vector< vector<string> > vs;

int search(int cur){
	for(int i=0;i<vs[cur].size();i++){
		if(mp.count(vs[cur][i])){
			int next = mp[vs[cur][i]];
			if(S[next].empty()) search(next);
			for(set<string>::iterator it=S[next].begin();it!=S[next].end();it++)
				S[cur].insert(*it);
		}
		else{
			S[cur].insert(vs[cur][i]);
		}
	}
	return S[cur].size();
}

int main(){
	int n;
	while(cin >> n, n){
		mp.clear();
		vs.assign(n, vector<string>());
		for(int i=0;i<n;i++){
			S[i].clear();
			string str; cin >> str;
			for(int j=0;j<str.size();j++)
				if(!islower(str[j])) str[j] = ' ';
			istringstream iss(str);
			iss >> str; mp[str] = i;
			while(iss >> str) vs[i].push_back(str);
		}
		cout << search(0) << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));
ll f(ll n)
{
    if (n % 2 == 0)
    {
        n /= 2;
        if (n % 2 == 0)
            return 2 * n;
        else
            return 2 * n + 1;
    }
    else
    {
        n++;
        n /= 2;
        if (n % 2 == 0)
            return 0;
        else
            return 1;
    }
}
int main()
{
    cout << fixed << setprecision(30);
    ll A, B;
    cin >> A >> B;
    if (A != 0)
        putout((ll)((f(A - 1) ^ f(B))));
    else
        putout(f(B));
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#pragma warning(disable:4996)

int main() {
	int num = 0;
	scanf("%d", &num);
	bool flag = 0;
	if (num >= 1 && num <= 100) {
		for (int i = 1; i <= 9; i++) {
			if ((num / i < 10) && (num % i == 0)) {
				flag = 1;
				break;
			}
		}
		if (flag == 1) {
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    vi dp(N+1, INF);
    dp[0] = 0;
    REP1(i, N)
    {
        int m = dp[i-1];
        int t = 1;
        while(t <= i)
        {
            m = min(m, dp[i-t]);
            t *= 6;
        }
        t = 1;
        while(t <= i)
        {
            m = min(m, dp[i-t]);
            t *= 9;
        }
        dp[i] = m+1;
    }
    cout << dp[N] << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.nextLine();
		String ans = "";
		for (int i=0; i<s.length(); i++) {
			if (Character.isUpperCase(s.charAt(i))) {
				ans += Character.toLowerCase(s.charAt(i));
			}else if (Character.isLowerCase(s.charAt(i))) {
				ans += Character.toUpperCase(s.charAt(i));
			}else{
				ans += s.charAt(i);
			}
		}
		System.out.println(ans);
	}
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = (x), i##_len = (int)(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = (int)(n) ; i < i##_len ; ++i)
#define repr(i, n) for(int i = (int)(n) - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())

const int IINF = 1e9 + 100;
const long long LLINF = 2e18 + 129;
const long long MOD = 1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

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

    lint n, m;
    cin >> n >> m;

    vector< LLP > v(n);
    for(auto &x : v){
        cin >> x.first >> x.second;
    }
    SORT(v);

    lint cnt = m, ans = 0;
    rep(i, n){
        ans += v[i].first * min(v[i].second, cnt);
        cnt = max(cnt - v[i].second, 0LL);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000

//using namespace atcoder;
using namespace std;

int main(void){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int ans = 0;
  b--; d--;
  for (int i = 0; i < 101; i++){
    if (a <= i && i <= b && c <= i && i <= d)
      ans++;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
package main
import(
  "fmt"
)
func main(){
  var n, i int
  count:=0
  var s string
  fmt.Scan(&n, &s)
  for i=0;i<n-2;i++{
    if s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'{
      count++
    }
  }
  fmt.Println(count)
}


Measured memory_bytes: 512
n=int(input())

x = list(map(int,input().split()))
y=[0]*n

for i in range(n):
    y[i]=x[i]
    
y.sort()

for i in range(n):
    if x[i]<y[n//2]:
        print(y[n//2])
    else:
        print(y[n//2-1])

Measured memory_bytes: 25228
#include <algorithm>
//#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define INF 1LL << 40;
#define MOD 1000000007;
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
struct edge {
    int to, cost;
};

int dp[3001][3001];
int prv[3001][3001];

int main() {
    string s, t;
    cin >> s >> t;
    rep(i, s.size() + 1) rep(j, t.size() + 1) dp[i][j] = -1;
    dp[0][0] = 0;
    rep(i, s.size() + 1) rep(j, t.size() + 1) {
        if(i < s.size() && chmax(dp[i + 1][j], dp[i][j]))
            prv[i + 1][j] = i * 3001 + j;
        if(j < t.size() && chmax(dp[i][j + 1], dp[i][j]))
            prv[i][j + 1] = i * 3001 + j;
        if(i < s.size() && j < t.size() && s[i] == t[j]) {
            if(chmax(dp[i + 1][j + 1], dp[i][j] + 1))
                prv[i + 1][j + 1] = i * 3001 + j;
        }
    }
    // rep(i, s.size() + 1) {
    //     rep(j, t.size() + 1) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    int n = s.size(), m = t.size(), tmp;
    string res;
    while(n != 0 || m != 0) {
        tmp = prv[n][m];
        if(tmp / 3001 == n - 1 && tmp % 3001 == m - 1) {
            res += s[n - 1];
        }
        n = tmp / 3001;
        m = tmp % 3001;
    }
    reverse(all(res));
    cout << res << endl;
}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int A, B; cin >> A >> B;    
    cout << 6 - A - B << endl;
}

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

    solve();

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int n,i,j;
	cin>>n;
	double t,a,h[n];
	cin>>t>>a;
	for(i=0;i<n;i++)
		cin>>h[i];
	int ind = 0;
	double mi = abs(a-(t-h[0]*0.006));
	for(i=1;i<n;i++)
	{
		if(mi>abs(a-(t-h[i]*0.006)))
		{
			ind = i;
			mi = min(mi,abs(a-(t-h[i]*0.006)));
		}
	}
	cout<<(ind+1)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
#include <cstring>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
// constexpr int mod = 1000000007;
constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    ll N, X, M;
    cin >> N >> X >> M;
    vector<vector<int>> graph(M), rev(M);
    for(int i = 0; i < M; ++i){
        ll v = (ll)i * i % M;
        graph[i].emplace_back(v);
        rev[v].emplace_back(i);
    }
    vector<int> vs;
    vector<bool> used(M, false);
    auto dfs = [&](auto&& self, int from) -> void {
        used[from] = true;
        for(int to : graph[from]){
            if(!used[to])   self(self, to);
        }
        vs.emplace_back(from);
    };
    for(int v = 0; v < M; ++v){
        if(!used[v])    dfs(dfs, v);
    }
    reverse(vs.begin(), vs.end());

    vector<int> scc_id(M, -1);
    int K = 0;
    auto rdfs = [&](auto&& self, int from) -> void {
        scc_id[from] = K;
        for(int to : rev[from]){
            if(scc_id[to] == -1)    self(self, to);
        }
    };
    for(int v : vs){
        if(scc_id[v] == -1){
            rdfs(rdfs, v);
            ++K;
        }
    }
    vector<vector<int>> scc_set(K);
    for(int i = 0; i < M; ++i){
        scc_set[scc_id[i]].emplace_back(i);
    }

    ll ans = X;
    --N;
    X = graph[X][0];
    while(N > 0){
        if(X == 0)  break;
        if(scc_set[scc_id[X]].size() == 1){
            if(X == graph[X][0]){
                ans += X * N;
                N = 0;
            }
            else{
                ans += X;
                X = graph[X][0];
                --N;
            }
        }
        else{
            int loop = scc_set[scc_id[X]].size();
            ll total = 0;
            for(int v : scc_set[scc_id[X]]){
                total += v;
            }
            ans += total * (N / loop);
            N %= loop;
            while(N-- > 0){
                if(X == 0){
                    N = 0;
                    break;
                }
                ans += X;
                X = graph[X][0];
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 19340
/*
//alds1_4_c:Dictionary
//算法:开放地址法散列表
//Time: 2018/1/8 星期一
*/
#include<stdio.h>
#include<string.h>

const int M=1000003;
const int L=14;

char H[M][L];

//对于每个字符返回的定义值
int getChar(char ch){
    if(ch=='A') return 1;
    if(ch=='C') return 2;
    if(ch=='D') return 3;
    if(ch=='T') return 4;
    return 0;
}
//对于字符串返回的初始散列值
long long getKey(char str[]){
    long long len=strlen(str),sum=0,p=1;
    for(int i=0;i<len;++i){
        sum+=p*getChar(str[i]);
        //每次获取定义值后p*5,相当于转换成五进制,不会冲突
        p*=5;
    }
    return sum;
}

//开放式散列值计算式: h(k,i)=(h1(k)+i*h2(k))%M
int h1(int key){
    return key%M;
}
//为了保证不会递归冲突(即往下算结果始终相同),必须使h2(key)与M互素
//TLE最好的情况就是改这个函数= =
//目前可以AC的: 1+(key%(M-1))
//(1+key)%(M-1)
int h2(int key){
    return (1+key)%(M-1);
}

//查找
//-1表示找到
//h表示找到第一个可插入点
int find(char str[]){
    long long key=getKey(str),i,h;
    for(i=0;;++i){
        h=(h1(key)+i*h2(key))%M;
        if(strcmp(H[h],str)==0) return -1;
        else if(strlen(H[h])==0) return h;
    }
    return 0;
}

//插入
void insert(char str[]){
    int key=find(str);
    if(key!=-1) strcpy(H[key],str);
}

int main(){
    for(int i=0;i<M;++i) H[M][0]='\0';
    char str[L],com[L];
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%s %s",com,str);

        if(com[0]=='i'){
            insert(str);
        }else{
            if(find(str)==-1)
                printf("yes\n");
            else
                printf("no\n");
        }
    }

    return 0;
}



Measured memory_bytes: 16244
import java.util.*;

public class Main {
	void solve() {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((a + b) / 2);
		scan.close();
	}
	
	public static void main(String[] args) {
		new Main().solve();
	}
}



Measured memory_bytes: 26284
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>
#include<list>
#include<bitset>
#include<functional>

#define FOR(i, a, b) for(long long int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LLINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979

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


int main(void) {
	int n;
	string s;
	bool flag = false;

	cin >> n;
	FOR(i, 1, n) {
		cin >> s[i];
		if (s[i] == 'Y') {
			flag = true;
		}
	}

	if (flag) {
		cout << "Four" << endl;
	}
	else {
		cout << "Three" << endl;
	}


	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;

int main(void) {
	string s, t, u;
	int a, b;
	cin >> s >> t >> a >> b >> u;
	
	map<string, int> mp;
	mp[s] = a;
	mp[t] = b;
	mp[u]--;
	
	cout << mp[s] << " " << mp[t] << endl;
	
	return 0;
}


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

using namespace std;

int main() {
  int n;
  int a[51];
  cin>>n;
  for (int i = 1; i <= n; i++)
    cin>>a[i];
  int res = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++)
      res += a[i] * a[j];
  cout<<res;
}

Measured memory_bytes: 256
N=int(input())
A=[0]+list(map(int,input().split()))

ANS=[0]*(N+1)

for i in range(N,0,-1):
    SUM=0
    for j in range(i*2,N+1,i):
        SUM=(SUM+ANS[j])%2

    ANS[i]=(A[i]-SUM)%2

if min(ANS)<0 or max(ANS)>1:
    print(-1)
else:
    ANS2=[i for i in range(N+1) if ANS[i]==1]
    print(len(ANS2))
    print(*ANS2)

Measured memory_bytes: 71004
import numpy as np
n, a, b = map(int, input().split())
sum_i = 0
for i in range(n + 1):
  base = i
  v5 = np.floor(base / 10000).astype(int)
  base -= v5 * 10000
  v4 = np.floor(base / 1000).astype(int)
  base -= v4 * 1000
  v3 = np.floor(base / 100).astype(int)
  base -= v3 * 100
  v2 = np.floor(base / 10).astype(int)
  base -= v2 * 10
  sum_10_1 = v5 + v4 + v3 + v2 + base
  if a <= sum_10_1 <= b:
    sum_i += i
print(sum_i)

Measured memory_bytes: 12504
n, m = map(int, input().split())
ks = [list(map(int, input().split())) for i in range(m)]
p=list(map(int, input().split()))
ans=0
for i in range(1<<n):
    val=[]
    tmp=i
    for j in range(n):
        val.append(tmp%2)
        tmp//=2
    if all(sum(val[k-1] for k in ks[j][1:])%2==p[j] for j in range(m)):
        ans+=1
print(ans)

Measured memory_bytes: 46556
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define f first
#define s second
#define inf 1000000007

ll N;
ll X[1010];
ll Y[1010];
ll kukan[32];

int main() {
    rep(i,32) kukan[i] = pow(2,i)-1;
    scanf("%lld",&N);
    rep(i,N) scanf("%lld%lld",&X[i],&Y[i]);
    ll check = (abs(X[0])+abs(Y[0]))%2;
    rep(i,N){
        if ((abs(X[i])+abs(Y[i]))%2 != check) {
            cout << -1 << endl;
            return 0;
        }
    }
    if (check == 0){
        rep(i,N) X[i] --;
    }
    ll len = -1;
    rep(i,N){
        ll temp = abs(X[i])+abs(Y[i]);
        rep(j,31){
            if (temp > kukan[j] && temp <= kukan[j+1]){
                len = max(len,j);
            }
        }
    }
    if (check == 1){
        cout << len+1 << endl;
        rep(i,len+1) cout << kukan[i]+1 << " ";
        cout << endl;
    }
    else{
        cout << len+2 << endl;
        cout << 1 << " ";
        rep(i,len+1) cout << kukan[i]+1 << " ";
        cout << endl;
    }
    rep(i,N){
        ll acx = X[i];
        ll acy = Y[i];
        ll aclen = len;
        ll acp = len;
        string ans;
        while(abs(acx)+abs(acy) != 0){
            ll d = pow(2,aclen);
           
            if (abs(acx-d)+abs(acy) <= kukan[acp]){
                ans += 'R';
                aclen --;
                acp --;
                acx -= d;
                continue;
            }
            if (abs(acx)+abs(acy-d) <= kukan[acp]){
                ans += 'U';
                aclen --;
                acp --;
                acy -= d;
                continue;
            }
            if (abs(acx+d)+abs(acy) <= kukan[acp]){
                ans += 'L';
                aclen --;
                acp --;
                acx += d;
                continue;
            }
            if (abs(acx)+abs(acy+d) <= kukan[acp]){
                ans += 'D';
                aclen --;
                acp --;
                acy += d;
                continue;
            }
        }
        if (check == 0){
            ans += 'R';
            reverse(ans.begin(),ans.end());
            cout << ans << endl;
        }
        else{
            reverse(ans.begin(),ans.end());
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))

d = {}
for i in range(N):
    if A[i] not in d.keys():
        d[A[i]] = 0
    d[A[i]] += 1

m1 = 0
m2 = 0
for k in sorted(list(d.keys()),reverse=True):
    if d[k] >= 2 and m1 == 0:
        m1 = k
    elif d[k] >= 2 and m1 != 0:
        m2 = k
        break


if m1 != 0:
    if d[m1] >= 4:
        print(m1*m1)
    else:
        print(m1*m2)
else:
    print(0)


Measured memory_bytes: 18060
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323



void solve()
{
       string s;
       cin>>s;
       ll cnt[26];
       memset(cnt, 0, sizeof cnt);
       rep(i,0,sz(s)) cnt[s[i]-'a']++;
       ll n = sz(s);
       ll ans = n*(n-1)/2;
       rep(i,0,26)
              if(cnt[i])
                     ans -= (cnt[i]*(cnt[i]-1))/2;
       cout<<ans+1;
}


int main()
{
    speed_up
    ll T=1;
    //cin>>T;
    while(T--)
        solve();
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int ans;
  if (C < A) {
    if (D <= A) ans = 0;
    else if (A < D && D <= B) ans = D - A;
    else if (B < D) ans = B - A;
  } else if (A <= C && C < B) {
    if (D <= B) ans = D - C;
    else if (B < D) ans = B - C;
  } else if (B <= C) {
    ans = 0;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)

bool solve(int n,int d,queue<int> *in,int *sum){
  while(true){
    int mini=10000*10000,maxi=0;
    bool a=false;
    rep(i,n){
      maxi=max(maxi,sum[i]);
    }
    if (maxi==0)break;
    rep(i,n){
      while(!in[i].empty() && maxi-(sum[i]-in[i].front()) <= d)
	sum[i]-=in[i].front(),in[i].pop(),a=true;
    }
    rep(i,n){
      if (sum[i] == maxi)sum[i]-=in[i].front(),in[i].pop(),a=true;
    }
    //    rep(i,n)cout << sum[i]<<" ";cout << endl;
    if (!a)return false;
    maxi=0;
    rep(i,n)maxi=max(maxi,sum[i]),mini=min(mini,sum[i]);
    if (maxi-mini > d)return false;
  }
  return true;
}

main(){
  int n,d;
  while(cin>>n>>d && n){
    int sum[n];queue<int> in[n];
    rep(i,n){
      sum[i]=0;int m,t;cin>>m;
      vector<int> a(m);rep(j,m)cin>>a[j];
      reverse(a.begin(),a.end());
      rep(j,m)sum[i]+=a[j],in[i].push(a[j]);
    }
    cout << (solve(n,d,in,sum)?"Yes":"No") << endl;
  }
}

Measured memory_bytes: 952