akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<set>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	string a;
	cin >> a;
	bool flag = 0;
	bool flag2 = 0;
	//すべて9ならflag=0のまま
	//先頭のみ!9であと9なら
	if (a[0]=='9') flag2 = 1;
	FOR(i,1,a.size()){
		if (a[i]!='9') flag = 1;
	}
	if (!flag2 && !flag) {
		cout << a[0] - '0' + 9*(a.size()-1) << endl;
	}
	else if (!flag){
	cout << 9*a.size() << endl;
	}
	else {
	cout << a[0] - '1' + 9*(a.size()-1) << endl;
	}
	return 0;
}






































































































Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scan()
	k := iScan()
	if len(s) == 1 {
		fmt.Println(k / 2)
	} else if len(s) == 2 {
		if s[0] == s[1] {
			fmt.Println(k)
		} else {
			fmt.Println(0)
		}
	} else {
		x := make([]int, 1)
		x[0] = 1
		for i := 1; i < len(s); i++ {
			if s[i-1] == s[i] {
				x[len(x)-1]++
			} else {
				x = append(x, 1)
			}
		}
		if len(x) == 1 {
			if x[0]%2 == 0 {
				fmt.Println(x[0] / 2 * k)
			} else {
				fmt.Println(x[0]*(k/2) + x[0]/2*(k%2))
			}
		} else {
			c := 0
			for _, v := range x {
				c += v / 2
			}
			c *= k
			if s[0] == s[len(s)-1] {
				if x[0]%2 != 0 && x[len(x)-1]%2 != 0 {
					c += k - 1
				}
			}
			fmt.Println(c)
		}
	}
}


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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  
  vector<int> H(N);
  for (int i = 0; i < N; i++) {
    cin >> H.at(i);
  }
  
  int best = 1;
  int diff;
  int min_diff = 1000000;
  for (int i = 0; i < N; i++) {
    diff = abs(T*1000 - H.at(i)*6 - A*1000);
    if (diff < min_diff) {
      min_diff = diff;
      best = i+1;
    }
  }
  
  cout << best << endl;
  
}


Measured memory_bytes: 256
import sys

def main():
  input = sys.stdin.readline
  H, W = map(int, input().split())
  A = [[0 for _ in range(W+2)] for _ in range(H+2)]
  for i in range(H):
    A[i+1] = [0] + [c == '#' for c in input().strip()] + [0]
  
  ans = 'Yes'
  for i in range(H):
    for j in range(W):
      if A[i+1][j+1]:
        if not any([A[i][j+1], A[i+2][j+1], A[i+1][j+2], A[i+1][j]]):
          ans = 'No'
          break
  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<algorithm>
using namespace std;
int s[3];
int t[3];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<3;i++)s[i]=t[i]=0;
		for(int i=0;i<a;i++){
			int p,q,r;
			scanf("%d:%d%d",&p,&q,&r);
			if(r<q)r+=60;
			r-=q;
			if(11<=p&&p<=14){
				s[0]++;
				if(r<=8)t[0]++;
			}
			if(18<=p&&p<=20){
				s[1]++;
				if(r<=8)t[1]++;
			}
			if(21<=p||p<2){
				s[2]++;
				if(r<=8)t[2]++;
			}
		}
		printf("lunch ");
		if(!s[0])printf("no guest\n");
		else printf("%d\n",t[0]*100/s[0]);
		printf("dinner ");
		if(!s[1])printf("no guest\n");
		else printf("%d\n",t[1]*100/s[1]);
		printf("midnight ");
		if(!s[2])printf("no guest\n");
		else printf("%d\n",t[2]*100/s[2]);
		
	}
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
#define ll long long
#define cpp boost::multiprecision::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
const double PI = 3.1415926535897932384626433832795;
struct edge {
	int to;
	ll cost;
};
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
ll N, A[100000];
ll B[100000];
int main() {
	COME_LET_THE_GAMES_BEGIN();
	cin >> N;
	rep(i, N) {
		cin >> A[i];
		if (i == 0) {
			B[i] = A[i];
		}
		else {
			B[i] = B[i - 1];
			if ((i & 1) == 0) {
				B[i] += A[i];
			}
			else {
				B[i] -= A[i];
			}
		}
	}
	rep(i, N) {
		if (i == 0) {
			cout << B[N - 1] << " ";
			continue;
		}
		ll ans = 0;
		if ((i & 1) == 0) {
			ans += B[N - 1] - B[i - 1];
			ans -= B[i - 1];
		}
		else {
			ans -= B[N - 1] - B[i - 1];
			ans += B[i - 1];
		}
		cout << ans << ((i == N - 1) ? "\n" : " ");
	}
}

Measured memory_bytes: 2944
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int t = sc.nextInt();
			if(t == 0) break;
			int n = sc.nextInt();
			for(int i = 0 ; i < n ; i++){
				int s = sc.nextInt();
				int f = sc.nextInt();
				t -= f - s;
			}
			if(t <= 0){
				System.out.println("OK");
			} else {
				System.out.println(t);
			}
		}
		
		
		sc.close();
	}

}

Measured memory_bytes: 23424
n = int(input())
candidate = []
for _ in range(n):
  x = int(input())
  candidate.append(x)
candidate.sort(reverse=True)
standard = max(candidate)
Answer_list = [standard]
for item in candidate:
  if item < standard:
    Answer_list.append(item)
    standard = item

print(len(Answer_list))
#print(Answer_list)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

ll A[3010][3010];
ll dp[3010][3010][4];

int main()
{
    cout << fixed << setprecision(15);
    ll R, C, K;
    cin >> R >> C >> K;

    Fill(A, 0);
    Fill(dp, 0);

    REP(i, K){
        ll r, c, v;
        cin >> r >> c >> v;

        A[r-1][c-1] = v;
    }

    for(ll i=0; i<=R; i++){
        for(ll j=0; j<=C; j++){
            // 今のマス目を入れた場合の更新を行う
            for(ll k=2; k>=0; k--){
                dp[i][j][k+1] = max(dp[i][j][k+1], dp[i][j][k] + A[i][j]);
            }
            for(ll k=0; k<=3; k++){
                dp[i+1][j][0] = max(dp[i+1][j][0], dp[i][j][k]);
                dp[i][j+1][k] = max(dp[i][j+1][k], dp[i][j][k]);
            }
        }
    }

    ll ans = 0;
    REP(i, 4){
        ans = max(ans, dp[R-1][C-1][i]);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 357544
import java.util.Scanner;


public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int[] c;
    static int[] s;
    static int[] f;
    static int[] answer;
    static int[] min;


    public static void main(String[] args) {
        n = sc.nextInt();
        c = new int[n];
        s = new int[n];
        f = new int[n];
        min = new int[n];
        answer = new int[n];

        for (int i = 0; i < n - 1; i++) {
            c[i] = sc.nextInt();
            s[i] = sc.nextInt();
            f[i] = sc.nextInt();
        }
        for (int i = 0; i < n; i++) {
            System.out.println(solve(i));
        }
    }

    private static int solve(int num) {
        if (num - 1 == n) {
            return 0;
        }
        int sum = 0;
        sum += s[num] + c[num];
        for (int i = num + 1; i < n - 1; i++) {
            if (sum < s[i]) {
                sum = s[i];
            }
            int t = 0;
            if (sum % f[i] != 0) {
                t = f[i] - sum % f[i];
            }
            sum += t + c[i];
        }
        return sum;

    }
}



Measured memory_bytes: 28112
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)      x.begin(), x.end()
#define SIZE(x)     static_cast<i64>(x.size())
#define rep(i,n)    for (i64 i = 0, i ## _limit = (n); i < i ## _limit; ++i)
#define reps(i,s,t) for (i64 i = (s), i ## _limit = (t); i <= i ## _limit; ++i)
#define repr(i,s,t) for (i64 i = (s), i ## _limit = (t); i >= i ## _limit; --i)

#ifdef DBG
#define trace(...) _trace(#__VA_ARGS__, __VA_ARGS__);
#else
#define trace(...)
#endif

using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template<class T, class U>inline bool chmax(T &a, const U &b){return b>a && (a=b, true);}
template<class T, class U>inline bool chmin(T &a, const U &b){return b<a && (a=b, true);}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template<class T>
ostream& operator<< (ostream &os, const vector<T> &vec) {
    rep(i, vec.size()) os << vec[i] << (i+1 == vec.size() ? "" : " ");
    return os;
}

template<class T, class U>
ostream& operator<< (ostream &os, const pair<T, U> &p) {
    return os << p.first << ' ' << p.second;
}

template<class Itr>
ostream& printContainer(Itr begin, Itr end, const string &separator = " ", ostream &os = cout) {
    const auto rbegin = std::prev(end);
    for (; begin != rbegin; ++begin) os << *begin << separator;
    os << *rbegin;
    return os;
}

ostream& operator<< (ostream &os, ostream&) {
    return os;
}

template <class T>
void _trace(const char *s, T&& x) {
    clog << '{';
    while(*s != '\0') clog << *(s++);
    clog << ":" << setw(3) << x << '}' << endl;
}

template <class Head, class... Tail>
void _trace(const char *s, Head&& head, Tail&&... tail) {
    clog << '{';
    while(*s != ',') clog << *(s++);
    clog << ":" << setw(3) << head << "}, ";
    for (++s; !isgraph(*s); ++s);
    _trace(s, std::forward<Tail>(tail)...);
}
// }}} End Header

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

    int N;
    int a[100010];

    cin >> N;
    reps(i, 1, N) cin >> a[i];

    int cnt = 0;
    reps(i, 1, N-1) {
        if (a[i] == i) {
            swap(a[i], a[i+1]);
            ++cnt;
        }
    }
    if (a[N] == N) ++cnt;

    cout << cnt << endl;

    return 0;
}


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

int main() {
  int k, x;
  cin >> k >> x;

  int min, max;
  min = x - (k - 1);
  max = x + (k - 1);

  for (int i = min; i <= max; i++) {
    cout << i << " ";
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int m,f,b;
  cin >> m >> f >> b;
  if(m+f<b){
    cout << "NA" << endl;
  }else{
    if(m>=b){
      cout << 0 << endl;
    }else{
      cout << b-m << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
using namespace std;


class Solve{
public:
  Solve()
  {
    cin>>s;
  }
  void print()
  {
    if(s>"2019/04/30")cout<<"TBD"<<endl;
    else cout<<"Heisei"<<endl;

  }
private:
  string s;
};
int main()
{
  Solve test;
  test.print();
}


Measured memory_bytes: 256
S = input()
T = input()

def isOk():
    sToT = {}
    tToS = {}
    for s, t in zip(S, T):
        if not s in sToT:
            sToT[s] = t
        elif sToT[s] != t:
            return False
        if not t in tToS:
            tToS[t] = s
        elif tToS[t] != s:
            return False
    return True

print('Yes' if isOk() else 'No')


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

using namespace std;

const int N = 3030;

vector< int > adj[N];
int a[N];

bool dfs(int v) {
  for (int u : adj[v]) {
    if (a[u] >= a[v])
      continue;
    if (!dfs(u))
      return true;
  }
  return false;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", a+i); 
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector< int > ans;
  for (int i = 0; i < n; i++)
    if (dfs(i))
      ans.push_back(i+1);
  for (int j = 0; j < ans.size(); j++)
    printf("%d ", ans[j]);
  printf("\n");
  return 0;
}

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

using namespace std;

int const N = 1234567;

vector<int> edges[N];

int dfs(int v, int pv) {
  int c1 = 0;
  for (int to : edges[v]) {
    if (to == pv) continue;
    int got = dfs(to, v);
    if (got == 2) {
      return 2;
    }
    if (got == 1) c1++;
  }
  if (c1 == 0) {
    return 1;
  }
  if (c1 > 1) {
    return 2;
  }
  return 0;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v;
    --u;
    edges[v].push_back(u);
    edges[u].push_back(v);
  }
  if (dfs(0, -1) >= 1) {
    puts("First");
  } else {
    puts("Second");
  }
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
long long mat[501][501];
int main(){
    FILE*fi,*fout;
    int i,j,n,m,l,c;
    //fi=fopen("B.in" ,"r");
    //fout=fopen("B.out" ,"w");
    fi=stdin;
    fout=stdout;
    fscanf(fi,"%d%d%d%d" ,&n,&m,&l,&c);
    if(l*c==1)
      fprintf(fout,"No\n");
    else{
    long long val=(l*c-1)*(1000000000/(l*c-1));
    val++;
    while(val>1000000000)
      val-=(l*c-1);
    for(i=l;i<=n;i+=l)
     for(j=c;j<=m;j+=c)
       mat[i][j] = -val;
    long long sum=0;
    for(i=1;i<=n;i++)
     for(j=1;j<=m;j++){
       if(mat[i][j]==0)
         mat[i][j]=(val-1)/(l*c-1);
       sum+=mat[i][j];
     }
    if(sum<0)
      fprintf(fout,"No\n");
    else{
      fprintf(fout,"Yes\n");
      for(i=1;i<=n;i++) {
         for(j=1;j<=m;j++)
           fprintf(fout,"%lld " ,mat[i][j]);
         fprintf(fout,"\n");
      }
    }
    }
   // fclose(fi);
   // fclose(fout);
    return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, w, s[90][90], a[90][90], b[90][90], ans = INF;
bool dp[90][90][21000];
int main() {
	cin >> h >> w;
	REP(i, h)REP(j, w)cin >> a[i][j];
	REP(i, h)REP(j, w)cin >> b[i][j];
	REP(i, h)REP(j, w)s[i][j] = abs(a[i][j] - b[i][j]);
	REP(i, h) {
		REP(j, w) {
			REP(k, 21000) {
				if (i == j and i == 0) {
					dp[i][j][10000 + s[i][j]] = true;
					dp[i][j][10000 - s[i][j]] = true;
					continue;
				}
				if (i > 0 and dp[i - 1][j][k] and k + s[i][j] < 21000)dp[i][j][k + s[i][j]] = true;
				if (j > 0 and dp[i][j - 1][k] and k + s[i][j] < 21000)dp[i][j][k + s[i][j]] = true;
				if (j > 0 and dp[i][j - 1][k] and k - s[i][j] >= 0)dp[i][j][k - s[i][j]] = true;
				if (i > 0 and dp[i - 1][j][k] and k - s[i][j] >= 0)dp[i][j][k - s[i][j]] = true;
			}
		}
	}
	REP(k, 21000) if (dp[h - 1][w - 1][k]) ans = min(ans, abs(10000 - k));
	cout << ans << endl;
	
}


Measured memory_bytes: 148736
#include <iostream>
#include <string>

using namespace std;

bool dp[3];
int array[4];

int train(int i){
    int sum = array[0];
    if(i == 3){
        for(int i = 0;i < 3;i++){
            if(dp[i]){
                sum += array[i+1];
            }else{
                sum -= array[i+1];
            }
        }

        if(sum == 7) return true;
        else return false;
    }

    dp[i] = true;

    if(train(i+1)) return true;

    dp[i] = false;

    if(train(i+1)) return true;

    return false;

}

int main(){
    int len,sum;
    string s;

    cin >> s;
    len = s.size();

    for(int i = 0;i < len;i++)
        array[i] = s[i] - '0';

    train(0);

    for(int i = 0;i < 4;i++){
        if(i == 0){
            cout << array[i];
            continue;
        }
        if(dp[i-1])
            cout << '+';
        else 
            cout << '-';
        
        cout << array[i];
    }

    cout << '=' << 7 << endl;

    return 0;
}

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

namespace AtCoder.Abc
{
    class QuestionB
    {
        public static void Main(string[] args)
        {
            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            // 整数配列の入力
            var aArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

            long total = aArray.Sum();

            string result = total >= inputLongArray[0] ? "Yes" : "No";

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 20960
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    int n;
    ll k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    //入力
    int dp[n]; //訪れたら何回めかを格納
    memset(dp, -1, sizeof(dp));
    ll time = 0;
    int loc = 0;
    dp[loc] = time;
    ll peri = 0;
    int start = 0;
    while (1)
    {
        time++;
        loc = a[loc] - 1;
        if (time == k)
        {
            cout << loc + 1;
            return 0;
        }
        if (dp[loc] == -1)
        {
            dp[loc] = time;
        }
        else
        {
            start = dp[loc];
            peri = time - dp[loc];
            break;
        }
    }
    k = (k - start) % peri + start;
    for (int i = 0; i < n; i++)
    {
        if (dp[i] == k)
        {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4772
a[1<<18];u[1<<18];i;j;b;r;h;m;main(n){for(;i<=n;i++)scanf("%d",i?a+i:&n);for(qsort(a+1,n,4,"׋+Ð");~scanf("%d",&b);j++?a[i]-b?r++:u[i]++:0)for(i=0,h=n+1;h-i>1;a[m]<b|a[m]==b&u[m]?h=m:(i=m))m=h+i>>1;puts(r?"NO":"YES");}

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

using namespace std;
const int N=5e5+5,mod=1e9+7;
#define ll long long
int a[N],val[N],vis[N];
int visid=0;
vector<int> adj[N];
void dfs(int u)
{
    vis[u]=visid;
    val[a[u]]=visid;
    for(auto v:adj[u])
        if(!vis[v])
            dfs(v);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=1;i<=n;i++)
    {
        visid++;
        if(!vis[i])
            dfs(i);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
        if(vis[i]==val[i])
            ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 21760
extern crate core;

use std::fmt;
use std::cmp::{Ordering, min, max};
use std::f32::MAX;
use std::ops::{Add, Sub, Mul, Div, Neg, Index, IndexMut, SubAssign, Range};
use std::collections::{BTreeMap, VecDeque, BinaryHeap, BTreeSet, HashMap};
use std::fmt::Display;

fn show<T: Display>(vec: &Vec<T>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        print!("[{}", vec[0]);
        for i in 1 .. vec.len() {
            print!(", {}", vec[i]);
        }
        println!("]");
    }
}
fn show2<T: Display>(vec: &Vec<Vec<T>>) {
    if vec.is_empty() {
        println!("[]");
    }else {
        for l in vec {
            show(l);
        }
    }
}

macro_rules! read_line{
    () => {{
        let mut line = String::new();
        std::io::stdin().read_line(&mut line).ok();
        line
    }};
    (delimiter: ' ') => {
        read_line!().split_whitespace().map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (delimiter: $p:expr) => {
        read_line!().split($p).map(|x|x.to_string()).collect::<Vec<_>>()
    };
    (' ') => {
        read_line!(delimiter: ' ')
    };
    ($delimiter:expr) => {
        read_line!(delimiter: $delimiter)
    };
    (' '; $ty:ty) => {
        read_line!().split_whitespace().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
    ($delimiter:expr; $ty:ty) => {
        read_line!($delimiter).into_iter().map(|x|x.parse::<$ty>().ok().unwrap()).collect::<Vec<$ty>>()
    };
}
macro_rules! read_value{
    () => {
        read_line!().trim().parse().ok().unwrap()
    }
}
macro_rules! let_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

macro_rules! let_mut_all {
    ($($n:ident:$t:ty),*) => {
        let line = read_line!(delimiter: ' ');
        let mut iter = line.iter();
        $(let mut $n:$t = iter.next().unwrap().parse().ok().unwrap();)*
    };
}

fn main() {
    loop {
        let_mut_all!(n: i32);
        if n == -1 {return}
        if n == 0 {
            println!("0");
            continue
        }
        let mut digits: Vec<i32> = Vec::new();
        while n != 0 {
            digits.push(n % 4);
            n /= 4;
        }
        println!("{}", digits.iter().map(|x| x.to_string()).rev().collect::<Vec<_>>().connect(""));
    }
}


Measured memory_bytes: 5044
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
const int MAX_N = 300;
const int MAX_A = 300;
const int MAX_L = MAX_A * MAX_N;
ll dp[MAX_N + 1][MAX_L + 1];
const ll MOD = 998244353;
//------------------------------------------------------------------------------
void Update(ll& a, const ll b)
{
    a = (a + b) % MOD;
}

void _main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    int sum = 0;
    rep(i, 0, N)
    {
        cin >> a[i];
        sum += a[i];
    }

    ll ans = 1;
    rep(i, 0, N)
    {
        ans = (ans * 3) % MOD;
    }

    dp[0][0] = 1;
    rep(i, 0, N)
    {
        rep(j, 0, MAX_L + 1)
        {
            // R
            if (j + a[i] <= MAX_L)
            {
                Update(dp[i + 1][j + a[i]], dp[i][j]);
            }

            // G
            Update(dp[i + 1][j], dp[i][j]);

            // B
            Update(dp[i + 1][j], dp[i][j]);
        }
    }

    rep(i, (sum + 1) / 2, MAX_L + 1)
    {
        ans -= dp[N][i] * 3;
        while (ans < 0) ans += MOD;
    }

    if (sum % 2 == 0)
    {
        rep(i, 0, MAX_N + 1)
        {
            rep(j, 0, MAX_L + 1)
            {
                dp[i][j] = 0;
            }
        }

        dp[0][0] = 1;
        rep(i, 0, N)
        {
            rep(j, 0, MAX_L + 1)
            {
                // R
                if (j + a[i] <= MAX_L)
                {
                    Update(dp[i + 1][j + a[i]], dp[i][j]);
                }

                // G
                Update(dp[i + 1][j], dp[i][j]);
            }
        }

        ans += dp[N][sum / 2] * 3;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 211968
using System;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Linq;
using System.IO;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
#if DEBUG
            ReadLine();
#endif
        }


        void Solve(ConsoleInput cin)
        {
            int n = cin.ReadInt;
            string s = cin.Read;

            int cnt = 0;
            for(int i = 0; i < n; i++)
            {
                if(s[i] == 'R')
                {
                    cnt++;
                }
                else
                {
                    cnt--;
                }
            }

            if(cnt > 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }

        class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;

            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }

            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }

            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

bool mp; //false -> left, true -> right
string s, rightw = "yhnmjkuiolp", leftw = "bgtrfvcdewsxzaq";

bool find(string t, char c)
{
    for (int i = 0; i < t.size(); i++)
    {
        if (t[i] == c)
            return true;
    }
    return false;
}

int main()
{
    while (cin >> s)
    {
        if (s == "#")
            return 0;
        int ans = 0;
        mp = find(rightw, s[0]);
        for (int i = 1; i < s.size(); i++)
        {
            if (mp == true && find(leftw, s[i]) == true)
            {
                mp = !mp;
                ans++;
            }
            if (mp == false && find(rightw, s[i]) == true)
            {
                mp = !mp;
                ans++;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int n, x, t; 
int main(){
	while(~scanf("%d%d%d",&n, &x, &t)) {
		if(n % x == 0)
			cout << (n / x) * t << endl;
		else 
			cout << (n / x + 1) * t << endl; 
	}
	return 0;
} 

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

const int MAX_N = 2999;
double dp[MAX_N + 1][MAX_N + 1];
double p[MAX_N + 1];

int main() {
	ios_base::sync_with_stdio(false);
	cout << setprecision(20) << endl;
	int N; cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
	}
	dp[0][0] = 1.0;
	for (int n = 0; n + 1 <= N; n++) {
		for (int h = 0; h <= n; h++) {
			dp[n + 1][h + 1] += p[n + 1] * dp[n][h];
			dp[n + 1][h] += (1 - p[n + 1]) * dp[n][h];
		}
	}
	double ans = 0.0;
	for (int i = ceil(static_cast<double>(N) / 2); i <= N; i++) {
		ans += dp[N][i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(void)
{
    while(true)
    {
        int n, r; cin >> n >> r;
        if(n == 0 && r == 0) break;

        vector<int> array(n, 0);
        vector<int> copy(n, 0);
        for(int i = 0; i < n; i++){
            array[i] = i+1;
        }
        for(int i = 0; i < r; i++){
            int p, c;
            cin >> p >> c;
            
            for(int j = n - p; j > n - p - c; j--){
                copy[j + p - 1] = array[j];
            }
            for(int j = n - p + 1; j < n; j++){
                array[j - c] = array[j];
            }
            for(int j = n - 1; j > n - 1 - c; j--){
                array[j] = copy[j];
            }
            
        }

        cout << array[n-1] << endl;
    }
    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

int n;

int main() {
	
	FAST;
	
	cin >> n;
	vector <int> l(n + 1);
	for (int i = 1; i <= n; i ++) cin >> l[i];
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		for (int j = i + 1; j <= n; j ++) {
			for (int k = j + 1; k <= n; k ++) {
				if (l[i] != l[j] && l[j] != l[k] && l[i] != l[k]) {
					// intt sum = l[i] + l[j] + l[k];
					// if (sum > 2 * l[i] && sum > 2 * l[j] && sum > 2 * l[k]) ans ++;
					if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i]) ans ++;
				}
			}
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3660
#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 CIN(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 COUT(...) 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() {
  CIN(int, a, b);
  if (a > b) swap(a, b);
  COUT(string(b, '0' + a));
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) for(auto x:obj)cout<<x<<' ';cout<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

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


int main(){
	int N,M; cin>>N>>M;
	vector<ll> a(M), b(M), c(M,0);
	rep(i,M){
		cin>>a[i]>>b[i];
		rep(j,b[i]){
			int t; cin>>t; --t;
			c[i] += (1<<t);
		}
	}

	vector<vector<ll>> dp(1010, vector<ll>(5050,inf));
	dp[0][0] = 0;

	rep(i,M){
		rep(j,(1<<N)){
			chmin(dp[i+1][j], dp[i][j]);
			int nj = j | c[i];
			chmin(dp[i+1][nj], dp[i][j] + a[i]);
		}
	}
	int ans = dp[M][(1<<N)-1];
	if(ans == inf){
		cout<<-1<<endl;
	}else{
		cout<<ans<<endl;
	}
	return 0;
}

// int main(){
// 	int N,M;
// 	cin>>N>>M;
// 	vector<ip> key(M+1); // based-on-10, value
// 	REP(i,M){
// 		int a,b;
// 		cin>>a>>b;
// 		key[i].second = a;
// 		int sum = 0;
// 		rep(j,b){
// 			int t; cin>>t;
// 			sum += pow(2,t-1);
// 		}
// 		key[i].first = sum;
// 	}
// 	//sort(all(key));
// 	vector<vector<int>> dp(1010, vector<int> (1030, inf));
// 	rep(i, M+1)dp[i][0] = 0;
// 	REP(i,M){
// 		for(int j = 1; j<(1<<N); ++j){
// 			chmin(dp[i][j], dp[i-1][j]);
// 			if(j & key[i].first){
// 				chmin(dp[i][j], dp[i-1][max(0,j-(j & key[i].first))] + key[i].second);
// 			}
// 		}
// 	}
// 	// rep(i,M+1){rep(j,(1<<N))cout<<dp[i][j]<<' ';cout<<endl;}
// 	int ans = dp[M][(1<<N)-1];
// 	if(ans == inf){
// 		cout<<-1<<endl;
// 	}else{
// 		cout<<ans<<endl;
// 	}
// 	return 0;
// }

Measured memory_bytes: 40320
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,l,r) for (int i=(l); i<=(r); i++)
typedef long long ll;
using namespace std;

int n,k;

int main(){
	scanf("%d%d",&n,&k);
	if (k>(n+1)/2) puts("NO"); else puts("YES");
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <utility>
#include <numeric>
#include <deque>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <limits>
#include <cassert>

#define for0(i, N)    for (int i = 0  ; i <  (N); ++i)
#define for1n(i, N)   for (int i = 1  ; i <= (N); ++i)
#define for1(i, N)    for (int i = 1  ; i <  (N); ++i)
#define forn(i, N)    for (int i = 0  ; i <= (N); ++i)
#define forx(i, N, x) for (int i = (x); i <  (N); ++i)
#define forl(i, N, x, a) for (int i = (x), a = 0; a < (N);  \
                              i = (i + 1) % (N), ++a)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef priority_queue<ll> pq;
typedef priority_queue<ll,vector<ll>, greater<ll>> pql;
typedef stack<ll> stk;
typedef queue<ll> qu;
typedef pair<ll, ll> pll;
typedef map<ll, ll> mll;
typedef unordered_map<ll, ll> umll;
typedef set<ll> sll;
typedef unordered_set<ll> usll;


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

    double a, b, x;

    cin >> a >> b >> x;

    x /= a;

    double l = b - x / a;

    if (l >= b / 2) {
        double t = 2 * x / b;
        printf("%.10f", atan2(b, t) * 180 / M_PI);
        return 0;
    } else {
        printf("%.10f", atan2(l, a / 2) * 180 / M_PI);
    }

    return 0;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
const int nax=1000*1007;
const int k=nax/2;

int n;

int pocz[nax];
int kon[nax];

ll wyn;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		pocz[a+k]++;
		kon[b+k]++;
	}
	int zacz=n;
	int skon=0;
	for (int i=0; i<nax-2; i++)
	{
		skon+=kon[i];
		int lew=skon;
		int pra=zacz;
		if (i<k)
			pra++;
		else
			lew++;
		wyn+=min(lew, pra);
		
		zacz-=pocz[i+1];
	}
	printf("%lld\n", wyn*2);
	return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N; cin >> N;
	vector<long long>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	long long ans = 0;
	for (int i = 0; i < N; i++ ) {
		for (int j = 0; j < N; j++) {
			ans = max(ans, abs(A.at(i) - A.at(j)));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
	unsigned short row;            	/* 行数格納用変数 */
	unsigned short col;            	/* 列数格納用変数 */
	unsigned long sheet[101][101];	/* 表格納用配列 */
	int i,j;            	/* ループ変数 */
	
	/* 配列の初期化 */
	for(i = 0;i < 101;i++){
		for(j = 0;j < 101;j++){
			sheet[i][j] = 0;
		}
	}
	
	/* 行数、列数の入力 */
	scanf("%d %d", &row, &col);
	
	/* 表の要素の入力 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素の入力 */
			scanf("%ld", &sheet[i][j]);
		}
	}
	
	/* 各行の要素の合計の計算 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素をi行末端に加算 */
			sheet[i][col] += sheet[i][j];
		}
	}
	
	/* 各列の要素の合計の計算 */
	for(i =0;i < row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素をj列末端に加算 */
			sheet[row][j] += sheet[i][j];
		}
	}
	
	/* 全要素の合計の計算 */
	for(i = 0;i < row;i++){
		/* 各行の合計を表の末端に加算 */
		sheet[row][col] += sheet[i][col];
	}
	
	/* 表を出力 */
	for(i =0;i <= row;i++){
		for(j = 0;j < col;j++){
			/* i行j列の要素の出力 */
			printf("%ld ", sheet[i][j]);
		}
		/* 末列の出力 */
		printf("%ld\n", sheet[i][col]);
	}
	return 0;
}


Measured memory_bytes: 2096
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	H := make([]int, N)
	for i := 0; i < N; i++ {
		H[i] = scanInt()
	}

	flg := true
	for i := 0; i < N-1; i++ {
		if diff := H[i+1] - H[i]; diff > 0 {
			H[i+1]--
		} else if diff < 0 {
			flg = false
			break
		}
	}

	if flg {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 3072
n = int(input())

def digit(n):
  digit = 0
  while n > 0:
    digit += n % 10
    n //= 10
  return digit
    
  

ans = 1000000
for i in range(1,n):
  if ans > digit(i) + digit(n-i):
    ans = digit(i) + digit(n-i)
print(ans)

Measured memory_bytes: 9100
#include<stdio.h>
int main(void)
{
	int a,b,menseki,syu;
	scanf("%d",&a);
	scanf("%d",&b);
	menseki=a*b;
	syu=(a+b)*2;
	printf("%d ",menseki);
	printf("%d\n",syu);
	return 0;
}


Measured memory_bytes: 2064
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i) 
const long long INF = 10e9 + 7;
typedef long long ll;
using namespace std;
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() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	/
	/
	/
	*/
	int a, b;
	cin >> a >> b;
	if (a > 8 || b > 8) {
		cout << ":(" << endl;
	}
	else {
		cout << "Yay!" << endl;
	}
	return 0;
}


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

bool check(long long temp)
{
    // cout<<temp<<" ";
    int sum=0;
    while(temp!=0)
    {
         sum = sum + temp%10;
         temp = temp/10;
    }
    // cout<<sum<<endl;
    
    if(sum%10 == 0 )
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main() {
	// your code goes here
	int n ;
	cin>>n;
	long long j=pow(n, 3);
	cout<<j<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static long ans = 0;
	public static String S = "";

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		S = sc.next();
		rec(0, 0, 0);
		System.out.println(ans);
	}

	static void rec(int count, long tmpkeep, long tmpsum) {
		if (S.length() == count + 1) {
			ans += tmpkeep * 10;
			ans += tmpsum;
			ans += Integer.parseInt("" + S.charAt(count));
			return;
		} else {
			// +入れない
			rec(count + 1, tmpkeep * 10 + Integer.parseInt("" + S.charAt(count)), tmpsum);
			// +入れる
			rec(count + 1, 0, tmpsum + tmpkeep * 10 + Integer.parseInt("" + S.charAt(count)));
		}
		return;
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long i, mn=1000000000000001, N, n;
  cin >> N;
  for(i=0;i<5;i++){
    cin>>n;
    mn=min(n, mn);
  }
  cout<<4+(N+mn-1)/mn<<endl;
  return 0;
}

Measured memory_bytes: 3560
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n;
	cin >> n;
	vector<pi> a(n);
	rep(i, n) cin >> a[i].fi, a[i].se = i + 1;
	sort(all(a));
	rep(i, n) cout << a[i].se << " ";
	cout << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 1664
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	ll H[303]={};
	scan(N>>K);
	rep(i,N){
		scan(H[i+1]);
	}
	ll dp[303][303];//dp[x][y]:
	fill(dp[0],dp[303],INFl);
	dp[0][0]=0;
	rep1(x,N){
		rep1(y,N){
			ll tmp=INFl;
			rep(i,x){
				tmp=min(tmp,dp[i][y-1]+max(0LL,H[x]-H[i]));
			}
			dp[x][y]=tmp;
		}
	}
	ll ans=INFl;
	rep(i,N+1) ans=min(ans,dp[i][N-K]);
	prin(ans);
	return 0;
}


Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 50;
ll K , n , a[N];

int main(){
    cin >> K;
    n = 50;
    rep(i,0,n) a[i] = i + K / n;
    rep(i,0,K%n) {
        int p=min_element(a,a+n)-a;
        a[p]+=n;
        rep(i,0,n) if(i!=p) a[i]--;
    }
    cout<<n<<endl;
    rep(i,0,n) cout<<a[i]<<" \n"[i+1==n];
    return 0;
}


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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std; 

int main(void)
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    cout << max(0, min(b,d) - max(a,c));
        
    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
N, A, B = map(int, input().split())
output = 0
for i in range(1, N + 1):
    # set each condition for i < 10^4
    if i < 10:
        digitsum = i
    elif i < 100:
        digitsum = i // 10 + i % 10
    elif i < 1000:
        digitsum = i // 100 + (i % 100) // 10 + (i % 100) % 10
    elif i < 10000:
        digitsum = i // 1000 + (i % 1000) // 100 + ((i % 1000) % 100) // 10 + ((i % 1000) % 100) % 10
    else:
        digitsum = 1

    if A <= digitsum and digitsum <= B:
        output +=  i

print (output)

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
int n=1;
int a,b,pa,pb;
for(;n!=0;){
cin>>n;
if(n==0){break;}
pa=0;pb=0;
for(int i=0;i<n;i++){
a=0;b=0;
cin>>a;
cin>>b;
if(a>b){pa+=a+b;}
if(a==b){pa+=a;pb+=b;}
if(a<b){pb+=a+b;}
}
cout<<pa<<" "<<pb<<endl;
}
return 0;
}

Measured memory_bytes: 0