akhauriyash/Code-Regression huggingface dataset:
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)
  
// states - position, count, tight 
const int M = 105;
ll dp[M][M][2];
int K;

ll countInRangeUtil(int pos, int cnt, int tight, vector<int> num) {
	if (pos == num.size()) {
		if (cnt <= K)
			return 1;
		return 0;
	}
	if (dp[pos][cnt][tight] != -1)
		return dp[pos][cnt][tight];
	ll ans = 0;
	ll limit = (tight ? 9 : num[pos]);
	for (int dig = 0; dig <= limit; dig++) { 
		int currCnt = cnt;
		if (dig != 0)
			currCnt++;
		int currTight = tight;
		if (dig < num[pos])
			currTight = 1;
		ans += countInRangeUtil(pos + 1, currCnt, currTight, num);
	}
	return dp[pos][cnt][tight] = ans; 
}

ll countInRange(string &s) { 
	vector<int> num; 
	for (auto &it : s) { 
		num.push_back(it - '0'); 
	}
	memset(dp, -1, sizeof(dp)); 
	return countInRangeUtil(0, 0, 0, num); 
} 

int main() {
	string N;
	cin >> N >> K;
	string tmp = "0";
	int ans = countInRange(N) - countInRange(tmp);
	--K;
	if (K > 0) {
		ans -= (countInRange(N) - countInRange(tmp));
		--K;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
import io.StdIn.readInt
object Main extends App {
    val a = readInt
    val b = readInt
    val c = readInt
    val x = readInt

    var count = 0
    for (count_a <- 0 to a; count_b <- 0 to b; count_c <- 0 to c)
        if (500*count_a+100*count_b+50*count_c == x) count += 1

    println(count)
}

Measured memory_bytes: 26856
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

typedef long long int ll;

int div(int n) {
	int cnt = 0;
	for (int i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			cnt++;
			if (n / i != i)
				cnt++;
		}
	}
	return cnt;
}

int main() {
	optimizar_io
	int n;

	cin >> n;
	ll ans = 0;
	for (int c = 1; c < n; c++) {
		int ab = n - c;
		if (ab == 1)
			ans++;
		else {
			ans += div(ab);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3656
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long w = sc.nextLong();
    long h = sc.nextLong();
    long x = sc.nextLong();
    long y = sc.nextLong();
    
    double area = (w*h)/2.0;
    int ju = 0;
    
    if(w == 2*x && h == 2*y) ju = 1;

    System.out.println(area + " " + ju);
    
  }
}

Measured memory_bytes: 38956
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;


int main() {
   
    string s;
    cin >> s;
    ll num0 = 0;
    ll num1 = 0;
    for (ll i=0;i<s.length();i++){
        if(s[i] == '0'){
            num0++;
        }else{
            num1++;
        }
    }
    cout << 2*min(num0,num1) << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long int
#define INF 999999999999999999
using namespace std;
int n;
vector<vector<int>> adj;
vector<bool> vis;
vector<int> indegree;
vector<int> d;
void dfs(int src)
{
  vis[src]=true;
  bool flag=true;
  for(auto i : adj[src])
    {
      d[i] = max(d[i],d[src]+1);
      indegree[i]--;
      if(indegree[i]==0)
        dfs(i);
    }
    
}

void solve()
{
  int m;
  cin>>n>>m;
  adj.resize(n);
  vis.assign(n,false);
  indegree.assign(n,0);
  for(int i=0,a,b;i<m;i++)
  {
    cin>>a>>b;
    --a;
    --b;
    adj[a].push_back(b);
    indegree[b]++;
  }
  // top_sort();
  vis.assign(n,false);
  d.assign(n,0);
  bool flag=true;
  while(flag)
  {
    flag=true;
    for(int i=0;i<n;i++)
    {
      if(!vis[i] and indegree[i]==0)
        {
          flag=false;
          dfs(i);
        }
      
    }
    if(flag)
      break;
  }

  int ans=INT_MIN;
  for(int i=0;i<n;i++)
  {
    ans=max(ans,d[i]);
  }

  cout<<ans<<endl;







}
signed main()

{
  FAST_IO;
  int t = 1;

  // cin>>t;

  while(t--)
  {
    solve();
  }
  
  return 0;
}

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

int main(){
    bool cards[4][14];
    int n,num;
    char mark;
    
    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            cards[s][r]=0;
        }
    }
    
    cin >> n;
    for(int i=0;i<n;i++){
        cin>> mark >> num;
        if(mark=='S') cards[0][num]=1;
        if(mark=='H') cards[1][num]=1;
        if(mark=='C') cards[2][num]=1;
        if(mark=='D') cards[3][num]=1;
    }
    
    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            if(cards[s][r]) continue;
            if(s==0) mark='S';
            if(s==1) mark='H';
            if(s==2) mark='C';
            if(s==3) mark='D';
            cout << mark << " "<< r<<endl;
        }
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using p = pair<int, int>;
#define rep(i,n)  for(int i = 0; i < n ; i++)

vector<vector<char>> maps (500 ,vector<char>(500));
static bool reached[500][500];
bool isGoal = false;

int main() {
	long H, W;
	cin >> H >> W;
	long count = 0;
    if(H == 1 || W == 1)
    {
      cout << 1 << endl;
      return 0;
    }
	if (H * W % 2 == 0) { count = H * W / 2; }
	else { count = H * W / 2 + 1; }
	cout << count << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
    for(int len; cin >> len, len; ) {
        vector<int> arr(len);
        for(int i = 0; i < len; i++) cin >> arr[i];
        int a = 0;
        int num = 32;
        num -= (num - 1) % 5;
        cout << num << endl;
        while(num >= 0) {
            if(arr[a] >= num) {
                cout << 0 << endl;
                break;
            }
            num -= arr[a];
            cout << num << endl;
            num -= (num - 1) % 5;
            cout << num << endl;
            a = (a + 1) % arr.size();
        }
    }
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 100000
vector<int>g[MAXN];
ll facs[MAXN+1];

// x^n in mod
ll modpow(ll x, ll n, ll mod){
  if(n==0) return 1;

  if(n%2==0){
    return modpow(x*x%mod, n/2, mod) % mod;
  }else{
    return x * modpow(x, (n-1), mod) % mod;
  }
}

// n! in mod
ll fac(ll n){
  return facs[n];
}

// nCr in mod
ll comb(ll n, ll r){
  if(n<0 || n<r || r<0)return 0;
  ll fn = fac(n);
  ll fr = fac(r);
  ll fn_r = fac(n-r);
  
  ll d = (modpow(fr, MOD-2, MOD) * modpow(fn_r, MOD-2, MOD)) % MOD;
  ll u = fn%MOD;
  
  ll result = u * d % MOD;
 
  return result;
}

// nPr in  mod
ll perm(ll n, ll r){
  if(n<0 || n<r || r<0)return 0;
  ll fn = fac(n);
  ll fn_r = fac(n-r);
  
  ll d = modpow(fn_r, MOD-2, MOD);
  ll u = fn%MOD;
  
  ll result = u * d % MOD;
 
  return result;
}

int n,k;

ll dfs(int node, int pre){
  ll result = 1;
  for(auto nex: g[node]){
    if(nex==pre)continue;

    result = result * dfs(nex, node) % MOD;
  }
  ll ck = pre==-1 ? (ll)k : (ll)(k-2);
  ll child_count = pre==-1 ? (ll)(g[node].size()+1) : (ll)(g[node].size()-1);
  result = result * perm( ck, child_count ) % MOD;
//cout<<node<<' '<<pre<<' '<<result<<endl;
  return result;
}

int main(){
  cin>>n>>k;
  rep(i, n-1){
    int a,b; cin>>a>>b; a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }

  facs[0]=1;
  rep(i, MAXN)facs[i+1] = (facs[i]*(i+1))%MOD;

  ll result=dfs(0, -1);
  cout<<result<<endl;

  return 0;
}

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

typedef double du ;
typedef string st ;
typedef long long ll ;

int main ()
{
    ll num1 , num2 , res = 0 ;
  cin >> num1 >> num2 ;
  
  res = num1 * 500 ;
  
  if (res >= num2 )
    cout << "Yes" << endl ;
  else 
    cout << "No" << endl ;
  
    return 0 ;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
        int upp = N/100;
        int downn = N%100;
        boolean my = ((1<=upp)&&(upp<=12));
        boolean ym = ((1<=downn)&&(downn<=12));
        
        if (my&&ym)
          System.out.println("AMBIGUOUS");
        else if(my)
          System.out.println("MMYY");
        else if(ym)
          System.out.println("YYMM");
        else
          System.out.println("NA");
	}
}

Measured memory_bytes: 21588
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest._500problems
{
    class CF2017B_C
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            long n = nm[0];
            int m = nm[1];

            List<int>[] graph = new List<int>[n];
            for(int i = 0; i < n; i++)
            {
                graph[i] = new List<int>();
            }
            for(int i = 0; i < m; i++)
            {
                int[] ab = ReadInts();
                int a = ab[0] - 1;
                int b = ab[1] - 1;
                graph[a].Add(b);
                graph[b].Add(a);
            }

            Queue<int[]> pos = new Queue<int[]>();
            pos.Enqueue(new int[2] { 0, 0 });
            int[] dist = new int[n];
            for (int i = 0; i < n; i++) dist[i] = int.MaxValue;
            while (pos.Count > 0)
            {
                int[] val = pos.Dequeue();
                if (dist[val[0]] == int.MaxValue)
                {
                    dist[val[0]] = val[1];
                }
                else
                {
                    if (val[1] == dist[val[0]]) continue;
                    else
                    {
                        WriteLine(n * (n - 1) / 2 - m);
                        return;
                    }
                }

                for(int i = 0; i < graph[val[0]].Count; i++)
                {
                    pos.Enqueue(new int[2]
                    { graph[val[0]][i], (val[1] + 1)%2 });
                }
            }

            long oddCnt = 0;
            for (int i = 0; i < n; i++)
            {
                if (dist[i] == 1) oddCnt++;
            }

            WriteLine((n - oddCnt) * oddCnt - m);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 29984
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var a = Reads();
            long ans = long.MaxValue;
            for (int i = -100; i <=100; i++)
            {
                long tmp = 0;
                for (int j = 0; j <n ; j++)
                {
                    tmp += (a[j]-i)*(a[j]-i);
                }
                if (tmp < ans) ans = tmp;
            }
            Console.WriteLine(ans);
         
            Console.Out.Flush();
        }
    }
}




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

using namespace std;

int main(){
  string s;
  int m, h, sum = 0;

  while(1){
    cin >> s >> m;
    if(s == "-"){ break; }
    for(int i = 0; i < m; i++){
      cin >> h;
      sum += h;
    }
    for(int i = 0; i < s.size(); i++){
      cout << s[(sum+i) % s.size()];
    }
    cout << endl;
    sum = 0;
  }

  return 0;
}
      



Measured memory_bytes: 3112
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String s = sc.next();
        int n = s.length();
        String run[] = s.split("");
        String x;
        int i,y,z;
        int ans = 1000;
        for(i = 2; i < n; i++){
          x = run[i -2] + run[i - 1] + run[i];
          y = 753 - Integer.parseInt(x);
          z = Integer.parseInt(x) - 753;
            if(y >= 0 && ans > y){
              ans = y;
            }else if(z >= 0 && ans > z){
              ans = z;
            }
          
        }
        
      	System.out.println(ans);
 
    }
}

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

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

	vector<int> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
	}
	if (H.at(0) != 1) {
		H.at(0)--;
	}

	if (N == 1) {
		cout << "Yes" << endl;
		return 0;
	}

	for (int i = 1; i < N - 1; i++) {
		if (H.at(i - 1) < H.at(i) && H.at(i) >= H.at(i + 1)) {
			H.at(i)--;
		}
	}
	for (int i = 0; i < N; i++) {
		if (i == N - 1) {
			cout << "Yes" << endl;
		}
		else if (H.at(i) > H.at(i + 1)) {
			cout << "No" << endl;
			break;
		}
	}

}


Measured memory_bytes: 640
#include <stdio.h>

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

    return(gcd(b, a % b));
}

int main(){
    long long int input_K;
    long long int sum_gcd=0;

    scanf("%lld", &input_K);

    for(auto a=1; a<=input_K; a++){
        for(auto b=1; b<=input_K; b++){
            for(auto c=1; c<=input_K; c++){
                // printf("a b %lld\n", gcd(a,b));
                // printf("ab c %lld\n", gcd(gcd(a,b),c));
                sum_gcd += gcd(gcd(a,b),c);
            }
        }
    }

    printf("%lld", sum_gcd);
}

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

#define int long long

int c[11][11];
string s;

inline void preparation() {
    c[0][0] = 1;
    int n = s.size();
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= i; ++j) {
            if (j == 0 or i == j) c[i][j] = 1;
            else c[i][j] += c[i - 1][j - 1] + c[i - 1][j];
        }
    }
}

int solve(int l, int r) {
    int ret = 0;
    if (r - l <= 0) return 0;
    ret += stoll(s.substr(l, r - l));
    for (int i = l + 1; i < r; ++i) {
        int u = 0;
        for (int k = 0; k <= r - i - 1; ++k) u += c[r - i - 1][k];
        ret += stoll(s.substr(l, i - l)) * u;
        ret += solve(i, r);
    }
    return ret;
}

signed main() {
    cin >> s;
    preparation();
    cout << solve(0, s.size()) << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
 
public class Main {

  public static void main(String[] args) {
    int i, j, k;
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int mat[][] = new int[n][n];
    for (i=0; i<n; i++) {
      int u = Integer.parseInt(sc.next());
      k = Integer.parseInt(sc.next());
      for (j=0; j<k; j++) {
        int v = Integer.parseInt(sc.next());
        mat[u-1][v-1] = 1; 
      }
    }

    for (i=0; i<n; i++)
      for (j=0; j<n; j++)
        System.out.print(String.valueOf(mat[i][j]) + ( (j==n-1) ? '\n' : ' '));
  }
}

Measured memory_bytes: 23804
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long ll;
string N;
int main(){
	cin>>N;
	if(N[0]==N[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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 == 0) {
    System.out.println(a + b);
  } else {
    System.out.println(b - a);
  }
}
}

Measured memory_bytes: 22608
h, w = map(int, input().split())
ch, cw = map(lambda x: int(x)-1, input().split())
dh, dw = map(lambda x: int(x)-1, input().split())
S = [list(input()) for _ in range(h)]

from collections import deque
# 座標, 座標, ワープカウント
q = deque([[ch, cw, 0]])
visited = [[-1] * w for _ in range(h)]
visited[ch][cw] = 0

ans = -1
while q:
    i, j, wc = q.popleft()
    if i == dh and j == dw:
        ans = wc
        break
    for mi, mj in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        ni, nj = i + mi, j + mj
        if 0 <= nj < w and 0 <= ni < h:
            if S[ni][nj] == '.' and visited[ni][nj] != wc:
                visited[ni][nj] = wc
                q.appendleft([ni, nj, wc])

    for wi, wj in ((-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),
                    (-1, -2), (-1, -1), (-1, 1), (-1, 2),
                    (0, -2), (0, 2),
                    (1, -2), (1, -1), (1, 1), (1, 2),
                    (2, -2), (2, -1), (2, 0), (2, 1), (2, 2)):
        ni, nj = i+wi, j+wj
        if (0 <= nj < w and 0 <= ni < h and S[ni][nj] == '.' and
            visited[ni][nj] == -1):
            visited[ni][nj] = wc+1
            q.append([ni, nj, wc+1])
print(ans)

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

#define ff 		first
#define ss 		second
#define ll 		long long
#define pb 		push_back
#define mp 		make_pair
#define pi 		pair<int,int>
#define vi 		vector<int>
#define pqb 	priority_queue<int>
#define pqs 	priority_queue<int,vi,greater<int>>
#define setbit(x) 	__builtin_popcountll(x)
#define mod 	1000000007
#define inf 	1e18
#define endl 	"\n"

int main() {
	ll k;
	cin >> k;
	string s;
	cin >> s;
	ll cnt = 0;
	for (ll i = 0; i < k; i++) {
		if (s[i] == 'R') {
			cnt++;
		}
	}
	ll res = 0;
	for (ll i = 0; i < cnt; i++) {
		if (s[i] == 'W') {
			res++;
		}
	}
	cout << res;



	return 0;

}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int s[n];
    char c[n];
    for(int i = 0; i < m; i++) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    for(int i = 0; i < 1000; i++){
        string t = to_string(i);
        if(t.size() < n) continue;
        bool flag = true;
        for(int j = 0; j < m; j++){
            if(t[s[j]] != c[j]) {
                flag = false;
            }
        }
        if(flag){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
using Graph = vector<vector<int>>;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, k ;
  cin >> n >> m >> k ;
  vint seen(n,0) ;
  vector<queue<int>> gra(n) ;
  stack<int> S ;
  vint num(n,0) ;
  vint ans(n,0) ;
  vint sum(n) ;
  vint ira(n,0) ;
  vint sig(n+1,1) ;
  
  REP(i,m){
    int a, b ;
    cin >> a >> b ;
    gra[a-1].push(b-1) ;
    gra[b-1].push(a-1) ;
  }
  
  REP(i,n){
    sum[i] = SZ(gra[i]) ;
  }
  
  int cnt = 1 ;
  
  S.push(0) ;
  seen[0] = 1 ;
  num[0] = cnt ;
  
  while(!S.empty()){
    int k = S.top() ;
    
    while(1){
      if(gra[k].empty()){
        S.pop() ;
        break ;
      }
      int l = gra[k].front() ;
      if(seen[l]==1){
        gra[k].pop() ;
        continue ;
      }
      else{
        S.push(l) ;
        gra[k].pop() ;
        seen[l] = 1 ;
        num[l] = num[k] ;
        sig[cnt]++ ;
        break ;
      }
    }
    
    if(S.empty()){
      FOR(i,k,n){
        if(seen[i]==0){
          S.push(i) ;
          seen[i] = 1 ;
          cnt++ ;
          num[i] = cnt ;
          break ;
        }
      }
    }  
  }
  
  REP(i,n){
    ira[i] = sig[num[i]] ;
  }
  
  REP(i,k){
    int c, d ;
    cin >> c >> d ;
    if(num[c-1]==num[d-1]){
      ans[c-1]-- ;
      ans[d-1]-- ;
    }
  }
  
  
  REP(i,n-1){
    cout << ira[i]-sum[i]+ans[i]-1 <<" " ;
  }
  cout << ira[n-1]-sum[n-1]+ans[n-1]-1 <<endl ;
  
  
  
  
  
    
  
  
  
  
  return 0 ;
}





Measured memory_bytes: 70784
N,M = map(int,input().split())

a = [0]*M
b = [0]*M
c = [0]*M

for i in range(M):
    a[i],b[i],c[i] = map(int,input().split())
    a[i] -= 1
    b[i] -= 1
    

d = [[float("inf")]*N for i in range(N)]

for i in range(M):
    d[a[i]][b[i]] = c[i]
    d[b[i]][a[i]] = c[i]
    
for i in range(N):
    d[i][i] = 0

for s in range(N):
    for j in range(N):
        for i in range(N):
            d[i][j] = min(d[i][j], d[i][s]+d[s][j])

count = 0
for i in range(M):
    if d[a[i]][b[i]] < c[i]:
        count += 1
print(count)

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

int main(){
  int64_t N, M;
  cin >> N >> M;
  vector<int64_t> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
    vec.at(i) %= M;
  }
  for(int i=1; i<N; i++){
    vec.at(i) += vec.at(i-1);
    vec.at(i) %= M;
  }
  
  map<int64_t,int64_t> mp;
  for(int i=0; i<N; i++){
    if(mp.count(vec.at(i))){
      mp[vec.at(i)]++;
    }
    else{
      mp[vec.at(i)] = 1;
    }
  }
  
  int64_t ans = 0;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    int64_t x = itr->second;
    int64_t y = itr->first;
    ans += x*(x-1)/2;
    if(y %M == 0){
      ans += x;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define SIZE 10
#define PI 3.141592653589793

using namespace std;
typedef long long ll;

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

	int X,N;
	int i,j;
	int tmp;
	int answer=0;
	int counter=0;
	vector<int> given;

	cin >> X >> N;

	for(i=0;i<N;i++){
		cin >> tmp;
		given.push_back(tmp);
	}

	sort(given.begin(),given.end());
	//sort(given.begin(),given.end(),greater<int>());
	for(i=0;i<10000;i++){
		if(std::find(given.begin(), given.end(), X-i) == given.end()){
			cout << X-i << endl;
			return 0;
		}

		if(std::find(given.begin(), given.end(), X+i) == given.end()){
			cout << X+i << endl;
			return 0;
		}
	}
}



Measured memory_bytes: 3656
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<set>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


int main(){
    int H,W,N;
    cin>>H>>W>>N;
    int si,sj,is=1,ie=H,js=1,je=W; cin>>si>>sj;
    string S,T;
    cin>>S>>T;
    reverse(S.begin(),S.end());
    reverse(T.begin(),T.end());

    for(int i=0;i<N;i++){
        for(int j=0;j<2;j++){
            if(i==0 && j==0) continue;
            if(j==0){
                char c=T[i];
                if(c=='L') je=min(je+1,W);
                else if(c=='R') js=max(js-1,1);
                else if(c=='U') is=max(is-1,1);
                else ie=min(ie+1,H);
            }else{
                //cout<<1<<endl;
                char c=S[i];
                if(c=='L') js++;
                else if(c=='R') je--;
                else if(c=='U') ie--;
                else is++;
                if(js>W || je<1 || is>H || ie<1 || je-js<0 || ie-is<0){
                    cout<<"NO"<<endl;
                    return 0;
                }
            }
            //cout<<is<<" "<<ie<<" "<<js<<" "<<je<<endl;
        }
    }
    si=H-si+1;
    if(is<=si && si<=ie && js<=sj && sj<=je) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}



Measured memory_bytes: 776
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n;cin>>n;
    vector<long long> a(n);
    vector<long long> b(n);
    for (int i=0;i<n;i++){
        cin >> a[i] >> b[i];
    }
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    long long acc = 0;
    for (int i=0;i<n;i++){
        auto b_i = b[i];
        auto remain = (a[i] + acc) % b[i];
        if (remain != 0){
            acc += b_i - remain;
        }
    }
    cout << acc << endl;
    return 0;
    
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
    string weather;
    cin >> weather;
    if(weather == "Sunny"){
        cout <<"Cloudy";
    }
    else if(weather == "Cloudy"){
        cout <<"Rainy";
    }
    else if(weather == "Rainy"){
        cout <<"Sunny";
    }
}

Measured memory_bytes: 256
n=int(input())
L=[[] for i in range(n)]
for i in range(n-1):
    u,v,w=map(int, input().split())
    u-=1
    v-=1
    L[u].append([v,w])
    L[v].append([u,w])
ans=[-1]*n
ans[0]=0
from collections import deque
stack=deque([])
stack.append(0)
while stack:
    v=stack.popleft()
    for u, w in L[v]:
        if ans[u]!=-1:
            continue
        ans[u]=(ans[v]+w)%2
        stack.appendleft(u)
for a in ans:
    print(a)


Measured memory_bytes: 82080
#include<bits/stdc++.h>
using namespace std;
const static int INF = 1 << 30;

int main()
{
  int n, m, W;
  int weight[15], ptr = 0;
  int bit[10000] = {};
  int sum[1 << 15] = {}, dp[1 << 15];
  int highest = 0;
  fill_n(dp, 1 << 15, INF);

  cin >> n >> m >> W;
  for(int i = 0; i < n; i++) {
    int k;
    cin >> k;
    if(k > 0) highest = i;
    for(int j = 0; j < k; j++) {
      int w;
      cin >> w;
      if(i > 0) {
        weight[ptr] = w;
        bit[i] |= 1 << ptr;
        ++ptr;
      }
    }
  }
  if(ptr == 0) {
    puts("0");
  } else {
    for(int i = 1; i < 1 << ptr; i++) {
      for(int j = 0; j < ptr; j++) {
        if((i >> j) & 1) sum[i] += weight[j];
      }
    } 

    dp[0] = 0;
    for(int i = 1; i < 1 << ptr; i++) {
      for(int j = i; j > 0; j = j - 1 & i) {
        if(sum[j] <= W) dp[i] = min(dp[i], dp[i - j] + 1);
      }
    }
    int ret = 0;
    for(int i = highest, bits = 0; i > 0; i--) {
      ret += dp[bits |= bit[i]] * 2 - 1;
    }
    cout << ret + fabs(highest - m + 1) << endl;
  }
}

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

P p[100000], q[100000];
vector<P>E[100000];
bool used[100000];
void add_edge(int from, int to, int cost) {
	E[from].push_back(P(cost, to));
	E[to].push_back(P(cost, from));
}
int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		scanf("%d%d", &p[i].first, &q[i].first);
		p[i].second = i; q[i].second = i;
	}
	sort(p, p + n); sort(q, q + n);
	rep(i, n - 1) {
		add_edge(p[i].second, p[i + 1].second, p[i + 1].first - p[i].first);
		add_edge(q[i].second, q[i + 1].second, q[i + 1].first - q[i].first);
	}
	priority_queue<P, vector<P>, greater<P>>que;
	que.push(P(0, 0));
	ll cnt = 0;
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (used[p.second])continue;
		used[p.second] = true; cnt += p.first;
		for (P u : E[p.second]) {
			if (!used[u.second])que.push(u);
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 10616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int n; cin >> n;
  vector<ll> A(n);
  loop(i,0,n) cin >> A[i];
  ll ans = 0;
  ll prev = A[0];
  loop(i,1,n) {
    ll d = 0;
    if (prev > A[i]) {
      d += prev-A[i];
    }
    ans += d;
    prev = d + A[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4832
#include <bits/stdc++.h>
using namespace std;
#define REP(I, N) for (std::decay_t<decltype(N)> I = 0, I##_LEN = (N); I < I##_LEN; ++I)
using llong = long long;

const int MOD = 1000000007;

// COM(n, k) -> nCk 
// テーブル
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// n-元集合から k-元を選ぶ方法の総数は COM(n, k)
// n-元集合から重複を許して k-元を選ぶ方法の総数は COM(n+k-1, k)

constexpr int max_x = 100'000, max_y = 100'000;

void solve() {
    // 1 <= H, W <<= 100,000    // 10万
    // 1 <= A < H
    // 1 <= B < W
    // 下からA個以内、かつ左からB個以内はだめ
    int H, W, A, B;
    cin >> H >> W >> A >> B;

    /* 何もなければパスカルの三角形そのもの
     * A=3, B=4, 上下の図は全く同じ
     * +--------+ 0C0 1C1 2C2 3C3 4C4  5C5  // 右辺2C2 + 3C2 + 4C2
     * |        | 1C0 2C1 3C2 4C3 5C4  6C5  // 下っていくのはいいとして、足し合わせるのはなぜ？
     * |        | 2C0 3C1 4C2 5C3 6C4  7C5
     * xxxx     | 3C0 4C1 5C2 6C3 7C4  8C5
     * xxxx     | 4C0 5C1 6C2 7C3 8C4  9C5
     * xxxx-----+ 5C0 6C1 7C2 8C3 9C4 10C5

     * +--------+ 0C0 1C0 2C0 3C0 4C0  5C0
     * |        | 1C1 2C1 3C1 4C1 5C1  6C1
     * |        | 2C2 3C2 4C2 5C2 6C2  7C2
     * xxxx     | 3C3 4C3 5C3 6C3 7C3  8C3
     * xxxx     | 4C4 5C4 6C4 7C4 8C4  9C4
     * xxxx-----+ 5C5 6C5 7C5 8C5 9C5 10C5
     */

    llong ans = 0;
    REP (i, H - A) {
        ans += COM(B-1+i, B-1) * COM(H-i-1 + W-B-1, W-B-1);
        ans %= MOD;
    }
    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    COMinit();
    solve();
}



Measured memory_bytes: 12288
#include <bits/stdc++.h>
using namespace std;
#define _MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) _MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define pb push_back
#define all(x) begin(x),end(x)
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cerr<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cerr<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.first<<","<<p.second<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
#else
#define dbg(...) {}
#endif

bool solve(){
  int l;
  cin>>l;
  string s;
  cin>>s;

  map<char,int> m;
  for(char c : s) m[c]++;

  return m['R'] > m['B'];
}

int main(){
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		String n = sc.next();
		int k = sc.nextInt();
		
		// 計算
		long result = 0;
		result = cnt(n, k);
		//System.out.println(next("00050"));
		// 出力
		System.out.println(result);
	}
	
	static long cnt(String n, int k){
	    int len = n.length();
	    long res = 0;
		if(k == 1){
		    int a = n.charAt(0)-'0';
		    res += (len-1)*9 + a;
		}
		if(len >= 2 && k == 2){
		    StringBuilder sb = new StringBuilder();
		    for(int i = 0; i < len-1; i++){
		        sb.append("9");
		    }
		    int a = n.charAt(0)-'0';
		    res += cnt(sb.toString(), 1)*(a-1);
		    res += cnt(sb.toString(), 2);
		    int index = next(n.substring(1));
		    if(index >= 0) res += cnt(n.substring(index+1), 1);
		}
		if(len >= 3 && k == 3){
		    StringBuilder sb = new StringBuilder();
		    for(int i = 0; i < len-1; i++){
		        sb.append("9");
		    }
		    res += cnt(sb.toString(), 2)*((n.charAt(0)-'0')-1);
		    res += cnt(sb.toString(), 3);
		    int index = next(n.substring(1));
		    if(index >= 0) res += cnt(n.substring(index+1), 2);
		}
		return res;
	}
	
	static int next(String n){
	    int res = 100000;
	    if(n.indexOf('1') >= 0){
	        res = min(res, n.indexOf('1'));
	    }
	    if(n.indexOf('2') >= 0){
	        res = min(res, n.indexOf('2'));
	    }
	    if(n.indexOf('3') >= 0){
	        res = min(res, n.indexOf('3'));
	    }
	    if(n.indexOf('4') >= 0){
	        res = min(res, n.indexOf('4'));
	    }
	    if(n.indexOf('5') >= 0){
	        res = min(res, n.indexOf('5'));
	    }
	    if(n.indexOf('6') >= 0){
	        res = min(res, n.indexOf('6'));
	    }
	    if(n.indexOf('7') >= 0){
	        res = min(res, n.indexOf('7'));
	    }
	    if(n.indexOf('8') >= 0){
	        res = min(res, n.indexOf('8'));
	    }
	    if(n.indexOf('9') >= 0){
	        res = min(res, n.indexOf('9'));
	    }
	    if(res == 100000) res = -1;
	    return res;
	}
}



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

const int N = 200005;

int n, k, ans = 1, a[N], u[N], v[N];
bool asc, chk[N];
deque<int> le, gr;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];

        if (le.front() <= i - k) {
            le.pop_front();
        }
        while (!le.empty() && a[le.back()] > a[i]) {
            le.pop_back();
        }
        le.push_back(i);
        u[i] = le.front();

        if (gr.front() <= i - k) {
            gr.pop_front();
        }
        while (!gr.empty() && a[gr.back()] < a[i]) {
            gr.pop_back();
        }
        gr.push_back(i);
        v[i] = gr.front();
        chk[i] = (le.size() == k);
    }
    asc = chk[k];
    for (int i = k + 1; i <= n; i++) {
        if (u[i - 1] != i - k || v[i] != i) {
            ans++;
        }
        if (chk[i]) {
            if (!asc) {
                asc = true;
            } else if (!chk[i - 1]) {
                ans--;
            }
        }
    }
    cout << ans;
}


Measured memory_bytes: 3584
/* ex 5_4
   suuxxu */

#include <stdio.h>
#include <string.h>

int main(void){
    char str[11];
    int i, tmp, ans;

    // strに文字列Sを入力
    scanf("%s", &str);
    
    tmp = 0; ans = 0;
    for(i = 0; i < strlen(str); i++){
        if(str[i] == 'A' || str[i] == 'C' || str[i] == 'G' || str[i] == 'T'){
            // A, C, G, T のどれかならtmpで文字数を数える
            tmp++;
        }else{
            // 数えるのをやめる
            tmp = 0;
        }
        if(tmp >= ans){
            // 今数えている長さが今の答え候補以上であれば、それが新たな答え候補
            ans = tmp;
        }
    }

    // 答えansを出力
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using ll=long long;
const ll MOD=1e9+7;
const int INF=1<<30;

int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<double> > v(N,vector<double>(D));
  rep(i,N){
    rep(j,D){
      cin >> v[i][j];
    }
  }
  int ans=0;
  rep(a,N-1){
    for(int b=a+1;b<N;b++){
      double nakami=0;
      rep(j,D){
        nakami+=(v[a][j]-v[b][j])*(v[a][j]-v[b][j]);
      }
      double dist=sqrt(nakami);
      int judge=sqrt(nakami);
      if(dist==judge)
        ans++;
    }
  }
  cout << ans << endl;    
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int L = sc.nextInt();
		int r=0;
		List<Pair> resList = new ArrayList<>();
		for(int i=19;i>0;i--){
			if(Math.pow(2, i)<=L){
				r = i;
				break;
			}
		}
		int N = r+1;
		for(int i=1;i<N;i++){
			resList.add(new Pair(i,i+1,0));
			resList.add(new Pair(i, i+1, (int)Math.pow(2, i-1)));
		}
		for(int i=r;i>0;i--){
			int tmp = (int) Math.pow(2, i-1);
			if((L-tmp)>=Math.pow(2, r)){
				resList.add(new Pair(i, N, L-tmp));
				L -= tmp;
			}
		}
		out.println(N+" "+resList.size());
		for(Pair tmp: resList){
			out.println(tmp.u+" "+tmp.v+" "+tmp.w);
		}
		out.flush();
	}
}

class Pair{
	final int u;
	final int v;
	final int w;
	public Pair(int u, int v, int w){
		this.u=u;
		this.v=v;
		this.w=w;
	}
}

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

Measured memory_bytes: 22612
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, [ $t:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        h: [i32; n],
    }
    let mut h = h;
    let mut ans = 0;
    loop {
        let mut ok = true;
        for i in 0 .. n { if h[i] > 0 { ok = false }}
        if ok { break }
        let mut lo = 0;
        for i in 0 .. n {
            if h[i] > 0 { lo = i; break }
        }
        let mut hi = n - 1;
        for i in lo + 1 .. n {
            if h[i] == 0 { hi = i - 1; break }
        }
        for i in lo .. hi + 1 { h[i] -= 1; }
        ans += 1;
    }
    puts!("{}\n", ans);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 8572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,i,j,a,b,c,d,ara[4];
	cin>>a>>b>>c>>d;
	ara[0]=a*c;
	ara[1]=a*d;
	ara[2]=b*c;
	ara[3]=b*d;
	sort(ara,ara+4);
	cout<<ara[3]<<'\n';
	return 0;
}

Measured memory_bytes: 3552
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,K = map(int, lines.pop(0).split(' '))
    re = int(N / 2)
    if N % 2 == 0:
        if re >= K:
            print('YES')
        else:
            print('NO')
    else:
        if re + 1 >= K:
            print('YES')
        else:
            print('NO')


#
# main
#

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

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

int main(){
	int N;
	long long answer = 0;
	
	cin >> N;
	
	for(int i = 1; i <= N - 1; i++){
		answer += i;
	}
	
	
	cout << answer << endl;
	
	return 0;
}

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

int main()
{

    int n;
    cin >> n;

    vector<int> v(n);

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

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

    double ans = (v.at(0) + v.at(1)) / 2.0;

    for (int i = 2; i < n; i++)
    {
        ans = (ans + v.at(i)) / 2.0;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong(),M=sc.nextLong(),sum=0;
			if(N*2>M){
			sum=M/2;
			}
			else if(M>N*2){
			sum=N;
			sum=sum+((M-N*2)/4);
			}
			System.out.println(sum);
	}
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define sort_(a) sort(a.begin(), a.end())
#define rsort(a) sort(a.rbegin(), a.rend())
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; 0 <= i; i--)
#define for_(i, start, end) for (int i = start; i < end; i++)
#define rfor(i, start, end) for (int i = start - 1; 0 <= i; i--)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1'050'000'000;
constexpr long long INF64 = 4'000'000'000'000'000'000;
constexpr int MOD7        = 1'000'000'007;
constexpr int MOD53       = 998'244'353;
constexpr double PI       = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

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

    int x, y;
    scan(x, y);

    ll ans = 0;
    if (x == 1)
        ans += 300000;
    if (x == 2)
        ans += 200000;
    if (x == 3)
        ans += 100000;
    if (y == 1)
        ans += 300000;
    if (y == 2)
        ans += 200000;
    if (y == 3)
        ans += 100000;
    if (x == 1 && y == 1)
        ans += 400000;
    print(ans);

    return 0;
}

Measured memory_bytes: 384
n, s = map(int, input().split())
a = list(map(int, input().split()))

MOD = 998244353

dp = [[0 for _ in range(s + 1)] for _ in range(n + 1)]

ans = 0

for i, x in enumerate(a):
    if x < s:
        dp[i+1][x] = i + 1
    if x == s:
        ans = (ans + (n-i) * (i+1)) % MOD
    for j in range(1, s):
        if dp[i][j] > 0:
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % MOD
            if j + x < s:
                dp[i+1][j+x] = (dp[i+1][j+x] + dp[i][j]) % MOD
            elif j + x == s:
                ans = (ans + dp[i][j] * (n-i)) % MOD

print(ans)

Measured memory_bytes: 119900