akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=100010;
ll x,y,a,b,c,ma,mb,mc,ans;
ll p[N],q[N],r[N];
bool cmp(ll i,ll j){
	return i>j;
}
int main(){
	scanf("%lld%lld%lld%lld%lld",&x,&y,&a,&b,&c);
	for(ll i=0;i<a;++i) scanf("%lld",&p[i]);
	for(ll i=0;i<b;++i) scanf("%lld",&q[i]);
	for(ll i=0;i<c;++i) scanf("%lld",&r[i]);
	sort(p,p+a,cmp);
	sort(q,q+b,cmp);
	sort(r,r+c,cmp);
	ma=x-1;mb=y-1;mc=0;
	while(r[mc]>min(p[ma],q[mb])&&ma>=0&&mb>=0){
		if(p[ma]<q[mb]) --ma;
		else --mb;
		++mc;
	}
	//printf("ma=%lld,mb=%lld,mc=%lld\n",ma,mb,mc);
	if(ma==-1){
		while(r[mc]>q[mb]){
			--mb;
			++mc;
		}
	}
	if(mb==-1){
		while(r[mc]>p[ma]){
			--ma;
			++mc;
		}
	}
	for(ll i=0;i<=ma;++i) ans+=p[i];
	for(ll i=0;i<=mb;++i) ans+=q[i];
	for(ll i=0;i<mc;++i) ans+=r[i];
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#define INF 1111111
using namespace std;
typedef pair<int,int> P;

int main(){
   int a,b;
  cin >> a >> b;
  
  int ans = (a-1)*(b-1);
  
  cout << ans << endl;
  
  
}





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

bool isSmallAlphabet(char& ch) {
  /* a ~ z(ascii) : 97 ~ 122 */
  if('a' <= ch && ch <= 'z') return true;
  else return false;
}

bool isHit(string& str) {
  if(str.find("the") != str.npos) return true;
  else if(str.find("this") != str.npos) return true;
  else if(str.find("that") != str.npos) return true;
  else return false;
}

/* ????????¶??????????§£??? */
void CaesarCipher(string _str) {
  
  /* parameter??????????????¢??????????????????????????????????????? */
  for(int parameter = 0; parameter < 26; ++parameter) {
    string str = _str;
    for(int i = 0; i < (int)str.length(); ++i) {
      
      /* ?°?????????¢??????????????????????????? */
      if(isSmallAlphabet(str[i])) {
        str[i] += parameter;
        /* ???????????????????°?????????§???????????£??????*/
        if(!isSmallAlphabet(str[i])) {
          str[i] -= 26;
        }
      }

    }

    /* Find "the" or "this" or "that" */
    if(isHit(str)) {
      cout << str << endl;
    }
  }
}

int main() {
  string str;
  while(getline(cin, str)) {
    CaesarCipher(str);
  }
  return 0;
}

Measured memory_bytes: 3112
S = input()

if S == 'SAT':
    print(1)
if S == 'SUN':
    print(7)
if S == 'MON':
    print(6)
if S == 'TUE':
    print(5)
if S == 'WED':
    print(4)
if S == 'THU':
    print(3)
if S == 'FRI':
    print(2)    

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

int main() {
	string s, t;
	cin >> s;
	t = s;
	bool f = 1;
	int n = s.size();
	for (int i = 0; i < n/ 2; i++)
		swap(t[i], t[n - 1 - i]);
	if (t != s)
		f = 0;

	t = s;
	for (int i = 0; i < (n - 1) / 2 / 2; i++)
		swap(t[i], t[(n - 1) / 2 - 1 - i]);
	if (t != s)
		f = 0;

	t = s;
	for (int i = (n + 3) / 2 - 1; i < (n + (n + 3) / 2 - 1) / 2; i++)
		swap(t[i], t[n - 1 - i]);
	if (t != s)
		f = 0;

	cout << (f ? "Yes" : "No") << endl;
	return 0;
}

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

using namespace std;

int main(void)
{
  int N, R;
  cin >> N >> R;

  int ans;

  if (N >= 10) {
      ans = R;
  } else{
      ans = 100 * (10 - N) + R;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main()
{
    ll n;
    cin >> n;
    map<ll, ll> ma;
    ll sum = 0;
    for(int i = 0; i < n; i++)
    {
        ll a;
        cin >> a;
        ma[a]++;
        sum += a;
    }
    int q;
    cin >> q;
    while(q--)
    {
        ll b, c;
        cin >> b >> c;
        ll num = ma[b];
        sum += (c-b) * num;
        ma[c] += num;
        ma[b] -= num;
        cout << sum << endl;
    }
}



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

int main() {
  int n;
  cin>>n;
  vector<int> A(n);
  long long stoolsum = 0;
  for(int i = 0 ; i < n; i++){
    cin>>A[i];
    if(i!=0 && A[i] < A[i-1]){ 
       stoolsum += (A[i-1] - A[i]);
       A[i] += (A[i-1] - A[i]);
    }
  }
  cout<<stoolsum;
  return 0;
}

Measured memory_bytes: 4036
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1e9
#define LINF 1e18
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
#define int long long
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
struct edge{int to,cost;};
//typedef pair<int,int> P;

bool isupper(char c){if('A'<=c&&c<='Z')return 1;return 0;}
bool islower(char c){if('a'<=c&&c<='z')return 1;return 0;}
bool isPrime(int x){if(x==1)return 0;if(x==2)return 1;if(x%2==0)return 0;for(int i=3;i*i<=x;i++)if(x%i==0)return 0;return 1;}
bool iskaibun(string s){for(int i=0;i<s.size()/2;i++)if(s[i]!=s[s.size()-i-1])return 0;return 1;}
bool isnumber(char c){return ('0'<=c&&c<='9');}
bool isalpha(char c){return (isupper(c)&&islower(c));}
void printvi(vector<int> v){rep(i,0,v.size()){if(i)cout<<" ";cout<<v[i];}cout<<endl;}
void printvil(vector<int> v){rep(i,0,v.size()){cout<<v[i]<<endl;}}
void printvvi(vector<vector<int>> v){
    rep(i,0,v.size()){
        rep(j,0,v[i].size()){
            if(j)cout<<" ";
            cout<<v[i][j];
        }
        cout<<endl;
    }
}
void printvstr(vector<string> v){
    rep(i,0,v.size()){
        cout<<v[i]<<endl;
    }
}

signed main (){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int k;cin>>k;
    k--;
    char c=s[k];
    rep(i,0,s.size()){
        if(s[i]==c)cout<<s[i];
        else cout<<"*";
    }
    cout<<endl;

}
/*
*/


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int N;
  cin >> N;
  cout << pow(N,3) << endl;
  return 0;
}

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

using namespace std;

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

  int w, h, n;
  cin >> w >> h >> n;
  int top = h, left = 0, right = w, bottom = 0;
  for (int i = 0; i < n; ++i) {
    int x, y, a;
    cin >> x >> y >> a;
    switch (a) {
    case 1:
      left = max(left, x);
      break;
    case 2:
      right = min(right, x);
      break;
    case 3:
      bottom = max(bottom, y);
      break;
    case 4:
      top = min(top, y);
      break;
    }
  }
  cout << max(0, (right - left)) * max(0, (top - bottom)) << "\n";
}


Measured memory_bytes: 256
N = int(input())
num = [str(i) for i in range(1, 10)]
lunlun = num
for i in range(10):
    temp_list = []
    for j in num:
        temp = int(j[-1])
        if 0 < temp < 9:
            temp_list.append(j + str(temp - 1))
            temp_list.append(j + str(temp))
            temp_list.append(j + str(temp + 1))
        elif temp == 0:
            temp_list.append(j + str(temp))
            temp_list.append(j + str(temp + 1))
        else:
            temp_list.append(j + str(temp - 1))
            temp_list.append(j + str(temp))
    num = temp_list
    lunlun = lunlun + num
lunlun = [int(l) for l in lunlun]
lunlun = list(set(lunlun))
lunlun.sort()
print(lunlun[N - 1])

Measured memory_bytes: 85076
//============================================================================
// Name        : AOL.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;



int main(){

	int w,a,b;
	int d;

	cin>>w>>a>>b;

	if(a<b){
		d=b-a;
	}else{
		d=a-b;
	}
	if(d<w){
		cout<<"0"<<endl;
	}else{
		cout<<d-w<<endl;
	}


	return 0;



}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

#define sz(x) int(x.size())
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main() {
  string s, t;
  cin >> s >> t;
  vector<vector<int> > is(26);

  int n = sz(s);
  int m = sz(t);
  for (int i = 0; i < n; i++) {
    is[s[i] - 'a'].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    is[s[i] - 'a'].push_back(i + n);
  }

  ll ans = 0;
  int p = 0;
  rep(i, m) {
    int c = t[i] - 'a';
    if (sz(is[c]) == 0) {
      puts("-1");
      return 0;
    }
    p = *lower_bound(is[c].begin(), is[c].end(), p)+1;
    if (p >= n) {
      p -= n;
      ans += n;
    }
  }
  ans += p;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1724
#include<iostream>
#include<cstdio>
#define read(x) scanf("%lld",&x)
using namespace std;
long long n,k;
long long ans;
int main()
{
	read(n);read(k);
	long long len = n / k;
	ans = len * len * len; 
	if(!(k & 1))
	{
		if((n - len * k) >= k / 2)
		{
			++len;
			ans += len * len * len;
		}
		else
		{
			ans += len * len * len;
		}
	}
	cout<<ans;
} 

Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


struct point
{
	long long name; long long dist;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};

ll const MAX = 200005;
ll a[MAX];
ll s[MAX];
ll t[MAX];

int main() {
	ll n;
	ll k;
	cin >> n >> k;
	REP(i, 1, n) {
		cin >> a[i];
	}
	s[0] = t[0] = 0;
	REP(i, 1, n) {
		s[i] = s[i - 1] + a[i];
		if (a[i] >= 0) {
			t[i] = t[i - 1] + a[i];
		}
		else {
			t[i] = t[i - 1];
		}
	}
	ll ans = 0;
	REP(i, 1, n - k + 1) {
		ll x = t[n] - t[i + k - 1] + t[i - 1];
		ll y = x + s[i + k - 1] - s[i - 1];
		ans = max({ ans,x,y });
	}
	cout << ans << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
const int MOD=1e9+7;
vector<long> fact_inv, inv, Com;
void init_nCk(int n,int k){
  fact_inv.resize(k+5);
  inv.resize(k+5);
  fact_inv[0]=fact_inv[1]=1;
  inv[1]=1;
  for(int i=2;i< k+5;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
  Com.resize(k+5);
  Com[0]=1;
  for(int i=1;i<k+5;i++){
    Com[i]=Com[i-1]*((n-i+1)*inv[i]%MOD)%MOD;
  }
}
int nCk(int k){
    assert(!(k<0));
    return Com[k];
}
int main(){
  int K;
  long x=1,ans=0;
  string S;
  cin>>K>>S;
  int a=K+S.size();
  init_nCk(a,K);
  for(int i=0;i<=K;i++){
    ans+=x*nCk(i);
    ans%=MOD;
    x*=25;
    x%=MOD;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 27732
#include <stdio.h>

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

    scanf("%d %d", &a, &b);

    if(a<b)
    {
        for(i = 0; i<b; i++)
            printf("%d", a);

        printf("\n");
    }
    else
    {
        for(i = 0; i<a; i++)
            printf("%d", b);

        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 128
//#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
//#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
int main()
{
	string s;
	int chk,l;
	map <char,int> mp;
	cin>>s;
	if(s.size()<26)
	{
		for(int i=0;i<s.size();i++) mp[s[i]]++;
		for(char j='a';j<='z';j++) 
			if(!mp[j])
			{
				cout<<s<<j;
				rt0;
			}
	}
	for(int i=s.size()-1;i>=0;i--)
	{
			
		{
			for(char k=s[i]+1;k<='z';k++) 
			{
				for(l=0;l<s.size();l++)
					if(k==s[l])	break;
				if(l==s.size())
				{
					s.pop_back();
					cout<<s<<k;
					rt0;
				}
			}
			s.pop_back();
		}
	}
	cout<<"-1";
    rt0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <random>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef complex<ld> compd;
#define rep(i,n)	for(int i=0;i<n;i++)
#define srep(i,a,n)	for(int i=a;i<n;i++)
#define REP(i,n)	for(int i=0;i<=n;i++)
#define SREP(i,a,n)	for(int i=a;i<=n;i++)
#define rrep(i,n)	for(int i=n-1;i>=0;i--)
#define RREP(i,n)	for(int i=n;i>=0;i--)
#define all(a)	(a).begin(),(a).end()
#define mp(a,b)	make_pair(a,b)
#define mt	make_tuple
#define pb	push_back
#define fst	first
#define scn second
#define bicnt(x)	__buildin__popcount(x)
#define debug(x)	cout<<"debug: "<<x<<endl
#define DEBUG 0

const ll inf = (ll)1e8;
const ll mod = 998244353;
const ld eps = 1e-9;
const int dx[] = { 0,1,0,-1 };
const int dy[] = { 1,0,-1,0 };

ll dist[300][300];

int main() {
	int n;	cin >> n;
	rep(i, n)	rep(j, n)	cin >> dist[i][j];
	rep(i, n)	rep(j, n)	rep(k, n) {
		if (dist[i][j] > dist[i][k] + dist[k][j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ret = 0;
	rep(i, n)	rep(j, n)	ret += dist[i][j];
	ret /= 2;
	rep(i, n)	rep(j, i)	rep(k, n) {
		if (k == i || k == j)	continue;
		if (dist[i][j] == dist[i][k] + dist[k][j]) {
			ret -= dist[i][j];
			break;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#include<math.h>
#define pi 3.14159265358979323846
using namespace std;
int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    cout.precision(18);
    cout.setf(ios::showpoint);
    long double hangle,mangle;
    hangle=360.0/12.0*h;
    mangle=m*6.0;
    hangle+=0.5*m;
    long double dif=abs(hangle-mangle);
    if(dif>180.0)
    {
        dif=360-dif;
    }
    dif= dif * pi / 180.0;
    long double c = sqrt(a*a+b*b-2.0*a*b*cos(dif));
    cout << c;
}


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

int main()
{
    string a,b,c;
    cin>>a>>b;
    int l1,l2;
    l1 = a.length();
    c=b.substr(0,l1);

    if(a==c)cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<random>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD = 1000000007;
const int INF = 1e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 500+10
    string S;
int main(){
    cin>>S;
    REP(i,S.size()){
        if(i%2==0)cout<<S[i];
    }
    //cout<<ans;
}


Measured memory_bytes: 512
N, M = map(int, input().split())
S = []
C = []
for i in range(M):
    s, c = map(int, input().split())
    S.append(s-1)
    C.append(str(c))
ans = []
for i in range(10 ** N):
    a = list(str(i))
    if len(a) != N:
        continue
    ansFlag = True
    for i in range(M):
        if a[S[i]] != C[i]:
            ansFlag = False
    if ansFlag:
        ans = a
        break

if ans == []:
    print(-1)
else:
    print("".join(ans))




Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  float R, G;
  cin >> R >> G;
  cout << 2*G - R << endl;
}

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

int main() {
  bool j = false;
  int n, ans;
  
  cin >> n;
  string x;
  vector<int> t(n);
  vector<string> s(n);
  
  for (int i=0;i < n;i++){
    cin >> s.at(i) >> t.at(i);
  }
  cin >> x;
  
  for(int i = 0; i<n;i++){
    if(j){
      ans = ans + t.at(i);
    }
    if(s.at(i) == x){
      j = true;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
B = []
for i in range(M):
    a, b = map(int, input().split())
    B.append([a, b])
B.sort(key=lambda x:x[1])
c = 1
r = B[0][1]
for i in range(1, M):
    if r <= B[i][0]:
        c += 1
        r = B[i][1]
print(c)

Measured memory_bytes: 21340
#include <stdio.h>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <sstream>
#include <cstring>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef long long ll;

const int MAX_SIZE = 10000;

struct edge{
	int to;
	int cost;
	int money;
};

class Situation{
public:
	int cost;
	int idx;
	int prvEdgeMoney;
	Situation(int cost_,int idx_,int pem_){
		cost=cost_;
		idx=idx_;
		prvEdgeMoney=pem_;
	}
	Situation();

	bool operator<(const Situation &s)const{
		if(s.cost==this->cost)return s.prvEdgeMoney<this->prvEdgeMoney;
		return s.cost < this->cost;
	}
};

int V;
const int MAX_V = 10001;
vector<edge> G[MAX_V];
int d[MAX_V];
int prvAdd[MAX_V];
const int INF = 1000000000;
void dijkstra(int s,int &res){
	priority_queue<Situation> que;
	fill(d,d+MAX_V,INF);
	memset(prvAdd,0,sizeof(prvAdd));
	d[s] = 0;
	que.push(Situation(0,s,0));
	while(!que.empty()){
		Situation p = que.top();
		que.pop();
		int v = p.idx;
		if(d[v] < p.cost)continue;
		if(prvAdd[v]!=0){
			if(prvAdd[v]>p.prvEdgeMoney){
				res-=prvAdd[v];
				res+=p.prvEdgeMoney;
				prvAdd[v]=p.prvEdgeMoney;
			}
			else continue;
		}
		else{
			res+=p.prvEdgeMoney;
			prvAdd[v]=p.prvEdgeMoney;
		}
		for(int i = 0; i < (int)G[v].size(); i++){
			edge e = G[v][i];
			if(d[e.to] >= d[v] + e.cost){
				d[e.to] = d[v] + e.cost;
				que.push(Situation(d[e.to],e.to,e.money));
			}
		}
	}
}

int n,m;

int main(){

	while(cin>>n>>m&&(n|m)){
		int res=0;
		for(int i=0;i<MAX_V;i++)G[i].clear();
		for(int i=0;i<m;i++){
			int u,v,d,c;
			cin>>u>>v>>d>>c;
			edge e;
			e.to=v;
			e.cost=d;
			e.money=c;
			G[u].push_back(e);
			e.to=u;
			G[v].push_back(e);
		}
		dijkstra(1,res);
		cout<<res<<endl;
	}

	return 0;
}

Measured memory_bytes: 2872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}
const ll MOD = 1e9 + 7;

int mainsolve(){

	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];

	vector<P> ps(n);
	rep(i,n) ps[i] = P(a[i],i);
	sort(ps.rbegin(), ps.rend());

	vector<vector<ll>> dp(n+1,vector<ll>(n+1));

	rep(i,n){
		rep(j,n+1){
          	if(i < j) continue;
			dp[i+1][j] = max(dp[i+1][j], dp[i][j] + ps[i].first * (n-(i-j)-1 - ps[i].second));
			if(j+1 <= n) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + ps[i].first * (ps[i].second - j));
		}
	}

	ll res = 0;
	rep(i,n+1) res = max(res, dp[n][i]);
	cout << res << endl;
	return 0;
}

int main(){

	return mainsolve();
}

Measured memory_bytes: 34608
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h,w,cl;
		h = sc.nextInt();
		w = sc.nextInt();
		char[][] map = new char[h][];
		int[][] map2 = new int[h][w];
		for(int i = 0;i < h;i++){
			map[i] = sc.next().toCharArray();
			cl = -1;
			for(int k = 0;k < map[i].length;k++){
				if(map[i][k] == 'c'){
					//System.out.print(0);
					map2[i][k] = 0;
					cl = k;
				}else if(cl != -1){
					//System.out.print(k-cl);
					map2[i][k] = k-cl;
				}else{
					//System.out.print(cl);
					map2[i][k] = cl;
				}
				//if(k != w-1)System.out.print(" ");
			}
			//System.out.println("");
		}
		for(int i = 0; i < h;i++){
			for(int k = 0; k < w;k++){
				System.out.print(map2[i][k]);
				if(k != w-1)System.out.print(" ");
			}
			System.out.println("");
		}
	}
}

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

int main()
{
    ll n;
    cin >> n;
    vector<ll> A(n), B(n), C(n);
    priority_queue<ll, vector<ll>, greater<ll>> a, b, c;
    vector<ll> B1(n);
    vector<ll> B2(n);
    rep(i, n)
    {
        //cin >> A[i];
        ll t;
        cin >> t;
        a.push(t);
    }
    rep(i, n)
    {
        // cin >> B[i];
        ll t;
        cin >> t;
        b.push(t);
    }

    rep(i, n)
    {
        // cin >> C[i];
        ll t;
        cin >> t;
        c.push(t);
    }
    rep(i, n)
    {
        A[i] = a.top();
        a.pop();
    }
    rep(i, n)
    {

        B[i] = b.top();
        b.pop();
    }

    rep(i, n)
    {

        C[i] = c.top();
        c.pop();
    } //全然いける
    rep(i, n)
    {
        //a[i]を超える最小のインデックス
        //  ll ind = upper_bound(B.begin(), B.end(), A[i]) - B.begin();
        //  n - ind; //これが大きさとしてある。
        //
        ll ind1 = upper_bound(C.begin(), C.end(), B[i]) - C.begin();
        // (n - ind) * (n - ind1);
        B1[i] = (n - ind1);
    }
    //後ろから累積和をとる
    for (int i = n - 1; i >= 0; i--)
    {
        if (i == n - 1)
        {
            B2[i] = B1[i];
        }
        else
        {
            B2[i] = B1[i] + B2[i + 1];
        }
    }
    ll count = 0;
    rep(i, n)
    {
        ll ind = upper_bound(B.begin(), B.end(), A[i]) - B.begin();
        //このinde~n-1までで何通りできるのかを考えると
        count += B2[ind];
    }
    cout << count << endl;
}

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

using namespace std;

int n;
long long k;
long long a[200010];

inline long long check(long long num){
	long long temp  = 0;
	for(int i=1;i<=n;i++){
		if(a[i] == 0 && num>=0)
			temp += n-1;
		else if (a[i] < 0){
			int l = 1, r = n, ans=n+1;
			while(l<=r){
				int mid = (l+r)>>1;
				if(a[mid]*a[i]<=num){
					ans = mid;
					r = mid-1;
				}else
					l=mid+1;
			}
//			printf("%d %d\n",ans,num);
			temp+=n - ans +1;
			if(a[i]*a[i]<=num)temp--;
//			printf("%d %d %d\n",a[i],ans, n-ans+1);
		} else if (a[i]>0){
			int l = 1, r = n, ans=0;
			while(l<=r){
				int mid = (l+r)>>1;
				if(a[mid]*a[i]<=num){
					ans = mid;
					l = mid+1;
				}else
					r=mid-1;
			}
			temp += ans;
			if(a[i]*a[i]<=num)temp--;
///			printf("%d %d %d\n",a[i],ans,ans);
		}
	}
	temp = temp / 2;
	return temp;
}
int main(){
	scanf("%d%lld",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",a+i);
	}
	sort(a+1,a+n+1);
	a[n+1]=a[n];
	a[0]=a[1];
//	printf("%lld\n",check(-12));
	//printf("%d\n",5/-2);
	long long l = min(a[1]*a[n], a[1]*a[2]), r = max(a[1]*a[2],a[n-1]*a[n]), ans = 0;
	while(l<=r){
		long long mid = (l+r)>>1;
		if(check(mid) >= k) {
			ans = mid;
			r= mid -1;
		}else 
			l= mid+1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 1792
N = gets.to_i
u = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
ans = 0
N.times do |i|
    cnt = 0
    0.upto(i) do |x| 
        cnt += u[x]
    end
    i.upto(N - 1) do |x|
        cnt += d[x]
    end
    ans = ans < cnt ? cnt : ans
end
puts ans
    

Measured memory_bytes: 1916
#include <iostream>

using namespace std;

int n;

int main() {
    cin >> n;
    int array[n];
    for (int i=0; i<n; i++){
        cin >> array[i];
    }
    int longest_side = 0;
    int other_sides = 0;
    for (int i=0; i<n;i++){
        longest_side = max(longest_side,array[i]);
    }
    
    for (int i=0;i<n;i++){
        other_sides += array[i];
    }

    other_sides -= longest_side;

    if (longest_side < other_sides){
        cout << "Yes";
    }
    else cout << "No";

    return 0;
}

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

vector<long long> division(long long n) {
	vector<long long> v;

	for (long long d = 1; d * d <= n; d += 1)
		if (n%d==0) v.push_back(d);
    v.push_back(n);
    return v;
}

int main() {
    long long n;
    cin >> n;
    vector<long long> v = division(n);
    vector<long long> m;
    if (v.size()==2)
        {
            cout << n-1;
            return 0;
        }
    for (long long i=0; i<v.size(); i++)
        m.push_back(n/v[i]+v[i]-2);
    cout << *min_element(m.begin(), m.end());
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
using namespace std;

struct Info{
	Info(ll arg_num){
		num = arg_num;
	}
	bool operator<(const struct Info &arg) const{
		return num < arg.num;
	};
	ll num;
};

int main(){

	int N,count = 0;
	ll ans = 1,tmp;
	scanf("%d",&N);

	priority_queue<Info> Q;

	for(int i = 0; i < N; i++){
		scanf("%lld",&tmp);
		Q.push(Info(tmp));
	}

	while(!Q.empty()){
		ans += ((tmp = Q.top().num - count/4) > 0)?tmp:0;
		count++;
		Q.pop();
	}

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

	return 0;
}

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

using namespace std;

int n;
int a[222];

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	n *= 2;
	int an = 0;
	for(int i = 1; i <= n; ++i){
		scanf("%d",&a[i]);
	}
	sort(a + 1, a + 1 + n);
	for(int i = 1; i <= n; i += 2){
		an += a[i];
	}
	printf("%d",an);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(a * b, c * d) << endl;
    return 0;
}


Measured memory_bytes: 3604
L, R = map(int, input().split())
intnumber = []
for i in range(L, min(R+1, L+2019)):
    intnumber.append(i%2019)

intnumber.sort()
ans = 2019
for i in range(len(intnumber)):
    for j in range(i+1, len(intnumber)):
        ans = min(ans, (intnumber[i]*intnumber[j])%2019)

print(ans)


Measured memory_bytes: 3060
#include <iostream>


int main ( void ) {
  int X, A, B;
  std::cin >> X >> A >> B;

  if( B - A > X ) {
    std::cout << "dangerous" << std::endl;
  } else if ( B - A > 0 ) {
    std::cout << "safe" << std::endl;
  } else {
    std::cout << "delicious" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
/*
strlen()で取得した長さだけ、for文でxを出力すればよくね？
*/

int main(){
  char s[100];
  memset(&s[0],0x00,sizeof(s));
  scanf("%s",&s);
  
  for(int i=0; i<strlen(s); i++){
    s[i] = 'x';
  }
  printf("%s",s);
}

Measured memory_bytes: 128
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans_lis = []

for i in range(N):
    ans_lis = ans_lis + [i + 1] * a[i]

for i in range(H):

    if i % 2 == 0:
        k = 1
    else:
        k = -1

    ans = ans_lis[i * W:(i + 1) * W][::k]
    ans = list(map(str, ans))
    print(" ".join(ans))


Measured memory_bytes: 9692
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main{
	private final static String NEGATIVE = "NO\n";
	private final static String AFFIRMATIVE = "YES\n";

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 512);
		int number = Integer.parseInt(br.readLine());//行数
		int sides[] = new int[3];
		int productAB;//辺abの積
		StringTokenizer tknz;
		StringBuilder builder = new StringBuilder();

		for (; 0 < number; number--) {
			tknz = new StringTokenizer(br.readLine());
			for (int i = 0; i < 3; i++) {
				sides[i] = Integer.parseInt(tknz.nextToken());
			}
			Arrays.sort(sides);
			if (((productAB = sides[0] * sides[1]) % 12) != 0) {
				builder.append(NEGATIVE);
			} else if (productAB * sides[2] % 60 != 0) {
				builder.append(NEGATIVE);
			} else if (Math.pow(sides[0], 2) + Math.pow(sides[1], 2) != Math.pow(sides[2], 2)) {
				builder.append(NEGATIVE);
			} else {
				builder.append(AFFIRMATIVE);
			}
		}
		System.out.print(builder);
	}
}

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

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

typedef long long ll;
typedef unsigned long long ull;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

int fx[]={1,-1,0,0};
int fy[]={0,0,-1,1};

int n, m;
int color[N];

vector < int > g[N];

int bfs(){
    queue < int > Q;
    memset(color, -1, sizeof color);
    color[1] = 1;
    Q.push(1);
    while(!Q.empty()){
        int u = Q.front(); Q.pop();
        for(int i = 0; i < g[u].size(); i++){
            int v = g[u][i];
            if(color[v] == color[u]) return 0;
            if(color[v] == -1){
                color[v] = 1 - color[u];
                Q.push(v);
            }
        }
    }
    return 1;
}

int Check(){
    int flag = bfs();
    if(!flag) return 0;
    int cnt = 0;
    for(int i = 1; i <= n; i++){
        if(color[i] == 1) cnt++;
    }
    return cnt;
}

int main(){
    fastScan(n); fastScan(m);
    for(int i = 1; i <= m; i++){
        int u, v;
        fastScan(u); fastScan(v);
        g[u].pb(v); g[v].pb(u);
    }
    int bipart = Check();
    if(bipart){
        ll lft = bipart, rgt = n - bipart;
        ll ans = lft * rgt - m;
        printf("%lld\n", ans);
    }else {
        ll ans = 1ll * n * (n - 1);
        ans /= 2;
        ans -= m;
        printf("%lld\n", ans);
    }
}


/*
9 18
1 4
1 5
1 6
1 7
1 8
1 9
2 4
2 5
2 6
2 7
2 8
2 9
3 4
3 5
3 6
3 7
3 8
3 9
*/


Measured memory_bytes: 6272
#include<bits/stdc++.h>
#include<vector>
#include<algorithm>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define ll long long int
using namespace std;
int main()
{
    int n,m,k,a,b;
    scanf("%d", &k);
 scanf("%d%d", &a, &b);
 
 int largest = (b / k) * k;
 if (a <= largest) {
 puts("OK");
 } else {
 puts("NG");
 }
 
 return 0;
 }


Measured memory_bytes: 3680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e6)


vector<string> split(string s,char ch){
    vector<string> ret;
    string tmp ="";
    rep(i,s.size()){
        if(s[i]==ch){
            ret.pb(tmp);
            tmp = "";
        }else tmp+=s[i];
    }
    if(tmp.size())ret.pb(tmp);
    return ret;
}

int main(){
    vector<string> vs;
    string s;
    while(cin>>s){
        vs.pb(s);
    }
    int h = vs.size();
    int w = (h+1)/2;
    vector<vector<int>> v(h,vector<int>(w,-INF));
    rep(i,vs.size()){
        vector<string> res = split(vs[i],',');
        rep(j,res.size()){
            v[i][j] = stoi(res[j]);
        }
    }
    
    vector<vector<int>> dp(h,vector<int>(w,-INF));
    dp[0][0] = v[0][0];
    
    for(int i=1;i<h;i++){
        if(i<=w-1){
            rep(j,w){
                int t = dp[i-1][j];
                if(j-1>=0)t = max(t,dp[i-1][j-1]);
                dp[i][j] = t+v[i][j];
            }
        }else{
            rep(j,w){
                int t = dp[i-1][j];
                if(j+1<w)t = max(t,dp[i-1][j+1]);
                dp[i][j] = t+v[i][j];
            }
        }
    }
    cout<<dp[h-1][0]<<endl;
}



Measured memory_bytes: 3216
n = int(input())
a = list(map(int, input().split()))

b1 = 0
b2 = 0
b4 = 0
for i in range(n):
   if a[i] % 4 == 0:
      b4 += 1
   elif a[i] % 2 == 0:
      b2 += 1
   else:
      b1 += 1
if b2 == 0:
   b4 += 1
if b1 <= b4:
   print('Yes')
else:
   print('No')


Measured memory_bytes: 19960
package main

import "fmt"

func main() {
	a, b, c, k := 0, 0, 0, 0
	fmt.Scanf("%d %d %d", &a, &b, &c)
	fmt.Scanf("%d", &k)
	if aa(a, b, c, k) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}
func aa(a, b, c, k int) bool {
	for {
		if b <= a {
			b *= 2
			k--
		} else {
			break
		}
		if k <= 0 {
			if c <= b {
                 //fmt.Println("b")
				return false
			} else {
              //fmt.Println("a")
				return true
			}
		}
	}
	for {
		if c <= b {
			c *= 2
			k--
		} else {
             //fmt.Println("d")
			return true
		}
		if k < 0 {
             //fmt.Println("e")
			return false
		}
	}
}


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

int main(){
    int n, k, temp, digit;
    cin >> n >> k;
    digit = 1;
    while (1){
        if(n / k > 0){
            temp = n / k;
            n = temp;
            digit++;
        } else {
            break;
        }

    }
    cout << digit << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define rep(i,n) for(int i=0;i<n;i++)
int gcd(int a, int b){
    int r=1;
    while(r!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
typedef long long ll;
void revStr(char* str){
    int size = strlen(str);
    int i,j;
    char tmp = {0};
    for(i = 0, j = size - 1; i < size / 2; i++, j--){
        tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }return;
}
typedef struct{
    int a,b;
}data;

//昇順
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
//構造体降順
int comp( const void *c1, const void *c2 )
{
  data test1 = *(data *)c1;
  data test2 = *(data *)c2;
  int tmp1 = test1.b;   /* b を基準とする */
  int tmp2 = test2.b;
  return tmp2 - tmp1;
}


int kai(int n){
    if(n==0){
        return 1;
    }
    int sum=1;
    for(int i=1;i<=n;i++){
        sum*=i;
    }
    return sum;
}

int main(){
    int N,M;
    scanf("%d%d",&N,&M);
    int city[N];
    rep(i,N){
        city[i]=0;
    }
    rep(i,M){
        int a,b;
        scanf("%d %d",&a,&b);
        city[a-1]++;
        city[b-1]++;
    }
    rep(i,N){
        printf("%d\n",city[i]);
    }
}


Measured memory_bytes: 1736
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main()
{ 
  string str;
  cin>>str; int i; long long sum=0;
  for(i=0;i<str.length();i++)
  {sum+=str[i]-'0';
  }
 if(sum%9ll==0ll)cout<<"Yes";
  else cout<<"No";
return 0;
}


Measured memory_bytes: 3488
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def is_prime(n):
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    for i in range(3, int(n**0.5) + 1, 2):
        if n % i == 0:
            return False
    return True

n = int(readline())
while is_prime(n) != True:
    n += 1
print(n)

Measured memory_bytes: 3060
#include <cstdio>

int n,m,k,p[11];
bool s[11][11];

int solve(int sn){
    if(sn>n){
        int i;
        for(i=1;i<=m;i++){
            if(p[i]==false)break;
        }
        if(i==m+1)return 1;
        else return 0;
    }

    int cnt=0;

    cnt += solve(sn+1);

    for(int i=1;i<=m;i++){
        if(s[i][sn])p[i]=!p[i];
    }
    cnt += solve(sn+1);
    for(int i=1;i<=m;i++){
        if(s[i][sn])p[i]=!p[i];
    }
    return cnt;
}

int main(void){
    int tmp;

    scanf("%d %d",&n,&m);
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            s[i][j] = false;
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&k);
        for(int j=1;j<=k;j++){
            scanf("%d",&tmp);
            s[i][tmp] = true;
        }
    }
    for(int i=1;i<=m;i++){
        scanf("%d",&tmp);
        p[i] = (tmp==0);
    }

    printf("%d\n",solve(1));

    return 0;
}


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

int N, ans, numA, numB, numBA;

int main() {
    cin >> N;
    string s[N];
    rep(i, N) {
        cin >> s[i];
        if (s[i][0] == 'B' && s[i][s[i].size()-1] == 'A') numBA++;
        else if (s[i][0] == 'B') numB++;
        else if (s[i][s[i].size()-1] == 'A') numA++;
        string str = s[i];
        while (str.find("AB") != string::npos) {
            ans++;
            str = str.substr(str.find("AB") + 1);
        }
        
    }
    //cout << numA << " " << numB << " " << numBA << " " << ans << endl;
    if (numBA) {
        ans += numBA - 1;
        if (numA) {
            ans++;
            numA--;
        }
        if (numB) {
            ans++;
            numB--;
        }
    }
    ans += min(numA, numB);
    /*
    int big = max(numA, numB), sml = min(numA, numB);
    cout << big << " " << sml << endl;
    ans += sml;
    big -= sml;

    ans += max(numBA - 1, 0);
    if (big > 0 && numBA > 0) ans++;
    */
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 768
//Is input file is the same as the below link?
//http://acm-icpc.aitea.net/index.php?plugin=attach&refer=2006%2FPractice%2F%CC%CF%B5%BC%B9%F1%C6%E2%CD%BD%C1%AA%2F%CC%E4%C2%EA%CA%B8%A4%C8%A5%C7%A1%BC%A5%BF%A5%BB%A5%C3%A5%C8&openfile=judge-data.zip
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
 
#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()
 
using namespace std;
 
const int INF = 1000000000;
const double eps = 1e-8;
 
int main(void) {
    int n;
    cin>>n;
    REP(i,n)
    {
        int h,w;
        cin>>h>>w;
        vector<string> table(h);
        set<char> s;
        REP(j,h)
        {
            cin>>table[j];
            REP(k,w)
            {
                s.insert(table[j][k]);
            }
        }
        s.erase('.');
        vector<char> mats;
        FORIT(j,s)
            mats.push_back(*j);
        if(mats.size())
        {
            bool flg = true;
            do
            {
                flg = true;
                vector<string> cp(h);
                REP(k,h)cp[k]=string(table[k]);
                REP(j,mats.size())
                {
                    int top=h,bottom=0,left=w,right=0;
                    REP(k,h)REP(l,w)
                    {
                        if(cp[k][l] == mats[j])
                        {
                            top=min(top,k);
                            bottom=max(bottom,k);
                            left=min(left,l);
                            right=max(right,l);
                        }
                    }
                    FOR(k,top,bottom+1)
                    {
                        FOR(l,left,right+1)
                        {
                            if(cp[k][l]=='.')
                            {
                                flg = false;
                                break;
                            }
                            else if(cp[k][l]==mats[j])
                            {
                                cp[k][l] = '.';
                            }
                        }
                        if(!flg)break;
                    }
                    if(!flg)break;
                }
                if(flg)break;
            }while(next_permutation(ALL(mats)));
            if(flg)
                cout << "SAFE" << endl;
            else
                cout << "SUSPICIOUS" << endl;
        }
        else
            cout << "SAFE"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
n = int(input())
H = list(map(int,input().split()))
dp = [0]*n

for i in range(1,n):
    if i == 1 or i == 2:
        dp[i] = abs(H[i]-H[0])
    else:
        dp[i] = min(abs(H[i]-H[i-2])+dp[i-2],abs(H[i]-H[i-1])+dp[i-1])

print(dp[n-1]) 


Measured memory_bytes: 13908
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        long[] A = new long[N];
        long[] F = new long[N]; //このAとFをintでやるとWA
        long allcost = 0;

        for(int i=0; i<N; i++){
            A[i]=sc.nextLong();
            allcost = allcost + A[i];
        }

        for(int i=0; i<N; i++){
            F[i]=sc.nextLong();
        }

        if(allcost<=K){
            System.out.println(0);
            return;
        }
        Arrays.sort(A);
        Arrays.sort(F);

       long ok = A[N-1]*F[N-1];
        long ng = 0;

        while(ok-ng>1){
            long h = (ok+ng)/2;
            long tot = 0;
            for(int i=0; i<N; i++){
                tot = tot+Math.max(A[N-i-1]-h/F[i], 0);
            }
            if(tot>K){
                ng = h;
            }else{
                ok = h;
            }
        }
        System.out.println(ok);
        
    }
}


Measured memory_bytes: 64588
import java.util.*;

public class Main {
  public static void main(String[] args) {
    new Main().execute();
  }

  public void execute() {
    Scanner sc = new Scanner(System.in);
    final int A = sc.nextInt();
    final int B = sc.nextInt();
    final int C = sc.nextInt();

    int m = Math.max(A, Math.max(B, C));

    int d = 3 * m - (A + B + C);
    if (d % 2 == 0) {
      System.out.println(d / 2);
    } else {
      System.out.println((d + 3) / 2);
    }
    sc.close();

  }

}

Measured memory_bytes: 22996
#include <cmath>
#include <cstring>
#include <iostream>
#include <ostream>
#include <vector>
 
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> v) {
  os << "[";
  for(int i = 0; i < int(v.size()); i++) {
    os << v[i] << (i == int(v.size()) - 1 ? "" : ", ");
  }
  os << "]";
  return os;
}
 
// n 以下の素数のリストを返す O(nlog(log(n)))
std::vector<int> eratosthenes(int n) {
  std::vector<int> is_prime(n + 1, 1);
  std::vector<int> primes;

  is_prime[0] = is_prime[1] = 0;
  primes.push_back(2);
  for(int i = 3; i <= n; i += 2) {
    if(is_prime[i]) {
      primes.push_back(i);
      for(int j = 3; i * j <= n; j += 2) {
        is_prime[i * j] = 0;
      }
    }
  }

  return primes;
}
 
int main() {
  int n;
  std::vector<int> primes = eratosthenes(10000);
 
  while(cin >> n, n) {
    int a = 2, b = 3;
    for(int i = 1; i < primes.size(); i++) {
      if (primes[i] > n) break;

      if(primes[i] - primes[i - 1] == 2) {
        a = primes[i - 1];
        b = primes[i];
      }
    }
    cout << a << " " << b << endl;
  }
 
  return 0;
}



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

const int MAXN = 100000;
int a[MAXN + 1], dir[MAXN + 1];
pair<int, int> b[MAXN + 1];


int main() {
    //ios_base::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, l, t;
    cin >> n >> l >> t;
    for(int i = 0; i < n; i++) {
        scanf("%d%d", &a[i], &dir[i]);
        if(dir[i] == 1)
            b[i] = { (a[i] + t) % l, i };
        else
            b[i] = { ((a[i] - t) % l + l) % l, i };
    }
    sort(b, b + n);
    ll shift = 0;
    vector<pair<int, int> > test;
    for(int j = 0; j < min(n, 4); j++) {
        shift = j;
        for (int i = 0; i < n; i++) {
            if (dir[i] != dir[j]) {
                ll len;
                if (dir[j] == 1)
                    len = a[i] - a[j];
                else
                    len = a[j] - a[i];
                if (len < 0)
                    len += l;
                ll calc = 0;
                if (2 * t < len)
                    calc = 0;
                else
                    calc = 1 + (2 * t - len) / l;
                if (dir[j] == 1)
                    shift = (shift + calc % n) % n;
                else
                    shift = ((shift - calc % n) % n + n) % n;
            }
        }
        int cur;
        if(dir[j] == 1)
            cur = (a[j] + t) % l;
        else
            cur = ((a[j] - t) % l + l) % l;
        test.push_back({ shift, cur });
    }
    for(int i = 0; i < n; i++) {
        bool ok = true;
        for(auto it: test) {
            if(b[(i + it.first) % n].first != it.second) {
                ok = false;
                break;
            }
        }
        if(!ok)
            continue;
        for(int j = 0; j < n; j++) {
            printf("%d\n", b[(i + j) % n]);
        }
        return 0;
    }
    return 0;
}

Measured memory_bytes: 2816