akhauriyash/Code-Regression huggingface dataset:
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <climits>
#include <queue>
#include <iostream>


#define MAX_H 1100
#define MAX_W 1100


struct status
{
  int x;
  int y;
  int step;
  int n;
};


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

  
int H,W,N;
char maze[MAX_H][MAX_W];
int flag[MAX_H][MAX_W];
int xs,ys;
std::queue<status> Q;


int BFS();

int main(int argc, char* argv[])
{
  //freopen("in.txt","r",stdin);
  while(std::cin>>H>>W>>N)
    {

      std::cin.get();
      //std::cout << H << W << N << std::endl;

      for(int i = 0 ; i < H ; i++)
	std::cin.getline(maze[i],MAX_W);

      //for(int i = 0 ; i < H ; i++)
      //	std::cout << maze[i] << std::endl;

      for(int j = 0 ; j < H ; j++)
	for(int i = 0 ; i < W ; i++)
	  if(maze[j][i] == 'S' )
	    {
	      xs = i;
	      ys = j;
	      break;
	    }
      memset(flag,0,sizeof(flag));
      std::cout<<BFS()<<std::endl;
      
    }
}


int BFS()
{

  while(Q.empty()==false)
    Q.pop();
  status start;
  start.x = xs;
  start.y = ys;
  start.step = 0;
  start.n = 1;

  Q.push(start);

  while(Q.empty() == false )
    {
      status tmp = Q.front();
      Q.pop();


      for(int i = 0 ; i < 4 ; i++)
	{
	  int cx = tmp.x + dx[i];
	  int cy = tmp.y + dy[i];
	  int cstep = tmp.step + 1;
	  int cn = tmp.n;

	  if(cx < 0 || cx >= W ) continue;
	  if(cy < 0 || cy >= H ) continue;
	  if(maze[cy][cx] == 'X' ) continue;

	  if( (maze[cy][cx] - '0') == tmp.n )
	    cn = tmp.n + 1;
	  else
	    cn = tmp.n;

	  if(cn == N+1)
	    return cstep;

	  
	  
	  if(flag[cy][cx] >= cn  ) continue;

	  flag[cy][cx] = cn;

	  status nstatus;
	  nstatus.x = cx;
	  nstatus.y = cy;
	  nstatus.n = cn;
	  nstatus.step = cstep;
	  Q.push(nstatus);
	  
	}
    }

  return -1;
  
}

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



int main(){
    ll N;cin>>N;
    string s;cin>>s;
    map<char,int> m;
    rep(i,0,N){
        m[s.at(i)]++;
    }
    ll ans=1;
    for(char i='a';i<='z';i++){
        ans=((m[i]+1)*ans)%1000000007;
    }
    cout<<ans-1<<endl;
}






Measured memory_bytes: 512
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int h[n];
    rep(i, n) scanf("%d", &h[i]);
    int deg[n], cnt[n];
    memset(deg, 0, sizeof(deg));
    memset(cnt, 0, sizeof(cnt));
    rep(i, m){
        int a, b;
        scanf("%d%d", &a, &b);
        --a; --b;
        ++deg[a]; ++deg[b];
        if(h[a] > h[b]) ++cnt[a];
        if(h[b] > h[a]) ++cnt[b];
    }
    int ans = 0;
    rep(i, n) ans += (deg[i] == cnt[i]);
    printf("%d\n", ans);
}

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

int dp[100001];
int n, h[100001];

int go(int i) {
    if(i == n - 1) return 0;
    if(dp[i] != -1) return dp[i];
    if(i + 2 > n - 1){
        return dp[i] = go(i + 1)+ abs(h[i] - h[i + 1]);
    }
    return dp[i] = min(go(i+1) + abs(h[i] - h[i + 1]), go(i+2) + abs(h[i] - h[i + 2]));
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> h[i];
    }
    cout << go(0);
}


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

int main(){
  
  int N;
  int A,B,C,D;
  
  cin>>N;
  
  A = N/1000; //1000の位
  B = (N%1000)/100; //100の位
  C = (N%100)/10; //10の位
  D = N%10; //1の位
  
  if (B == C) {
    
    if (A == B || C == D) {
      cout << "Yes" << endl;
    }
    
    else {
      cout << "No" << endl;
    }
    
  }
  
  else {    
    cout << "No" << endl;
  }
}

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

int main()
{
	int n;
	cin >> n;
	set<string> s;
	string t;
	rep(i,n)
	{
		cin >> t;
		s.insert(t);
	}
	cout << s.size();

	//////////////////////////////////
	//--------end--------
	//
	return 0;
}

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

//1
int main(int argc, const char * argv[]) {
    int A = 0;
    int B = 0;
    cin >> A;
    cin >> B;

    int num = 0;
    if(A >= 13){
        num = B;
    }else if(A >= 6 && A <= 12){
        num = B/2;
    }else{
        num = 0;
    }
    cout << num << endl;
    return 0;
}

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


int main(){
	int a, b, c;
	int k;
	int suma=0;
	vector<int> v;

	cin>>a>>b>>c;
	cin>>k;

	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());

	for(int i=0; i<k; i++){
		v[2] = v[2] * 2;
	}

	cout << v[0] + v[1] + v[2] << endl;

} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef vector<double> vd;

int main() {FIN

    int n, i;
    double m, d;
    while (cin >> n, n) {
        vd s(n);
        m = 0;
        for (i = 0; i < n; i++) {
            cin >> s[i];
            m += s[i];
        }
        m /= n;
        d = 0;
        for (i = 0; i < n; i++)
            d += (s[i] - m) * (s[i] - m);
        cout << fixed << setprecision(8) << sqrt(d / n) << "\n";
    }
    return 0;
}



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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second

using namespace std;

const int N = 500000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-6;
const double pi = atan2(0, -1);

bool check(int n, set<int> a)
{
    while (n)
    {
        if (a.count(n % 10))
            return false;
        n /= 10;
    }
    return true;
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output_smart.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //int TL = 1.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, k;
    cin >> n >> k;
    set<int> a;
    rep(i, 0, k)
    {
        int x;
        cin >> x;
        a.insert(x);
    }
    while (!check(n, a))
        n++;
    cout << n << endl;
    return 0;
}


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

const int MAX = 210000;
const int MOD = 1000000007;

ll fac[MAX],finv[MAX],inv[MAX];

void COMinit() {
  fac[0]=fac[1]=1;
  finv[0]=finv[1] = 1;
  inv[1]=1;
  for (int i=2; i<MAX; i++) {
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(int n, int k){
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main() {
  int n,k; cin>>n>>k;
  COMinit();
  ll res=0;
  ll mi=0,ma=0;
  for (int i=0; i<=n+1; i++) {
    if (i>=k) res=(res+ma-mi+1LL)%MOD;
    mi+=i;
    ma+=(n-i);
  }
  cout<<res<<endl;
}


Measured memory_bytes: 8552
N, M = map(int,input().split())
if N*M == 1:
    ans = 1
elif N == 2 or M == 2:
    ans = 0
elif N == 1 or M == 1:
    ans = N*M - 2
else:
    ans = N*M - (2*(N-1)+2*(M-1))
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>
#define rep(i, a, b) for (int(i) = (a); i < (b); i++)
using namespace std;

using ll = long long;

typedef pair<int, int> P;

const int INF = 100000000;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
	ll ans=1;
	for(;y>0;y>>=1){
		if(y&1)(ans*=x)%=mod;
		(x*=x)%=mod;
	}
	return ans;
}

ll n;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	//問題文中の添え字が0-indexか1-indexか確認!
	cin >> n;
	vector<ll> a(n);
	rep(i, 0, n) cin >> a[i];
	sort(a.begin(), a.end(), greater<ll>());
	ll x = a[0];
	ll point = n;
	rep(i,0,n){
		if(a[i]<=(double)x/2){
			point = i;
			break;
		}
	}
	if(point==n){
		cout << x <<" "<< a[n - 1];
	}else if((a[point-1]+a[point])<x){
		cout << x <<" "<< a[point - 1];
	}else{
		cout << x <<" "<< a[point];
	}
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] SP = new int[r+1][c+1];

		for(int x = 0 ; x < r ; x++){
			for(int y = 0; y < c ; y++){
				SP[x][y] = scanner.nextInt();
				SP[x][c] = SP[x][c] + SP[x][y];
				SP[r][y] = SP[r][y] + SP[x][y];
				SP[r][c] = SP[r][c] + SP[x][y];
			}
		}
		for(int x = 0 ; x < r+1 ; x++){
			for(int y = 0; y < c+1 ; y++){
				if(y==c){
					System.out.print(SP[x][y] );
				}
				else{
					System.out.print(SP[x][y] + " ");
				}
			}
			System.out.println();
		}
	}

}

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

int main()
{
    string S, T, U;
    int A, B;
    cin >> S >> T;
    cin >> A >> B;
    cin >> U;
    if (U == S) {
        A-=1;
        cout << A<<" "<<B;
    }
    else if (U == T) {
        B-=1;
        cout << A<<" "<<B;
    }
    return 0;

}

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

int money, y, n, op, fee;
double p;

int calc(){
    int m = money;
    if(op == 0){
        int ex = 0;
        for(int i = 0; i < y; i++){
            ex += m*p;
            m -= fee;
        }
        return ex + m;
    }else{
        for(int i = 0; i < y; i++){
            m = m*(1.0+p)-fee;
        }
        return m;
    }
}

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

    while(q-- > 0){
        int ans = 0;

        cin >> money >> y >> n;

        for(int i = 0; i < n; i++){
            cin >> op >> p >> fee;
            ans = max(ans, calc());
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3112
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

typedef std::vector<std::vector<int>> graph;

std::vector<int> makescc(const graph& g)
{
	const int n = g.size();
	std::vector<int> num(n), low(n), scc(n, -1);
	std::vector<bool> visited(n);
	std::stack<int> r, s;
	int index = 0;

	for (int u = 0; u < n; ++u) {
		if (visited[u]) {
			continue;
		}
		r.push(u);
		while (!r.empty()) {
			const int v = r.top();
			if (num[v] == 0) {
				s.push(v);
				num[v] = low[v] = ++index;
				for (const int w : g[v]) {
					if (num[w] == 0) {
						r.push(w);
					}
				}
				continue;
			}
			r.pop();
			if (visited[v]) {
				continue;
			}
			visited[v] = true;
			for (const int w : g[v]) {
				if (scc[w] == -1) {
					low[v] = std::min(low[v], low[w]);
				}
			}
			if (num[v] == low[v]) {
				int w;
				do {
					w = s.top();
					s.pop();
					scc[w] = v;
				} while (w != v);
			}
		}
	}

	return scc;
}

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

	int V, E;
	std::cin >> V >> E;
	graph g(V);
	for (int i = 0; i < E; ++i) {
		int s, t;
		std::cin >> s >> t;
		g[s].push_back(t);
	}
	auto scc = makescc(g);

	int Q;
	std::cin >> Q;
	for (int i = 0; i < Q; ++i) {
		int u, v;
		std::cin >> u >> v;
		std::cout << (scc[u] == scc[v]) << '\n';
	}
}

Measured memory_bytes: 3676
N,K=gets.chomp.split(' ').map{|n| n.to_i}
A=gets.chomp.split(' ').map{|n| n.to_i}
X=Array.new(A.size)
sum = 0
A.each_with_index{|a,i| (i%2==0) ? sum+=a : sum-=a}
# p sum
X[0]=sum
for i in 1..(N-1)
	X[i]=2*A[i-1]-X[i-1]
end
puts X.join(" ")



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

int mas[100][100]={0};
int dx[] = {0,1,0,-1},dy[] = {1,0,-1,0};
int w,h,maxi;

void dfs(int x,int y,int cnt){
    for(int i=0;i<4;i++){
        int nx = x + dx[i];
        int ny = y + dy[i];
        if(mas[ny][nx] == 1){
            mas[ny][nx] = 0;
            dfs(nx,ny,cnt+1);
            mas[ny][nx] = 1;
        }
    }
    maxi = max(maxi,cnt);
}

int main(){
    while(1){
        maxi = 0;
        cin >> w >> h;
        if(w == 0 && h == 0) break;
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++) cin >> mas[i][j];
        }
        
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(mas[i][j] == 1) dfs(j,i,0);
            }
        }
        cout << maxi << endl;
    }
}

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

int main() {
  int64_t N;
  cin >> N;
  int root = sqrt(N);
  int64_t B = 0;
  for (int i = 1; i <= root; i++) {
    if (N % i == 0) {
      B = N / i;
    }
  }
  
  int ans = 0;
  while(B > 0) {
    ans++;
    B /= 10;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
from numpy import loadtxt, int64, bincount, reshape, argmax

A = loadtxt(open(0), int64, skiprows=1, ndmin=2)

N = ans = len(A)

while A.any():
    b = bincount(A[:, 0])
    A = reshape(A[A != argmax(b)], (N, -1))
    ans = min(ans, max(b))

print(ans)


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

using namespace std;

#define int long long
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"
#define Printv(v)                                                              \
    {                                                                          \
        FOREACH(x, v) { cout << x << " "; }                                    \
        cout << "\n";                                                          \
    }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
    std::fill((T *)array, (T *)(array + N), val);
}

typedef long long ll;
typedef unsigned long long ul;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, VL, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18 + 1;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N, A, dp[51][51][2501];
VL x;

signed main() {
    cin >> N >> A;
    REP(i, N) x.emplace_back(IN());
    dp[0][0][0] = 1;
    REP(i, N) REP(j, i + 2) REP(k, N * A + 1) {
        if(k - x[i] >= 0 && j > 0)
            dp[i + 1][j][k] = dp[i][j][k] + dp[i][j - 1][k - x[i]];
        else
            dp[i + 1][j][k] = dp[i][j][k];
    }
    ll ans = 0;
    FOR(i, 1, N + 1) { ans += dp[N][i][i * A]; }
    cout << ans << "\n";
}

Measured memory_bytes: 49152
a = [] 
for i in range(3):
    a.extend(input().split())
n = int(input())
for i in range(n):
    c = input()
    if c in a:
        a[a.index(c)] = '0'
if (a[0] == a[1] == a[2] or a[3] == a[4] == a[5] or a[6] == a[7] == a[8] or
    a[0] == a[3] == a[6] or a[1] == a[4] == a[7] or a[2] == a[5] == a[8] or
        a[0] == a[4] == a[8] or a[2] == a[4] == a[6]):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
A, B, C, D = map(int, input().split())

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

lcm = C * D // gcd(C, D)

def get_num(X):
    num_c = X // C
    num_d = X // D
    common = X // lcm
    return X - (num_c + num_d) + common


print(get_num(B) - get_num(A - 1))


Measured memory_bytes: 2940
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(i=a;i<b;i++)
    #define rfo(i,b,a) for(i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e5 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    vector<int> dp(MAX,MOD);
    int a[MAX];
    void solve()
    {
        cin>>n>>k;
        fo(i,1,n+1)
        {
            cin>>a[i];
        }
        
        dp[1]=0;
        // deb(dp[2])
        fo(i,1,n+1)
    	{
    	    for(j=i-1;j>=1 && j>=i-k;j--)
    	    dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
    	   // deb(dp[i])
    	}
    	cout<<dp[n]<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int N, W; cin >> N >> W;
  vi w(N), v(N);
  rep(i, N) cin >> w[i] >> v[i];

  vvi dp(N, vi(W+1, -1));
  dp[0][0] = 0;
  dp[0][w[0]] = v[0];
  REP(i, 1, N) {
    rep(j, W+1) {
      if (dp[i-1][j] == -1) continue;
      dp[i][j] = max(dp[i][j], dp[i-1][j]);
      if (j+w[i] <= W) {
        dp[i][j+w[i]] = max(dp[i][j+w[i]], dp[i-1][j] + v[i]);
      }
    }
  }
  ll ans = 0;
  rep(i, W+1) {
    ans = max(ans, dp[N-1][i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 1e5 + 10;

int DP[MAX][2][2][2];

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

	int N;
	cin >> N;

	vector<int> a(N), b(N), c(N);

	for(int i = 0; i < N; i++){
		cin >> a[i] >> b[i] >> c[i];
	}

	memset(DP, 0, sizeof DP);
	DP[0][1][0][0] = a[0];	
	DP[0][0][1][0] = b[0];	
	DP[0][0][0][1] = c[0];	

	for(int i = 1; i < N; i++){

		DP[i][1][0][0] = a[i] + max(DP[i-1][0][0][1], DP[i-1][0][1][0]);		
		DP[i][0][1][0] = b[i] + max(DP[i-1][0][0][1], DP[i-1][1][0][0]);		
		DP[i][0][0][1] = c[i] + max(DP[i-1][1][0][0], DP[i-1][0][1][0]);		

	} 

	int ans = max({ DP[N-1][0][0][1], DP[N-1][0][1][0], DP[N-1][1][0][0] });

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


Measured memory_bytes: 7404
import sys
sys.setrecursionlimit(10**7)

n = int(input())
graph = {i : [] for i in range(n)}
for i in range(n-1):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a -= 1
    b -= 1
    graph[a].append(b)
    graph[b].append(a)

stack = [0]
already = set()
parent = [i for i in range(n)]
flg = False
while len(stack) > 0:
    cur = stack.pop(-1)
    already.add(cur)
    for _next in graph[cur]:
        if _next not in already:
            stack.append(_next)
            parent[_next] = cur
            if _next == n - 1:
                flg = True
                break
    if flg:
        break

path = []
cur = n - 1
while cur != 0:
    path.append(cur)
    cur = parent[cur]
path.append(0)
path.reverse()
flg_2 = len(path) % 2 != 0
left = path[len(path) // 2 - 1 + flg_2]
right = path[len(path) // 2 + flg_2]

def dfs(x, last):
    res = 1
    for _next in graph[x]:
        if _next != last:
           res += dfs(_next, x)
    return res

left_res = dfs(left, right)
#print(left_res)
print("Fennec" if left_res > (n - left_res) else "Snuke")


Measured memory_bytes: 118756
#!/usr/bin/env python3

# from numba import njit
from collections import defaultdict
# input = stdin.readline

# @njit
def solve(n,p):
  def primedict(num):
    res = defaultdict(int)
    if num == 1:
      return {1:1}
    f = 2
    while f * f <= num:
      if num % f == 0:
        res[f] += 1
        num //= f
      else:
        f += 1
    if num != 1:
      res[num] += 1
    return res


  ans = 1
  d = primedict(p)
  for k,v in d.items():
    ans *= k**(v//n)
  
  return ans



def main():
  N,P = map(int,input().split())
  print(solve(N,P))
  return

if __name__ == '__main__':
  main()


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

using namespace std;
using ll = long long int;


int main() {
	string s,t;
	cin>>s>>t;
	int ans = 0, n = s.size();
	
	for(int i = 0; i < n; i++) {
		if(s[i] != t[i]) {
			ans++;
		}
	}
	cout<<ans<<endl;
}


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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int N;
    cin >> N;
    int mx = 1;
    while ((mx * (mx + 1)) < 2 * N)
        mx++;
    int mn = (mx * (mx + 1)) / 2 - N;
    for (int i = 1; i <= mx; i++)
        if (i != mn)
            cout << i << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#define int long long
#ifndef FAST_IO
  #define IOS ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
#endif
#define ff first
#define ss second
#define endl "\n"
#define all(c) c.begin(),c.end()
template<typename T>void print(T t){for(auto &it:t)cout<<it<<" "; cout<<endl;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(){
  int n,t;
  cin>>n>>t;
  vector< pair<int,int> > v;
  for(int i=0;i<n;i++){
	   int x,y;
	   cin>>x>>y;
	   v.emplace_back(make_pair(x,y));
	 }
	 int ans=INT_MAX;
	 for(auto it:v){
	  if(it.second<=t)ans=min(ans,it.first);	 
	}
	cout<<(ans==INT_MAX?"TLE":to_string(ans))<<endl;	
}
int32_t main(){
   IOS;
   solve();
   //debug();
  #ifdef LOCAL_DEFINE
   cerr<<"time elapsed "<<(double)clock()/CLOCKS_PER_SEC<<endl;
  #endif	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
int k,x;
signed main(){
  cin>>k>>x;
  int p=x-k+1;
  int ll=0-1000000;
  for(int i=0;i<(k*2)-1;i++){
    int ans=p+i;
    if(ans>=ll&&ans<=(1000000))cout<<ans<<' ';
  }
  cout<<endl;
}

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

int main()
{
	int n, m;
	int zek[100 + 10];
	int tmp;

	int i,j;

	cin >> n >> m;

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

	for (i = 2; i <= m; i++)
	{
		for (j = 1; j < n; j++)
		{
			if (zek[j] % i > zek[j + 1] % i)
			{
				tmp = zek[j];
				zek[j] = zek[j + 1];
				zek[j + 1] = tmp;
			}
		}
	}

	for (i = 1; i <= n; i++)
	{
		cout << zek[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
 
using namespace std;
typedef unsigned long long int ll;
/*const ll hell = 100005; 
bool comp(const pair<string,ll> &a,const pair<string, ll> &b)
{
   return a.second>b.second;
}
ll binpow(ll a,ll b) 
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
*/
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a[3][3]={0};
    for(ll i=0; i<3;i++)
        for(ll j=0; j<3;j++)
            a[i][j]=0;
    for(ll i=0; i<3;i++)
        for(ll j=0; j<3;j++)
            cin>>a[i][j];
    ll n;
    cin>>n;
    for(ll k=0;k<n;k++)
    {
        ll t;
        cin>>t;
    for(ll i=0;i<3; i++)
    {
        for(ll j=0;j<3;j++)
        {
            if(a[i][j]==t)
                a[i][j]=0;
        }
    }
    }
    ll c1=a[0][0]+a[1][0]+a[2][0],c2=a[0][1]+a[1][1]+a[2][1],c3=a[0][2]+a[1][2]+a[2][2];
    ll r1=a[0][0]+a[0][1]+a[0][2],r2=a[1][0]+a[1][1]+a[1][2],r3=a[2][0]+a[2][1]+a[2][2];
    ll d1=a[0][0]+a[1][1]+a[2][2], d2=a[0][2]+a[1][1]+a[2][0];
    if(r1==0 || r2==0 ||r3==0 ||c1==0||c2==0||c3==0||d1==0||d2==0)
        cout<<"Yes";
    else 
        cout<<"No";
    return 0;
}

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

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int A, B, T; cin>>A>>B>>T;
  int ans = 0, t = A;
  while(true) {
    if(t > T) break;
    ans += B;
    //    cout << t << " " << ans << endl;                                               
    t += A;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[tuple(map(int,input().split())) for i in range(n)]
money=0
ab.sort(key=lambda tup:tup[0])
for a,b in ab:
    if m-b>0:
        money+=a*b
        m-=b        
    else:
        money+=a*m
        break
print(money)



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


int main(){
 int H,W;
 cin>>H>>W;
 char f[W][H];
 bool flag = true;
 for(int i = 0;i < W;i++){
     for(int j = 0;j < H;j++)cin>>f[i][j];
 }
 for(int i = 0;i < W;i++){
     for(int j = 0;j < H;j++){
         if(f[i][j]=='#'){
         if(f[i][j+1] == '#' || f[i+1][j] == '#' ||f[i][j-1] == '#' ||f[i-1][j] == '#');
         else flag =false;
         }
     }
 }
 if(flag)cout<<"Yes";
 else cout<<"No";
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main (String[] args) {
		int max = -2147483648;
		int min =2147483647;
		long sum = 0;

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		int [] a = new int[n];

		for (int i = 0; i< n; i++) {
			a[i] = scan.nextInt();
		}
		for (int i = 0; i<a.length; i++) {
			max = Math.max(max,a[i]);
			min = Math.min(min, a[i]);
			sum += a[i];
		}

		System.out.println(min + " " + max + " "+ sum );

		}
	}


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

#define INF (1LL << 31 - 1)
#define MOD int(1e9+7)
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

using ll = long long;

ll n;

int main() {
  init();
  cin >> n;
  ll sum = 0, p;

  for (int i = 1; sum < n; ++i) {
    p = i;
    sum += i;
  }

  int k = sum - n;
  //cout << "sum = " << sum << endl;

  if (sum == n) {
    for (int i = 1; i <= p; ++i) {
      cout << i << endl;
    }
  }
  else {
    for (int i = 1; i <= p; ++i) {
      if (i != k) cout << i << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

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

    for (long long i = 0; ; i++) {
        long long D = M / N - i;
        if (M % D == 0) {
            cout << D << endl;
            return 0;
        }
    }

    return 0;
}


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

int main()
{
   long a,b,n;
 
   cin>>a>>b>>n;
   long long max=0;
   long double op=min(b-1,n);
//   for(long double i=1;i<=op;i++)
//   {
       
       
//      long double p= i/b;
     
//      // cout<<p<<endl;
//      long long  j=  a* floor(p);
//      long  long f= floor(a*p);
//       long long ans=f-j;
//      //  cout<<ans<<endl;
//       if(max<ans)
//       max=ans;
       
//   }

long long  ans =  a*(op/b);
   cout<<ans;
   return 0;
}

Measured memory_bytes: 3620
function Main(input) {
  var data = input.split("\n");
  var N = parseInt(data[0]);
  var A = parseInt(data[1]);
  var B = parseInt(data[2]);

  if (N === 1){
    console.log('Hello World');
  } else {
    console.log(A + B);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(){

  int x,n;
  cin >> x >> n;
  map<int,bool> mp;
  int a;
  for(int i=0;i<n;i++){
    cin >> a;
    mp[a]=1;
  }

  int distance=-1;
  while(1){
    distance++;
    if(mp[x-distance]==0){
      cout << x-distance << endl;
      return 0;
    }else if(mp[x+distance]==0){
      cout << x+distance << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  vector<int> A2 = A, B2 = B;
  sort(A2.begin(), A2.end());
  sort(B2.begin(), B2.end());
  if (N % 2 == 1){
    int lb = A2[N / 2];
    int ub = B2[N / 2];
    vector<pair<int, int>> bound;
    for (int i = 0; i < N; i++){
      if (A[i] <= ub && B[i] >= lb){
        bound.push_back(make_pair(max(A[i], lb), min(B[i], ub)));
      }
    }
    sort(bound.begin(), bound.end());
    int M = bound.size();
    vector<pair<int, int>> bound2;
    bound2.push_back(bound[0]);
    for (int i = 1; i < M; i++){
      if (bound[i].first > bound2.back().second){
        bound2.push_back(bound[i]);
      } else {
        bound2.back().second = max(bound2.back().second, bound[i].second);
      }
    }
    int M2 = bound2.size();
    int ans = 0;
    for (int i = 0; i < M2; i++){
      ans += bound2[i].second - bound2[i].first + 1;
    }
    cout << ans << endl;
  } else {
    int L1 = A2[N / 2 - 1];
    int L2 = A2[N / 2];
    int R1 = B2[N / 2 - 1];
    int R2 = B2[N / 2];
    cout << (R2 + R1) - (L2 + L1) + 1 << endl;
  }
}

Measured memory_bytes: 8504
#include<iostream>
using namespace std;
int main()
{
	int r, p, n, m, h;
	
	cin >> r;
	
	p = r / 3600;
	n = r % 3600;
	m = n / 60;
	h = n % 60;
	
	cout << p << ":" << m << ":" << h << endl;

}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
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; }

const ll MOD = 998244353;
const ll inf = 1e18;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    ll n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    ll mem = 0, b = 0, w = 0;
    vll a(n + 1);
    REP(i, n + 1) {
        a[i] = int(s[i] - '0');
        if (a[i] == 1) b++;
        else {
            chmax(mem, b);
            b = 0;
        }
    }

    if (mem >= m) {
        cout << -1 << endl;
        return 0;
    }
    reverse(ALL(a));
    vll res;
    ll cur = 0;
    
    while (cur != n) {
        ll dice = m;
        while (1) {
            chmin(dice, n - cur);
            if (a[cur + dice] == 0) {
                cur += dice;
                res.push_back(dice);
                break;
            }
            dice--;
        }
    }
    reverse(ALL(res));
    for (auto x : res) {
        cout << x << " ";
    }
    return 0;
}

Measured memory_bytes: 2248
N = int(input().strip())
arr = []
for n in range(N):
  A, B = list(map(int, input().split()))
  arr.append([ A + B , A, B])

arr = sorted(arr, reverse=True)
ta = sum([a[1] for a in arr[::2]])
ao = sum([a[2] for a in arr[1::2]])
print(ta - ao)

Measured memory_bytes: 24496
// 🐋💭
import Foundation

func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func readInt() -> Int {
    return Int(readLine()!)!
}

func readDoubles () -> [Double] {
    return readLine()!.split(separator: " ").map { Double($0)! }
}

func readDouble() -> Double{
    return Double(readLine()!)!
}

func readLines() -> [String] {
    return readLine()!.map { String($0) }
}

///最大公約数を返す
func gcd(_ m:Int, _ n:Int) -> Int {
    if n == 0 {return m}
    return gcd(n, m % n)
}

///最大公約数を返す
func gcd(_ array: [Int]) -> Int {
    var value = array[0]
    if array.count > 1 {
        for i in 1..<array.count {
            value = gcd(value, array[i])
        }
    }
    return value
}

///最小公倍数を返す
func lcm(_ m:Int, _ n:Int) -> Int {
    return m * n / gcd(m, n)
}

///素数判定(試し割り)
func isPrime(_ x:Int) -> Bool {
    if x <= 1 || x % 2 == 0 { return false }
    if x == 2 { return true }
    for i in stride(from: 3, to: Int(ceil(sqrt(Double(x)))), by: 2){
        if x % i == 0 {
            return false
        }
    }
    return true
}

//https://program-life.com/669
///実行速度の計測
func exectionTime(action: () -> Void) {
    let startDate = Date()
    action()
    let endDate = Date()
    print(endDate.timeIntervalSince(startDate))
}

//https://riptutorial.com/ja/swift/example/14738/インデックスを知らずに配列から要素を削除する
extension Array where Element: Equatable {
    
    mutating func remove(_ element: Element) {
        _ = firstIndex(of: element).flatMap {
            self.remove(at: $0)
        }
    }
}

func binarySearch(right:Int, key:Int, ary:[String]) -> Int{
    var left = 0
    var right = right
    
    while abs(right - left) > 1 {
        let mid = left + (right - left) / 2
        
        if Int(ary[mid])! < key {
            left = mid
            
        } else {
            right = mid
        }
    }
    return left
}

func arrangement (prev:String, ary:[String], returnVal:[String]) -> [String] {
    var returnVal = returnVal
    if ary.count == 0 {
        returnVal.append(prev)
        return returnVal
    }
    
    for s in ary {
        let wprev = prev + s
        var wary = ary
        wary.remove(s)
        returnVal = arrangement(prev: wprev, ary: wary, returnVal: returnVal)
    }
    return returnVal
}
// https://algo-logic.info/divisor/
/// 約数の配列を返す
func divisor(_ n:Int) -> [Int] {
    var ret = [Int]()
    var i = 1
    while i * i <= n {
        if n % i == 0 {
            ret.append(i)
            if i * i != n {
                ret.append(n / i)
            }
        }
        i += 1
    }
    return ret.sorted()
}

func main() {
    let n = readInt()
    let l = readInts().sorted(by: >)
    //＿＿＿＿＿＿＿＿＿＿＿＿＿＿＿ここまで入力
    var ans = 0
    if n == 1 {
        print(0)
        return
    }
    
    for i in 0..<n - 2 {
        for j in i+1..<n - 1 {
            for k in j+1..<n {
                if l[i] == l[j] || l[j] == l[k] || l[i] == l[k] { continue }
                if l[i] < l[j] + l[k] {
                    ans += 1
                }
            }
        }
    }
    print(ans)
}
main()


Measured memory_bytes: 13612
#include <iostream>

 

using namespace std;

 

int main()
{
    int a ,b, temp, i;
    for(i=1; i<=3000; i++)
    {
        cin >> a >> b;
        if(a==0 && b==0)
            break;
            
        if(a > b)
        {
            a = a+b;
            b = a-b;
            a = a-b;
        }
        cout << a << " " << b << endl;
    }
}


Measured memory_bytes: 2968
void main(){
	long n = _scan!long();
	long[] a = _scanln!long();
	a.sort!("a>b");
	long ans;
	for(long i=1; i<n; i++){
		ans += a[i/2];
	}
	ans.writeln();
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 11740
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>

using namespace std;

#define mod 1000000007

int result[100001] = {};

int solve(string s, int n)
{
    if(n == s.length()) return 1;
    if(result[n] != 0) return result[n];
    result[n] = -1;
    if((s.substr(n, 5) == "erase" || s.substr(n, 5) == "dream") && solve(s, n + 5) == 1){
        result[n] = 1;
    } else if(s.substr(n, 6) == "eraser" && solve(s, n + 6) == 1){
        result[n] = 1;
    } else if(s.substr(n, 7) == "dreamer" && solve(s, n + 7) == 1){
        result[n] = 1;
    }
    // cout << n << result[n] << endl;
    return result[n];
}

int main()
{
    string s;
    cin >> s;
    if(solve(s, 0) == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 4224
#include<ctime>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath> 
#include<cstring> 
#include<cassert>
#include<string>
#include<sstream>
#include<fstream>
#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<list>
#include<stack>
#include<set>
#include<bitset>
#include<iomanip>
#include<utility>
#include<functional>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cwchar>
#include<cwctype>
#include<exception>
#include<locale>
#include<numeric>
#include<new>
#include<stdexcept>
#include<limits>
using namespace std;

#define ll long long
#define INF 1e9
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
#define pii pair<int,int>
#define sz(s) s.size()
#define all(s) (s.begin(),s.end())


const int maxn=200005;
int n,m;
bool can1[maxn],cann[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	while(m--){
		int a,b;
		cin>>a>>b;
		if(a==1)can1[b]=true;
		if(b==1)can1[a]=true;
		if(a==n)cann[b]=true;
		if(b==n)cann[a]=true;
	}
	for(int i=2;i<n;i++)
	if(can1[i]&&cann[i]){
		cout<<"POSSIBLE";
		return 0;
	}
	cout<<"IMPOSSIBLE";
	return 0;
} 

Measured memory_bytes: 640
n = int(input())
r3 = 3 ** 0.5
A = (0.0, 0.0)
B = (100.0, 0.0)

def koch(n, A, B):
    if n == 0:
        return

    C1 = ((2 * A[0] + B[0]) / 3, (2 * A[1] + B[1]) / 3)
    C3 = ((A[0] + 2 * B[0]) / 3, (A[1] + 2 * B[1]) / 3)
    X, Y = C3[0] - C1[0], C3[1] - C1[1]
    C2 = (C1[0] + (X - Y * r3) / 2, C1[1] + (X * r3 + Y) / 2)

    koch(n - 1, A, C1)
    print("{:.5f} {:.5f}".format(C1[0], C1[1]))
    koch(n - 1, C1, C2)
    print("{:.5f} {:.5f}".format(C2[0], C2[1]))
    koch(n - 1, C2, C3)
    print("{:.5f} {:.5f}".format(C3[0], C3[1]))
    koch(n - 1, C3, B)

print("{:.5f} {:.5f}".format(A[0], A[1]))
koch(n, A, B)
print("{:.5f} {:.5f}".format(B[0], B[1]))


Measured memory_bytes: 5732
#include <algorithm>
#include <bitset>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF INT32_MAX / 2
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    int cnt = 0;
    int a, b;
    while (n--) {
        cin >> a >> b;
        if (a == b)
            cnt++;
        else
            cnt = 0;
        if (cnt == 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3620
fun main(arr: Array<String>) {
    println(if(getAns()) "Yes" else "No")
}

fun getAns():Boolean {
    val (h,w) = readLine()!!.split(" ").map { it.toInt() }
    val map = (1..h).map { readLine()!! }
    val cnt = mutableMapOf<Char, Int>()
    map.forEach { line -> line.forEach { cnt[it] = (cnt[it]?:0)+1 } }
    if(h%2==0) {
        if(w%2==0) {
            return cnt.values.all { it%4==0 }
        } else {
            if(cnt.values.any{it%2!=0}) {
                return false
            }
            return cnt.values.filter { it%4!=0 && it%2==0 }.count()*2 <= h
        }
    } else {
        if(w%2==0) {
            if(cnt.values.any{it%2!=0}) {
                return false
            }
            return cnt.values.filter { it%4!=0 && it%2==0 }.count()*2 <= w
        } else {
            if(cnt.values.count { it%2!=0 } != 1) {
                return false
            }
            return cnt.values.filter { it%4!=0&&it%2==0 }.count()*2 <= w+h-2
        }
    }
}


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

#define num_max(p,q)((p)>(q)?(p):(q))
#define num_min(p,q)((p)<(q)?(p):(q))
int cmp(const void *a, const void *b)
{
	return *(int*)a - *(int*)b;//昇順
	 //降順ならreturn *(int*)b - *(int*)a;
}
int main()
{
 int A,B,C;
 scanf("%d%d%d",&A,&B,&C);
 if(A+B+C>=22)printf("bust\n");
 else printf("win\n");
	return 0;
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int n = t.length();
    int m = s.length();
    int ans = 2000;
    for (int start = 0; start <= m - n; ++start) {
        int res = 0;
        for (int i = 0; i < n; ++i) {
            if (s[start + i] != t[i])
                res++;
        }
        ans = min(ans, res);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3608
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

using E = pair<ll, ll>;

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, Q;
  while (cin >> N >> Q) {
    vector<ll> S(N), T(N), X(N);
    for (int i = 0; i < N; i++) cin >> S[i] >> T[i] >> X[i];
    vector<ll> D(Q);
    for (ll &x : D) cin >> x;
    vector<E> bs, es;
    for (int i = 0; i < N; i++) {
      bs.emplace_back(S[i] - X[i], X[i]);
      es.emplace_back(T[i] - X[i], X[i]);
    }
    sort(bs.begin(), bs.end());
    sort(es.begin(), es.end());
    int bi = 0, ei = 0;
    multiset<ll> xS;
    for (ll d : D) {
      while (bi < N && bs[bi].fst <= d) xS.insert(bs[bi++].snd);
      while (ei < N && es[ei].fst <= d) xS.erase(xS.find(es[ei++].snd));
      if (xS.empty()) {
        cout << -1 << endl;
      } else {
        cout << *xS.begin() << endl;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 23132
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
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; }

using ll = long long;
using P = pair<ll, ll>;

constexpr double PI = 3.14159265358979323846;
mt19937_64 engine(chrono::steady_clock::now().time_since_epoch().count());

class B {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      string s; cin >> s;
      int n = s.size();
      int ans = 0;
      rep(i, n) {
        if (s[i] != s[n-i-1]) {
          s[i] = s[n-i-1];
          ans++;
        }
      }
      cout << ans << endl;
    }
};

signed main() {
  B solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 256