akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;
using namespace std;

int main() {
    string s;
    cin >> s;
    if(s[0] == s[2]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let n: u64 = read();

    let mut ans: u64 = 0;

    for i in 1..n + 1 {
        let cnt = (n / i) as u64;
        ans += cnt * (cnt + 1) / 2 * i;
    }

    println!("{}", ans);
}


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

int main(void) {

    int N, A, B, C, X;
    while (cin >> N >> A >> B >> C >> X,
           N || A || B || C || X) {

        vector<int> Y(N);
        for (int i = 0; i < N; i++) cin >> Y[i];

        int ans = -1, pos = 0;
        for (int i = 0; i <= 10000; i++) {
            if (X == Y[pos]) {
                pos++;
                if (pos == N) {
                    ans = i;
                    break;
                }
            }
            X = (A*X + B) % C;
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3012
def solve():
    T1, T2 = map(int, input().split())
    A1, A2 = map(int, input().split())
    B1, B2 = map(int, input().split())

    if A1 < B1 and A2 < B2:
        return 0
    elif A1 > B1 and A2 > B2:
        return 0

    C1, C2 = B1-A1, B2-A2

    if C1*T1 + C2*T2 == 0:
        return 'infinity'

    if C1*T1 + C2*T2 < 0:
        C1, C2 = -C1, -C2

    if abs(C1*T1) > abs(C2*T2):
        return 0

    x1, x2 = T1, 2*T1+T2
    y1, y2 = C1*T1, 2*C1*T1+C2*T2

    x = -y1 * (x2-x1) // (y2-y1) + x1

    z = x-T1
    T = T1+T2
    num = z//T
    ans = num*2
    dist = C1*T1 + (C1*T1 + C2*T2)*num
    if dist != 0:
        ans += 1

    return int(ans)


print(solve())


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

s = []
o = [-1] * (n + 1)
count = 0

v = 1
while o[v] == -1:
    o[v] = count
    s.append(v)
    v = a[v-1]
    count += 1

l = o[v]
c = len(s) - o[v]
    
if k < l:
    print(s[k])
else:
    k -= l
    k = k % c
    print(s[l+k])


Measured memory_bytes: 32300
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
using namespace std;
#define ll           long long
#define all(v)       (v).begin() , (v).end()
#define vi           vector <ll>
#define vii          vector <pair<ll,ll>>
#define ii           pair<ll,ll>
#define sz(v)	     ((int)((v).size()))
#define lp(i,a,b)    for(int i=a;i<b;i++)
#define pb           push_back
#define pf           push_front
#define F            first
#define S            second
#define endl         "\n"
#define IOS          ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const double PI = 3.14159265358979323846;
const ll inf=2e9,MOD=1e9+7,MAX=1e5+1;
int n;
ll s;
set<pair<ll,ll>>adj[MAX];
vector<int>vis(MAX);
priority_queue<pair<ll,pair<ll,ll>>>st;
ll x;
ll dfs(int node){
    vis[node]=1;
    ll ret=0;
    for(auto i:adj[node]){
        if(!vis[i.first]){
            x=dfs(i.F);
            st.push({x*i.S,{i.S,x}});
            ret+=x;
        }
    }
    if(sz(adj[node])==1)
        ret++;
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int n,k;
    cin>>n>>k;
    int a[n];
    lp(i,0,n)
        cin>>a[i];
    sort(a,a+n);
    int res=0;
    lp(i,0,k)
        res+=a[i];
    cout<<res;
}

Measured memory_bytes: 8292
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]

tf = [[False for _ in range(3)] for _ in range(3)]
for i in range(3):
    for j in range(3):
        if A[i][j] in b:
            tf[i][j] = True
ans = "No"
for i in range(3):
    total = 0
    for j in range(3):
        if tf[i][j]:
            total += 1
    if total == 3:
        ans = "Yes"
for i in range(3):
    total = 0
    for j in range(3):
        if tf[j][i]:
            total += 1
    if total == 3:
        ans = "Yes"
if tf[0][0] == tf[1][1] == tf[2][2] == True:
    ans = "Yes"
if tf[2][0] == tf[1][1] == tf[0][2] == True:
    ans = "Yes"
print(ans)

Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)
// 素因数分解
vector<pair<long long, long long>> prime_factorize(long long n)
{
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p)
  {
    if (n % p != 0)
      continue;
    int num = 0;
    while (n % p == 0)
    {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1)
    res.push_back(make_pair(n, 1));
  return res;
}
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> sv(m), cv(m);
  rep(i, m)
  {
    cin >> sv[i];
    sv[i]--;
    cin >> cv[i];
  }
  for (int ans = 0; ans <= 999; ans++)
  {
    string s = to_string(ans);
    bool ok = true;
    if (s.length() != n)
    {
      ok = false;
    }
    for (int i = 0; i < m; i++)
    {
      if ((s[sv[i]] - '0') != cv[i])
      {
        ok = false;
      }
    }
    if (ok)
    {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3668
#### 逆元リストいらない
mod = 998244353
fact = [1]
fact_inv = [1]
for i in range(2*10**5+2):
    new_fact = fact[-1]*(i+1)%mod
    fact.append(new_fact)
    fact_inv.append(pow(new_fact,mod-2,mod))
def mod_comb_k(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod
def power_func(a,n,p):
  bi=str(format(n,"b"))#2進表現に
  res=1
  for i in range(len(bi)):
    res=(res*res) %p
    if bi[i]=="1":
      res=(res*a) %p
  return res
N,M,K = map(int,input().split())
ans = 0
for i in range(K+1):
    X = mod_comb_k(N-1,i,mod)
    Z = power_func(M-1,N-(i+1),mod)
    #print(X,Z)
    ans += X * M * Z % mod
ans %= mod
print(ans)


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

int f(vector<vector<char>> &S, int sh, int sw) {
  int H = S.size();
  int W = S.at(0).size();
  vector<vector<int>> dist(H, vector<int>(W, -1));
  dist.at(sh).at(sw) = 0;
  vector<int> mh(4), mw(4);
  mh = {-1, 0, 1, 0};
  mw = {0, 1, 0, -1};
  queue<pair<int,int>> Q;
  Q.push({sh, sw});
  int mx = 0;
  while (Q.size()) {
    auto [h, w] = Q.front(); Q.pop();
    for (int i = 0; i < 4; i++) {
      int nh = h + mh.at(i);
      int nw = w + mw.at(i);
      if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
      if (S.at(nh).at(nw) == '#') continue;
      if (dist.at(nh).at(nw) == -1) {
        dist.at(nh).at(nw) = dist.at(h).at(w) + 1;
        Q.push({nh, nw});
        mx = max(mx, dist.at(nh).at(nw));
      }
    }
  }
  return mx;
}

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> S.at(i).at(j);
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S.at(i).at(j) == '#') continue;
      ans = max(ans, f(S, i, j));
    }
  }
  cout << ans << "\n";
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

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


ll solve(int k, VVI &g, int p, int v) {
  int color;
  p == -1 ? color = k - 1 : color = k - 2;
  ll ret = 1;
  if(color + 1 < g[v].size()) return 0;
  for(auto u : g[v]) {
    if(u == p) continue;
    ret *= color;
    ret %= MOD;
    color--;
  }
  for(auto u : g[v]) {
    if(u == p) continue;
    ret *= solve(k, g, v, u);
    ret %= MOD;
  }
  return ret;
}


signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  VVI g(n);
  rep(i, n-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  ll ans = k * solve(k, g, -1, 0);
  out(ans%MOD);
  return 0;
}


Measured memory_bytes: 11648
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

void rotate(char str[][16])
{
	char tmp[8][8];
	rep(i, 8) rep(j, 8)
		tmp[i][j] = str[7-j][i];
	rep(i, 8)
		copy(tmp[i], tmp[i]+8, str[i]);
}

int main()
{
	char str[16][16];
	rep(i, 8)
		scanf("%s", str[i]);
	
	rep(i, 3){
		rotate(str);
		printf("%d\n", (i+1)*90);
		rep(j, 8)
			puts(str[j]);
	}
	return 0;
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define fastcin {\
    cin.tie(0);\
    ios::sync_with_stdio(false);\
}
#define REP(i, a, b) for(int i = a; i < b; i++)
#define RREP(i, a, b) for(int i = a; i > b; i--)
#define print(x) cout << x << "\n"
#define SORT(a, n) sort(a, a+n);
#define REVERSE(a,n) reverse(a,a+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VREVERSE(v) reverse(v.begin(), v.end());
#define MOD 1000000007
typedef long long ll;

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

Measured memory_bytes: 256
import sys

n = int( sys.stdin.readline() )
output = []
for i in range( 1, n+1 ):
	x = i
	if x%3 == 0:
		output.append( " {:d}".format( i ) )
	else:
		while x:
			if x%10 == 3:
				output.append( " {:d}".format( i ) )
				break
			x /= 10
print( "".join( output ) )

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

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

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

int main(){

	int N, M;
	vector<pair<int, int>> V;
	cin >> N >> M;
	int a, b;
	for(int i = 0; i < M; i ++){
		cin >> a >> b;
		V.pb(mp(b, a));
	}
	sort(all(V));
	int lastBreakBridge = 0, ans = 0;
	for(int i = 0; i < M; i ++){
		if(lastBreakBridge < V[i].second){
			ans ++;
			lastBreakBridge = V[i].first - 1;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
vector<int> x = {1,-1,0,0};
vector<int> y = {0,0,-1,1};
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> field(h,vector<char>(w));
    rep(i,0,h){
        rep(j,0,w){
            cin >> field[i][j];
        }
    }
    int out = 0;
    rep(i,0,h){
        rep(j,0,w){
            if(field[i][j]=='#'){
                int cnt = 0;
                rep(k,0,4){
                    
                    if(i+x[k]>=0&&i+x[k]<h&&j+y[k]>=0&&j+y[k]<w){
                        if(field[i+x[k]][j+y[k]]=='#'){
                            cnt++;
                        }
                    }
                    
                }
                if(cnt==0){
                        //cout<<i<<j<<endl;
                        out = 1;
                        break;
                }
            }
        }
    }
    if(out){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	string s1 = s;
	int min = 1000000007;
	for (int i = 0; i < s.size(); i++) {
		int co = 0;
		for (;;) {
			int co1 = 0;
			for (int k = 0; k < s.size() - co; k++) {
				if (s[k] == s1[i]) {
					co1++;
				}
			}
			if (co1 == s.size() - co) {
				if (co < min) {
					min = co;
				}
				s = s1;
				break;
			}
			co++;
			for (int j = 0; j < s.size() - co; j++) {
				if (s[j] == s1[i] || s[j + 1] == s1[i]) {
					s[j] = s1[i];
				}
			}
		}
	}
	cout << min << endl;
	return 0;
}

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

void solve(long long K, long long N, std::vector<long long> A)
{
    /*
    sort(A.begin(), A.end());
    int a = A[A.size() - 1]-A[0];

    for (int i = 0; i < A.size()-1;i++){
        A[i] = K-A[i];
        if(A[i] == K){
            A[i] = 0;
        }
    }
    */
    int len = A.size();
    int sum = 0;
    int A_top = A[0];
    for (int i = 0; i < len; i++)
    {
        if (i == len - 1)
        {
            A[len - 1] = K - A[len - 1] + A_top;
        }
        else
            A[i] = A[i + 1] - A[i];

        sum += A[i];
        }
    int ans = sum - A[0];
    for (int i = 1; i < len; i++)
    {
        if (ans > sum - A[i])
            ans = sum - A[i];
    }
    cout << ans << endl;
    //cout << sum << endl;
}

int main()
{
    long long K;
    scanf("%lld", &K);
    long long N;
    scanf("%lld", &N);
    std::vector<long long> A(N);
    for (int i = 0; i < N; i++)
    {
        scanf("%lld", &A[i]);
    }
    solve(K, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl "\n"
#define int long long
using namespace std;

void xor_calculate(){
	int N ;
	cin >> N;
	if ((N >= 2 && N <= 200000 ) && (!(N & 1)) ){
		vector<int> arr(N+5) , ans(N+5);  
		int xor_val = 0;
			
		for(int i =0 ; i < N ; i++){
			cin >> arr[i];
			xor_val ^= arr[i] ;
		}
	for(int i =0; i < N ; i++){
		ans[i] = xor_val ^ arr[i] ;
		cout<<ans[i]<<' ';
	}
  }	
}
int32_t main() {
	
	ios_base::sync_with_stdio(false) ,cin.tie(nullptr);
  	xor_calculate();
	return 0;
}

Measured memory_bytes: 6356
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
//素数判定 O(√N)
bool isPrime(int64_t x){
    if(x<=1){
        return false;
    }
    for(int i=2 ;i*i<=x ;i++){
        if(x%i==0){
            return false;
        }
    }
    return true;
}
int main(){
    int64_t n;
    cin>>n;
    /*
    if(n==1){
        cout<<0<<endl;
        return 0;
    }
    */
    /*
    if(isPrime(n)){
        cout<<1<<endl;
        return 0;
    }
    */
    map<int64_t,int> p;//素因数分解 O(√N)でできる
    int64_t num=n;
    for(int64_t i=2;i*i<=num;i++){
        while(num%i==0){
            p[i]++;
            num /= i;
        }
    }
    if(num!=1){
        p[num]++;
    }
    int64_t sum=0;
    for(auto c:p){
        //cout<<c.first<<" "<<c.second<<endl;
        int e = c.second;
        int count=0;
        for(int i=1;i*i<n;i++){
            count += i;
            if(e<count){
                sum += i-1;
                //cout<<sum<<" ";
                break;
            }   
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


const int MAX_V = 100010;
struct edge {
    ll to,cost;
};

int n;
vector<edge> G[MAX_V];  //重み付き有効グラフの隣接リスト表現
ll d[MAX_V];


void dijkstra(int s){
    //greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>,greater<P> > que;
    fill(d,d+n,INF);
    d[s] = 0;
    que.push(P(0,s));

     while(!que.empty()){
         P p = que.top(); que.pop();     // firstは最短距離、secondは頂点の番号
         int v = p.second;
         if(d[v] < p.first) continue;  
         for(int i = 0; i < G[v].size(); i++){
             edge e = G[v][i];
             if(d[e.to] > d[v] + e.cost){
                // 現在のd[]の要素とくらべて小さいものだけ追加するため、高速に計算可能
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));    
             }
         }
    }
}


int main()
{
    cin >> n;
    
    for(int i = 0; i < n-1; i++){
        ll a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        edge e1,e2;
        e1.to = a; e2.to = b;
        e1.cost = c; e2.cost = c;
        G[a].push_back(e2);
        G[b].push_back(e1);
    }
    int q,k;
    cin >> q >> k;
    dijkstra(k-1);
    for(int i = 0; i < q; i++){
        int x,y;
        cin >> x >> y;
        x--; y--;
        cout << (d[x] + d[y]) << endl;
    }
}

Measured memory_bytes: 9984
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    string s;
    cin >> s;
    int n = s.size();
    int c0 = 0, c1 = 0;
    for(char c : s) {
        if(c == '0') c0++;
        else c1++;
    }
    cout << n-abs(c0-c1) << endl;
}

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

int main()
{
	long long A, B; cin >> A >> B;
	if(A==0)A=1;
	long long ans = 0;
	long long x = 2;
	for (int i = 0; i < 63; i++)
	{
		//cerr<<x<<endl;
		//cerr<<B<<" "<<A<<endl;
		long long val = (B / x)*(x / 2) + (B%x) / (x / 2) * (B%x - x / 2 + 1) - ((A-1) / x)*(x / 2) - ((A-1) % x) / (x / 2) * ((A-1)%x - x / 2 + 1);
		//cout << val << endl;
		if (val % 2)ans += x / 2;
		x *= 2;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
using namespace std;

string conv(string &str){
    int n = str.length();
    string ret = "";
    for(int i=0; i<n; i++){
        if('a'<=str[i] && str[i]<='z'){
            ret += str[i] -'a' +'A';
        }
        if('A'<=str[i] && str[i]<='Z'){
            ret += str[i];
        }
    }
    return ret;
}

int main(){
    string input;
    while(getline(cin, input)){
        string str = conv(input);
        int n = str.length();
        vector<string> ans;
        set<string> canceled;

        for(int d=0; d<2; d++){
            for(int i=1; i<n-1-d; i++){
                if(d==1 && str[i]!=str[i+1]) continue;
                int l=i-1, r=i+d+1;
                string sub = "";
                while(l>=0 && r<n && str[l]==str[r]){
                    canceled.insert(sub);
                    sub = str.substr(l, r-l+1);
                    l--;
                    r++;
                }
                if(sub != "" && canceled.find(sub)==canceled.end()){
                    ans.push_back(sub);
                    canceled.insert(sub);
                }
            }
        }
        if(ans.empty()){
            cout << endl;
        }else{
            vector<string> newans;
            for(int i=0; i<(int)ans.size(); i++){
                bool ok = true;
                for(int j=0; j<(int)ans.size(); j++){
                    if(ans[i].length()%2 != ans[j].length()%2) continue;
                    if(ans[i].length() >= ans[j].length()) continue;
                    int lendiff = ans[j].length() -ans[i].length();
                    lendiff/=2;
                    if(ans[i] == ans[j].substr(lendiff, ans[i].length())){
                        ok = false;
                        break;
                    }
                }
                if(ok) newans.push_back(ans[i]);
            }
            ans = newans;
            for(int i=0; i<(int)ans.size()-1; i++){
                cout << ans[i] << " ";
            }
            cout << ans.back() << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3188
from collections import deque
N = int(input())
A = deque(list(map(int, input().split())))

ans = 0
cnt = 1
while A:
    a = A.popleft()
    if cnt == a:
        cnt += 1
        continue
    else:
        ans += 1
if ans == N:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 33924
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define ones(n) __builtin_popcount(n)
#define ONES(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef pair<int, int> ii;
typedef pair<long long, pair<int, int>> iii;
typedef pair<ii, ii> iiii;

const double PI = acos(-1.0), EPS = 1e-6;
const int N = 1003, M = 102, mod = 1000000007, mxLog = 20;
char grid[N][N];
int memo[N][N];
int n, m;

int solve(int i, int j) {
    if (i == n - 1 && j == m - 1) {
        return 1;
    }
    int &ret = memo[i][j];
    if (~ret)
        return ret;
    ret = 0;
    if (i != n - 1 && grid[i + 1][j] == '.') {
        ret += solve(i + 1, j);
    }
    if (j != m - 1 && grid[i][j + 1] == '.') {
        ret += solve(i, j + 1);
    }
    ret %= mod;
    return ret;
}



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(7), cout << fixed;

    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> grid[i][j];
        }
    }
    memset(memo, -1, sizeof memo);
    cout << solve(0, 0);

    return 0;
}

Measured memory_bytes: 5248
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-8;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=100010;
int n;
int head[N],nxt[N<<1],to[N<<1],co[N<<1],lst=1;
inline void adde(int x,int y,int c) {
	nxt[++lst]=head[x]; to[lst]=y; co[lst]=c; head[x]=lst;
}
int fa[N],val[N];
void Build(int u) {
	for(int i=head[u];i;i=nxt[i]) {
		int v=to[i]; val[u]^=co[i];
		if(v==fa[u]) continue;
		fa[v]=u; Build(v);
	}
}
int num[N],ind=0;
int ans=0;
int f[1<<16];
inline void DP() {
	int St=0;
	for(int i=1;i<=ind;i++) St|=1<<num[i];
	mem(f,63); f[St]=0;
	for(int i=St;i>=0;i--) 
		for(int p1=1;p1<16;p1++)
			if(i&(1<<p1))
				for(int p2=1;p2<16;p2++)
					if(i&(1<<p2)){
						int sta=i^(1<<p1)^(1<<p2),v=1;
						if(sta&(1<<(p1^p2))) ++v;
						sta^=1<<(p1^p2);
						f[sta]=min(f[sta],f[i]+v);
					}
	ans+=f[0];
}
signed main()
{
	read(n);
	for(int i=1;i<n;i++) {
		int x,y,c; read(x); read(y); read(c);
		++x; ++y; adde(x,y,c); adde(y,x,c);
	}
	Build(1);//good transfor: edge->point
	sort(val+1,val+n+1); val[n+1]=16;
//	for(int i=1;i<=n;i++) printf("%d ",val[i]); puts("");
	int cnt=1;
	for(int i=2;i<=n+1;i++) {
		if(val[i]!=val[i-1]) {
			if(val[i-1]) {
				ans+=cnt/2;
				if(cnt&1) num[++ind]=val[i-1];
			}
			cnt=1;
		} else ++cnt;
	}
	DP();
	printf("%d\n",ans);
	return 0;
}
/*
7
0 1 1
0 2 3
0 3 2
1 4 2
2 5 3
3 6 2
*/

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = fact[1] = 1;
    for(int i=2; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
}

void create_seq_inv_mod(int num){
    seq_inv[0] = seq_inv[1] = 1;
    for(int i=2; i<=num; i++) seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
}

void create_fact_inv_mod(int num){
    fact_inv[0] = fact_inv[1] = 1;
    for(int i=2; i<=num; i++) fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<pair<int64_t, int>> prime_division(int64_t n){
    vector<pair<int64_t, int>> ret;
    for(int64_t i=2; i*i<=n; i++){
        int cnt = 0;
        while(n % i == 0){
            n /= i;
            cnt++;
        }
        if(cnt) ret.emplace_back(i, cnt);
    }
    if(n > 1) ret.emplace_back(n, 1);
    return ret;
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    map<int, int> mp;
    for(int a : A){
        auto pr = prime_division(a);
        for(auto& p : pr) mp[p.first] = max(mp[p.first], p.second);
    }

    int64_t ans = 0;
    for(int a : A) add(ans, inv_mod(a));
    for(auto& p : mp) mul(ans, power_mod(p.first, p.second));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <map>
#include <vector>

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		vector<int> Vec(N);
		for(int i = 0; i < N; ++i)
		{
			cin >> Vec[i];
		}
		int count = 0;
		bool Flag = true;
		while(Flag)
		{
			++count;
			map<int, int> Map;
			Flag = false;
			for(int i = 0; i < N; ++i)
			{
				++Map[Vec[i]];
			}
			vector<int> VecBuf(N);
			for(int i = 0; i < N; ++i)
			{
				VecBuf[i] = Map[Vec[i]];
			}
			for(int i = 0; i < N; ++i)
			{
				if(Vec[i] != VecBuf[i])
				{
					Flag = true;
					for(int j = 0; j < N; ++j)
					{
						Vec[j] = VecBuf[j];
					}
					goto NEXT;
				}
			}
NEXT:
			;
		}
		cout << --count << endl;
		for(int i = 0; i < N - 1; ++i)
		{
			cout << Vec[i] << " ";
		}
		cout << Vec[N - 1] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int N = int.Parse(str[0]);
		int M = int.Parse(str[1]);
		int[][]A = new int[M][];
		var listA = new HashSet<int>[N];
		for(var i=0;i<N;i++){
			listA[i] = new HashSet<int>();
		}
		for(var i=0;i<M;i++){
			string[] str2 = Console.ReadLine().Split();
			A[i] = new int[2]{int.Parse(str2[0]),int.Parse(str2[1])};
			listA[A[i][0]-1].Add(A[i][1]);
		}
		string[] str3 = Console.ReadLine().Split();
		int S = int.Parse(str3[0]);
		int T = int.Parse(str3[1]);
		var list = new HashSet<int>();
		list.Add(S);
		int[]C = new int[N];
		C[S-1] = 1;
		int ans = 0;
		while(list.Count>0){
			ans++;
          	//int[]D = new int[N];
			var list2 = new List<int>(list);
			list.Clear();
			bool flag = false;
			bool flag2 = false;
			foreach(var i in list2){
				foreach(var j in listA[i-1]){
					list.Add(j);
				}
			}
			list2 = new List<int>(list);
			list.Clear();
			foreach(var i in list2){
				foreach(var k in listA[i-1]){
					list.Add(k);
				}
			}
			list2 = new List<int>(list);
			list.Clear();
			foreach(var i in list2){
				foreach(var l in listA[i-1]){
					if(C[l-1]==0){
						list.Add(l);
						C[l-1]=1;
						flag = true;
						if(l==T){
							flag2 = true;
							break;
						}
					}
				}
			}
			if(flag2){
				break;
			}
			if(!flag){
				ans = -1;
				break;
			}
		}
		Console.WriteLine(ans);
	}
}


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

int main()
{
	long long  a , b ;
	long long x ,sum;
	scanf("%lld %lld %lld" ,&a,&b,&x);
	sum=(b/x) - ((a)/x);

    if(a%x == 0)
    ++sum;
    printf("%lld\n",sum);
}


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

int main()
{
    string str = "aouie" ;
    char j;
    int i ;
    bool flag ;
    cin >> j;
        for (i=0 ; i<5 ; i++)
        {
            if (j == str[i]){
                flag =true;
                break;}

            else{
                flag = false;}  
        }
        if (flag){
            cout <<"vowel"<< endl;}
        else{
            cout <<"consonant" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;

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

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	int d = max(a, max(b, c));
	cout << 9 * d + a + b + c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
			res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int ans = ((modpow(10, n, mod) - (2 * modpow(9, n, mod) % mod) + mod) % mod + modpow(8, n, mod)) % mod;
	cout << ans;

	return 0;
}

Measured memory_bytes: 3648
n, k = map(int, input().split())

h = []
for i in range(n):
  t = int(input())
  h.append(t)
h = sorted(h)

ans = max(h)
for i in range(n - k + 1):
  ans = min(h[i + k - 1] - h[i], ans)
print(ans)

Measured memory_bytes: 8280
import java.util.*;
 
public class Main {
  
  public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    
	    int N = sc.nextInt();
	    int A[] = new int[N];
	    
	    List<Integer> list = new ArrayList<>();
	    
	    for(int i=0; i<N; i++) {
			A[i]= sc.nextInt();
			list.add(A[i]);
		}
	    
	    Collections.sort(list);
	    
	    for(int i=0; i<N; i++) {
	    	if(A[i]==list.get(N-1)) {
	    		System.out.println(list.get(N-2));
	    	}else {
	    		System.out.println(list.get(N-1));
	    	}
	    }
	    
	} 

}

Measured memory_bytes: 67276
m;main(d){for(;scanf("%d%d",&m,&d),m;printf("%sday\n","Thurs\0Fri\0__Satur\0Sun\0__Mon\0__Tues\0_Wednes"+(d-13*~m/5)%7*6))m<3?d-=2,m+=12:0;}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define fo(i, a, b) for (int i = a; i < b; i++)
#define re(i, n) fo(i, 0, n)
using namespace std;
typedef long long ll;
int main()
{
  string s;
  cin >> s;

  vector<char> a(s.size());
  re(i, s.size()) {
    if (i % 2 == 0) a[i] = '1';
    else a[i] = '0';
  }
  vector<char> b(s.size());
  re(i, s.size()) {
    if (i % 2 == 0) b[i] = '0';
    else b[i] = '1';
  }

  int c_a = 0, c_b = 0;
  re(i, s.size()) {
    if (s[i] != a[i]) c_a++;
    if (s[i] != b[i]) c_b++;
  }

  cout << min(c_a, c_b) << endl;

  return 0;
}


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

int main() {
	int A, B;	//入力
  cin >> A >> B;
  int a, b, c, d, e;	//それぞれの位
	int i, j;	//for処理
      int sum;
  sum = 0;
  int l;
  l = A;
  j = B - A + 1;
  for (i = 0; j> i; i++) {
      a = l / 10000;
    b = (l % 10000) / 1000;
    c = (l % 1000) / 100;
    d = (l % 100) / 10;
    e = l % 10;
    if (a == e && b == d)
      sum++;
    l++;  
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin>>n;
  vector<int>p(n);
  rep(i,n)cin>>p[i];
  rep(i,n)rep(j,n)
  {
    vector<int>q(n);
    q=p;
    swap(q[i],q[j]);
    int f=1;
    rep(i,n-1)
    {
      if(q[i]>q[i+1]){f=0;break;}
    }
    if(f)
    {
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;

}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

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

  int64_t l,r;
  cin>>l>>r;
  int64_t ml=l%2019,mr=r%2019;
  if(ml>=mr||r-l>=2018){
    cout<<0<<endl;
    return 0;
  }else{
    int64_t result=2019;
    for(int64_t i=ml;i<=mr;i++){
      for(int64_t j=i+1;j<=mr;j++){
        result=std::min(result,i*j%2019);
      }
    }
    cout<<result<<endl;
  }



  return 0;
}


Measured memory_bytes: 256
def main():
    MOD = 998244353

    def cmb(n, r):
        if n - r < r:
            return cmb(n, n - r)
        if r < 0:
            return 0
        if r == 0:
            return 1
        if r == 1:
            return n
        return f[n] * invs[r] * invs[n - r] % MOD

    N, A, B, K = map(int, input().split())

    f = [-1] * (N + 1)
    f[0] = 1
    t = 1
    for i in range(1, N + 1):
        t *= i
        t %= MOD
        f[i] = t

    inv = pow(t, MOD - 2, MOD)
    invs = [-1] * (N + 1)
    invs[N] = inv
    for i in range(N - 1, 0, -1):
        inv *= (i + 1)
        inv %= MOD
        invs[i] = inv

    ret = 0
    for i in range(K // A + 1):
        j, r = divmod(K - A * i, B)
        if r == 0:
            ret = (ret + cmb(N, i) * cmb(N, j)) % MOD

    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 28788
#include <iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a[s.size()]={0};
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')a[i]=1;
	}
	int ans=0,num=0;
	for(int i=0;i<s.size();i++){
		if(a[i])num++;
		else {ans=max(ans,num);num=0;}
	}
	ans=max(ans,num);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N=gets.to_i

yaku = []

(1..[[(N/2),100000].min, 1].max).each{|i|
  yaku<<i if N%i==0
}

min = 11 #てきとう

yaku.each{|t|
  a = t.to_s.size
  b = (N/t).to_s.size
  a = b if b > a 
  min = a if a < min
}

puts min

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
using namespace std;
int main(){
  double a,b,c,r,n;
  while(cin >> a >> b >> c, a+b+c){
    cin >> n;
    while(n--){
    cin >> r;
    if(sqrt(a*a + b*b) < 2*r ||
       sqrt(c*c + b*b) < 2*r ||
       sqrt(a*a + c*c) < 2*r)cout << "OK" << endl;
    else cout << "NA" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1220
#!/usr/bin/env python3
import sys


def solve(s: str):
    answer = ""
    for i in range(len(s)):
        if s[i] == 'B':
            if answer:
                answer = answer[:len(answer)-1]
        else:
            answer += s[i]
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    s = next(tokens)  # type: str
    solve(s)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define drep(i,a,b) for(int i=(a); i>=(b);i--) 

const int maxn = 1e5 + 5;
const int MOD = 1e9 + 7;

int a[55];

int main()
{
   ios::sync_with_stdio(false); cin.tie(0);cout.tie(0);
   int n;
   cin >> n;
   rep(i,1,n) cin >> a[i];
   int ans = 0;
   rep(i,1,n){
      if(a[i] != i) ans++;
   }
   if(ans > 2) cout << "NO";
   else cout << "YES";
   return 0;
}

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

int main()
{
  int L,R,d;
  cin >> L >> R >> d;
  
  int mul;
  int num = 0;
  for(int i = 1; i <= R; i++){
    mul = i * d;
    if( (mul >= L) && (mul <= R) ){
      num++;
    }//if
  }//for
  
  cout << num << endl;
    
}

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


int main()

{

    int n;
    cin>>n;
    int cnt=0;

    if(n<=9)cnt+=n;
    else if(n<100)cnt+=9;
    else if(n<=999)cnt+=n-99+9;
    else if(n<1e4)cnt+=909;
    else if(n<=99999)cnt+=n-9999+909;
    else cnt+=90909;

    cout<<cnt<<endl;



    return 0;
}



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

int main() {
    cin.tie(0)->sync_with_stdio(false);

    ll n, a, b;
    cin >> n >> a >> b;

    ll ans;
    if (b < a) ans = 0;
    else if (n == 1) {
        if(a != b) ans = 0;
        else ans = 1;
    }
    else if (n == 2) ans = 1;
    else if (a == b) ans = 1;
    else {
        ll num = b - a + 1;
        ans = num + (num - 1) * (n - 2 - 1);
    }

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#!/bin/ruby
until (n=gets.to_i)==0
  c=gets.chomp.split('')
  b=0
  p=Array.new(n){0}
  c.each_with_index do |e,x|
    mx=x%p.size
    p[mx]+=1
    if e=='S' then
      b+=p[mx]
      p[mx]=0
    elsif e=='L' then
      p[mx]+=b
      b=0
    end
  end
  puts (p.sort<< b).join(' ')
end

Measured memory_bytes: 6104
#include <iostream>
#include <numeric>
#include <vector>
#include <math.h>
#include <map>
#include <algorithm>
#include <stdio.h>
#include <set>
#define mod 1000000007
using namespace std; 

int main(){
	int n; cin >> n;
	set<string> A;
	for (int i=0;i<n;i++){
		string a; cin >> a;
		A.insert(a);
	}
	cout << A.size() << "\n";
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

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

	if(b>=a) cout << a << endl;
	else cout << a - 1 << endl;


	return 0;

}


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

public class Main {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

       int n = sc.nextInt();
       int d = sc.nextInt();

       int ans = n / (2 * d + 1);

       if(n % (2 * d + 1) == 0){
           System.out.println(ans);
       } else {
           System.out.println(ans + 1);
       }
    }


}


Measured memory_bytes: 23764
MOD = 10 ** 9 + 7

X, Y = map(int, input().split())

if (X + Y) % 3 != 0:
    print(0)
    exit()

a = (2 * X +   - Y) // 3
b = (  - X + 2 * Y) // 3


if a < 0 or b < 0:
    print(0)
    exit()

#calculate (a+b)!/a!b!

fac = [1, 1]
for i in range(2, a+b+1):
    fac.append(fac[-1] * i % MOD)

print(fac[a+b] * pow(fac[a] * fac[b], MOD-2, MOD) % MOD)

Measured memory_bytes: 35172
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<set>
#include<cmath>
#include<queue>
#include<unordered_map>
#include<map>
#include<stack>
#include<bits/stdc++.h>
#include<string.h>
#include <ext/pb_ds/assoc_container.hpp>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
//#define f first
//#define s second
#define respr(fir,sec) for(int i=0;i<=fir;i++){for(int j=0;j<=sec;j++){cout << res[i][j] << " ";}cout << "\n";}
#define pb push_back
//#define INF (1LL<<31)
using namespace std;
using namespace __gnu_pbds;
const int mod = 1e9+7;
const ll MAX = 1000000000000000000;
typedef pair<int,ll> pii;
typedef pair<ll,int> pi;
typedef tuple<long long,int> tp;
typedef tuple<int,int,long long> tu;
typedef multimap<pii , int> mpp;
typedef priority_queue< tp , vector<tp>, greater<tp>>  minheap;
typedef priority_queue<pii , vector<pii>> maxheap;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>  new_data_set;
const int nax=3001;
double dp[nax];


int main()
{
	FASTIO;
	int n;
	scanf("%d" , &n);
	
	dp[0]=1;
	for(int coin=0;coin<n;coin++){
		double p_head;
		scanf("%lf",&p_head);
		for(int i=coin+1;i>=0;--i){
			if(i>0){
			dp[i] = p_head*dp[i-1]+(1-p_head)*dp[i];
			}
			else{
				dp[i] = (1-p_head)*dp[i];
			}
		}
	}
	double sum=0;
	for(int i=(n/2)+1;i<=n;i++)
		sum += dp[i];
	printf("%.10lf\n", sum);
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int x = sc.nextInt();
    int y = sc.nextInt();
    int r = sc.nextInt();
    
    if((x - r) < 0 || (y - r) < 0 || (x + r) > W || (y + r) > H){
        System.out.println("No");    
    }else if((x - r) >= 0 && (y - r) >= 0 && (x + r) <= W && (y + r) <= H){
        System.out.println("Yes");
    }
    


  }

}


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

int main() {
    string s;
    int k;
    cin >> s >> k;
    vector<ll> n(s.size());
    for (size_t i = 0; i < s.size(); i++) {
        n[i] = s[i] - 48;
    }

    vector<vector<ll>> dp0(n.size(), vector<ll>(4));
    vector<vector<ll>> dp1(n.size(), vector<ll>(4));

    dp0[0][1] = 1;
    dp0[0][2] = 0;
    dp0[0][3] = 0;

    dp1[0][1] = n[0] - 1;
    dp1[0][2] = 0;
    dp1[0][3] = 0;

    for (size_t i = 1; i < n.size(); i++) {
        // same as n
        dp0[i][1] = (n[i] == 0) ? dp0[i - 1][1] : 0;
        dp0[i][2] = (n[i] == 0) ? dp0[i - 1][2] : dp0[i - 1][1];
        dp0[i][3] = (n[i] == 0) ? dp0[i - 1][3] : dp0[i - 1][2];

        dp1[i][1] = dp1[i - 1][1] + 9;
        dp1[i][2] = dp1[i - 1][2] + dp1[i - 1][1] * 9;
        dp1[i][3] = dp1[i - 1][3] + dp1[i - 1][2] * 9;

        if (n[i] != 0) {
            dp1[i][1] += dp0[i - 1][1];
            dp1[i][2] += dp0[i - 1][2] + dp0[i - 1][1] * max(n[i] - 1, 0LL);
            dp1[i][3] += dp0[i - 1][3] + dp0[i - 1][2] * max(n[i] - 1, 0LL);
        }
    }

    cout << (dp0[n.size() - 1][k] + dp1[n.size() - 1][k]) << endl;
}

Measured memory_bytes: 256