akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
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;
}
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Pl = pair<long long, long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;
#define INF 1e+9

int main() {
    int H,W;
    cin >> H >> W;
    int N;
    cin >> N;
    veci A(N);
    REP(i,N) cin >> A[i];
    veci ans;
    REP(i,N) {
        REP(j, A[i])
        ans.push_back(i + 1);
    }
    REP(i, H)
    {
        if(i%2 == 0) for(int j = 0; j < W; j++) {
            cout << ans[i*W + j] << " ";
        }
        else {
            for (int j = W - 1; j >= 0; j--) {
                cout << ans[i*W + j] << " ";
            }
        }
        cout << endl;
    }
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll a, b, c;
    cin >> a >> b >> c;
    cout << min(b/a, c) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n,a,b ;
	cin >> n >> a >> b ;
	a -= b ;
	vll h(n) ;
	for(auto &i:h) cin >> i ;
	sort(all(h)) ;
	reverse(all(h)) ;
	ll l=0,r=1e9+1,m ;
	while(l+1<r){
		m = (l+r)/2 ;
		ll cnt = 0 ;
		for(int i=0;i<n;i++){
			cnt += (max(0LL,h.at(i)-m*b+a-1))/a ;
		}
		if(cnt<=m) r = m ;
		else l = m ;
	}
	cout << r << endl ;
}


Measured memory_bytes: 4012
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

template<int Modulo = MOD> struct Mint {
	Int val;
	constexpr Mint(Int v = 0) noexcept : val(v% Modulo) {
		if (val < 0) v += Modulo;
	}
	constexpr int getmod() { return Modulo; }
	constexpr Mint operator - () const noexcept { return val ? Modulo - val : 0; }
	constexpr Mint operator + (const Mint& r) const noexcept { return Mint(*this) += r; }
	constexpr Mint operator - (const Mint& r) const noexcept { return Mint(*this) -= r; }
	constexpr Mint operator * (const Mint& r) const noexcept { return Mint(*this) *= r; }
	constexpr Mint operator / (const Mint& r) const noexcept { return Mint(*this) /= r; }
	constexpr Mint& operator += (const Mint& r) noexcept {
		val += r.val;
		if (val >= Modulo) val -= Modulo;
		return *this;
	}
	constexpr Mint& operator -= (const Mint& r) noexcept {
		val -= r.val;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr Mint& operator *= (const Mint& r) noexcept {
		val = val * r.val % Modulo;
		return *this;
	}
	constexpr Mint& operator /= (const Mint& r) noexcept {
		Int a = r.val, b = Modulo, u = 1, v = 0;
		while (b) {
			Int t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % Modulo;
		if (val < 0) val += Modulo;
		return *this;
	}
	constexpr bool operator == (const Mint& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Mint& r) const noexcept {
		return this->val != r.val;
	}
	friend ostream& operator << (ostream& os, const Mint<Modulo>& x) noexcept {
		return os << x.val;
	}
	friend istream& operator >> (istream& is, Mint<Modulo>& x) noexcept {
		Int tmp; is >> tmp;
		x = Mint<Modulo>(tmp);
		return is;
	}
	friend constexpr Mint<Modulo> modpow(const Mint<Modulo>& a, Int n) noexcept {
		Mint res(1), tmp = a;
		while (n > 0) {
			if (n & 1) res *= tmp;
			tmp *= tmp;
			n >>= 1;
		}
		return res;
	}
};

using mint = Mint<>;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> a(N);
	Int sum = 0;
	for (Int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}

	vector<Int> yama(N);
	/*Int sum = 0;
	for (Int i = 0; i < N; i++) {
		sum += a[i];
	}*/

	Int odd = 0;
	for (Int i = 1; i < N-1; i+=2) {
		odd += a[i];
	}

	yama[0] = (sum - 2*odd) / 2;
	for (Int i = 1; i < N; i++) {
		yama[i] = a[i - 1] - yama[i - 1];
	}

	for (Int i = 0; i < N; i++) {
		printf("%ld ", 2 * yama[i]);
	}
}

Measured memory_bytes: 2944
from sys import stdin
def make_divisors(n):
    mod0 = set()
    mod1 = set()
    for i in range(2, int(n**0.5)+1):
        if n%i==0:
            mod0.add(i)
            mod0.add(n/i)
        if (n-1)%i==0:
            mod1.add(i)
            mod1.add((n-1)/i)
    return mod0,mod1

N=list(map(int,(stdin.readline().strip().split())))

num=N[0]
if num==2:print(1)
else:
    K=0
    mod0,mod1=(make_divisors(num))
    # mod0.remove(1)
    # mod1.remove(1)
    for i in mod0:
        num = N[0]
        while(num % i == 0):
            num/=i

        if num%i==1:
            K+=1
    K+=len(mod1)+2
    print(K)


Measured memory_bytes: 3828
import heapq
n, m, s, t = map(int, input().split())
edges_yen = [[]for _ in range(n)]
edges_snuuk = [[]for _ in range(n)]
for _ in range(m):
    u, v, a, b = map(int, input().split())
    edges_yen[u-1].append((a, v-1))
    edges_yen[v-1].append((a, u-1))
    edges_snuuk[u-1].append((b, v-1))
    edges_snuuk[v-1].append((b, u-1))


def dijkstra(init_v, edges):
    next_v = [(0, init_v)]
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        d, v = heapq.heappop(next_v)
        if dist[v] < d:
            continue
        for d, v2 in edges[v]:
            if dist[v2] <= dist[v]+d:
                continue
            dist[v2] = dist[v]+d
            heapq.heappush(next_v, (dist[v2], v2))
    return dist


dist_yen = dijkstra(s-1, edges_yen)
dist_snuuk = dijkstra(t-1, edges_snuuk)
dist = [x+y for x, y in zip(dist_yen, dist_snuuk)]
ans = []
INF = 10**18
MIN = INF
for x in dist[::-1]:
    if x < MIN:
        MIN = x
    ans.append(MIN)
for x in ans[::-1]:
    print(10**15-x)

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

struct FS{
	ll x,y;
}n,a,b,c;

FS operator + (FS u,FS v){
	return (FS){ u.x*v.y+v.x*u.y , u.y*v.y };
}
FS operator - (FS u,FS v){
	return (FS){ u.x*v.y-v.x*u.y , u.y*v.y };
}
bool operator < (FS u,FS v){
	return u.x*v.y<v.x*u.y;
}

int main(){
	ll t;cin>>t;n=(FS){4,t};
	for (int i=1;i<=3500;i++){
		a=(FS){1,i};
		for (int j=1;j<=3500;j++){
			b=(FS){1,j};
			c=a+b;
			if (c<n){
				c=n-c;
				if (c.y%c.x==0){
					printf("%d %d %lld",i,j,c.y/c.x);
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

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

	int ans[4]={};
	ans[0]=A+A-1;
	ans[1]=B+B-1;
	ans[2]=A+B;
	ans[3]=A+B;
	sort(ans,ans+4);
	cout << ans[3] << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
	ll s,w;
	cin>>s>>w;
	if(w>=s)
	{
		cout<<"unsafe"<<endl;
	}
	else
	{
		cout<<"safe"<<endl;
	}
	return 0;
}

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

using namespace std;

struct pp {
	long long coord;
	long long val;
	
	bool operator < (const pp& el) const {
		return (coord < el.coord);
	}
};

struct ppp {
	long long right;
	long long val;
};

int main() {
	ios::sync_with_stdio(false);
	long long n, d, a;
	cin>>n>>d>>a;
	vector < pp > v(n);
	for (long long i = 0; i < n; i++) {
		cin>>v[i].coord>>v[i].val;
		v[i].val = v[i].val / a + (v[i].val % a != 0);	
	}
	
	sort(v.begin(), v.end());
	
	/*for (int i = 0; i < n; i++)
		cout<<v[i].coord<<" "<<v[i].val<<endl;*/
	
	vector < long long > s(n);
	for (long long i = 0; i < n; i++)
		s[i] = 0;
	
	long long r = 0;
	
	long long sum = 0;
	vector < ppp > rb;
	long long cind = 0;
	
	long long res = 0;
	for (long long l = 0; l < n; l++) {
		while ((r < n) && (v[r].coord - v[l].coord <= 2 * d))
			r++;
		//cout<<"l r "<<l<<" "<<r<<endl;
		while (cind < rb.size() && (rb[cind].right <= l)) {
			sum -= rb[cind].val;
			cind++;
		}
		
		res += max(0LL, v[l].val - sum);
		rb.push_back({r, max(0LL, v[l].val - sum)});
		//cout<<rb.back().val<<endl;
		sum += rb.back().val;
		
	}
	
	cout<<res<<endl;
	
}


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

using namespace std;

int ball[11] = {0}, B = 0, C = 0;
int c = 0;
bool solve(int x, int y, int z){
	if(x == 10) return true;
	if(ball[x] > y){
		if(solve(x + 1, y = ball[x], z)) return true;
	}
	if(ball[x] > z){
		if(solve(x + 1, y, z = ball[x])) return true;
	}
	else return false;
}

int main(){
	int N;
	int i, j;
	cin >> N;
	for(i = 0; i < N; ++i){
		for(j = 0; j < 10; ++j) cin >> ball[j];
		if(solve(0, B, C)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 3012
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int>b(m);
    for(int i=0;i<m;i++)
    {
        cin>>b[i];
    }
    vector<vector<int>>v(n,vector<int>(m));
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>v[i][j];
        }
    }
    vector<int>result;
    for(int i=0;i<n;i++)
    {
        int fresult=0;
        for(int j=0;j<m;j++)
        {
            fresult+=(v[i][j]*b[j]);
        }
        fresult+=c;
        result.push_back(fresult);
    }
    int count=0;
    for(int i=0;i<result.size();i++)
    {
        if(result[i]>0){
            count++;
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3624
#include<iostream>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<stdio.h>
using namespace std;

#define rep(i,n) for(long long i = 0; i < n; i++)

typedef long long ll;
typedef unsigned long long int ulli;

const ll INF = ll(1e18) + 1;

//--------------------------------------------------

ulli gcd(ulli a, ulli b) {
	return (b <= 0) ? a : gcd(b, a % b);
}

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

//---------------------------------------------------
typedef pair<int, int> P;

void Main()
{
	int n; cin >> n;
	cout << ((n % 2 == 0) ? n / 2 : (n / 2 + 1)) << endl;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	Main();
	return 0;
}

Measured memory_bytes: 256
while 1:
    s=input()
    if '#' in s:break
    p=0
    e=[[]*2 for _ in range(10)]
    for x in s:
        if x=='b':e[p]+=['b']
        elif x=='/':p+=1
        else:e[p]+='.'*int(x)
    ans=''
    a,b,c,d=map(int,input().split())
    e[a-1][b-1],e[c-1][d-1]=e[c-1][d-1],e[a-1][b-1]
    for i in range(p+1):
        if i:ans+='/'
        a=0
        for j in e[i]:
            if j=='b':
                if a:ans+=str(a)
                ans+='b'
                a=0
            else:a+=1
        if a:ans+=str(a)
    print(ans)

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

  
// int knapsack(vector<int> weight,vector<int> value, int n, int w)
// {
//   if(n==0 || w==0)
//   {
//     return 0;
//   }
//   else if(weight[n-1]>w)
//   {
//     return knapsack(weight,value,n-1,w);
//   }
//   else
//   {
//     return max(value[n-1]+knapsack(weight,value,n-1,w-weight[n-1]),knapsack(weight,value,n-1,w));
//   }
// }

int main(){
	int n,w;
  cin >> n>> w;
  vector<long> weight(n);
  vector<long> value(n);
  for(int i= 0; i<n; i++)
  {
    cin >>weight[i]>>value[i];
  }
  vector<vector<long> > dp(n+1,vector<long>(w+1,0));
  for(int i = 0; i<n+1;i++)
  {
    for(int j = 0; j<w+1;j++)
    {
      if(i==0 || j==0)
      {
        dp[i][j] = 0;
      }
      else if(weight[i-1]>j)
      {
        dp[i][j] = dp[i-1][j];
      }
      else{
        dp[i][j] = max(value[i-1]+dp[i-1][j-weight[i-1]],dp[i-1][j]);
    }
  }
}
  
  cout << dp[n][w]<<endl;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	ll a;
	ll b;
	cin>>a>>b;
	if(a<b&&abs(a-b)>=a)cout<<a<<endl;
	else if(b==1||a%b==0)cout<<0<<endl;
	else
	{
		ll d=a/b;
		ll dd=d+1;
		ll ans=min(abs(a-(d*b)),abs(a-(dd*b)));
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rbf(a, x) for (auto& a : x)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb emplace_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    template<typename Num>
        constexpr Num mypow(Num a, long long b) {
            if(b==0)return 1;
            if (a==0)return 0;
            Num x = 1;
              while (b > 0) {
                if(b & 1)x*=a;
                a*=a;
                b >>= 1;
              }
              return x;
        }

    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;
    }

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s,t;
        cin>>s>>t;
        cout<<t+s<<endl;
    }

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
const int dx[4] = {0,1,0,-1};
const int dy[4] = {1,0,-1,0};
const int ddx[4] = {1,1,-1, -1};
const int ddy[4] = {1,-1,-1,1};
//////////////////////////////////

int main() {
    int a, b; cin >> a >> b;
    if(a < 10 && b < 10) cout << a*b << endl;
    else cout << -1 << endl;

    return 0;
}

// EOF


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

int main(){
	int muki = 1;//0 is n,1 is e,2 is s,3 is w
	int t = 1, myoko= 1, mtate = 0;
	char yoko[7][6], tate[7][6];
	for(int i = 0; i < 7; i++){
		for(int j = 0; j < 6; j++){
			yoko[i][j] = '0';
			tate[i][j] = '0';
		}
	}
	for(int i = 1; i < 10; i++){
		if(i % 2 != 0){
			for(int j = 1; j < 5; j++){
				cin >> yoko[(i/2)+1][j];
			}
		}
		else{
			for(int j = 1; j < 6; j++){
				cin >> tate[j][t];
			}
			t++;
		}
	}
	cout << "R";
	while(myoko != 0 || mtate != 0){
		if(muki == 0){
			if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else{
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
		}
		else if(muki == 1){
			if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else{
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
		}
		else if(muki == 2){
			if(yoko[mtate+1][myoko+1] == '1'){
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
			else if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else{
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
		}
		else{
			if(tate[myoko+1][mtate+1] == '1'){
				mtate = mtate+1;
				cout << "D";
				muki = 2;
			}
			else if(yoko[mtate+1][myoko] == '1'){
				myoko = myoko-1;
				cout << "L";
				muki = 3;
			}
			else if(tate[myoko+1][mtate] == '1'){
				mtate = mtate-1;
				cout << "U";
				muki = 0;
			}
			else{
				myoko = myoko+1;
				cout << "R";
				muki = 1;
			}
		}
	}
	cout << endl;
}

Measured memory_bytes: 1136
#include<iostream>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#define ll long long
using namespace std;
const int maxn=((1<<17)+10);
const int mod=1e9+7;
int n,m,a[18];
ll dp[maxn],inv[maxn],jc[maxn],tw[maxn],cnt[maxn],ans;
ll kuai(ll x,int y)
{
	ll ans=1;
	while(y)
	{
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;y>>=1;
	}
	return ans%mod;
}
void pre()
{
	jc[0]=jc[1]=1;tw[0]=1;inv[0]=1; 
	for(int i=1;i<=n;i++)
		tw[i]=tw[i-1]*2%mod;
	for(int i=1;i<=tw[n];i++)
		jc[i]=jc[i-1]%mod*i%mod;
	inv[tw[n]]=kuai(jc[tw[n]],mod-2);
	for(int i=tw[n];i>=1;i--)
		inv[i-1]=inv[i]*i%mod;
	cnt[0]=0;
	for(int i=1;i<=tw[n];i++)
		cnt[i]=cnt[i>>1]+(i&1);
}

ll C(ll n,ll m)
{
	if(n<m||n<0||m<0)return 0;
	return jc[n]%mod*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
	scanf("%d%d",&n,&m);
	pre();//cout<<C(2,1)<<endl;
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	dp[0]=1;sort(a+1,a+m+1);
	for(int i=m;i>=1;i--)
		for(int sta=tw[n]-1;sta>=0;sta--)
			for(int k=0;k<=n;k++)//Ã¶¾Ù 
			if(sta&tw[k])
				(dp[sta]+=dp[sta^tw[k]]%mod*C(tw[n]-a[i]-sta+tw[k],tw[k]-1)%mod*jc[tw[k]]%mod)%=mod;
	for(int i=0;i<=tw[n];i++)
	{
		dp[i]=dp[i]*jc[tw[n]-i-1]%mod;//¿ÕÎ»ÖÃËæ±ã 
		if(cnt[i]&1)ans=(ans-dp[i]+mod)%mod;
		else ans=(ans+dp[i])%mod;//cout<<ans<<endl;
	}
	printf("%lld",(ans*tw[n]%mod));
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W, K;
  cin >> H >> W >> K;
  int map[6][6];
  for (int h = 0; h < H; h++) {
    getchar();
    for (int w = 0; w < W; w++)
      map[h][w] = (getchar() == '#');
  }
  int count = 0;
  for (int hc = 0; hc < (1 << H); hc++) {
    bitset<6> hs(hc);
    for (int wc = 0; wc < (1 << W); wc++) {
      bitset<6> ws(wc);
      int hashs = 0;
      for (int a = 0; a < H; a++)
        for (int b = 0; b < W; b++)
          hashs += map[a][b] * hs[a] * ws[b];
      count += (int)(hashs == K);
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 3556
import sys
from collections import deque
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
MAX = 10**5+5
INF = 10**9
P = 1000000007

def resolve():
    s = input().strip()
    dp = [[0]*13 for _ in range(MAX)]
    dp[0][0]=1
    for i,x in enumerate(s):
        if x=='?':
            c=-1
        else:
            c=int(x)
        for j in range(10):
            if(c!=-1 and c!=j):
                continue
            for k in range(13):
                t=(k*10+j)%13
                dp[i+1][t] = dp[i+1][t]+dp[i][k]
        for j in range(13):
            dp[i+1][j]=dp[i+1][j]%P
    l=len(s)
    print(dp[l][5]%P)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 62044
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {

	int x, y, z;
	scanf("%d%d%d", &x, &y, &z);
	printf("%d\n", (x - z) / (y + z));

	return 0;
}


Measured memory_bytes: 128
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        e: [(usize1, usize1); n - 1],
    }
    let mut g = vec![vec![]; n];
    for (a, b) in e {
        g[a].push(b);
        g[b].push(a);
    }
    let mut r = (0, 0);
    for _ in 0..2 {
        let mut stack = vec![(r.1, r.1, 0)];
        while let Some((v, p, d)) = stack.pop() {
            r = std::cmp::max(r, (d, v));
            for &u in &g[v] {
                if u != p {
                    stack.push((u, v, d + 1));
                }
            }
        }
    }
    let ans = if r.0 % 3 == 1 {"Second"} else {"First"};
    println!("{}", ans);
}

fn main() {
    run();
}


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

int main() {
	int a,b;
	cin>>a;
	if(a<105)b=0;
	else if(a<135)b=1;
	else if(a<165)b=2;
	else if(a<189)b=3;
	else if(a<195)b=4;
	else b=5;
	cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
			int a = sc.nextInt();
			int l = sc.nextInt();
			if (l==0) {
				break;
			}
			HashMap<Integer, Integer> appear = new HashMap<Integer, Integer>();
			int i = 0;
			while(true) {
				if (appear.containsKey(a)) {
					int j = appear.get(a);
					System.out.println(j + " " + a + " " + (i-j));
					break;
				}else{
					appear.put(a, i);
				}
				i++;
				a = next(a,l);
			}
		}
	}
	
	public static int next(int x,int l) {
		int[] a = new int[l];
		for(int i=0;i<l;i++) {
			a[i] = x%10;
			x/=10;
		}
		Arrays.sort(a);
		int big = 0;
		int sml = 0;
		for(int i=0;i<l;i++) {
			big*=10;
			sml*=10;
			big += a[l-1-i];
			sml += a[i];
		}
		return big-sml;
	}

}

Measured memory_bytes: 20436
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char const *argv[]) {
  string s;
  cin>>s;
  string year,month,day;
  for(int i=0;i<4;i++){
    year.push_back(s[i]);
  }
  for(int i=5;i<7;i++){
    month.push_back(s[i]);
  }
  for(int i=8;i<10;i++){
    day.push_back(s[i]);
  }
int y=stoi(year),m=stoi(month);
  if(y<=2019&&m<=4){
    cout<<"Heisei"<<endl;
  }else{
    cout<<"TBD"<<endl;
  }

  return 0;
}


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

int main() {
  int n, a, b, p1, p2;
  cin >> n >> a >> b;
  
  p1 = a * n;
  p2 = b;
  
  if (p1 > p2) {
    cout << p2 << endl;
  }
  else {
    cout << p1 << endl;
  }
}

Measured memory_bytes: 3584
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder_Beginner_Contest_065
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            int x = 1, seach = 0;
            var problem = new List<int>();
            for (int i = 0; i < count; i++)
            {
                problem.Add(int.Parse(Console.ReadLine()));
            }
            seach = problem[0];
            while (seach!=2&&x<count)
            {
                x++;
                seach = problem[seach - 1];
            }
            if (seach==2)
            {
                Console.WriteLine(x);
            }
            else
            {
                Console.WriteLine(-1);
            }
        }
    }
}


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

//nのp乗
ll power(ll n,ll p){
    if(p==0){return 1;}
    if(p%2==1){return n*power(n,(p-1)/2)*power(n,(p-1)/2);}
    else{return power(n,p/2)*power(n,p/2);}
}

int main() {
    int H,W,K;
    cin>>H>>W>>K;
    vector<vector<int>> S(H,vector<int>(W));
    rep(i,H){
        rep(j,W){
            char c;
            cin>>c;
            S.at(i).at(j)=c-'0';
        }
    }

    ll ans=100000;

    rep(i,power(2,H-1)){
        vector<int> yoko(H);
        int x=i;
        rep(j,H-1){
            yoko.at(j+1)=yoko.at(j)+(x%2);
            x/=2;
        }
        int line=yoko.at(H-1)+1;
        ll sma=line-1;
        vector<int> old(line),ne(line);
        bool J=true;
        rep(j,W){
            rep(k,H){
                ne.at(yoko.at(k))+=S.at(k).at(j);
            }
            rep(k,line){
                if(ne.at(k)>K){J=false;}
                old.at(k)+=ne.at(k);
            }
            bool cha=false;
            rep(k,line){
                if(old.at(k)>K){cha=true;}
            }
            if(cha){
                sma++;
                rep(k,line){
                    old.at(k)=ne.at(k);
                }
            }
            rep(k,line){ne.at(k)=0;}
        }
        if(J){
            ans=min(ans,sma);
        }
    }

    cout<<ans<<endl;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define FOR(i, n, m) for(int (i) = (n); (i) < (m); ++(i))

constexpr int INF = 1e9;
//constexpr ll INF = 1LL<<61;
constexpr ll mod = 1e9+7;



int main(){
  int N;
  cin >> N;
  vector<int> A(N+1);
  REP(i, N+1){
    cin >> A[i];
  }
  vector<pair<ll, ll>> whole(N+1), node(N+1);
  node[N] = whole[N] = {A[N], A[N]};
  REPR(i, N-1){
    ll under = (whole[i+1].first+1)/2, upper = whole[i+1].second;
    node[i] = {under, upper};
    whole[i] = {under+A[i], upper+A[i]};
  }
  ll beki = 1;
  ll ans = 0;
  REP(i, N+1){
    if(i==0 && (whole[i].first != 1)){
      cout << -1 << endl;
      return 0;
    }
    if(beki*2 < whole[i].first || whole[i].second < beki){
      cout << -1 << endl;
      return 0;
    }
    if(i==0){
      ans += beki;
      continue;
    }
    beki = min(beki*2, whole[i].second);
    ans += beki;
    // cerr << "i:" << i << " beki:" << beki << " whole:" << whole[i].first << " " << whole[i].second << endl;
    beki -= A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6692
{-# LANGUAGE BangPatterns #-}

import Control.Monad
import Control.Monad.Trans.State
import Data.Char
import Data.List
import Data.Maybe
import qualified Data.ByteString.Unsafe as B
import qualified Data.ByteString.Char8  as C8

type Pair = (Int, Int)

main :: IO ()
main = do
  [n,m] <- readInts
  ps <- sortOn fst <$> replicateM n readPair
  print $ solve m ps

solve :: Int -> [Pair] -> Int
solve m = fst . foldl' f e
  where
    e = (0,0)
    f (!s,!n) (a,b)
      | n == m    = (s,n)
      | c > m     = (s+a*(m-n),m)
      | otherwise = (s+a*b,c)
      where
        c = n+b

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

readPair :: IO Pair
readPair = head . unfoldr readT <$> C8.getLine
  where
    readT = runStateT $
      (,) <$> StateT (C8.readInt . C8.dropWhile isSpace)
          <*> StateT (C8.readInt . B.unsafeTail)

Measured memory_bytes: 38268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

template<class T>inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T>inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	string s; cin >> s;
	if (s == "ABC")cout << "ARC" << "\n";
	else cout << "ABC" << "\n";

	return 0;
}


Measured memory_bytes: 3616
#include<stdio.h>
int main(void) {
	int k,i=0;
	char s[102];
	scanf("%d",&k);
	scanf("%s",s);
	while(s[i]!='\0') {
		i++;
	}
	if(i<=k) {
		printf("%s\n",s);
	}
	else if(i>k) {
		for(int j=0;j<k;j++) {
			printf("%c",s[j]);
		}
		printf("...\n");
	}
	return 0;
}

Measured memory_bytes: 1648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderD
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        long answer = 0;
        for (int i = 1; i <= n; i++)
        {
            answer += i - 1;
        }
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

using P = pair<int, int>;

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

    string s;
    cin >> s;

    int n = s.size();
    vector< vs32 > sum(n + 1, vs32(26));
    rep (i, 26) sum[0][i] = 0;

    rep (i, n)
    {
        rep (j, 26)
        {
            sum[i + 1][j] += sum[i][j] + (s[i] - 'a' == j);
        }
    }

    rep (j, 26)
    {
        priority_queue<P, vector<P>, greater<P>> pq;
        pq.push(P{1, -1});
        rep (i, n)
        {
            if (pq.top().first < 2 * sum[i + 1][j] - i && i - pq.top().second > 1)
            {
                cout << pq.top().second + 2 << " " << i + 1 << "\n";
                return 0;
            }
            pq.push(P{2 * sum[i + 1][j] - i, i});
        }
    }

    cout << "-1 -1\n";
    return 0;
}



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

#define int long long
#define ld long double

#define pb push_back
#define F first
#define S second
#define I insert
#define sz(a) (int)((a).size())
#define all(a) (a).begin(), (a).end()

#define debug1(a) cerr<<" "<<#a<<" : "<<a<<"\n"
#define debug2(a,b) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define debug3(a,b,c) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define debug4(a,b,c,d) cerr<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"
 
#define INF (int)100000000000000000
#define PI (double)3.14159265358979
#define MOD 1000000007


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
    int n;
    cin>>n;
    int a[n];
    int ans = 0;
    for (int i=0;i<n;++i)
    {
        cin >> a[i];
    }
    int mx = a[0];

    for (int i=1;i<n;++i)
    {
        if (a[i] < mx)
        {
            ans += mx - a[i];
        }
        mx = max(a[i], mx);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 5212
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int n,tmp,check;
    cin>>n;
    vector<int> a(n,0);
    check=n%2;
    for(int i=0;i<n;i++){
        cin>>tmp;
        a[tmp]++;
        if(tmp%2==check){
            cout<<"0"<<endl;
            return 0;
        }
        if(a[tmp]>2){
            cout<<"0"<<endl;
            return 0;
        }
    }
    long long int ans=0;
    if((check==1)&&(a[0]>1)){
        cout<<"0"<<endl;
            return 0;
    }
    for(int i=1;i<n;i++){
        if(a[i]%2==1){
            cout<<"0"<<endl;
            return 0;
        }
        if(a[i]>1){
            ans++;
        }
    }
    long long int finalans=1;
    for(int i=0;i<ans;i++){
        finalans*=2;
        finalans%=1000000007;
    }
    cout<<finalans<<endl;
}


Measured memory_bytes: 640
n = int(raw_input())
data = map(int, raw_input().split())
m = int(raw_input())
test = map(int, raw_input().split())

# def solve(i,left):
#     if left == 0:
#         return True
#     elif i >= n:
#         return False
#     return solve(i+1, left) or solve(i+1, left - data[i])

# for j in range(m):
#     if solve(0, test[j]):
#         print 'yes'
#     else:
#         print 'no'

a = [0]
for i in range(n):
    a = a + [a[j] + data[i] for j in range(len(a))]

for i in range(m):
    if test[i] in a:
        print 'yes'
    else:
        print 'no'
        

Measured memory_bytes: 57208
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>


using namespace std;

int main() {
    int cnt=0;
    string s; cin >> s;
    for (auto c:s) 
        if (c == 'x')cnt++;
    cout << (cnt < 8 ? "YES" : "NO") << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,M;
vector<int>a;
int v[222222];
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    cin>>N>>M;
    while(M--){
        int x,y;
        cin>>x>>y;
        if(x==1)a.push_back(y);
        if(y==1)a.push_back(x);
        if(x==N)v[y]++;
        if(y==N)v[x]++;
    }
    for(int i:a){
        if(v[i]){
            cout<<"POSSIBLE";
            return 0;
        }
    }
    cout<<"IMPOSSIBLE";
}


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

int main() {
  int N;
  cin >> N;
  
  int min;
  
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    
    int ope = 0;
    while (A % 2 == 0) {
      A /= 2;
      ope++;
    }

    if (i == 0) {
      min = ope;
    }
    
    if (ope < min) {
      min = ope;
    }
  }
  cout << min << endl;
}


Measured memory_bytes: 3588
import copy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    ans = []
    H,W,K = map(int, readline().split())
    c_ = [list(map(int, list(readline().strip()))) for _ in range(H)]

    for a in range(H):
        for b in range(W):
            c = copy.deepcopy(c_)
            c[a][b] = 0

            seq = [[1] for _ in range(H)]
            ans_tmp = [0]
            
            score = 0
            weight = 1
            while True:
                # 落とす
                for i in reversed(range(H)):
                    for j in range(W):
                        if c[i][j] == 0:
                            for h in reversed(range(i)):
                                if c[h][j] != 0:
                                    c[h][j], c[i][j] = c[i][j], c[h][j]
                                    break

                # 消す
                for i, line in enumerate(c):
                    for j in range(1,W):
                        if line[j] == line[j-1]:
                            seq[i][-1] += 1
                        else:
                            seq[i].append(1)
                
                    acc = -1
                    for s in seq[i]:
                        acc += s
                        if s >= K:
                            score += s * line[acc] * weight
                            for j in range(acc - s + 1, acc + 1):
                                line[j] = 0
                    seq[i] = [1]
                
                weight *= 2

                ans_tmp.append(score)
                if ans_tmp[-1] == ans_tmp[-2]:
                    ans.append(ans_tmp[-1])
                    break

    print(max(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 56924
in_num = input()
in_data=[]
for i in range(0,int(in_num)):
  in_data.append(input())
  
out_num = input()

out_data = []

for i in range(0,int(out_num)):
  out_data.append(input())

max_count=0
for n in in_data:
  tmp = in_data.count(n) - out_data.count(n)
  if tmp > max_count:
    max_count = tmp
    
print(max_count)

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

using namespace std;

int main() {
    double m, maxm = 0.0, minm = 1000000.0;
    while (scanf("%lf", &m) != EOF) {
        if (m > maxm) maxm = m;
        if (m < minm) minm = m;
    }
    cout << maxm - minm << endl;

    return 0;
}


Measured memory_bytes: 3308
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,i;
    long long a[100010],x=0,y=-1,s=0;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a[i];
        if(a[i]<0){
            x++;
            a[i]=-a[i];
        }
        s+=a[i];
        if(a[i]<y || y==-1)
            y=a[i];
    }
    if(x%2!=0)
        cout << s-2*y << endl;
    else
        cout << s << endl;
    return 0;
}


Measured memory_bytes: 1024
string = input()

length = len(string)
sindex = 0
for i in range(0, length):
  if string[i] == "S": 
    sindex = i
    break
    
s_count = 0

for i in range(sindex, len(string)):
  if string[i] == "S": s_count += 1
  if string[i] == "T" and s_count > 0:
    s_count -= 1
    length -= 2
    
print(length)

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

#define rep(i,n) for(int i=0; i<n; i++)
#define swap(a,b) tmp=a, a=b, b=tmp
int main(){
	long long int a, b, ai, bi, tmp;
	while(cin >>ai>>bi){
		a=ai, b=bi;
		if(a<b) swap(a,b);
		while(true){
			if(a%b==0) break;
			a%=b;
			swap(a,b);
		}
		cout << b << " " << ai*bi/b << endl;
	}
		

    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18+7107;
int n,a[200005];
ll dpf[200005],dpb[200005],f[200005],sum[200005],ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=n;i++) sum[i]=sum[i-1]+a[i];
	ans=INF;
	for(int i=1;i<=n;i++)
	{
		dpf[i]=min(sum[i-1],dpf[i-1])+(a[i]&1);
		if(!a[i]) dpf[i]+=2;
		//printf("dpf(%d)=(%lld,%lld)\n",i,dpf[i][0],dpf[i][1]);
	}
	for(int i=n;i>=1;i--)
	{
		dpb[i]=min(sum[n]-sum[i],dpb[i+1])+(a[i]&1);
		if(!a[i]) dpb[i]+=2;
		//printf("dfb(%d)=(%lld,%lld)\n",i,dpb[i][0],dpb[i][1]);
	}
	for(int i=1;i<=n;i++)
	{
		f[i]=min(min(sum[i-1],dpf[i-1]),f[i-1])+((a[i]&1)^1);
		ans=min(ans,min(f[i]+min(sum[n]-sum[i],dpb[i+1]),
			min(sum[i-1],dpf[i-1])+min(sum[n]-sum[i],dpb[i])));
		//printf("f(%d)=%lld\n",i,f[i]);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7424
#include <stdio.h>
#define INFTY 2147483647
#define N 500000
int L[N/2+2], R[N/2+2];
int cnt;
void merge(int *, int, int, int, int);
void mergeSort(int *, int, int, int);

int main(){
  int S[N], i;
  int n;
  cnt = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&S[i]);
  }
  mergeSort(S, n, 0, n);
  for(i=0; i<n; i++){
    if( i==n-1 ) {
      printf("%d\n", S[i]); 
    }
    else printf("%d ", S[i]);
  }
  printf("%d\n", cnt);
  return 0;
}


void mergeSort(int *S, int n, int left, int right){
  int mid;
  if(left+1 < right){
    mid = (left + right)/2;
    mergeSort(S, n, left, mid);
    mergeSort(S, n, mid, right);
    merge(S, n, left, mid, right);
  }
}

void merge(int *S, int n, int left, int mid, int right){
  int n1,n2;
  int i, j, k;
  n1 = mid - left;
  n2 = right - mid;
  for(i = 0; i < n1; i++){
    L[i] = S[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = S[mid + i];
  }
  L[n1] = R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left; k < right; k++) {
    cnt++;
    if(L[i] <= R[j]){
      S[k] = L[i];
      i = i + 1;
    }
    else {
      S[k] = R[j];
      j = j + 1;
    } 
  }
}



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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n, m;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  vector<pair<int, int>> edges;
  vector<vector<int>> g(n);
  vector<int> a(n);
  range(i, 0, n) {
    cin >> a[i];
  }
  range(i, 0, m) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    g[u].push_back(v);
    g[v].push_back(u);
    edges.emplace_back(u, v);
  }

  vector<int> color(n, -1);

  range(i, 0, n) {
    bool ok = false;
    for(int j : g[i]) ok |= a[j] <= a[i];
    if(!ok) {
      cout << -1;
      return 0;
    }
  }

  for(auto x : edges) {
    int u = x.first;
    int v = x.second;
    if(a[u] == a[v]) {
      if(color[u] == -1 && color[v] == -1) {
        color[u] = 0;
        color[v] = 1;
      } else {
        if(color[u] == -1) color[u] = color[v] ^ 1;
        if(color[v] == -1) color[v] = color[u] ^ 1;
      }
    }
  }

  range(i, 0, n) if(color[i] == -1) color[i] = 0;

  range(i, 0, n) {
    cout << (color[i] ? 'B' : 'W');
  }
  cout << endl;
  for(auto x : edges) {
    int u = x.first, v = x.second;
    if(color[u] != color[v]) cout << max(a[u], a[v]);
    else {
      if(a[u] == a[v]) cout << 1000000000;
      else cout << abs(a[u] - a[v]);
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 10736
#include <iostream>
using namespace std;
int main(void){
    int n, m;
    cin >> n >> m;
    
    //??????A?????\???????????????
    int A[n*m];
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> A[i * m + j];
        }
    }
    
    //??????B?????\???????????????
    int B[m];
    for (int i = 0; i < m; i++) {
        cin >> B[i];
    }
    
    //A*B=C??¨?????????????????????C????¨????
    int C[n];
    for (int i = 0; i < n; i++) {
        C[i] = 0;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            C[i] += A[i * m + j] * B[j];
        }
    }
    
    //??????
    for (int i = 0; i < n; i++) {
        std::cout << C[i] << std::endl;
    }
    
}

Measured memory_bytes: 1200
import java.io.IOException;
import java.util.Scanner;

public class Main {
	int n;
	int max;
	int a[];
	int b[];
	int c[];
	static final int MAX_INT = 10000;
	public static void main(String args[]) throws IOException {
		new Main().run();
	}
	Main() throws IOException {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		a = new int[n];
		b = new int[n];
		c = new int[MAX_INT + 1];
		max = 0;
		for (int i = 0; i < n; i++) {
			a[i] = scan.nextInt();
			max = Math.max(max, a[i]);
		}
	}
	void run() {
		for (int j = 0; j < n; j++) {
			c[a[j]]++;
		}
		for (int i = 1; i < max + 1; i++) {
			c[i] = c[i] + c[i-1];
		}
		for (int j = n - 1; j >= 0; j--) {
			b[c[a[j]] - 1] = a[j];
			c[a[j]]--;
		}
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < n; i++) {
			sb.append((i == 0? "" : " ") + b[i]);
		}
		System.out.println(sb);
	}
}


Measured memory_bytes: 557236
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long int;

//ARC090-D
//Union-Find木で各条件を検証する

vector<int> par;	//親
vector<ll> dfromp;	//親からの距離dist.from.par

ll dfr(int x) {		//根までの距離dist.from.root
	if (par[x] != x) {
		return dfromp[x] + dfr(par[x]);
	}
	else {
		return 0;
	}
}
int root(int x) {	//根
	if (par[x] == x) {
		return x;
	}
	else {
		dfromp[x] = dfr(x);
		par[x] = root(par[x]);
		return par[x];
	}
}

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

	for (int i = 0; i <= N; i++) {	//初期化
		par.push_back(i);
		dfromp.push_back(0);
	}
	for (int i = 0; i < M; i++) {
		int l, r, d; cin >> l >> r >> d;

		if (root(l) == root(r)) {	//同じ木にあるなら、距離の比較が可能
			if (dfr(r) != dfr(l) + d) {
				cout << "No"; return 0;//新情報によって矛盾が生じたらOUT
			}
		} else {	//違う木にあるなら、距離の比較が不能なので矛盾は生じない

			if (dfr(r) > dfr(l) + d) {
				dfromp[root(l)] = dfr(r) - dfr(l) - d;
				par[root(l)] = root(r);
			}
			else {
				dfromp[root(r)] = dfr(l) + d - dfr(r);
				par[root(r)] = root(l);
			}
		//	par[r] = l;	// l ← r として木をつなぐ
		//	dfromp[r] = d;//　辺の重みは距離
		}
	}

	cout << "Yes";
	return 0;
}


Measured memory_bytes: 1780
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	void main() {
		char c = (char) (sc.next().charAt(0) + 1);
		println(c);
	}
}


Measured memory_bytes: 23380