akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
#include <atcoder/fenwicktree>
typedef long long ll;
using namespace std;
using namespace atcoder;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    fenwick_tree<ll> fw(n);
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        fw.add(i, a);
    }
    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;
        if (t == 0) {
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        }
        else {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 8236
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <complex>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL-1
double EPS=1e-9;
using namespace std;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef complex<double> P;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
set<int> nums;
int main(){
	double N;
	cin>>N;
	while(1){
		if(N==0)break;
		double hoge=(-1.0+sqrt(1.0+8.0*N))/2.0;
		int x=hoge;
		double y=x;
		if(y<hoge)y++;
		cout<<y<<endl;
		N-=y;
	}
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import           Control.Monad         (replicateM)
import qualified Data.ByteString.Char8 as BS
import           Data.List             (transpose)
import           Data.Maybe            (fromJust)

main :: IO ()
main = do
  css <- replicateM 3 getIntsLn
  putStrLn $ if solve css then "Yes" else "No"

solve :: [[Int]] -> Bool
solve css = css == [[a1 + b1, a1 + b2, a1 + b3]
                   ,[a2 + b1, a2 + b2, a2 + b3]
                   ,[a3 + b1, a3 + b2, a3 + b3]] where
  a1 = 0
  a2 = c21 - c11
  a3 = c31 - c11
  b1 = c11
  b2 = c12
  b3 = c13
  [c11, c12, c13] = css !! 0
  [_, c21, c31] = transpose css !! 0

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

getIntsLn :: IO [Int]
getIntsLn = map readInt . BS.words <$> BS.getLine


Measured memory_bytes: 380
#include<set>
#include<map>
#include<list>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<complex>
#include<sstream>
#include<iostream>
#include<fstream>
#include<algorithm>
#include<numeric>
#include<utility>
#include<functional>
#include<stdio.h>
#include<assert.h>
#include<memory.h>
#include<bitset>
using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define sz(v)				((int)((v).size()))
#define clr(v, d)			memset(v, d, sizeof(v))
#define rep(i, v)		for(int i=0;i<sz(v);++i)
#define lp(i, n)		for(int i=0;i<(int)(n);++i)
#define lpi(i, j, n)	for(int i=(j);i<(int)(n);++i)
#define lpd(i, j, n)	for(int i=(j);i>=(int)(n);--i)

typedef long long         ll;
const ll OO = 1e8;

const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}

#define pb					push_back
#define MP					make_pair
#define P(x)				cout<<#x<<" = { "<<x<<" }\n"
#define ll long long
#define MOD 1000000007
typedef long double   	  ld;
typedef vector<int>       vi;
typedef vector<double>    vd;
typedef vector< vi >      vvi;
typedef vector< vd >      vvd;
typedef vector<string>    vs;

int main(){
    ll n,k;
    cin >> n >> k;
    ll arr[n];
    lp(i,n)cin >> arr[i];
    //sort(arr,arr+n);
    ll res1[n],res2[n];
    memset(res1,0,sizeof(res1));
    memset(res2,0,sizeof(res2));
    for(int i = 0;i<n;i++){
        int num = arr[i],counter = 0;
        for(int j = i;j<n;j++)
            if(arr[j] < num)counter++;
        res1[i] = counter;
        //cout << counter<<endl;
    }
    for(int i = n-1;i>=0;i--){
        int num = arr[i],counter = 0;
        for(int j = i;j>=0;j--)
            if(arr[j] < num)counter++;
        res2[i] = counter;
        //cout << counter<<endl;
    }
    /*for(int i = 0;i<n;i++)
        cout << res2[i] << " ";
    cout << endl;*/
    ll sum = 0;
    for(int i = 0;i<n;i++){
        ll leftP  = (res1[i] % MOD ) * ((((k+1)*k)/2)%MOD);
        leftP = leftP%MOD;
        ll rightP = (res2[i] % MOD ) * ((((k-1)*k)/2)%MOD);
        rightP = rightP%MOD;
        sum += (leftP + rightP)%MOD;
        sum = sum%MOD;
    }
    cout << sum;
}

/*
(10 9 8 7 6 5 4 3 2 1)
 9  8 7 6 5 4 3 2 1 0
 0  0 0 0 0 0 0 0 0 0

 1 2 1 2
*/


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

int main(){
    int n,m;
    cin >> n >> m;
    int c[100]={0};
    pair<int,int> a[100];
    for(int i=0;i<m;i++){
        cin >> a[i].first >> a[i].second;
    }
    for(int i=0;i<m;i++){
        for(int j=1;j<=n;j++){
            if(a[i].first==j || a[i].second==j)c[j]++;
        }
    }
    for(int i=1;i<=n;i++){
        cout << c[i] << endl;
    }
}

Measured memory_bytes: 256
open Printf open Scanf
open Array

let split2 s t =
  let ls,lt = String.(length s,length t) in
  if ls<lt then [s]
  else if ls=lt then (
    if s=t then ["";""] else [s]
  ) else (
    let res = Str.split (Str.regexp_string t) s in
    let res = if String.sub s 0 lt = t then ""::res else res in
    let res = if String.sub s (ls-lt) lt = t then
      List.rev @@ ""::List.rev res else res in
    res
  )

let count_substr s t =
  List.length (split2 s t) - 1

let () = scanf " %d" @@ fun n ->
  let arr = init n (fun _ -> scanf " %s" @@ fun s -> s)
  in
  let kba,kbx,kxa,kab = ref 0,ref 0,ref 0,ref 0 in
  iter (fun s ->
    let bx = s.[0] = 'B' in
    let xa = s.[String.length s-1] = 'A' in
    let ba = bx && xa in
    if ba then incr kba
    else if bx then incr kbx
    else if xa then incr kxa;
    kab := !kab + count_substr s "AB"
  ) arr;
  let kba,kbx,kxa,kab = !kba,!kbx,!kxa,!kab in
  print_int @@ kab +
    if kba >= 1 then (
      let pair_ba = kba - 1 in
      let add,kbx =
        if kbx > 0 then 1,kbx-1 else 0,kbx in
      let add,kxa =
        if kxa > 0 then add+1,kxa-1 else add,kxa in
      pair_ba + add + min kbx kxa
    ) else
      min kbx kxa





Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;

int main(){
  int map[400][400] = {0};
  REP(i,400){
    REP(j,400){
      map[i][j] = -1;
    }
  }
  int N;
  while(cin >> N,N){
    REP(i,400){
    REP(j,400){
      map[i][j] = -1;
    }
  }
    map[200][200] = 0;
    int t = 0;
    REP(k,N-1){
      int n,d;
      cin >> n >> d;
      int f;
      t++;
      
    REP(i,400){
      REP(j,400){
	f = 0;
	if(map[i][j] == n){
	  //cout << i << " " << j << endl;
	  if(d == 0){
	    
	    map[i][j-1] = t;
	    //cout << map[i][j-1] << endl;
	  }
	  else if(d == 1)
	    map[i+1][j] = t;
	  else if(d == 2)
	    map[i][j+1] = t;
	  else{
	    map[i-1][j] = t;
	    //cout << map[i-1][j] << endl;
	  }
	  
	  /*f = 1;
	    break;*/
	}
      }
      /*if(f == 1)
	break;*/
    }
    
    }
    int u,d,l,r;
    REP(i,400){
      REP(j,400){
	if(map[j][i] != -1)
	  r = i;
	
      }
    }
    //cout << map[199][200] << endl;
    int f = 0;
    REP(i,400){
      REP(j,400){
	if(map[j][i] != -1){
	  l = i;
	  f = 1;
	  break;
	}      
	
      }
      if(f == 1)
	break;
    }
    f = 0;
    REP(i,400){
      REP(j,400){
	if(map[i][j] != -1){
	  u = i;
	  f = 1;
	  break;
	}      
      
      }
      if(f == 1)
	break;
    }
    REP(i,400){
      REP(j,400){
	if(map[i][j] != -1)
	  d = i;
      
      }
    }
    //cout << l << " " << r << " " << u << " " << d << endl; 
    cout << r-l+1 << " " << d-u+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define acc(v) accumulate(v.begin(), v.end(), 0)

using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
	ll n, a, b;
	cin >> n >> a >> b;
	cout << n / (a + b) * a + (n % (a + b) > a ? a : n % (a + b)) << endl;
}


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

int main(void){
  int H,W;
  cin >> H >> W;
  char a[H][W]={};
  int h[H]={},w[W]={};
  for(int i=0;i<H;i++){
    cin >> a[i];
    for(int j=0;j<W;j++){
      h[i]+=(a[i][j]=='#');
    }
  }
  for(int j=0;j<W;j++){
    for(int i=0;i<H;i++){
      w[j]+=(a[i][j]=='#');
    }
  }
  int c=0;
  for(int i=0;i<H;i++){
    if(h[i]==0){
      c++;
      continue;
    }
    for(int j=0;j<W;j++){
      if(w[j]==0){
        continue;
      }
      cout << a[i][j];
    }
    cout << endl;
  }
  if(c==H)
    cout <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int tall[10];
    int max[3];
    int i = 0;
    
    while (i<10) {
        scanf("%d",&tall[i]);
        //printf("%d\n",tall[i]);
        
        if (max[0] < tall[i]) {
            max[2] = max[1];
            max[1] = max[0];
            max[0] = tall[i];
        } else if (max[1] < tall[i]) {
            max[2] = max[1];
            max[1] = tall[i];
        } else if (max[2] < tall[i]) {
            max[2] = tall[i]; 
        }
        //printf("j:%d\n",j);
        i++;
        }

    printf("%d\n%d\n%d\n",max[0],max[1],max[2]);
    
    return 0;
}

Measured memory_bytes: 600
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.bigint, std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

void chmin(T)(ref T x, T y) { x = min(x, y); } void chmax(T)(ref T x, T y) { x = max(x, y); }
bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
T lcm(T)(T x, T y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998_244_353;
//long mod = 1_000_003;
void moda(T)(ref T x, T y) { x = (x + y) % mod; }
void mods(T)(ref T x, T y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(T)(ref T x, T y) { x = (x * y) % mod; }
void modpow(T)(ref T x, T y) { if (!y) { x = 1; return; } auto t = x; x.modpow(y>>1); x.modm(x); if (y&1) x.modm(t); }
void modd(T)(ref T x, T y) { y.modpow(mod - 2); x.modm(y); }

void main()
{
	auto H = RD;
	auto W = RD;
	auto K = RD;
	auto c = new long[][](H, W);
	foreach (i; 0..H)
	{
		auto s = RD!string;
		foreach (j; 0..W)
		{
			if (s[j] == '#')
				c[i][j] = 1;
		}
	}

	long ans;
	foreach (i; 0..2^^H)
	{
		foreach (j; 0..2^^W)
		{
			long cnt;
			foreach (ii; 0..H)
			{
				auto bit1 = 1L << ii;
				if (i & bit1) continue;
				foreach (jj; 0..W)
				{
					auto bit2 = 1L << jj;
					if (j & bit2) continue;
					cnt += c[ii][jj];
				}
			}
			if (cnt == K)
				++ans;
		}
	}

	writeln(ans);
	stdout.flush;
	debug readln;
}

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

#define LL long long
#define Dl double
#define Pb push_back
#define Mp make_pair

using namespace std;

typedef vector<LL> Vl;
typedef pair<LL, LL> Pll;
typedef vector<Pll> Vpl;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
#define X first
#define Y second

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

    string s;
    cin >> s;
    K--;

    for(LL i = 0; i < N; i++){
        if(i == K)
            cout << (char)(s[i] + 32);
        else
            cout << s[i];
    }
    cout << '\n';
    return 0;
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC099
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();
            while (true)
            {
                string line = Console.ReadLine();
                if (line == null) break;
                list.Add(line);
            }
            var u = list[0].ToCharArray();
            var d = list[1].ToCharArray();
            
            List<char> ans = new List<char>();
            int count = 0;
            while (true)
            {
                if (u.Count()>count)
                {
                    ans.Add(u[count]);
                }

                if (d.Count() > count)
                {
                    ans.Add(d[count]);
                }
                
                count++;
                if (u.Count()==count)
                {
                    break;
                }
            }
            string s="";
            foreach (var item in ans)
	        {
		        s=s+=item;
	        }
            Console.WriteLine(s);
        }

    }
}


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

int main()
{
  string s;
  int ret = 0;

  cin >> s;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '+')
      ret++;
    else
      ret--;
  }

  cout << ret << '\n';

  return 0;
}


Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <climits>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A;
    cin >> A;
    long long N = A.size();
    map<char, long long> mp;
    for(int i=0; i<26; i++) mp['a'+i] = 0;
    for(int i=0; i<N; i++) mp[A[i]]++;

    long long ans = (N*(N-1))/2;
    for(int i=0; i<26; i++){
        long long tmp = mp['a'+i];
        if(tmp <= 1) continue;
        ans -= (tmp*(tmp-1))/2;
    }
    ans++;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 720
#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 reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int W, H;
  cin >> W >> H;
  pqasc<int> p, q;
  int w = W + 1, h = H + 1;
  rep(i, W) {
    int x;
    cin >> x;
    p.emplace(x);
  }
  rep(i, H) {
    int x;
    cin >> x;
    q.emplace(x);
  }
  i64 ans = 0;
  while (p.size() || q.size()) {
    if (!p.size()) {
      int x = q.top(); q.pop();
      ans += (i64) x * w;
      continue;
    } else if (!q.size()) {
      int x = p.top(); p.pop();
      ans += (i64) x * h;
      continue;
    }
    if (p.top() <= q.top()) {
      int x = p.top(); p.pop();
      ans += (i64) x * h;
      w--;
    } else {
      int x = q.top(); q.pop();
      ans += (i64) x * w;
      h--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1400
from functools import reduce

n, a, b = list(map(int, input().split()))

s = 0
for i in range(n + 1):
    v = 0
    n = i
    while n > 0:
        v += n % 10
        n //= 10
    if a <= v <= b:
        s += i

print(s)


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<cstdlib>

int main(){
    int n, q;
    std::cin >> n;
    int* S = new int[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &S[i]);
    }
    std::cin >> q;
    int* T = new int[q];
    for(int i = 0; i < q; i++){
        scanf("%d", &T[i]);
    }

    int cnt = 0;
    for(int i = 0; i < q; i++){
        int head = 0;
        int tail = n - 1;
        int j = (head + tail)/2;
        while(1){
            if(S[j] == T[i]){
                cnt++;
                break;
            }else if(tail - head == 1){
                if(S[head] == T[i] || S[tail] == T[i]){
                    cnt++;
                }
                break;
            }else if(S[j] > T[i]){
                tail = j;
                j = (head + tail)/2;
            }else if(S[j] < T[i]){
                head = j;
                j = (head + tail)/2;
            }
        }
    }

    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 3680
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

using G = vector<vector<int>>;

template <class Tidx, class Tdist>
void Dijkstra(const Tidx org, const G& g, vector<Tdist>& d);

int n, m;
G g;
Vl d;
const ll INF = linf;
int start, goal;

void init()
{
	cin >> n >> m;
	n *= 3;
	g.resize(n);

	REP(_i, m)
	{
		int a, b;
		cin >> a >> b;
		--a; --b;
		a *= 3;
		b *= 3;

		g[a    ].PB(b + 1);
		g[a + 1].PB(b + 2);
		g[a + 2].PB(b);
	}

	cin >> start >> goal;
	--start; --goal;
	start *= 3;
	goal *= 3;
}

int main()
{
	init();
	Dijkstra(start, g, d);

	if (d[goal] == INF)
		cout << -1 << endl;
	else
		cout << d[goal] / 3 << endl;
}

template <class Tidx, class Tdist>
void Dijkstra(const Tidx org, const G& g, vector<Tdist>& d)
{
	using pli = pair<Tdist, Tidx>;

	vector<bool> done(n + 1, false);
	d.assign(n + 1, INF);
	d[org] = 0;

	priority_queue<pli, vector<pli>, greater<pli>> que;
	que.push(MP((Tdist)0, org));

	while (!que.empty())
	{
		Tdist c = que.top().first;
		Tidx v = que.top().second;
		que.pop();
		done[v] = true;

		for (Tidx u : g[v])
			if (!done[u] && chmin(d[u], c + 1))
				que.push(MP(d[u], u));
	}
}

Measured memory_bytes: 19072
H,W=map(int,input().split())
r=H if W%3 else 0
for i in range(1,H):
  l=[i*W, (H-i)*(W//2), (H-i)*(W-W//2)]
  m=[i*W,((H-i)//2)*W,(H-i-(H-i)//2)*W]
  r=min([r,max(l)-min(l),max(m)-min(m)])
for i in range(1,W):
  l=[i*H, (W-i)*(H//2), (W-i)*(H-H//2)]
  m=[i*H,((W-i)//2)*H,(W-i-(W-i)//2)*H]
  r=min([r,max(l)-min(l),max(m)-min(m)])
print(r)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  ll w,h,n;
  cin >> w>> h >> n;
  vector<ll> x(n),y(n),a(n);
  ll u=h,d=0,l=0,r=w;
  rep(i,n){
    cin >> x.at(i) >> y.at(i) >> a.at(i);
  }
  rep(i,n){
    if(a.at(i)==1){
      l=max(l,x.at(i));
    }else if(a.at(i)==2){
      r=min(r,x.at(i));
    }else if(a.at(i)==3){
      d=max(d,y.at(i));
    }else{
      u=min(u,y.at(i));
    }
  }
  if(r-l>0 && u-d>0){
    cout << (r-l)*(u-d);
  }else{
    cout << 0;
  }
}
      
  

Measured memory_bytes: 3628
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.util.function.DoubleToLongFunction;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		int[] ABC = {sc.nextInt(), sc.nextInt(), sc.nextInt()};
		Arrays.sort(ABC);
		if(ABC[0] == 5 && ABC[1] == 5 && ABC[2] == 7) System.out.println("YES");
		else System.out.println("NO");
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

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

int kj(int m) {
  if(m == 0) return 0;
  else {
    int sum = 1;
    for(int i = 1;i <= m;i++) sum *= i;
    return sum;
  }
}
int nc(int n) {
  int p, s, x = 0;
  vector<int> v(n, 1);
  for(int i = 0;i < n;i++) {
    cin >> p;
    v[p-1] = 0;
    s = 0;
    for(int j = 0;j < p;j++) s += v[j];
    x += s * kj(n - i - 1);
  }
  return x;
}

int main() {
  int n;
  cin >> n;
  int a = nc(n), b = nc(n);
  cout << abs(a - b) << endl;
}

Measured memory_bytes: 3628
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	string s, t;
	cin >> s >> t;
	int ans = INF;
	for(int i = 0; i <= s.size() - t.size(); i++) {
		int res = 0;
		for(int j = 0; j < t.size(); j++) {
			res += (t[j] != s[i + j]);
		}
		ans = min(ans, res);
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 3656
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    int n, x, y; cin >> n >> x >> y; x--, y--;
    vector<vector<int>> G(n);
    rep(i, n-1){
        G[i].push_back(i+1);
        G[i+1].push_back(i);
    }
    G[x].push_back(y); G[y].push_back(x);

    vector<int> res(n, 0); //各距離の経路数
    queue<int> que;
    rep(i, n){
        vector<int> cost(n, -1);
        que.push(i); cost[i] = 0;
        while(!que.empty()){
            int v = que.front(); que.pop();
            for(int e: G[v]){
                if(cost[e] != -1) continue;
                cost[e] = cost[v] + 1;
                if(e > i)res[cost[e]]++;
                que.push(e);
            }
        }
    }
    for(int i=1; i<n; i++){
        cout << res[i] << ln;
    }
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int r = sc.nextInt();
        solve(n, r);
    }

    public static void solve(int n, int r){
        int res = 0;
        res = (n>=10?0:100*(10-n)) +r;
        System.out.println(res);
    }
}

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

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

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right


def main():
    s = input()
    N = len(s)
    l = 0
    r = N-1
    ans = 0
    while s[l:r+1]:
        if s[l] == s[r]:
            l += 1
            r -= 1
        elif s[l] == 'x':
            ans += 1
            l += 1
        elif s[r] == 'x':
            ans += 1
            r -= 1
        else:
            print(-1)
            exit()
    print(ans)




if __name__ == "__main__":
    main()


Measured memory_bytes: 9536
/*-----lusar98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
vector<vector<ll> > adj;
vector<ll> vis,dp;
ll dfs(ll u)
{
	vis[u]=1;
	ll th =0;
	for(ll i=0;i<adj[u].size() ;i++)
	{
		if(vis [ adj[u][i] ] == 0 )
			th = max( dfs(adj[u][i]) + 1 , th );
		else
			dp[u] = max( dp [adj[u][i]] +1 ,dp[u]);

	}
	return dp[u] = max( th , dp[u] ) ;

}
int main()
{
    //fast();
    ll n,m;
    cin>>n>>m;
    adj.resize(n+2);
    dp.resize(n+2);
    vis.assign(n+2,0);
    for(ll i=0;i<m;i++)
    {
    	ll x, y;
    	cin>>x>>y;
    	adj[x].pb(y);
    }
    for(ll i=1;i<=n;i++)
    {
    	if(vis[i]==0)
    		dfs(i);
    }
    cout<< *max_element(dp.begin(), dp.end() )<<endl;
}


Measured memory_bytes: 9984
n,m=map(int,input().split())
a=[]
b=[]
for i in range(n):
    a+=[input()]

for i in range(m):
    b+=[input()]
ans='No'
if n==m:
    ans='Yes'

else:
    for i in range(n-m):
        for j in range(n-m):
            for k in range(m):
                if a[i+k][j:j+m]!=b[k]:
                    break
            else:
                ans='Yes'
            if ans=='Yes':
                break
        if ans=='Yes':
            break

   
print(ans)

Measured memory_bytes: 3064
using System;
class Program
{
	static void Main(string[] args)
	{
        string input;
        input = Console.ReadLine();
        int h = int.Parse(input); //縦
        input = Console.ReadLine();
        int w = int.Parse(input);  //横
        input = Console.ReadLine();
        int n = int.Parse(input);  //塗りつぶす数

        int[] A = new int[h+w];  //数

        for (int i = 0; i < h; i++)
        {
            A[i] = w;
        }

        for (int i = 0; i < w; i++)
        {
            A[i+h] = h;
        }

        int x = 0;
        int max = 0;
        int sum = 0;
        int count = 0;
        while(sum < n)
        {
            max = 0;
            for (int i = 0; i < h+w; i++)
            {
                if(max < A[i])
                {
                    max = A[i];
                    x = i;
                }
            }

            sum += A[x];
            A[x] = -1;
            count++;

            if(x < h)
            {
                for (int i = 0; i < w; i++)
                {
                    A[i+h]--;
                }
            }
            else
            {
                for (int i = 0; i < h; i++)
                {
                    A[i]--;
                }
            }
        }
		//出力
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    int n; cin>>n;
    long long a[n],M=-INF,m=INF,Mid,mid;
    rep(i,n){
        cin>>a[i];
        if(a[i]>M) M=a[i],Mid=i;
        if(a[i]<m) m=a[i],mid=i;
    }
    int cnt=0; vector<pair<int,int>> v;
    if(M==m&&M==0) cnt=0;
    else if(m>0){
        for(int i=1;i<n;i++){
            while(a[i-1]>a[i]){
                a[i]+=M;
                v.push_back({Mid+1,i+1});
                cnt++;
                if(a[i]>M) M=a[i],Mid=i;
            }
        }
    }else if(M<0){
        for(int i=n-2;i>=0;i--){
            while(a[i]>a[i+1]){
                a[i]+=m;
                v.push_back({mid+1,i+1});
                cnt++;
                if(a[i]<m) m=a[i],mid=i;
            }
        }
    }else{
        if(M<abs(m)){
            for(int i=n-2;i>=0;i--){
                while(a[i]>a[i+1]){
                    a[i]+=m;
                    v.push_back({mid+1,i+1});
                    cnt++;
                    if(a[i]<m) m=a[i],mid=i;
                }
            }
        }else{
            for(int i=1;i<n;i++){
                while(a[i-1]>a[i]){
                    a[i]+=M;
                    v.push_back({Mid+1,i+1});
                    cnt++;
                    if(a[i]>M) M=a[i],Mid=i;
                }
            }
        }
    }
    cout<<cnt<<endl;
    for(auto i:v){
        printf("%d %d\n",i.first,i.second);
    }
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <cmath>
#include <map>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;

int main(){
    int n,m;cin>>n>>m;
    vector<int> v(m);
    for(int i=0;i<n;i++){
        int a;cin>>a;
        for(int j=0;j<a;j++){
            int yay;cin>>yay;
            v[yay-1]++;
        }
    }
    int ans=0;
    for(int i=0;i<m;i++){
        if(n==v[i])ans++;
    }
    cout<<ans;
    
}

Measured memory_bytes: 256
def main():
    s = input()
    flag = False
    for i in s[0:len(s):2]:
        if i not in ["R", "U", "D"]:
            flag = True
    for i in s[1:len(s):2]:
        if i not in ["L", "U", "D"]:
            flag = True
    if flag:print("No")
    else:print("Yes")
         

if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
	int n, x, b, f, r, v, a[4][3][10];
	
	for(b = 0; b < 4; b++){
		for(f = 0; f < 3; f++){
			for(r = 0; r < 10; r++){
				a[b][f][r] = 0;
			}
		}
	}
	
	scanf("%d%*c", &n);
	for(x = 0; x < n; x++){
		scanf("%d%d%d%d%*c", &b, &f, &r, &v);
		a[b-1][f-1][r-1] += v;
	}
	
	for(b = 0; b < 4; b++){
		if(b != 0){
			printf("####################\n");
		}
		for(f = 0; f < 3; f++){
			for(r = 0; r < 10; r++){
				printf(" %d", a[b][f][r]);
			}
			printf("\n");
		}
	}
	
	return(0);
}



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

int main() {
    int N, T;
    std::cin >> N >> T;

    int ans = -1;

    std::vector<int> c(N), t(N);
    for (int i = 0; i < N; i++) {
        std::cin >> c[i] >> t[i];

        if (t[i] <= T and (ans < 0 or c[i] < ans)) {
            ans = c[i];
        }
    }

    if (ans < 0) std::cout << "TLE" << std::endl;
    else std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val N = readInputLine().toCharArray()
    val K = readInputLine().toInt()

    // dp[i][j][k]
    // 上位i桁を見たときに、0以外の個数がj個、k=1なら現時点で見ている桁までNと等しい
    val dp = Array(N.size + 1) { Array(K + 2) { IntArray(2) } }

    dp[0][0][1] = 1

    for (i in N.indices) {
        for (j in 0..K) {
            // 参照している桁に0を設定
            // Nより小さいケース数は無条件で加算
            dp[i + 1][j][0] += dp[i][j][0]

            if (N[i] == '0') {
                // 参照している桁が0の場合のみ、Nに等しい数は0以外の個数そのままで引き継がれる
                dp[i + 1][j][1] += dp[i][j][1]
            } else {
                // 参照している桁が0以外の場合は、Nに等しいケースがNより小さいケースに移行
                dp[i + 1][j][0] += dp[i][j][1]
            }

            // 参照している桁に0以外を設定
            // Nより小さいケースは無条件で1～9設定可
            dp[i + 1][j + 1][0] += dp[i][j][0] * 9

            if (N[i] != '0') {
                // Nに等しいケースは、1～参照している桁-1までの値を設定して、Nに等しいケースからより小さいケースに遷移
                dp[i + 1][j + 1][0] += dp[i][j][1] * (N[i] - '1')
                
                // Nに等しいケースで、その桁の値を設定してNに等しいケースを継続
                dp[i + 1][j + 1][1] += dp[i][j][1]
            }
        }
    }

    println(dp[N.size][K][0] + dp[N.size][K][1])
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 34208
n=int(input())
L=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int, input().split())
    u-=1
    v-=1
    L[u].append([v,w])
    L[v].append([u,w])
ans=[-1]*n
ans[0]=0
que=[0]
while que:
    v=que.pop()
    for u, w in L[v]:
        if ans[u]!=-1:
            continue
        ans[u]=(ans[v]+w)%2
        que.append(u)
for a in ans:
    print(a)

Measured memory_bytes: 44996
def main():
    c = 'abcdefghijklmnopqrstuvwxyz'
    x = sorted(input())
    y = sorted(input(), reverse=True)
    if x == y[:len(x)] and len(y) > len(x):
        print('Yes')
    else:
        if c.index(x[0]) >= c.index(y[0]):
            print('No')
        else:
            print('Yes')


main()


Measured memory_bytes: 2940
#include <iostream>
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
void solve()
{
   double h;
   cin>>h;
   ll t=floor(log(h)/log(2));
   ll ans=2*pow(2,t)-1;
   cout<<ans;
}
int main() {
	ll t;
// 	cin>>t;
// 	while(t--)
	    solve();
	return 0;
}

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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s:String = read();
    let k :i64 = read();
    let s:Vec<char> = s.chars().collect();
    if s.len() == 1 {
        println!("{}",s[0]);
        return;
    } else if  k <= s.len() as i64 {
        if  s.iter().take(k as usize).all(|&x| x == '1') {
            println!("1");
            return;
        } else {
            let ans = s.into_iter().filter(|&x| x != '1').nth(0).unwrap_or('1');
            println!("{}",ans );
            return;
        }
    } else {
        let ans = s.into_iter().filter(|&x| x != '1').nth(0).unwrap_or('1');
        println!("{}",ans );
        return;
    }

}

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

#define Bye return 0
#define ll long long

using namespace std;

void solve(){
    int n; cin>>n;
    int x[n];
    for (int i=0; i<n; i++) cin>>x[i];
    sort(x, x+n);
    int mini = INT_MAX;
    for (int i=x[0]; i<=x[n-1]; i++){
        int sum = 0;
        for (int j=0; j<n; j++){
            int num = abs(x[j]-i);
            sum += num*num;
        }
        mini = min(mini, sum);
    }
    cout<<mini<<endl;
}

int main(){
    solve();
    Bye;
}

Measured memory_bytes: 3632
/n,a,b=gets.split.map(&:to_i)/
/.sort/
/S = gets.chomp.chars/
b=gets.chomp
if(b=='A')
  puts "T"
elsif(b=='T')
  puts "A"
elsif(b=='G')
  puts "C"
elsif(b=='C')
  puts "G"
end

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
long mod=1e9+7,dp[2<<17];
int c[2<<17],pr[2<<17];
main()
{
	int n;cin>>n;
	dp[0]=1;
	for(int i=0;i++<n;)
	{
		int C;cin>>C;
		dp[i]=dp[i-1]+(pr[C]!=0&&pr[C]<i-1?dp[pr[C]]:0);
		dp[i]%=mod;
		pr[C]=i;
	}
	cout<<dp[n]<<endl;
}

Measured memory_bytes: 3072
#include <stdio.h>
#include <stdlib.h>

/*
int fib(int n){
  int u,v;
  if(n == 0 || n == 1){
    return 1;
  }
  else {
    u = fib(n-1);
    v = fib(n-2);
  
    return u+v;
  }
}
*/

int main(void){
  int n,f[44],i,fib,j=1,k=1,h;
  
  scanf("%d",&n);
  
  //f = fib(n);
  
  if(n==0 || n==1){
      h = 1;
  }
  else {
    for(i = 1 ; i < n ; i++){
      h = j + k;
      j = k;
      k = h;
    }
  }
  printf("%d\n",h);
  
  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <sstream>
using namespace std;


int main(void){

string input;
int num[2];
int counter = 0;
istringstream stream(input);

while(getline(cin,input)){
        stream.str("");
        stream.clear(stringstream::goodbit);
        stream.str(input);
        stream >> num[0] >> num[1];
        if(num[0] == 0 && num[1] == 0) break;
        else if(num[0] <= num[1]) cout << num[0] << " " << num[1] << "\n";
        else cout << num[1] << " " << num[0] << "\n";
}
return 0;
}

Measured memory_bytes: 1228
import numpy as np
import sys

input = sys.stdin.readline

N = int(input())
X = [list(map(int, input().split())) for _ in range(N)]

dp = np.zeros((N + 1, 3),dtype=int)

for i in range(1, N + 1):
    for j in range(3):
        # A=0,B=1,C=2
        dp[i][j] = max(dp[i - 1][(j + 1) % 3] + X[i - 1][j], dp[i - 1][(j + 2) % 3] + X[i - 1][j])

print(max(dp[N][0], dp[N][1], dp[N][2]))


Measured memory_bytes: 41780
import java.util.Scanner;

class Main{
	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);
		String string = scanner.next();
		
		String ans = "";
		
		for(int i = 0;i < string.length();i++){
			String aString =  string.substring(i,i+1);
			
			if(aString.equals("1")){
				
				ans = ans+ "9";
				
				
			}else if(aString.equals("9")){
				
				ans = ans + "1";
			}else{
				
				ans = ans + aString;
			}
		}
		
		System.out.println(ans);
		
	}
}



Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  int b;
  int c;
  cin>> a;
  cin>> b;
  cin>> c;
  if(c-b > a){cout<< b*2 + a + 1 <<endl;}
  if(c-b <= a){cout<< b + c <<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    ld t, x; cin >> t >> x;
    cout << t / x << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const ll Mod = 998244353;
const int MAX = 510000;
const double PI = 3.14159265358979;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};

int main() {
  string s;
  cin >> s;
  ll res = 0, start = 0, size = (ll)s.size();
  for (ll i=0; i<size-2; i++) {
    if (s[i]!='A') start = i+1;
    else if (s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') {
      res += i-start+1;
      s[start] = 'B';
      s[start+1] = 'C';
      ll cnt = 0;
      for (ll j=i+2; j>=start+2; j--) {
        s[j] = 'A';
        cnt++;
        if (cnt>=3) break;
      }
      start += 2;
    }
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

template <class T>
T inf = numeric_limits<T>::max();

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

  ll N, K;
  cin >> N >> K;
  vector<ll> A(N), sum(N+1, 0);
  repr(i, N, 0) {
    cin >> A[i];
    sum[i+1] = A[i] + sum[i];
  }

  for (int i = K+1; i <= N; ++i) {
    if (sum[i] - sum[i-K] > sum[i-1] - sum[i-1-K]) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 6364
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

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

	vector<LL> T(N);
	rep(i, N) cin >> T[i];

	LL M;
	cin >> M;

	vector<vector<LL> > required_time(M,vector<LL>(2));
	rep(i, M) {
		cin >> required_time[i][0] >> required_time[i][1];
		required_time[i][0]--;
	}

	LL initial_total = accumulate(ALL(T), 0);
	for (int i = 0; i < M; i++) {
		cout << initial_total - T[required_time[i][0]] + required_time[i][1] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
#include <sstream>
#include <queue>
using namespace std;
typedef long long ll;

int func(int x) {
  if (x % 2 != 0) return 0;
  return func(x / 2) + 1;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += func(a);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3216
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	int N;
	cin >> N;
	vector<bitset<30>> a(N);
	bitset<30> base(0);
	for(int i=0; i<N; ++i){
		int A;
		cin >> A;
		a[i] = bitset<30>(A);
		base = base ^ a[i];
	}
	for(int i=0; i<N; ++i){
		bitset<30> ans(0);
		for(int j=0; j<30; ++j){
			if(base[j]){
				if(!a[i][j]){
					ans.set(j);
				}
			}else{
				if(a[i][j]) ans.set(j);
			}
		}
		cout << ans.to_ullong() << " ";
	}
	cout << endl;
}

Measured memory_bytes: 4820
n,m = map(int,input().split())
d = [None]*n
for i in range(n):
    a,b = map(int,input().split())
    d[i] = [a,b]

d.sort(key=lambda x: x[0])

ryoukin = 0
cnt = 0
for lst in d:
    for i in range(lst[1]):
        ryoukin += lst[0]
        cnt += 1
        if cnt == m:
            break
    else:
        continue
    break    

print(ryoukin)

Measured memory_bytes: 21332