akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, k, r, s, p;
int f(char ops, int j){
    if(ops == 's' && j == 0) return r;
    if(ops == 'p' && j == 1) return s;
    if(ops == 'r' && j == 2) return p;
    return 0;
}
int main(void){
    int ans = 0;
    string t;
    vector< vector<int> > dp;
    cin >> n >> k >> r >> s >> p >> t;

    for(int i=0;i<k;i++){
        vector<int> v(6, 0);
        for(int j=i;j<n;j+=k){
            v[0] = max(v[4], v[5]) + f(t[j], 0);
            v[1] = max(v[3], v[5]) + f(t[j], 1);
            v[2] = max(v[3], v[4]) + f(t[j], 2);
            v[3] = v[0];
            v[4] = v[1];
            v[5] = v[2];
        }
        ans += max(v[3], max(v[4], v[5]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
import queue
h, w = map(int, input().split())
s = []
black_num = 0
for i in range(h):
    s_ij = input()
    s.append(s_ij)
    for j in range(w):
        if s_ij[j] == "#":
            black_num += 1

already_pass = set()
already_pass.add((1, 1))
q = queue.Queue()
q.put([(1, 1), 1])

while not q.empty():
    x_y, l = q.get()
    x = x_y[0]
    y = x_y[1]
    if x == h and y == w:
        print(h * w - black_num - l)
        break
    next_xy = [(max(1, x - 1), y), (min(h, x + 1), y),
               (x, max(1, y - 1)), (x, min(w, y + 1))]
    for i in next_xy:
        if i not in already_pass and s[i[0] - 1][i[1] - 1] != "#":
            q.put([i, l + 1])
            already_pass.add(i)
else:
    print(-1)


Measured memory_bytes: 9760
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0 and b_list:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)



Measured memory_bytes: 12116
#include <iostream>
using namespace std;
int main() {
    string S;
    int N;
    cin>>N;
    cin>>S;
    int counter=0;
    int  flag=1;
    if (N>=3 && N<=50){

           for (int i=0;i<N;i++){
                 if (islower(S[i])){
                   break;
                 }
                 if(S[i]=='A'){
                    if (S[i+1]=='B'){

                        if (S[i+2]=='C'){

                           counter=counter+1;
                           flag=0;
                         }

                    }

                 }


          }

      }
      if (flag==0){
           cout<<counter;
          }
          else cout<<0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
constexpr ll INF = (1LL << 60);
ll gcd(ll a, ll b){
    if(b == 0)return a;
    return gcd(b,a%b);
}

ll lcm(ll c, ll d){
    ll g = gcd(c,d);
    ll l = c/g*d;//最小公倍数
    return l;
}
int main() {
  int n;
  cin >> n;
  ll res = 1;
  rep(i,n) {
    ll a;
    cin >> a;
    res = lcm(res, a);
  }
  cout << res << endl;
  return 0; 
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[101],s;
int main() 
{
    for(int i=1;i<=3;i++)
    {
		cin>>a[i];
		s+=a[i];
	}
    cout<<s-(*max_element(a+1,a+4))<<endl;
    //函数求最大值
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;

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

    map<int, int> m;
    for (int i = 0; i < N; i++) {
        int Ai;
        cin >> Ai;
        ++m[Ai];
    }

    int cntEven = 0;
    for (map<int, int>::iterator itr = m.begin(); itr != m.end(); ++itr) {
        if (!(itr->second & 0x1)) {
            ++cntEven;
        }
    }

    if (cntEven & 0x1) {
        cout << m.size() - 1 << endl;
    } else {
        cout << m.size() << endl;
    }

    return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<cmath>
using namespace std;
#define KMAX 30
#define VMAX 1000000
int K[KMAX];
unsigned char T[KMAX][VMAX+1];
void eratos ( int n, bool prime[]){
 for ( int i = 0; i <= n; i++ ) prime[i] = false;
 for ( int i = 3; i <= n; i += 2 ) prime[i] = true;
 prime[2] = true;
 int limit = (int)sqrt((double)n) + 1;
 for ( int i = 3; i <= limit; i += 2 ){
if ( !prime[i] ) continue;
for ( int j = i + i; j <= n; j += i ) prime[j] = false;
 }
}
main(){
 bool prime[VMAX + 1];
 eratos( VMAX, prime );
 int k, v;
 while( cin >> k >> v && !(k == 0 && v == 0) ){
for ( int i = 0; i < k; i++ ) cin >> K[i];
for ( int j = 0; j <= v; j++ ) T[0][j] = 0;
for ( int j = K[0]; j <= v; j += K[0] ) T[0][j] = 1;
for ( int i = 0; i < k; i++ ) T[i][0] = 1;
for ( int i = 1; i < k; i++ ){
 for ( int j = 1; j < K[i]; j++ ) T[i][j] = T[i-1][j];
 for ( int j = K[i]; j <= v; j++ ){
T[i][j] = (T[i-1][j] | T[i][j-K[i]]);
 }
}
int ans = -1;
for ( int i = v; i >= 2; i-- ){
 if ( prime[i] && T[k-1][i] ) { ans = i; break; }
}
if ( ans == -1 ) cout << "NA" << endl;
else cout << ans << endl;
 }
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin>>s;
	int n=s.length(),cnt=0;
	for(int i=n;i>0;i--){
		n=s.length();
		if(i-5>=0){
			if(s.substr(i-5,i)=="dream"){
				s.erase(i-5,i);
				i-=4;
				if(s.length()==0){
					cout<<"YES"<<endl;
					return 0;
				}
			}
			if(s.substr(i-5,i)=="erase"){
				s.erase(i-5,i);
				i-=4;
				if(s.length()==0){
					cout<<"YES"<<endl;
					return 0;
				}
			}
		}
		if(i-6>=0){
			if(s.substr(i-6,i)=="eraser"){
				s.erase(i-6,i);
				i-=5;
				if(s.length()==0){
					cout<<"YES"<<endl;
					return 0;
				}
			}
		}
		if(i-7>=0){
			if(s.substr(i-7,i)=="dreamer"){
				s.erase(i-7,i);
				i-=6;
				if(s.length()==0){
					cout<<"YES"<<endl;
					return 0;
				}
			}
		}
		if(n==s.length()){
			cnt++;
			if(cnt>=8){
				cout<<"NO"<<endl;
				return 0;
			}
		}else{
			cnt=0;
		}
	}
	if(s.length()==0){
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}
}


Measured memory_bytes: 512
#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 repi(i,a,b) for (int i = (a); i < (b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;

int main() {
  int x, y;
  cin >> x >> y;
  
  vi a = {1,3,5,7,8,10,12};
  vi b = {4,6,9,11};
  
  if (count(all(a),x) == 1 && count(all(a),y) == 1) 
    cout << "Yes" << endl;
  else if (count(all(b),x) == 1 && count(all(b),y) == 1) 
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
n = input()
a = map(int,raw_input().split())
m = 1000000007

c = [0]*n
ct = 1
for x in a:
    p1 = (n-1+x)/2
    p2 = (n-1-x)/2
    c[p1] += 1
    c[p2] += 1
    if (c[p1]<2 and c[p2]<2):
        ct *= 2
        ct = ct%m
    elif (c[p1]>2 and c[p2]>2):
        ct = 0
        break
print ct

Measured memory_bytes: 11328
#include<bits/stdc++.h>
#define l(i) (n/2-(n-i+1)/2)
#define r(i) (i+1)/2
#define st(i) i/2-1
using namespace std;
typedef long long ll;
int n,a[200005];
ll ans=-1e16;
ll dp[200005][3];//j的范围在i/2-1到(i+1)/2，最多3个
int main() {
	cin>>n;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(int i=1; i<=n; i++) {
		for(int j=0; j<3; j++)
			dp[i][j]=(!i?0:-1e16);
	}
	dp[1][1-st(1)]=a[1],dp[1][0-st(1)]=0;
	for(int i=2; i<=n; i++) {
		for(int j=l(i); j<=r(i); j++) {
			if(j==0) dp[i][j-st(i)]=0;
			else {
				for(int k=i-2; l(k)<=j-1&&r(k)>=j-1&&k>=0; k--)
					dp[i][j-st(i)]=max(dp[i][j-st(i)],dp[k][j-1-st(k)]+a[i]);
			}
		}
	}
	for(int i=n/2; i<=n; i++)
		for(int j=l(i); j<=r(i); j++)
			j==n/2 ? ans=max(ans,dp[i][j-st(i)]):0;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 9112
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for ( auto blockTime = make_pair(chrono::high_resolution_clock::now(), true);blockTime.second;\
debug("%s: %lld ms\n", d, chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - blockTime.first).count()), blockTime.second = false)
#define li long long int
#define ld long double
#define eb push_back
#define pb pop_back
#define INF 1e18+10
#define MINF -1e18-10
#define rep(i,a,b) for(li i=a;i<b;i++)
#define size(a) a.size()
#define rev(a) reverse(a.begin(),a.end())
#define len(a) a.length()
#define f first
#define s second
#define sort(a) sort(a.begin(),a.end())
#define vli vector<li>
#define vvli vector<vli >
#define pli pair<li,li>199
#define vpli vector<pli>
#define inp(t) li t;cin>>t; while(t--)
using namespace std;
const li mod = 1e9+7;
#define MAXN 2000001

li power(li a, li b) { a%=mod; li ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;}
li add(li a,li b) { return (((a%mod)+(b%mod))%mod);}
li sub(li a,li b) { return (((a%mod)-(b%mod))%mod);}
li mul(li a,li b) { return (((a%mod)*(b%mod))%mod);}

void solve()
{
  li n;
  cin>>n;
  
  if(n%10==2 || n%10==4 || n%10==5 || n%10==7 || n%10==9)
  {
    cout<<"hon";
  }
  else if(n%10==0 || n%10==1 || n%10==6 || n%10==8)
  {
	cout<<"pon";
  }
  else
  {
    cout<<"bon";
  }
}
int main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("input2.txt","r",stdin);
    freopen("output2.txt","w",stdout);
    #endif

    solve();
    
    return 0;
}

Measured memory_bytes: 3648
#include <iostream>

int  main(){
    int w,a,b;
    std::cin>>w>>a>>b;

    int aw=a+w;
    int ans=0;
    if(b<a) ans=a-(b+w);
    else if(a<b&&b<aw) ans=0;
    else if(b>aw) ans=b-aw;

    std::cout<<ans<<std::endl;

}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm(a, b) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<int> Div(int n) {
    vector<int> ret;
    for(int i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);

            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

int bfs(int s, int t);

vector< P > graph[SIZE];

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

    int n, m;
    cin >> n >> m;

    while(m--) {
        int u, v;
        cin >> u >> v;
        graph[u].pb(MP(v, 1));
        graph[u].pb(MP(v, 2));
        graph[u].pb(MP(v, 3));

    }

    int s, t;
    cin >> s >> t;
    int res = bfs(s, t);
    if(res != -1) res /= 3;
    cout << res << endl;

    return 0;
}

int bfs(int s, int t) {
    queue<P> q;
    q.push(MP(s, 0));

    bool isvisit[SIZE][4];
    int cost[SIZE][3];
    for(int i = 0; i < SIZE; ++i) {
        for(int j = 0; j < 4; ++j) {
            isvisit[i][j] = false;
            cost[i][j] = 0;

        }
    }
    isvisit[s][0] = true;
    while(!q.empty()) {
        P p = q.front(); q.pop();

        for(int i = 0; i < graph[p.F].size(); ++i) {
            int to, pat;
            to = graph[p.F][i].F;
            pat = graph[p.F][i].S;
            if(p.S == 3 && pat != 1 ||
               p.S == 2 && pat != 3 ||
               p.S == 1 && pat != 2 ||
               p.S == 0 && pat != 1 ) {
                continue;

            }

            if(isvisit[to][pat]) {
                continue;

            }
            isvisit[to][pat] = true;
            if(to == t && pat == 3) {
                return cost[p.F][2] + 1;

            }
            cost[to][pat] = cost[p.F][p.S] + 1;
            q.push(MP(to, pat));

        }
    }

    return -1;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    int a,b,c;cin>> a >> b >> c;
    int k;cin >> k;
    if(k <= a){
        cout << k << "\n";
    }else if(k <= a + b){
        cout << a << "\n";
    }else{
        int ans = a;
        k -= a + b;
        ans -= k;
        cout << ans << "\n";
    }
}

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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define vi vector <ll>
#define hell 1000000009
#define pii pair <ll,ll>
#define inf (ll)(1e16)
#define pb push_back

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vi a(n+1);
    rep(i,0,n)
    {
        ll x;
        cin>>x;
        a[x]=i+1;
    }
    rep(i,1,n+1)
        cout<<a[i]<<" ";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 1664
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prl puts("\n------------------\n")
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prl 
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}


int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
        #if __cplusplus >= 201103L
        auto start = steady_clock::now();
        #endif
    #endif
    ll n;
    sf(n);
    ll s = n * (1 + n) / 2 - n;
    cout << s << endl;

    #ifdef LOCAL
        #if __cplusplus >= 201103L
        auto end = steady_clock::now();
        duration<double> time_span = duration_cast<duration<double>>(end - start);;
        printf("Total time: %.6fs\n", time_span.count());
        #endif
    #endif
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int a = sc.nextInt();
      int b = sc.nextInt();
      int cnt1 = 0;
      int cnt2 = 0;
      int cnt3 = 0;
      for(int i = 0;i < n;i++){
      	int p = sc.nextInt();
        if(p <= a)cnt1++;
        else if(a < p&&p <= b)cnt2++;
        else cnt3++;
      }
      System.out.println(Math.min(cnt1,Math.min(cnt2,cnt3)));
    }
}


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

int main() {
	
	int f=0;
	int k;
	cin >> k;
	vector<int>x(k),y(k);
	for(int i=0; i<k; i++) cin >> x.at(i) >> y.at(i);
	vector<int>a(8),b(8);
	for(int i=0; i<8; i++) a.at(i)=i, b.at(i)=i;
	do{
		do{
			int cnt = 0;
			for(int j=0; j<k; j++){
				for(int i=0; i<8; i++){
					if((x.at(j)==a.at(i) && y.at(j)==b.at(i))) cnt++;
				}
			}
			if(cnt<k) continue;
			bool flg = 1;
			for(int i=0; i<7; i++){
				for(int j=i+1; j<8; j++){
					if((a.at(i)-a.at(j)==b.at(i)-b.at(j))||(a.at(i)-a.at(j)==b.at(j)-b.at(i)))flg=0;
				}
			}
			if(flg){
				for(int i=0; i<8; i++){
					for(int j=0; j<8; j++){
						bool flg2=0;
						for(int k=0; k<8; k++){
							if(a.at(k)==i && b.at(k)==j) flg2=1;
						}
						if(flg2) cout << 'Q';
						else cout << '.';
					}
					cout << endl;
				} 
				return 0;
			}
		}while(next_permutation(b.begin(),b.end()));
	}while(next_permutation(a.begin(),a.end()));
	
}


Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define ld long double
typedef pair<ll,ll> P;
#define boost ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0);
bool comp(pair<ll,ll> p1,pair<ll,ll> p2)
{
    if(p1.first<p2.first)
    return true;
    else if(p1.first==p2.first && p1.second>=p2.second)
    return true;
    return false;
}
int main()
{
   ll n,w,i,a,b,j;
   cin>>n>>w;
   vector<pair<ll,ll>> V;
   for(i=0;i<n;i++)
   {
       cin>>a>>b;
       V.push_back(make_pair(a,b)); 
   }
   sort(V.begin(),V.end());
   ll DP[n+1][w+1];
   memset(DP,0,sizeof(DP)); 
   for(i=1;i<=n;i++)
   {
       for(j=1;j<=w;j++)
       {
           if(j>=V[i-1].first)
           {DP[i][j]=max(max(DP[i-1][j],DP[i][j-1]),V[i-1].second+DP[i-1][j-V[i-1].first]);}
           else
            {DP[i][j]=max(DP[i-1][j],DP[i][j-1]);}
       }
   }
   /*
   for(i=0;i<=n;i++)
   {
   for(j=0;j<=w;j++)
   {
       cout<<DP[i][j]<<" ";
   }
   cout<<endl;
   } */
   cout<<DP[n][w]<<endl;
}


Measured memory_bytes: 79104
#ALDS1_3-C Elementary data structures - Doubly Linked List
import collections
q = collections.deque()
cmds={"insert":lambda cmd: q.appendleft(cmd[1]),
      "delete":lambda cmd: q.remove(cmd[1]) if (q.count(cmd[1]) > 0) else "none",
      "deleteFirst":lambda cmd: q.popleft(),
      "deleteLast": lambda cmd: q.pop()
     }

n=int(input())
for i in range(n):
    cmd=input().split()
    cmds[cmd[0]](cmd)
print(*q)

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

typedef struct _dataset_st
{
    char str[202];
    int h_total;
} dataset_st;

#define BUFFSIZE 202

int main(int argc, char *argv[])
{
    dataset_st datasets[10] = {};
    int dataset_count = 0;
    for (char line[BUFFSIZE]; dataset_count < 10 && fgets(line, BUFFSIZE, stdin) && strtok(line, "\n") && strcmp(line, "-"); ++dataset_count)
    {
        strtok(line, "\n");
        strcpy(datasets[dataset_count].str, line);
        int total = 0;
        fgets(line, BUFFSIZE, stdin);
        int m;
        sscanf(line, "%d", &m);
        for (int i = 0; i < m; ++i)
        {
            fgets(line, BUFFSIZE, stdin);
            int h;
            sscanf(line, "%d", &h);
            total += h;
        }
        datasets[dataset_count].h_total = total;
    }
    for (dataset_st *elm = datasets, *const end = elm + dataset_count; elm != end; ++elm)
    {
        const int len = strlen(elm->str);
        for (int i = elm->h_total % len, end = i + len; i < end; ++i)
        {
            printf("%c", elm->str[i % len]);
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2140
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main()
{
	ll n;
	while ((n = in()) != -1) {
		double x = 1, y = 0, theta = 0;
		REP(i, n - 1) {
			double ox = x, oy = y;
			x -= sin(theta);
			y += cos(theta);
			theta += atan(1 / hypot(ox, oy));
		}
		SETP(10);
		cout << x << endl;
		cout << y << endl;
	}
}


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

using namespace std;
#define ll long long
#define mod 1000000007

ll v[22][22], n, dp[22][5000000];

ll f(ll i, ll mask) {
    if (i == n) {
        return 1;
    }

    if (dp[i][mask] != -1) return dp[i][mask];

    ll ans = 0;
    for (ll j = 0; j < n; j++) {
        if (v[i][j] == 1 && (mask & (1 << j)) == 0) {
            ans += f(i + 1, mask | (1 << j));
            ans %= mod;
        }
    }
    dp[i][mask] = ans;
    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(dp, -1, sizeof(dp));

    cin >> n;

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

    cout << f(0, 0);
}


Measured memory_bytes: 863008
def dist_int?(x, y)
    a = x.zip(y).map{|xi, yi| (xi - yi) ** 2 }.inject(&:+)
    Math.sqrt(a).floor ** 2 == a
end

N, D = gets.chomp.split(" ").map(&:to_i)
x = []
N.times do 
    x << gets.chomp.split(" ").map(&:to_i)
end

ans = 0
for i in 0..N-1
    for j in i+1..N-1
        ans += 1 if dist_int?(x[i], x[j])
    end
end
puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;

int main() {
  int h, w, n, m, c=0, d=0, e=0;
  cin >> h >> w;
  int a[w], b[h];
  char s[h][w]={}, ss[h][w]={}, sss[h][w]={};
  rep(i,0,h){
    rep(j,0,w){
      cin >> s[i][j];
    }
  }
  
  rep(i,0,h){
    c=0;
    rep(j,0,w) if(s[i][j]=='.') c++;
    a[i]=c;
  }
  rep(i,0,w){
    c=0;
    rep(j,0,h) if(s[j][i]=='.') c++;
    b[i]=c;
  }
  rep(i,0,h){
    rep(j,0,w){
      if(a[i]!=w && b[j]!=h) cout << s[i][j];
    }
    if(a[i]!=w) cout << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
    init();

	string s, t; cin >> s >> t;
	int a, b; cin >> a >> b;
	string u; cin >> u;
	if (s == u)--a;
	else --b;
	cout << a << " " << b << "\n";

    return 0;
}

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

/**
 * 解説どおりに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc103/submissions/15700130 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			Pair[] pairs = new Pair[m];
			IntStream.range(0, m).forEach(i -> pairs[i] = new Pair(scanner.nextInt() - 1, scanner.nextInt() - 1));
			Arrays.sort(pairs);
			int count = 1, current = pairs[0].b;
			for (int i = 1; i < m; i++) {
				if (pairs[i].a >= current) {
					current = pairs[i].b;
					count++;
				}
			}
			System.out.println(count);
		}
	}

	/**
	 * aとbを格納するクラス
	 */
	private static class Pair implements Comparable<Pair> {
		int a;
		int b;

		Pair(int a, int b) {
			super();
			this.a = a;
			this.b = b;
		}

		@Override
		public int compareTo(Pair pair) {
			return Integer.compare(this.b, pair.b);
		}
	}
}


Measured memory_bytes: 62660
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;

int main()
{
    int n;
    int i, judge = 1;
    string s;
    
    cin >> s;
    
    n = s.size();
    
    int a[n];
    
    for(i = 0; i < n; i++) {
        a[i] = int(s[i]);
    }
    
    sort(a, a+i);
    
    for(i = 0; i < n-1; i++) {
        if(a[i] == a[i+1]) {
            judge = 0;
        }
    }
    
    if(judge == 1) {
        cout << "yes\n";
    } else {
        cout << "no\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int numMagic = 0;
		int continuity = 1;
		int prevColor = in.nextInt();
		for(int i=1;i<n;i++) {
			int nowColor = in.nextInt();
			if(prevColor==nowColor) {
				continuity++;
			}else {
				numMagic += continuity/2;
				continuity = 1;
				prevColor = nowColor;
			}
		}
		numMagic += continuity/2;
		System.out.println(numMagic);
	}

}

Measured memory_bytes: 23764
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
 
class Main
{
	static class Pair
	{
		int first, second;
		public Pair(int f, int s)
		{
			first = f;
			second = s;
		}
		
		public String toString()
		{
			return first + " " + second;
		}
	}
	
	static class PairComparator implements Comparator <Pair>
	{
		public int compare(Pair p1, Pair p2)
		{
			if(p1.first < p2.first)
				return -1;
			if(p1.first > p2.first)
				return 1;
			if(p1.second < p2.second)
				return -1;
			if(p1.second > p2.second)
				return 1;
			return 0;
		}
	}
	
	static int log2(double a)
	{
		return (int)(Math.log(a) / Math.log(2));
	}
	
	static long gcd(long a, long b)
	{
		long r;
		while((r = a % b) > 0)
		{
			a = b;
			b = r;
		}
		return b;
	}
	
	static class TrieNode
	{
		TrieNode z, o;
		boolean end;
		long count;
		
		public TrieNode()
		{
			 z = null;
			 o = null;
			 count = 0;
			 end = false;
		}
	}
	
	public static void main(String[] args) throws IOException
	{
		long n = in.nextLong();
		long a = in.nextLong();
		sop(n * n - a);
	}
    
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader()
        {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt()
        {
            return Integer.parseInt(next());
        }
 
        long nextLong()
        {
            return Long.parseLong(next());
        }
 
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
 
        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
	
    static FastReader in = new FastReader();
  
    public static void sop(Object o)
    {
    	System.out.print(o);
    }
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n;
    cin >> n;
    ll t = 0;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
        t ^= a[i];
    }
    rep(i, n) {
        if(i) cout << " ";
        ll ans = a[i] ^ t;
        cout << ans;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
typedef pair<int,int> P;
typedef long long ll;
const int INF = 1001001001;
const ll INFL = 1e17;
const int MOD = 1e9+7;


int main(){
    ll n;
    cin >> n;
    ll zmin=INFL,zmax=-INFL,wmin=INFL,wmax=-INFL;
    for(ll i=0; i<n; i++){
        ll x,y;
        cin >> x >> y;
        zmin = min(zmin,x+y);
        zmax = max(zmax,x+y);
        wmin = min(wmin,x-y);
        wmax = max(wmax,x-y);
    }
    ll ans = max(zmax-zmin,wmax-wmin);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
n = gets.to_i
d, x = gets.split.map(&:to_i)
a = n.times.map{ gets.to_i }

sum = 0
a.each do |i|
    d.times do |j|
        hoge = (i * j) + 1
        break if hoge > d
        sum += 1
    end
end
puts sum + x

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define INF 2000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string S;
  cin >> S;
  if (S.at(S.size() - 1) == 's') {
    S += 'e';
  }
  S += 's';
  cout << S << "\n";
}


Measured memory_bytes: 3660
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int N, M;
string S;
string T;
int dp[2002][2002][2];
int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N >> M;
	cin >> S;
	cin >> T;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			dp[i][j][0] = -1;
			dp[i][j][1] = -1;
		}
	}
	reverse(S.begin(), S.end());
	reverse(T.begin(), T.end());
	//cout << S << endl;
	//cout << T << endl;
	S = '(' + S;
	T = 'T' + T;
	if (S[1] == 'I')dp[1][0][1] = 1;
	if (T[1] == 'I')dp[0][1][1] = 1;
	for (int i = 1; i < N + M; i++) {
		for (int j = max(0, i - M); j <= min(i, N); j++) {
			//	cout << i << " " << j << endl;
			if (S[j + 1] == 'O')dp[j + 1][i - j][0] = max({ dp[j + 1][i - j][0], dp[j][i - j][1] + 1 ,0 });
			else dp[j + 1][i - j][1] = max({ 1, dp[j + 1][i - j][1], dp[j][i - j][0] + 1 });
			if (T[i - j + 1] == 'O')dp[j][i - j + 1][0] = max({ dp[j][i - j + 1][0], dp[j][i - j][1] + 1 ,0 });
			else dp[j][i - j + 1][1] = max({ 1, dp[j][i - j + 1][1] ,dp[j][i - j][0] + 1 });
		}
	}
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j <= M; j++) {
			ans = max(ans, dp[i][j][1]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 34508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int  main()
{
	int n,a,b; cin >> n >> a >> b;
	int tr = a * n;
	int tx = b;
	cout << min(tr, tx) << endl;
	return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define MOD 1000000007
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
ll int power(ll int x, ll int y, ll int p)  
{  
   ll int res = 1;     // Initialize result  
 
    x = x % p; // Update x if it is more than or  
                // equal to p
   
    if (x == 0) return 0; // In case x is divisible by p;
 
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
 
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  

int main()
{
   ll int T;
T=1;


    while(T--)
    {
      ll int n;
      cin>>n;
       ll int ans = 1ll,tans=1ll,tans1=1ll;
       if(n<2)
        {cout<<0<<endl;continue;}
      ll int i;
      for(i=1;i<=n;i++)
        {ans*=10;ans%=MOD;}
      for(i=1;i<=n;i++)
      {
        tans*=9;tans%=MOD;tans1*=8;tans1%=MOD;
      }
    //  cout<<tans<<tans1<<endl;
      tans*=2;
      tans%=MOD;
      ans-=tans;
      ans+=MOD;
      ans%=MOD;
      ans+=tans1;
      ans%=MOD;
      


     
      cout<<ans<<endl;
     
    }

    return 0;
       }

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

int main(void) {
  char s[256];
  scanf( "%s", s);
  if( strstr( s, "ABC") ) { printf( "ARC\n" ); }
  else if( strstr( s, "ARC") ) { printf( "ABC\n" ); }
}

Measured memory_bytes: 1660
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD =1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////

ll iv(ll i) {
	if (i == 1) { return 1; }
	return MOD - iv(MOD%i)*(MOD / i) % MOD;
}

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

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

ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


int main() {
	COMinit();

	ll B, W;
	cin >> B >> W;

	ll all = 1;
	ll beat = 0;
	ll weat = 0;

	repn(i, B + W) {
		ll bo = all * 2%MOD;
		ll si = (all - beat + weat)%MOD;
		if (si < 0) { si += MOD; }
		cout << si * iv(bo) % MOD<<endl;

		all = (all * 2)%MOD;
		beat = (beat * 2 + COM(i - 1, B - 1))%MOD;
		weat = (weat * 2 + COM(i - 1, W - 1))%MOD;
	}

	system("PAUSE");
}


Measured memory_bytes: 25848
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let n = Int(readLine()!)!
    var upper = readInts()
    var middle = readInts()
    var lower = readInts()
    var ans = 0
    //_______________________________ここまで入力
    upper.sort()
    middle.sort()
    lower.sort()  { $0 > $1 }
    
    var (uR, lR) = (0, n - 1)
    
    for i in 0..<n {
        while uR < n && middle[i] > upper[uR] {
            uR += 1
        }
        while lR >= 0 && middle[i] >= lower[lR] {
            lR -= 1
        }
        ans += uR * (lR + 1)
    }
    
    print(ans)
}
main()


Measured memory_bytes: 22900
/*input
2
9
3 6
*/

#include <bits/stdc++.h>
using namespace std;

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 200003

long  divisors(long x) {
    long limit = x;
    long numberOfDivisors = 0;

    if (x == 1) return 1;

    for (long i = 1; i < limit; ++i) {
        if (x % i == 0) {
            limit = x / i;
            if (limit != i) {
                numberOfDivisors++;
            }
            numberOfDivisors++;
        }
        if(numberOfDivisors>=4)
        {
            break;
        }
    }

    return numberOfDivisors;
}
 bool isPrime(long n)
{
   
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (long i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
#define max_a 100001
bool visit[max_a]={false};
vector<long> a[max_a];
long sum=0;
long cost[max_a];
void dfs(long node)
{
    visit[node]=true;
    
    for(int i=0;i<(int)a[node].size();i++)
    {
        if(visit[a[node][i]]==false)
        {
            sum+=cost[a[node][i]];
            dfs(a[node][i]);
            
        }
    }
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int k;
    cin>>k;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int val;
        cin>>val;
        ans+=2*(min(val,abs(val-k)));
    }
    cout<<ans;
    return 0;
}




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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
    int N,K; cin>>N>>K;
    vector<ll> V(N); rep(i,N)cin>>V.at(i);
    ll res = 0;
    for(int l = 0; l <= min(N,K); l++){
        for(int r = 0; l+r <= min(N,K); r++){
            vector<ll> T;
            rep1(i,l)T.push_back(V.at(i-1));
            rep1(i,r)T.push_back(V.at(N-i));
            sort(T.begin(),T.end());
            int deq = K - l - r;
            int s = T.size();
            rep(i,min(deq,s)){
                if(T.at(i)<0)T.at(i)=0;
                else break;
            }
            ll now = 0;
            for(auto i: T){
                now += i;
            }
            res = max(res,now);
        }
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
vector<int> c(26);
vector<vector<int>> s(365, vector<int>(26, 0));
vector<int> last(26, -1);
int main() {
    int d;
    cin >> d;
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int> t(d, -1);
    int score = 0;
    for(int i = 0; i < d; i++) {
        for(int j = 0; j < 26; j++) {
            score -= c[j] * (i - last[j]);
        }
        int ind = -1;
        int tmp = score;
        for(int k = 0; k < 26; k++) {
            if(tmp < score + s[i][k] + c[k] * (i - last[k])) {
                ind = k;
                tmp = score + s[i][k] + c[k] * (i - last[k]);
            }
        }
        t[i] = ind;
        last[t[i]] = i;
        score = tmp;
    }
    for(int i = 0; i < d; i++) {
        cout << t[i] + 1 << endl;
    }
}

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

typedef long long int ll;

int main(void) {
	int n, a;
	vector<int> x;
	ll ans;

	cin >> n >> a;
	x.resize(n);
	for (int i = 0; i < n; ++i)
		cin >> x[i];

	vector<ll> v(n * a + 1, 0);
	vector< vector<ll> > vv(n + 1, v);
	vector< vector< vector<ll> > > dp(n + 1, vv);
	dp[0][0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j <= i; ++j) {
			for (int k = 0; k <= n * a; ++k) {
				if (k + x[i] <= n * a)
					dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
				dp[i + 1][j][k] += dp[i][j][k];
			}
		}
	}

	ans = 0;
	for (int i = 1; i <= n; ++i)
		ans += dp[n][i][a * i];
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 52224
#include <iostream>
#include <algorithm>

using namespace std;

int tanri(int y, int A, int fee, double rate){
    int sum = 0;
    for(int i=0; i < y; i++){
        sum += (int)A*rate;
        A -= fee;
    }
    return A+sum;
}

int hukuri(int y, int A, int fee, double rate){
    for(int i=0; i < y; i++){
        A += (int)(A*rate)-fee;
    }
    return A;
}

int main(){
    int n;
    cin >> n;
    for(int p=0; p < n; p++){
        long long money;
        cin >> money;
        int y, m;
        cin >> y >> m;

        int res = 0;
        for(int i=0; i < m; i++){
            int s, fee;
            double rate;
            cin >> s >> rate >> fee;
            if(s == 0) res = max(res, tanri(y, money, fee, rate));
            else res = max(res, hukuri(y, money, fee, rate));
        }
        cout << res << endl;
    }
}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    int N; cin >> N;
    int mn = INF;
    int sum = 0;
    for(int i=0; i<N; i++){
        int a; cin >> a;
        if(a%10!=0) mn = min(a, mn);
        sum += a;
    }
    
    int ans = sum;
    if(ans%10 == 0){
        if(mn==INF) ans = 0;
        else ans = ans - mn;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

import java.lang.*;

import java.math.*;



public class Main {

	Scanner sc = new Scanner(System.in);



	void run() {

		int[] fd = new int[180];

		int[] fd2 = new int[180];

		int k=0;

		for (int i = 1, j = 0; i * (i + 1) * (i + 2) / 6 < 1000000; i++, j++) {

			fd[j] = i * (i + 1) * (i + 2) / 6;

			if ((fd[j] & 1) == 1) {

				fd2[k] = fd[j];

				k++;

			}

		}

		fd2 = Arrays.copyOfRange(fd2,0 , k);

		

		int dp[] = new int[1000000];

		int dp2[] = new int[1000000];

		Arrays.fill(dp, Integer.MAX_VALUE);

		Arrays.fill(dp2, Integer.MAX_VALUE);

		dp[0] = dp2[0] = 0;

//		System.out.println(Arrays.toString(fd));

//		System.out.println(Arrays.toString(fd2));

		for (int i = 0; i < 1000000; i++) {

			if (dp[i] == Integer.MAX_VALUE)

				continue;

			for (int j = 0; j < fd.length; j++) {

				if (i + fd[j] >= 1000000)

					break;

				dp[i + fd[j]] = Math.min(dp[i] + 1, dp[i + fd[j]]);

			}

		}

		for (int i = 0; i < 1000000; i++) {

			if (dp2[i] == Integer.MAX_VALUE)

				continue;

			for (int j = 0; j < fd2.length; j++) {

				if (i + fd2[j] >= 1000000)

					break;

				dp2[i + fd2[j]] = Math.min(dp2[i] + 1, dp2[i + fd2[j]]);

			}

		}



		for (;;) {

			int n = sc.nextInt();

			if (n == 0)

				break;

			System.out.println(dp[n] + " " + dp2[n]);

		}

	}



	public static void main(String[] args) {

		Main m = new Main();

		m.run();

	}

}

Measured memory_bytes: 20000
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    ll i = 0;
    while ((i+1)*(i+2)/2 <= n) i++;
    int m = n-i*(i+1)/2;
    REP(j,i-m) cout << j+1 << " ";
    REP(j,m) cout << i-m+j+2 << " ";
    cout << endl;

    return 0;
}

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int a = 0, b = 0;
    for (int i = 0; i < N; i++) {
        if(S[i] == 'R')a++;
        else b++;
    }
    cout << ((a > b) ? "Yes" : "No") << endl;
    return 0;
}

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

#pragma GCC optimize "O3"
#define rep(i,a,n) for(int i=a; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

int main(void){
   long double a,b; cin >> a >> b;
   ll c = a*b;
   cout << c << "\n";
}

Measured memory_bytes: 3732
fun main(args: Array<String>) {
  val sRaw = readLine()!!
  val n = sRaw.length
  val s = sRaw + "$$$"
  var from = 0
  var ans = 0L
  while (from < n) {
    if (s[from] != 'A') {
      from++
      continue
    }
    var inclusiveTo = from
    while (true) {
      if (s[inclusiveTo + 1] == 'A') {
        inclusiveTo++
        continue
      } else if (s[inclusiveTo + 1] == 'B' && s[inclusiveTo + 2] == 'C') {
        inclusiveTo += 2
        continue
      }
      break
    }
    // println("$from $inclusiveTo")
    val aIndexSum = (from..inclusiveTo).filter { s[it] == 'A' }.map { it.toLong() }.sum()
    val aCount = (from..inclusiveTo).count { s[it] == 'A' }
    val aIndexSumAfter = ((inclusiveTo - aCount + 1)..inclusiveTo).map { it.toLong() }.sum()
    ans += (aIndexSumAfter - aIndexSum) / 2
    from = inclusiveTo + 1
  }
  println(ans)
}

Measured memory_bytes: 53564
#include <stdio.h>

#define MAX 100000

int n, k;
double T[MAX];

int check(double p){
  int i=0, j;
  double s;
  for(j=0; j<k; j++){
    s=0.0;
    while(s+T[i] <= p){
      s+=T[i];
      i++;
      if(i==n) return n;
    }
  }
  return i;
}

int solve(){
  double left=0.0;
  double right=100000*10000;
 double mid;
  int v;

  while(right - left > 1){
    mid=(left+right)/2;
    v=check(mid);
    if(v>=n) right=mid;
    else left=mid;
  }
  return right;
}

int main(){
  int i;
  double ans;
  scanf("%d%d",&n, &k);
  for(i=0; i<n; i++) scanf("%lf",&T[i]);
  ans=solve();
  printf("%d\n",(int)ans);

  return 0;
}

Measured memory_bytes: 1416
#include<iostream>

const int N = 10000;

int main(){
  int n;
  int n_min = 1000000;
  int n_max = -1000000;
  long long sum = 0;
  
  std::cin >> n;
  for(int i = 0; i < n; i++){
    int t;
    std::cin >> t;

    if(t < n_min) n_min = t;
    if(t > n_max) n_max = t;
    sum += t;
  }

  std::cout << n_min << " " << n_max << " " << sum << std::endl;

  return 0;
}



Measured memory_bytes: 3100
checkKaibun :: String -> Bool
checkKaibun [x] = True
checkKaibun [x, y] = x == y
checkKaibun (x:y:xs) = (x == last xs) && checkKaibun (y : init xs)

firstPart n = take ((n - 1) `div` 2)
lastPart n = drop (((n + 3) `div` 2) - 1)

solve x = checkKaibun x && (checkKaibun $ firstPart len x) && (checkKaibun $ lastPart len x)
            where 
              len = length x
main = do 
  s <- getLine
  putStrLn $ if solve s then "Yes" else "No"

Measured memory_bytes: 636