akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0;
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0)
using namespace std;
vector<int>V,L;
vector<string>Ans;
map<int,int>M;
set<ll>S;
set<char>:: iterator it;
ll n,m,a,b,c,d,e,f,x,y,z,t,l=100,r,ans,cnt,score;
string   s,winner,temp,p;
ll   arr[1001][1001];
bool xy=0;
char bd;
float ans1;
int main()
{
    TIME;
    cin>>a>>b;
    for (int i =0; i <b; i ++)
        cin>>x,S.insert(x);
        l=a;
        r=a;
    while (true)
    {
        if (S.count(l)==0)
        {
            cout<<l;
            r_0;
        }
        if (S.count(r)==0)
        {
            cout<<r;
            r_0;
        }
        r++;
        l--;
    }
}


Measured memory_bytes: 3668
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class MainClass
{
    static void Main()
    {
        var NK = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int N = NK[0], K = NK[1];
        var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Console.WriteLine(h.Count(_=>_>=K));
    }
}

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

const int MOD = 1000000007;
const long long INF = 1LL << 60;

int main()
{
    int a, b;
    cin >> a >> b;
    int mean = (a + b + 1) / 2;

    cout << mean << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color, D; vll path;
//***********//
vl A = { 1 };
vl P = { 1 };
ll f(ll N, ll X) {
	if (N == 0) {
		if (X <= 0) return 0;
		else return 1;
	}
	else if (X <= 1 + A[N - 1]) return f(N - 1, X - 1);
	else return P[N - 1] + 1 + f(N - 1, X - 2 - A[N - 1]);
}
int main() {
	ll X;
	cin >> N >> X;
	for (i = 0; i < N; i++) {
		A.push_back(A[i] * 2 + 3);
		P.push_back(P[i] * 2 + 1);
	}
	cout << f(N, X);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,X,T;
    cin >> N >> X >> T;
    for (int i=0;i < 10000;i++){
        if (X*i >= N){
            cout << i*T << endl;
            return 0;
        }

    }
    return 0;
}

Measured memory_bytes: 3628
/* ex 7_3
   nabe9393 */

#include<stdio.h>
#include<stdlib.h>

int main(void){
  int height, width, i, j, *row, *col;
  char **ptr;
  //縦と横のマスの数を入力
  scanf("%d %d", &height, &width);
  
  //メモリの動的確保
  ptr = (char**)calloc(height, sizeof(char*));
  if(ptr == NULL){
    exit(1);
  }
  for(i = 0; i < height; i++){
    ptr[i]=(char*)calloc(width, sizeof(char));
    if(ptr[i] == NULL){
      exit(1);
    }
  }
  
  
  //rowのメモリ確保
  row = (int*)calloc(height, sizeof(int));
  if(row == NULL){
    exit(1);
  }
  //colのメモリ確保
  col = (int*)calloc(width, sizeof(int));
  if(col == NULL){
    exit(1);
  }

  for(i=0; i<height; i++){
    for(j=0; j<width; j++){
      //入力
      scanf(" %c", &ptr[i][j]);
      if(ptr[i][j]=='#'){
        //i行j列目の文字が#ならrow[i]とcol[j]を１にする
        row[i] = 1;
        col[j] = 1;
      }
    }
  }
 
  
  for(i=0; i<height; i++){
    if(row[i]==1){
      for(j=0; j<width; j++){
        if(col[j]==1){
          //rowとcolが１のものをプリントしていく
          printf("%c", ptr[i][j]);
        }
      }
      //改行の場所を間違えると正しい答えにならなくなる
      printf("\n");
    }
  }
 
  //メモリを順に解放
  free(row);
  free(col);
  for(i=0; i<height; i++){
    free(ptr[i]);
  }
  free(ptr); 
  return 0;
}

Measured memory_bytes: 1640
#include <stdio.h>

int gcd(int,int);

int main(){
  int x,y,r,ans;
  scanf("%d%d",&x,&y);
  if(x<y)ans = gcd(y,x);
  else ans = gcd(x,y);
  printf("%d\n",ans);
  return 0;
}

int gcd(int a, int b)
{
  int r;
  while(b>0){
    r = a%b;
    a = b;
    b = r;
  }
  return a;
}

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

int main(){
    int n, x[8], y[8], nc;
    double sum = 0.0;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            double r = sqrt(pow((x[i] - x[j]), 2) + pow((y[i] - y[j]), 2));
            sum += r;
        }
    }
    cout << setprecision(10) << sum * 2 / n << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
int main()
{
  int ele,haire[N],minnum,i,j,hokan=0,cou=0,bunki=0;
  scanf("%d",&ele);
  for(i=0;i<ele;i++)
    {
      scanf("%d",&haire[i]);
      //minnum=haire[i];
    }
  // minnum=haire[0];
  for(i=0;i<ele;i++)
    {
      minnum=i;
      for(j=i;j<ele;j++)
	{
	  if(haire[j]<haire[minnum])
	    {
	      minnum=j;
	      bunki=1;
	    }
	  //cou++;
	}
      if(bunki==1)
	{
	  hokan=haire[i];
	  haire[i]=haire[minnum];
	  haire[minnum]=hokan;
	  cou++;
	}
      bunki=0;
    }
  for(i=0;i<ele;i++)
    {
      if(i<ele-1)
	{
	  printf("%d ",haire[i]);
	}
      else
	{
	  printf("%d",haire[i]);
	}
    }
  printf("\n");
  printf("%d\n",cou);
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const int MOD2 = 998244353;
const double EPS = 1e-9;

int main() {
  int N, M, L; cin >> N >> M >> L;
  vector<vector<P>> edge(N);
  rep(i,M) {
    int a, b, c; cin >> a >> b >> c; --a; --b;
    edge[a].push_back(P(c, b));
    edge[b].push_back(P(c, a));
  }

  rep(i,N) sort(all(edge[i]));

  Graph move(N);
  rep(i,N) {
    priority_queue<P> pq;
    vb seen(N, false);
    pq.push(P(L, i));

    while (!pq.empty()) {
      auto p = pq.top(); pq.pop();
      int f, v; tie(f, v) = p;
      if (seen[v]) continue;
      seen[v] = true;

      for (auto np : edge[v]) {
        int d, nv; tie(d, nv) = np;
        if (f < d) break;
        if (seen[nv]) continue;
        pq.push(P(f-d, nv));
      }
    }

    seen[i] = false;
    rep(j,N) {
      if (seen[j]) move[i].push_back(j);
    }
  }

  Graph query(N, vi(N, -1));
  rep(i,N) {
    queue<int> q;
    q.push(i);
    query[i][i] = 0;

    while (!q.empty()) {
      auto v = q.front(); q.pop();

      for (auto nv : move[v]) {
        if (query[i][nv] != -1) continue;
        query[i][nv] = query[i][v] + 1;
        q.push(nv);
      }
    }
  }

  int Q; cin >> Q;
  rep(i,Q) {
    int s, t; cin >> s >> t; --s; --t;
    if (query[s][t] == -1) cout << -1 << endl;
    else cout << query[s][t] - 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 2728
#include<stdio.h>
#define N 200000
int main(){

  int i,j,n;
  int data[N];
  int res,max_i;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&data[i]);
  }

  max_i=1;
  for(i=2;i<n;i++){
    if(data[max_i]<data[i]){
      max_i=i;
    }
  }
  res=data[1]-data[0];
  for(i=0;i<n-1;i++){
    if(max_i==i){
      max_i++;
      for(j=i+1;j<n;j++){
	if(data[max_i]<data[j]){
	  max_i=j;
	}
      }
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
    else{ 
      if(res<data[max_i]-data[i]){
	res=data[max_i]-data[i];
      }
    }
  }
  printf("%d\n",res);
  return 0;
}
  



Measured memory_bytes: 2644
import java.io.*; 
import java.math.*;
import java.util.*;
import java.awt.Point;
 
public class Main {
	//static final long MOD = 998244353L;
	//static final long INF = -1000000000000000007L;
	static final long MOD = 1000000007L;
	//static final int INF = 1000000007;
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter pw = new PrintWriter(System.out);
		int N = sc.ni();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.ni();
		int[] vals = new int[3];
		long ans = 1;
		for (int i = 0; i < N; i++) {
			int choices = 0;
			if (vals[0] == A[i])
				choices++;
			if (vals[1] == A[i])
				choices++;
			if (vals[2] == A[i])
				choices++;
			ans *= choices;
			ans %= MOD;
			if (vals[0] == A[i]) {
				vals[0] += 1;
			} else if (vals[1] == A[i]) {
				vals[1] += 1;
			} else {
				vals[2] += 1;
			}
		}
		pw.println(ans);
		pw.close();
 	}
    
    public static int[][] sort(int[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    int[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<int[]>() {
			  @Override
        	  public int compare(int[] arr1, int[] arr2) {
				  return arr1[0]-arr2[0]; //ascending order
	          }
		});
		return array;
	}
    
    public static long[][] sort(long[][] array) {
    	//Sort an array (immune to quicksort TLE)
		Random rgen = new Random();
		for (int i = 0; i < array.length; i++) {
		    int randomPosition = rgen.nextInt(array.length);
		    long[] temp = array[i];
		    array[i] = array[randomPosition];
		    array[randomPosition] = temp;
		}
		Arrays.sort(array, new Comparator<long[]>() {
			  @Override
			  //Descending order
        	  public int compare(long[] arr1, long[] arr2) {
				  if (arr2[0] < arr1[0])
					  return -1;
				  if (arr2[0] > arr1[0])
					  return 1;
				  return 0;
	          }
		});
		return array;
	}
    
    static class FastScanner { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastScanner() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int ni() { 
            return Integer.parseInt(next()); 
        } 
  
        long nl() { 
            return Long.parseLong(next()); 
        } 
  
        double nd() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try { 
                str = br.readLine(); 
            } catch (IOException e) {
                e.printStackTrace(); 
            } 
            return str; 
        }
    }
}

Measured memory_bytes: 33992
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#define ll long long
#define faltu ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define binary(x) std::string binary = std::bitset<25>(x).to_string(); //to binary
#define inf 1000000007
#define mod 1000000007
#define pi pair<int,int>
#define lpi pair<int,int>
#define mp make_pair
#define pb push_back
#define vi vector<int>
#define lvi vector<long long int>
#define pie 3.14159265358979323846
ll int MMM=inf;
int pw(ll int a, ll int b) {
    if (b == 0) return 1;
    ll int t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
using namespace std;
vi pm;
void prm(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
              prime[i] = false;
        }
    }
    for (int p=2; p<=n; p++)
       if (prime[p]) pm.pb(p);
}
bool sortbysecdesc(const pair<ll int,ll int> &a,const pair<ll int,ll int> &b)
{
    return a.first>b.first;
}
bool cmp(int x,int y){return x>y;}
int gcd(int a,int b)
{
    if(a<b)
        swap(a,b);
    return (b==0)?a:gcd(b,a%b);
}
int main()
{
	faltu;
	string s;
	cin>>s;
	for(int i=1;i<=s.length();i++)
	{
		if(i%2&&(s[i-1]=='R'||s[i-1]=='U'||s[i-1]=='D'))continue;
		else if(i%2==0&&(s[i-1]=='L'||s[i-1]=='U'||s[i-1]=='D'))continue;
		else
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;

}










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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> setans(0);
  int sum = 0;
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    setans.push_back(x);
    sum += x;
  }
  sort(setans.begin(), setans.end(), greater<int>());
  if (setans.at(M - 1) * 4 * M < sum)
    cout << "No";
  else
    cout << "Yes";
  cout << endl;
}

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

int main() {
  char s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  string t1, t2, t3;
  t1 += s1;
  t2 += s2;
  t3 += s3;
  int sum = stoi(t1) + stoi(t2) + stoi(t3);
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
  int n;
  cin >> n;

  map<int, int> m[2];
  for(int i=0;i<n;++i) {
    int x;
    cin >> x;
    if (m[i%2].count(x)) {
      ++m[i%2][x];
    } else {
      m[i%2][x]=1;
    }
  }

  int nmax[2][2];
  int val[2][2];
  for(int i=0;i<2;++i) {
    // Find top two
    nmax[i][0] = nmax[i][1] = 0;
    for(auto &it : m[i]) {
      if (it.second > nmax[i][0]) {
	nmax[i][1] = nmax[i][0];
	val[i][1]  = val[i][0];
	nmax[i][0] = it.second;
	val[i][0]  = it.first;
      } else if (it.second > nmax[i][1]) {
	nmax[i][1] = it.second;
	val[i][1]  = it.first;
      }
    }
  }
  int x;
  if (val[0][0] != val[1][0]) {
    x = n - nmax[0][0] - nmax[1][0];
  } else if (nmax[0][1] > nmax[1][1]) {
    x = n - nmax[1][0] - nmax[0][1];
  } else {
    x = n - nmax[0][0] - nmax[1][1];
  }

  cout << x << endl;
  return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<ll, ll> ll_ll;
typedef pair<double, int> d_i;
const int MOD = 1e9 + 7;
const ll INF = LLONG_MAX / 10;
struct edge { int v, w; };

int dp[310][310][310];

int main() {
	string s; cin >> s;
	int N = s.length();
	int K; cin >> K;
	for (int d = N; d >= 1; d--)
		for (int l = 0; l + d <= N; l++) {
			int r = l + d;
			rep(k, K + 1) {
				int x = dp[l][r][k];
				dp[l + 1][r][k] = max(dp[l + 1][r][k], x);
				dp[l][r - 1][k] = max(dp[l][r - 1][k], x);
				if (d == 1) continue;
				if (s[l] == s[r - 1])
					dp[l + 1][r - 1][k] = max(dp[l + 1][r - 1][k], x + 1);
				if (k + 1 <= K)
					dp[l + 1][r - 1][k + 1] = max(dp[l + 1][r - 1][k + 1], x + 1);
			}
		}
	int ans = 0;
	for (int l = 0; l <= N; l++) ans = max(ans, dp[l][l][K] * 2);
	for (int l = 0; l + 1 <= N; l++)
		ans = max(ans, dp[l][l + 1][K] * 2 + 1);
	cout << ans << endl;
}


Measured memory_bytes: 114816
#include <stdio.h>

int main(void)
{
	int h, n, a, aSum;
	int i;

	scanf("%d%d", &h, &n);

	aSum = 0;

	for (i = 0; i < n; i++)
	{
		scanf("%d", &a);
		aSum += a;
	}

	if (aSum >= h)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
	}

	return 0;
}

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

using namespace std;

int main () {

    while (1) {
        string card;

        cin >> card;

        if (card[0] == '-') {
            break;
        }

        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            
            int h;
            cin >> h;

            string tmp;
            tmp = card.substr(0, h);

            // cout << tmp << endl;

            // int gomi;
            // cin >> gomi;

            int cnt = 0;
            for (int j = h; card[j] != 0; j++) {
                card[j - h] = card[j];
                cnt++;
            }
            for (int j = cnt; card[j] != 0; j++) {
                card[j] = tmp[j - cnt];
            }

        }

        cout << card << endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  if(b > 1){
    while(b > a){
      b -= a - 1;
      ans++;
    }
    ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
 
using namespace std;
 
priority_queue<pair<int, int> > q;
int n, m, d[1000001], a, b;
 
main(){
  cin >> n >> m;
  q.push(make_pair(0, -1));
  for(int i=0;i<m;i++){
    cin >> a >> b;
    d[a] += b;
    q.push(make_pair(d[a], -a));
    while(1){
      pair<int, int> p = q.top();
      if(p.first == d[-p.second]){
        cout << -p.second << ' ' << p.first << endl;
        break;
      }
      q.pop();
    }
  }
}

Measured memory_bytes: 6008
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int X = input.nextInt();

        int[] L = new int[n];

        for (int i = 0; i < L.length; i++) {
            L[i] = input.nextInt();
        }
        int count = 0;
        for (int j = 0; j < L.length; j++) {
            X -= L[j];
            if (X >= 0) {
                count += 1;
            }
        }

        System.out.println(count+1);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

signed main(){
    int n; cin >> n;
    int a[n];
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int now=0;
    rep(i,n){
        int k=now;
        now=a[k];
        if(now==1){
            cout << i+1 << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


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

int main(){
  int N;
  cin >> N;
  double ans = 0;
  vector<vector<string>> vec(N,vector<string>(2));
  for(int i=0; i<N; i++){
    for(int j=0; j<2; j++){
      cin >> vec.at(i).at(j);
    }
  }
  for(int k=0; k<N; k++){
    double d = 0;
    d = stod(vec.at(k).at(0));
    if(vec.at(k).at(1) == "JPY"){
      ans = ans + d;
    }
    if(vec.at(k).at(1) == "BTC"){
      ans = ans + d*380000;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int i,ans=0;
  string s,t;
  cin >> s >> t;
  for(i=0;i<3;i++){
    if(s[i]==t[i]){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
typedef long long ll;
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(int i=num, i##_len=(n); i<i##_len; ++i)
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; }
#define print(x) (cout << (x) << endl)
#define pb push_back
#define mp make_pair
#define sz(x) int(x.size())
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
#define fs first
#define sc second

const int INF = 1e9;
const ll LLINF = 1e16;
const ll MOD = 1e9+7;
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}
 
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
 

// 指定した文字cが文字列に何文字入ってるか
ll stringcount(string s, char c) {
    return count(s.cbegin(), s.cend(), c);
}


// 割り算の切り上げ処理
template<typename T>
T rp(T a, T b) {
  return (a + b - 1) / b;
}

// 桁和
template<typename T>
T digsum(T n) {
    T res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

// 回文判定
bool kai (string s) {
    string t{s};
    reverse(begin(t), end(t));
    return s == t;
}

using pint = pair<int, int>;
using pll = pair<ll, ll>;



int main(void)
{
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    vector<string> a = {"hi","hihi","hihihi","hihihihi","hihihihihi"};
    string s;
    cin >> s;
    rep(i, sz(a)){
        if(a[i] == s){
            print("Yes");
            return 0;
        }
    }
    print("No");


}



//queue<pint>().swap(q); キュー内を全て削除
//priority_queue<ll, vector<ll>, greater<ll> > que;
//auto dp=make_v<int>(4,h,w);
//vector<vector<ll>> g;
//g.assign(n, vector<ll>()); g.resize(n);でも大丈夫っぽい
//fill_v(dp,0);
//int n;
//cin >> n;
//vector<int> test(n);
//cins(all(test));
//array_output(all(test));
// Yes(true);

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/2;
    public static final int inf = Integer.MAX_VALUE/2;

    static void solve(InputReader in, PrintWriter out){
        int n = in.ni(), m = in.ni();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.ni();
            sum += a[i];
        }
        int count = 0;
        for (int i = 0; i < n; i++) {
            if(a[i]*4*m>=sum) count++;
        }
        out.println(count>=m?"Yes":"No");
    }

    public static void main(String[] args){
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public double nd(){
            return Double.parseDouble(ns());
        }
        public char nc(){
            return ns().toCharArray()[0];
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21204
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[5000],y[5000],dp[5000][5000];
signed main(){
	int a,b;
	cin>>a>>b;
	f(i,a)cin>>x[i];
	f(i,b)cin>>y[i];
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(x[i-1]==y[j-1])dp[i][j]=dp[i-1][j-1]+1;
			dp[i][j]+=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
			while(dp[i][j]<0)dp[i][j]+=mod;
			dp[i][j]%=mod;
		}
	}
	cout<<(dp[a][b]+1)%mod<<endl;
}


Measured memory_bytes: 79104
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  int N,M,X,count=0,A[110000];
  cin>>N>>M>>X;

  for(int i=0;i<M;i++) cin>>A[i];

  for(int i=0;i<M;i++){
    if(A[i]<X) count++;
    else break;
  }

  cout<<min(count,M-count)<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll N;
    cin >> N;
    cout << fixed << setprecision(12) << 2 *  3.1415926535 * N << endl;
   return 0;
}

Measured memory_bytes: 3776
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int K = Integer.parseInt(S[1]);
    
    String[] T = sc.nextLine().split(" ");
    int G = Integer.parseInt(T[0]);
    int C = Integer.parseInt(T[1]);
    int P = Integer.parseInt(T[2]);
    
    String str = sc.nextLine();
    char[] c = str.toCharArray();
    long ans = 0;
    for(int i = 0; i < N; i++){
      if(i < K){
        if(c[i] == 'r'){
          ans += P;
        }else if(c[i] == 's'){
          ans += G;
        }else{
          ans += C;
        }
      }else{
        if(c[i] == 'r'){
          if(c[i] != c[i-K]){
            ans += P;
          }else{
            c[i] = 'a';
          }
        }else if(c[i] == 's'){
          if(c[i] != c[i-K]){
            ans += G;
          }else{
            c[i] = 'a';
          }
        }else{
          if(c[i] != c[i-K]){
            ans += C;
          }else{
            c[i] = 'a';
          }
        }
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 27972
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int[] s = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int x3 = s[2]-s[3]+s[1];
        int y3 = s[3]+s[2]-s[0];
        int x4 = x3-y3+s[3];
        int y4 = y3+x3-s[2];
        Console.WriteLine("{0} {1} {2} {3}", x3, y3, x4, y4);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int h, w, a, b;
    cin >> h >> w >> a >> b;
    vvi ans(h, vi(w));
    for(int i =0; i < h; i++) {
        for(int j = 0;j < w; j++) {
            if(i < b && j < a) ans[i][j] = 0;
            else if(i < b && j >= a) ans[i][j] = 1;
            else if(i >= b && j < a) ans[i][j] = 1;
            else ans[i][j] = 0;
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cout << ans[i][j];
            if(j == w-1) cout << endl;
        }
    }
}

Measured memory_bytes: 6784
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static bool isSorted(const uint64_t N, const uint64_t* num) {
    for (uint64_t i = 0; i < N; i++) {
        if (num[i] != i + 1) {
            return false;
        }
    }

    return true;
}

int main(void) {
    uint64_t N, p[50];

    scanf("%"PRIu64, &N);
    for (uint64_t i = 0; i < N; i++) {
        scanf("%"PRIu64, &p[i]);
    }

    bool isSortable = isSorted(N, p);
    for (uint64_t i = 0; i < N-1 && !isSortable; i++) {
        for (uint64_t j = i + 1; j < N && !isSortable; j++) {
            uint64_t tmp = p[i];
            p[i] = p[j];
            p[j] = tmp;

            if (isSorted(N, p)) {
                isSortable = true;
            }

            p[j] = p[i];
            p[i] = tmp;
        }
    }

    puts(isSortable ? "YES" : "NO");

    return 0;
}


Measured memory_bytes: 128
/******************************************
* AHAM BRAHMASHMI ;) *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pll pair<ll,ll>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007


template <class T>
void print(vector<T> arr)
{
	cout << "start printing the vector\n";
	for (auto u : arr)
		cout << u << " ";
	cout << "\n";
}

template <class T>
void print_mat(vector<vector<T>> a)
{
	cout << "start printing the matrix\n";
	for (auto v : a)
	{
		for (auto e : v)
		{
			cout << e << " ";
		}
		cout << "\n";
	}
}

/******************************************
* NUMBER THEORY ;) *
******************************************/



ll powermod(ll x, ll y)
{
	ll res = 1;
	x = x % mod;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % mod;
		y = y >> 1;
		x = (x * x) % mod;
	}
	res %= mod;
	return res;
}
ll factmod(ll n)
{
	ll res = 1;
	while (n > 1)
	{
		res = (res * ((n / mod) % 2 ?  mod - 1 : 1)) % mod;
		for (ll i = 2; i <= n % mod; ++i)
			res = (res * i) % mod;
		n /= mod;
	}
	res %= mod;
	return res;
}



void solve()
{
	ll n, d;
	cin >> n >> d;
	ll count = 0;
	ll x, y;
	while (n--)
	{
		cin >> x >> y;
		if (x * x + y * y <= d * d)
			count++;
	}
	cout << count << "\n";

}

int main()
{

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	// ll t;
	// cin>>t;
	// while(t--)
	// {
	solve();
	// }

	return 0;
}

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

using namespace std;
const int INF = (int) 1e9 + 7; //prime
const double EPS = 1e-9;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

#define all(c) (c).begin(),(c).end()
#define faster ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())        //for set or map or any container that implements find();
#define vpresent(c, x) (find(all(c),x) != (c).end())    //for vectors
#define print_array(arr, n) for (int i=0; i<n ;i++) { cout << arr[i] << ' ';}
#define nl "\n"
#define sp " "
#define debug(x) cerr<<#x<<" = "<<(x)<< nl
#define read_array(arr, n) for(int i=0; i<n; i++){cin >> arr[i];}
#define read freopen("input.txt", "r", stdin)
#define print freopen("output.txt", "w", stdout)

int mod = (int)1e9+7;
int n;
int memo[(int)1e6][2][2];

static int dp(int i, int zero, int nine) {
  if(i == n){
    if(zero == 1 && nine == 1){
      return 1;
    } else {
      return 0;
    }
  }
  if(memo[i][zero][nine] != -1)
    return memo[i][zero][nine];
  
  int cnt = 0;
		if(zero == 0 && nine == 0) {
			cnt = (int)(((1l * dp(i + 1, 1, nine) + dp(i + 1, zero, 1)) % mod + 8l * dp(i + 1, zero, nine)) % mod);
		} else if(zero == 0) {
			cnt = (int)((1l * dp(i + 1, 1, nine) + 9l * dp(i + 1, zero, nine)) % mod);
		} else if(nine == 0) {
			cnt = (int)((1l * dp(i + 1, zero, 1) + 9l * dp(i + 1, zero, nine)) % mod);
		} else {
			cnt = (int)(10l * dp(i + 1, zero, nine) % mod);
		}
  
  return memo[i][zero][nine] = cnt;
}

int main() {
  faster;
  cin >> n;
  if(n == 1) {
    cout << "0\n";
  } else {
    for(int i = 0; i < n; i++)
      for(int j = 0; j < 2; j++)
        for(int k = 0; k < 2; k++)
          memo[i][j][k] = -1;
    cout << dp(0, 0, 0) << "\n";
  }
}

Measured memory_bytes: 81660
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,P;cin>>N>>P;
    vector<int> a(N);
    REP(i,N)cin>>a[i];
    vector<vector<ll> > dp(N+1,vector<ll>(2,0LL));
    dp[0][0]=1;
    REP(i,N){
        dp[i+1][0]=dp[i][0]+(a[i]%2?dp[i][1]:dp[i][0]);
        dp[i+1][1]=dp[i][1]+(a[i]%2?dp[i][0]:dp[i][1]);
    }
    cout<<dp[N][P]<<endl;
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = n.times.map{gets.chomp}
t = gets.chomp

a = s.map{|w| w.tr(??,?z)}+[t]
aa = a.sort.index(t)

b = s.map{|w| w.tr(??,?a)}+[t]
bb = b.sort.rindex(t)


puts (aa+1..bb+1).to_a*" "


Measured memory_bytes: 4216
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <cassert>
#include <vector>
//#include <array>
//#include <set>
//#include <map>
//#include <unordered_set>
//#include <unordered_map>
//#include <stack>
//#include <queue>
using ll = long long;
using namespace std;

int main() {
	int n;
	cin >> n;
	if (n == 1) {
		cout << "Hello World" << endl;
	}
	else {
		int a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}


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

int main() {
  int n, ans = 0;
  string s;
  char temp;

  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> temp;
    if (s.find(temp) == string::npos) ans++;
    s += temp;
  }

  cout << (ans == 3 ? "Three" : "Four");

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a, b, c, d, w, x, y, z, ans;

    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    w=a*c;
    x=a*d;
    y=b*c;
    z=b*d;

    if(w>= x&& w>=y && w>=z)
        printf("%lld\n", w);
    else if(x>= w&& x>=y && x>=z)
        printf("%lld\n", x);
    else if(y>= x&& y>=x && y>=z)
        printf("%lld\n", y);
    else
        printf("%lld\n", z);

    return 0;
}


Measured memory_bytes: 3820
N = int(input())
data = list(map(int,input().split()))

i = 0
max_cnt = 0
while i<N-1:
    # i = tmp_i
    cnt = 0
    flag = True
    while flag:
        if i+1<N and data[i]>=data[i+1]:
            cnt += 1
            i += 1
        else:
            flag = False
            i += 1
    # tmp_i+=1
    if max_cnt<cnt:
        max_cnt=cnt

print(max_cnt)


Measured memory_bytes: 14252
#include<stdio.h>
int main()
{


int n;
scanf("%d",&n);
	if(n==1)printf("1\n");
	if(n>=2&&n<=3)printf("2\n");
	if(n>=4&&n<=7)printf("4\n");
	if(n>=8&&n<=15)printf("8\n");
	if(n>=16&&n<=31)printf("16\n");
	if(n>=32&&n<=63)printf("32\n");
	if(n>=64)printf("64\n");
		return 0;
}

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

int main(){
    int N,L,T;
    cin >> N >> L >> T;
    vector<int> X(N);
    vector<int> W(N);
    vector<int> A(N);
    vector<int> R(N);
    rep(i,N){
        cin >> X[i] >> W[i];
        if(W[i] == 1){
            A[i] = X[i] + T;
            A[i] %= L; 
        }else{
            A[i] = X[i] - T;
            A[i] %= L;
            if(A[i] < 0) A[i] += L;
        }
    }
    int cnt = 0;
    //int tmp = 0;
    rep(i,N){
        if(W[i] == 1){
            cnt += (X[i]+T)/L;
        }else{
            cnt -= (T + L - X[i]-1)/L;
            //cnt -= (T - (X[i] + 1) + L) / L;
            //cnt += (T / L);
            //if((T%L) < X[i]) cnt -= 1; 
        }
    }
    sort(A.begin(), A.end());

    //cnt = (cnt % N + N) % N;
    cnt = ((cnt % N) + N) % N; 
    //cout << cnt << endl;
    for (int i = 0; i < N; ++i) R[i] = A[(i+cnt)%N]; //R[(i+cnt)%N] = A[i];
    for (int i = 0; i < N; ++i) cout << R[i] << endl;
    /*
    int cnt = 0;
    int itr = 0;
    int rec = A[0];4 20 9
7 2
9 1
12 1
18 1
    for(int i=1;i<N;i++){
        if(W[0] == 1){
            if(W[0] != W[i]){
                if(X[i] - X[0] < 2*T) cnt++;
            } 
        }else{
            if(W[0] != W[i]){
                if(L-(X[i] - X[0]) <2*T) cnt++;
            }
        }
    }
    sort(A.begin(), A.end());
    if(W[0] == 1){
    rep(i,N){
        if(rec == A[i]){
            if(W[0] == 1){
                if(i - cnt < 0){
                    itr = i-cnt+N;
                }else{
                    itr = i-cnt;
                } 
            }else{
                if(i-(N-cnt) < 0){
                    itr = i-(N-cnt)+N;
                }else{
                    itr = i-(N-cnt);
                }
            }

            break;
        }
    }
    }else{
        for(int i=N-1;i>=0;i--){
        if(rec == A[i]){
            if(W[0] == 1){
                if(i - cnt < 0){
                    itr = i-cnt+N;
                }else{
                    itr = i-cnt;
                } 
            }else{
                if(i-(N-cnt) < 0){
                    itr = i-(N-cnt)+N;
                }else{
                    itr = i-(N-cnt);
                }
            }
            break;
        }
    }
    }
    for(int i=0;i<N;i++){
        if(i+itr < N){
            cout << A[i+itr] << endl;
        }else{
            cout << A[i+itr-N] << endl;
        }
    }
    */
    //cout << "aaa:"<< rec <<","<<N-cnt<< endl;

}



Measured memory_bytes: 2816
#include <iostream>
#include <vector>
#define P 0
#define A 1
#define O 2
#define N -1

using namespace std;

void dfs(vector< vector<int> > &vec, int x, int y){
  int h = vec.size();
  int w = vec[0].size();

  int pos_val = vec[x][y];
  vec[x][y] = N;

  if (y - 1 >= 0 && vec[x][y-1] == pos_val) // left
    dfs(vec, x, y - 1);
  if (y + 1 <= w - 1 && vec[x][y+1] == pos_val) // right
    dfs(vec, x, y + 1);
  if (x - 1 >= 0 && vec[x-1][y] == pos_val) // top
    dfs(vec, x - 1, y);
  if (x + 1 <= h - 1 && vec[x+1][y] == pos_val) // down
    dfs(vec, x + 1, y);

  return;
}

int count_area (vector< vector<int> > &vec) {
  int h = vec.size(), w = vec[0].size(), count = 0;

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (vec[i][j] != N) {
	dfs(vec, i, j);
	count++;
      }
    }
  }

  return count;
}

int main(int argc, char** argv){
  int h, w;

  while (cin >> h && cin >> w) {
    if (h == 0 && w == 0) break; // all case done

    vector< vector<int> > vec; vec.resize(h); for(int i = 0; i < h; i++) vec[i].resize(w);

    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
	char tmp;
	cin >> tmp;

	if (tmp == '#')
	  vec[i][j] = P;
	else if (tmp == '@')
	  vec[i][j] = A;
	else if (tmp == '*')
	  vec[i][j] = O;
      }
    }

    cout << count_area(vec) << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
        int n;
        scanf("%d", &n);
        vector<long long> a(n + 10);
        for (int i = 1; i <= n; i++) {
                scanf("%lld", &a[i]);
        }
        vector<vector<long long>> dp(n + 10, vector<long long>(2, 0LL));
        dp[1][0] = a[1];
        dp[2][1] = -a[1] - a[2];
        dp[2][0] = a[1] + a[2];
        for (int i = 3; i <= n; i++) {
                dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + a[i];
                long long fi = (i == 3 ? dp[i - 2][0] : max(dp[i - 2][0], dp[i - 2][1])) - a[i - 1] - a[i];
                dp[i][1] = max(fi, dp[i - 1][1] + 2LL * a[i - 1] - a[i]);
        }
        printf("%lld\n", max(dp[n][0], dp[n][1]));
        return 0;
}

Measured memory_bytes: 6528
import scala.io.StdIn

object Main extends App {
  
  var index = -1
  val inp = StdIn.readLine().trim
  val result = inp.foldLeft(List.empty[Int], List.empty[(Int, Int)], 0){  (acc, e) =>
    var tempAll  = acc._1
    var tempEach = acc._2
    var allmenseki = acc._3
    //println(tempAll)
    //println(tempEach)

    index += 1
    if(e == '\\') {
      tempAll = index :: tempAll  
    } else if(e == '/' && tempAll.length > 0){
      var j = tempAll.head
      allmenseki += index - j
      tempAll = if(tempAll.length == 1) Nil else tempAll.tail
      var a = index - j
      while(tempEach.size > 0 && tempEach.head._1 > j){
        a += tempEach.head._2
        tempEach = tempEach.tail
      }
      tempEach = (j, a) :: tempEach
    }
    (tempAll, tempEach, allmenseki)
  }
  
  println(result._3)
  println(result._2.size + (if(result._2.size == 0) "" else
    " " + result._2.reverse.map(e => e._2).mkString(" ")))
  
}



Measured memory_bytes: 49528
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(int (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define MAX 1005
const ll MOD=1e9+7;
using namespace std;

int main() {
  int N;
  cin >> N;
  int b[8]={};
  int other=0;
  rep(i,N){
    int a;
    cin >> a;
    if(1<=a&&a<400) b[0]++;
    else if(400<=a&&a<800) b[1]++;
    else if(800<=a&&a<1200) b[2]++;
    else if(1200<=a&&a<1600) b[3]++;
    else if(1600<=a&&a<2000) b[4]++;
    else if(2000<=a&&a<2400) b[5]++;
    else if(2400<=a&&a<2800) b[6]++;
    else if(2800<=a&&a<3200) b[7]++;
    else other++;
  }
  sort(b,b+8);

  int min=0;
  rep(i,8){
    if(b[i]>0) min++;
  }
  cout << max(min,1) << " " << min+other << endl;
}

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

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#ifdef MAROON_LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

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

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%" SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

signed main(){
	int n=read();
	vi a(n);
	REP(i,n)a[i]=read();
	
	int ans=0;
	int cur=0,j=0;
	REP(i,n){
		while(j<n&&(cur^a[j])==(cur+a[j])){
			cur^=a[j];
			j++;
		}
		ans+=j-i;
		cur^=a[i];
	}
	
	print(ans);
}


Measured memory_bytes: 1792
import sys
#input = sys.stdin.readline
import numpy as np

def main():
    N = int(input())
    s = [list(map(str,input())) for _ in range(N)]
    s = np.array(s)
    ans = 0
    for i in range(N):
        T = np.vstack((s[i:],s[:i]))
        if np.all(T==T.T):
            ans += N
            
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 13808
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	((A+B)%24).writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256