akhauriyash/Code-Regression huggingface dataset:
#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 1000000000
#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
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int n;cin>>n;vector<int> v(n);
    rep(i,0,n)cin>>v[i];
    int q;cin>>q;
    rep(i,0,q){
        int x;cin>>x;
        cout<<lower_bound(all(v),x)-v.begin()<<" "<<upper_bound(all(v),x)-v.begin()<<endl;
    }
    
    
}



/*

*/



Measured memory_bytes: 3088
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define yesno(flg) if(flg){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define MAX_N 2002
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<P1,P1> P2;
const ll INF=100000000000000001;
int dp1[MAX_N][MAX_N]={};
int dp2[MAX_N][MAX_N]={};
bool d[MAX_N][MAX_N]={};
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
queue<P1> que;
vector<string> v;

int main() {
	string s;
	cin>>s;
	cout<<s.substr(0,4)<<" "<<s.substr(4,8)<<endl;

	return 0;
}


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

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

    static int counter[100000];
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;

        counter[a - 1]++;
    }

    // 基本的には重複しているカードが2枚ずつ消えていく
    int even = 0,
        odd  = 0;
    for (int a = 0; a < 100000; a++) {
        if (counter[a] == 0) continue;
        else if (counter[a] % 2) odd++;
        else even++;
    }
    cout << even + odd - (even % 2) << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {// AtCorderの時はMainじゃないとコンパイルエラーになる

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(System.in);
		String S = sc.nextLine();

		if (S.equals("SSS")) {
			System.out.print("0");
		} else if (S.equals("RRS")||S.equals("SRR")) {
			System.out.print("2");
		} else if (S.equals("RRR")) {
			System.out.print("3");
		} else {
			System.out.print("1");
		}

	}
}


Measured memory_bytes: 35612
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
#define  B   begin()
#define  E   end()
const int N=2e5+3;
string s;
int main()
{
    ft
    int t,i,j,n,m,l,r;
    cin>>n>>s;
    m=s.size();
    for(i=0;i<m;i++)
    {
        l=s[i]-65;
        l+=n;
        l%=26;
        s[i]=(char)(l+65);
    }
    cout<<s<<"\n";
    return 0;
}



Measured memory_bytes: 3660
// Problem : A - Multiplication 1
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

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

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f, N = 100003, M = N << 1;

int n, m;

int main()
{
	//File("");
    int T = 1; 
    while (T--)
    {
    	n = gi(), m = gi();
    	cout << n * m << endl;
    }
	return 0;
}

Measured memory_bytes: 3588
#include<iostream>
#include<cstring> 
#include<algorithm>
#include<iomanip>
using namespace std;
int main()
{
	int k=0;
	int n,m;
	cin>>n>>m;
	while (n>=m)
	{
		n=n/m;
		k++;
	}
	cout<<k+1<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

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

int main(void)
{
  int x, y;
  scanf("%d%d", &x, &y);
  printf("%d\n", gcd(x, y));

  return 0;
}

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


int main() {
    int n;
    cin >> n;
    
    map<string, int> mp;
    string s;
    rep(i, n) {
        cin >> s;
        mp[s]++;
    }
    
    int mx = 0;
    for (auto p : mp) mx = max(mx, p.second);
    for (auto p : mp) {
        if (p.second != mx) continue;
        cout << p.first << endl;
    }
}

Measured memory_bytes: 25216
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	int N;
	cin >> N;
	vector<int> D(N);
	for(int i = 0; i < N; i++) cin >> D[i];
	sort(all(D));
	cout << D[N / 2] - D[N / 2 - 1] << endl;

	return 0;
}

Measured memory_bytes: 640
N = int(input())
p = list(map(int,input().split()))
ret = 0
flag = 0
for i in range(len(p)):
  if i + 1 == p[i]:
    if flag == 0:
      ret += 1
      if i < len(p)-1 and p[i+1] == i+2:
        flag = 1
    else:
      flag = 0
print(ret)

Measured memory_bytes: 14008
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define CINVEC(vec) const int size = (vec).size(); REP(i,size) cin>>(vec)[i];

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    int N;
    cin >> N;
    vector<int>A(N);
    CINVEC(A);

    SORT(A);

    cout << A[N - 1] - A[0] << endl;
    return 0;
}

Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W;
string S[100];

LL ans = 0;

void solve(){
	//(i,j)に到達するのに必要な、反転に必要な最小回数
	vector<vector<LL>> dp(H,vector<LL>(W,INF));
	dp[0][0] = (S[0][0]=='#');
	int direction[2][2] = {{1,0},{0,1}};
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			for(int k=0;k<2;k++){
				int ni = i+direction[k][0];
				int nj = j+direction[k][1];
				if(ni>=H || nj>=W) continue;
				if(S[i][j]=='.' && S[ni][nj]=='#'){
					dp[ni][nj] = min(dp[ni][nj],dp[i][j]+1);
				}else{
					dp[ni][nj] = min(dp[ni][nj],dp[i][j]);
				}
			}
		}
	}
	ans = dp[H-1][W-1];
}
 
int main(){
    cin >> H >> W;
    for(int i=0;i<H;i++) cin >> S[i];
 
    solve();

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

Measured memory_bytes: 384
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<ll> vl;

ll gcd(ll a, ll b){
    return b? gcd(b, a%b): a;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    ll a, b;
    cin >> a >> b;
    if (a < b) swap(a, b);
    ll g = gcd(a, b);
    
    ll ans = 1;
    for (ll i=2;i*i<=g;i++){
        if (g%i==0){
            ans++;
            while(g%i==0) g /= i;
        }
    }
    if (g > 1) ans++;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A,B,sum=0;
  cin >> A >> B;

  for (int i=A;i<B+1;i++){
	if(i/10000 == i%10){
    	if(i/1000%10 == i%100/10){
        	sum+=1;
        }
    }
  } 
  	cout << sum << endl;
}

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

int main(){
  int n;
  ll a,b;
  cin>>n>>a>>b;
  ll vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  ll ans=0;
  for(int i=0;i<n-1;i++){
    ans+=min(a*(vec[i+1]-vec[i]),b);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <iostream>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <iomanip>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define tii tuple<int,int,int>
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}



int main(){
    int n=in(),m=in();
    vector<vector<pair<int,ll>>> e(n);
    rep(i,n-1){
        e[i+1].pb(mp(i,0));
    }
    rep(i,m){
        int l=in()-1,r=in()-1;
        ll c=in();
        e[l].pb(mp(r,c));
    }
    ll INF=LONG_MAX;
    vecll d(n,INF);
    d[0]=0;
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
    q.push(mp(0,0));
    while(!q.empty()){
        ll cost=q.top().first;
        int v=q.top().second;
        q.pop();
        if(d[v]>cost)continue;
        REP(x,e[v])if(d[x.first]>d[v]+x.second){
            d[x.first]=d[v]+x.second;
            q.push(mp(d[x.first],x.first));
        }
    }
    cout<<(d[n-1]==INF?-1:d[n-1])<<endl;
}

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

using namespace std;

double rast(int x1,int y1,int x2,int y2)
{
    return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}

int main()
{

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

    int a,b;
    cin >> a >> b;
    cout << max(a-b,max(a+b,a*b));

}


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

using ll = long long;
#define countof(a) (sizeof(a)/sizeof((a)[0]))
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define int long long

const int MOD = 1000000007;

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

    string S; cin >> S;

    vector<vector<int>> dp(4, vector<int>(S.size()+1, 0));
    dp[0][0] = 1;
    
    for (int w = 1; w <= S.size(); w++) {
        for (int h = 0; h < 4; h++) {
            dp[h][w] = dp[h][w-1] * (S[w-1] == '?' ? 3 : 1);
            dp[h][w] += h != 0 && (S[w-1] == '?' || S[w-1] - 'A' + 1 == h) ? dp[h-1][w-1] : 0;
            dp[h][w] %= MOD;
        }
    }
    cout << dp.back().back() << endl;
}


Measured memory_bytes: 4432
#084_C
n = int(input())
csf = [list(map(int, input().split())) for _ in range(n-1)]

def train(i, t):
    if i==n-1:
        return t
    
    c, s, f = csf[i]
    
    if t < s:
        return train(i+1, s+c)
    else:
        return train(i+1, -(-t//f)*f+c)
    
for i in range(n):
    print(train(i, 0))

Measured memory_bytes: 3700
#include <stdio.h>

int main(void)
{
	int a,b,c,d=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a*10+b+c>d){
		d=a*10+b+c;
	}
	if(a+b*10+c>d){
		d=a+b*10+c;
	}
	if(a+b+c*10>d){
		d=a+b+c*10;
	}
	printf("%d",d);
	return 0;
}

Measured memory_bytes: 128
import sys
input = sys.stdin.readline

N = int(input())
data = dict()
for _ in range(N):
    s = input()[:-1]
    if s in data:
        data[s] += 1
    else:
        data.setdefault(s, 1)

ans = sorted(data.items(), key=lambda x:x[1], reverse=True)
M = ans[0][1]
A = []
for item, i in ans:
    if M == i:
        A.append(item)
    else:
        break
A.sort()
for item in A:
    print(item)

Measured memory_bytes: 45788
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>
#include<unordered_set>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    unordered_set<int> h;
    rep(i, N) h.insert(A[i]);
    if (A.size() == h.size()) cout << "YES" << endl;
    else cout << "NO" << endl;



	return 0;
}


Measured memory_bytes: 9288
#include<iostream>
#include<string>
#include <cstdio>
#include<vector>
#include<map>
#include<utility>
#include<list>
#include<algorithm>
#include <ctype.h>
#include<deque>
using namespace std;
using ll = long long int;

int n;
vector<bool> used;
map<int, int> a;

int main(void) {
	cin >> n;
	used.resize(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	int ret = 0;
	int b=1;
	while (b != 2) {
		if (!used[b]) {
			used[b] = true;
			b = a[b];
			ret++;
		}
		else {
			ret = -1;
			break;
		}
	}
	cout << ret << endl;
	return 0;
}

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

int main() {
   int n[4];
   for(int i=0;i<4;i++)cin>>n[i];
   sort(n,n+4);
   int x[4] = {1,4,7,9};
   for(int i=0;i<4;i++){
      if(n[i]!=x[i]){
         cout<<"NO";
         return 0;
      }
   }
   cout<<"YES";
   return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000000LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int func(int n){
  if(n % 2 == 0)
    return n / 2;
  else
    return n * 3 + 1; 
}

int main() {
  int s;
  cin >> s;
  int cnt = 1;
  bool f = false;
  set<int> st;
  st.insert(s);
  while(!f){
    s = func(s);
    cnt++;
    st.insert(s);
    if(st.size() < cnt) f = true;
  }
  cout << cnt << ln;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <iomanip>
#include <typeinfo>
#include <iterator>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <tuple>
#include <map>
#include <set>
#include <numeric>
using namespace std;

#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))
#define LLONG_MAX numeric_limits<long long>::max()
#define INT_MAX numeric_limits<int>::max()

typedef long long       ll;
typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<string>  vs;
typedef vector<char>    vc;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;
typedef vector<vll>		vvll;
typedef vector<vi>		vvi;
typedef vector<vb>		vvb;
typedef vector<vs>		vvs;
typedef vector<vc>		vvc;

typedef struct edge_ {
	ll to;
	ll cost;
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr ll		INF = 1 << 15;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template<typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

template<typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " " << p.second << "}";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	string S;
	cin >> S;
	int N = S.length();

	int rnum, bnum;
	rnum = bnum = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == '0')
			rnum++;
		else if (S[i] == '1')
			bnum++;
	} 

	cout << min(rnum, bnum) * 2 << endl;

	return 0;
}

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

int main()
{
	int n,x;
	for (;;)
	{
		cin >> n >> x;
		if ((n==0)&&(x==0))
		{
			return 0;
		}

		int i,j,k;
		int count=0;

		for (i=1;i<=n;++i)
		{
			for (j=i+1;j<=n;++j)
			{
				for (k=j+1;k<=n;++k)
				{
					if (i+j+k==x)
					{
						++count;
					}
				}
			}
		}
		cout << count << endl;
	}
}








Measured memory_bytes: 3100
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(v) cout<<v<<"\n"

int main() {
  int N; scanf("%d", &N);

  map<ll, int> m;
  int ans = 0;
  rep(i, N) {
    ll a; scanf("%d", &a);
    ++m[a];
    if (m[a] % 2 == 1) ++ans;
    else --ans;
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 6528
fun main() {
    val k = readInt()

    var n = 0
    var t = 1
    var count = 0
    while (true) {
        n = (n + 7 * t) % k
        t = (t * 10) % k
        count++
        if (n == 0) {
            println(count)
            return
        }
        if (count > k) {
            println(-1)
            return
        }
    }
}

private fun readInt() = readLine()!!.toInt()
private fun readInts() = readLine()!!.split(" ").map { it.toInt() }
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }


Measured memory_bytes: 34644
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath> 
#include<memory.h> 
#include<sstream>
#include<time.h>
using namespace std;
const unsigned long long BIGEST=1000000000000000000+1000000000000000000;
const long long BIGER=1000000000000000000;
const int BIG=1000000000;
const long long MOD=19260817;
int main()
{
	int a,b;
	string st;
	cin>>a>>b;
	cin>>st;
	int g=0;
	for(int i=0;i<st.size();i++)
	{
		g+=(st[i]=='-');
	}
	if(g!=1)
	{
		cout<<"No";
		return 0;
	}
	if(st[a]!='-')
	{
		cout<<"No";
		return 0;
	}
	cout<<"Yes";
	return 0;
}

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

using namespace std;

const int N = 1234567;

char a[N], b[N], c[N];

int main() {
  scanf("%s %s %s", a, b, c);
  int la = strlen(a), lb = strlen(b), lc = strlen(c);
  if (a[la - 1] == b[0] && b[lb - 1] == c[0]) puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main() {

	int a, b;

	std::cin >> a >> b;

	if (a < b) {
		std::cout << "a < b"
			<< std::endl;
	}
	else if (a > b) {
		std::cout << "a > b"
			<< std::endl;
	}
	else{
		std::cout << "a == b"
			<< std::endl;
	}
		return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define REP(i,n,s) for (int i = (s); i < (n); i++)
#define SIZE 201
using namespace std;
typedef long long int LL;

int H, W, A[SIZE][SIZE], dp[2][SIZE][SIZE];

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

	memset(A, 0, sizeof(A));
	cin >> H >> W;
	REP(i, H, 0) {
		REP(j, W, 0) {
			cin >> A[i][j];
		}
	}

	int pos = 0;
	memset(dp, -1, sizeof(dp));
	dp[pos][0][0] = A[0][0];
	REP(i, H+W-1, 1) {
		pos ^= 1;
		memset(dp[pos], -1, sizeof(dp[pos]));
		REP(j, W, 0) {
			REP(k, W, 0) {
				if (dp[pos^1][j][k] == -1) continue;
				REP(x, j+2, j) {
					REP(y, k+2, k) {
						int s = i - x, t = i - y;
						if (s<0||s>=H||t<0||t>=H||x>=W||y>=W) continue;
						dp[pos][x][y] = max(dp[pos][x][y], dp[pos^1][j][k] + A[s][x] + (s==t?0:A[t][y]));
					}
				}
			}
		}
	}
	cout << dp[pos][W-1][W-1] << endl;
}

Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <stack>
#include <queue>
#include <algorithm>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
typedef long long int ll;
using   namespace std;
#define ALL(a) ((a).begin(),(a).end())
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
const ll MOD = 1000000007;

    ll  temp
        ,N,ans=0,sum=0,fir=0,sec=-1;
        priority_queue<ll> A;
        int count;
    ll S[3][100010];

int main() {
    cin>>N;
    int temp;
    REP(i,N*3){
        cin>>temp;
        A.push(temp);
    }
    REP(i,N*2){
        //cout<<A.top()<<endl;
        if(i%2==1){sum+=A.top();}
        A.pop();
    }


    cout<<sum;
}


Measured memory_bytes: 6128
import java.io.PrintWriter

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun main(args: Array<String>) {
    main()
    pw.flush()
}

fun main() {
    val K = nextInt()
    val a = K / 2
    val b = (K + 1) / 2
    println(a * b)
}

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

using namespace std;

int main()
{
	// 入出力関連設定
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);

	string s;
	cin >> s;

	for(int i=0;i<s.length();i++){
		if(s[i]=='?') s[i]='D';
	}
	cout << s << endl;
}

Measured memory_bytes: 3768
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#define pii pair<int,int>
#define mp make_pair
using namespace std;
int n,m,k,cx,cy,ans=1e9;
char s[805][805];
int d[805][805];
const int dx[]={0,1,-1,0},dy[]={1,0,0,-1};
void bfs()
{
	queue<pii> q;
	q.push(mp(cx,cy));d[cx][cy]=0;
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++)
		{
			int nx=x+dx[i],ny=y+dy[i];
			if(d[nx][ny]<=d[x][y]+1||s[nx][ny]=='#')continue;
			d[nx][ny]=d[x][y]+1;
		    q.push(mp(nx,ny));
	    }
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
		for(int j=1;j<=m;j++)
		{if(s[i][j]=='S')cx=i,cy=j,s[i][j]='.';d[i][j]=1e9;} 
	}
	bfs();
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	if(d[i][j]<=k)
	ans=min(ans,1+(min(min(i-1,n-i),min(j-1,m-j))+k-1)/k);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
long long a,b,c,d,i,e,f,g,n,m,k,l,j,A[500005],t;
string s;  
int main() {
           cin>>n>>a>>b;
           cout<<((n)/(a+b))*a+min(((n)%(a+b)),a);
}

Measured memory_bytes: 256
while n = gets.to_i
	break if n.zero?
	time_data = Array.new
	waiting_time = [0]
	n.times{ time_data << gets.to_i }
	time_data.sort[0,n-1].each.with_index { |time, i| waiting_time[i+1] = waiting_time[i] + time }
	puts waiting_time.inject(&:+)
end

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

int S[1000],top;

int pop(void);
void push(int);

int main(){
  
  int a,b;
  char s[100];
  
  top=0;

  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }

    else if(s[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
    }

    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }

    else push(atoi(s));

  }

  printf("%d\n",pop());

  return 0;
}

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
} 



Measured memory_bytes: 2076
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<queue>
using namespace std;
struct bian{int nxt,to;}bi[4040];
bitset<2020>p[4040],mp[2020],cur,ok,pr[2020];
int n,m,rd[2020][2020],id[2020][2020],idnum,head[2020],num,ans,f[2020][12],dep[2020];
inline void add(int from,int to){bi[++num]=bian{head[from],to};head[from]=num;}
void dfs(int v,int fa,int rt,int up,int num)
{
	rd[rt][v]=up;
	p[num][v]=0;
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa)continue;
		dfs(u,v,rt,up,num);
	}
}
void dfs1(int v,int fa)
{
	pr[v]=pr[fa];
	pr[v][v]=1;
	dep[v]=dep[fa]+1;
	f[v][0]=fa;
	for(int i=1;i<=10;++i)f[v][i]=f[f[v][i-1]][i-1];
	for(int i=head[v],u;i;i=bi[i].nxt)
	{
		u=bi[i].to;
		if(u==fa)continue;
		dfs1(u,v);
	}
}
queue<pair<int,int> >q;
void work(int x,int y)
{
	cur=ok&mp[y]&~mp[x];
//	printf("work %d %d\n",x,y);
//	for(int i=1;i<=n;++i)if(cur[i])printf("%d ",i);printf("\n");
	int z=cur._Find_next(0);
	while(z<=n)q.push(make_pair(x,z)),mp[x][z]=mp[z][x]=1,z=cur._Find_next(z);
}
int lca(int x,int y)
{
	if(dep[x]<dep[y])swap(x,y);
	for(int i=10;~i;--i)if(dep[f[x][i]]>=dep[y])x=f[x][i];
	if(x==y)return x;
	for(int i=10;~i;--i)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
	return f[x][0];
}
int main()
{
	scanf("%d %d",&n,&m);
	int x,y;
	for(int i=1;i<n;++i)
	{
		scanf("%d %d",&x,&y);
		add(x,y),add(y,x);
	}
	for(int i=1;i<=n;++i)
		for(int j=head[i];j;j=bi[j].nxt)
		{
			id[i][bi[j].to]=++idnum;
			p[idnum].set();
			dfs(bi[j].to,i,i,bi[j].to,idnum);
	//		printf("%d %d:\n",i,bi[j].to);
	//		for(int k=1;k<=n;++k)if(p[idnum][k])printf("%d ",k);
	//		printf("\n");
		}
	dfs1(1,0);
	for(int i=1;i<=n;++i)mp[i][i]=1;
	for(int i=1;i<=m;++i)
	{
		scanf("%d %d",&x,&y);
		mp[x][y]=mp[y][x]=1;
		q.push(make_pair(x,y));
	}
	while(!q.empty())
	{
		x=q.front().first,y=q.front().second;q.pop();
	//	printf("%d %d\n",x,y);
		++ans;
		ok=pr[x]^pr[y];
		ok[lca(x,y)]=1;
		ok=p[id[y][rd[y][x]]]|p[id[x][rd[x][y]]]|ok;
//		for(int i=1;i<=n;++i)if(cur[i])printf("%d ",i);
	//	printf("\n");
		work(x,y);
		work(y,x);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 49716
public class Main {

    public static void main(String[] a) {
        int qq = 9;
        StringBuilder sb = new StringBuilder();
        for (int i = 1; i <= qq; i++) {
            for (int j = 1; j <= qq; j++) {
                sb.append(i + "x" + j + "=" + i * j + "\n");
            }
        }
        System.out.print(sb.toString());
    }

}

Measured memory_bytes: 16852
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define INF 1000000000001
#define se second
#define mod 1000000007
int main()
{
	ll x,y,ans=0;
	cin>>x>>y;
	if((y-2*x)%2==0)
	{
		ll b=(y-2*x)/2;
		ll a=x-b;
		if(a>=0 && b>=0)
		ans=1;
	}
	if(ans==1)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
inline int rd(){
	char c=getchar();int x=0,flag=1;
	for(;c<'0'||c>'9';c=getchar())if(c=='-')flag=-1;
	for(;c>='0'&&c<='9';c=getchar())x=x*10+c-'0';
	return x*flag;
}
int len,sz[26]={0},nw[26]={0},c[200010],st[200010]={0},vec[26][200010];
char str[200010];bool vis[200010]={false};
inline void update(int x,int v){
	for(;x<=len;x+=x&-x)
		st[x]+=v;
	return;
}
inline int ask(int x){
	int res=0;
	for(;x;x-=x&-x)
		res+=st[x];
	return res;
}
int main(){
	scanf("%s",str+1);
	len=strlen(str+1);
	for(int i=1;i<=len;i++)
		c[i]=str[i]-'a';
	for(int i=1;i<=len;i++)
		vec[c[i]][++sz[c[i]]]=i;
	int flag=0;
	for(int i=0;i<26;i++)
		flag+=sz[i]&1;
	if((len%2==0&&flag)||flag>1){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=len;i++)
		update(i,1);
	ll ans=0;int num=0,sum=len;
	for(int i=1;i<=len;i++){
		if(vis[i])
			continue;
		nw[c[i]]++;num++;
		if(nw[c[i]]>(sz[c[i]]>>1)){
			ans+=(len>>1)+1-num;
			continue;
		}
		ans+=sum-ask(vec[c[i]][sz[c[i]]-nw[c[i]]+1]);
		update(i,-1);update(vec[c[i]][sz[c[i]]-nw[c[i]]+1],-1);
		vis[i]=vis[vec[c[i]][sz[c[i]]-nw[c[i]]+1]]=true;
		sum-=2;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 20608
# -*- coding: utf-8 -*-

N,T = map(int, input().split())
tN = list(map(int, input().split()))

ans = T
for i in range(1,N):

    if tN[i] - tN[i-1] < T:
        ans += tN[i] - tN[i-1]
    else:
        ans += T

print(ans)

Measured memory_bytes: 26708
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main() {
  while ( true ) {
	int b, r, g, c, s, t;
	cin >> b >> r >> g >> c >> s >> t;
	if ( b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0 ) break;
	cout << 100 + b * 15 * 6 + 15 * r * 4 + g * 7 + c * 2 - 3 * ( t - s - b * 5 - r * 3 ) - 2 * ( b * 5 + r * 3 ) << endl;
  }  
}

Measured memory_bytes: 1160
#include <cstdio>
#include <iostream>
#define ll long long
const int MAXN = 1e5 + 7;
const ll INF = 1ll << 60;
using namespace std;
ll a[MAXN];

ll sum, ans = INF, res, n;
int main() {
	
	bool flag = 0;
	cin>>n;
	for(int i = 1; i <= n; i++)
		cin>>a[i];
	
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(!flag) { // if flag is 0 , means sum is postive
			if(sum <= 0) {
				res += 1 - sum;
				sum = 1;
			}
		}else {
			if(sum >= 0) {
				res += sum + 1;
				sum = -1;
			}
		}
		flag ^= 1;
	}
	if(res < ans) ans = res;
	flag = 0, res = sum = 0;
	for(int i = 1; i <= n; i++) {
		sum += a[i];
		if(!flag) { // if flag is 0 , means sum is negative
			if(sum >= 0) {
				res += sum + 1;
				sum = -1;
			}
		}else {
			if(sum <= 0) {
				res += 1 - sum;
				sum = 1;
			}
		}
		flag ^= 1;
	}
	if(res < ans) ans = res;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
//
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define maxnn 2010
ll n;
ll ry[maxnn][maxnn];
ll ru[maxnn];
ll d=0;
ll mark[maxnn];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<n;j++)
	{
		scanf("%lld",&ry[i][j]);
		ru[i]=1;
	}
	}
	while(1)
	{
		d++;
		for(int i=1;i<=n;i++)
{
		mark[i]=0;
}
		int tt=0;
		int tr=0;
		for(int i=1;i<=n;i++)
{
		if(ru[i]==n)	{continue;}
		if(mark[i]) {continue;}
		if(ry[ry[i][ru[i]]][ru[ry[i][ru[i]]]]!=i) 
	{
		tt++;
	} 
	else
	if(!mark[i]&&!mark[ry[i][ru[i]]])
	{
			ru[ry[i][ru[i]]]++;
			mark[i]=1;
			mark[ry[i][ru[i]]]=1;
			ru[i]++;
	}
}
	for(int i=1;i<=n;i++)
	if(ru[i]==n) tr++;
	if(tr==n) {cout<<d;return 0;}
	if(n-tr==tt) {cout<<-1;return 0;}
	}
} 

Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
const double pi=acos(-1);
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};
#define ll long long
#define inf int(1e9+7)
#define pb push_back
#define mp make_pair
string s,t;
vector<pair<string,int> >v;
int main()
{
	cin>>s>>t;
	int l=t.length();
	for(int i=0;i<s.length()-l+1;i++)
	{
		string tmp=s.substr(i,l);
		v.pb(mp(tmp,i));
	}
	for(int i=v.size()-1;i>=0;i--)
	{
		string tmp=v[i].first;
		int beg=v[i].second;
		bool same=1;
		int k=0;
		for(int j=beg;j<beg+l;j++)
		{
			if(s[j]!='?'&&s[j]!=t[k])
			{
				same=0;
				break;
			}
			k++;
		}
		if(!same)
			continue;
		k=0;
		for(int j=beg;j<beg+l;j++)
			s[j]=t[k],k++;
		for(int j=0;j<s.size();j++)
			if(s[j]=='?')
				s[j]='a';
		cout<<s;
		return 0;
	}
	puts("UNRESTORABLE");
	return 0;
}

Measured memory_bytes: 256
/*  "Sahand Alitanloo"  */
#include <bits/stdc++.h>
#define F first
#define S second
#define fast() ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define per(i) cout<<fixed<<setprecision(i)
#define pb push_back
#define all(v) begin(v),end(v)
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
typedef long double ld;
typedef long long ll;
const int MAX_N = 1e3+10;
const ll mod = 1e9+7;
const ll INF = 1e9;
inline ll bpow(ll t,ll n){ll ans=1,Sahaand=2018;while(n>0){if(n&1)ans=(ans*t)%mod;t=(t*t)%mod,n>>=1;}return ans;}
/*
ll fact[MAX_N],ifact[MAX_N];
inline ll c(ll n,ll k){if(k>n||k<0)return 0;return (fact[n]*ifact[k]%mod*ifact[n-k])%mod;}
inline void get_fact(){fact[0]=1;ifact[0]=1;for(ll i=1;i<MAX_N;i++)fact[i]=(fact[i-1]*i)%mod,ifact[i]=bpow(fact[i],mod-2);}
*/
#define int ll
int dp[MAX_N][MAX_N][2],dp2[MAX_N][MAX_N][2];
main(){
    fast();per(0);
    //get_fact();
    int n,k;cin>>n>>k;
    int cnt[2]={0,0};
    for(int i=1;i<=n;i++){
        char t;int x,y;cin>>x>>y>>t;
        int xx=x/k,yy=y/k;
        bool ok=(t=='B')^(xx&1)^(yy&1);
        cnt[ok]++;
        dp[x%k][y%k][ok]++;
        dp2[x%k][y%k][ok]++;
    }
    for(int i=0;i<k;i++)
        for(int j=0;j<k;j++)
            for(int t=0;t<2;t++){
                if(i>0)
                    dp2[i][j][t]+=dp2[i-1][j][t];
                if(j>0)
                    dp2[i][j][t]+=dp2[i][j-1][t];
                if(i>0&&j>0)
                    dp2[i][j][t]-=dp2[i-1][j-1][t];
            }
    for(int i=k-1;i>=0;i--)
        for(int j=k-1;j>=0;j--)
            for(int t=0;t<2;t++)
                dp[i][j][t]+=(dp[i+1][j][t]+dp[i][j+1][t]-dp[i+1][j+1][t]);
    int ans=0;
    for(int i=0;i<k;i++)
        for(int j=0;j<k;j++)
            if(i>0&&j>0)
                ans=max({ans,dp[i][j][0]-dp[i][j][1]+dp2[i-1][j-1][0]+cnt[1]-dp2[i-1][j-1][1],
                        dp[i][j][1]-dp[i][j][0]-dp2[i-1][j-1][0]+dp2[i-1][j-1][1]+cnt[0]});
            else
                ans=max({ans,dp[i][j][0]+cnt[1]-dp[i][j][1],dp[i][j][1]+cnt[0]-dp[i][j][0]});
    cout<<ans;
}




Measured memory_bytes: 32000
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    string S;
    cin >> S;
    int C = 0;  
    if (S[0] != 'A') goto BAD;
    for (int i = 2; i <= S.size() - 2; i++) if (S[i] == 'C') C++;
    if (C != 1) goto BAD;
    for (int i = 1; i < S.size(); i++) {
        char c = S[i];
        if (c == 'C' || (c >= 'a' && c <= 'z')) continue;
        goto BAD;
    }
    cout << "AC" << endl;
    return 0;
BAD:
    cout << "WA" << endl;
}


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

using namespace std;
typedef long long 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 = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#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};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  VI l(n);
  rep(i, n) cin >> l[i];
  sort(rall(l));
  int ans = 0;
  rep(i, n - 2) {
    for(int j = i + 1; j < n - 1; ++j) {
      int r = n - 1;
      int ll = j + 1;
      while((r - ll) > 1) {
        int m = (r + ll) / 2;
        if(l[m] + l[i] > l[j] && l[m] + l[j] > l[i]) ll = m;
        else r = m - 1;
      }
      if (l[r] + l[i] > l[j] && l[r] + l[j] > l[i]) ans += r - j;
      else if (l[ll] + l[i] > l[j] && l[ll] + l[j] > l[i]) ans += ll - j;
    }
  }
  out(ans);
  return 0;
}


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

int main() {
  int X , A , B ;
  cin >> X >> A >> B ;
  
  if (A >= B){
    cout << "delicious" << endl;
  }
  else if (X >= B - A){
    cout << "safe" << endl;
  }
  else {
    cout << "dangerous" << endl;
  }
}



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

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

    long N, K; cin>>N>>K;
    vector<long> A(N); for (auto& a : A) cin>>a;

    sort(A.begin(), A.end());

    auto check = [&](long x) -> bool {
        vector<long> M(N);
        for (int i = 0; i < N; i++)
            M[i] = A[i]%x;
        sort(M.begin(), M.end());
        long cap = K;
        int l = 0, r = N-1;
        while (cap > 0 and l < r) {
            if (M[l] <= x-M[r]) {
                cap -= M[l];
                M[r] += M[l];
                if (M[r] == x)
                    M[r--] = 0;
                M[l++] = 0;
            } else {
                cap -= x-M[r];
                M[l] -= x-M[r];
                M[r--] = 0;
            }
        }
        return cap >= 0 and M[l] == 0;
    };

    long ans = 0;
    long sum = 0;
    for (auto a : A) sum += a;
    long sup = *max_element(A.begin(), A.end())*N;
    for (long n = 1; n < sqrt(sum)+1; n++) {
        if (sum%n)
            continue;
        if (check(sum/n)) {
            ans = sum/n;
            break;
        } else if (check(n)) {
            ans = n;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n;
int a[20], b[20], c[20];
int ans;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	for (int i = 0; i < n; i++) {
		scanf("%d", b + i);
		ans += b[i];
	}
	for (int i = 0; i < n - 1; i++) {
		scanf("%d", c + i);
	}
	for (int i = 0; i < n - 1; i++) {
		if (a[i] + 1 == a[i + 1])ans += c[a[i] - 1];
	}
	printf("%d\n", ans);
}

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

int main(void)
{
  int N,i = 0,r = 0,b = 0;
  char s[256];
  scanf("%d",&N);
  scanf("%s",s);
  for(i=0;i<N;i++) {
    if(s[i] == 'R') r++;
    else if(s[i] == 'B') b++;
  }
  if(r > b) printf("Yes\n");
  else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define N 8
#define NOT_FREE 1
#define FREE 0

int p[N],row[N],col[N],dpos[2*N-1],dneg[2*N-1];

void PrintBoard()
{
  int i,j;
  for(i=0;i<N;i++)
    {
      for(j=0;j<N;j++)
	{
	  if(row[i]==j)
	    printf("Q");
	  else
	    printf(".");
	}
      printf("\n");
    }
}
void PutQueen(int i)
{
  int j;
  
  if(i==N)
    {
      PrintBoard();
      return;
    }

  if(p[i]==NOT_FREE)
    {
      PutQueen(i+1);
    }

  else
    {
      for(j=0;j<N;j++)
	{
	  if(col[j]==NOT_FREE || dpos[i+j]==NOT_FREE || dneg[i-j+N-1]==NOT_FREE)
	    continue;
	  
	      row[i]=j;
	      col[j]=dpos[i+j]=dneg[i-j+N-1]=NOT_FREE;
	      PutQueen(i+1);
	      col[j]=dpos[i+j]=dneg[i-j+N-1]=FREE;
	}
    }
}

int main()
{
  int i,r,c,k;
  
  scanf("%d",&k);
  for(i=0;i<k;i++)
    {
      scanf("%d%d",&r,&c);
      p[r]=NOT_FREE;
      row[r]=c;
      col[c]=dpos[r+c]=dneg[r-c+N-1]=NOT_FREE;
    }
  PutQueen(0);
  
  return 0;
}

Measured memory_bytes: 2596
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char *argv[])
{
	int i, n, len;
	int sum = 0;
	char buf[11];

	scanf("%s", buf);
	n = atoi(buf);
	len = strlen(buf);
	
	for (i = 0; i < len; i++) {
		sum += buf[i] - '0';
	}

	if (n % sum == 0) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}


	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
N = int(raw_input())
cnt = 0
dic = {}

for _ in xrange(N):
	rs = ''.join(sorted(raw_input()))
	
	if rs in dic:
		cnt += dic[rs]
		dic[rs] += 1
	else:
		dic[rs] = 1
print cnt

Measured memory_bytes: 16060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0;
int ch[1000005][26],s[1000005][26],h[1000005][26],n,tot=1;
string str[200005];
void Insert(string str){
	int now=1,l=str.length();
	for(int j=0;j<26;j++)h[l][j]=0;
	for(int i=l-1;i>=0;i--){
		for(int j=0;j<26;j++)h[i][j]=h[i+1][j];
		h[i][str[i]-'a']=1;
	}
	for(int i=0;i<l;i++){
		int w=str[i]-'a';
		if(!ch[now][w])ch[now][w]=++tot;
		for(int j=0;j<26;j++)if(h[i][j])s[now][j]++;
		now=ch[now][w];
	}
}
int Query(string str){
	int now=1,l=str.length();
	for(int i=0;i<l-1;i++){
		int w=str[i]-'a';
		if(!ch[now][w])return 0;
		now=ch[now][w];
	}
	return s[now][str[l-1]-'a'];
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>str[i],reverse(str[i].begin(),str[i].end());
	sort(str+1,str+n+1,[](string i,string j){return i.length()^j.length()?i.length()>j.length():i>j;});
	for(int i=1;i<=n;i++)ans+=Query(str[i]),Insert(str[i]);
	cout<<ans;
    return 0;
}


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

int main() {
    int N; cin >> N;
    int64_t a = 1, b = 1;
    rep(i, N) {
        int64_t A, B; cin >> A >> B;
        int64_t xa = (a + A - 1) / A;
        int64_t xb = (b + B - 1) / B;
        a = A * max(xa, xb);
        b = B * max(xa, xb);
    }
    cout << a + b << '\n';
    return 0;
}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
//using namespace std;
//const int mod=1000003;
//long long ksm(long long a,long long b)
//{
//    a%=mod;
//    long long ret=1;
//    while(b)
//    {
//        if(b&1)ret=ret*a%mod;
//        b>>=1;
//        a=a*a%mod;
//    }
//    return ret;
//}
//long long A[1000010];
//int main()
//{
//    int t,cas=1;
//    A[0]=1;
//    for(int i=1;i<=1000000;i++)A[i]=A[i-1]*i%mod;
//    scanf("%d",&t);
//    while(t--)
//    {
//        int a,b;
//        scanf("%d%d",&a,&b);
//        printf("Case %d: %lld\n",cas++,A[a]*ksm(A[b]*A[a-b],mod-2)%mod);
//    }
//    return 0;
//}
//#include<bits/stdc++.h>
//using namespace std;
//#define N 1100
//typedef long long ll;
//ll num[N];
//int main()
//{
//    int n;
//    scanf("%d", &n);
//    for(int i=0; i<n; i++)
//        scanf("%lld", &num[i]);
//
//    if(n == 2)
//    {
//    	if(num[0] < num[1])
//    	   swap(num[0], num[1]);
//    	if((ll)(num[0]-num[1]) * (1.0+sqrt(5.0))/ 2.0 )
//    	   printf("B\n");
//    	else
//    	   printf("A\n");
//	}
//    else
//    {
//    	ll k = num[0];
//    	for(int i=1; i<n; i++)
//    	    k = k ^ num[i];
//    	if(k == 0)
//    	    printf("B\n");
//    	else
//    	    printf("A\n");
//	}
//
//	return 0;
//}
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n,a[100010],b[100010],c[100010],bb[100010];
int main()
{
    scanf("%lld",&n);
    for(ll i=0; i<n; i++)
        scanf("%lld",&a[i]);
    for(ll i=0; i<n; i++)
        scanf("%lld",&b[i]);
    for(ll i=0; i<n; i++)
        scanf("%lld",&c[i]);
    sort(a,a+n);
    sort(c,c+n);
    a[n]=c[n]=0x3f3f3f3f;
    ll sum=0;
    for( ll i=0; i<n; i++)
    {
        ll k=lower_bound(a,a+n,b[i])-a;
        ll x=upper_bound(c,c+n,b[i])-c;
        sum+=k*(n-x);
    }

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

    return 0;
}



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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, K;
    cin >> N >> K;

    vector<ll> L(N);

    REP(i, N){
        cin >> L[i];
    }

    sort(L.rbegin(), L.rend());

    ll ans = 0;
    REP(i, K){
        ans += L[i];
    }

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

Measured memory_bytes: 3632