akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(string N){
    int ret = 0;
    if (N.size() == 1) {
        std::cout << N[0] << std::endl;
        return;
    }
    bool flag = true;
    for (int i = 1; i < N.size(); i++) {
        if (N[i] != '9') {
            flag = false;
        }
    }
    if (flag) {
        ret++;
    }
    ret += N[0] - '1';
    for (int i = 1; i < N.size(); i++) {
        ret += 9;
    }
    std::cout <<  ret << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    string N;
    std::cin >> N;
    solve(N);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


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

int main() {
  int N, fx = 0;
  cin >> N;

  for (int i = 1; i <= 100000000; i *= 10) {
    fx += N % (i * 10) / i;
  }
  if (N % fx == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define MAXN  200005
using namespace std;
vector<ll>g[MAXN];
ll des;
bool dfs(ll node,ll dep,ll par){
    if(dep==2&&node==des)
        return 1;
    if(dep==2)
        return 0;
    bool ans=0;
    for(auto it=g[node].begin();it!=g[node].end();it++){
        if(*it!=par)
      ans|=dfs(*it,dep+1,node);
}
return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,m,a,b;
    cin>>n>>m;
    des=n;
    for(ll i=0;i<m;i++){
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    ll ans=dfs(1,0,-1);
    if(ans)
        cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";


    return 0;
}



Measured memory_bytes: 12776
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
using namespace std;
typedef long long li;

const int maxn = 2e5;

int main(void) {
  li A, B, C, K;
  scanf("%lld%lld%lld%lld", &A, &B, &C, &K);
  li ans = A - B;
  if (K & 1) {
    ans *= -1;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    int maxD = A[0] + (K-A[N-1]);
    rep(i, N-1) {
        maxD = max(maxD, A[i+1]-A[i]);
    }

    LL ans = K-maxD;



    cout << ans << endl;

    return 0;
}


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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

double pi = acos(-1.0);
double INF = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL n;
  cin>>n;
  double r, theta;
  cin >> r >> theta;
  vector<pii> xy;
  REP(i,n){
    LL x,y;
    cin >> x >>y;
    xy.push_back({x, y});
  }

  vector<vector<vector<bool>>> graph(n, vector < vector<bool>>(n, vector<bool>(n, false)));
  
  REP(i,n){
    REP(j,n){
      REP(k,n){
        if(i!=j&&j!=k&&k!=i){
          double bax = xy[i].first - xy[j].first;
          double bay = xy[i].second - xy[j].second;
          double bcx = xy[k].first - xy[j].first;
          double bcy = xy[k].second - xy[j].second;
          double babc = bax * bcx + bay * bcy;
          double ban = (bax * bax) + (bay * bay);
          double bcn = (bcx * bcx) + (bcy * bcy);
          double radian = acos(babc / (sqrt(ban * bcn)));
          double angle = radian * 180 / pi;
          if((180-angle)<=theta){
            graph[i][j][k] = true;
          }
        }
      }
    }
  }

  vector<vector<double>> length(n, vector<double>(n, INF));
  REP(i,n){
    REP(j,n){
      length[i][j] = 
      sqrt((xy[i].first - xy[j].first) * (xy[i].first - xy[j].first) + 
      (xy[i].second - xy[j].second) * (xy[i].second - xy[j].second));
    }
  }

  vector<vector<vector<double>>> dp(10001, vector<vector<double>>(n, vector<double>(n, INF)));
  
  REP(i,n){
    dp[0][i][0] = 0;
  }

  REP(i,10000){
    REP(j,n){
      REP(k,n){
        REP(l,n){
          if(graph[j][k][l]||
          (i==0&&k!=l)){
            dp[i + 1][k][l] = min(dp[i][j][k] + length[k][l], dp[i + 1][k][l]);
          }
        }
      }
    }
  }
  
  LL max = 0;
  REP(i,10001){
    REP(j,n){
      REP(k,n){
        if(dp[i][j][k]<=r){
          if(max<i){
            max = i;
          }
        }
      }
    }
  }

  cout << max << endl;
}



Measured memory_bytes: 42928
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int d = sc.nextInt();
        while (true) {
            if (d == 0)
                break;
            int n = sc.nextInt();
            if (n == 1) {
                System.out.println("#");
            } else {
                char[][] map = new char[n][n];
                for (int i = 0; i < n; i++) {
                    Arrays.fill(map[i], ' ');
                }
                int x = 0;
                int y = n - 1;
                int dx = 0;
                int dy = -1;
                int right = n - 1;
                int left = 0;
                int top = 0;
                int bottom = n - 1;
                while (true) {
                    if (map[y][x] == '#')
                        break;
                    int[] ddx = { 0, 1, 0, -1 };
                    int[] ddy = { 1, 0, -1, 0 };
                    int c = 0;
                    for (int i = 0; i < 4; i++) {
                        int nx = x + ddx[i];
                        int ny = y + ddy[i];
                        if (nx >= 0 && ny < n && ny >= 0 && nx < n
                                && map[ny][nx] == '#') {
                            c++;
                        }
                    }
                    if (c > 1)
                        break;
                    map[y][x] = '#';
                    int nx = x + dx;
                    int ny = y + dy;
                    if (ny < top) {
                        dy = 0;
                        dx = 1;
                        left += 2;
                        nx = x + dx;
                        ny = y + dy;
                    } else if (nx > right) {
                        dy = 1;
                        dx = 0;
                        top += 2;
                        nx = x + dx;
                        ny = y + dy;
                    } else if (ny > bottom) {
                        dx = -1;
                        dy = 0;
                        right -= 2;
                    } else if (nx < left) {
                        dx = 0;
                        dy = -1;
                        bottom -= 2;
                    }
                    x += dx;
                    y += dy;
                }
                for (int i = 0; i < n; i++) {
                    for (int j = 0; j < n; j++) {
                        System.out.print(map[i][j]);
                    }
                    System.out.println();
                }
            }
            d--;
            if(d!=0)System.out.println();
        }
    }
}

Measured memory_bytes: 12000
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


enum LEN = 300;
enum E = 30;

int[][] program;

void add(int i, int j, int k) {
  program ~= [0, i, j, k];
}
void cmp(int i, int j, int k) {
  program ~= [1, i, j, k];
}

void test(long a, long b) {
  auto xs = new long[LEN];
  xs[0] = a;
  xs[1] = b;
  foreach (line; program) {
    const op = line[0];
    const i = line[1];
    const j = line[2];
    const k = line[3];
    xs[i] = (op == 0) ? (xs[j] + xs[k]) : ((xs[j] < xs[k]) ? 1 : 0);
    // writeln(a, " ", b, "; ", xs);
  }
  assert(a * b == xs[2], format("%s * %s = %s", a, b, xs[2]));
}

void main() {
  enum A = 0, B = 1, ans = 2;
  enum zero = 3;
  enum one = 4;
  cmp(10, zero, A);
  cmp(11, zero, B);
  add(12, 10, 11);
  cmp(one, zero, 12);
  
  int[] makeTwo(int head, int ini) {
    auto two = iota(head, head + 2 * E).array;
    add(two[0], ini, zero);
    foreach (i; 1 .. 2 * E) {
      add(two[i], two[i - 1], two[i - 1]);
    }
    return two;
  }
  
  const two = makeTwo(100, one);
  
  enum sa = 5;
  enum sb = 6;
  add(sa, zero, zero);
  foreach_reverse (i; 0 .. E) {
    add(sb, zero, zero);
    foreach_reverse (j; 0 .. E) {
      // sa + 2^i <= A && sb + 2^j <= B
      add(20, sa, two[i]);
      add(21, sb, two[j]);
      add(22, A, one);
      add(23, B, one);
      cmp(24, 20, 22);
      cmp(25, 21, 23);
      add(26, 24, 25);
      cmp(26, one, 26);
      const twoFake = makeTwo(200, 26);
      add(ans, ans, twoFake[i + j]);
      add(sb, sb, twoFake[j]);
    }
    // sa + 2^i <= A
    {
      add(20, sa, two[i]);
      add(22, A, one);
      cmp(24, 20, 22);
      const twoFake = makeTwo(200, 24);
      add(sa, sa, twoFake[i]);
    }
  }
  
  writeln(program.length);
  foreach (line; program) {
    writefln("%s %s %s %s", "+<"[line[0]], line[2], line[3], line[1]);
  }
  
  debug {
    foreach (a; 0 .. 10 + 1) foreach (b; 0 .. 10 + 1) {
      test(a, b);
    }
    foreach (a; 10L^^9 - 10 .. 10L^^9 + 1) foreach (b; 10L^^9 - 10 .. 10L^^9 + 1) {
      test(a, b);
    }
  }
}


Measured memory_bytes: 7372
#!/usr/bin/env python3
import sys
import collections as cl


def II(): return int(sys.stdin.readline())


def MI(): return map(int, sys.stdin.readline().split())


def LI(): return list(map(int, sys.stdin.readline().split()))


def main():
    n, k = MI()

    amari = n % k
    print(min(amari, k - amari))


main()


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

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()


int main() {
  VI A(3);
  REP(i,3){
    cin >> A.at(i);
  }
  
  SORT(A);
  
  if(A.at(0)==A.at(1)) cout << A.at(2) << endl;
  else cout << A.at(0) << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
n,*z=[*$<].map{|i|i.split.map &:to_i}
p (1..1023).map{|b|eval (0...n[0]).map{|i|z[i+n[0]][eval (0..9).map{|k|b[k]&z[i][-k-1]}*?+]}*?+}.max


Measured memory_bytes: 2684
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

ll cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    ll h, w, n;
    cin >> h >> w >> n;

    map<pair<ll,ll>,ll> mp;

    rep(i, n){
        int a, b;
        cin >> a >> b;
        a--; b--;

        for(int j = 0; j < 3; j++){
            for(int k = 0; k < 3; k++){
                if(a - j < 0 || b - k < 0) continue;
                if(a - j >= h - 2 || b - k >= w - 2) continue;
                mp[{a - j, b - k}]++;
            }
        }
    }

    vector<ll> ans(10, 0);
    ll total = 0;
    for(auto &i : mp){
        //cout << i.first.first << " " << i.first.second << " " << i.second << endl;
        ans[i.second]++;
        total++;
    }

    ans[0] = (h - 2) * (w - 2) - total;

    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

bool L[200100];
char T[200100];
int N, Q;
string S;

bool solvel(int mid){
    if(mid < 0) return false;
    if(mid >= N) return true;

    int v = mid;
    for(int i = 0; i < Q; i++){
        char t = T[i];
        bool left = L[i];

        if(t == S[v]){
            if(left) v--;
            else v++;
            if(v < 0) return false;
        }
    }
    return true;
}

bool solver(int mid){
    if(mid < 0) return true;
    if(mid >= N) return false;

    int v = mid;
    for(int i = 0; i < Q; i++){
        char t = T[i];
        bool right = !L[i];

        if(t == S[v]){
            if(right) v++;
            else v--;
            if(v >= N) return false;
        }
    }
    return true;
}

int main(){
    cin >> N >> Q;
    cin >> S;
    REP(i,Q){
        char t, d;
        cin >> t >> d;
        T[i] = t;
        L[i] = d == 'L';
    }

    int right = N;
    int left = 0;
    while(right - left > 1){
        int mid = (right+left)/2;
        bool valid = solvel(mid);
        if(valid){
            right = mid;
        }
        else{
            left = mid;
        }
    }

    int lim_left = left;
    //cout << lim_left << endl;
   
    
    right = N;
    left = 0;
    while(right - left > 1){
        int mid = (right+left)/2;
        bool valid = solver(mid);
        if(valid){
            left = mid;
        }
        else{
            right = mid;
        }
    }

    int lim_right = right;

    int ans = N;
    ans -= min(N, (lim_left+1) + (N-lim_right));

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


Measured memory_bytes: 900
/*
	Created by Faisal Ahmed
*/

#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;

int temp[200010];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	int n;
	string a, b;
	
	cin >> n;
	cin >> a >> b;
	
	for(int i = 0; i < n; i++){
		cout << a[i] << b[i];
	}
	cout << endl;
	
	return 0;
} 

Measured memory_bytes: 256
h,w = map(int,input().split())
s = [0]*h
for i in range(h):
    s[i] = list(input())
ver = [[0 for j in range(w)] for i in range(h)]
hol = [[0 for j in range(w)] for i in range(h)]

for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            pass
        elif j >= 1 and hol[i][j-1] != 0:
            hol[i][j] = hol[i][j-1]
        else:
            for k in range(2000):
                if j+k+1 >= w:
                    break
                if s[i][j+k+1] == "#":
                    break
            hol[i][j] = k+1
            
for j in range(w):
    for i in range(h):
        if s[i][j] == "#":
            pass
        elif ver[i][j] == 0 and i >= 1 and ver[i-1][j] != 0:
            ver[i][j] = ver[i-1][j]
        else:
            for k in range(2000):
                if i+k+1 >= h:
                    break
                elif s[i+k+1][j] == "#":
                    break
            ver[i][j] = k+1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, hol[i][j] + ver[i][j] - 1)
print(ans)

Measured memory_bytes: 298340
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define FASTIO
#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

#ifdef FASTIO
#define scanf abacaba
#define printf abacaba
#endif

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

int cc[100];

int main() {
#ifdef FASTIO
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
#endif
	for (int i = 0; i < 4; ++i) {
		int x;
		cin >> x;
		++cc[x];
	}
	if (cc[1] && cc[9] && cc[7] && cc[4])
		cout << "YES\n";
	else
		cout << "NO\n";
	return 0;
}




Measured memory_bytes: 256
N = int(input())
res = N
for i in range(N+1):
    cc = 0
    t = i
    while t > 0:
        cc += t%6
        t //= 6
    t = N-i
    while t > 0:
        cc += t%9
        t //= 9
    if res > cc:
        res = cc
print(res)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

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

		String s = sc.nextLine();

		String[] days = new String[] { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT", };

		for (int i = 0; i < 7; i++) {
			if (s.equals(days[i])) {
				System.out.println(7 - i);
			}
		}
	}

}


Measured memory_bytes: 20948
import java.util.*

fun main() {
    d()
}

fun a() {
    val N = readLong()
    val otsuri = (1000 - N % 1000) % 1000
    println("${otsuri}")
}

fun b() {
    val N = readLong().toInt()
    val map = mutableMapOf<String, Long>()
    repeat(N) {
        val s = readLine()!!
        map[s] = map.getOrDefault(s, 0) + 1
    }
    listOf("AC", "WA", "TLE", "RE").forEach {
        println("$it x ${map.getOrDefault(it, 0)}")
    }
}

fun c() {
    val (H, W, K) = readLongList()
    val set = mutableSetOf<Pair<Int, Int>>()
    repeat(H.toInt()) { h ->
        readLine()!!.forEachIndexed { w, c ->
            if (c == '#') set.add(h to w)
        }
    }

    pairs((0b0 until (1 shl H.toInt()).toLong()), (0b0 until (1 shl W.toInt()).toLong())).count { bits ->
        set.count { it.first in bits.first.bitFilter(1) && it.second in bits.second.bitFilter(1) } == K.toInt()
    }.let { println(it) }
}

fun d() {
    val N = readLong().toInt()
    val A = readLongList().sortedDescending()
    val queue = LinkedList<Long>()
    var ans = 0L
    queue.add(A[0])
    (1 until N).forEach {
        ans += queue.remove()
        A[it].let {
            queue.add(it)
            queue.add(it)
        }
    }
    println(ans)
}

fun readLong() = readLine()!!.toLong()
fun readLongList() = readLine()!!.split(" ").map { it.toLong() }

fun Long.bitEach(action: (Int) -> Unit) { (0 until Long.SIZE_BITS).forEach { action(((this shr it) and 1).toInt()) } }
fun Long.bitFilter(bit: Int) = (0 until Long.SIZE_BITS).filter { ((this shr it) and 1) == 1L }

fun <T1, T2> pairs(first: Iterable<T1>, second: Iterable<T2>) = first.flatMap { t1 -> second.map { t2 -> t1 to t2 } }

fun Long.print() { println(this) }

Measured memory_bytes: 83380
#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using vvpi = vector<vpi>;
const ull MOD = 998244353;
#ifdef LOCAL
#include "../../pp.hpp"
#define debug pp::debug
#else
#define debug(args...)
#endif

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

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

    string ans;
    int i = n - 1;
    int j = m - 1;
    while (true) {
        if (i == 0) {
            if (dp[i][j] == 1) ans.push_back(s[i]);
            break;
        } else if (j == 0) {
            if (dp[i][j] == 1) ans.push_back(t[j]);
            break;
        } else if (dp[i-1][j] == dp[i][j]) {
            --i;
        } else if (dp[i][j-1] == dp[i][j]) {
            --j;
        } else if (dp[i-1][j-1] == dp[i][j]) {
            --i;
            --j;
        } else {
            ans.push_back(s[i]);
            --i;
            --j;
        }
    }
    debug("dp", dp);
    debug("len lcs", dp[n-1][m-1]);
    reverse(ans.begin(), ans.end());
    cout << ans << '\n';
}


Measured memory_bytes: 37632
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;



int main() {
	int Q;
	long long A, B;

	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> A >> B;

		if (A == B) {
			cout << 2 * A - 2 << "\n";
		}
		else {
			if (A < B) { long long swap;
			swap = A;
			A = B;
			B = swap;
			}
			long long smin = B;
			long long smax = A;
			while (smax - smin > 1) {
				long long smiddle = (smin + smax) / 2;
				if (smiddle* smiddle > A*B) {
					smax = smiddle;
				}
				else {
					smin = smiddle;
				}
			}
			if (smin * smin == A * B) {
				cout << 2 * smin - 3 << "\n";
			}
			else if (smin * (smin + 1) >= A * B) {
				cout << 2 * smin - 2 << "\n";
			}
			else {
				cout << 2 * smin - 1 << "\n";
			}

		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <cstdio>
#define INF 1LL<<60
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef long double ld;
using namespace std;

struct edge{int to, l;};
int n, m;
vector<edge> G[100000];
ll d[100000];

bool check(){
  REP(i, n) d[i] = (-1)*INF;
  REP(i, n){
    if(d[i] == (-1)*INF){
      d[i] = 0;
      queue<int> q;
      q.push(i);
      while(q.size()){
        int f = q.front();
        q.pop();
        for(edge e: G[f]){
          if(d[e.to] == (-1)*INF){
            d[e.to] = d[f] + e.l;
            q.push(e.to);
          }
          else if(d[e.to] != d[f] + e.l) return false;
        }
      }
    }
  }
  return true;
}

int main() {
  cin >> n >> m;
  REP(i, m){
    int a, b, c;
    cin >> a >> b >> c;
    G[a-1].pb({b-1, c});
    G[b-1].pb({a-1, (-1)*c});
  }
  if(check()) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 9728
n = int(input())
a,b=[],[]

for i in range(n):
    x,y = map(int,input().split())
    a.append(x)
    b.append(y)

a=list(reversed(a))
b=list(reversed(b))

ans=0
OK=0
for i in range(n):
    tmp=a[i]+OK
    if tmp<=b[i] and tmp!=0:
        ok=b[i]-tmp
    elif tmp==0:
        continue
    else:
        ok=-(-tmp//b[i])*b[i]-tmp
    OK=OK+ok

print(OK)

Measured memory_bytes: 17684
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;

#define int long long int
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define rep(i,a,b) for (int i = a; i < b; ++i)
#define IOS ios::sync_with_stdio(false); cin.tie(NULL);
#ifndef LOCAL
#define dbg(...) ;
#define endl '\n'
#endif

const int inf = 1e15;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;

int g[N];

int power(int x, int y) 
{ 
    int res = 1;
    x = x % MOD;
    while (y) {
        if(y & 1) res = res * x % MOD;
        y >>= 1;
        x = x * x % MOD;
    }
    return res; 
}

signed main(){
    IOS;
    int n, k;
    cin >> n >> k;
    g[k] = 1;
    for (int i = k - 1; i >= 1; i--) {
        g[i] = power(k/i, n);
        for (int j = 2 * i; j <= k; j += i) {
            g[i] = (g[i] - g[j] + MOD) % MOD;
        }
    }
    int ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += i * g[i] % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4400
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        long first = Long.parseLong(in.nextLine());
        int res = 0;
        for (long i = 2; i * i <= first; i++) {
            int counter = 1;
            int c = 2;
            for (int j = 1; first % i == 0; j++) {
                first /= i;
                if (counter == j) {
                    res++;
                    counter += c++;
                }
            }
        }
        System.out.println(first > 1 ? res + 1 : res);
    }
}


Measured memory_bytes: 35804
/*
 *Author - Bhanu Pratap
 */
#include <bits/stdc++.h>
#define endl '\n'
#define all(c) c.begin(), c.end()

using namespace std;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9 + 7;
const ld PI = 3.141592653589793;

void solve () {  
        int n;
        cin>>n;
        int a;
        double sum=0;
        for (int i=0; i<n; i++) {
            cin>>a;
            sum+=(1/(double)a);
        } 
        sum=1/sum;
        cout<<fixed<<setprecision(16)<<sum;
}
main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    
    solve();
    return 0;
    }


Measured memory_bytes: 256
s = int(input())
ans = [s]
bool = True
while bool==True:
	if ans[-1] % 2 == 0:
		tmp = int(ans[-1] / 2)
		ans.append(tmp)
	else:
		tmp = int((ans[-1]*3)+1)
		ans.append(tmp)
	num = []
	for index,a in enumerate(ans):
		if a in num:
			print(index+1)
			bool = False
		num.append(a)
	


Measured memory_bytes: 3060
# Editorial solution for question C

a,b,c,d,e,f = map(int,input().split())

waterCombinations = {0}
sugarCombinations = {0}

while True:
    copy = set(waterCombinations)
    for i in copy:
        m = i+a * 100
        n = i+b * 100
        if m <= f:
            waterCombinations.add(m)
        if n <= f:
            waterCombinations.add(n)
    if copy==waterCombinations:
        break

while True:
    copy = set(sugarCombinations)
    for i in copy:
        m = i+c
        n = i+d
        if m <= f:
            sugarCombinations.add(m)
        if n <= f:
            sugarCombinations.add(n)
    if copy==sugarCombinations:
        break


best = 0
bestWater = 1
bestSugar = 1
for i in waterCombinations:
    for j in sugarCombinations:
        maxSugarAllowed = e*(i/100)
        if i+j > 0:
            l = (100 * j) / (i + j)
            if best <= l and j <= maxSugarAllowed and i+j <= f:
                bestWater = i
                bestSugar = j
                best = l
print(bestWater + bestSugar, bestSugar)




Measured memory_bytes: 3540
n = gets.chomp.to_i
values = gets.chomp

count = 0
loop do
  w_pos = values.index('W')
  r_pos = values.rindex('R')
  
  if w_pos == nil || r_pos == nil
    break
  end

  if w_pos > r_pos
    break
  end

  values[w_pos] = 'R'
  values[r_pos] = 'W'
  count += 1
end

puts count

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

typedef long long ll;

using namespace std;
const int INF = 1e9 + 5;

int main()
{
	int n;
	cin >> n ;
	vector<int> dp(3);
	for(int day = 0 ; day < n ; day++)
	{
		vector<int> new_dp(3,0);
		vector<int> cost(3);
		for(int &c : cost)
		{
			cin >> c;
		}
		for(int i = 0 ; i < 3; i++)
		{
			for(int j = 0 ; j < 3 ;j++)
			{
				if (i != j)
					new_dp[j] = max(new_dp[j] , dp[i] + cost[j]);
			}
		}
		dp = new_dp;
	}
	cout << max(max(dp[0],dp[1]),dp[2]);
}


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

int main(){
  int a,b,c,d=0,i,array[1000000]={};
  cin>>a>>b>>c;
  for(i=0; ;i++){
    d+=a;
    if(d%b==c){
      cout<<"YES"<<endl;
      return 0;
    }
    array[i]=d%b;
    for(int j=0;j<i;j++){
      if(array[i]==array[j]&&i!=j){
        cout<<"NO"<<endl;
        return 0;
      }
    }
  }
}

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

string solve(string s, int K)
{
    for (auto& c : s)
    {
        if (c == 'a') continue;
        const auto needed = 'z'-c+1;
        if (K >= needed)
        {
            K -= needed;
            c = 'a';
        }
    }

    K %= 26;

    s.back() = static_cast<char>(s.back() + K);

    return s;
}

int main()
{
    string s; cin >> s;
    int K; cin >> K;
    cout << solve(move(s), K) << endl;
}


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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  string s;
  cin >> s;
  if (s == "SSS") {
    cout << 0 << endl;
  }
  else if (s == "RRS" || s == "SRR") {
    cout << 2 << endl;
  }
  else if (s == "RRR") {
    cout << 3 << endl;
  }
  else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 3592
n,a,b=gets.strip.split.map(&:to_i)

def calc_digit_sum n
    sum=0
    while n>0 do
    a=n%10
    sum+=a
    n/=10
    end
    sum
end

ans=(1..n).map{|i| [i,calc_digit_sum(i)]}.select{|i| a<=i[1]&&i[1]<=b}.inject(0){|sum,num| sum+=num[0]}


puts ans


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

int k;
long long sum = 0;

int gcd(int a, int b, int c)
{
    int lo = 1, hi = min(a, min(b, c));
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> k;
    for (int a = 1; a <= k; a++)
    {
        for (int b = 1; b <= k; b++)
        {
            for (int c = 1; c <= k; c++)
            {
                sum += (long long)__gcd(a, __gcd(b, c));
            }
        }
    }

    cout << sum;
    cin >> k;
}

Measured memory_bytes: 3628
#include<cstdio>
#include <iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pr;

ll n, k;
vector<Pr> p;

int main()
{
	cin >> n >> k;
	p.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> p[i].first >> p[i].second;
	}

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

	ll rank = 0;
	for (int i = 0; i < n; i++) {
		rank += p[i].second;
		if (rank >= k) {
			cout << p[i].first << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <numeric>

int main() {
        // まず縦横の判定をしてから、最後にナナメ判定
        // どれか1本でもビンゴが確認できたら、達成しているものとして終了する
        using namespace std;

        int l, a[3][3], n, s1, s2;

        for(int i=0; i<3; i++)
        {
                for(int j=0; j<3; j++)
                {
                        cin >> a[i][j];
                        //cout << a[i][j] << endl;
                }
        }

        cin >> n;

        while(cin>>l)
        {
                // 同じものがあったら、その数字を0にする
                for(int i=0; i<3; i++)
                {
                        for(int j=0; j<3; j++)
                        {
                                if (a[i][j] == l)
                                {
                                        a[i][j] = 0;
                                        continue;
                                }
                        }
                }
        }

        // 列の数字を足し算して0ならビンゴ
        for(int i=0; i<3; i++)
        {
                int s = a[i][0] + a[i][1] + a[i][2];
                if (s == 0)
                {
                        cout << "Yes";
                        return 0;
                }
        }
        for(int j=0; j<3; j++)
        {
                int s = a[0][j] + a[1][j] + a[2][j];
                if (s == 0)
                {
                        cout << "Yes";
                        return 0;
                }
        }

        s1 = a[0][0] + a[1][1] + a[2][2];
        s2 = a[2][0] + a[1][1] + a[0][2];

        if (s1 == 0 || s2 == 0)
        {
            cout << "Yes";
            return 0;
        }

        cout << "No";
        return 0;
        /*
           for (int i=0; i<n; i++)
           {
            cin >> b[i];
            cout << b[i] << endl;

           }
         */



        return 0;
}


Measured memory_bytes: 256
import collections


def solve(n, m, x, bookPrices, bookKnowledge):
    def go(i, achievedKnowledge):
        allHigherThanX = True

        for j in range(m):
            if achievedKnowledge[j] < x:
                allHigherThanX = False
                break

        if allHigherThanX:
            return 0

        if i >= n:
            return float("inf")

        newKnowledge = [achievedKnowledge[j] + bookKnowledge[i][j]
                        for j in range(m)]
        ans1 = bookPrices[i]

        return min(ans1 + go(i+1, newKnowledge), go(i+1, achievedKnowledge))

    ans = go(0, [0 for _ in range(m)])

    return -1 if ans == float("inf") else ans


[n, m, x] = list(map(int, input().strip().split()))

bookPrices = []
bookKnowledge = []

for i in range(n):
    arr = list(map(int, input().strip().split()))
    bookPrices.append(arr[0])
    bookKnowledge.append(arr[1:])


print(solve(n, m, x, bookPrices, bookKnowledge))


Measured memory_bytes: 70492
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long n, k;
  cin>>n>>k;
  if(k > n){
    long long ans = n;
    long long x = n;
    x = abs(x - k);
    if(x < ans)ans = x;
    x = abs(x - k);
    if(x < ans)ans = x;
    cout<<ans<<endl;
  }
  else{
    long long x = n % k;
    long long ans = n;
    x = abs(x - k);
    if(x < ans)ans = x;
    x = abs(x - k);
    if(x < ans)ans = x;
    cout<<ans<<endl;
  }
  return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  string S;
  cin >> S;
  for(int i=0;i<(int)S.size();i++){
    if(i==A){
      if(S[i]!='-'){
        cout << "No" << endl;
        return 0;
      }
    }
    else{
      if(!(S[i]-'0'>=0 && S[i]-'0'<=9)){
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 3576
#include <bits/stdc++.h>
typedef long long LL;
using namespace std;

bool prime_check(int x) {
  for (int i = 2; i * i <= x; i ++) {
    if (x % i == 0) return false;
  }
  return true;
}

int main() {
  int n; cin >> n;
  vector<int> a;
  for (int i = 2; i <= 55555; i ++) {
    if (i % 5 == 1) {
      if (prime_check(i)) a.push_back(i);
    }
  }

  for (int i = 0; i < n; i ++) {
    if (i) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[]args){
		
		//????????£????????????
		Scanner sc = new Scanner(System.in);
		
		//?????? 
		int S = sc.nextInt();
		int h = S / 3600; 
		
		//???
		int m = S % 3600 / 60;
		
		
		//?§?
		int s = S % 60;
		
		System.out.println(h + ":" + m + ":" + s);
	}
}

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

int main() {
  int64_t H;
  cin >> H;
  int p = floor(log2(H)) + 1;
  int64_t ans = pow(2, p) - 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
N, A, B = map(int, input().split())
lst = []
for _ in range(N):
    lst += [int(input())]

def check(T):
    t = 0
    for i in range(N):
        if lst[i] > B * T:
            t += max((lst[i]-B*T + (A-B-1))//(A-B), 0)
        else:
            pass
    return t <= T

la = -1
ua = 10 ** 9
ans = 10 ** 9
while ua - la > 1:
    mid = (la + ua)//2
    if check(mid):
        ans = min(ans, mid)
        ua = mid
    else:
        la = mid
print (ans)

Measured memory_bytes: 50904
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<bits/stdc++.h>
using namespace std;
#define rint register int
#define rep(i,l,r) for(rint i=l;i<=r;i++)
#define per(i,l,r) for(rint i=l;i>=r;i--)
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define fir first
#define sec second
#define mset(s,t) memset(s,t,sizeof(s))
template<typename T1,typename T2>void ckmin(T1 &a,T2 b){if(a>b)a=b;}
template<typename T1,typename T2>void ckmax(T1 &a,T2 b){if(a<b)a=b;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
int read(){
  int x=0,f=0;
  char ch=getchar();
  while(!isdigit(ch))f|=ch=='-',ch=getchar();
  while(isdigit(ch))x=10*x+ch-'0',ch=getchar();
  return f?-x:x;
}
int main(){
  ll a,b;
  ll c,d;
  cin>>a>>b;
  cin>>c>>d;
  cout<<max(max(a*c,a*d),max(b*c,b*d))<<'\n';
}

Measured memory_bytes: 3632
//Let's play :)
#include<bits/stdc++.h>
using namespace std;

#define tarzan ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int long long 

int rr[] = {0, 1, 1, 1, 0, -1, -1, -1};
int cc[] = {1, 1, 0, -1, -1, -1, 0, 1};

const int mod = 1e9 + 7;
const int N = 300050;

signed main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    tarzan;
    int test = 1;
    //cin >> test;a
    while(test--) {
        int n;
        cin >> n;
        long double x = 1.0 * n / 3;
        long double ans = x * x * x;
        cout << fixed << setprecision(10) << ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void call(int);

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

	return 0;
}

void call(int n)
{
	int i,x;

	for (i = 1; i <= n; i++)
	{
		x = i;
		if (x % 3 == 0)
			cout << " " << i;
		else if (x % 10 == 3)
			cout << " " << i;
		else
			while (1)
			{
			x /= 10;

			if (x % 10 == 3)
			{
				cout << " " << i;
				break;

			}
			else if (x < 1)
				break;

			}
	}
	cout << endl;
}

Measured memory_bytes: 1160
//code by lynmisakura.wish to be accepted
/****************************/
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int>> vpi;
 
const long long Mod = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { int ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 
vector<vector<int>> G(100010,vector<int>(0));
int visit[100010];
void dfs(int n){
	visit[n] = 1;
	for(int i = 0;i < G[n].size();i++){
		if(visit[G[n][i]] == 0) dfs(G[n][i]);
	}
}
int main(void){
	int n,m;cin >> n >> m;
	for(int i = 0;i < m;i++){
		int x,y,z;cin >> x >> y >> z;
		G[--x].pb(--y);
		G[y].pb(x);
	}
	int ans = 0;
	for(int i = 0;i < n;i++){
		if(visit[i] == 0){
			ans++;
			dfs(i);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 9216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

vector<ll> bitconversion(ll i, ll n, ll N){
    ll x = 1;
    rep(j,N){
        x *= n;
    }
    vector<ll> vec(N);
    rep(j,N){
        x /= n;
        vec[j] = i / x;
        i -= x * vec[j];
    }
    return vec;
}

int main(){
    ll N;
    cin >> N;
    string X;
    cin >> X;
    vector<ll> popcount(200004,0);
    for (ll i = 1; i <= 200003; i++){
        vector<ll> binary = bitconversion(i, 2, 20);
        ll count = 0;
        rep(j,20){
            if (binary[j] == 1) count++;
        }
        popcount[i] = count;
    }
    vector<ll> popcount_time(200004,0);
    popcount_time[1] = 1;
    popcount_time[2] = 1;
    popcount_time[3] = 2;
    popcount_time[4] = 1;
    popcount_time[5] = 2;
    popcount_time[6] = 1;
    popcount_time[7] = 2;
    popcount_time[8] = 1;
    popcount_time[9] = 2;
    popcount_time[10] = 1;
    popcount_time[11] = 2;
    popcount_time[12] = 1;
    popcount_time[13] = 2;
    popcount_time[14] = 2;
    popcount_time[15] = 3;
    popcount_time[16] = 1;
    popcount_time[17] = 2;
    popcount_time[18] = 1;
    popcount_time[19] = 2;
    popcount_time[20] = 1;
    for (ll i = 21; i <= 200003; i++){
        popcount_time[i] = (popcount_time[i % popcount[i]]) + 1;
    }
    ll cnt = 0;
    rep(i,N){
        if (X[i] == '1') cnt++;
    }
    ll cnt_minus = cnt - 1;
    ll cnt_plus = cnt + 1;
    if (cnt_minus == 0) cnt_minus = 2;
    vector<ll> bit_minus(N,0);
    vector<ll> bit_plus(N,0);
    ll num_minus = 1;
    rep(i,N){
        bit_minus[N - i - 1] = num_minus % cnt_minus;
        num_minus = (num_minus * 2) % cnt_minus;
    }
    ll num_minus_all = 0;
    rep(i,N){
        if (X[i] == '1') num_minus_all = (num_minus_all + bit_minus[i]) % cnt_minus;
    }
    ll num_plus = 1;
    rep(i,N){
        bit_plus[N - 1 - i] = num_plus % cnt_plus;
        num_plus = (num_plus * 2) % cnt_plus;
    }
    ll num_plus_all = 0;
    rep(i,N){
        if (X[i] == '1') num_plus_all = (num_plus_all + bit_plus[i]) % cnt_plus;
    }
    /*rep(i,N){
        if (X[i] == '1') cout << (num_minus_all + cnt_minus - bit_minus[i]) % cnt_minus << endl;
        else cout << (num_plus_all + cnt_plus + bit_plus[i]) % cnt_plus << endl;
    }*/
    rep(i,N){
        if (X[i] == '1'){
            if (cnt_plus == 2) cout << 0 << endl;
            else cout << popcount_time[(num_minus_all + cnt_minus * 1000000 - bit_minus[i]) % cnt_minus] + 1 << endl;
        }
        else{
            cout << popcount_time[(num_plus_all + cnt_plus + bit_plus[i]) % cnt_plus] + 1 << endl;
        }
    }
}

Measured memory_bytes: 9648
import java.util.*;

public class Main{
	public static void main(String args[]){
		
		Scanner ob = new Scanner(System.in);
		int[] nums = new int[5];
		int C = 0;

		for(int i = 0; i < 5; i++){
			nums[i] = ob.nextInt();
		}

		for(int j = 0; j < 5; j++){
			if(nums[j] == 0){
				C = j + 1;
				break;
			}
		}

		System.out.println(C);
	}
}


Measured memory_bytes: 35712
n = int(input())
a = list(map(int,input().split()))
m = 10**9+1
ans = 0
cnt = 0
flag = 0
for i in range(n):
  if a[i] < 0:
    cnt += 1
  elif a[i] == 0:
    flag = 1
  ans += abs(a[i])
  m = min(m,abs(a[i]))
if cnt % 2 == 0 or flag:
  print(ans)
else:
  print(ans-2*m)

Measured memory_bytes: 14412
#include <iostream>
using namespace std;
int main()
{
  string s;
 int x,y,sum=0;
  cin>>s;
x=s.find("A");
y=s.rfind("Z");
for(int i=x;i<=y;i++)
{
	sum++;
}
cout<<sum;
 return 0;
}

Measured memory_bytes: 832