akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] array = new int[N];
		for (int i = 0; i < N; i++) {
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		
		int sum = 0;
		for (int i = 0; i < N; i++) {
			sum += array[N - i - 1] * ((i % 2 == 0) ? 1 : -1);
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 23124
s1 = input().split()
intN = int(s1[0])
s2 = input().split()

cnt = 0
wk = 1
while wk <= intN:
    if (wk % 2 != 0) :
        if (int(s2[wk-1]) % 2 != 0) :
            #print(wk)
            #print(s2[wk-1])
            cnt += 1
    wk += 1

print(cnt)

Measured memory_bytes: 9076
//header{{{
#include<bits/stdc++.h>
  
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define setout(n,x) setw(n+1) << setfill(x)
#define Fixed fixed << setprecision(10)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod = 1e9+7; 
constexpr int MOD = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
int gcd(int a,int b){ return b ? gcd(b,a % b) : a;}
int lcm(int a,int b){ return a / gcd(a,b) * b;}

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}
//UnionFind{{{
struct UnionFind {
    vector < int > par;
    vector < int > siz;
 
    UnionFind(int n): par(n), siz(n, 1) { //初期化
        for(int i = 0; i < n; i++) par[i] = i;
    }
 
    int root(int x){ //根の更新＋判定
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }
 
    int size(int x){ //サイズ
        return siz[root(x)];
    }
 
    bool same(int x, int y){ //グループの判定
        return root(x) == root(y);
    }
 
    bool unite(int x, int y){ //つなげる
        if((x=root(x))==(y=root(y))) return false;
        if( siz[y] > siz[x] ) swap(x,y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }
};
//}}}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n,m,p = 1e5;
    cin >> n >> m;
    UnionFind uf(n+1);
    vector<vector<int> > g(2e5+1);
    reps(i,n){
        int k;
        cin >> k;
        rep(j,k){
            int l;
            cin >> l;
            g[i].emplace_back(l+p);
            g[l+p].emplace_back(i);
        }
    }

    queue<int> que;
    vector<int> visited(2e5+1);
    visited[1] = true;
    que.emplace(1);
    while(!que.empty()){
        int now = que.front();
        que.pop();
        rep(i,g[now].size()){
            int next = g[now][i];
            if(!visited[next]){
                que.emplace(next);
                visited[next] = true;
                if(next <= n){
                    uf.unite(1,next);
                }
            }
        }
    }

    for(int i = 2;i <= n;++i){
        if(!uf.same(1,i)) return cout << "NO\n",0;
    }
    cout << "YES\n";


	return 0;
}


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

int A, B;

int main() {
	cin>>A>>B;
	if (A==B) {
		cout<<"Draw"<<endl; 
	} else if ((A > B)&&(B!=1)) {
		cout<<"Alice"<<endl;
	} else if (B==1) {
		cout<<"Bob"<<endl; 
	} else if ((A < B)&&(A!=1)) {
		cout<<"Bob"<<endl;
	} else if (A==1) cout<<"Alice"<<endl;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
py=[list(map(int,input().split())) for _ in range(m)]
res=[[] for _ in range(n)]
for i in range(m):
    res[py[i][0]-1].append(py[i][1])
for i in range(n):
    res[i].sort()
import bisect
for p,y in py:
    t=bisect.bisect_left(res[p-1],y)
    ans=str(1000000+p)[1::]+str(1000000+t+1)[1::]
    print(ans)

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

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;


int main() {
	ll h;
	int n;
	cin >> h >> n;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		h -= a;
	}
	if (h <= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
const ll INF=1LL<<60;
const ll MOD=1000000007;


int main(){
    ll N;
    cin >> N;
    ll K;
    cin >> K;
    if(K>(N-1)*(N-2)/2){cout<<-1<<endl;return 0;}
    ll t=(N-1)*(N-2)/2-K;
    deque<P> ans;
    for(ll i=2;i<=N;i++){
        ans.emplace_back(P(1,i));
    ;}
    deque<P> deq;
    for(ll i=2;i<=N-1;i++){
     for(ll j=i+1;j<=N;j++){
         deq.emplace_back(P(i,j));
     ;}
    ;}
    for(ll i=0;i<t;i++){
        ans.emplace_back(deq[i]);
    ;}
    cout<<N-1+t<<endl;
    while(!ans.empty()){
        cout<<ans.front().first<<" "<<ans.front().second<<endl;
        ans.pop_front();
    }
    
    
    return 0;
}


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

#define MAX 51

int main(){
  int H, W;
  int dp[MAX][MAX], field[MAX][MAX];
  string tmp[MAX];
  cin >> H >> W;
  
  fill(dp[0], dp[0]+MAX*MAX, (1<<29));
  
  for(int i = 0 ; i < H ; i++){
      cin >> tmp[i];
  }
  
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      field[i][j] = tmp[i][j]-'0';
    }
  }

  dp[0][0] = field[0][0];
  
  for(int i = 0 ; i < H ; i++){
    for(int j = 0 ; j < W ; j++){
      if(i == 0){
	dp[i][j] = min(dp[i][j], dp[i][j-1]+field[i][j]);
      }
      else if(j == 0){
	dp[i][j] = min(dp[i][j], dp[i-1][j]+field[i][j]);
      }
      else{
	dp[i][j] = min(dp[i][j], min(dp[i][j-1]+field[i][j], dp[i-1][j]+field[i][j]));
      }
    }
  }
  cout << dp[H-1][W-1] << endl;
  return 0;
}

Measured memory_bytes: 1228
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    ll n;
    cin>>n;
    map<string,vector<pll>> M;
    for(int i=0;i<n;i++){
        string s;
        ll p;
        cin>>s>>p;
        M[s].push_back({p,i+1});
    }
    for(auto &I:M){
        sort(I.S.begin(),I.S.end(),greater<pll>());
        for(auto &T:I.S){
            cout<<T.S<<endl;
        }
    }
    
    
    return 0;
}


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

#define all(a) a.begin(), a.end()
#define forn(l, r) for(int i = l; i < (r); ++i)
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
///#define int long long int

using namespace std;
using namespace __gnu_pbds;
using ll = long long int;
using ii = pair<int, int>;
using li = pair<ll, int>;
using vi = vector<int>;
using graph = vector<vi>;
using ordered_set = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll mod =  1000000007;
const int INF = 0x3f3f3f3f;
const int MAXN = 112345;
// const double pi = 3.14159265359;
const double eps = 0.00000001;

int swp[MAXN];
ii gates[MAXN];

int32_t main() {
    $
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> gates[i].F >> gates[i].S;
        swp[gates[i].F]++;
        swp[gates[i].S + 1]--;
    }
    sort(gates, gates + m);
    vector<ii> res(1, gates[0]);
    for (int i = 1; i < m; ++i) {
        if (res.back().S < gates[i].F) {
            res.push_back(gates[i]);
            return cout << "0\n", 0;
        } else if (res.back().S >= gates[i].F) {
            res.back().S = gates[i].S;
        }
    }
    int ans = -INF, cnt = 0;
    for (int i = 1; i <= n; ++i) {
        swp[i] += swp[i - 1];
        if (swp[i] != m) {
            cnt = 0;
        }
        cnt += (swp[i] == m);
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
}   



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

using namespace std;

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

  int n, x;
  cin >> n >> x;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long sum = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] + a[i] > x) {
      int d = a[i - 1] + a[i] - x;
      sum += d;
      a[i] = max(0, a[i] - d);
    }
  }
  cout << sum << '\n';
  return 0;
}

Measured memory_bytes: 640
def main(arg):
    arg = str(arg)
    numbers = [int(x)for x in arg.split(" ")]
    numbers = sorted(numbers)
    a,b,c = numbers[0],numbers[1],numbers[2]
    return "{} {} {}".format(a,b,c)


if __name__ == '__main__':
    print(main(input()))

Measured memory_bytes: 7688
from itertools import combinations

S = input()
patterns = []

for i in range(1, len(S)):
    patterns += list(combinations(range(1, len(S)), i)) 

answer = int(S)
for pattern in patterns:
    s = 0 
    for pos in pattern:
        answer += int(S[s:pos])
        s = pos 
    answer += int(S[pos:])

print(answer)

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

int main() {
    string s1, s2;
    cin >> s1 >> s2;

    int mw = min(s1.size(), s2.size());
    int res = 0;
    for(int w=mw; w>0; --w) {
        set<vector<int>> s;
        vector<int> cnt1(26);
        for(int i=0; i<w; ++i) {
            cnt1[s1[i]-'a']++;
        }
        s.insert(cnt1);
        for(int i=1; i+w-1<s1.size(); ++i) {
            cnt1[s1[i-1]-'a']--;
            cnt1[s1[i+w-1]-'a']++;
            s.insert(cnt1);
        }

        bool f = false;
        vector<int> cnt2(26);
        for(int i=0; i<w; ++i) {
            cnt2[s2[i]-'a']++;
        }
        if(s.count(cnt2) == 1) {
            res = w;
            f = true;
        }
        if(f) {
            break;
        }
        for(int i=1; i+w-1<s2.size(); ++i) {
            cnt2[s2[i-1]-'a']--;
            cnt2[s2[i+w-1]-'a']++;
            if(s.count(cnt2) == 1) {
                res = w;
                f = true;
            }
        }
        if(f) {
            break;
        }
    }
    cout << res << endl;
}


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

int solve(int a[], int n)
{
    int dp[n];
    for(int i=0;i<n;i++)dp[i]=INT_MAX;
    
    dp[0] = 0;
    for(int i=0;i<n-1;i++)
    {
        if(i+1 < n)
        {
            dp[i+1] = min(dp[i+1], dp[i]+abs(a[i+1]-a[i]));
        }
        if(i+2 < n)
        {
            dp[i+2] = min(dp[i+2], dp[i]+abs(a[i+2]-a[i]));
        }

    }
    
    return dp[n-1];
}

int main()
{
    int n;
    cin>>n;
    
    int a[n];
    for (int i=0;i<n;i++)
    cin>>a[i];
    
    int res = solve(a, n);
    cout<<res<<endl;
}


Measured memory_bytes: 1024
ary = []
5.times do
  ary << gets.chomp.to_i
end

ary = ary.sort_by{|x| (x-1)%10 }
sum = 0

(1..4).to_a.each do |i|
    sum += ary[i] % 10 == 0? ary[i]: ary[i] + 10 - ary[i]%10
end

puts sum + ary[0]


Measured memory_bytes: 1788
#include<stdio.h>

int main()
{
  int n;
  int a[101];
  int i,j;
  int A,B;
  int t;
  A=0;
  B=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      t=a[i];
      if(a[i]<a[j]){
        a[i]=a[j];
        a[j]=t;
      }
    }
  }
  for(i=0;i<n;i++){
    if(i%2==0) A+=a[i];
    if(i%2==1) B+=a[i];
  }
  printf("%d",A-B);
  return 0;
}


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

int main(){
    using namespace std;
    unsigned long N, M;
    cin >> N >> M;
    string s;
    cin >> s;
    vector<unsigned long> uku(N + 1);
    for(unsigned long i = 0; i <= N; ++i){
        if(s[i] == '1')uku[i] = numeric_limits<unsigned long>::max();
        else uku[i] = i;
    }
    reverse(uku.begin(), uku.end());
    vector<unsigned long> tap(N);
    stack<unsigned long> front, back;
    unsigned long loc{numeric_limits<unsigned long>::max()};
    front.push(loc);
    const auto& push = [&back, &loc](unsigned long x) -> void {
        back.push(x);
        loc = min(loc, x);
    };
    const auto& pop = [&front, &back, &loc]() -> void {
        if(front.size() == 1){
            while(!back.empty()){
                auto t = back.top();
                back.pop();
                front.push(min(front.top(), t));
            }
            loc = numeric_limits<unsigned long>::max();
        }
        front.pop();
    };
    const auto& get = [&front, &loc]() -> unsigned long { return min(front.top(), loc); };
    for(unsigned long i = 0; i < M; ++i)push(uku[i]);
    for(unsigned long i = 0; i < N; ++i){
        if(i + M <= N)push(uku[i + M]);
        pop();
        tap[i] = get();
    }
    tap.push_back(0);
    reverse(tap.begin(), tap.end());
    vector<unsigned long> ans{N};
    unsigned long idx{N};
    while(idx > 0){
        idx = tap[idx];
        if(idx > N)return 0 & puts("-1");
        ans.push_back(idx);
    }
    reverse(ans.begin(), ans.end());
    auto n{ans.size()};
    for(unsigned long i = 1; i < n; ++i)cout << ans[i] - ans[i - 1] << " ";
    cout << endl;
    return 0;
}

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

int main() {
  char N;
  cin >> N;
  if(N=='A'||N=='B'||N=='C'||N=='D'||N=='E'||N=='F'||N=='G'||N=='H'||N=='I'
     ||N=='J'||N=='K'||N=='L'||N=='N'||N=='M'||N=='O'||N=='P'||N=='Q'||N=='R'
     ||N=='S'||N=='T'||N=='U'||N=='V'||N=='W'||N=='X'||N=='Y'||N=='Z'){
    cout << 'A' << endl;
  }else {
    cout << 'a' << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3528
from collections import defaultdict
dic = defaultdict(lambda:0)

N = int(input())

for _ in range(N):
  s = input()
  dic[s] += 1

print("AC x "+str(dic['AC']))
print("WA x "+str(dic['WA']))
print("TLE x "+str(dic['TLE']))
print("RE x "+str(dic['RE']))

Measured memory_bytes: 9496
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<stack>
#include <cmath>
#include<bits/stdc++.h>
#include<math.h>
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;

int main(){
    int n,x; cin >> n >> x;
    int l[n]; cinf(n,l);
    int d=0,ans=1;
    for(int i=0;i<n;i++){
        d += l[i];
        if(x >= d) ans++;
    }
    cout << ans;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi b(n+1, INF);
    for (int i=1; i<n; ++i) cin >> b[i];
    vi a(n);
    rep(i, n) a[i] = min(b[i], b[i+1]);
    int ans = 0;
    rep(i, n) ans += a[i];
    cout << ans << endl;
    return 0;
}


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

namespace ConsoleApp1
{
    static class CMaximalValue
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int n = nk[0];
            int k = nk[1];
            var s = Console.ReadLine();
            var sSplits = s.ToList().Select(x => x.ToString()).ToList();

            int firstCount = 0;
            for (int i = 1; i < sSplits.Count; i++)
            {
                if (sSplits[i - 1] == sSplits[i])
                {
                    firstCount++;
                }
            }

            Console.WriteLine(Math.Min(firstCount + 2 * k, n - 1));
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 18016
S = input()
Q = int(input())

add_to_last = []
add_to_beginning = []

queries = [input() for _ in range(Q)]

mode = 1
for i in range(Q):
  query = queries[i]
  if query=='1':
    mode *= -1
  else:
    _, F, C = query.split()
    if F=='1':
      if mode==1:
        add_to_beginning.append(C)
      else:
        add_to_last.append(C)
    else:
      if mode==1:
        add_to_last.append(C)
      else:
        add_to_beginning.append(C)   

if mode==1:
  add_to_beginning.reverse()
  print("".join(add_to_beginning), end="")
  print(S, end="")
  print("".join(add_to_last))
else:
  add_to_last.reverse()
  print("".join(add_to_last), end="")
  print(S[::-1], end="")
  print("".join(add_to_beginning))


Measured memory_bytes: 17948
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
 
int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int H,W,K;
  cin >> H >> W >> K;
  vector<string> S(H);
  for(int i=0;i<H;i++)  cin >> S.at(i);
 
  int ans=0;
  for(int bitH=0;bitH<(1<<H);bitH++){
    for(int bitW=0;bitW<(1<<W);bitW++){
      int cnt=0;
      for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
          if(bitH&(1<<i)) continue;
          if(bitW&(1<<j)) continue;
          if(S.at(i).at(j)=='#')  cnt++;
        }
      }
      if(cnt==K)  ans++;
    }
  }
  cout << ans << endl;
 
  return 0;
}

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

using std::pair;
using std::vector;
using std::string;

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

#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)

template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }

const int oo = 0x3f3f3f3f;

string procStatus() {
    std::ifstream t("/proc/self/status");
    return string(std::istreambuf_iterator<char>(t), std::istreambuf_iterator<char>());
}

template <typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
    return x *= f;
}

const int N = 100000;

int n, cnt = 1;
char st[N + 5];

void addedge(int u, int v) {
    printf("%d %d\n", u, v);
}

void dfs(int u, int sz) {
    for(int i = sz-1; i >= 0; --i) if(st[i] == '1') {
        if(i) {
            addedge(u, ++ cnt);
            dfs(cnt, i);
        }
        for(int j = 1; j < sz - i; ++j) addedge(u, ++ cnt);
        return;
    }
}

int main() {
#ifdef Wearry
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif

    scanf("%s", st + 1);
    n = strlen(st + 1);
    if(st[1] == '0' || st[n-1] == '0' || st[n] == '1') return !puts("-1");
    for(int i = 1; i < n; ++i) if(st[i] != st[n - i]) return !puts("-1");

    dfs(1, n);

    return 0;
}


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

//const int INF = 1001001001;
const ll INF = 1000000000000000000;

int main() {
	int n, m;
	cin >> n >> m;

	vector<vector<int>> light(m);
	rep(i, m) {
		int k;
		cin >> k;
		rep(j,k) {
			int s;
			cin >> s; s--;
			light[i].push_back(s);
		}
	}
	vector<int> p(m);
	rep(i,m) cin >> p[i];
	int ans = 0;
	for (int bit = 0; bit < (1<<n); bit++) {
		bitset<10> bs(bit);
		//cout << bs << endl;
		bool lon = false;
		rep(i,m) {
			int on_cnt = 0;
			for (auto x : light[i]) {
				//cout << " " << x << " and " << bs[x];
				if (bs[x] == 1) on_cnt++;
			}
			//cout << endl;
			if ((on_cnt % 2) == p[i]) lon = true;
			else {
				lon = false;
				break;
			}
		}
		if (!lon) continue;
		ans++;
	}
	cout << ans << endl;
	return 0;
} 


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
    /*
    char S[4+1] = {0};
    cin >> S;
    //cout << S;

    char c12[2+1];
    c12[0] = S[0];
    c12[1] = S[1];
    c12[2] = '\0';
    int i12 = atoi(c12);

    char c34[2+1];
    c34[0] = S[3];
    c34[1] = S[4];
    c34[2] = '\0';
    int i34 = atoi(c34);
    */

    int S = 0;
    cin >> S;
    int i12 = S/100;
    int i34 = S%100;

    if (1 <= i12 && i12 <= 12) {
        if (1 <= i34 && i34 <= 12) {
            cout << "AMBIGUOUS" << "\n";
        } else {
            cout << "MMYY" << "\n";
        }
    } else {
        if (1 <= i34 && i34 <= 12) {
            cout << "YYMM" << "\n";
        } else {
            cout << "NA" << "\n";
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
using namespace std;
int main(int argc, char *argv[]) {
    int n;
    int mx=0;
    bool hit[26];
    char s[100];
    scanf("%d\n", &n);
    for (int i = 0; i < n; i++) {
        scanf("%c", &s[i]);
    }
    for (int i = 0; i < n - 1; i++) {
        memset(hit, 0, 26);
        int t=0;
        for (int j = 0; j <= i ; j++) {
            for (int k = i + 1; k < n; k++) {
                if ((s[k] == s[j]) && (hit[s[k]-'a']==false)) {
                    hit[s[k]-'a'] = true;
                    t++;
                    break;
                }
            }
        }
        if (t>mx){
            mx=t;
        }
    }
    printf("%d\n", mx);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;

int main() {
    
    int n; cin >> n;
    vector<pint> v; v.resize(n);
    for (int i=0; i<n; i++) cin >> v[i].first >> v[i].second;

    vector<int> s; for (int i=0; i<n; i++) s.emplace_back(i);

    double ans = 0;
    int counter = 0;
    do {
        for (int i=0; i<n-1; i++) {
            ans += sqrt(pow(v[s[i]].first - v[s[i+1]].first, 2) + pow(v[s[i]].second - v[s[i+1]].second, 2));
        }
        counter += 1;
    } while (next_permutation(s.begin(), s.end()));

    cout << setprecision(10) << (double)ans/(double)counter << "\n";
    
    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 P = pair<int,int>;
using ll = long long;
using namespace std;
int main() {
    int a[5];
    rep(i, 5){cin >> a[i];}
    rep(i, 5){
        if(a[i] == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3572
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int opt = 0;
        ArrayList<Integer> D = new ArrayList<>();
        for(int i=0;i<N;i++) D.add(sc.nextInt());
        for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) opt+=D.get(i)*D.get(j);
        System.out.println(opt);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<ctime>
#include<set>
#include<iomanip>
#define sqr(x) (x)*(x)
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
int n,m,i,j,a[15][15],c[15];
int main()
{
	fz1(i,3)
	{
		int x,y;
		cin>>x>>y;
		a[x][y]=a[y][x]=1;
	}
	fz1(i,4) c[i]=i;
	do
	{
		fz1(i,3) if (!a[c[i]][c[i+1]]) break;
		if (i==4){puts("YES");return 0;}
	}while (next_permutation(c+1,c+5));
	puts("NO");
	return 0;
}

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

int main(void){
    int a,b,n,sum,j;
    int count = 0;
    cin >> n >> a >> b;
    
    for(int i = 1;i < n+1;i++){
        for(sum = 0,j = i;j > 0;j /= 10){
            sum += j % 10;
        }
        if(a <= sum && sum <= b)count += i;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
int main()
{
    int n, k, t;
    cin >>n;
    if(n==0) cout<<0;
    else
    {
        vector <int> v;
        while(n != 0)
        {
            k = n % -2;
            n /= -2;
            if(k < 0)
            {
                k -= -2;
                n++;
            }
            v.push_back(k);
        }
        for(int i=v.size()-1; i>=0 ; i--)
            cout<<v[i];
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define lli long long int
# define pb push_back
# define pf pop_front()
# define loop(i,a,b) for(int i=a;i<b;i++)
# define loopl(i,a,b) for(lli i=a;i<b;i++)
# define lb lower_bound
# define ub upper_bound
# define INF 1000000000
# define mod 1000000007

using namespace std ;

int gcd(int a, int b)
{
    if (a == 0)   return b;
    if(b==0)      return a;
    if (a == b)   return a;
    if (a > b)    return gcd(a%b, b);
    return gcd(a, b%a);
}

lli pow(lli n)
{
	lli temp = n;
	lli count=0 ;
	while( temp%2 == 0)
	{
		temp/=2 ;
		count++;
	}
	return count;
}
int main()
{
   lli n;
   cin>>n;
   lli a[n];
   lli ans=0;
   loopl(i,0,n)
   {
   	cin>>a[i];
   	if(a[i]%2 == 0) ans+=pow(a[i]) ;
	 }  
	 cout<<ans<<endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h> 
using namespace std; 
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define scan(a,n) for (ll i = 0; i < n; ++i) cin >> a[i]
typedef long long int ll;
int main() 
{ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	ll d,t,s;
	cin>>d>>t>>s;
	if(t*s>=d)
		cout<<"Yes"<<"\n";
	else
		cout<<"No"<<"\n";
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n;
	cin >> n;
	int all = 1, odd = 1;
	rep(i, n) {
		all *= 3;
		int a; cin >> a;
		if (a % 2 == 0) odd *= 2;
	}
	cout << all - odd << endl;
	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    string s; cin >> s;
    int cnt = 0;
    rep(i,s.size()){
        if(s[i] == 'A') cnt++;
    }
    if(cnt == 3 || cnt == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
}

Measured memory_bytes: 3572
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    if(n == m){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define IREP(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define IMAX INT_MAX
#define IMIN INT_MIN
#define LMAX LLONG_MAX
#define LMIN LLONG_MIN
template<typename T> inline void chmin(T &a, T b){ if(a > b) a = b; }
template<typename T> inline void chmax(T &a, T b){ if(a < b) a = b; }
template<typename T> inline void xch(T &a, T &b){ T w = a; a = b; b = w; }


int main() {
    int N;
    cin >> N;
    REP(notc, N){
        string s1, s2;
        cin >> s1;
        cin >> s2;
        int len1 = s1.length() - 1, len2 = s2.length() - 1;
        int n[90];
        int length = 0;
        REP(i, 90){
            n[i] = 0;
        }
        REP(i, 82){
            int a = (len1 - i >= 0)?s1[len1 - i] - '0':0;
            int b = (len2 - i >= 0)?s2[len2 - i] - '0':0;
            n[i] += a + b;
            n[i + 1] += n[i] / 10;
            n[i] %= 10;
            if(n[i] != 0) length = i + 1;
        }
        if(length >= 81){
            cout << "overflow" << endl;
        }
        else if(length == 0){
            cout << 0 << endl;
        }
        else{
            IREP(i, length){
            cout << n[i];
            }
            cout << endl;
        }
        
    }
    return 0;
}



Measured memory_bytes: 3016
#include<cstdio>
#include<cstring>

#define INF 2147483647
#define Fast register
char BUF[16384],*S=BUF,*T=BUF;
inline char Getchar(){return(S==T)&&(T=(S=BUF)+fread(BUF,1,16384,stdin),S==T)?EOF:*S++;}
inline int Getint(){
	Fast int s=0;Fast char c;
	while(c=Getchar(),c<48||c>57);
	while(s=s*10+c-48,c=Getchar(),c>47&&c<58);
	return s;
}

struct Edge{
	int to,v;Edge*next;
	Edge(const int&T,const int&V,Edge*&N):to(T),v(V),next(N){}
}*Front[100001];
#define AddEdge(x,y,z) Front[x]=new Edge(y,z,Front[x])

int val[100001];
inline bool Fail(const int&now,const int&Fa){
	for(Fast Edge*o=Front[now];o!=NULL;o=o->next){
		if(o->to==Fa)continue;
		if(val[o->to]==INF){
			val[o->to]=val[now]+o->v;
			if(Fail(o->to,now))return true;
		}
		else if(val[o->to]!=val[now]+o->v)return true;
	}
	return false;
}

int main(){
	Fast int N=Getint(),M=Getint()+1;
	for(Fast int i=1;i<=N;++i)val[i]=INF;
	while(--M){
		Fast int L=Getint(),R=Getint(),D=Getint();
		AddEdge(L,R,D);AddEdge(R,L,-D);
	}
	for(Fast int i=1;i<=N;++i)if(val[i]==INF&&(val[i]=0,Fail(i,0)))return(puts("No"),0);
	return(puts("Yes"),0);
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
#define ROUNDUP(divisor,dividend) (divisor + (dividend - 1)) / dividend
int n,m;int a,b,am,bm; int temp1=0,temp2=999999;
int main(){
  cin >> n >> m;
  bool wa=false;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    temp1 = max(temp1,a);
    temp2 = min(temp2,b);
  }
  cout << (temp1 > temp2 ? 0 : (temp2 - temp1)+1) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

int main(){
  char a,b;
  cin >> a >> b;
  cout << (a==b ? 'H' : 'D') << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n;

  while(scanf("%d",&n)!=EOF){
    int a,b,c,d;
    int count=0;
    for (a=0;a<10;a++){
      for (b=0;b<10;b++){
	for (c=0;c<10;c++){
          for (d=0;d<10;d++){
            if ((a+b+c+d)==n){
              count+=1;
            }
          }
	}
      }
    }
    printf("%d\n",count);
  }


  return 0;
}

Measured memory_bytes: 596
from itertools import combinations

# 自分の答案に組み込んで見る
a,b = map(int,input().split())

S  = (a-1)*(a-2)//2
def solve(x,y,s):
    print(a+s-y-1)
    for i in range(1,a):print(1,1+i)
    c = s-b
    edges = list(combinations(range(2, a+1), 2))[:c]
    for i, j in edges:
        print(i, j)
# print(b,S)
if not 0<= b <= S:
    print(-1)
    exit()
else:
    solve(a,b,S)


Measured memory_bytes: 3992
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
        string S;
    cin >> S;
    set<char> st;
    for (int i = 0; i < 3; i++) st.insert(S[i]);
    cout << ((st.size() == 3) ? "Yes" : "No") << '\n';
}


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

int n;

int main()
{
	cin >> n;
	int t, a[n+1]={};
	for(int i = 2; i <= n; i++)
	{
		cin >> t;
		a[t]++;
	}
	
	for(int i = 1; i <= n; i++)	cout << a[i] << endl;
	
//	system("pause");
	return 0;
}

Measured memory_bytes: 4360
<?php
  fscanf(STDIN, "%i", $n);
  fscanf(STDIN, "%s", $s);
  $x = 0;
  $max = 0;
  for ($i = 0; $i < $n; $i++)
  {
    if ($s[$i] === 'I')
    {
      $x++;
    }
    else if ($s[$i] === 'D')
    {
      $x--;
    }
    $max = max([$max, $x]);
  }
  echo $max;
?>


Measured memory_bytes: 2936
import heapq
a, b = map(int,input().split())
l = list(map(int,input().split()))
for i in range(a):
    l[i] = -l[i]
heapq.heapify(l)

def cal(t,T):
    return -(-t//T)
for _ in range(b):
    heapq.heappush(l,cal(heapq.heappop(l),2))
s = 0
for x in l:
    s += -x
print(s)

Measured memory_bytes: 14180
#include <iostream>
#include <vector>

using namespace std;

int main() {
	vector<int> furui(10000001, 0);
	furui[0] = furui[1] = 1;
	for (int i = 2; i*i < 10000001; i++) {
		if (furui[i] == 0) {
			for (int j = 2; j <= 10000000/i; j++) {
				furui[i*j] = 1;
			}
		}
	}
	long long int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = n; i >= 0; i--) {
			if (furui[i] == 0) {
				if (furui[i-2] == 0) {
					if (furui[i-6] == 0) {
						if (furui[i-8] == 0) {
							cout << i << endl;
							break;
						} else {
							i -= 8;
						}
					} else {
						i -= 6;
					}
				} else {
					i -= 2;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 40176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <array>
#include <iomanip>
using namespace std;
long Nchoose2(long n){
    return n*(n-1)/2;
}
int main(){
    long n;
    cin >> n;
    int ans = 0;
    //vector<int> a(n);
    ans += 1000 * (n/500);
    n = n%500;
    ans += 5 * (n/5);
    cout << ans << endl;   
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4 6", "3 1 2 3", "2 4 2", "2 4 6", "1 6" ].parse.expand.solve == "YES" );
	assert( [ "4 4", "2 1 2", "2 1 2", "1 3", "2 4 3" ].parse.expand.solve == "NO" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto lss = new long[][ nm[ 0 ] ];
	foreach( ref ls; lss )
	{
		input.popFront;
		auto kls = input.front.split.to!( long[] );
		ls = kls[ 1 .. $ ];
	}
	return tuple( nm[ 1 ], lss );
}

auto solve( long m, long[][] lss )
{
	// 人と言語でグループを構成
	auto uft = UnionFindTree( lss.length + m );
	foreach( i, ls; lss )
	{
		foreach( l; ls )
		{
			uft.unite( i, lss.length - 1 + l );
		}
	}
	
	// 全員が同じグループに属しているか（＝コミュニケーションを取れるか）を判定
	foreach( i; 1L .. lss.length )
	{
		if( !uft.same( 0, i ) ) return "NO";
	}
	return "YES";
}

// UnionFind木
struct UnionFindTree
{
	private long[] ps;
	private long[] rs;
	
	public this( long n )
	{
		ps.length = n;
		ps[] = -1;
		rs.length = n;
	}
	
	public long root( long i )
	{
		if( ps[ i ] < 0 ) return i;
		else              return ps[ i ] = root( ps[ i ] );
	}
	
	public bool same( long i, long j )
	{
		return root( i ) == root( j );
	}
	
	public void unite( long i, long j )
	{
		i = root( i );
		j = root( j );
		if( i == j ) return;
		if( rs[ i ] < rs[ j ] )
		{
			ps[ j ] += ps[ i ];
			ps[ i ] = j;
		}
		else
		{
			ps[ i ] += ps[ j ];
			ps[ j ] = i;
			if( rs[ i ] == rs[ j ] ) rs[ i ]++;
		}
	}
}


Measured memory_bytes: 21372
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>


using namespace std;

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

    int ans =0;
    for(int i=1;i<=N;i++) {
        int cnt = 0;
        int d = i;
        while (d) {
            d /= 10;
            cnt++;
        }
        if (cnt % 2)ans++;
    }

    cout<< ans <<endl;
}





Measured memory_bytes: 256
n = int(input())
L = list(map(int, input().split()))
from itertools import combinations
ns=[i for i in range(n)]
ans=0
for i in combinations(ns,3):
    if L[i[0]]!=L[i[1]] and L[i[0]]!=L[i[2]] and L[i[1]]!=L[i[2]]:
        new=[L[i[0]],L[i[1]],L[i[2]]]
        new=sorted(new)
        if new[0]+new[1]>new[2]:
            ans+=1
        
print(ans)

Measured memory_bytes: 68360
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

#define rep(i,a,b) for(int i=int(a),nn=int(b);i<=nn;++i)
#define vep(i,a,b) for(int i=int(a),nn=int(b);i>=nn;--i)
#define xep(i,b) for(int i=0,nn=int(b);i<nn;++i)

const int N = 200100;
typedef long long ll;
const int inf = 1000000005;
ll as;
int ano, x[N], y[N] ;
int n, od[N];

template <typename tp> inline tp imn(tp a, tp b) { return a<b?a:b;}
template <typename tp> inline tp imx(tp a, tp b) { return a>b?a:b;}
inline bool cmp(int a, int b) {
  	return x[a] == x[b] ? y[a] < y[b] : x[a] < x[b];
}
int main() {
  	ios :: sync_with_stdio(false);
	cin.tie(0), cout.tie(0);

	cin >> n;
	int mx = 0, mn = inf;
	rep(i, 1, n) {
		cin >> x[i] >> y[i];
		if (x[i] > y[i]) swap(x[i], y[i]);
		mx = imx(y[i], mx), mn = imn(y[i], mn);
		od[i] = i;
	}
	sort(od+1, od+1+n, cmp);
	as = (ll) (mx-mn) * (x[od[n]] - x[od[1]]);
	ano = mx - x[od[1]];
	mx = x[od[n]], mn = inf;
	rep(i, 1, n-1) {
	  	mx = imx(mx, y[od[i]]);
		mn = imn(mn, y[od[i]]);
		as = imn(as, (ll)(mx-imn(mn, x[od[i+1]]))*ano);
	}
	return printf("%lld\n", as), 0;
}



Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main() {
  string weather;
  cin >> weather;
  if (weather == "Sunny") {
    cout << "Cloudy" << endl;
  }
  else if (weather == "Cloudy") {
    cout << "Rainy" << endl;
  }
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#![allow(unused)]

// ///////////////
// Fenwick Tree //
// ///////////////

struct FenwickTree {
    n: isize,
    value: Vec<usize>,
}

impl FenwickTree {
    fn new(n: usize) -> Self {
        Self {
            n: n as isize,
            value: vec![0; n],
        }
    }
    fn add(&mut self, pos: usize, value: usize) {
        let mut x = pos as isize;
        while x <= self.n {
            self.value[x as usize - 1] += value;
            x += x & -x;
        }
    }

    fn get(&self, pos: usize) -> usize {
        let mut sum = 0;
        let mut x = pos as isize;
        while x > 0 {
            sum += self.value[x as usize - 1];
            x -= x & -x;
        }
        sum
    }

    // 1-indexed, [l,r]
    fn sum(&self, l: usize, r: usize) -> usize {
        self.get(r) - self.get(l - 1)
    }
}

fn main() {
    use proconio::*;
    input! {
    n: usize,
    q: usize,
    a: [usize;n],
    b: [(usize,usize,usize);q],
    }

    let mut fwt = FenwickTree::new(n);
    for i in 0..n {
        fwt.add(i + 1, a[i]);
    }
    for (t, l, r) in b {
        let l = l + 1;
        match t {
            0 => fwt.add(l, r),
            1 => {
                println!("{}", fwt.sum(l, r));
            }
            _ => {}
        }
    }
}


Measured memory_bytes: 37108
#include <iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<bits/stdc++.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<string>
using namespace std;

const double PI  =3.141592653589793238463;
#define pb push_back
#define pf push_front
#define sz(v)  ((int)(v).size());
#define all(v) ((v).begin()),((v).end())
typedef unsigned long long ull;
typedef long long ll;

typedef vector<int> vi;
typedef pair<int,int> pi;
//2 7 3 4 9

void printVec(vi v1)
{
    for(int i=0; i<v1.size(); i++)
        cout<<v1[i]<<" ";
    cout<<endl;
}
int main()
{
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
string s;cin>>s;
string t;cin>>t;
ll ctr=0;
for(ll i=0;i<s.length();i++){
    if(s[i]!=t[i]){
        ctr++;
    }
}
cout<<ctr;
    return 0;

}


Measured memory_bytes: 3816
import sys
from statistics import *
from collections import *
from operator import itemgetter

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b = na()
s = int(str(a) + str(b))
ans = 'No'
for i in range(1, s):
    if i * i == s:
        ans = "Yes"
print(ans)

Measured memory_bytes: 5276
n = int(input())
r = range(1,101)
l = [0]*n

for x in r:
    for y in r:
        for z in r:
            t = x*x+y*y+z*z+y*z+z*x+x*y
            if t <= n:
                l[t-1] +=1
for i in l:
    print(i)

Measured memory_bytes: 9364
import sys
 
read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7
 
 
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]
 
    def group_count(self):
        return len(self.roots())
 
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
 
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
 
 
def main():
    N, M = map(int, readline().split())
    uf = UnionFind(N)
 
    for _ in range(M):
        a, b = map(int, readline().split())
        uf.union(a - 1, b - 1)
    print(uf.group_count() - 1)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 13056
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        var c = new int[] { 500, 100, 50, 10, 5, 1 };
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = Array.ConvertAll(line, int.Parse);
            if (a[0] == 0) break;
            var ans = getAns(c, a, a[0]);
            Console.WriteLine(ans);
        }
    }
    static int getAns(int[] c, int[] a, int p)
    {
        var ans = int.MaxValue;
        for (int i = p; i <= p + 500; i++)
        {
            var w1 = getPay(c, a, i);
            if (w1 != -1)
            {
                var w2 = getChange(c, i - p);
                ans = Min(ans, w1 + w2);
            }
        }
        return ans;
    }

    static int getPay(int[] c, int[] a, int t)
    {
        var ans = 0;
        var p = 6;
        foreach (var x in c)
        {
            var w = t / x;
            var w2 = Min(a[p--], w);
            ans += w2;
            t -= x * w2;
        }
        return t == 0 ? ans : -1;
    }
    static int getChange(int[] c, int a)
    {
        var ans = 0;
        foreach (var x in c)
        {
            var w = a / x;
            ans += w;
            a -= x * w;
        }
        return ans;
    }
}



Measured memory_bytes: 17928
#include<iostream>
#include<cstring>
using namespace std;
const int MaxN=200055;
char str[MaxN];
bool a[MaxN];
int pos[10],l[MaxN],r[MaxN],sum[MaxN];
int main()
{
	cin>>str+1;
	int n=strlen(str+1);
	for(int i=1;str[i];++i)
		if(str[i]=='R')
			a[i]=1;
	for(int i=1;i<=n;++i)
		l[i]=(str[i-1]=='L'?l[i-1]:i);
	for(int i=n;i>=1;--i)
		r[i]=(str[i+1]=='R'?r[i+1]:i);
	for(int i=1;i<=n;++i)
 	{
		if(str[i]=='L')sum[l[i]+((i-l[i])%2==0?0:-1)]++;
		else sum[r[i]+((r[i]-i)%2==0?0:1)]++;
	}
	for(int i=1;i<=n;++i)
		cout<<sum[i]<<" ";
	puts("");
	return 0;
}


Measured memory_bytes: 1792