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

class Queue[A](nl:List[A]=Nil, rl:List[A]=Nil) {
  private var normal:List[A] = nl
  private var reverse:List[A] = rl
  def enque(x:A):Queue[A] = { reverse = x::reverse ; this }
  def deque():(Option[A], Queue[A])= {
    (normal, reverse) match {
      case (Nil, Nil) => (None, this)
      case (Nil, xs) => {
        val ls = xs.reverse
        normal = ls.tail
        reverse= Nil
        (Some(ls.head), this)
      }
      case (x::xs, ys) => { normal = xs; (Some(x), this) }
    }
  }
  def clear(): Queue[A] = new Queue(Nil,Nil)
  def isEmpty(): Boolean = this.count==0
  def count(): Int = normal.length + reverse.length
}

object Main extends App {
  def readALine(c:Int, ac:List[Int]):List[Int] =
    if (c > 0) readALine(c-1, sc.nextInt::ac) else ac.reverse
  def readLines(r:Int, c:Int, ac:List[List[Int]]):List[List[Int]] =
    if (r > 0) readLines(r-1, c, readALine(c, Nil)::ac) else ac.reverse
  val sc = new Scanner(System.in)
  val N,M = sc.nextInt
  val ls = readLines(M, 2, Nil)

  def makePassage(ls:List[List[Int]], ps:Array[List[Int]]): Array[List[Int]] = {
    if (ls.isEmpty) ps else {
      val p = ls.head
      val i = p.head-1
      val j = p.tail.head-1 
      ps.update(i, j::ps(i))
      ps.update(j, i::ps(j))
      makePassage(ls.tail, ps)
    }
  }
  val passage = makePassage(ls, Array.fill(N)(Nil))

  // type Room  = Option[(Int,Int)]
  case class Room(val visited:Boolean, val step:Int, val nextTo:Int)
  type QItem = (Int,Int)

  def solve(que:Queue[QItem], rooms:Array[Room]): Array[Room] = {
    def iter(curId:Int, ps:List[Int], qu:Queue[QItem], rm:Array[Room]): (Queue[QItem], Array[Room]) =
      if (ps.isEmpty) (qu, rm) else {
        val p = ps.head
        if (rm(p).visited) iter(curId, ps.tail, qu, rm)
        else {
          rm.update(p, Room(true, rm(curId).step+1, curId))
          iter(curId, ps.tail, qu.enque((curId, p)), rm)
        }
      }

    que.deque() match {
      case (None, _) => rooms
      case (Some((preId, curId)), nextQue) => {
        val (qu, rm) = iter(curId, passage(curId), nextQue, rooms)
        solve(qu, rm)
      } 
    }
  }

  val rslt = solve(new Queue[(Int, Int)](List((-1, 0))), Array.fill(N)(Room(false, 0, 0)).updated(0, Room(true,0,-1)))

  // println(rslt.mkString(","))

  if (rslt.forall((r) => r.visited)) {    
    println("Yes")
    for (i <- 1 to N-1) {
      println(rslt(i).nextTo+1)
    }
  } else println("No")

}

Measured memory_bytes: 117708
#define rep(i,n) for (int i = 0; i < n; i++)
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const ll INF = 1e18;


int main() {
	int n, m;
	cin >> n >> m;
	vector<string> a(n);
	rep(i, n) cin >> a[i];
	vector<vector<int>> dp(n);
	rep(i, n) dp[i].resize(m, 0);
	dp[0][0] = 1;
	rep(i, n) {
		rep(j, m) {
			if ((i==0&&j==0)||a[i][j] == '#') continue;
			dp[i][j] = (dp[max(0, i - 1)][j] + dp[i][max(0, j - 1)]) % mod;
		}
	}
	cout << dp[n - 1][m - 1] << endl;
	return 0;
}

Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            string sT = Console.ReadLine().Trim();

            // 解析
            // 互いに足りない文字ないかチェック
            List<char> lstsS = sS.ToCharArray().ToList().Distinct().ToList();
            List<char> lstsT = sT.ToCharArray().ToList().Distinct().ToList();
            Boolean bEx = true;
            for (int i = 0; i < lstsT.Count; i++)
            {
                if (!lstsS.Contains(lstsT[i])) { bEx = false; break; }              // 互いの文字列違いチェック
            }
            if (bEx)                                                                // 同じ文字存在
            {
                for (int i = 0; i < lstsS.Count; i++)
                {
                    if (!lstsT.Contains(lstsS[i])) { bEx = false; break; }          // 互いの文字列違いチェック
                }
            }

            // 回転チェック
            string sOut = "No";
            if (bEx)                                                                // 同じ文字存在
            {
                string sJ = sS;
                for (int i = 0; i < sJ.Length; i++)
                {
                    if (sJ == sT) { sOut = "Yes"; break; }
                    sJ = SetsS(sJ);
                }
            }

            //出力
            Console.WriteLine("{0}", sOut.ToString());

#if DEBUG
        Console.WriteLine("続行するには何かキーを押してください．．．");
        Console.ReadKey();
#endif

    }

        private static string SetsS(string sS)
        {
            List<char> lstsS = sS.ToCharArray().ToList();
            List<char> lstsJ = new List<char>();
            lstsJ.Add(lstsS[lstsS.Count - 1]);
            for (int i = 0; i < lstsS.Count - 1; i++)
            {
                lstsJ.Add(lstsS[i]);
            }
            return new String(lstsJ.ToArray());
        }

}


Measured memory_bytes: 11232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;

int main(){
	cin >> n;
	int ans = 0;
	REP(i, n + 1)ans += i;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  vector<string> data = {"pon", "pon", "hon", "bon", "hon", "hon", "pon", "hon", "pon", "hon"};
  cout << data.at(S.at(S.size() - 1) - '0') << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

void rsort_u32(void *base, const int count){
	typedef uint32_t rsort_t;
	rsort_t *a=base;
	rsort_t *b=malloc(count*sizeof(rsort_t));
	int c[0x100];
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(0<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(0<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(1<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(1<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(2<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(2<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i]>>(3<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ b[--c[(a[i]>>(3<<3))&0xFF]]=a[i]; }{void *t=a; a=b; b=t;}
	free(b);
}

char s[100][101];
char t[]="100 100\n";
int main(void){
	int a=nextint()-1;
	int b=nextint()-1;
	for(int i=0; i<50; i++){
		for(int j=0; j<100; j++){
			s[i][j]='#';
		}
		s[i][100]=10;
	}
	for(int i=50; i<100; i++){
		for(int j=0; j<100; j++){
			s[i][j]='.';
		}
		s[i][100]=10;
	}
	for(int i=0; i<20; i+=2){
		for(int j=0; j<100; j+=2){
			if(a>0){ a--; s[i][j]='.'; }
		}
	}
	for(int i=80; i<100; i+=2){
		for(int j=0; j<100; j+=2){
			if(b>0){ b--; s[i][j]='#'; }
		}
	}
	write(1, t, sizeof(t)-1);
	write(1, s, sizeof(s));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define int long long
#define ll long long
#define EPS 0.00000000000001
#define ld long double
#define inf 2000000000000
#define N 200000

int32_t main()
{
    IOS;

    int h,w,a,b;
    cin >> h >> w >> a >> b;
    for(int i = 0;i < b;i++)
    {
        for(int j = 0;j < a;j++)
            cout << 1;
        for(int j = a;j < w;j++)
            cout << 0;
        cout << endl;

    }
    for(int i = b;i < h;i++)
    {
        for(int j = 0;j < a;j++)
            cout << 0;
        for(int j = a;j < w;j++)
            cout << 1;
        cout << endl;
    }    

    return 0;
}
 
 

Measured memory_bytes: 1280
N = int(input())
A = [int(i) for i in input().split()]

Adict = {}

for a in A:
    if str(a) in Adict:
        Adict[str(a)] += 1
    else:
        Adict[str(a)] = 1

ct = 0

for i in Adict:
    if int(i) < Adict[i]:
        ct += (Adict[i]-int(i))
    elif int(i) > Adict[i]:
        ct += Adict[i]
print(ct)

Measured memory_bytes: 23460
#include <iostream>
#include <vector>
#include <algorithm> // sort
#include <map>       // pair
#include <string>
using namespace std;

int main(int argc, const char *argv[])
{
    int H,W,h,w;

    cin>>H>>W>>h>>w;

    int all = H*W;

    cout<<H*W - W*h - H*w + h*w;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[200021];
multiset<int >s;
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		s.insert(a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		set<int >::iterator it;
		if((it=s.find(a[i]))!=s.end())
		{
			s.erase(it);
		}
		cout<<*--s.end()<<endl;
		s.insert(a[i]);
	}
	
}

Measured memory_bytes: 11904
unittest
{
	assert( [ "3", "3 1 4" ].parse.expand.solve == 2 );
	assert( [ "5", "1 1 1 1 1" ].parse.expand.solve == 5 );
	assert( [ "6", "40 1 30 2 7 20" ].parse.expand.solve == 4 );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto t = 0L;
	foreach( a; as.sort() )
	{
		if( a <= t * 2 ) ans++;
		else             ans = 1;
		t += a;
	}
	return ans;
}


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

int main(){
   int M[100][100];
   int n;
   cin >> n;

   for(int i=0; i<n; i++)
      for(int j=0; j<n; j++)
         M[i][j]=0;

   int u, k, v;
   for(int i=0; i<n; i++){
      cin >> u >> k;
      u--;
      for(int j=0; j<k; j++){
         cin >> v;
         v--;
         M[u][v]=1;
      }
   }

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

   return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sun Apr 19 21:19:48 JST 2020
 **/

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

template <class T, class S> T make_vec(S x) { return x; }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) {
    return std::vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...));
}

signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    std::vector<Int> ord(n);
    std::iota(ord.begin(), ord.end(), 0);
    std::sort(ord.begin(), ord.end(), [&](Int i, Int j) { return a[i] > a[j]; });
    auto dp = make_vec<Int>(n + 1, n + 1, 0);
    REP(i, n) {
        REP(j, n - i) {
            Int idx = ord[i + j];
            chmax(dp[i + 1][j], dp[i][j] + a[idx] * std::abs(i - idx));
            chmax(dp[i][j + 1], dp[i][j] + a[idx] * std::abs((n - 1 - j) - idx));
        }
    }
    Int ma = -1;
    REP(i, n + 1) REP(j, n + 1) {
        chmax(ma, dp[i][j]);
    }
    std::cout << ma << std::endl;
}


Measured memory_bytes: 34592
#include<stdio.h>
int main(){
	int a, b, c, d, l, x, y;
	scanf("%d",&l);
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	x = a / c;
	if(( a % c) != 0){
		x++;
	}
	y = b / d;
	if(( b % d) != 0){
		y++;
	}
	if( x > y){
		l = l - x;
	}else{
		l = l - y;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))

//qsort用(昇順，降順)
int cmp_asc( const void *p, const void *q ) {
    return *(int*)p - *(int*)q;
}
int cmp_desc( const void *p, const void *q ) {
    return *(int*)q - *(int*)p;
}


int main(void){
	int n,m,i;
	scanf("%d %d",&n,&m);
	int x[m];
	for(i=0;i<m;i++) scanf("%d",&x[i]);
	qsort(x,m,sizeof(int),cmp_desc);
	int diff[m-1];
	for(i=0;i<m-1;i++) {
		diff[i]=x[i]-x[i+1];
		//printf("%d\n",diff[i]);
	}
	qsort(diff,m-1,sizeof(int),cmp_asc);
	int ans=0;
	for(i=0;i<m-n;i++) ans+=diff[i];
	if(n>=m) ans=0;
	printf("%d",ans);
	return 0;


}


Measured memory_bytes: 1268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 10005;
const int MOD = 1e9+7;
int N;
int A[MAX_N];
vector<int> primes;
const int MAX_P = 1e6+10;
bool is_prime[MAX_P];
map<int, int> factors;

int cal(ll x, ll y)
{
	int res = 0;
	while(x % y == 0){
		res++;
		x/=y;
	}
	return res;
}

ll modpow(ll x, int y)
{
	ll res = 1;
	while(y){
		if(y & 1) (res*=x)%=MOD;
		(x *= x) %= MOD;
		y>>=1;
	}
	while(res < 0) res += MOD;
	return res % MOD;
}

void solve()
{
	const int n = primes.size();
	for(int i=0;i<N;++i){
		int x = A[i];
		for(int j=2;j*j<=x;++j){
			if(x % j == 0){
				int cnt = 0;
				while(x % j == 0){
					cnt++;
					x/=j;
				}
				if(factors.count(j)) factors[j]=max(factors[j],cnt);
				else factors[j]=cnt;
			}
		}
		if(x!=1){
			if(!factors.count(x)) factors[x]=1;
		}
	}
	ll ans = 0;
	ll lcm = 1;
	for(const auto& p : factors) (lcm *= modpow(p.first, p.second))%=MOD;
	for(int i=0;i<N;++i){
		ans = (ans+lcm*modpow(A[i],MOD-2))%MOD;
	}
	cout << ans << '\n';
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> N;
	for(int i=0;i<N;++i) cin >> A[i];
	solve();
	return 0;
}

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

int k, p, f[100][15], d[100];

int main() {
    cin >> k;
    for (int i = 0; i <= 9; ++i) f[1][i] = 1;
    if (k <= 9) {
        cout << k << endl;
        return 0;
    }
    int sum = 9;
    for (p = 2;; ++p) {
        for (int j = 0; j <= 9; ++j) {
            f[p][j] = f[p - 1][j];
            if (j) f[p][j] += f[p - 1][j - 1];
            if (j < 9) f[p][j] += f[p - 1][j + 1];
            if (j) { sum += f[p][j]; if (sum >= k) break; }
        }
        if (sum >= k) break;
    }
    for (int i = 1; i < p; ++i) for (int j = 1; j <= 9; ++j) k -= f[i][j];
    for (int i = p, last, now; i; --i) {

        if (i == p) now = 1; else now = max(0, last - 1);
        for (; k > f[i][now]; k -= f[i][now], ++now);
        d[i] = now; last = now;
    }
    for (int i = p; i; --i) cout << d[i];
    return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int a;
  cin >> a;
  cout << (1000 - (a % 1000)) % 1000;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

namespace abc107_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] nums = Console.ReadLine().Split(' ');
            int n = int.Parse(nums[0]);
            int k = int.Parse(nums[1]);
            int[] x = new int[100001];
            int sign_bound = 0;

            nums = Console.ReadLine().Split(' ');

            for(int i = 0; i < n; ++i)
            {
                x[i] = int.Parse(nums[i]);
            }

            int min_t = 1 << 30;

            for(int i = 0; i < n - k + 1; ++i)
            {
                int t;
                int l = x[i];
                int r = x[i + k - 1];

                if (l >= 0)
                {
                    t = r;
                }
                else if (r <= 0)
                {
                    t = -l;
                }
                else if (-l < r)
                {
                    t = 2 * -l + r;
                }
                else
                {
                    t = -l + 2 * r;
                }

                if(t < min_t)
                {
                    min_t = t;
                }
            }

            Console.WriteLine(min_t);
        }
    }
}


Measured memory_bytes: 20320
#include <stdio.h>
int main() {
    char S[10];
    scanf("%s",S);
    if (!strcmp(S, "Sunny")) {
        printf("Cloudy");
    }else if (!strcmp(S, "Cloudy")){
        printf("Rainy");
    }else if (!strcmp(S, "Rainy")){
        printf("Sunny");
    }
    return 0;
}



Measured memory_bytes: 128
K, N = map(int, input().split())
A = list(map(int, input().split()))

dists = []
for i in range(N):
  if i==N-1:
    dists.append(K-A[N-1]+A[0])
                 
  else:
    dists.append(A[i+1]-A[i])
    
print(K-max(dists))

Measured memory_bytes: 32296
n, l = map(int, input().split())
temp_list = []
for i in range(n):
  temp_list.append(input())
ans_list = []
for temp_str in temp_list:
  if len(ans_list) == 0:
    ans_list.append(temp_str)
  else:
    max_flg = True
    for i in range(len(ans_list)):
      if temp_str <= ans_list[i]:
        ans_list.insert(i, temp_str)
        max_flg = False
        break
    if max_flg == True:
      ans_list.append(temp_str)
ans = ''.join(ans_list)
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[101000], L[101000];
int Num[101000], n, m, chk, C[3], cc;
long long Res;
void DFS(int a){
    int i;
    C[Num[a]]++;
    cc += E[a].size();
    for(i=0;i<E[a].size();i++){
        if(Num[E[a][i]] == -1){
            Num[E[a][i]] = (Num[a] + L[a][i])%3;
            DFS(E[a][i]);
        }
        else{
            if(Num[E[a][i]] != (Num[a] + L[a][i])%3)chk = 1;
        }
    }
}
int main(){
    int i, a, b, j;
    scanf("%d%d",&n,&m);
    for(i=1;i<=n;i++)Num[i]=-1;
    while(m--){
        scanf("%d%d",&a,&b);
        E[a].push_back(b);L[a].push_back(1);
        E[b].push_back(a);L[b].push_back(2);
    }
    for(i=1;i<=n;i++){
        if(Num[i] == -1){
            Num[i] = 0;
            chk = 0;
            cc = 0;
            for(j=0;j<3;j++)C[j]=0;
            DFS(i);
            if(chk){
                Res += 1ll * (C[0]+C[1]+C[2])*(C[0]+C[1]+C[2]);
            }
            else{
                if(!C[0]||!C[1]||!C[2])Res += cc/2;
                else Res += 1ll*C[0]*(C[1]+C[2])+1ll*C[1]*C[2];
            }
        }
    }
    printf("%lld\n",Res);
}

Measured memory_bytes: 17920
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <tuple>


int main() {
  int L;
  scanf("%d", &L);
  int bit = 0;
  while ((1 << bit + 2) <= L) ++ bit;
  std::vector<std::tuple<int, int, int>> vec;
  int n = 20;
  for (int i = 0; i + 1 < n; ++ i)
    vec.emplace_back(i, i + 1, 0);
  for (int i = 0; i <= bit; ++ i)
    vec.emplace_back(i, i + 1, 1 << i);
  for (int i = 0; i + 1 < n; ++ i) if (L >> i & 1) {
    int t = L >> i + 1 << i + 1;
    if (t) {
      vec.emplace_back(i, n - 1, t);
    }
  }
  printf("%d %d\n", n, vec.size());
  for (auto t : vec) {
    int a, b, c;
    std::tie(a, b, c) = t;
    printf("%d %d %d\n", a + 1, b + 1, c);
  }
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	static int mod=1000000007;

	public static void main(String[] $){
		System.err.println();
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int[]a=new int[n];
		Arrays.setAll(a,i->s.nextInt());

		for(int i=n-2;i>=0;--i) {
			if(a[i]>a[i+1])
				--a[i];
			if(a[i]>a[i+1]) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


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

using namespace std;

int main()
{
    char c;
    while (cin >> c, c != '0') {
        char b[3][3]; b[0][0] = c;
        for (int i = 1; i < 9; i++) {
            cin >> b[i/3][i%3];
        }
        
        auto win = [&](char c) -> bool {
            for (int i = 0; i < 3; i++) {
                if (b[i][0] == c && b[i][1] == c && b[i][2] == c) {
                    return true;
                }
                if (b[0][i] == c && b[1][i] == c && b[2][i] == c) {
                    return true;
                }
            }

            if (b[0][0] == c && b[1][1] == c && b[2][2] == c) {
                return true;
            }
            if (b[0][2] == c && b[1][1] == c && b[2][0] == c) {
                return true;
            }
            
            return false;
        };

        if (win('b')) {
            cout << 'b' << endl;
        } else if (win('w')) {
            cout << 'w' << endl;
        } else {
            cout << "NA" << endl;
        }
    }
    return 0;
}

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

using namespace std;

template <typename T>std::string NumberToString ( T Number ){std::ostringstream ss; ss << Number;return ss.str(); } // Usages NumberToString(3)
template <typename T>T StringToNumber ( const string &Text ){istringstream ss(Text);T result;return ss >> result ? result : 0;} // StringToNumber<int>("3")

int main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

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

    if(b>=a) cout <<"unsafe"<<endl;
    else cout <<"safe"<<endl;

   return 0;
}

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

int main(){
   string steps;
   bool hard = false;
   cin >> steps;
   for(int i=1; i<=steps.size(); i++){
       if(i%2==0 && steps[i-1]=='R') hard = true;
       if(i%2!=0 && steps[i-1]=='L') hard = true;
   }
   if(hard) cout << "No\n";
   else cout << "Yes\n";
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);

	void run() {
		int n = sc.nextInt();
		int q = sc.nextInt();
		PriorityQueue<Pair> pq = new PriorityQueue<Pair>(n);
		HashMap<Integer, Pair> map = new HashMap<Integer, Pair>();
		StringBuilder sb = new StringBuilder();
		while (q-- > 0) {
			int num = sc.nextInt();
			int get = sc.nextInt();
			if (!map.containsKey(num)) {
				Pair p = new Pair(num, get);
				map.put(num, p);
				pq.add(p);
			} else {
				Pair update = map.get(num);
				pq.remove(update);
				update.cnt += get;
				pq.add(update);
			}
			Pair max = pq.peek();
			sb.append(max.num + " " + max.cnt + "\n");
		}
		System.out.print(sb);
	}

	class Pair implements Comparable<Pair> {
		int num;
		int cnt;

		public Pair(int num, int cnt) {
			super();
			this.num = num;
			this.cnt = cnt;
		}

		@Override
		public int compareTo(Pair arg0) {
			if (this.cnt == arg0.cnt) return this.num - arg0.num;
			return arg0.cnt - this.cnt;
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 110424
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


N = I()
s = [S() for i in range(N)]
M = I()
t = [S() for i in range(M)]
dic = {}

for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

for i in t:
    if i in dic:
        dic[i] -= 1


cnt = list(dic.values())
cnt.sort()
if cnt == "" or cnt[-1] < 0:
    print(0)
else:
    print(cnt[-1])

Measured memory_bytes: 12440
/*
ID: hn.csxs1
TASK: test
LANG: C++
*/
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f;

int n, m;
char a[5];

int main()
{
	//File("");
    scanf("%s", a + 1);
    if (a[1] == a[2] && a[1] == a[3] && a[2] == a[3]) puts("No");
    else puts("Yes");
	return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
  cin>>a>>b;
  	if(a>b)cout<<2*a-1<<endl;
  	else if(a==b)cout<<2*a<<endl;
  	else if(a<b)cout<<2*b-1<<endl;
  return 0;
}


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

int main(int argc, char const *argv[])
{
	//ifstream cin("input.txt");
	ll n,k;
	cin>>k>>n;
	
	ll a1,a2;
	cin>>a1;
	ll mx = 0;
	ll s = a1;
	rep(i, 0, n-2)
	{
		cin>>a2;
		mx = max(mx, a2 - a1);
		a1 = a2;
	}
	mx = max(mx, (k +s) - a2);
	cout<<k -mx;
}

Measured memory_bytes: 3612
#include <stdio.h>
#define abs(x) ((x) < 0 ? - (x) : (x))

int main(){
	int		n, dt, dd;
	int		cx=0, cy=0, ct=0, nx, ny, nt;
	scanf("%d", &n);

	for(int i=0; i<n; i++){
		scanf("%d %d %d", &nt, &nx, &ny);
		
		//距離差Δd
		dd = abs(nx-cx) + abs(ny-cy);
		//時間差Δt
		dt = nt-ct;

		//時間が足りない
		if( dd > dt ){ printf("No\n"); return 0; }
		//時間をつぶせない	//(距離差:偶 && 時間差:奇) || (距離差:奇 && 時間差:偶) 
		if( ((dd % 2 == 0) && (dt % 2 != 0)) || ((dd % 2 != 0) && (dt % 2 == 0)) ){ printf("No\n"); return 0; }
		
		cx = nx;
		cy = ny;
		ct = nt;	
	}
	printf("Yes\n");
	return 0;
}

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

using namespace std;

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

    int n,t,i,mn=9999;
    pair<int,int> arr[1002];
    cin>>n>>t;
    for(i=0;i<n;i++)cin>>arr[i].first>>arr[i].second;
    for(i=0;i<n;i++)
    {
        if(arr[i].second<=t && arr[i].first<mn)mn=arr[i].first;
    }
    if(mn==9999)cout<<"TLE\n";
    else cout<<mn<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,A,B,C,D,X,Y;
  cin>>N>>A>>B>>C>>D;
  X=N%A==0?N/A*B:(N/A+1)*B;
  Y=N%C==0?N/C*D:(N/C+1)*D;
  cout<<(X<Y?X:Y)<<endl;
  return 0;
}


Measured memory_bytes: 3116
/**
 *      ABC 108 B
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 21:03:22
**/

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
    
    cout << x2 - y2 + y1 << " " << y2 + x2 - x1 << " " << x1 - y2 + y1 << " " << y1 + x2 - x1 << endl;
    
    return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
namespace Base{
	# define mr make_pair
	typedef long long ll;
	typedef double db;
	const int inf = 0x3f3f3f3f, INF = 0x7fffffff;
	const ll  infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll;
	template<typename T> void read(T &x){
    	x = 0; int fh = 1; double num = 1.0; char ch = getchar();
		while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); }
		while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); }
	    if (ch == '.'){
	    	ch = getchar();
	    	while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();}
		}
		x = x * fh;
	}
	template<typename T> void chmax(T &x, T y){x = x < y ? y : x;}
	template<typename T> void chmin(T &x, T y){x = x > y ? y : x;}
}
using namespace Base;

const int N = 310, P = 998244353;
char s[N];
int f[N][N][N], K, n, num[N], sum[N], h[N][N][N], g[N][N][N];
int main(){
	scanf("\n%s", s + 1); read(K);
	int l = strlen(s + 1), cnt = 1;
	for (int i = 1; i <= l; i++)
		if (s[i] == '1') num[cnt]++;
			else cnt++;
	for (int i = 1; i <= cnt; i++) sum[i] = sum[i - 1] + num[i];
	n = sum[cnt]; K = min(K, n);
	f[0][0][0] = 1;
	for (int i = 1; i <= cnt; i++){
		for (int j = sum[i - 1]; j <= n; j++)
			for (int k = 0; k <= K; k++){
				g[i - 1][j][k] = h[i - 1][j][k] = f[i - 1][j][k];
				if (j > 0) g[i - 1][j][k] = (g[i - 1][j - 1][k] + g[i - 1][j][k]) % P;
				if (k > 0 && j > 0) h[i - 1][j][k] = (h[i - 1][j - 1][k - 1] + h[i - 1][j][k]) % P;
			}
		for (int j = sum[i]; j <= n; j++)
			for (int k = 0; k <= K; k++){
				f[i][j][k] = g[i - 1][j][k];
				if (j - num[i] > 0){
					f[i][j][k] = (f[i][j][k] - g[i - 1][j - num[i] - 1][k] + P) % P;
					if (k > 0) f[i][j][k] = (f[i][j][k] + h[i - 1][j - num[i] - 1][k - 1]) % P;
				}
				/*for (int t = max(0, j - num[i]); t <= j; t++)
					f[i][j][k] = (f[i][j][k] + f[i - 1][t][k]) % P;
				for (int t = j - num[i] - 1; t >= 0; t--){
					int c = j - t - num[i];
					if (c > k) break;
					f[i][j][k] = (f[i][j][k] + f[i - 1][t][k - c]) % P;
				}*/
			}
	}
	int ans = 0;
	for (int i = 0; i <= K; i++)
		ans = (ans + f[cnt][n][i]) % P;
	cout << ans << endl;
    return 0;
}


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

int main(){
    int C,N,M,judge=0,answer=0;
    cin>>N>>M>>C;
    vector<int> b(M);
    vector<vector<int>> a(N,vector<int>(M));
    for(int i=0;i<M;i++){
        cin>>b.at(i);
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            cin>>a.at(i).at(j);
        }
    }
    for(int i=0;i<N;i++){
        for(int j=0;j<M;j++){
            judge+=b.at(j)*a.at(i).at(j);
        }
        if(judge+C>0) answer+=1;
        judge=0;
    }
    cout<<answer<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){ 
int n,k;
cin>>n>>k;
long long a=0;
vector<int> h(n);
for(int i=0; i<n; i++){
cin>>h[i];
}
sort(h.begin(), h.end());
if(n<=k){
cout<<0<<endl;
}
else{
  for(int i=0; i<n-k; i++){
  a+=h[i];
  }
  cout<<a<<endl;
}
}


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

using namespace std;

int main()
{
    int n,i;
    cin >> n;
    vector<int> d(n);

    for(i=0; i<n; i++){
        cin >> d.at(i);
    }

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

    int ans = d.at(n/2) - d.at(n/2-1) ;
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double value = v[0];
    for (int i = 1; i < n; i++) {
        value = (value + v[i]) / 2;
    }
    cout << setprecision(20) << value << endl;
    return 0;
}

Measured memory_bytes: 3784
#include <stdio.h>

int main(void)
{
	int n;
	
	while (scanf("%d", &n) * n != 0){
		int icecream[10] = {0};
		int i;
		
		while (n-- > 0){
			int t;
			
			scanf("%d", &t);
			icecream[t]++;
		}
		for (i = 0; i < 10; i++){
			if (icecream[i] == 0){
				puts("-");
				continue;
			}
			while (icecream[i]-- > 0){
				printf("*");
			}
			puts("");
		}
	}
	
	return 0;
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(vector<ll> sosuu){
  int size = sosuu.size();
  REP(i,size){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(size)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=size;j++){
      sosuu[i*j] =false;
    }
  }
}

ll n,a,b;
ll x[100000];
ll sum = 0;
int main(){
  cin >> n>>a>>b;
  REP(i,n) cin >> x[i];
  REP(i,n-1){
    ll diff = x[i+1]-x[i];
    sum += min(diff*a,b);
  }
  cout <<sum<<endl;
}


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

int main(){
  char s[4];
  scanf("%s",s);

  if(strcmp(s,"ABC")==0){
    printf("ARC\n");}
  else{
    printf("ABC\n");}
  
  return 0;
}


Measured memory_bytes: 1616
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
using namespace std;
 
const int p=1e9+7;
const int maxn=1e5+2;

void solve() {
    int N, K; cin>>N>>K;
    int h[N]; 
    for(int i=0; i<N; i++) cin>>h[i];
    int DP[N];
    for(int i=1;i<N;i++) DP[i] = INT_MAX;
    DP[0] = 0;
    for(int i = 1; i < N; i++) {
       for(int j = 1; j <= K; j++) {
           if(i-j >= 0) {
               DP[i] = min(DP[i], DP[i-j] + abs(h[i] - h[i-j]));
           }
           else break;
       }
    }
    cout << DP[N-1] << "\n";
}

int main() {
    fast 
    // input output
    int t=1; 
    // cin>>t; 
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 4392
#include<bits/stdc++.h>
using namespace std;
#define N 19
#define mod 1000000007

int n,m,k,a[2*N][2*N],f[1<<N],g[1<<N];

void pls(int &x,int y){x=(x+y)%mod;}

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}
 
int main(){
	n=read()-1;m=read();k=read();
	memset(a,255,sizeof(a));
	for (int i=1;i<=k;i++){
		int x=read(),y=read()-1;
		a[x][y]=read();
	}
	for (int i=f[0]=1;i<=m;i++)
		for (int j=0;j<n;j++){
			memset(g,0,sizeof(g));
			for (int k=0;k<(1<<n);k++){
				if (a[i][j]!=1&&(k&(1<<j))==0) pls(g[k],f[k]);
				if (a[i][j]!=0) pls(g[k-(((k>>j)&-(k>>j))<<j)+(1<<j)],f[k]);
			}
			memcpy(f,g,sizeof(f));
		}
	int ans=0;
	for (int i=0;i<(1<<n);i++)
		pls(ans,f[i]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4480
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 	first
#define s 	second
#define ll 	int
#define int 	long long
#define ld 	long double
#define pb 	push_back
#define eb 	emplace_back
#define mk 	make_pair
#define vi 	vector<int>
#define pii 	pair<int,int>
#define vpi 	vector<pii>
#define fori(a,b,c) for(register int i=a;i<b;i+=c)
#define ford(a,b,c) for(register int i=a;i>=b;i-=c)
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl()
{
	cout<<"Control\n";
}
signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n,k;
    cin>>n;

    int s=0,d=1;

    for(int i=0;i<=50;i++)
    {
        

        if(n>=d)
        s+=d;
        else
        {
            break;
        }

        d=d*2;
        
    }
    cout<<s;


return 0;
}

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

int top, S[1000];

void push(int x) {
    top++;
    S[top] = x;
}

int pop() {
    top--;
    return S[top + 1];
}

int main() {
    int a, b;
    top = 0;
    char s[100];

    while(scanf("%s", &s) != EOF) {
        if(s[0] == '+') {
            a = pop();
            b = pop();
            push(a + b);
        } else if(s[0] == '-') {
            b = pop();
            a = pop();
            push(a - b);
        } else if(s[0] == '*') {
            a = pop();
            b = pop();
            push(a * b);
        } else {
            push(atoi(s));
        }
    }

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


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

long long a,b,k; 

int main(){
    cin>>a>>b>>k;
    
    if (a>k) {
        a-=k;
        k=0;
    }
    else{
        k-=a;
        a=0;
    }
    
    if (b>k) {
        b-=k;
        k=0;
    }
    else {
        b=0;
    }
    
    cout<<a<<" "<<b;
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
typedef long long LL;

int main() {
	std::string str;

	std::cin >> str;

	for (int i = 0; i < 3; ++i) {
		if (str[i] - 48 == 9) {
			std::cout << 1;
		}
		else {
			std::cout << 9;
		}
	}

	std::cout << "" << std::endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (b < a) {
            System.out.println(a - 1);
        } else {
            System.out.println(a);
        }
    }
}



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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while (true) {
    C = C - B;
    if (C <= 0) {
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if (A <= 0) {
      cout << "No" << endl;
      break;
    }
  }
}

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

int main(void){
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
    int A, B;
    cin >> A >> B;
    int a, b, c, d;
    double time{0};
    int sum{0};

    while(true){
        sum=0;
        for(int i{A}; i<=B; ++i){
            a = i/10000;
            b = i/1000%10;
            c = i/10%10;
            d = i%10;
            if(a==d and b==c)
                ++sum;
        }
        end  = chrono::system_clock::now();
        time =  static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0);
        if(time>1900)
            break;
    }
    cout << sum << endl;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

class Main {

	void solve() {
		
		int n = inint()*100 + inint()*10 + inint();
		out.println(n%4==0 ? "YES" : "NO");
		
	}

	public static Scanner in = new Scanner(System.in);
	public static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	public int inint() {
		return in.nextInt();
	}

	public long inlong() {
		return in.nextLong();
	}
	
	public String instr() {
		return in.next();
	}

	public char inchar() {
		return in.next().charAt(0);
	}
	
	public int[] inintar(int num) {
		int[] a = new int[num];
		for (int i=0; i<num; i++) {
			a[i] = in.nextInt();
		}
		return a;
	}

	public char[] incharar() {
		return in.next().toCharArray();
	}

}

Measured memory_bytes: 21716
#include <algorithm>
#include <complex>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define rep(i, n) repi(i, 0, n)
#define rep1(i, n) repi(i, 1, n + 1)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)

typedef long long ll;

int main()
{
    int n, m;
    cin >> n;
    map<string, int> mp;
    rep(i, n) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cin >> m;
    rep(i, m) {
        string s;
        cin >> s;
        mp[s]--;
    }
    int ans = 0;
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (ans < it->second) ans = it->second;
    }
    cout << ans << endl;
    return 0;
}

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

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

        int n = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();

        int[] t = new int[n];
        for(int i= 0; i < n; i++) {
            t[i] = sc.nextInt();
        }

        Arrays.sort(t);

        int countBus = 1;
        int minPerson = 0;
        for(int i = 1; i < n; i++) {
            // capacity is full
            if(i - minPerson + 1 <= c && t[i] - t[minPerson] <= k) {
                // ok
            } else {
                countBus++;
                minPerson = i;
            }
        }

        System.out.println(countBus);
    }
}


Measured memory_bytes: 48552
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  if (N == 1) cout << "Hello World" << endl;
  else {
    int A,B;
    cin >> A >> B;
    cout << A+B << endl;
  }
  return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define dbg(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define dbg(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define in(type, ...) \
  type __VA_ARGS__;   \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define out(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;

using namespace std;

int main() {
  in(string, s);
  int ans = 0;
  while (s.size() > 1) {
    if (s[0] != s[s.size() - 1]) {
      ++ans;
    }
    s = s.substr(1, s.size() - 2);
  }
  out(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> ve[N];
priority_queue<int> qe;
int main(){
	int n,m;cin>>n>>m;
	
	int a,b;
	for(int i=0;i<n;++i){
		cin>>a>>b;
		if(m-a+1<1) continue;
		ve[m-a+1].push_back(b);
	}
	int anx=0;
	for(int i=m;i>=1;--i){
		for(int j=0;j<ve[i].size();++j){
			qe.push(ve[i][j]);
		}
		if(!qe.empty()){
			anx+=qe.top();qe.pop();
		}
	}
	cout<<anx<<"\n";
}

Measured memory_bytes: 8908
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<map>
#include<stdbool.h>
#include<math.h>
#include<sstream>
#include<math.h>
#include<vector>
#include<functional>
#include<queue>
#include<utility>
#include<bitset>
typedef long long ll;
#define N (1000000000+7)
#define INF 1e10
using namespace std;
typedef pair<ll, ll> P;

ll dp[110][100010];


int main(void) {
	ll n, w;
	cin >> n >> w;
	vector<ll>x(n + 1), y(n + 1);
	dp[0][0] = 0;
	for (ll i = 1;i <= n;i++)cin >> x[i] >> y[i];
	for (ll i = 1;i <= n;i++) {
		for (int j = 1;j <= w;j++) {
			if (x[i] > j)dp[i][j] = dp[i - 1][j];
			else {
				dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - x[i]] + y[i]);
			}
		}
	}
	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 79360
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = 1; i <= n; i++)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
using P = pair <int, int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
 
ll MOD = 1000000007;
ll INF =1<<30;



int main(){
   ll n,p;
   cin >> n >> p;
   if(n==1) {
       cout << p <<endl;
       return 0;
   }
   if(p==1){
       cout << 1 << endl;
       return 0;
   }
   vector<ll> g,cnt;
   for(ll i = 2;i*i<=p;i++){
       int c = 0;
       if(p%i!=0) continue;
       if(p%i==0){
           g.push_back(i);
           while(p%i==0){
               p/=i;
               c++;
           }
           cnt.push_back(c);
       }
    
   }
   if(p!=1){
       g.push_back(p);
       cnt.push_back(1);
   }
   ll ans = 1;
   rep(i,cnt.size()){
       if(cnt[i]>=n){
           ans=ans *pow(g[i],cnt[i]/n);
       }
   }
   cout << ans <<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int i = 0;
    int ans = 0;
    int temp = 0;
    while(i < n-1) {
        if(h[i]>=h[i+1]) {
            temp++;
            i++;
        }
        else{
            ans = max(temp, ans);
            temp = 0;
            i++;
        }
    }
    ans = max(temp, ans);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640