akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

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

        //out.print("AMan");
        int n = sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++) {
            a[i] = sc.nextInt();
        }
        int dp[] = new int[n];
        Arrays.fill(dp,(int)1e9+7);
        dp[0]=0;
        for(int i=0;i<n;i++) {
            if(i+1<n) dp[i+1] = Math.min(dp[i+1],dp[i]+Math.abs(a[i+1]-a[i]));
            if(i+2<n) dp[i+2] = Math.min(dp[i+2],dp[i]+Math.abs(a[i+2]-a[i]));
        }
        out.println(dp[n-1]);

        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public boolean ready() throws IOException {
            return br.ready();
        }
    }
}

Measured memory_bytes: 31420
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		char[] c1 = s.toCharArray();
		char[] c2 = t.toCharArray();
		Character[] c3 = new Character[t.length()];
		for(int i = 0 ; i < t.length() ; i++) {
			c3[i] = c2[i];
		}
		Arrays.sort(c1);
		Arrays.sort(c3, Comparator.reverseOrder());
		for(int i = 0 ; i < t.length() ; i++) {
			c2[i] = c3[i];
		}

		if(String.valueOf(c1).compareTo(String.valueOf(c2)) < 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

//		System.out.println();

		sc.close();

	}

}


Measured memory_bytes: 23380
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N; cin >> N;
	vector<LLONG> as(N); for (auto &ai : as) cin >> ai;
	sort(as.begin(), as.end(), greater<LLONG>());
	// 各スポットで取得できる心地よさaとスポット数のマップ
	map<LLONG, int, greater<LLONG>> a2numMap{ {as.front(), 1} };
	LLONG ans = 0;
	for (int i = 1; i < N; ++i)
	{
		// 新しくaiを入れることでスポットが２箇所できる
		LLONG ai = as[i];
		a2numMap[ai] += 2;
		// スポットのうち最も心地よさが高くなるスポットを使う
		auto itr = a2numMap.begin();
		ans += itr->first;
		itr->second -= 1;
		// 最も心地よさが高いスポットが空になったらマップから削除
		if (itr->second == 0)
		{
			a2numMap.erase(itr);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11156
#include <bits/stdc++.h>
using namespace std;
const int N=3e3;
double p[N];
double cache[N][N];
bool vis[N][N];
int n;


double dp(int idx,int count)
{
    if(idx==n+1)
    return (count*2>=n);
    double &ans=cache[idx][count];
    if(vis[idx][count])
    return ans;
    vis[idx][count]=1;
    ans=p[idx]*dp(idx+1,count+1)+(1-p[idx])*dp(idx+1,count);
    return ans;
}
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    cin>>p[i];
    memset(vis,false,sizeof(vis));
    double ans=dp(1,0);
    cout<<fixed<<setprecision(12)<<ans;
    return 0;
}

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

int main() {
  int n = 5;
  vector<int> a(n);
  for (auto &e : a) {
    cin >> e;
  }
  int r = 0, d = 0;
  for (auto e : a) {
    r += ((e - 1) / 10 + 1) * 10;
    d = max(d, 9 - (e - 1) % 10);
  }
  cout << r - d << endl;
}


Measured memory_bytes: 256
// The moment you think of giving up you have already lost the battle
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
typedef long double dl;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }

    }
}
int main()
{
   string S,T;
   int i,j;
   int ans=1e7;
   cin>>S>>T;
   int n,m;
   n=S.length();
   m=T.length();
   for(i=1;i<=n-m+1;i++)
   {
       int cnt=0,pos=0;
       for(j=i;j<=i+m-1;j++)
       {
           if(S[j-1]!=T[pos])
            cnt++;

           pos++;
       }
       ans=min(ans,cnt);

   }
   cout<<ans;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> pass(n + 2);
    for (int i = 0; i < m; ++i) {
        int l, r;
        cin >> l >> r;
        pass[l]++; pass[r + 1]--;
    }
    vector<int> sum(n + 1);
    sum[0] = pass[0];
    for (int i = 1; i <= n; i++) {
        sum[i] = sum[i - 1] + pass[i];
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (sum[i] == m) ans++;
    }
    cout << ans << endl;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int x;

main() {
    cin >> x;
    if (x<1200) ct("ABC")
    else ct("ARC")
}



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

int main(){
  int n,k; cin>>n>>k;
  vector<int> h(n);
  for(int i=0;i<n;++i){
    cin>>h[i];
  }

  vector<int> dp(n, 1e9+1);
  dp[0] = 0;
  for(int i=0;i<n;++i)
    for(int j=0;j<=k;++j)
      if(i-j>=0) dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));

  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int gcd(int a,int b){int r,tmp;if(a < b){tmp = a;a = b;b = tmp;}r = a % b;while(r != 0){a = b;b = r;r = a % b;}return b;}
int lcm(int a,int b){int r;r = gcd(a,b);r = a / r * b;return r;}

int main()
{
    int n,a[100000],i,j;

    scanf("%d",&n);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }

    int r = a[0];
    for (i = 1; i < n; i++)
    {
        r = gcd(r,a[i]);
    }
    printf("%d",r);
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = 0; i < (a); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define fst first
#define snd second
#define pf push_front
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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

  int n, ma, mb;
  cin >> n >> ma >> mb;
  VI a(n), b(n), c(n);
  vector<vector<vector<int> > > dp(402, VVI(402, VI(n, 10000)));
  rep(i, n) cin >> a[i] >> b[i] >> c[i];

  dp[a[0]][b[0]][0] = c[0];
  rep(i, n-1){
    rep(j, 401){
      rep(k, 401){
        if(j - a[i+1] >= 0 && k - b[i+1] >= 0) dp[j][k][i+1] = min(dp[j][k][i+1], min(dp[j][k][i], dp[j - a[i+1]][k - b[i+1]][i] + c[i+1]));
        else  dp[j][k][i+1] = min(dp[j][k][i+1], dp[j][k][i]);
      }
    }
    dp[a[i+1]][b[i+1]][i+1] = min(dp[a[i+1]][b[i+1]][i+1], c[i+1]);
  }
  int ans = 10000;
  rep(i, 401){
    rep(j, 401){
      if(j * ma == i * mb) ans = min(ans, dp[i][j][n-1]);
    }
  }
  ans == 10000 ? cout << -1 << endl : out(ans);
  return 0;
}


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

const int maxn = 4e3 + 3;

typedef long long ll;

int n;
char s[maxn];
ll ans, cnta[maxn][3];

int rh(char a) {
    return a == 'R' ? 0 : a == 'G' ? 1 : 2;
}

int main() {
    scanf("%d%s", &n, s);
    for(int j = 0; j < n; ++j) {
        for(int i = 0; i < j; ++i) {
            int k = j + (j - i);
            if(k < 0 || k >= n)
                continue;
            if(s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
                ans -= 1;
            }
        }
    }
    for(int j = n - 1; j >= 0; --j) {
        for(int k = n - 1; k > j; --k) {
            if(s[j] != s[k]) {
                cnta[j][rh(s[k])] += 1;
            }
        }
    }
    for(int i = n - 1; i >= 0; --i) {
        for(int j = n - 1; j > i; --j) {
            if(s[i] != s[j]) {
                ans += cnta[j][3 - rh(s[i]) - rh(s[j])];
            }
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 3924
#include <vector>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <map>
#include <unordered_map>
#include <ctime>
#include <cassert>
#include <cstring>
#include <sys/time.h>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]){
  int h, n;
  cin >> h >> n;
  vector<int> a;
  for(int i=0;i<n;i++){
    int ai;
    cin >> ai;
    a.push_back(ai);
  }
  int sum = 0;
  for(int i=0;i<n;i++){
    sum += a[i];
  }
  if(h<=sum){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 892
package main

import (
	"fmt"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)
	var h = make([]int, n)
	var c = 0
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}
	for i := 0; i < n; i++ {
		if k <= h[i] {
			c++
		}
	}
	fmt.Printf("%v", c)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(long long &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const long long &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
int n, w_cap, w[100], v[100];
long long dp[100][1000 * 100 + 1];
long long calc(int i, int v_sum) {
	if(i >= n) return v_sum == 0 ? 0 : INT_MAX;
	if(dp[i][v_sum] != -1) return dp[i][v_sum];
	long long res = calc(i + 1, v_sum);
	if(v[i] <= v_sum) res = min(res, calc(i + 1, v_sum - v[i]) + w[i]);
	return dp[i][v_sum] = res;
}
int main() {
	R(n, w_cap);
	for(int i = 0; i < n; i++) R(w[i], v[i]);
	memset(dp, -1, sizeof(dp));
	int ans = INT_MIN;
	for(int i = 0; i <= 1000 * n; i++) {
		if(calc(0, i) <= w_cap) ans = i;
	}
	W(ans);
	return 0;
}

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

int main()
{
  int n;
  while(cin>>n && n){
    vector<int> taro, hanako;
    for(int i = 0; i < n; i++){
      int buf;
      cin>>buf;
      taro.push_back(buf);
    }
    sort(taro.begin(), taro.end());
    vector<int>::iterator it;  
    for(int i = 0; i < 2*n; i++){
      if(!binary_search(taro.begin(), taro.end(), i+1)) hanako.push_back(i+1);
    }
    //sort(hanako.begin(), hanako.end());

    /*cout<<"hanako card"<<endl;
    for(int i = 0; i < hanako.size(); i++)
      cout<<hanako[i]<<endl;
    cout<<"hanako end "<<endl;
    */
    int card = 0;
    while(1){//!taro.empty() && !hanako.empty()){
      it = upper_bound(taro.begin(), taro.end(), card);
      if(it != taro.end()){
	//cout<<"taro "<<(*it)<<endl;
	card = (*it);
	taro.erase(it);
      }else{
	//cout<<"taro pass"<<endl;
	card = 0;
      }
      if(taro.empty()) break;
      it = upper_bound(hanako.begin(), hanako.end(), card);
      if(it != hanako.end()){
	//cout<<"hanako "<<(*it)<<endl;
	card = (*it);
	hanako.erase(it);
      }else{
	//cout<<"hanako pass"<<endl;
	card = 0;
      }
      if(hanako.empty()) break;
    }
    if(taro.empty()) cout<<hanako.size()<<endl<<0<<endl;
    else cout<<0<<endl<<taro.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define pb push_back
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define pll pair<ll,ll>
#define pii pair<int,int>
#define F first
#define S second
const int maxn = 2e5 + 5;
const double eps = 1e-9;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll a, b, c;
    while(cin >> a >> b >> c) {
        if (a + b >= c) {
            cout << "No\n";
            continue;
        }
        ll dif1 = (c - a - b) * (c - a - b);
        ll dif = a * b * 4;
        if (dif >= dif1) {
            cout << "No\n";
        }
        else {
            cout << "Yes\n";
        }
    }
}


Measured memory_bytes: 256
#
# File    : D.rb
# Author  : Kazune Takahashi
# Created : 12/8/2018, 9:19:27 PM
# Powered by Visual Studio Code
#

n, x = gets.chomp.split(" ").map{|i| i.to_i}

@l = Array.new(51)
@q = Array.new(51)

@l[0] = 1
@q[0] = 1

for i in 1...51
  @l[i] = 3 + 2 * @l[i - 1]
  @q[i] = 1 + 2 * @q[i - 1]
end

def calc(y, k)
  if k == 0
    return y
  end
  if y <= 1
    return 0
  elsif y <= @l[k] / 2
    return calc(y - 1, k - 1)
  elsif y == @l[k] / 2 + 1
    return @q[k - 1] + 1
  elsif y <= @l[k] - 1
    return @q[k - 1] + 1 + calc(y - @l[k]/2 - 1, k - 1)
  else
    return 2 * @q[k - 1] + 1
  end
end

puts calc(x, n)


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

int main(){
//x + Y + Z = S →　Z = S - Y - X  

int K, S;
cin >> K >> S;

int cnt = 0;
for(int y = 0; y <= K; y++){ 
   for(int x = 0; x <= K ; x++){ 
   	int Z = S - y - x;
     if(Z >= 0 && Z <= K) cnt++;
   }
}
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
string s;
long long k , len , sol , sum;
char c;
vector<long long>v;
int main(){
	cin >> s;
	cin >> k;
	c = s[0];
	sum = 0;
	for(int i = 0 ; i < s.size() ; i++){
		if(s[i] == c){
			len++;
		}
		if(s[i] != c || i == s.size() - 1){
			v.pb(len);
			len = 1;
			c = s[i];
		}
	}
	if(v.size() == 1){
		sum = v[0];
		sol = (sum*k)/2;
	}
	else if(s[0] == s[s.size() - 1]){
		for(int i = 1 ; i < v.size() - 1 ; i++){
			sol += v[i]/2;
		}
		sol *= k;
		sum += (v[0] + v[v.size() - 1])/2;
		sum *= (k - 1);
		sol += sum;
		sol += (v[0]/2) + (v[v.size() - 1]/2);
	}
	else{
		for(int i = 0 ; i < v.size() ; i++){
			sol += v[i]/2;	
		}
		sol *= k;
	}
	cout << sol << endl;
}

Measured memory_bytes: 3652
#include <iostream>

using namespace std;

int n;
int p[100005];
bool used[100005];

bool check(int i)
{
	do{
		used[i] = true;
		i = p[i];
	}while(!used[i]);
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	int r, c;
	for(int i = 1; i <= n; i++){
		cin >> r >> c;
		if(p[r]){
			cout << -1 << endl;
			return 0;
		}
		p[r] = c;
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		if(!used[i]) ans++, check(i);
	}
	cout << n - ans << endl;
	
	return 0;
}


Measured memory_bytes: 3616
N=input()

l=len( str(N) )

s="357"

P=[ set() for i in range(l+1) ]   #Pattern
P[0].add(0)

for i in range(1,l+1):
	k=l-i	#keta
	for x in P[i-1]:
		for j in s:
			j=int(j)
			P[i].add(  x+(10**k)*j )
			P[i].add( 0 )


ans=0
for x in P[-1]:
	if  1<= x <= N:
		for i in s:
			if i not in str(x):
				break
		else:
			ans+=1

print ans
	

Measured memory_bytes: 36380
N, X = map(int, input().split())
a = [1]
for _ in range(N - 1):
    a.append(a[-1] * 2 + 3)
p = [1]
for _ in range(N - 1):
    p.append(p[-1] * 2 + 1)
# print(a)
# print(p)
def func(n, x):
    if n == 0 and x == 1:
        return 1
    if x == 1:
        return 0
    elif x <= 1 + a[n - 1]:
        return func(n - 1, x - 1)
    elif x == 2 + a[n - 1]:
        return p[n - 1] + 1
    elif x <= 2 + a[n - 1] * 2:
        return p[n - 1] + 1 + func(n - 1, x - a[n - 1] - 2)
    else:
        return p[n - 1] * 2 + 1

print(func(N, X))


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

#define int long long
#define MOD 1000000007

int memo[200][10][10][10][10] = {};
int n;

int dp(int i, int a, int b, int c, int d){

    if(a == 1 && b == 2 && c == 3){
        return 0;
    }

    if(a == 2 && b == 1 && c == 3){
        return 0;
    }

    if(a == 1 && b == 3 && c == 2){
        return 0;
    }

    if(a == 1 && b == 2 && d == 3){
        return 0;
    }

    if(a == 1 && c == 2 && d == 3){
        return 0;
    }

    if(b == 1 && c == 2 && d == 3){
        return 0;
    }

    if(b == 2 && c == 1 && d == 3){
        return 0;
    }

    if(b == 1 && c == 3 && d == 2){
        return 0;
    }


    if(i == n){
        return 1;
    }

    int ta, tb, tc, td;
    ta = a;
    tb = b;
    tc = c;
    td = d;
    if(memo[i][a][b][c][d] != -1){
        return memo[i][a][b][c][d];
    }

    a = b;
    b = c;
    c = d;
    int ans = 0;
    for(int j = 0;j < 4;j++){
        d = j;
        ans += dp(i+1, a, b, c, d);
        ans %= MOD;
    }

    return memo[i][ta][tb][tc][td] = ans;
}

signed main(){
    cin >> n;

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

    cout << dp(0, 5, 5, 5, 5) << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

int n, k;
ll sol;
int A[100005];
int Dp[100005];

int main()
{
    #ifdef acm
    freopen("a.in", "r", stdin);
    #endif // acm

    cin.tie(0);
    ios_base::sync_with_stdio(0);

    cin >> n;

    for( int i = 1; i <= n; i ++ ){
        cin >> A[i];
    }

    /*for( int i = 1; i <= n; i ++ ){
        Dp[i] = max( Dp[i], Dp[i-1] + A[i]/2 );

        if( i+1 <= n ){
            Dp[i+1] = max( Dp[i+1], Dp[i-1] + min( A[i], A[i-1] ) );
        }

        if( i+2 <= n ){


        }
    }*/


    ll ant = 0;
    for( int i = 1; i <= n; i ++ ){
        ll y = min( ant, 1ll*A[i] );
        sol += y;
        A[i] -= y;
        y = A[i]/2;
        sol += y;
        ant = A[i]%2;
    }

    cout << sol;

    return 0;
}


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

int main(int argc, char** argv){
  unsigned long long sum = 0, A;
  int N;
  bool carry = false;
  cin >> N;
  for(int  i = 0; i < N; i++){
    cin >> A;
    if(carry&&A>0){
      sum++;
      A--;
    }
    sum += A/2;
    carry = A%2 == 1;
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	string S, T;
	int ctoi(char c) {
		return c - 'a';
	}
	
	void ans() {
		cin >> S >> T;
		vector<int> s(26, 0), t(26, 0);
		int n = S.size();
		REP(i, n) {
			s[ctoi(S[i])]++;
			t[ctoi(T[i])]++;
		}
		sort(s.begin(), s.end(), greater<int>());
		sort(t.begin(), t.end(), greater<int>());
		string res = "No\n";
		if (s == t) res = "Yes\n";
		cout << res;
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}

Measured memory_bytes: 916
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a: usize,
        b: usize,
        t: usize,
    }
    println!("{}", b * (t / a));
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

lint A[15][15];
lint C[15];

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

    for(lint i=0; i<N; i++) {
        cin >> C[i];
        for(lint j=0; j<M; j++) {
            cin >> A[i][j];
        }
    }

    lint base = 2;
    lint exp = N;
    lint ans = 1e18;
    for(lint poly = 0; poly < pow(base, exp); poly++) {
        lint tmp = poly;
        vector<lint> coef;
        for(lint i=0; i<exp; i++) {
            coef.push_back(tmp % base);
            tmp /= base;
        }

        lint B[15] = {};
        lint money = 0;
        for(lint i=0; i<N; i++) {
            if(!coef[i]) continue;
            money += C[i];
            for(lint j=0; j<M; j++) {
                B[j] += A[i][j];
            }
        }
        bool ok = true;
        for(lint j=0; j<M; j++) {
            ok &= (B[j] >= X);
        }

        if(ok) ans = min(ans, money);
    }

    cout << (ans==1e18 ? -1 : ans) << endl;
}

Measured memory_bytes: 4076
#include <stdio.h>

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


Measured memory_bytes: 2552
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<map>
#include<cstring>
#include <stack>
#include <numeric>
#include<climits>
#include<cmath>
#include<set>
#include<unordered_set>
#include<iomanip>
#include<queue>
#include<unordered_map>
#define vi vector<float>
#define vl vector<long long>
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define loop(i,n) for(int i=0; i<n; i++)
#define pb push_back
#define mp make_pair
#define ll long long
#define pii pair<float,float>
#define umap unordered_map<ll,float>
using namespace std;

#define xx first
#define yy second

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);

// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// #endif

	unsigned ll n, a, b;
	cin >> n >> a >> b;

	unsigned ll g = (n) / (a + b);
	unsigned ll blue = g * a;
	unsigned ll rem = n - g * (a + b);

	//cout << blue << " " << rem << endl;

	if (rem <= a) {
		cout << blue + (rem) << endl;
	} else {
		cout << blue + a << endl;
	}







	return 0;
}










Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define LL long long
#define ll __int64
#define INF 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}


/*
    1.Shoud it use long long ?
    2.Have you ever test several sample(at least three) yourself?
    3.Can you promise that the solution is right? At least,the main ideal
    4.use the puts("") or putchar() or printf and such things?
    5.init the used array or any value?
    6.use error MAX_VALUE?
    7.use scanf instead of cin/cout?
    8.whatch out the detail input require
*/
const int maxn=1e3+5;
int m[maxn][maxn];
int n;
struct node
{
	int x,y;
}a[maxn],b[maxn];
int used[maxn];
int match[maxn];
bool dfs(int u)
{
	for(int i=1;i<=n;i++)
	{
		if(!used[i]&&m[u][i])
		{
			used[i]=1;
			if(match[i]==-1||dfs(match[i]))
			{
				match[i]=u;
				return 1;
			}
		}
	}
	return 0;
}
int hungry()
{
	int ans=0;
	memset(match,-1,sizeof(match));
	for(int i=1;i<=n;i++)
	{
		mem(used);
		if(dfs(i)) ++ans;
	}
	return ans;
} 

int main()
{
	si(n);
	for(int i=1;i<=n;i++)
	{
		si(a[i].x);si(a[i].y);
	}
	for(int i=1;i<=n;i++)
	{
		si(b[i].x);si(b[i].y);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(a[i].x<b[j].x&&a[i].y<b[j].y)
			{
				m[i][j+n]=1;
				//m[j+n][i]=1;
			}
		}
	}
	n+=n;
	printf("%d\n",hungry());
}






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

int N;

class DisjointSet{
public:
  vector<int> rank,p;
  vector<int> sz;
 
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    sz.resize(size,0);
    for(int i=0;i<size;i++) makeSet(i);
  }
 
  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
    sz[x]=1;
  }
 
  bool same(int x,int y){
    return findSet(x)==findSet(y);
  }
 
  void unite(int x,int y){
    link(findSet(x),findSet(y));
  }
 
  void link(int x,int y){
    if(rank[x]>rank[y]){
      p[y]=x;
      sz[x]+=sz[y];
    }else{
      p[x]=y;
      sz[y]+=sz[x];
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }
 
  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
 
  int findSize(int x){
    return sz[findSet(x)];
  }
};


void solve(){
    vector<double> x(N),y(N),z(N),r(N);
    for(int i=0;i<N;i++) cin>>x[i]>>y[i]>>z[i]>>r[i];

    vector<tuple<double,int,int>> edges;
    for(int i=0;i<N;i++){
        for(int j=1;j<N;j++){
            double dis;
            double s=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j])+(z[i]-z[j])*(z[i]-z[j]);
            double t=(r[i]+r[j])*(r[i]+r[j]);
            if(s<=t) dis=0.0;
            else{
                double z=sqrt(s)-(r[i]+r[j]);
                if(z>0) dis=z;
                else dis=0.0;
            }
            edges.push_back(make_tuple(dis,i,j));
        }
    }

    sort(edges.begin(),edges.end());
    DisjointSet ds(N);
    double ans=0.0;
    for(int i=0;i<edges.size();i++){
        int x=get<1>(edges[i]);
        int y=get<2>(edges[i]);
        if(ds.same(x,y)) continue;
        ds.unite(x,y);
        ans+=get<0>(edges[i]);
    }
    
    cout<<fixed<<setprecision(3)<<ans<<endl;
}


int main(){
  while(1){
      cin>>N;
      if(N==0) break;
      solve();
  }

  return 0;
}



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

const int N = 2e5 + 10;
int n, a[N], t[2][N << 2];

inline int read() {
	int s = 0, f = 1;
	char ch;
	for(; ch < '0' || ch > '9'; ch = getchar())	if(ch == '-')	f = -1;
	for(; ch >= '0' && ch <= '9'; ch = getchar())	s = (s << 1) + (s << 3) + ch - '0';
	return s * f;
}

inline void add(int o, int pos, int l, int r, int cnt) {
	if (a[cnt] < a[t[o][pos]])	t[o][pos] = cnt;
	if (l == r)	return;
	int mid = (l + r) >> 1;
	if (cnt <= mid)	add(o, pos << 1, l, mid, cnt);
	else	add(o, pos << 1 | 1, mid + 1, r, cnt);
}

inline int ask(int o, int pos, int l, int r, int L, int R) {
	if (l > R || r < L)	return 0;
	if (L <= l && r <= R)	return t[o][pos];
	int mid = (l + r) >> 1;
	int lans = ask(o, pos << 1, l, mid, L, R);
	int rans = ask(o, pos << 1 | 1, mid + 1, r, L, R);
	return a[lans] < a[rans] ? lans : rans;
}

struct node {
	int l, r, v;
	node() {}
	node(int _l, int _r){ l = _l, r = _r, v = l > r ? 0 : ask(l & 1, 1, 1, n, l, r); }
	friend bool operator < (node A,node B) { return a[A.v] < a[B.v]; }
};

set <node> s;

int main() {
	n = read();
	a[0] = n + 1;
	for(int i = 1; i <= n; ++i) {
		a[i] = read();
		add(i & 1, 1, 1, n, i);
	}
	s.clear();
	s.insert(node(1, n));
	for(int i = 1; i <= n >> 1; ++i) {
		node now = *s.begin();
		s.erase(s.begin());
		int l = now.l, r = now.r;
		int lmid = now.v, rmid = ask((lmid & 1) ^ 1, 1, 1, n, lmid, r);
		printf("%d %d ", a[lmid], a[rmid]);
		s.insert(node(l, lmid - 1));
		s.insert(node(lmid + 1, rmid - 1));
		s.insert(node(rmid + 1, r));
	}
	puts("");
	return 0;
}


Measured memory_bytes: 11008
num=[]
n,k=map(int,input().split())
for i in range(n):
    num.append(list(map(int,input().split())))
str= lambda val: val[0]
num.sort(key=str)
num1=0
for i in range(n):
    num1+=num[i][1]
    if num1>=k:
        ans=num[i][0]
        break
print(ans)


Measured memory_bytes: 28648
#include<iostream>

using namespace std;

int main() {
	char s;
	int count = 0;
	//CODEFESTIVAL2016

	cin >> s;
	if (s != 'C')++count;
	cin >> s;
	if (s != 'O')++count;
	cin >> s;
	if (s != 'D')++count;
	cin >> s;
	if (s != 'E')++count;
	cin >> s;
	if (s != 'F')++count;
	cin >> s;
	if (s != 'E')++count;
	cin >> s;
	if (s != 'S')++count;
	cin >> s;
	if (s != 'T')++count;
	cin >> s;
	if (s != 'I')++count;
	cin >> s;
	if (s != 'V')++count;
	cin >> s;
	if (s != 'A')++count;
	cin >> s;
	if (s != 'L')++count;
	cin >> s;
	if (s != '2')++count;
	cin >> s;
	if (s != '0')++count;
	cin >> s;
	if (s != '1')++count;
	cin >> s;
	if (s != '6')++count;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 256
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const intmax_t MOD = INTMAX_C(1e9) + 7;
const intmax_t MAX = INTMAX_C(2e5);

intmax_t modpow(intmax_t a, intmax_t n)
{
    intmax_t res = 1;
    while (n > 0) {
        if (n & 1)
            res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void swap(intmax_t *a, intmax_t *b)
{
    intmax_t t;
    t = *a;
    *a = *b;
    *b = t;
}

intmax_t modinv(intmax_t a, intmax_t m)
{
    intmax_t b = m, u = 1, v = 0;
    while (b) {
        intmax_t t = a / b;
        a -= t * b;
        swap(&a, &b);
        u -= t * v;
        swap(&u, &v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

intmax_t nCk(intmax_t n, intmax_t k)
{
    intmax_t a = 1, b = 1;
    for (size_t i = (n - k + 1); i <= n; i++) {
        a *= i;
        a %= MOD;
    }
    for (size_t i = 1; i <= k; i++) {
        b *= i;
        b %= MOD;
    }
    return a * modinv(b, MOD) % MOD;
}

int main(void)
{
    intmax_t n, a, b;
    intmax_t ans = 0;

    scanf("%jd%jd%jd", &n, &a, &b);

    ans = modpow(2, n);

    intmax_t nCa = nCk(n, a);
    intmax_t nCb = nCk(n, b);

    ans -= nCa;
    ans %= MOD;
    if (ans < 0)
        ans += MOD;

    ans -= nCb;
    ans %= MOD;
    if (ans < 0)
        ans += MOD;

    ans -= 1;
    ans %= MOD;
    if (ans < 0)
        ans += MOD;

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
dividers::Int ->[Int]
dividers n = filter (\x-> (mod n x ) == 0 ) [1..(truncate (sqrt (fromIntegral n)))]

able::Int -> [(Int,Int)]
able n = [(i ,div n i)|i<-dividers n]

dig::Int -> Int
dig x = length (takeWhile (\y->x>=y) [ 10^i |i<-[0..]])

solver::Int -> Int
solver n =  minimum (map (\(x,y)-> dig (max x y)) (able n))

main::IO()
main=do
  nc<-getLine
  print (solver (read nc))

Measured memory_bytes: 892
c, op, d = gets.split
a = c.to_i
b = d.to_i
while op != "?" do
	if op == "+" then
		puts a + b
	elsif op == "-" then
		puts a - b
	elsif op == "*" then
		puts a * b
	elsif op == "/" then
		puts a / b
	end
	c, op, d = gets.split
	a = c.to_i
	b = d.to_i
end

Measured memory_bytes: 8736
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll A, B, C, X;
  cin >> A >> B >> C >> X;

  ll ans = 0;
  rep(i,A+1)rep(j,B+1){
    ll s = (i*500 + j*100);
    if(s <= X){
      ll k = (X-s)/50;
      if(k <= C) ans ++;
    }
    
  }
  
  cout << ans << endl;
  
  
  //cout << fixed << setprecision(16) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
var input=require("fs").readFileSync("/dev/stdin","utf8");
var i;

input=input.split("\n");
var n=parseInt(input[0]);
var str=input[1].split(" ");

var min=parseFloat(str[0]);
var max=parseFloat(str[0]);
var sum=parseFloat(str[0]);

for(i=1;i<n;i++){
    if(max<parseFloat(str[i])){
        max=parseFloat(str[i]);
    }
    if(min>parseFloat(str[i])){
        min=parseFloat(str[i]);
    }
    sum+=parseFloat(str[i]);
}

console.log(min+" "+max+" "+sum);


Measured memory_bytes: 17168
#include <bits/stdc++.h>
using namespace std;
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTG(c) sort((c).begin(),(c).end(),greater<auto>())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int main(){
   LL n, ans;
   cin >> n;
   ans  = n*(n-1)/2;
   cout << ans << endl;
}

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

int main(){
  int n;cin >> n;
  string s,t;cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int N[][] = new int[n][n];
		for (int i = 0; i < n; i++) {
			for (int j = 0;j < n; j++) {
				N[i][j] = 0;
			}
		}

		for (int i = 0; i < n; i++) {
			int m1 = scanner.nextInt();
			int m2 = scanner.nextInt();
			for (int j = 0; j < m2; j++) {
				int x = scanner.nextInt();
				N[m1 - 1][x - 1] = 1;
			}
		}
		for (int k = 0;k < n; k++) {
			for (int l = 0; l < n - 1; l++) {
				System.out.print(N[k][l] + " ");
			}
			System.out.println(N[k][n - 1]);
		}
	}
}



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

#define LL long long
#define pii pair<int,int>
using namespace std;
const int inf = 2147483647;
const int mod = 1e9 + 7;
const int N = 301;

int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
inline 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 << 3) + (x << 1) + (ch ^ 48), ch = getchar();
    return x * f;
}
void put(int x) {
	if(x < 0) putchar('-'), x = -x;
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

int f[2][N][N], p[N * 2];

int add(int x, int y) {x += y; return x >= mod ? x - mod : x;}

int main() {
	int n = read(), s = 0;
	for(int i = 1; i <= n; i++) {
		int x = read(), y = read();
		if(x != -1 && y != -1) {p[x] = p[y] = -1; continue;}
		if(x != -1) p[x] = 1;
		else if(y != -1) p[y] = 1;
		else s++;
	} int now = 0, s1 = 0, s2 = 0; f[0][0][0] = 1;
	for(int i = 2 * n; i >= 1; i--) {
		if(p[i] == -1) continue;
		now ^= 1; memset(f[now], 0, sizeof(f[now]));
		for(int j = 0; j <= _min(s1, n); j++) for(int k = 0; k <= _min(s2, n); k++) if(f[now ^ 1][j][k]){
			int c = f[now ^ 1][j][k];
			if(p[i]) {
				if(j) f[now][j - 1][k] = add(f[now][j - 1][k], c);
				f[now][j][k + 1] = add(f[now][j][k + 1], c);
			} else {
				f[now][j + 1][k] = add(f[now][j + 1][k], c);
				if(j) f[now][j - 1][k] = add(f[now][j - 1][k], c);
				if(k) f[now][j][k - 1] = add(f[now][j][k - 1], (LL)c * k % mod);
			}
		} s1 += p[i] == 0, s2 += p[i] == 1;
	} int ans = f[now][0][0];
	for(int i = 1; i <= s; i++) ans = (LL)ans * i % mod;
	put(ans), puts("");
	return 0;
}


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

int main() {
	int n;
	cin >> n;
	vector<vector<int>> h(n+1, vector<int>(3));
	h.at(0) = { 0,0,0 };
	for (int i = 1; i <= n; i++)cin >> h.at(i).at(0) >> h.at(i).at(1) >> h.at(i).at(2);
	vector<vector<int>> dp(7, vector<int>(n + 1, -1));
	dp.at(0).at(0) = 0;
	dp.at(0).at(1) = max(max(h.at(1).at(0), h.at(1).at(1)), h.at(1).at(2));
	if (n == 1) {
		cout << dp.at(0).at(1) << endl;
		return 0;
	}
	dp.at(1).at(2) = h.at(1).at(0) + h.at(2).at(1);
	dp.at(2).at(2) = h.at(1).at(0) + h.at(2).at(2);
	dp.at(3).at(2) = h.at(1).at(1) + h.at(2).at(0);
	dp.at(4).at(2) = h.at(1).at(1) + h.at(2).at(2);
	dp.at(5).at(2) = h.at(1).at(2) + h.at(2).at(0);
	dp.at(6).at(2) = h.at(1).at(2) + h.at(2).at(1);
	int x = 0;
	for (int i = 1; i <= 6; i++) {
		x = max(x, dp.at(i).at(2));
	}
	dp.at(0).at(2) = x;
	if (n == 2) {
		cout << dp.at(0).at(2) << endl;
		return 0;
	}
	for (int i = 3; i <= n; i++) {
		dp.at(1).at(i) = max(dp.at(3).at(i - 1), dp.at(5).at(i - 1)) + h.at(i).at(1);
		dp.at(2).at(i) = max(dp.at(3).at(i - 1), dp.at(5).at(i - 1)) + h.at(i).at(2);
		dp.at(3).at(i) = max(dp.at(1).at(i - 1), dp.at(6).at(i - 1)) + h.at(i).at(0);
		dp.at(4).at(i) = max(dp.at(1).at(i - 1), dp.at(6).at(i - 1)) + h.at(i).at(2);
		dp.at(5).at(i) = max(dp.at(2).at(i - 1), dp.at(4).at(i - 1)) + h.at(i).at(0);
		dp.at(6).at(i) = max(dp.at(2).at(i - 1), dp.at(4).at(i - 1)) + h.at(i).at(1);
		int y = 0;
		for (int j = 1; j <= 6; j++) {
			y = max(y, dp.at(j).at(i));
		}
		dp.at(0).at(i) = y;
	}
	cout << dp.at(0).at(n) << endl;

}

Measured memory_bytes: 8832
N = int(input())
k = 1
while N > (k * (k + 1)) // 2:
  k += 1
for i in range(k):
  if N > ((k - i) * (k - i - 1)) // 2 and N <= ((k - i) * (k - i + 1)) // 2:
    print(k - i)
    N -= (k - i)
  if N == 0:
    break

Measured memory_bytes: 3316
#include <stdlib.h>
#include <iostream>
using namespace std;

bool sum_of_two(int a, int b, int c);

int main(){
	int a, b, c;

	cin >> a >> b >> c;
	bool res = sum_of_two(a, b, c);
	if(res){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;	
	}
	return 0;
}

bool sum_of_two(int a, int b, int c){
	if(a+b == c) return true;
	if(a+c == b) return true;
	if(b+c == a) return true;
	return false;

}


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

using namespace std;

int data[8][8], odr[5], h, w, c, dy[] = {-1, 0, 1, 0}, dx[] = {0, 1, 0, -1}, tmp[8][8];
bool vis[8][8];

bool check(int y, int x){
  if(y<0 || y>=h) return false;
  if(x<0 || x>=w) return false;
  return true;
}

void dfs(int y, int x, int p, int s){
  vis[y][x] = true;
  for(int i=0;i<4;i++){
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(!check(ny, nx)) continue;
    if(tmp[ny][nx] != s) continue;
    if(vis[ny][nx]) continue;
    dfs(ny, nx, p, s);
  }
  tmp[y][x] = p;
}

int countPannel(int y, int x, int p){
  int res = 1;
  vis[y][x] = true;
  for(int i=0;i<4;i++){
    int ny = y + dy[i];
    int nx = x + dx[i];
    if(!check(ny, nx)) continue;
    if(tmp[ny][nx] != p) continue;
    if(vis[ny][nx]) continue;
    res += countPannel(ny, nx, p);
  }
  return res;
}

int calc(){
  for(int i=0;i<5;i++){
    fill(vis[0], vis[8], false);
    dfs(0, 0, odr[i], tmp[0][0]);
  }
  fill(vis[0], vis[8], false);
  return countPannel(0, 0, odr[4]);
}

void init(){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      tmp[i][j] = data[i][j];
    }
  }
}

main(){
  while(cin >> h >> w >> c && (h|w|c)){
    odr[4] = c;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> data[i][j];
      }
    }
    int ans = 0;
    for(odr[0]=1;odr[0]<=6;odr[0]++){
      for(odr[1]=1;odr[1]<=6;odr[1]++){
        for(odr[2]=1;odr[2]<=6;odr[2]++){
          for(odr[3]=1;odr[3]<=6;odr[3]++){
            init();
            ans = max(ans, calc());
          }
        }
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 868
d = [[[-1, -1], [0, -1], [1, -1], [1, 0], [0, 1], [-1, 0]],
     [[-1,  0], [0, -1], [1,  0], [1, 1], [0, 1], [-1, 1]]]

w, h = gets.split.map(&:to_i)
fld = (h+2).times.map{ [false]*(w+2) }
(1..h).each do |i|
  gets.split(" ").each_with_index{ |e, j| fld[i][j+1] = true if e == "1" }
end

tmp = (h+2).times.map{ [false]*(w+2) }
arr = []
arr << [0, 0]
tmp[0][0] = true
until arr.empty?
  y, x = arr.pop
  d[y%2].each do |dy, dx|
    u = y + dy; v = x + dx
    next if u < 0 || u > h+1 || v < 0 || v > w+1
    if !fld[u][v] && !tmp[u][v]
      tmp[u][v] = true
      arr << [u, v]
    end
  end
end
fld = fld.flatten.zip(tmp.flatten).map{|f,p| !(!f&p) }
p fld.map.with_index{|e, i| i if e}.compact.map{ |i| u, v = i.divmod(w+2); d[u%2].count{ |y, x| !fld[i+y*(w+2)+x]}}.compact.reduce(:+)

Measured memory_bytes: 9600
import sys

num_exam = int(raw_input())
current_scores    = map(int, raw_input().split())
exam_boarderlines = map(int, raw_input().split())

margin_scores = []
lack_scores   = []
count_adjusted = 0

if sum(current_scores) < sum(exam_boarderlines):
  print(-1)
  sys.exit()

for i in range(num_exam):
  if current_scores[i] < exam_boarderlines[i]:
    lack_scores.append(current_scores[i] - exam_boarderlines[i])
    count_adjusted += 1
  elif current_scores[i] > exam_boarderlines[i]:
    margin_scores.append(current_scores[i] - exam_boarderlines[i])

desc_sorted_margin_scores = sorted(margin_scores, reverse=True)
total_lack_score = sum(lack_scores)
for i in range(len(desc_sorted_margin_scores)):
  if total_lack_score >= 0:
    break

  total_lack_score += desc_sorted_margin_scores[i]
  count_adjusted += 1

print(count_adjusted)

Measured memory_bytes: 16272
#include<bits/stdc++.h>
#define ll long long
#define thekingisborn ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ld  long double
#define f first
#define se second
#define pb push_back
#define maxn 200005
#define mod 1000000007
#define pi 3.14159265359

using namespace std;

typedef pair<int,int>pii;
typedef pair<ll,ll>pll;

/*ll power(ll a,ll n)
{
    if(n == 1)return a%mod;
    if(n == 0)return 1;
    a = a%mod;
    if(n&1)return ((a%mod)*(power((a*a)%mod,n>>1))%mod)%mod;
    return power((a*a)%mod,n>>1)%mod;
}
ll gcd(ll a,ll b)
{
    if(a%b == 0)return b;
    return gcd(b,a%b);
}*/
/*int root(int x)
{
    while(par[x] != x)
    x = par[x];
    return x;
}
void dsu(int x,int y)
{
  if(root(x) == root(y))return;
  par[root(y)] = root(x);
  return;
}
void dfs(int x)
{
    done[x] = true;
    for(int i=0;i<int(adj[x].size());++i)
    {
        int y = adj[x][i];
        if(!done1[y])
        dfs(y);
    }
}*/
ll n;
vector<ll>v(3*maxn);

int main()
{
    thekingisborn;
    /*cin >> n;
    for(int i=0;i<(1<<n);++i)
    cin >> v[i];*/
    int a,b;
    cin >> a >> b;
    if(a+b == 15)
    cout << '+';
    else if(a*b == 15)
    cout << '*';
    else cout << 'x';
    return 0;
}


Measured memory_bytes: 4992
program main
   implicit none
   integer n,k
   integer i,j
   real(8),allocatable,dimension(:)::ka
   read(*,*)n,k
   allocate(ka(n))
   do i=1,n
      do j=0,20
         if(i*2**j>=k)exit
      enddo
      ka(i)=1/real(2**j,8)
   enddo
   write(*,*)sum(ka)/n
   
   
   
   
 
 
 
 
 
 
 
   
contains
  subroutine heapsort(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  integer :: t
  
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k.eq.1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(array(j).lt.array(j+1))j=j+1
        endif
        if (t.lt.array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo

  return
end subroutine heapsort
end program main


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a,b,c,d,e,f;
  a=n/1000;
  b=n%1000;
  c=b/100;
  d=b%100;
  e=d/10;
  f=d%10;
  if(a==c&&c==e||c==e&&e==f){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans;
  cin>>n;
  ans=n;
  vector<string> vec(n);
  for(int i=0; i<n; i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for(int i=0; i<n-1; i++){
    if(vec.at(i)==vec.at(i+1)){
      ans=ans-1;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 9548