akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>

using namespace std;

int main()
{
	int N;
	string S;
	cin >> N;
	cin >> S;
	int maxMatch = 0;
	bool juhuku = 0;

	for (int i = 0; i <= N; ++i){
		string X, Y;
		for (int j = 0; j <= N; ++j){
			if (i > j)
				X += S[j];
			else
				Y += S[j];
		}
	/*	cout << "X,Y" << endl;
		cout << X << endl;
		cout << Y << endl;*/

		string match;
		for (int x = 0; x < X.size(); ++x){
			for (int y = 0; y < Y.size(); ++y){
				juhuku = 0;
				if (X[x] == Y[y]){
					for (int m = 0; m < match.size(); ++m){
						if (match[m] == X[x])
							juhuku = 1;
					}
					if (!juhuku)
					match += X[x];
				}
			}
		}
		if (maxMatch < match.size())
			maxMatch = match.size();
	}

	cout << maxMatch << endl;
	return 0;
}

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


#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ll long long


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

    int a, b, x;
    cin >> a >> b >> x;

    cout << (x - a <= b and x - a >= 0 ? "YES\n" : "NO\n");

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define here(s)      cout<<s<<endl;
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


typedef long long ll;


int main()
{
    run;
    ll h,n;
    cin>>h>>n;
    ll a,s=0;
    fr(i,0,n)
    {
        cin>>a;
        s+=a;
        
    }
    if(h>s)
    {
        cout<<"No";
    }else{
    cout<<"Yes";}




    return 0;
}


Measured memory_bytes: 256
# AOJ2019
shukuba = []
n = 0
m = 0

def solve():
    shukuba.sort(key = lambda x: x[1])
    s = sum(map(lambda x: x[0], shukuba)) - m
    if s <= 0:
        return 0
    e = 0
    i = 0
    while s > 0:
        d = shukuba[i][0] if s >= shukuba[i][0] else s
        e += shukuba[i][1] * d
        s -= d
        i += 1
    return e

while True:
    shukuba = []
    line = input()
    n, m = map(int, line.split())
    if n == 0 and m == 0:
        break
    for _ in range(0, n):
        c = list(map(int, list(input().split())))
        shukuba.append(c)
    print(solve())


Measured memory_bytes: 7144
using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = Read();
		var b = Read();

		var rn = Enumerable.Range(0, n).ToArray();
		var m = Enumerable.Range(0, 1 << n)
			.Select(x => Array.ConvertAll(rn, i => (x & (1 << i)) == 0 ? (a[i], false) : (b[i], true)))
			.Select(Swap)
			.Min();
		Console.WriteLine(m == 1 << 30 ? -1 : m);

		int Swap((int v, bool rev)[] c)
		{
			var g = Array.ConvertAll(c, _ => _.v);
			Array.Sort(g);
			var u = new bool[n];

			var map = new int[n];
			for (int i = 0; i < n; i++)
			{
				map[i] = -1;
				for (int j = 0; j < n; j++)
				{
					if (u[j] || g[i] != c[j].v || (i - j) % 2 != 0 != c[j].rev) continue;
					u[j] = true;
					map[i] = j;
					break;
				}
				if (map[i] == -1) return 1 << 30;
			}

			var t = 0;
			for (int i = 0; i < n; i++)
				for (int j = i + 1; j < n; j++)
					if (map[i] > map[j]) t++;
			return t;
		}
	}
}


Measured memory_bytes: 46980
/**
 *     author: qodjf
 *     created: 04.17.2020 00:29:18
 */
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;

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

string s;

int main() {
  cin >> s;
  int N = s.size();
  ll ans = 0;
  ll cntOfW = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (s[i] == 'W') {
      cntOfW++;
    } else {
      ans += cntOfW;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
string a;
string b;
vector<string> vt;
int ch[26];
int main()
{
	cin >> a;
	int t = a.size();
	for (int i = 0; i < t; i++)
	{
		for (int y = a[i] - 'a' + 1; y < 26; y++)
		{
			if (!ch[y])
			{
				string c = b + (char)(y + 'a');
				vt.push_back(c);
				break;
			}
		}
		b += a[i];
		ch[a[i] - 'a']++;
	}
	for (int i = 0; i < 26; i++) {
		if (!ch[i])
		{
			string c = a + (char)(i + 'a');
			vt.push_back(c);
			break;
		}
	}
	if (!vt.size()) {
		puts("-1");
		return 0;
	}
	sort(vt.begin(), vt.end());
	cout << vt[0];

}

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

int main() {
    long long n , a , b;
    cin >> n >> a >> b;
    long long MIN = (n - 1) * a + b , MAX = (n - 1) * b + a;
    long long ass = MAX - MIN;
    if(ass < 0) cout << 0 << endl;
    else cout << ass + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

// vを上三角化する
void make(vector<ll> &v){
    int ind = 0;
    int sz = v.size();
    bool check;
    for (int i = 62; i >= 0; i--) {
        if(ind == sz) break;
        check = true;
        if(!(v[ind] & 1LL<<i)){
            check = false;
            for (int j = ind+1; j < sz; j++) {
                if(v[j] & 1LL<<i){
                    swap(v[ind], v[j]);
                    check = true;
                    break;
                }
            }
        }
        if(!check) continue;
        for (int j = 0; j < sz; j++) {
            if(j == ind) continue;
            if(v[j] & 1LL<<i){
                v[j] = v[j] ^ v[ind];
            }
        }
        ind++;
    }
}

// 上三角化されたvでaが作れるか判定する
bool ok(vector<ll> &v, ll a){
    ll tmp = a;
    int ind = 0;
    int sz = v.size();
    for (ll i = 62; i >= 0; i--) {
        if(ind == sz) break;
        if(!(v[ind] & 1LL<<i)) continue;
        if(tmp & 1LL<<i){
            tmp = v[ind] ^ tmp;
        }
        ind++;
    }
    return tmp == 0;
}

void solve(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }
    string S; cin >> S;
    vector<ll> v;
    
    bool check = true;
    for (int i = N-1; i >= 0; i--) {
        if(S[i] == '1'){
            if(!ok(v, A[i])){
                check = false;
            }
        }
        else{
            v.push_back(A[i]);
            make(v);
        }
    }
    if(check){
        printf("%d\n", 0);
    }
    else{
        printf("%d\n", 1);
    }
}

int main(){
    int T;
    cin >> T;
    for (int i = 0; i < T; i++) {
        solve();
    }
}

Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;

struct edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

ll V;

#define MAX_V 100005
#define INF (1ll << 50)
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {

    cin >> V;
    ll X,Y;
    cin >> X >> Y;

    X--;Y--;
    for (ll i=0; i<V - 1; ++i) {
        auto e = edge{i + 1,1};
        G[i].push_back(e);
        e = edge{i,1};
        G[i + 1].push_back(e);
    }
    auto e = edge{Y,1};
    G[X].push_back(e);
    e = edge{X,1};
    G[Y].push_back(e);
    dijkstra(X);
    for (int i = 0; i < V; ++i) {
        //cout << d[i] << endl;
    }
    //cout << endl;
    ll count[V];
    for (int i = 0; i < V; ++i) {
        count[i] = 0;
    }
    for (int si = 0; si < V-1; ++si) {
        for (int gi = si + 1; gi < V; ++gi) {
            ll l = min((ll)(gi-si),d[gi] + d[si]);
            count[l - 1]++;
        }
    }
    for (int i = 0; i < V - 1; ++i) {
        cout << count[i] << endl;
    }
}



Measured memory_bytes: 2688
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
      os << *i;
  }
  return os;
}

ll W;
ll c[10],d[10];

void init(ll B[100]){
  rep(i,W-1){
    if(B[i]==1){
      c[i]++;
    }
  }
  rep(i,W){
    if(i==0){
      if(B[i]==0){
        d[i]++;
      }
    }
    else if(i==W-1){
      if(B[i-1]==0){
        d[i]++;
      }
    }
    else{
      if(B[i]==0 && B[i-1]==0){
        d[i]++;
      }
    }
  }
}

void dfs(ll i,ll B[100]){
  if(i>=W-1){
    init(B);
    return;
  }
  else{
    dfs(i+1,B);
    B[i]=1;
    dfs(i+2,B);
    B[i]=0;
  }
}

ll dp[1007][10];

int main(){
  ll H,K,B[100];
  rep(i,99){
    B[i]=0;
  }
  cin >> H >> W >> K;
  dfs(0LL,B);
  dp[0][0]=1;
  Rep(i,1,H+1){
    rep(j,W){
      dp[i][j]=(j>0 ? dp[i-1][j-1]*c[j-1] : 0)
                     +dp[i-1][j]*d[j]
           +(j<W-1 ?  dp[i-1][j+1]*c[j] : 0);
      dp[i][j]%=MOD;
    }
  }
  cout << dp[H][K-1] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

vector<vi> g(700);
bool c = true;

int used[700];

int cnt[2];

void dfs(int now){
    cnt[used[now]]++;
    rep(i,g[now].size()){
        int ne = g[now][i];
        if(used[ne] == -1){
            used[ne] = 1 - used[now];
            dfs(ne);
        }else if(used[ne] == used[now]){
            c = false;
            return;
        }
    }
}

signed main(void) {
    int i,j;
    int n, m;
    cin >> n >> m;
    int d[700][700];
    rep(i,n)rep(j,n)d[i][j]=1;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--,b--;
        d[a][b]--;
        d[b][a]--;
    }
    rep(i,n)rep(j,n)if(d[i][j]==1 && i!=j){
        g[i].push_back(j);
    }
    vector<pii> p;
    rep(i,n) used[i] = -1;
    rep(i,n)if(used[i]==-1){
        used[i] = 0;
        cnt[0] = cnt[1] = 0;
        dfs(i);
        if(c==false)break;
        p.push_back(pii(cnt[0],cnt[1]));
    }
    if(c==false){
        cout << -1 << endl;
        return 0;
    }
    int dp[705][705] = {};
    dp[0][0] = 1;
    rep(i,p.size())rep(j,705)if(dp[i][j]){
        dp[i+1][j+p[i].first]++;
        dp[i+1][j+p[i].second]++;
    }
    int ans = INF;
    rep(i,n+1)if(dp[p.size()][i]){
        ans = min(ans, i*(i-1)/2 + (n-i)*(n-i-1)/2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 10240
//============================================================================
// Name        : ProjG.cpp
// Author      : Yong Kiat
// Version     :
// Copyright   : By Algotae.
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>

using namespace std;

int n, w, ai, bi;
vector<int> a, b; // weight, value
long long dp[100001];

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

    cin >> n >> w;
    for (int i = 0; i < n && cin >> ai >> bi; i++) {
    	a.push_back(ai);
    	b.push_back(bi);
    }

    fill(dp, dp + 100001, 1e9 + 1);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
    	for (int j = 100000 - b[i]; j >= 0; j--) {
    		dp[b[i] + j] = min(dp[b[i] + j], dp[j] + a[i]);
    	}
    }

    for (int i = 100000; i >= 0; i--) {
    	if (dp[i] <= w) {
    		cout << i;
    		break;
    	}
    }

}


Measured memory_bytes: 1024
read a b c d
if (( d >= $((a > c ? a - c : c - a)) )); then 
  echo Yes
elif (( d >= $((a > b ? a - b : b - a)) )); then 
  if (( d >= $((b > c ? b - c : c - b)) )); then 
    echo Yes
  else
    echo No
  fi
else
  echo No
fi

Measured memory_bytes: 376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main()
{
    vector<int> a(3, 0);
    rep(i, 3) cin >> a[i];

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

    rep(i, 2) cout << a[i] << " ";
    cout << a[2] << endl;

    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
int m, d;
long long len, sum, c;

int main()
{
	scanf("%d", &m);
	len = sum = -1;
	for (int i = 0; i < m; ++i)
	{
		scanf("%d%lld", &d, &c);
		len += c;
		sum += c * d;
	}
	printf("%lld\n", len + sum / 9);
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>

using namespace std;

int dfs(int n){
	if(n<10) return 0;
	int res=0,a,ten=1;
	for(a=n%10,n/=10;n>0;ten*=10,a+=n%10*ten,n/=10) res=max(res,a*n);
	return dfs(res)+1;
}

int main(){
	int q; scanf("%d",&q);
	while(q--){ int n; scanf("%d",&n); printf("%d\n",dfs(n)); }
	return 0;
}

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

int n;
long long y;

void solve(){
  bool flag = false;
  for(int a = 0; a <= n; a++){
    for(int b = 0; b <= n; b++){
      if(a+b > n) continue;
      int c = n-a-b;
      if(y == 10000*a + 5000*b + 1000*c){
        cout << a << " " << b << " " << c;
        flag = true;
      }
      if(flag) break;
    }
    if(flag) break;
  }
  if(!flag) cout << "-1 -1 -1" << endl;
}
  
int main(){
  cin >> n >> y;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int H,W,i,j,count;
  char S[52][52];

  scanf("%d %d",&H,&W);

  for(i=0;i<H;i++){
    scanf("%s",S[i]);
  }

  for(i=0;i<H;i++){
    for(j=0;j<W;j++){
      count=0;
      if(S[i][j]=='#'){
	printf("#");
      } else if(S[i][j]=='.'){
	if(S[i][j+1]=='#'){
	  count++;
	}
	if(S[i][j-1]=='#'){
	  count++;
	}
	if(S[i+1][j]=='#'){
	  count++;
	}
	if(S[i-1][j]=='#'){
	  count++;
	}
	if(S[i+1][j+1]=='#'){
	  count++;
	}
	if(S[i+1][j-1]=='#'){
	  count++;
	}
	if(S[i-1][j+1]=='#'){
	  count++;
	}
	if(S[i-1][j-1]=='#'){
	  count++;
	}
	printf("%d",count);
      }
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(){
	string str; int count=0;
	while(cin>>str){
		int len=str.size();
		for(int i=0;i<len/2;i++){
			if(str[i]!=str[len-1-i]) break;
			if(i==len/2-1) count++;
		};
		if(len==1) count++;
	};
	cout << count << '\n' ;
}

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

#define PB push_back
#define MP make_pair
#define LL long long
#define int LL
#define FOR(i,a,b) for(int i = (a); i <= (b); i++)
#define RE(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(int)(n)-1)
#define R(i,n) REP(i,n)
#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<PII>
#define LD long double

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(11);
    cerr << fixed << setprecision(6);
    int x;
    cin >> x;
    cout << ((x) ? 0 : 1) << endl;
}


Measured memory_bytes: 3648
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n,u,v = map(int,ipt().split())
    way = [[] for _ in range(n+1)]
    for _ in range(n-1):
        a,b = map(int,ipt().split())
        way[a].append(b)
        way[b].append(a)

    ta = [-1]*(n+1)
    tt = [-1]*(n+1)
    ta[v] = 0 #AOKI
    tt[u] = 0
    qa = queue.Queue()
    qt = queue.Queue()
    qt.put((0,u,-1))
    qa.put((0,v,-1))

    while not qa.empty():
        ti,pi,pp = qa.get()
        for i in way[pi]:
            if i == pp:
                continue
            if ta[i] == -1:
                ta[i] = ti+1
                qa.put((ti+1,i,pi))

    while not qt.empty():
        ti,pi,pp = qt.get()
        if ta[pi] <= ti:
            continue
        for i in way[pi]:
            if i == pp:
                continue
            if ta[i] > ti:
                tt[i] = ti+1
                qt.put((ti+1,i,pi))

    ma = 0
    for i in range(1,n+1):
        if tt[i] == -1:
            continue
        if ma < tt[i]+max(0,ta[i]-tt[i]-1):
            ma = tt[i]+max(0,ta[i]-tt[i]-1)
    print(ma)


    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 80412
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll n, m, x;
    cin >> n >> m >> x;
    ll a[n + 1];
    za(n + 1, a);
    rp(i, 0, m)
    {
        ll aa;
        cin >> aa;
        a[aa] = 1;
    }
    rp(i, 0, n) a[i + 1] += a[i];
    ce(min(a[x], a[n - 1] - a[x]));
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<bitset>
#include<tuple>
#include<time.h>
#include<list>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


int n;
string s[202020];
map<string, int> mp;

void solve(){
	cin >> n;
	int ma = 0;
	for(int i = 0; i < n; i++){
		cin >> s[i];
		mp[s[i]]++;
		chmax(ma, mp[s[i]]);
	}
	
	sort(s, s+n);
	for(int i = 0; i < n; i++){
		if(ma == mp[s[i]]){
			cout << s[i] << endl;
			mp[s[i]] = 0;
		}
	}
}

int main(){
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 28800
A, B, C, x = map(int, [input() for _ in range(4)])
count = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if x == 500*a + 100*b + 50*c:
                count += 1
                break

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

//chMIN
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main(){
    ll n;
    cin >> n;

    vector<ll> h(n);
    rep(i,n){
        cin >> h[i];
    }

    ll dp[100099];
    ll INF = 1e9;
    rep(i,100099){
        dp[i] = INF;
    }
    dp[0] = 0;

    for(ll i=1; i<n; i++){
        chmin(dp[i] , dp[i-1] + abs(h[i]-h[i-1]));
        if(i>1){
            chmin(dp[i] , dp[i-2] + abs(h[i]-h[i-2]));
        }

    }

    dunk(dp[n-1]);

}

Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int seisu = scan.nextInt();
		double[] array = new double[seisu];
		double sum = 0;
		double gyaku = 0;

		for(int i=0;i<seisu;i++) {
			array[i] = scan.nextInt();
			sum += 1/array[i];
		}
		gyaku = 1/sum;

		System.out.println(gyaku);
		scan.close();
	}

}


Measured memory_bytes: 22996
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// -9.2e-18 <= long long <= 9.2e18
// 0 <= unsigned int <= 4.2e9
// 0 <= unsigned long long <= 18.4e18
// cout << fixed << setprecision(10);

const int up = 1;
const int flat = 0;
const int down = -1;
const int unknown = -2;

int main() {
    uint N;
    cin >> N;
    vector<ullong> A(N, 0);
    for (auto &a: A) cin >> a;
    ullong money = 1000;
    ullong nKabu = 0;

    int dir = flat;
    bool first = true;
    for (size_t i=0; i<A.size()-1; ++i) {
        // 次下がる -> 売っとく
        if (A[i] > A[i+1]) {
            //if ((dir == flat) || (dir == up)) {
            if (dir == up) {
                if (nKabu > 0) {
                    ullong addMoney = nKabu * A[i];
                    money += addMoney;
                    nKabu = 0;
                }
            }
            dir = down;
        }
        // 次上がる -> 買っとく
        else if (A[i] < A[i+1]) {
            //if ((dir == flat) || (dir == down)) {
            if ((dir == down) || (first)){
                ullong addKabu = money / A[i];
                nKabu += addKabu;
                money -= addKabu * A[i];
                if (first) first = false;
            }
            dir = up;
        }
//        else {
//            dir = flat;
//        }
    }
    if (nKabu > 0) {
        ullong addMoney = nKabu * A[A.size()-1];
        money += addMoney;
        nKabu = 0;
    }
    cout << money << endl;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void){
    // Your code here!
    int n, k, a, num[200000];
    for (int i = 0; i < 200000; i++) num[i] = 200001;
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (num[a - 1] == 200001) num[a - 1] = 1;
        else num[a - 1]++;
    }
    sort(num, num + 200000);
    int l = 0;
    while (num[l++] != 200001);
    int res = 0;
    for (int i = 0; i < l - 1 - k; i++) res += num[i];
    cout << res << endl;
}


Measured memory_bytes: 1024
n, p = gets.split(" ").map(&:to_i)
a = gets.split(" ").map(&:to_i)
count = 0
a.sort!

n.times do |i|
  if i == n-1
    if a[i] == p
      count += 1
    end
  elsif p >= a[i]
        p -= a[i]
        count += 1
  end
end


puts count

Measured memory_bytes: 1788
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
    int a,b;
    cin >> a>>b;
    if(a==b)
        for (int i = 1; i <= a;i++)
            cout << b;
    else if(a>b)
        for (int i = 1; i <= a;i++)
            cout << b;
    else
        for (int i = 1; i <= b;i++)
            cout << a;
            //system("pause");
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
a=[i for i in map(int,input().split())]
a.sort()
b=[]
for _ in range(m):
    b1=[i for i in map(int,input().split())]
    b1.reverse()
    b+=[b1]
b.sort(reverse=True)

i=0
f=0
s=0
lenb=len(b)
lena=len(a)
while f==0:
    if i>lenb-1 or s>lena-1:
        break
    elif s+b[i][1]>lena-1:
        b[i][1]=lena-s
    if a[s+b[i][1]-1]<b[i][0]:
        a[s:s+b[i][1]]=[b[i][0]]*(b[i][1])
        s+=b[i][1]
    elif a[s]<b[i][0]:
        j=0
        while a[s+j]<b[i][0]:
            a[s+j]=b[i][0]
            j+=1
            if s+j>lena-1:
                break
        break
    else:
        break
    i+=1

print(sum(a))

Measured memory_bytes: 26700
fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val scores = (1..n).map { readLine()!!.toInt() }
    var total = scores.sum()
    if(total % 10 == 0) {
        val tmp = scores.filter { it % 10 != 0 }.min()
        total -= tmp?:total
    }
    println(total)
}


Measured memory_bytes: 33956
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;

int main() {
    long long N; cin >> N;
    long long ans = (1LL << 63) - 1;
    for (long long i = 1; i <= sqrt(N); i++) {
        if (N % i != 0) continue;
        long long tmp = i + N / i; 
        if (tmp < ans) ans = tmp;
    }
    cout << ans - 2 << endl;
}


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

int main(){
    int q;cin>>q;
    for(int i=0;i<q;i++){
        char s[10];
        scanf("%s",s);
        long long t;
        sscanf(s, "%llx", &t);
        int sign=(t>>31&1)? -1 : 1;
        t &=~(1LL<<31);
        if(sign==-1)cout << "-";
        char ans[100];
        sprintf(ans,"%.20lf",1.*t/(1<<7));
        int j;
        for(j=strlen(ans)-1;ans[j]=='0';j--){
            ans[j]=0;
        }
        if(ans[j]=='.')ans[j+1]='0',ans[j+2]=0;
        cout << ans << endl;
    }
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  
  if(abs(a-c) <= d || (abs(a-b) <= d && abs(b-c) <= d)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try(Scanner scanner = new Scanner(System.in)) {
			String data = scanner.nextLine();

			double a = Double.parseDouble(data);

			BigDecimal b1 = new BigDecimal(String.valueOf(Math.pow(a, 1)));
			BigDecimal b2 = new BigDecimal(String.valueOf(Math.pow(a, 2)));
			BigDecimal b3 = new BigDecimal(String.valueOf(Math.pow(a, 3)));

			System.out.println(b1.add(b2).add(b3).longValue());
		}
	}
}

Measured memory_bytes: 36164
#include <bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl '\n'
#define display(v) for (auto x : v) cout << x << ", "
#define dbg(x) cout << (#x) << " = " << (x) << "\n"
#define dbgp(x) cout << (#x) << " = {" << (x.first) << ", " << (x.second) << "}\n";
#define print(x) cout << (#x) << " = [ ";display(x); cout << "]\n"
#define pb push_back
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int main()
{
	fastio;

    ll a, b;
    cin >> a >> b;
    ll c = a + b;
    if (c % 2)
    cout << "IMPOSSIBLE";
    else cout << c / 2;
    return 0;
}


Measured memory_bytes: 256
A,B,C,D = [int(i) for i in input()]

if A+B+C+D == 7:
    print("{}+{}+{}+{}=7".format(A,B,C,D))
elif A+B+C-D == 7:
    print("{}+{}+{}-{}=7".format(A,B,C,D))
elif A+B-C+D == 7:
    print("{}+{}-{}+{}=7".format(A,B,C,D))
elif A+B-C-D == 7:
    print("{}+{}-{}-{}=7".format(A,B,C,D))
elif A-B+C+D == 7:
    print("{}-{}+{}+{}=7".format(A,B,C,D))
elif A-B+C-D == 7:
    print("{}-{}+{}-{}=7".format(A,B,C,D))
elif A-B-C+D == 7:
    print("{}-{}-{}+{}=7".format(A,B,C,D))
elif A-B-C-D == 7:
    print("{}-{}-{}-{}=7".format(A,B,C,D))

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll a, b, k;
    cin >> a >> b >> k;

    while(k > 0) {
        if (a % 2 == 1) a--;
        b += a/2;
        a /= 2;
        k--;
        if (k > 0) {
            if (b % 2 == 1) b--;
            a += b/2;
            b /= 2;
            k--;
        }
    }
    cout << a << " " << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;
const ll max_N = 200000;
ll fac[max_N + 1000], facinv[max_N + 1000];
ll N,K;

ll power(ll x, ll n){
    if(n == 0) return 1LL;
    ll res = power(x * x % MOD, n/2);
    if(n % 2 == 1){
        res = res * x % MOD;
    }
    return res;
}

ll nck(ll n, ll k){
    if(k == 0 || n == k){
        return 1;
    }
    return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
}

ll npk(ll n, ll k){
    if(k == 0 || n == k){
        return 1;
    }
    return fac[n] * facinv[n-k] % MOD;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll H,W,A,B;
    cin >> H >> W >> A >> B;
    fac[0] = 0;
    fac[1] = 1;
    rep(i,2,max_N){
        fac[i] = (fac[i-1] * i) % MOD;
    }
    rep(i,0,max_N){
        facinv[i] = power(fac[i], MOD - 2);
    }
    ll all_c = nck(H+W-2, H-1);
    ll ab_min = min(A,B);
    ll ex_c = 0;
    rep(i,0,ab_min){
        ll v1 = nck(H-A+B-1, B-i-1) % MOD;
        ll v2 = nck(W-B+A-1,A-i-1) % MOD;
        all_c -= v1 * v2 % MOD;
        all_c = (all_c + MOD) % MOD;
    }
    ll ans = (all_c - ex_c + MOD) % MOD;
    print(all_c);

}


Measured memory_bytes: 3456
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str,strArray[];
		int a,b,n,temp;

		while((str=br.readLine()) != null){
			int sum=0,r=1;
			strArray = str.split(" ");
			a = Integer.parseInt(strArray[0]);
			b = Integer.parseInt(strArray[1]);
			n = Integer.parseInt(strArray[2]);
		    sum=0;
			temp=a%b;

			for(int i=0; i<n; i++){
				sum += temp*10/b;
				temp = temp*10%b;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 16944
// D - Caracal vs Monster
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll in(){ll x;cin>>x;return x;}

int main(){
	ll count = 1;
	for(ll H=in(); H; H>>=1) count<<=1;
	cout<< count-1 <<endl;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
r,s,p=map(int,input().split())
a=list(input())

hand={"r":p,"s":r,"p":s}
ans=0
for i in range(n):
    if a[i-k]==a[i] and i-k>=0:
        a[i]="0"
    else:
        ans+=hand[a[i]]
print(ans)

Measured memory_bytes: 4084
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	static final PrintStream out = System.out;
	static final Scanner sc = new Scanner(System.in);
	static final long Mod = 1000_000_007L;
	long A,B,K;
	String S;

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
		System.exit(0);
	}

	void solve() {
		A = nextLong();
		B = nextLong();
		K = nextLong();

		if(K <= A) {
			A-=K;
			out.println(A +" " + B);
			return;
		}
		K -= A;
		A = 0;
		B -= K;
		B = Math.max(B,0);
		out.println(A + " " + B);
	}


	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)a[i] = nextInt();
		return a;
	}
	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)a[i] = nextLong();
		return a;
	}
	public int nextInt() {
		return Integer.parseInt(next());
	}
	public long nextLong() {
		return Long.parseLong(next());
	}
	public String next() {
		return sc.next();
	}

	long gcd(long m,long n) {
		if (m<n) return gcd(n,m);
		if (n==0)return m;
		return gcd(n,m%n);
	}

	long lcm(long m, long n) {
	        return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, X, T;
    cin >> N >> X >> T;
    cout << T * ((N + X - 1) / X) << endl;

    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    stack<int> S1;
    stack< pair<int, int> > S2;
    char ch;

    int sum = 0;

    for (int i = 0; cin >> ch; i++) {
        if (ch == '\\') {
            S1.push(i);
        } else if (ch == '/' && S1.size() > 0) {
            int j = S1.top();
            S1.pop();
            sum += i - j;
            int a = i - j;
            while (S2.size() > 0 && S2.top().first > j) {
                a += S2.top().second;
                S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;

    while (S2.size() > 0) {
        ans.push_back(S2.top().second);
        S2.pop();
    }

    reverse(ans.begin(), ans.end());

    cout << sum << endl;
    cout << ans.size();
    for (int i = 0; i < ans.size(); i++) {
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
    
}


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

using namespace std;

 
int main(){
    string a;
    cin>>a;
    int l=a.size();
    int p=l/2;
    int count=0;
    for (int i=0; i<p; i++){
        if (a[i]!=a[l-1-i]) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<62;
constexpr double eps = (1e-9);

constexpr ll mod = 1000000007;

ll dp[105][4][4][4];

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

  int N;
  cin >> N;

  // T:0, A: 1, G: 2, C: 3
  dp[0][0][0][0] = 1;

  for (int i = 0; i < N; i++) {
    for (int l = 0; l < 4; l++) {
      for (int m = 0; m < 4; m++) {
        for (int n = 0; n < 4; n++) {
          if (dp[i][l][m][n] == 0) continue;
          // 新しく追加する文字
          for (int c = 0; c < 4; c++) {
            if (m == 1 && n == 2 && c == 3) continue;  // AGC
            if (m == 2 && n == 1 && c == 3) continue;  // GAC
            if (m == 1 && n == 3 && c == 2) continue;  // ACG
            if (l == 1 && n == 2 && c == 3) continue;  // A*GC
            if (l == 1 && m == 2 && c == 3) continue;  // AG*C

            dp[i+1][m][n][c] += dp[i][l][m][n];
            dp[i+1][m][n][c] %= mod;
          }
        }
      }
    }
  }

  ll ans = 0;
  rep(l, 4) rep(m, 4) rep(n, 4) {
    ans += dp[N][l][m][n];
    ans %= mod;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const int Maxn = 3010;
const ll INF = (ll) 1e10;

int dp[Maxn][Maxn];

int main() {
    string s, t;
    cin >> s >> t;
    int n = (int) s.size(), m = (int) t.size();
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }

    vector<char> v;
    while (n > 0 && m > 0) {
        if (dp[n][m] == dp[n - 1][m]) --n;
        else if (dp[n][m] == dp[n][m - 1]) --m;
        else{
            v.emplace_back(s[n - 1]);
            --n;
            --m;
        }
    }

    reverse(v.begin(), v.end());
    for (auto i : v) cout << i;
    cout << endl;

    return 0;
}

Measured memory_bytes: 35584
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
//#include <algorithm>
#include <vector>
 
int main(int argc, char* argv[])
{
    char str[101]={0};
    scanf("%s", str);

    long long k = 0;
    scanf("%lld", &k);

    long len = strlen( str);
    long i;
    for(i=0; i<len; i++) {
        if(str[i] !='1')
            break;
    }
    if(k-1<i) {
        printf("1\n");
    }
    else {
        printf("%d\n", (long)(str[i] - '0'));
    }
 
    return 0;
}


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

using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    int len = (int)s.size(), h = len / 2, cnt = 0;
    for (int i=0; i<h; i++) {
        if (s[i] != s[len-i-1]) cnt++;
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
l = list(map(int, input().split()))

s = [0]
for i in range(n):
    s.append((s[-1]+l[i])%m)

s.sort()

ans = 0
mae = s[0]
cnt = 1
for k in range(1, n+1):
    if s[k]==mae:
        cnt += 1
    else:
        ans += cnt*(cnt-1)//2
        mae = s[k]
        cnt = 1
    if k==n:
        ans += cnt*(cnt-1)//2

print(ans)


Measured memory_bytes: 14696
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int MOD = 1000000007;

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

    // [N / x] の値でグループ分け
    vector<pair<int, int>> layer; // ([N / x], 個数)
    for(int i = 1; i * i <= N; ++i) {
        layer.emplace_back(i, 0);
        layer.emplace_back(N / i, 0);
    }
    sort(layer.begin(), layer.end());
    reverse(layer.begin(), layer.end());
    layer.erase(unique(layer.begin(), layer.end()), layer.end());
    for(int i = 0; i < layer.size() - 1; ++i) {
        int l = N / layer[i].first;
        int r = N / layer[i + 1].first;
        layer[i + 1].second = r - l;
    }
    layer.front().second = 1;

    // map で [N / x] と id を対応させる
    int M = layer.size();
    map<int, int> ma;
    for(int i = 0; i < M; ++i) {
        ma[layer[i].first] = i;
    }

    // dp[i][j] := i 個目の数を j 層目の数にするときの条件を満たす場合の数
    vector<vector<int64>> dp(K + 1, vector<int64>(M));
    dp[0][ma[N]] = 1;
    for(int i = 0; i < K; ++i) {
        for(int j = 0; j < M - 1; ++j) {
            dp[i][j + 1] += dp[i][j];
            dp[i][j + 1] %= MOD;
        }
        for(int j = 0; j < M; ++j) {
            int x = layer[j].first;
            int cnt = layer[j].second;
            int id = ma[N / x];
            dp[i + 1][j] = dp[i][id] * cnt;
            dp[i + 1][j] %= MOD;
        }
    }

    // 集計
    int ans = 0;
    for(int j = 0; j < M; ++j) {
        ans += dp[K][j];
        ans %= MOD;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 54264
#include <iostream>
#include <vector>
#include <algorithm>

unsigned mod(long x)
{
  if (x < 0) return -x; 
  return x;
}

unsigned get_sum(unsigned sum, std::vector<long>& cache, std::vector<int>& vec, unsigned i)
{
  if (i+1 == vec.size())
  { 
    cache[i] = 0;
    return sum; 
  }  
  if (i+2 == vec.size())
  { 
    cache[i] = mod(vec[i] - vec[i+1]);
    return sum + cache[i];
  }
  unsigned sum1;
  unsigned sum2;
  if (cache[i] == -1)
  { 
    sum1 = get_sum(mod(vec[i] - vec[i+1]), cache, vec, i+1);
    sum2 = get_sum(mod(vec[i] - vec[i+2]), cache, vec, i+2);
    cache[i] = std::min(sum1, sum2);
  }
  return std::min(sum + cache[i], sum + cache[i]);
}

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

  unsigned N = 0;
  std::cin >> N;
  std::vector<int> vec(N, 0);
  for (unsigned i = 0; i < N; ++i)
  {
    std::cin >> vec[i];
  }
  std::vector<long> cache(vec.size(), -1);
  unsigned ans = get_sum(0, cache, vec, 0);
  std::cout << ans;

  return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    if((a+b)%2==0){
        cout<<(a+b)/2<<endl;
    }else{
        cout<<(a+b)/2+1<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
	int N,i,j,a=0,c=0;
	scanf("%d",&N);
	int sort[N];
	for(i=0;i<N;i++)
	{
		scanf("%d",&sort[i]);
	}
	
	for(i=0;i<N-1;i++)
	{
		int min=i;
		for(j=i;j<N;j++)
		{
			if(sort[j]<sort[min])
			{
				min=j;
			}
		}
		
		if(sort[i]>sort[min])
		{
			a=sort[i];
			sort[i]=sort[min];
			sort[min]=a;
			c=c+1;
		}
		
	}
	
	for(i=0;i<N-1;i++)
	{
		printf("%d ",sort[i]);
	}
	printf("%d",sort[N-1]);
	printf("\n");
	printf("%d\n",c);
	
	return 0;
}


Measured memory_bytes: 2092
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<map>
#include<queue>
#include<tuple>
#define lson (now<<1)
#define rson ((now<<1)|1)
#define mid ((nl+nr)>>1)
#define maxn 2000005
using namespace std;
typedef long long ll;
int n;
int a[maxn];
int main()
{
	ll ans=0;
	scanf("%d",&n);
	ll pre=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>pre)
		{
			pre=a[i];
		}
		else
		{
			ans+=pre-a[i];
		}
	}
	printf("%lld\n",ans);
}

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

using namespace std; 
const int MAX_N = 100005; 
const int MOD = 1000000007; 
vector <int> adj[MAX_N]; 
long long dp[MAX_N][2]; 
int n;                     
long long DFS(int u, int father, int color) {
	if (dp[u][color] != -1) {
		return dp[u][color]; 
	}

	long long res = 1; 
	for (int i = 0; i < (int) adj[u].size(); i++) {
		int v = adj[u][i];
		if (v == father) {
			continue; 
		}

		if (color == 0) {
			(res *= (DFS(v, u, 0) + DFS(v, u, 1)) % MOD) %= MOD; 		
		}
		else {
			(res *= DFS(v, u, 0)) %= MOD; 
		}
	}

	return (dp[u][color] = res); 
}

int main () {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin >> n; 
	for (int i = 1; i < n; i++) {
		int u, v; 
		cin >> u >> v; 
		adj[u].push_back(v); 
		adj[v].push_back(u); 
	}

	for (int i = 1; i <= n; i++) {
		for (int c = 0; c < 2; c++) {
			dp[i][c] = -1; 
		}
	}

	long long res = 0;
	(res += DFS(1, -1, 0)) %= MOD; 
	(res += DFS(1, -1, 1)) %= MOD;          
	cout << res; 
	return 0; 
}

Measured memory_bytes: 15616
#include <iostream>
#include <cstdio>
#include<vector>
#include <map>
#include <string>
#include<algorithm>
#define debug 0
using namespace std;
#define MAXSIZE 1000010
typedef pair<int, int> pairi;
typedef long long LL;

int a[105][105] = { 0 };
int main() {
#if debug
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	int n,m,p;
	scanf("%d%d%d", &n,&m,&p);
	int i = -1, j = 0;
	for (int q = 1; q <= p;q++) {
		int num;
		scanf("%d", &num);
		while (num--) {
			if (j % 2 == 0) {
				if (i + 1 < n) a[++i][j] = q;
				else a[i][++j] = q;
			}
			else {
				if (i - 1 >= 0)a[--i][j] = q;
				else a[i][++j] = q;
			}
		}
	}
	for (int w = 0; w < n; w++) {
		for (int e = 0; e < m; e++) {
			printf("%d", a[w][e]);
			if (e != m - 1)printf(" ");
		}
		printf("\n");
	}
	system("pause");
	return 0;
}

Measured memory_bytes: 512
S=input()
S_list=list(S)
num_B = S.count('W')
count = 0
i = 0
for nb in range(num_B):
  while S_list[i] != 'W': i+=1
  count += i - nb
  S_list[nb],S_list[i]=S_list[i],S_list[nb]
  i+=1
print(count)

Measured memory_bytes: 4968